]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blobdiff - misc/mke2fs.c
Merge branch 'maint' into next
[thirdparty/e2fsprogs.git] / misc / mke2fs.c
index b157006ae71f23fb4a1b7ece15c42431acefb08f..d585a9e22019950da5924f2c27406569aabc7aba 100644 (file)
@@ -113,6 +113,9 @@ char **fs_types;
 const char *src_root_dir;  /* Copy files from the specified directory */
 static char *undo_file;
 
+static int android_sparse_file; /* -E android_sparse */
+static char *android_sparse_params;
+
 static profile_t       profile;
 
 static int sys_page_size = 4096;
@@ -553,7 +556,7 @@ static void zap_sector(ext2_filsys fs, int sect, int nsect)
        int retval;
        unsigned int *magic;
 
-       buf = malloc(512*nsect);
+       buf = calloc(512, nsect);
        if (!buf) {
                printf(_("Out of memory erasing sectors %d-%d\n"),
                       sect, sect + nsect - 1);
@@ -1026,6 +1029,8 @@ static void parse_extended_opts(struct ext2_super_block *param,
                                badopt = token;
                                continue;
                        }
+               } else if (!strcmp(token, "android_sparse")) {
+                       android_sparse_file = 1;
                } else {
                        r_usage++;
                        badopt = token;
@@ -1077,6 +1082,7 @@ static __u32 ok_features[3] = {
                EXT3_FEATURE_INCOMPAT_JOURNAL_DEV|
                EXT2_FEATURE_INCOMPAT_META_BG|
                EXT4_FEATURE_INCOMPAT_FLEX_BG|
+               EXT4_FEATURE_INCOMPAT_EA_INODE|
                EXT4_FEATURE_INCOMPAT_MMP |
                EXT4_FEATURE_INCOMPAT_64BIT|
                EXT4_FEATURE_INCOMPAT_INLINE_DATA|
@@ -1986,6 +1992,7 @@ profile_error:
                ext2fs_clear_feature_filetype(&fs_param);
                ext2fs_clear_feature_huge_file(&fs_param);
                ext2fs_clear_feature_metadata_csum(&fs_param);
+               ext2fs_clear_feature_ea_inode(&fs_param);
        }
        edit_feature(fs_features ? fs_features : tmp,
                     &fs_param.s_feature_compat);
@@ -2011,6 +2018,11 @@ profile_error:
                                                "metadata_csum feature.\n"));
                        exit(1);
                }
+               if (ext2fs_has_feature_ea_inode(&fs_param)) {
+                       fprintf(stderr, "%s", _("The HURD does not support the "
+                                               "ea_inode feature.\n"));
+                       exit(1);
+               }
        }
 
        /* Get the hardware sector sizes, if available */
@@ -2320,6 +2332,26 @@ profile_error:
                        (unsigned long long) fs_blocks_count);
        }
 
+       if (quotatype_bits & QUOTA_PRJ_BIT)
+               ext2fs_set_feature_project(&fs_param);
+
+       if (ext2fs_has_feature_project(&fs_param)) {
+               quotatype_bits |= QUOTA_PRJ_BIT;
+               if (inode_size == EXT2_GOOD_OLD_INODE_SIZE) {
+                       com_err(program_name, 0,
+                               _("%d byte inodes are too small for "
+                                 "project quota"),
+                               inode_size);
+                       exit(1);
+               }
+               if (inode_size == 0) {
+                       inode_size = get_int_from_profile(fs_types,
+                                                         "inode_size", 0);
+                       if (inode_size <= EXT2_GOOD_OLD_INODE_SIZE*2)
+                               inode_size = EXT2_GOOD_OLD_INODE_SIZE*2;
+               }
+       }
+
        /* Don't allow user to set both metadata_csum and uninit_bg bits. */
        if (ext2fs_has_feature_metadata_csum(&fs_param) &&
            ext2fs_has_feature_gdt_csum(&fs_param))
@@ -2420,19 +2452,6 @@ profile_error:
                exit(1);
        }
 
-       /*
-        * If inode size is 128 and project quota is enabled, we need
-        * to notify users that project ID will never be useful.
-        */
-       if (ext2fs_has_feature_project(&fs_param) &&
-           fs_param.s_inode_size == EXT2_GOOD_OLD_INODE_SIZE) {
-               com_err(program_name, 0,
-                       _("%d byte inodes are too small for project quota; "
-                         "specify larger size"),
-                       fs_param.s_inode_size);
-               exit(1);
-       }
-
        /* Make sure number of inodes specified will fit in 32 bits */
        if (num_inodes == 0) {
                unsigned long long n;
@@ -2828,7 +2847,21 @@ int main (int argc, char *argv[])
         */
        if (!quiet)
                flags |= EXT2_FLAG_PRINT_PROGRESS;
-       retval = ext2fs_initialize(device_name, flags, &fs_param, io_ptr, &fs);
+       if (android_sparse_file) {
+               android_sparse_params = malloc(PATH_MAX + 32);
+               if (!android_sparse_params) {
+                       com_err(program_name, ENOMEM, "%s",
+                               _("in malloc for android_sparse_params"));
+                       exit(1);
+               }
+               snprintf(android_sparse_params, PATH_MAX + 32, "%s:%u:%u",
+                        device_name, fs_param.s_blocks_count,
+                        1024 << fs_param.s_log_block_size);
+               retval = ext2fs_initialize(android_sparse_params, flags,
+                                          &fs_param, sparse_io_manager, &fs);
+       } else
+               retval = ext2fs_initialize(device_name, flags, &fs_param,
+                                          io_ptr, &fs);
        if (retval) {
                com_err(device_name, retval, "%s",
                        _("while setting up superblock"));
@@ -2915,7 +2948,14 @@ int main (int argc, char *argv[])
         * Parse or generate a UUID for the filesystem
         */
        if (fs_uuid) {
-               if (uuid_parse(fs_uuid, fs->super->s_uuid) !=0) {
+               if ((strcasecmp(fs_uuid, "null") == 0) ||
+                   (strcasecmp(fs_uuid, "clear") == 0)) {
+                       uuid_clear(fs->super->s_uuid);
+               } else if (strcasecmp(fs_uuid, "time") == 0) {
+                       uuid_generate_time(fs->super->s_uuid);
+               } else if (strcasecmp(fs_uuid, "random") == 0) {
+                       uuid_generate(fs->super->s_uuid);
+               } else if (uuid_parse(fs_uuid, fs->super->s_uuid) != 0) {
                        com_err(device_name, 0, "could not parse UUID: %s\n",
                                fs_uuid);
                        exit(1);
@@ -3197,8 +3237,6 @@ no_journal:
 
        if (ext2fs_has_feature_bigalloc(&fs_param))
                fix_cluster_bg_counts(fs);
-       if (ext2fs_has_feature_project(&fs_param))
-               quotatype_bits |= QUOTA_PRJ_BIT;
        if (ext2fs_has_feature_quota(&fs_param))
                create_quota_inodes(fs);