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;
110 int fmt_length = strlen(fmt);
113 if ((ctx->options & E2F_OPT_MULTITHREAD) && ctx->global_ctx) {
114 tinfo = &ctx->thread_info;
115 buf_size = sizeof(tinfo->et_log_buf);
116 left_size = buf_size - tinfo->et_log_length;
119 msg_size = vsnprintf(tinfo->et_log_buf + tinfo->et_log_length,
120 left_size, fmt, pvar);
123 if (msg_size >= left_size) {
124 tinfo->et_log_buf[tinfo->et_log_length] = '\0';
126 assert(msg_size < buf_size);
127 if (msg_size < buf_size) {
128 thread_log_out(tinfo);
131 msg_size = vsnprintf(tinfo->et_log_buf, buf_size,
135 tinfo->et_log_length += msg_size;
136 tinfo->et_log_buf[tinfo->et_log_length] = '\0';
139 tinfo->et_log_length += msg_size;
140 tinfo->et_log_buf[tinfo->et_log_length] = '\0';
143 if (tinfo->et_log_length > 0 &&
144 tinfo->et_log_buf[tinfo->et_log_length - 1] == '\n')
145 thread_log_out(tinfo);
156 vfprintf(ctx->logf, fmt, pvar);
161 void log_err(e2fsck_t ctx, const char *fmt, ...)
166 vfprintf(stderr, fmt, pvar);
170 vfprintf(ctx->logf, fmt, pvar);
175 void *e2fsck_allocate_memory(e2fsck_t ctx, unsigned long size,
176 const char *description)
181 #ifdef DEBUG_ALLOCATE_MEMORY
182 printf("Allocating %lu bytes for %s...\n", size, description);
184 if (ext2fs_get_memzero(size, &ret)) {
185 sprintf(buf, "Can't allocate %lu bytes for %s\n",
187 fatal_error(ctx, buf);
193 char *string_copy(e2fsck_t ctx EXT2FS_ATTR((unused)),
194 const char *str, size_t len)
204 strncpy(ret, str, len);
212 * Incredibly, libc5 doesn't appear to have strnlen. So we have to
215 int e2fsck_strnlen(const char * s, int count)
219 while (count-- && *cp)
226 static int read_a_char(void)
233 if (e2fsck_global_ctx &&
234 (e2fsck_global_ctx->flags & E2F_FLAG_CANCEL)) {
247 int ask_yn(e2fsck_t ctx, const char * string, int def)
251 const char *short_yes = _("yY");
252 const char *short_no = _("nN");
253 const char *short_yesall = _("aA");
254 const char *english_yes = "yY";
255 const char *english_no = "nN";
256 const char *english_yesall = "aA";
257 const char *yesall_prompt = _(" ('a' enables 'yes' to all) ");
258 const char *extra_prompt = "";
259 static int yes_answers;
261 #ifdef HAVE_TERMIOS_H
262 struct termios termios, tmp;
264 if (tcgetattr (0, &termios) < 0)
265 memset(&termios, 0, sizeof(termios));
267 tmp.c_lflag &= ~(ICANON | ECHO);
270 tcsetattr (0, TCSANOW, &tmp);
274 defstr = _(_("<y>"));
276 defstr = _(_("<n>"));
278 defstr = _(" (y/n)");
280 * If the user presses 'y' more than 8 (but less than 12) times in
281 * succession without pressing anything else, display a hint about
284 if (yes_answers > 12)
286 else if (yes_answers > 8)
287 extra_prompt = yesall_prompt;
288 log_out(ctx, "%s%s%s? ", string, extra_prompt, defstr);
291 if ((c = read_a_char()) == EOF)
294 #ifdef HAVE_TERMIOS_H
295 tcsetattr (0, TCSANOW, &termios);
297 if (ctx->flags & E2F_FLAG_SETJMP_OK) {
299 longjmp(e2fsck_global_ctx->abort_loc, 1);
301 log_out(ctx, "%s", _("cancelled!\n"));
305 if (strchr(short_yes, (char) c)) {
308 if (yes_answers >= 0)
311 } else if (strchr(short_no, (char) c)) {
316 } else if (strchr(short_yesall, (char)c)) {
320 ctx->options |= E2F_OPT_YES;
322 } else if (strchr(english_yes, (char) c)) {
324 } else if (strchr(english_no, (char) c)) {
326 } else if (strchr(english_yesall, (char) c)) {
328 } else if ((c == 27 || c == ' ' || c == '\n') && (def != -1)) {
334 log_out(ctx, "%s", _("yes to all\n"));
336 log_out(ctx, "%s", _("yes\n"));
338 log_out(ctx, "%s", _("no\n"));
339 #ifdef HAVE_TERMIOS_H
340 tcsetattr (0, TCSANOW, &termios);
345 int ask (e2fsck_t ctx, const char * string, int def)
347 if (ctx->options & E2F_OPT_NO) {
348 log_out(ctx, _("%s? no\n\n"), string);
351 if (ctx->options & E2F_OPT_YES) {
352 log_out(ctx, _("%s? yes\n\n"), string);
355 if (ctx->options & E2F_OPT_PREEN) {
356 log_out(ctx, "%s? %s\n\n", string, def ? _("yes") : _("no"));
359 return ask_yn(ctx, string, def);
362 void e2fsck_read_bitmaps(e2fsck_t ctx)
364 ext2_filsys fs = ctx->fs;
367 unsigned int save_type;
370 if (ctx->invalid_bitmaps) {
371 com_err(ctx->program_name, 0,
372 _("e2fsck_read_bitmaps: illegal bitmap block(s) for %s"),
377 old_op = ehandler_operation(_("reading inode and block bitmaps"));
378 e2fsck_set_bitmap_type(fs, EXT2FS_BMAP64_RBTREE, "fs_bitmaps",
380 flags = ctx->fs->flags;
381 ctx->fs->flags |= EXT2_FLAG_IGNORE_CSUM_ERRORS;
382 retval = ext2fs_read_bitmaps(fs);
383 ctx->fs->flags = (flags & EXT2_FLAG_IGNORE_CSUM_ERRORS) |
384 (ctx->fs->flags & ~EXT2_FLAG_IGNORE_CSUM_ERRORS);
385 fs->default_bitmap_type = save_type;
386 ehandler_operation(old_op);
388 com_err(ctx->program_name, retval,
389 _("while retrying to read bitmaps for %s"),
395 void e2fsck_write_bitmaps(e2fsck_t ctx)
397 ext2_filsys fs = ctx->fs;
401 old_op = ehandler_operation(_("writing block and inode bitmaps"));
402 retval = ext2fs_write_bitmaps(fs);
403 ehandler_operation(old_op);
405 com_err(ctx->program_name, retval,
406 _("while rewriting block and inode bitmaps for %s"),
412 void preenhalt(e2fsck_t ctx)
414 ext2_filsys fs = ctx->fs;
416 if (!(ctx->options & E2F_OPT_PREEN))
418 log_err(ctx, _("\n\n%s: UNEXPECTED INCONSISTENCY; "
419 "RUN fsck MANUALLY.\n\t(i.e., without -a or -p options)\n"),
421 ctx->flags |= E2F_FLAG_EXITING;
423 fs->super->s_state |= EXT2_ERROR_FS;
424 ext2fs_mark_super_dirty(fs);
425 ext2fs_close_free(&fs);
427 exit(FSCK_UNCORRECTED);
430 #ifdef RESOURCE_TRACK
431 void init_resource_track(struct resource_track *track, io_channel channel)
433 #ifdef HAVE_GETRUSAGE
436 io_stats io_start = 0;
438 track->brk_start = sbrk(0);
439 gettimeofday(&track->time_start, 0);
440 #ifdef HAVE_GETRUSAGE
442 memset(&r, 0, sizeof(struct rusage));
444 getrusage(RUSAGE_SELF, &r);
445 track->user_start = r.ru_utime;
446 track->system_start = r.ru_stime;
448 track->user_start.tv_sec = track->user_start.tv_usec = 0;
449 track->system_start.tv_sec = track->system_start.tv_usec = 0;
451 track->bytes_read = 0;
452 track->bytes_written = 0;
453 if (channel && channel->manager && channel->manager->get_stats)
454 channel->manager->get_stats(channel, &io_start);
456 track->bytes_read = io_start->bytes_read;
457 track->bytes_written = io_start->bytes_written;
462 #define _INLINE_ __inline__
467 static _INLINE_ float timeval_subtract(struct timeval *tv1,
470 return ((tv1->tv_sec - tv2->tv_sec) +
471 ((float) (tv1->tv_usec - tv2->tv_usec)) / 1000000);
474 void print_resource_track(e2fsck_t ctx, const char *desc,
475 struct resource_track *track, io_channel channel)
477 #ifdef HAVE_GETRUSAGE
480 struct timeval time_end;
482 if ((desc && !(ctx->options & E2F_OPT_TIME2)) ||
483 (!desc && !(ctx->options & E2F_OPT_TIME)))
486 e2fsck_clear_progbar(ctx);
487 gettimeofday(&time_end, 0);
490 log_out(ctx, "%s: ", desc);
492 #define kbytes(x) (((unsigned long long)(x) + 1023) / 1024)
493 #ifdef HAVE_MALLINFO2
495 struct mallinfo2 malloc_info = mallinfo2();
497 log_out(ctx, _("Memory used: %lluk/%lluk (%lluk/%lluk), "),
498 kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
499 kbytes(malloc_info.uordblks),
500 kbytes(malloc_info.fordblks));
502 #elif defined HAVE_MALLINFO
503 /* don't use mallinfo() if over 2GB used, since it returns "int" */
504 if ((char *)sbrk(0) - (char *)track->brk_start < 2LL << 30) {
505 struct mallinfo malloc_info = mallinfo();
507 log_out(ctx, _("Memory used: %lluk/%lluk (%lluk/%lluk), "),
508 kbytes(malloc_info.arena), kbytes(malloc_info.hblkhd),
509 kbytes(malloc_info.uordblks),
510 kbytes(malloc_info.fordblks));
513 log_out(ctx, _("Memory used: %lluk, "),
514 kbytes(((char *)sbrk(0)) - ((char *)track->brk_start)));
516 #ifdef HAVE_GETRUSAGE
517 getrusage(RUSAGE_SELF, &r);
519 log_out(ctx, _("time: %5.2f/%5.2f/%5.2f\n"),
520 timeval_subtract(&time_end, &track->time_start),
521 timeval_subtract(&r.ru_utime, &track->user_start),
522 timeval_subtract(&r.ru_stime, &track->system_start));
524 log_out(ctx, _("elapsed time: %6.3f\n"),
525 timeval_subtract(&time_end, &track->time_start));
527 #define mbytes(x) (((x) + 1048575) / 1048576)
528 if (channel && channel->manager && channel->manager->get_stats) {
530 unsigned long long bytes_read = 0;
531 unsigned long long bytes_written = 0;
534 log_out(ctx, "%s: ", desc);
536 channel->manager->get_stats(channel, &delta);
538 bytes_read = delta->bytes_read - track->bytes_read;
539 bytes_written = delta->bytes_written -
540 track->bytes_written;
542 log_out(ctx, "I/O read: %lluMB, write: %lluMB, "
544 mbytes(bytes_read), mbytes(bytes_written),
545 (double)mbytes(bytes_read + bytes_written) /
546 timeval_subtract(&time_end, &track->time_start));
549 #endif /* RESOURCE_TRACK */
551 void e2fsck_read_inode(e2fsck_t ctx, unsigned long ino,
552 struct ext2_inode * inode, const char *proc)
556 retval = ext2fs_read_inode(ctx->fs, ino, inode);
558 com_err("ext2fs_read_inode", retval,
559 _("while reading inode %lu in %s"), ino, proc);
564 void e2fsck_read_inode_full(e2fsck_t ctx, unsigned long ino,
565 struct ext2_inode *inode, int bufsize,
570 retval = ext2fs_read_inode_full(ctx->fs, ino, inode, bufsize);
572 com_err("ext2fs_read_inode_full", retval,
573 _("while reading inode %lu in %s"), ino, proc);
579 #define e2fsck_get_lock_context(ctx) \
580 e2fsck_t global_ctx = ctx->global_ctx; \
585 * before we hold write lock, read lock should
588 void e2fsck_pass1_fix_lock(e2fsck_t ctx)
592 if (!ctx->fs_need_locking)
595 e2fsck_get_lock_context(ctx);
596 err = pthread_rwlock_trywrlock(&global_ctx->fs_fix_rwlock);
598 pthread_rwlock_unlock(&global_ctx->fs_fix_rwlock);
599 pthread_rwlock_wrlock(&global_ctx->fs_fix_rwlock);
602 void e2fsck_pass1_fix_unlock(e2fsck_t ctx)
604 if (!ctx->fs_need_locking)
606 e2fsck_get_lock_context(ctx);
607 /* unlock write lock */
608 pthread_rwlock_unlock(&global_ctx->fs_fix_rwlock);
609 /* get read lock again */
610 pthread_rwlock_rdlock(&global_ctx->fs_fix_rwlock);
613 void e2fsck_pass1_check_lock(e2fsck_t ctx)
615 if (!ctx->fs_need_locking)
617 e2fsck_get_lock_context(ctx);
618 pthread_rwlock_rdlock(&global_ctx->fs_fix_rwlock);
621 void e2fsck_pass1_check_unlock(e2fsck_t ctx)
623 if (!ctx->fs_need_locking)
625 e2fsck_get_lock_context(ctx);
626 pthread_rwlock_unlock(&global_ctx->fs_fix_rwlock);
629 void e2fsck_pass1_block_map_w_lock(e2fsck_t ctx)
631 if (!ctx->fs_need_locking)
633 e2fsck_get_lock_context(ctx);
634 pthread_rwlock_wrlock(&global_ctx->fs_block_map_rwlock);
637 void e2fsck_pass1_block_map_w_unlock(e2fsck_t ctx)
639 if (!ctx->fs_need_locking)
641 e2fsck_get_lock_context(ctx);
642 pthread_rwlock_unlock(&global_ctx->fs_block_map_rwlock);
645 void e2fsck_pass1_block_map_r_lock(e2fsck_t ctx)
647 if (!ctx->fs_need_locking)
649 e2fsck_get_lock_context(ctx);
650 pthread_rwlock_rdlock(&global_ctx->fs_block_map_rwlock);
653 void e2fsck_pass1_block_map_r_unlock(e2fsck_t ctx)
655 if (!ctx->fs_need_locking)
657 e2fsck_get_lock_context(ctx);
658 pthread_rwlock_unlock(&global_ctx->fs_block_map_rwlock);
661 void e2fsck_pass1_fix_lock(e2fsck_t ctx)
666 void e2fsck_pass1_fix_unlock(e2fsck_t ctx)
670 void e2fsck_pass1_check_lock(e2fsck_t ctx)
674 void e2fsck_pass1_check_unlock(e2fsck_t ctx)
678 void e2fsck_pass1_block_map_w_lock(e2fsck_t ctx)
683 void e2fsck_pass1_block_map_w_unlock(e2fsck_t ctx)
688 void e2fsck_pass1_block_map_r_lock(e2fsck_t ctx)
693 void e2fsck_pass1_block_map_r_unlock(e2fsck_t ctx)
699 void e2fsck_write_inode_full(e2fsck_t ctx, unsigned long ino,
700 struct ext2_inode * inode, int bufsize,
705 e2fsck_pass1_fix_lock(ctx);
706 retval = ext2fs_write_inode_full(ctx->fs, ino, inode, bufsize);
707 e2fsck_pass1_fix_unlock(ctx);
709 com_err("ext2fs_write_inode", retval,
710 _("while writing inode %lu in %s"), ino, proc);
715 void e2fsck_write_inode(e2fsck_t ctx, unsigned long ino,
716 struct ext2_inode * inode, const char *proc)
720 e2fsck_pass1_fix_lock(ctx);
721 retval = ext2fs_write_inode(ctx->fs, ino, inode);
722 e2fsck_pass1_fix_unlock(ctx);
724 com_err("ext2fs_write_inode", retval,
725 _("while writing inode %lu in %s"), ino, proc);
731 void mtrace_print(char *mesg)
733 FILE *malloc_get_mallstream();
734 FILE *f = malloc_get_mallstream();
737 fprintf(f, "============= %s\n", mesg);
741 blk64_t get_backup_sb(e2fsck_t ctx, ext2_filsys fs, const char *name,
744 struct ext2_super_block *sb;
745 io_channel io = NULL;
748 blk64_t superblock, ret_sb = 8193;
750 if (fs && fs->super) {
751 ret_sb = (fs->super->s_blocks_per_group +
752 fs->super->s_first_data_block);
754 ctx->superblock = ret_sb;
755 ctx->blocksize = fs->blocksize;
761 if (ctx->blocksize) {
762 ret_sb = ctx->blocksize * 8;
763 if (ctx->blocksize == 1024)
765 ctx->superblock = ret_sb;
768 ctx->superblock = ret_sb;
769 ctx->blocksize = 1024;
772 if (!name || !manager)
775 if (manager->open(name, 0, &io) != 0)
778 if (ext2fs_get_mem(SUPERBLOCK_SIZE, &buf))
780 sb = (struct ext2_super_block *) buf;
782 for (blocksize = EXT2_MIN_BLOCK_SIZE;
783 blocksize <= EXT2_MAX_BLOCK_SIZE ; blocksize *= 2) {
784 superblock = blocksize*8;
785 if (blocksize == 1024)
787 io_channel_set_blksize(io, blocksize);
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;
808 io_channel_close(io);
810 ext2fs_free_mem(&buf);
815 * Given a mode, return the ext2 file type
817 int ext2_file_type(unsigned int mode)
819 if (LINUX_S_ISREG(mode))
820 return EXT2_FT_REG_FILE;
822 if (LINUX_S_ISDIR(mode))
825 if (LINUX_S_ISCHR(mode))
826 return EXT2_FT_CHRDEV;
828 if (LINUX_S_ISBLK(mode))
829 return EXT2_FT_BLKDEV;
831 if (LINUX_S_ISLNK(mode))
832 return EXT2_FT_SYMLINK;
834 if (LINUX_S_ISFIFO(mode))
837 if (LINUX_S_ISSOCK(mode))
844 * Check to see if a filesystem is in /proc/filesystems.
845 * Returns 1 if found, 0 if not
847 int fs_proc_check(const char *fs_name)
850 char buf[80], *cp, *t;
852 f = fopen("/proc/filesystems", "r");
856 if (!fgets(buf, sizeof(buf), f))
860 while (*cp && !isspace(*cp))
863 while (*cp && isspace(*cp))
865 if ((t = strchr(cp, '\n')) != NULL)
867 if ((t = strchr(cp, '\t')) != NULL)
869 if ((t = strchr(cp, ' ')) != NULL)
871 if (!strcmp(fs_name, cp)) {
881 * Check to see if a filesystem is available as a module
882 * Returns 1 if found, 0 if not
884 int check_for_modules(const char *fs_name)
889 char buf[1024], *cp, *t;
894 snprintf(buf, sizeof(buf), "/lib/modules/%s/modules.dep", uts.release);
900 if (!fgets(buf, sizeof(buf), f))
902 if ((cp = strchr(buf, ':')) != NULL)
906 if ((cp = strrchr(buf, '/')) != NULL)
913 if (!strcmp(t, ".ko"))
916 if (!strcmp(cp, fs_name)) {
922 #endif /* __linux__ */
927 * Helper function that does the right thing if write returns a
928 * partial write, or an EAGAIN/EINTR error.
930 int write_all(int fd, char *buf, size_t count)
936 ret = write(fd, buf, count);
938 if ((errno == EAGAIN) || (errno == EINTR))
949 void dump_mmp_msg(struct mmp_struct *mmp, const char *fmt, ...)
954 printf("MMP check failed: ");
960 time_t t = mmp->mmp_time;
962 printf("MMP_block:\n");
963 printf(" mmp_magic: 0x%x\n", mmp->mmp_magic);
964 printf(" mmp_check_interval: %d\n",
965 mmp->mmp_check_interval);
966 printf(" mmp_sequence: %08x\n", mmp->mmp_seq);
967 printf(" mmp_update_date: %s", ctime(&t));
968 printf(" mmp_update_time: %lld\n",
969 (long long) mmp->mmp_time);
970 printf(" mmp_node_name: %.*s\n",
971 EXT2_LEN_STR(mmp->mmp_nodename));
972 printf(" mmp_device_name: %.*s\n",
973 EXT2_LEN_STR(mmp->mmp_bdevname));
977 errcode_t e2fsck_mmp_update(ext2_filsys fs)
981 retval = ext2fs_mmp_update(fs);
982 if (retval == EXT2_ET_MMP_CHANGE_ABORT)
983 dump_mmp_msg(fs->mmp_cmp,
984 _("UNEXPECTED INCONSISTENCY: the filesystem is "
985 "being modified while fsck is running.\n"));
990 void e2fsck_set_bitmap_type(ext2_filsys fs, unsigned int default_type,
991 const char *profile_name, unsigned int *old_type)
994 e2fsck_t ctx = (e2fsck_t) fs->priv_data;
997 *old_type = fs->default_bitmap_type;
998 profile_get_uint(ctx->profile, "bitmaps", profile_name, 0,
999 default_type, &type);
1000 profile_get_uint(ctx->profile, "bitmaps", "all", 0, type, &type);
1001 fs->default_bitmap_type = type ? type : default_type;
1004 errcode_t e2fsck_allocate_inode_bitmap(ext2_filsys fs, const char *descr,
1007 ext2fs_inode_bitmap *ret)
1010 unsigned int save_type;
1012 e2fsck_set_bitmap_type(fs, deftype, name, &save_type);
1013 retval = ext2fs_allocate_inode_bitmap(fs, descr, ret);
1014 fs->default_bitmap_type = save_type;
1018 errcode_t e2fsck_allocate_block_bitmap(ext2_filsys fs, const char *descr,
1021 ext2fs_block_bitmap *ret)
1024 unsigned int save_type;
1026 e2fsck_set_bitmap_type(fs, deftype, name, &save_type);
1027 retval = ext2fs_allocate_block_bitmap(fs, descr, ret);
1028 fs->default_bitmap_type = save_type;
1032 errcode_t e2fsck_allocate_subcluster_bitmap(ext2_filsys fs, const char *descr,
1035 ext2fs_block_bitmap *ret)
1038 unsigned int save_type;
1040 e2fsck_set_bitmap_type(fs, deftype, name, &save_type);
1041 retval = ext2fs_allocate_subcluster_bitmap(fs, descr, ret);
1042 fs->default_bitmap_type = save_type;
1046 /* Return memory size in bytes */
1047 unsigned long long get_memory_size(void)
1049 #if defined(_SC_PHYS_PAGES)
1050 # if defined(_SC_PAGESIZE)
1051 return (unsigned long long)sysconf(_SC_PHYS_PAGES) *
1052 (unsigned long long)sysconf(_SC_PAGESIZE);
1053 # elif defined(_SC_PAGE_SIZE)
1054 return (unsigned long long)sysconf(_SC_PHYS_PAGES) *
1055 (unsigned long long)sysconf(_SC_PAGE_SIZE);
1057 #elif defined(CTL_HW)
1058 # if (defined(HW_MEMSIZE) || defined(HW_PHYSMEM64))
1059 # define CTL_HW_INT64
1060 # elif (defined(HW_PHYSMEM) || defined(HW_REALMEM))
1061 # define CTL_HW_UINT
1066 # if defined(HW_MEMSIZE)
1067 mib[1] = HW_MEMSIZE;
1068 # elif defined(HW_PHYSMEM64)
1069 mib[1] = HW_PHYSMEM64;
1070 # elif defined(HW_REALMEM)
1071 mib[1] = HW_REALMEM;
1072 # elif defined(HW_PYSMEM)
1073 mib[1] = HW_PHYSMEM;
1075 # if defined(CTL_HW_INT64)
1076 unsigned long long size = 0;
1077 # elif defined(CTL_HW_UINT)
1078 unsigned int size = 0;
1082 # warning "Don't know how to detect memory on your platform?"