Whamcloud - gitweb
misc: fix compile warnings on master branch
[tools/e2fsprogs.git] / misc / mke2fs.c
index 3c71b80..dd4d213 100644 (file)
@@ -16,7 +16,7 @@
  * enforced (but it's not much fun on a character device :-).
  */
 
-#define _XOPEN_SOURCE 600 /* for inclusion of PATH_MAX in Solaris */
+#define _XOPEN_SOURCE 600 /* for inclusion of PATH_MAX */
 
 #include "config.h"
 #include <stdio.h>
@@ -55,7 +55,7 @@ extern int optind;
 #include "profile.h"
 #include "prof_err.h"
 #include "../version.h"
-#include "quota/mkquota.h"
+#include "quota/quotaio.h"
 #include "mke2fs.h"
 #include "create_inode.h"
 
@@ -96,6 +96,8 @@ static __u32  fs_stride;
 static int     quotatype = -1;  /* Initialize both user and group quotas by default */
 static __u64   offset;
 static blk64_t journal_location = ~0LL;
+static int     proceed_delay = -1;
+static blk64_t dev_size;
 
 static struct ext2_super_block fs_param;
 static char *fs_uuid = NULL;
@@ -110,7 +112,6 @@ const char *root_dir;  /* Copy files from the specified directory */
 static profile_t       profile;
 
 static int sys_page_size = 4096;
-static int linux_version_code = 0;
 
 static void usage(void)
 {
@@ -338,13 +339,11 @@ static void write_reserved_inodes(ext2_filsys fs)
        ext2_ino_t      ino;
        struct ext2_inode *inode;
 
-       retval = ext2fs_get_mem(EXT2_INODE_SIZE(fs->super), &inode);
+       retval = ext2fs_get_memzero(EXT2_INODE_SIZE(fs->super), &inode);
        if (retval) {
-               com_err("inode_init", retval,
-                       "while allocating memory");
+               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,
@@ -383,6 +382,7 @@ static errcode_t packed_allocate_tables(ext2_filsys fs)
                ext2fs_block_alloc_stats_range(fs, goal,
                                               fs->inode_blocks_per_group, +1);
                ext2fs_inode_table_loc_set(fs, i, goal);
+               ext2fs_group_desc_csum_set(fs, i);
        }
        return 0;
 }
@@ -641,6 +641,14 @@ static void show_stats(ext2_filsys fs)
        dgrp_t                  i;
        int                     need, col_left;
 
+       if (!verbose) {
+               printf(_("Creating filesystem with %llu %dk blocks and "
+                        "%u inodes\n"),
+                      ext2fs_blocks_count(s), fs->blocksize >> 10,
+                      s->s_inodes_count);
+               goto skip_details;
+       }
+
        if (ext2fs_blocks_count(&fs_param) != ext2fs_blocks_count(s))
                fprintf(stderr, _("warning: %llu blocks unused.\n\n"),
                       ext2fs_blocks_count(&fs_param) - ext2fs_blocks_count(s));
@@ -689,11 +697,14 @@ static void show_stats(ext2_filsys fs)
                       s->s_blocks_per_group, s->s_clusters_per_group);
        printf(_("%u inodes per group\n"), s->s_inodes_per_group);
 
+skip_details:
        if (fs->group_desc_count == 1) {
                printf("\n");
                return;
        }
 
+       if (!e2p_is_null_uuid(s->s_uuid))
+               printf(_("Filesystem UUID: %s\n"), e2p_uuid2str(s->s_uuid));
        printf("%s", _("Superblock backups stored on blocks: "));
        group_block = s->s_first_data_block;
        col_left = 0;
@@ -1058,7 +1069,8 @@ static __u32 ok_features[3] = {
                EXT2_FEATURE_INCOMPAT_META_BG|
                EXT4_FEATURE_INCOMPAT_FLEX_BG|
                EXT4_FEATURE_INCOMPAT_MMP |
-               EXT4_FEATURE_INCOMPAT_64BIT,
+               EXT4_FEATURE_INCOMPAT_64BIT|
+               EXT4_FEATURE_INCOMPAT_INLINE_DATA,
        /* R/O compat */
        EXT2_FEATURE_RO_COMPAT_LARGE_FILE|
                EXT4_FEATURE_RO_COMPAT_HUGE_FILE|
@@ -1411,7 +1423,7 @@ out:
 
 static void PRS(int argc, char *argv[])
 {
-       int             b, c;
+       int             b, c, flags;
        int             cluster_size = 0;
        char            *tmp, **cpp;
        int             blocksize = 0;
@@ -1420,14 +1432,13 @@ static void PRS(int argc, char *argv[])
        unsigned long   flex_bg_size = 0;
        double          reserved_ratio = -1.0;
        int             lsector_size = 0, psector_size = 0;
-       int             show_version_only = 0;
+       int             show_version_only = 0, is_device = 0;
        unsigned long long num_inodes = 0; /* unsigned long long to catch too-large input */
        errcode_t       retval;
        char *          oldpath = getenv("PATH");
        char *          extended_opts = 0;
        char *          fs_type = 0;
        char *          usage_types = 0;
-       blk64_t         dev_size;
        /*
         * NOTE: A few words about fs_blocks_count and blocksize:
         *
@@ -1789,8 +1800,18 @@ profile_error:
        if (optind < argc)
                usage();
 
-       if (!force)
-               check_plausibility(device_name);
+       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))
+               flags |= CHECK_FS_EXIST;
+       if (!quiet)
+               flags |= VERBOSE_CREATE;
+       if (!check_plausibility(device_name, flags, &is_device) && !force)
+               proceed_question(proceed_delay);
+
        check_mount(device_name, force, _("filesystem"));
 
        /* Determine the size of the device (if possible) */
@@ -1832,10 +1853,10 @@ profile_error:
                                fs_blocks_count &= ~((blk64_t) ((sys_page_size /
                                             EXT2_BLOCK_SIZE(&fs_param))-1));
                }
-       } else if (!force && (fs_blocks_count > dev_size)) {
+       } else if (!force && is_device && (fs_blocks_count > dev_size)) {
                com_err(program_name, 0, "%s",
                        _("Filesystem larger than apparent device size."));
-               proceed_question();
+               proceed_question(proceed_delay);
        }
 
        if (!fs_type)
@@ -1903,20 +1924,20 @@ profile_error:
        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"));
+                       fprintf(stderr, "%s", _("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"));
+                       fprintf(stderr, "%s", _("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"));
+                       fprintf(stderr, "%s", _("The HURD does not support the "
+                                               "metadata_csum feature.\n"));
                        exit(1);
                }
        }
@@ -1982,6 +2003,9 @@ profile_error:
         * 32-bit vs 64-bit block number support.
         */
        if ((fs_blocks_count > MAX_32_NUM) &&
+           (fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT))
+               fs_param.s_feature_compat &= ~EXT2_FEATURE_COMPAT_RESIZE_INODE;
+       if ((fs_blocks_count > MAX_32_NUM) &&
            !(fs_param.s_feature_incompat & EXT4_FEATURE_INCOMPAT_64BIT) &&
            get_bool_from_profile(fs_types, "auto_64-bit_support", 0)) {
                fs_param.s_feature_incompat |= EXT4_FEATURE_INCOMPAT_64BIT;
@@ -2136,7 +2160,7 @@ profile_error:
                        com_err(program_name, 0,
                                _("%d-byte blocks too big for system (max %d)"),
                                blocksize, sys_page_size);
-                       proceed_question();
+                       proceed_question(proceed_delay);
                }
                fprintf(stderr, _("Warning: %d-byte blocks too big for system "
                                  "(max %d), forced to continue\n"),
@@ -2214,14 +2238,8 @@ profile_error:
                                  "See https://ext4.wiki.kernel.org/"
                                  "index.php/Bigalloc for more information\n\n"));
 
-       if (!quiet &&
-           (fs_param.s_feature_ro_compat & EXT4_FEATURE_RO_COMPAT_QUOTA))
-               fprintf(stderr, "%s", _("\nWarning: the quota feature is "
-                                 "still under development\n"
-                                 "See https://ext4.wiki.kernel.org/"
-                                 "index.php/Quota for more information\n\n"));
-
-       /* Since sparse_super is the default, we would only have a problem
+       /*
+        * Since sparse_super is the default, we would only have a problem
         * here if it was explicitly disabled.
         */
        if ((fs_param.s_feature_compat & EXT2_FEATURE_COMPAT_RESIZE_INODE) &&
@@ -2280,6 +2298,19 @@ profile_error:
                fs_param.s_inode_size = inode_size;
        }
 
+       /*
+        * If inode size is 128 and inline data is enabled, we need
+        * to notify users that inline data will never be useful.
+        */
+       if ((fs_param.s_feature_incompat &
+            EXT4_FEATURE_INCOMPAT_INLINE_DATA) &&
+           fs_param.s_inode_size == EXT2_GOOD_OLD_INODE_SIZE) {
+               com_err(program_name, 0,
+                       _("inode size is %d, inline data is useless"),
+                       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;
@@ -2563,7 +2594,7 @@ int main (int argc, char *argv[])
        errcode_t       retval = 0;
        ext2_filsys     fs;
        badblocks_list  bb_list = 0;
-       unsigned int    journal_blocks;
+       unsigned int    journal_blocks = 0;
        unsigned int    i, checkinterval;
        int             max_mnt_count;
        int             val, hash_alg;
@@ -2628,17 +2659,19 @@ int main (int argc, char *argv[])
                                       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 "
+                       printf("%s",
+                              _("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"));
+                       printf("%s",
+                              _("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 */
@@ -2648,7 +2681,7 @@ int main (int argc, char *argv[])
                journal_blocks = figure_journal_size(journal_size, fs);
 
        /* Can't undo discard ... */
-       if (!noaction && discard && (io_ptr != undo_io_manager)) {
+       if (!noaction && discard && dev_size && (io_ptr != undo_io_manager)) {
                retval = mke2fs_discard_device(fs);
                if (!retval && io_channel_discard_zeroes_data(fs->io)) {
                        if (verbose)
@@ -2881,8 +2914,9 @@ int main (int argc, char *argv[])
        if (journal_device) {
                ext2_filsys     jfs;
 
-               if (!force)
-                       check_plausibility(journal_device);
+               if (!check_plausibility(journal_device, CHECK_BLOCK_DEV,
+                                       NULL) && !force)
+                       proceed_question(proceed_delay);
                check_mount(journal_device, force, _("journal"));
 
                retval = ext2fs_open(journal_device, EXT2_FLAG_RW|
@@ -2971,25 +3005,13 @@ no_journal:
                if (!quiet)
                        printf("%s", _("Copying files into the device: "));
 
-               /*
-                * Allocate memory for the hardlinks, we don't need free()
-                * since the lifespan will be over after the fs populated.
-                */
-               if ((hdlinks.hdl = (struct hdlink_s *)
-                               malloc(hdlink_cnt * sizeof(struct hdlink_s))) == NULL) {
-                       fprintf(stderr, "%s", _("\nNot enough memory\n"));
-                       retval = ext2fs_close(fs);
-                       return retval;
-               }
-
-               hdlinks.count = 0;
-               current_fs = fs;
-               root = EXT2_ROOT_INO;
-               retval = populate_fs(root, root_dir);
-               if (retval)
-                       fprintf(stderr, "%s",
-                               _("\nError while populating file system"));
-               else if (!quiet)
+               retval = populate_fs(fs, EXT2_ROOT_INO, root_dir,
+                                    EXT2_ROOT_INO);
+               if (retval) {
+                       com_err(program_name, retval, "%s",
+                               _("\nError while populating file system\n"));
+                       exit(1);
+               } else if (!quiet)
                        printf("%s", _("done\n"));
        }