Whamcloud - gitweb
mke2fs: improve the error message when a non-existent file is specified
authorTheodore Ts'o <tytso@mit.edu>
Mon, 25 Aug 2014 03:54:37 +0000 (23:54 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 25 Aug 2014 03:54:37 +0000 (23:54 -0400)
If the user does not specify the file system size, and the file does
not exist, give an error message like this:

   The file /tmp/foo.img does not exist and no size was specified.

instead of this:

    Creating regular file /tmp/foo.img
    mke2fs: Device size reported to be zero.  Invalid partition specified, or
    partition table wasn't reread after running fdisk, due to
    a modified partition being busy and in use.  You may need to reboot
    to re-read your partition table.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
misc/mke2fs.c
misc/util.c
misc/util.h

index da77e3a..550e886 100644 (file)
@@ -1796,6 +1796,8 @@ profile_error:
                flags |= CHECK_FS_EXIST;
        if (!quiet)
                flags |= VERBOSE_CREATE;
+       if (fs_blocks_count == 0)
+               flags |= NO_SIZE;
        if (!check_plausibility(device_name, flags, &is_device) && !force)
                proceed_question(proceed_delay);
 
index 1fcae1d..2898830 100644 (file)
@@ -198,6 +198,11 @@ int check_plausibility(const char *device, int flags, int *ret_is_dev)
        char *fs_label = NULL;
 
        fd = ext2fs_open_file(device, fl, 0666);
+       if ((fd < 0) && (errno == ENOENT) && (flags & NO_SIZE)) {
+               fprintf(stderr, _("The file %s does not exist and no "
+                                 "size was specified.\n"), device);
+               exit(1);
+       }
        if ((fd < 0) && (errno == ENOENT) && (flags & CREATE_FILE)) {
                fl |= O_CREAT;
                fd = ext2fs_open_file(device, fl, 0666);
index 476164b..f3827dd 100644 (file)
@@ -22,6 +22,7 @@ extern char   *journal_location_string;
 #define CREATE_FILE    0x0002
 #define CHECK_FS_EXIST 0x0004
 #define VERBOSE_CREATE 0x0008
+#define NO_SIZE                0x0010
 
 #ifndef HAVE_STRCASECMP
 extern int strcasecmp (char *s1, char *s2);