Whamcloud - gitweb
Merge branch 'maint' into next
[tools/e2fsprogs.git] / misc / mke2fs.c
index 74df434..c1cbcaa 100644 (file)
@@ -308,6 +308,27 @@ _("Warning: the backup superblock/group descriptors at block %u contain\n"
        ext2fs_badblocks_list_iterate_end(bb_iter);
 }
 
+static void write_reserved_inodes(ext2_filsys fs)
+{
+       errcode_t       retval;
+       ext2_ino_t      ino;
+       struct ext2_inode *inode;
+
+       retval = ext2fs_get_mem(EXT2_INODE_SIZE(fs->super), &inode);
+       if (retval) {
+               com_err("inode_init", retval,
+                       "while allocating memory");
+               exit(1);
+       }
+       bzero(inode, EXT2_INODE_SIZE(fs->super));
+
+       for (ino = 1; ino < EXT2_FIRST_INO(fs->super); ino++)
+               ext2fs_write_inode_full(fs, ino, inode,
+                                       EXT2_INODE_SIZE(fs->super));
+
+       ext2fs_free_mem(&inode);
+}
+
 static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed)
 {
        errcode_t       retval;
@@ -353,6 +374,12 @@ static void write_inode_tables(ext2_filsys fs, int lazy_flag, int itable_zeroed)
        ext2fs_zero_blocks2(0, 0, 0, 0, 0);
        ext2fs_numeric_progress_close(fs, &progress,
                                      _("done                            \n"));
+
+       /* Reserved inodes must always have correct checksums */
+       if (fs->super->s_creator_os == EXT2_OS_LINUX &&
+           fs->super->s_feature_ro_compat &
+           EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)
+               write_reserved_inodes(fs);
 }
 
 static void create_root_dir(ext2_filsys fs)
@@ -630,6 +657,23 @@ static void show_stats(ext2_filsys fs)
 }
 
 /*
+ * Returns true if making a file system for the Hurd, else 0
+ */
+static int for_hurd(const char *os)
+{
+       if (!os) {
+#ifdef __GNU__
+               return 1;
+#else
+               return 0;
+#endif
+       }
+       if (isdigit(*os))
+               return (atoi(os) == EXT2_OS_HURD);
+       return (strcasecmp(os, "GNU") == 0 || strcasecmp(os, "hurd") == 0);
+}
+
+/*
  * Set the S_CREATOR_OS field.  Return true if OS is known,
  * otherwise, 0.
  */
@@ -897,7 +941,7 @@ static __u32 ok_features[3] = {
 #ifdef CONFIG_QUOTA
                EXT4_FEATURE_RO_COMPAT_QUOTA|
 #endif
-               0
+               EXT4_FEATURE_RO_COMPAT_METADATA_CSUM
 };
 
 
@@ -1026,15 +1070,11 @@ static char **parse_fs_type(const char *fs_type,
        const char      *size_type;
        struct str_list list;
        unsigned long long meg;
-       int             is_hurd = 0;
+       int             is_hurd = for_hurd(creator_os);
 
        if (init_list(&list))
                return 0;
 
-       if (creator_os && (!strcasecmp(creator_os, "GNU") ||
-                          !strcasecmp(creator_os, "hurd")))
-               is_hurd = 1;
-
        if (fs_type)
                ext_type = fs_type;
        else if (is_hurd)
@@ -1722,10 +1762,40 @@ profile_error:
                tmp = get_string_from_profile(fs_types, "default_features",
                                              "");
        }
+       /* Mask off features which aren't supported by the Hurd */
+       if (for_hurd(creator_os)) {
+               fs_param.s_feature_incompat &= ~EXT2_FEATURE_INCOMPAT_FILETYPE;
+               fs_param.s_feature_ro_compat &=
+                       ~(EXT4_FEATURE_RO_COMPAT_HUGE_FILE |
+                         EXT4_FEATURE_RO_COMPAT_METADATA_CSUM);
+       }
        edit_feature(fs_features ? fs_features : tmp,
                     &fs_param.s_feature_compat);
        if (tmp)
                free(tmp);
+       /*
+        * If the user specified features incompatible with the Hurd, complain
+        */
+       if (for_hurd(creator_os)) {
+               if (fs_param.s_feature_incompat &
+                   EXT2_FEATURE_INCOMPAT_FILETYPE) {
+                       fprintf(stderr, _("The HURD does not support the "
+                                         "filetype feature.\n"));
+                       exit(1);
+               }
+               if (fs_param.s_feature_ro_compat &
+                   EXT4_FEATURE_RO_COMPAT_HUGE_FILE) {
+                       fprintf(stderr, _("The HURD does not support the "
+                                         "huge_file feature.\n"));
+                       exit(1);
+               }
+               if (fs_param.s_feature_ro_compat &
+                   EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) {
+                       fprintf(stderr, _("The HURD does not support the "
+                                         "metadata_csum feature.\n"));
+                       exit(1);
+               }
+       }
 
        /* Get the hardware sector sizes, if available */
        retval = ext2fs_get_device_sectsize(device_name, &lsector_size);
@@ -1972,6 +2042,13 @@ profile_error:
        if (extended_opts)
                parse_extended_opts(&fs_param, extended_opts);
 
+       /* Don't allow user to set both metadata_csum and uninit_bg bits. */
+       if ((fs_param.s_feature_ro_compat &
+            EXT4_FEATURE_RO_COMPAT_METADATA_CSUM) &&
+           (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_GDT_CSUM))
+               fs_param.s_feature_ro_compat &=
+                               ~EXT4_FEATURE_RO_COMPAT_GDT_CSUM;
+
        /* Can't support bigalloc feature without extents feature */
        if ((fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_BIGALLOC) &&
            !(fs_param.s_feature_incompat & EXT3_FEATURE_INCOMPAT_EXTENTS)) {
@@ -2125,7 +2202,8 @@ static int should_do_undo(const char *name)
        int csum_flag, force_undo;
 
        csum_flag = EXT2_HAS_RO_COMPAT_FEATURE(&fs_param,
-                                              EXT4_FEATURE_RO_COMPAT_GDT_CSUM);
+                               EXT4_FEATURE_RO_COMPAT_GDT_CSUM |
+                               EXT4_FEATURE_RO_COMPAT_METADATA_CSUM);
        force_undo = get_int_from_profile(fs_types, "force_undo", 0);
        if (!force_undo && (!csum_flag || !lazy_itable_init))
                return 0;
@@ -2383,6 +2461,26 @@ int main (int argc, char *argv[])
                com_err(device_name, retval, _("while setting up superblock"));
                exit(1);
        }
+       fs->progress_ops = &ext2fs_numeric_progress_ops;
+
+       /* Check the user's mkfs options for metadata checksumming */
+       if (!quiet &&
+           EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+                                      EXT4_FEATURE_RO_COMPAT_METADATA_CSUM)) {
+               if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
+                               EXT3_FEATURE_INCOMPAT_EXTENTS))
+                       printf(_("Extents are not enabled.  The file extent "
+                                "tree can be checksummed, whereas block maps "
+                                "cannot.  Not enabling extents reduces the "
+                                "coverage of metadata checksumming.  "
+                                "Pass -O extents to rectify.\n"));
+               if (!EXT2_HAS_INCOMPAT_FEATURE(fs->super,
+                               EXT4_FEATURE_INCOMPAT_64BIT))
+                       printf(_("64-bit filesystem support is not "
+                                "enabled.  The larger fields afforded by "
+                                "this feature enable full-strength "
+                                "checksumming.  Pass -O 64bit to rectify.\n"));
+       }
 
        /* Calculate journal blocks */
        if (!journal_device && ((journal_size) ||
@@ -2414,6 +2512,7 @@ int main (int argc, char *argv[])
            (fs_param.s_feature_ro_compat &
             (EXT4_FEATURE_RO_COMPAT_HUGE_FILE|EXT4_FEATURE_RO_COMPAT_GDT_CSUM|
              EXT4_FEATURE_RO_COMPAT_DIR_NLINK|
+             EXT4_FEATURE_RO_COMPAT_METADATA_CSUM|
              EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)))
                fs->super->s_kbytes_written = 1;
 
@@ -2434,6 +2533,7 @@ int main (int argc, char *argv[])
                }
        } else
                uuid_generate(fs->super->s_uuid);
+       ext2fs_init_csum_seed(fs);
 
        /*
         * Initialize the directory index variables
@@ -2510,6 +2610,10 @@ int main (int argc, char *argv[])
                        sizeof(fs->super->s_last_mounted));
        }
 
+       if (EXT2_HAS_RO_COMPAT_FEATURE(fs->super,
+                                      EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
+               fs->super->s_checksum_type = EXT2_CRC32C_CHKSUM;
+
        if (!quiet || noaction)
                show_stats(fs);
 
@@ -2556,8 +2660,7 @@ int main (int argc, char *argv[])
                 * inodes as unused; we want e2fsck to consider all
                 * inodes as potentially containing recoverable data.
                 */
-               if (fs->super->s_feature_ro_compat &
-                   EXT4_FEATURE_RO_COMPAT_GDT_CSUM) {
+               if (ext2fs_has_group_desc_csum(fs)) {
                        for (i = 0; i < fs->group_desc_count; i++)
                                ext2fs_bg_itable_unused_set(fs, i, 0);
                }