#include <strings.h>
#include <ctype.h>
#include <time.h>
-#ifdef __linux__
-#include <sys/utsname.h>
-#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
-#endif
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#else
return l;
}
-#ifdef __linux__
-static int parse_version_number(const char *s)
-{
- int major, minor, rev;
- char *endptr;
- const char *cp = s;
-
- if (!s)
- return 0;
- major = strtol(cp, &endptr, 10);
- if (cp == endptr || *endptr != '.')
- return 0;
- cp = endptr + 1;
- minor = strtol(cp, &endptr, 10);
- if (cp == endptr || *endptr != '.')
- return 0;
- cp = endptr + 1;
- rev = strtol(cp, &endptr, 10);
- if (cp == endptr)
- return 0;
- return KERNEL_VERSION(major, minor, rev);
-}
-
-static int is_before_linux_ver(unsigned int major, unsigned int minor,
- unsigned int rev)
-{
- struct utsname ut;
- static int linux_version_code = -1;
-
- if (uname(&ut)) {
- perror("uname");
- exit(1);
- }
- if (linux_version_code < 0)
- linux_version_code = parse_version_number(ut.release);
- if (linux_version_code == 0)
- return 0;
-
- return linux_version_code < (int) KERNEL_VERSION(major, minor, rev);
-}
-#else
-static int is_before_linux_ver(unsigned int major, unsigned int minor,
- unsigned int rev)
-{
- return 0;
-}
-#endif
-
/*
* Helper function for read_bb_file and test_disk
*/
else {
magic = (unsigned int *) (buf + BSD_LABEL_OFFSET);
if ((*magic == BSD_DISKMAGIC) ||
- (*magic == BSD_MAGICDISK))
+ (*magic == BSD_MAGICDISK)) {
+ free(buf);
return;
+ }
}
}
EXT4_FEATURE_INCOMPAT_FLEX_BG|
EXT4_FEATURE_INCOMPAT_EA_INODE|
EXT4_FEATURE_INCOMPAT_MMP |
+ EXT4_FEATURE_INCOMPAT_DIRDATA|
EXT4_FEATURE_INCOMPAT_64BIT|
EXT4_FEATURE_INCOMPAT_INLINE_DATA|
EXT4_FEATURE_INCOMPAT_ENCRYPT |
int use_bsize;
char *newpath;
int pathlen = sizeof(PATH_SET) + 1;
+#ifdef HAVE_BLKID_PROBE_GET_TOPOLOGY
struct device_param dev_param;
+#endif
if (oldpath)
pathlen += strlen(oldpath);
memset(&fs_param, 0, sizeof(struct ext2_super_block));
fs_param.s_rev_level = 1; /* Create revision 1 filesystems now */
- if (is_before_linux_ver(2, 2, 0))
+ if (ext2fs_is_before_linux_ver(2, 2, 0))
fs_param.s_rev_level = 0;
if (argc && *argv) {
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"));
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"));
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
* be appropriately configured.
*/
fs_types = parse_fs_type(fs_type, usage_types, &fs_param,
- fs_blocks_count ? fs_blocks_count : dev_size,
- argv[0]);
+ fs_blocks_count, argv[0]);
if (!fs_types) {
fprintf(stderr, "%s", _("Failed to parse fs types list\n"));
exit(1);
if (use_bsize == -1) {
use_bsize = sys_page_size;
- if (is_before_linux_ver(2, 6, 0) && use_bsize > 4096)
+ if (ext2fs_is_before_linux_ver(2, 6, 0) &&
+ use_bsize > 4096)
use_bsize = 4096;
}
if (lsector_size && use_bsize < lsector_size)
* We now need to do a sanity check of fs_blocks_count for
* 32-bit vs 64-bit block number support.
*/
- if ((fs_blocks_count > MAX_32_NUM) &&
- ext2fs_has_feature_64bit(&fs_param))
- ext2fs_clear_feature_resize_inode(&fs_param);
- if ((fs_blocks_count > MAX_32_NUM) &&
- !ext2fs_has_feature_64bit(&fs_param) &&
- get_bool_from_profile(fs_types, "auto_64-bit_support", 0)) {
- ext2fs_set_feature_64bit(&fs_param);
- ext2fs_clear_feature_resize_inode(&fs_param);
- }
- if ((fs_blocks_count > MAX_32_NUM) &&
- !ext2fs_has_feature_64bit(&fs_param)) {
- fprintf(stderr, _("%s: Size of device (0x%llx blocks) %s "
+ if (fs_blocks_count > MAX_32_NUM) {
+ if (!ext2fs_has_feature_64bit(&fs_param) &&
+ get_bool_from_profile(fs_types, "auto_64-bit_support", 0))
+ ext2fs_set_feature_64bit(&fs_param);
+
+ if (ext2fs_has_feature_64bit(&fs_param)) {
+ ext2fs_clear_feature_resize_inode(&fs_param);
+ } else {
+ fprintf(stderr,
+ _("%s: Size of device (0x%llx blocks) %s "
"too big to be expressed\n\t"
"in 32 bits using a blocksize of %d.\n"),
- program_name, (unsigned long long) fs_blocks_count,
- device_name, EXT2_BLOCK_SIZE(&fs_param));
- exit(1);
+ program_name,
+ (unsigned long long) fs_blocks_count,
+ device_name, EXT2_BLOCK_SIZE(&fs_param));
+ exit(1);
+ }
}
+
/*
* Guard against group descriptor count overflowing... Mostly to avoid
* strange results for absurdly large devices. This is in log2:
fs_param.s_feature_compat = 0;
fs_param.s_feature_ro_compat &=
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM;
- }
+ }
/* Check the user's mkfs options for 64bit */
- if (ext2fs_has_feature_64bit(&fs_param) &&
+ if (fs_blocks_count > MAX_32_NUM &&
!ext2fs_has_feature_extents(&fs_param)) {
- printf("%s", _("Extents MUST be enabled for a 64-bit "
- "filesystem. Pass -O extents to rectify.\n"));
+ printf("%s", _("Extents MUST be enabled for filesystems with "
+ "over 2^32 blocks. Use '-O extents' to fix.\n"));
exit(1);
}
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;
}
}
/* Metadata checksumming wasn't totally stable before 3.18. */
- if (is_before_linux_ver(3, 18, 0) &&
+ if (ext2fs_is_before_linux_ver(3, 18, 0) &&
ext2fs_has_feature_metadata_csum(&fs_param))
fprintf(stderr, _("Suggestion: Use Linux kernel >= 3.18 for "
"improved stability of the metadata and journal "
* On newer kernels we do have lazy_itable_init support. So pick the
* right default in case ext4 module is not loaded.
*/
- if (is_before_linux_ver(2, 6, 37))
+ if (ext2fs_is_before_linux_ver(2, 6, 37))
lazy_itable_init = 0;
else
lazy_itable_init = 1;
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
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;
n = ext2fs_blocks_count(&fs_param) * blocksize / inode_ratio;
if (n > MAX_32_NUM) {
- if (ext2fs_has_feature_64bit(&fs_param))
- num_inodes = MAX_32_NUM;
- else {
+ num_inodes = MAX_32_NUM;
+ if (!ext2fs_has_feature_64bit(&fs_param))
com_err(program_name, 0,
- _("too many inodes (%llu), raise "
- "inode ratio?"),
- (unsigned long long) n);
- exit(1);
- }
+ _("too many inodes (%llu), reduced to "
+ "%llu"), n, MAX_32_NUM);
}
} else if (num_inodes > MAX_32_NUM) {
com_err(program_name, 0,
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)
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;
/*
* 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;
exit(1);
}
+ if (ext2fs_has_feature_dirdata(fs->super)) {
+ if (ext2fs_has_feature_inline_data(fs->super)) {
+ printf("%s", _("The dirdata feature can not enabled "
+ "with inline data feature.\n"));
+ exit(1);
+ }
+ if (ext2fs_has_feature_casefold(fs->super)) {
+ printf("%s", _("The dirdata feature can not enabled "
+ "with casefold feature.\n"));
+ exit(1);
+ }
+ }
+
/* Calculate journal blocks */
if (!journal_device && ((journal_size) ||
ext2fs_has_feature_journal(&fs_param)))