2 * util.c --- miscellaneous utilities
4 * Copyright (C) 1993, 1994, 1995, 1996, 1997 Theodore Ts'o.
7 * This file may be redistributed under the terms of the GNU Public
20 #include <sys/utsname.h>
26 #define read_a_char() getch()
47 extern e2fsck_t e2fsck_global_ctx; /* Try your very best not to use this! */
52 #include <sys/resource.h>
54 void fatal_error(e2fsck_t ctx, const char *msg)
56 ext2_filsys fs = ctx->fs;
57 int exit_value = FSCK_ERROR;
60 fprintf (stderr, "e2fsck: %s\n", msg);
63 if (fs->io && fs->super) {
64 ext2fs_mmp_stop(ctx->fs);
65 if (ctx->fs->io->magic == EXT2_ET_MAGIC_IO_CHANNEL)
66 io_channel_flush(ctx->fs->io);
68 log_err(ctx, "e2fsck: io manager magic bad!\n");
70 if (ext2fs_test_changed(fs)) {
71 exit_value |= FSCK_NONDESTRUCT;
72 log_out(ctx, _("\n%s: ***** FILE SYSTEM WAS MODIFIED *****\n"),
74 if (ctx->mount_flags & EXT2_MF_ISROOT)
75 exit_value |= FSCK_REBOOT;
77 if (!ext2fs_test_valid(fs)) {
78 log_out(ctx, _("\n%s: ********** WARNING: Filesystem still has "
79 "errors **********\n\n"), ctx->device_name);
80 exit_value |= FSCK_UNCORRECTED;
81 exit_value &= ~FSCK_NONDESTRUCT;
84 ctx->flags |= E2F_FLAG_ABORT;
85 if (!(ctx->options & E2F_OPT_MULTITHREAD) &&
86 ctx->flags & E2F_FLAG_SETJMP_OK)
87 longjmp(ctx->abort_loc, 1);
89 fprintf(ctx->logf, "Exit status: %d\n", exit_value);
94 static void thread_log_out(struct e2fsck_thread *tinfo)
96 printf("[Thread %d] %s", tinfo->et_thread_index,
98 tinfo->et_log_length = 0;
99 tinfo->et_log_buf[0] = '\0';
103 void log_out(e2fsck_t ctx, const char *fmt, ...)
106 struct e2fsck_thread *tinfo;
112 if ((ctx->options & E2F_OPT_MULTITHREAD) && ctx->global_ctx) {
113 tinfo = &ctx->thread_info;
114 buf_size = sizeof(tinfo->et_log_buf);
115 left_size = buf_size - tinfo->et_log_length;
118 msg_size = vsnprintf(tinfo->et_log_buf + tinfo->et_log_length,
119 left_size, fmt, pvar);
122 if (msg_size >= left_size) {
123 tinfo->et_log_buf[tinfo->et_log_length] = '\0';
125 assert(msg_size < buf_size);
126 if (msg_size < buf_size) {
127 thread_log_out(tinfo);
130 msg_size = vsnprintf(tinfo->et_log_buf, buf_size,
134 tinfo->et_log_length += msg_size;
135 tinfo->et_log_buf[tinfo->et_log_length] = '\0';
138 tinfo->et_log_length += msg_size;
139 tinfo->et_log_buf[tinfo->et_log_length] = '\0';
142 if (tinfo->et_log_length > 0 &&
143 tinfo->et_log_buf[tinfo->et_log_length - 1] == '\n')
144 thread_log_out(tinfo);
155 vfprintf(ctx->logf, fmt, pvar);
160 void log_err(e2fsck_t ctx, const char *fmt, ...)
165 vfprintf(stderr, fmt, pvar);
169 vfprintf(ctx->logf, fmt, pvar);
174 void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
175 const char *description)
180 #ifdef DEBUG_ALLOCATE_MEMORY
181 printf("Allocating %lu bytes for %s...\n", size, description);
183 if (ext2fs_get_memzero(size, &ret)) {
184 sprintf(buf, "Can't allocate %lu bytes for %s\n",
186 fatal_error(ctx, buf);
192 char *string_copy(e2fsck_t ctx EXT2FS_ATTR((unused)),
193 const char *str, size_t len)
203 strncpy(ret, str, len);
211 * Incredibly, libc5 doesn't appear to have strnlen. So we have to
214 int e2fsck_strnlen(const char * s, int count)
218 while (count-- && *cp)
225 static int read_a_char(void)
232 if (e2fsck_global_ctx &&
233 (e2fsck_global_ctx->flags & E2F_FLAG_CANCEL)) {
246 int ask_yn(e2fsck_t ctx, const char * string, int def)
250 const char *short_yes = _("yY");
251 const char *short_no = _("nN");
252 const char *short_yesall = _("aA");
253 const char *english_yes = "yY";
254 const char *english_no = "nN";
255 const char *english_yesall = "aA";
256 const char *yesall_prompt = _(" ('a' enables 'yes' to all) ");
257 const char *extra_prompt = "";
258 static int yes_answers;
260 #ifdef HAVE_TERMIOS_H
261 struct termios termios, tmp;
263 if (tcgetattr (0, &termios) < 0)
264 memset(&termios, 0, sizeof(termios));
266 tmp.c_lflag &= ~(ICANON | ECHO);
269 tcsetattr (0, TCSANOW, &tmp);
273 defstr = _(_("<y>"));
275 defstr = _(_("<n>"));
277 defstr = _(" (y/n)");
279 * If the user presses 'y' more than 8 (but less than 12) times in
280 * succession without pressing anything else, display a hint about
283 if (yes_answers > 12)
285 else if (yes_answers > 8)
286 extra_prompt = yesall_prompt;
287 log_out(ctx, "%s%s%s? ", string, extra_prompt, defstr);
290 if ((c = read_a_char()) == EOF)
293 #ifdef HAVE_TERMIOS_H
294 tcsetattr (0, TCSANOW, &termios);
296 if (ctx->flags & E2F_FLAG_SETJMP_OK) {
298 longjmp(e2fsck_global_ctx->abort_loc, 1);
300 log_out(ctx, "%s", _("cancelled!\n"));
304 if (strchr(short_yes, (char) c)) {
307 if (yes_answers >= 0)
310 } else if (strchr(short_no, (char) c)) {
315 } else if (strchr(short_yesall, (char)c)) {
319 ctx->options |= E2F_OPT_YES;
321 } else if (strchr(english_yes, (char) c)) {
323 } else if (strchr(english_no, (char) c)) {
325 } else if (strchr(english_yesall, (char) c)) {
327 } else if ((c == 27 || c == ' ' || c == '\n') && (def != -1)) {
333 log_out(ctx, "%s", _("yes to all\n"));
335 log_out(ctx, "%s", _("yes\n"));
337 log_out(ctx, "%s", _("no\n"));
338 #ifdef HAVE_TERMIOS_H
339 tcsetattr (0, TCSANOW, &termios);
344 int ask (e2fsck_t ctx, const char * string, int def)
346 if (ctx->options & E2F_OPT_NO) {
347 log_out(ctx, _("%s? no\n\n"), string);
350 if (ctx->options & E2F_OPT_YES) {
351 log_out(ctx, _("%s? yes\n\n"), string);
354 if (ctx->options & E2F_OPT_PREEN) {
355 log_out(ctx, "%s? %s\n\n", string, def ? _("yes") : _("no"));
358 return ask_yn(ctx, string, def);
361 void e2fsck_read_bitmaps(e2fsck_t ctx)
363 ext2_filsys fs = ctx->fs;
366 unsigned int save_type;
369 if (ctx->invalid_bitmaps) {
370 com_err(ctx->program_name, 0,
371 _("e2fsck_read_bitmaps: illegal bitmap block(s) for %s"),
376 old_op = ehandler_operation(_("reading inode and block bitmaps"));
377 e2fsck_set_bitmap_type(fs, EXT2FS_BMAP64_RBTREE, "fs_bitmaps",
379 flags = ctx->fs->flags;
380 ctx->fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
381 retval = ext2fs_read_bitmaps(fs);
382 ctx->fs->flags = (flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) |
383 (ctx->fs->flags & ~EXT2_FLAG_IGNORE_CSUM_ERRORS);
384 fs->default_bitmap_type = save_type;
385 ehandler_operation(old_op);
387 com_err(ctx->program_name, retval,
388 _("while retrying to read bitmaps for %s"),
394 void e2fsck_write_bitmaps(e2fsck_t ctx)
396 ext2_filsys fs = ctx->fs;
400 old_op = ehandler_operation(_("writing block and inode bitmaps"));
401 retval = ext2fs_write_bitmaps(fs);
402 ehandler_operation(old_op);
404 com_err(ctx->program_name, retval,
405 _("while rewriting block and inode bitmaps for %s"),
411 void preenhalt(e2fsck_t ctx)
413 ext2_filsys fs = ctx->fs;
415 if (!(ctx->options & E2F_OPT_PREEN))
417 log_err(ctx, _("\n\n%s: UNEXPECTED INCONSISTENCY; "
418 "RUN fsck MANUALLY.\n\t(i.e., without -a or -p options)\n"),
420 ctx->flags |= E2F_FLAG_EXITING;
422 fs->super->s_state |= EXT2_ERROR_FS;
423 ext2fs_mark_super_dirty(fs);
424 ext2fs_close_free(&fs);
426 exit(FSCK_UNCORRECTED);
429 #ifdef RESOURCE_TRACK
430 void init_resource_track(struct resource_track *track, io_channel channel)
432 #ifdef HAVE_GETRUSAGE
435 io_stats io_start = 0;
437 track->brk_start = sbrk(0);
438 gettimeofday(&track->time_start, 0);
439 #ifdef HAVE_GETRUSAGE
441 memset(&r, 0, sizeof(struct rusage));
443 getrusage(RUSAGE_SELF, &r);
444 track->user_start = r.ru_utime;
445 track->system_start = r.ru_stime;
447 track->user_start.tv_sec = track->user_start.tv_usec = 0;
448 track->system_start.tv_sec = track->system_start.tv_usec = 0;
450 track->bytes_read = 0;
451 track->bytes_written = 0;
452 if (channel && channel->manager && channel->manager->get_stats)
453 channel->manager->get_stats(channel, &io_start);
455 track->bytes_read = io_start->bytes_read;
456 track->bytes_written = io_start->bytes_written;
461 #define _INLINE_ __inline__
466 static _INLINE_ float timeval_subtract(struct timeval *tv1,
469 return ((tv1->tv_sec - tv2->tv_sec) +
470 ((float) (tv1->tv_usec - tv2->tv_usec)) / 1000000);
473 void print_resource_track(e2fsck_t ctx, const char *desc,
474 struct resource_track *track, io_channel channel)
476 #ifdef HAVE_GETRUSAGE
479 struct timeval time_end;
481 if ((desc && !(ctx->options & E2F_OPT_TIME2)) ||
482 (!desc && !(ctx->options & E2F_OPT_TIME)))
485 e2fsck_clear_progbar(ctx);
486 gettimeofday(&time_end, 0);
489 log_out(ctx, "%s: ", desc);
491 #define kbytes(x) (((unsigned long long)(x) + 1023) / 1024)
492 #ifdef HAVE_MALLINFO2
494 struct mallinfo2 malloc_info = mallinfo2();
496 log_out(ctx, _("Memory used: %lluk/%lluk (%lluk/%lluk), "),
497 kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
498 kbytes(malloc_info.uordblks),
499 kbytes(malloc_info.fordblks));
501 #elif defined HAVE_MALLINFO
502 /* don't use mallinfo() if over 2GB used, since it returns "int" */
503 if ((char *)sbrk(0) - (char *)track->brk_start < 2LL << 30) {
504 struct mallinfo malloc_info = mallinfo();
506 log_out(ctx, _("Memory used: %lluk/%lluk (%lluk/%lluk), "),
507 kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
508 kbytes(malloc_info.uordblks),
509 kbytes(malloc_info.fordblks));
512 log_out(ctx, _("Memory used: %lluk, "),
513 kbytes(((char *)sbrk(0)) - ((char *)track->brk_start)));
515 #ifdef HAVE_GETRUSAGE
516 getrusage(RUSAGE_SELF, &r);
518 log_out(ctx, _("time: %5.2f/%5.2f/%5.2f\n"),
519 timeval_subtract(&time_end, &track->time_start),
520 timeval_subtract(&r.ru_utime, &track->user_start),
521 timeval_subtract(&r.ru_stime, &track->system_start));
523 log_out(ctx, _("elapsed time: %6.3f\n"),
524 timeval_subtract(&time_end, &track->time_start));
526 #define mbytes(x) (((x) + 1048575) / 1048576)
527 if (channel && channel->manager && channel->manager->get_stats) {
529 unsigned long long bytes_read = 0;
530 unsigned long long bytes_written = 0;
533 log_out(ctx, "%s: ", desc);
535 channel->manager->get_stats(channel, &delta);
537 bytes_read = delta->bytes_read - track->bytes_read;
538 bytes_written = delta->bytes_written -
539 track->bytes_written;
541 log_out(ctx, "I/O read: %lluMB, write: %lluMB, "
543 mbytes(bytes_read), mbytes(bytes_written),
544 (double)mbytes(bytes_read + bytes_written) /
545 timeval_subtract(&time_end, &track->time_start));
548 #endif /* RESOURCE_TRACK */
550 void e2fsck_read_inode(e2fsck_t ctx, unsigned long ino,
551 struct ext2_inode * inode, const char *proc)
555 retval = ext2fs_read_inode(ctx->fs, ino, inode);
557 com_err("ext2fs_read_inode", retval,
558 _("while reading inode %lu in %s"), ino, proc);
563 void e2fsck_read_inode_full(e2fsck_t ctx, unsigned long ino,
564 struct ext2_inode *inode, int bufsize,
569 retval = ext2fs_read_inode_full(ctx->fs, ino, inode, bufsize);
571 com_err("ext2fs_read_inode_full", retval,
572 _("while reading inode %lu in %s"), ino, proc);
578 #define e2fsck_get_lock_context(ctx) \
579 e2fsck_t global_ctx = ctx->global_ctx; \
584 * before we hold write lock, read lock should
587 void e2fsck_pass1_fix_lock(e2fsck_t ctx)
591 if (!ctx->fs_need_locking)
594 e2fsck_get_lock_context(ctx);
595 err = pthread_rwlock_trywrlock(&global_ctx->fs_fix_rwlock);
597 pthread_rwlock_unlock(&global_ctx->fs_fix_rwlock);
598 pthread_rwlock_wrlock(&global_ctx->fs_fix_rwlock);
601 void e2fsck_pass1_fix_unlock(e2fsck_t ctx)
603 if (!ctx->fs_need_locking)
605 e2fsck_get_lock_context(ctx);
606 /* unlock write lock */
607 pthread_rwlock_unlock(&global_ctx->fs_fix_rwlock);
608 /* get read lock again */
609 pthread_rwlock_rdlock(&global_ctx->fs_fix_rwlock);
612 void e2fsck_pass1_check_lock(e2fsck_t ctx)
614 if (!ctx->fs_need_locking)
616 e2fsck_get_lock_context(ctx);
617 pthread_rwlock_rdlock(&global_ctx->fs_fix_rwlock);
620 void e2fsck_pass1_check_unlock(e2fsck_t ctx)
622 if (!ctx->fs_need_locking)
624 e2fsck_get_lock_context(ctx);
625 pthread_rwlock_unlock(&global_ctx->fs_fix_rwlock);
628 void e2fsck_pass1_block_map_w_lock(e2fsck_t ctx)
630 if (!ctx->fs_need_locking)
632 e2fsck_get_lock_context(ctx);
633 pthread_rwlock_wrlock(&global_ctx->fs_block_map_rwlock);
636 void e2fsck_pass1_block_map_w_unlock(e2fsck_t ctx)
638 if (!ctx->fs_need_locking)
640 e2fsck_get_lock_context(ctx);
641 pthread_rwlock_unlock(&global_ctx->fs_block_map_rwlock);
644 void e2fsck_pass1_block_map_r_lock(e2fsck_t ctx)
646 if (!ctx->fs_need_locking)
648 e2fsck_get_lock_context(ctx);
649 pthread_rwlock_rdlock(&global_ctx->fs_block_map_rwlock);
652 void e2fsck_pass1_block_map_r_unlock(e2fsck_t ctx)
654 if (!ctx->fs_need_locking)
656 e2fsck_get_lock_context(ctx);
657 pthread_rwlock_unlock(&global_ctx->fs_block_map_rwlock);
660 void e2fsck_pass1_fix_lock(e2fsck_t ctx)
665 void e2fsck_pass1_fix_unlock(e2fsck_t ctx)
669 void e2fsck_pass1_check_lock(e2fsck_t ctx)
673 void e2fsck_pass1_check_unlock(e2fsck_t ctx)
677 void e2fsck_pass1_block_map_w_lock(e2fsck_t ctx)
682 void e2fsck_pass1_block_map_w_unlock(e2fsck_t ctx)
687 void e2fsck_pass1_block_map_r_lock(e2fsck_t ctx)
692 void e2fsck_pass1_block_map_r_unlock(e2fsck_t ctx)
698 void e2fsck_write_inode_full(e2fsck_t ctx, unsigned long ino,
699 struct ext2_inode * inode, int bufsize,
704 e2fsck_pass1_fix_lock(ctx);
705 retval = ext2fs_write_inode_full(ctx->fs, ino, inode, bufsize);
706 e2fsck_pass1_fix_unlock(ctx);
708 com_err("ext2fs_write_inode", retval,
709 _("while writing inode %lu in %s"), ino, proc);
714 void e2fsck_write_inode(e2fsck_t ctx, unsigned long ino,
715 struct ext2_inode * inode, const char *proc)
719 e2fsck_pass1_fix_lock(ctx);
720 retval = ext2fs_write_inode(ctx->fs, ino, inode);
721 e2fsck_pass1_fix_unlock(ctx);
723 com_err("ext2fs_write_inode", retval,
724 _("while writing inode %lu in %s"), ino, proc);
730 void mtrace_print(char *mesg)
732 FILE *malloc_get_mallstream();
733 FILE *f = malloc_get_mallstream();
736 fprintf(f, "============= %s\n", mesg);
740 blk64_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name,
743 struct ext2_super_block *sb;
744 io_channel io = NULL;
746 int blocksize = EXT2_MIN_BLOCK_SIZE;
747 int blocksize_known = 0;
749 blk64_t ret_sb = 8193;
751 if (fs && fs->super) {
752 blocksize = fs->blocksize;
754 bpg = fs->super->s_blocks_per_group;
757 if (ctx && ctx->blocksize) {
758 blocksize = ctx->blocksize;
762 if (!name || !manager)
765 if (manager->open(name, 0, &io) != 0)
768 if (ext2fs_get_mem(SUPERBLOCK_SIZE, &buf))
770 sb = (struct ext2_super_block *) buf;
772 for (; blocksize <= EXT2_MAX_BLOCK_SIZE; blocksize *= 2) {
773 dgrp_t grp, three = 1, five = 5, seven = 7;
774 dgrp_t limit = (dgrp_t)-1;
775 blk_t this_bpg = bpg ? bpg : blocksize * 8;
777 if (ctx->num_blocks && limit > ctx->num_blocks / this_bpg)
778 limit = ctx->num_blocks / this_bpg;
780 io_channel_set_blksize(io, blocksize);
782 while ((grp = ext2fs_list_backups(NULL, &three,
783 &five, &seven)) < limit) {
784 blk64_t superblock = (blk64_t)grp * this_bpg;
786 if (blocksize == 1024)
788 if (io_channel_read_blk64(io, superblock,
789 -SUPERBLOCK_SIZE, buf))
791 #ifdef WORDS_BIGENDIAN
792 if (sb->s_magic == ext2fs_swab16(EXT2_SUPER_MAGIC))
793 ext2fs_swap_super(sb);
795 if ((sb->s_magic == EXT2_SUPER_MAGIC) &&
796 (EXT2_BLOCK_SIZE(sb) == blocksize)) {
799 ctx->superblock = superblock;
800 ctx->blocksize = blocksize;
812 io_channel_close(io);
814 ext2fs_free_mem(&buf);
819 * Given a mode, return the ext2 file type
821 int ext2_file_type(unsigned int mode)
823 if (LINUX_S_ISREG(mode))
824 return EXT2_FT_REG_FILE;
826 if (LINUX_S_ISDIR(mode))
829 if (LINUX_S_ISCHR(mode))
830 return EXT2_FT_CHRDEV;
832 if (LINUX_S_ISBLK(mode))
833 return EXT2_FT_BLKDEV;
835 if (LINUX_S_ISLNK(mode))
836 return EXT2_FT_SYMLINK;
838 if (LINUX_S_ISFIFO(mode))
841 if (LINUX_S_ISSOCK(mode))
848 * Check to see if a filesystem is in /proc/filesystems.
849 * Returns 1 if found, 0 if not
851 int fs_proc_check(const char *fs_name)
854 char buf[80], *cp, *t;
856 f = fopen("/proc/filesystems", "r");
860 if (!fgets(buf, sizeof(buf), f))
864 while (*cp && !isspace(*cp))
867 while (*cp && isspace(*cp))
869 if ((t = strchr(cp, '\n')) != NULL)
871 if ((t = strchr(cp, '\t')) != NULL)
873 if ((t = strchr(cp, ' ')) != NULL)
875 if (!strcmp(fs_name, cp)) {
885 * Check to see if a filesystem is available as a module
886 * Returns 1 if found, 0 if not
888 int check_for_modules(const char *fs_name)
893 char buf[1024], *cp, *t;
898 snprintf(buf, sizeof(buf), "/lib/modules/%s/modules.dep", uts.release);
904 if (!fgets(buf, sizeof(buf), f))
906 if ((cp = strchr(buf, ':')) != NULL)
910 if ((cp = strrchr(buf, '/')) != NULL)
917 if (!strcmp(t, ".ko"))
920 if (!strcmp(cp, fs_name)) {
926 #endif /* __linux__ */
931 * Helper function that does the right thing if write returns a
932 * partial write, or an EAGAIN/EINTR error.
934 int write_all(int fd, char *buf, size_t count)
940 ret = write(fd, buf, count);
942 if ((errno == EAGAIN) || (errno == EINTR))
953 void dump_mmp_msg(struct mmp_struct *mmp, const char *fmt, ...)
958 printf("MMP check failed: ");
964 time_t t = mmp->mmp_time;
966 printf("MMP_block:\n");
967 printf(" mmp_magic: 0x%x\n", mmp->mmp_magic);
968 printf(" mmp_check_interval: %d\n",
969 mmp->mmp_check_interval);
970 printf(" mmp_sequence: %08x\n", mmp->mmp_seq);
971 printf(" mmp_update_date: %s", ctime(&t));
972 printf(" mmp_update_time: %lld\n",
973 (long long) mmp->mmp_time);
974 printf(" mmp_node_name: %.*s\n",
975 EXT2_LEN_STR(mmp->mmp_nodename));
976 printf(" mmp_device_name: %.*s\n",
977 EXT2_LEN_STR(mmp->mmp_bdevname));
981 errcode_t e2fsck_mmp_update(ext2_filsys fs)
985 retval = ext2fs_mmp_update(fs);
986 if (retval == EXT2_ET_MMP_CHANGE_ABORT)
987 dump_mmp_msg(fs->mmp_cmp,
988 _("UNEXPECTED INCONSISTENCY: the filesystem is "
989 "being modified while fsck is running.\n"));
994 void e2fsck_set_bitmap_type(ext2_filsys fs, unsigned int default_type,
995 const char *profile_name, unsigned int *old_type)
998 e2fsck_t ctx = (e2fsck_t) fs->priv_data;
1001 *old_type = fs->default_bitmap_type;
1002 profile_get_uint(ctx->profile, "bitmaps", profile_name, 0,
1003 default_type, &type);
1004 profile_get_uint(ctx->profile, "bitmaps", "all", 0, type, &type);
1005 fs->default_bitmap_type = type ? type : default_type;
1008 errcode_t e2fsck_allocate_inode_bitmap(ext2_filsys fs, const char *descr,
1011 ext2fs_inode_bitmap *ret)
1014 unsigned int save_type;
1016 e2fsck_set_bitmap_type(fs, deftype, name, &save_type);
1017 retval = ext2fs_allocate_inode_bitmap(fs, descr, ret);
1018 fs->default_bitmap_type = save_type;
1022 errcode_t e2fsck_allocate_block_bitmap(ext2_filsys fs, const char *descr,
1025 ext2fs_block_bitmap *ret)
1028 unsigned int save_type;
1030 e2fsck_set_bitmap_type(fs, deftype, name, &save_type);
1031 retval = ext2fs_allocate_block_bitmap(fs, descr, ret);
1032 fs->default_bitmap_type = save_type;
1036 errcode_t e2fsck_allocate_subcluster_bitmap(ext2_filsys fs, const char *descr,
1039 ext2fs_block_bitmap *ret)
1042 unsigned int save_type;
1044 e2fsck_set_bitmap_type(fs, deftype, name, &save_type);
1045 retval = ext2fs_allocate_subcluster_bitmap(fs, descr, ret);
1046 fs->default_bitmap_type = save_type;
1050 /* Return memory size in bytes */
1051 unsigned long long get_memory_size(void)
1053 #if defined(_SC_PHYS_PAGES)
1054 # if defined(_SC_PAGESIZE)
1055 return (unsigned long long)sysconf(_SC_PHYS_PAGES) *
1056 (unsigned long long)sysconf(_SC_PAGESIZE);
1057 # elif defined(_SC_PAGE_SIZE)
1058 return (unsigned long long)sysconf(_SC_PHYS_PAGES) *
1059 (unsigned long long)sysconf(_SC_PAGE_SIZE);
1061 #elif defined(CTL_HW)
1062 # if (defined(HW_MEMSIZE) || defined(HW_PHYSMEM64))
1063 # define CTL_HW_INT64
1064 # elif (defined(HW_PHYSMEM) || defined(HW_REALMEM))
1065 # define CTL_HW_UINT
1070 # if defined(HW_MEMSIZE)
1071 mib[1] = HW_MEMSIZE;
1072 # elif defined(HW_PHYSMEM64)
1073 mib[1] = HW_PHYSMEM64;
1074 # elif defined(HW_REALMEM)
1075 mib[1] = HW_REALMEM;
1076 # elif defined(HW_PYSMEM)
1077 mib[1] = HW_PHYSMEM;
1079 # if defined(CTL_HW_INT64)
1080 unsigned long long size = 0;
1081 # elif defined(CTL_HW_UINT)
1082 unsigned int size = 0;
1086 # warning "Don't know how to detect memory on your platform?"