aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTheodore Ts'o <tytso@mit.edu>2021-08-02 21:08:01 -0400
committerTheodore Ts'o <tytso@mit.edu>2021-08-02 21:22:41 -0400
commit53464654bd33e58e3fff079f34261b823d839f3b (patch)
treeafdbd8cbbba865d70fc16defeb4e5d877ec2cdf0
parentea97af65c5194137cec7bd770b79cd601d2a92a0 (diff)
downloade2fsprogs-53464654bd33e58e3fff079f34261b823d839f3b.tar.gz
mke2fs: fix creating a file system image w/o a pre-existing file
The mke2fs program should allow creating a file system image when an explicit file system size is specified, even if the file doesn't yet exist. By deferring the call to check_plausible() in commit 942b00cb9d2f ("mke2fs: do not warn about a pre-existing partition table when using a non-zero offset") this behaviour was broken. Fix this regression by explicitly creating the file if the file system size is specified. Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rw-r--r--misc/mke2fs.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
index 306064df6..31e8de1ac 100644
--- a/misc/mke2fs.c
+++ b/misc/mke2fs.c
@@ -1986,6 +1986,25 @@ profile_error:
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;
+ 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"));