48 lines
1.5 KiB
Diff
48 lines
1.5 KiB
Diff
commit 53464654bd33e58e3fff079f34261b823d839f3b
|
|
Author: Theodore Ts'o <tytso@mit.edu>
|
|
Date: Mon Aug 2 21:08:01 2021 -0400
|
|
|
|
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>
|
|
|
|
diff --git a/misc/mke2fs.c b/misc/mke2fs.c
|
|
index 306064df..31e8de1a 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"));
|