diff options
Diffstat (limited to 'misc/mke2fs.c')
-rw-r--r-- | misc/mke2fs.c | 111 |
1 files changed, 72 insertions, 39 deletions
diff --git a/misc/mke2fs.c b/misc/mke2fs.c index bd60d49e..ba5f179a 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -585,8 +585,10 @@ static void zap_sector(ext2_filsys fs, int sect, int nsect) else { magic = (unsigned int *) (buf + BSD_LABEL_OFFSET); if ((*magic == BSD_DISKMAGIC) || - (*magic == BSD_MAGICDISK)) + (*magic == BSD_MAGICDISK)) { + free(buf); return; + } } } @@ -1480,7 +1482,7 @@ extern const char *mke2fs_default_profile; static const char *default_files[] = { "<default>", 0 }; struct device_param { - unsigned long min_io; /* prefered minimum IO size */ + unsigned long min_io; /* preferred minimum IO size */ unsigned long opt_io; /* optimal IO size */ unsigned long alignment_offset; /* alignment offset wrt physical block size */ unsigned int dax:1; /* supports dax? */ @@ -1570,7 +1572,6 @@ static void PRS(int argc, char *argv[]) * Finally, we complain about fs_blocks_count > 2^32 on a non-64bit fs. */ blk64_t fs_blocks_count = 0; - long sysval; int s_opt = -1, r_opt = -1; char *fs_features = 0; int fs_features_size = 0; @@ -1604,9 +1605,12 @@ static void PRS(int argc, char *argv[]) #define _SC_PAGESIZE _SC_PAGE_SIZE #endif #ifdef _SC_PAGESIZE - sysval = sysconf(_SC_PAGESIZE); - if (sysval > 0) - sys_page_size = sysval; + { + long sysval = sysconf(_SC_PAGESIZE); + + if (sysval > 0) + sys_page_size = sysval; + } #endif /* _SC_PAGESIZE */ #endif /* HAVE_SYSCONF */ @@ -1922,10 +1926,10 @@ profile_error: #ifdef CONFIG_TESTIO_DEBUG if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { io_ptr = test_io_manager; - test_io_backing_manager = unix_io_manager; + test_io_backing_manager = default_io_manager; } else #endif - io_ptr = unix_io_manager; + io_ptr = default_io_manager; retval = ext2fs_open(journal_device, EXT2_FLAG_JOURNAL_DEV_OK, 0, 0, io_ptr, &jfs); @@ -1971,18 +1975,8 @@ profile_error: profile_get_integer(profile, "options", "proceed_delay", 0, 0, &proceed_delay); - /* The isatty() test is so we don't break existing scripts */ - flags = CREATE_FILE; - if (isatty(0) && isatty(1) && !offset) - flags |= CHECK_FS_EXIST; - if (!quiet) - flags |= VERBOSE_CREATE; - if (fs_blocks_count == 0) - flags |= NO_SIZE; - else + if (fs_blocks_count) explicit_fssize = 1; - if (!check_plausibility(device_name, flags, &is_device) && !force) - proceed_question(proceed_delay); check_mount(device_name, force, _("filesystem")); @@ -1994,6 +1988,26 @@ profile_error: retval = ext2fs_get_device_size2(device_name, EXT2_BLOCK_SIZE(&fs_param), &dev_size); + if (retval == ENOENT) { + int fd; + + if (!explicit_fssize) { + fprintf(stderr, + _("The file %s does not exist and no " + "size was specified.\n"), device_name); + exit(1); + } + fd = ext2fs_open_file(device_name, + O_CREAT | O_WRONLY, 0666); + if (fd < 0) { + retval = errno; + } else { + dev_size = 0; + retval = 0; + close(fd); + printf(_("Creating regular file %s\n"), device_name); + } + } if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) { com_err(program_name, retval, "%s", _("while trying to determine filesystem size")); @@ -2036,6 +2050,9 @@ profile_error: if (!usage_types) profile_get_string(profile, "devices", device_name, "usage_types", 0, &usage_types); + if (!creator_os) + profile_get_string(profile, "defaults", "creator_os", 0, + 0, &creator_os); /* * We have the file system (or device) size, so we can now @@ -2329,9 +2346,9 @@ profile_error: device_name); } else { /* setting stripe/stride to blocksize is pointless */ - if (dev_param.min_io > blocksize) + if (dev_param.min_io > (unsigned) blocksize) fs_param.s_raid_stride = dev_param.min_io / blocksize; - if (dev_param.opt_io > blocksize) { + if (dev_param.opt_io > (unsigned) blocksize) { fs_param.s_raid_stripe_width = dev_param.opt_io / blocksize; } @@ -2514,11 +2531,12 @@ profile_error: exit(1); } - if (!quiet && ext2fs_has_feature_bigalloc(&fs_param)) - fprintf(stderr, "%s", _("\nWarning: the bigalloc feature is " - "still under development\n" - "See https://ext4.wiki.kernel.org/" - "index.php/Bigalloc for more information\n\n")); + if (!quiet && ext2fs_has_feature_bigalloc(&fs_param) && + EXT2_CLUSTER_SIZE(&fs_param) > 16 * EXT2_BLOCK_SIZE(&fs_param)) + fprintf(stderr, "%s", _("\nWarning: bigalloc file systems " + "with a cluster size greater than\n" + "16 times the block size is considered " + "experimental\n")); /* * Since sparse_super is the default, we would only have a problem @@ -2591,6 +2609,17 @@ profile_error: exit(1); } + /* + * Warn the user that filesystems with 128-byte inodes will + * not work properly beyond 2038. This can be suppressed via + * a boolean in the mke2fs.conf file, and we will disable this + * warning for file systems created for the GNU Hurd. + */ + if (inode_size == EXT2_GOOD_OLD_INODE_SIZE && + get_bool_from_profile(fs_types, "warn_y2038_dates", 1)) + printf( +_("128-byte inodes cannot handle dates beyond 2038 and are deprecated\n")); + /* Make sure number of inodes specified will fit in 32 bits */ if (num_inodes == 0) { unsigned long long n; @@ -2648,6 +2677,17 @@ profile_error: free(fs_type); free(usage_types); + + /* The isatty() test is so we don't break existing scripts */ + flags = CREATE_FILE; + if (isatty(0) && isatty(1) && !offset) + flags |= CHECK_FS_EXIST; + if (!quiet) + flags |= VERBOSE_CREATE; + if (!explicit_fssize) + flags |= NO_SIZE; + if (!check_plausibility(device_name, flags, &is_device) && !force) + proceed_question(proceed_delay); } static int should_do_undo(const char *name) @@ -2656,7 +2696,7 @@ static int should_do_undo(const char *name) io_channel channel; __u16 s_magic; struct ext2_super_block super; - io_manager manager = unix_io_manager; + io_manager manager = default_io_manager; int csum_flag, force_undo; csum_flag = ext2fs_has_feature_metadata_csum(&fs_param) || @@ -2792,7 +2832,7 @@ static int mke2fs_discard_device(ext2_filsys fs) struct ext2fs_numeric_progress_struct progress; blk64_t blocks = ext2fs_blocks_count(fs->super); blk64_t count = DISCARD_STEP_MB; - blk64_t cur; + blk64_t cur = 0; int retval = 0; /* @@ -2800,10 +2840,9 @@ static int mke2fs_discard_device(ext2_filsys fs) * we do not print numeric progress resulting in failure * afterwards. */ - retval = io_channel_discard(fs->io, 0, fs->blocksize); + retval = io_channel_discard(fs->io, 0, 1); if (retval) return retval; - cur = fs->blocksize; count *= (1024 * 1024); count /= fs->blocksize; @@ -2931,12 +2970,6 @@ try_user: return 0; } -// TODO(b/141583541): stop leaks -const char *__asan_default_options() -{ - return "detect_leaks=0"; -} - int main (int argc, char *argv[]) { errcode_t retval = 0; @@ -2968,10 +3001,10 @@ int main (int argc, char *argv[]) #ifdef CONFIG_TESTIO_DEBUG if (getenv("TEST_IO_FLAGS") || getenv("TEST_IO_BLOCK")) { io_ptr = test_io_manager; - test_io_backing_manager = unix_io_manager; + test_io_backing_manager = default_io_manager; } else #endif - io_ptr = unix_io_manager; + io_ptr = default_io_manager; if (undo_file != NULL || should_do_undo(device_name)) { retval = mke2fs_setup_tdb(device_name, &io_ptr); @@ -3364,7 +3397,7 @@ int main (int argc, char *argv[]) retval = ext2fs_open(journal_device, EXT2_FLAG_RW| EXT2_FLAG_JOURNAL_DEV_OK, 0, - fs->blocksize, unix_io_manager, &jfs); + fs->blocksize, default_io_manager, &jfs); if (retval) { com_err(program_name, retval, _("while trying to open journal device %s\n"), |