#include <errno.h>
#endif
-#ifdef HAVE_SYS_SYSCTL_H
-#include <sys/sysctl.h>
-#endif
-
#include "e2fsck.h"
extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
}
}
-void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned int size,
+void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
const char *description)
{
void *ret;
char buf[256];
#ifdef DEBUG_ALLOCATE_MEMORY
- printf("Allocating %u bytes for %s...\n", size, description);
+ printf("Allocating %lu bytes for %s...\n", size, description);
#endif
- ret = malloc(size);
- if (!ret) {
- sprintf(buf, "Can't allocate %u bytes for %s\n",
+ if (ext2fs_get_memzero(size, &ret)) {
+ sprintf(buf, "Can't allocate %lu bytes for %s\n",
size, description);
fatal_error(ctx, buf);
}
- memset(ret, 0, size);
+
return ret;
}
char *string_copy(e2fsck_t ctx EXT2FS_ATTR((unused)),
- const char *str, int len)
+ const char *str, size_t len)
{
char *ret;
static int yes_answers;
#ifdef HAVE_TERMIOS_H
- struct termios termios = {0, }, tmp;
+ struct termios termios, tmp;
- tcgetattr (0, &termios);
+ if (tcgetattr (0, &termios) < 0)
+ memset(&termios, 0, sizeof(termios));
tmp = termios;
tmp.c_lflag &= ~(ICANON | ECHO);
tmp.c_cc[VMIN] = 1;
#ifdef HAVE_GETRUSAGE
struct rusage r;
#endif
-#ifdef HAVE_MALLINFO
- struct mallinfo malloc_info;
-#endif
struct timeval time_end;
if ((desc && !(ctx->options & E2F_OPT_TIME2)) ||
if (desc)
log_out(ctx, "%s: ", desc);
-#ifdef HAVE_MALLINFO
-#define kbytes(x) (((unsigned long)(x) + 1023) / 1024)
-
- malloc_info = mallinfo();
- log_out(ctx, _("Memory used: %luk/%luk (%luk/%luk), "),
- kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
- kbytes(malloc_info.uordblks), kbytes(malloc_info.fordblks));
-#else
- log_out(ctx, _("Memory used: %lu, "),
- (unsigned long) (((char *) sbrk(0)) -
- ((char *) track->brk_start)));
+#define kbytes(x) (((unsigned long long)(x) + 1023) / 1024)
+#ifdef HAVE_MALLINFO2
+ if (1) {
+ struct mallinfo2 malloc_info = mallinfo2();
+
+ log_out(ctx, _("Memory used: %lluk/%lluk (%lluk/%lluk), "),
+ kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
+ kbytes(malloc_info.uordblks),
+ kbytes(malloc_info.fordblks));
+ } else
+#elif defined HAVE_MALLINFO
+ /* don't use mallinfo() if over 2GB used, since it returns "int" */
+ if ((char *)sbrk(0) - (char *)track->brk_start < 2LL << 30) {
+ struct mallinfo malloc_info = mallinfo();
+
+ log_out(ctx, _("Memory used: %lluk/%lluk (%lluk/%lluk), "),
+ kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
+ kbytes(malloc_info.uordblks),
+ kbytes(malloc_info.fordblks));
+ } else
#endif
+ log_out(ctx, _("Memory used: %lluk, "),
+ kbytes(((char *)sbrk(0)) - ((char *)track->brk_start)));
+
#ifdef HAVE_GETRUSAGE
getrusage(RUSAGE_SELF, &r);
/*
* Helper function that does the right thing if write returns a
- * partial write, or an EGAIN/EINTR error.
+ * partial write, or an EAGAIN/EINTR error.
*/
int write_all(int fd, char *buf, size_t count)
{
return c;
}
-void dump_mmp_msg(struct mmp_struct *mmp, const char *msg)
+void dump_mmp_msg(struct mmp_struct *mmp, const char *fmt, ...)
{
+ va_list pvar;
- if (msg)
- printf("MMP check failed: %s\n", msg);
+ if (fmt) {
+ printf("MMP check failed: ");
+ va_start(pvar, fmt);
+ vprintf(fmt, pvar);
+ va_end(pvar);
+ }
if (mmp) {
time_t t = mmp->mmp_time;
- printf("MMP error info: last update: %s node: %s device: %s\n",
- ctime(&t), mmp->mmp_nodename, mmp->mmp_bdevname);
+ printf("MMP_block:\n");
+ printf(" mmp_magic: 0x%x\n", mmp->mmp_magic);
+ printf(" mmp_check_interval: %d\n",
+ mmp->mmp_check_interval);
+ printf(" mmp_sequence: %08x\n", mmp->mmp_seq);
+ printf(" mmp_update_date: %s", ctime(&t));
+ printf(" mmp_update_time: %lld\n",
+ (long long) mmp->mmp_time);
+ printf(" mmp_node_name: %.*s\n",
+ EXT2_LEN_STR(mmp->mmp_nodename));
+ printf(" mmp_device_name: %.*s\n",
+ EXT2_LEN_STR(mmp->mmp_bdevname));
}
}
# elif defined(CTL_HW_UINT)
unsigned int size = 0;
# endif
-# if defined(CTL_HW_INT64) || defined(CTL_HW_UINT)
- size_t len = sizeof(size);
-
- if (sysctl(mib, 2, &size, &len, NULL, 0) == 0)
- return (unsigned long long)size;
-# endif
return 0;
#else
# warning "Don't know how to detect memory on your platform?"