archrelease: copy trunk to staging-x86_64
[arch-packages.git] / e2fsprogs / trunk / 0001-mke2fs-fix-creating-a-file-system-image-w-o-a-pre-existing-file.patch
blobe2db927b7beff06cc44bee385b12c23236cec27d
1 commit 53464654bd33e58e3fff079f34261b823d839f3b
2 Author: Theodore Ts'o <tytso@mit.edu>
3 Date: Mon Aug 2 21:08:01 2021 -0400
5 mke2fs: fix creating a file system image w/o a pre-existing file
7 The mke2fs program should allow creating a file system image when an
8 explicit file system size is specified, even if the file doesn't yet
9 exist. By deferring the call to check_plausible() in commit
10 942b00cb9d2f ("mke2fs: do not warn about a pre-existing partition
11 table when using a non-zero offset") this behaviour was broken.
13 Fix this regression by explicitly creating the file if the file system
14 size is specified.
16 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
18 diff --git a/misc/mke2fs.c b/misc/mke2fs.c
19 index 306064df..31e8de1a 100644
20 --- a/misc/mke2fs.c
21 +++ b/misc/mke2fs.c
22 @@ -1986,6 +1986,25 @@ profile_error:
23 retval = ext2fs_get_device_size2(device_name,
24 EXT2_BLOCK_SIZE(&fs_param),
25 &dev_size);
26 + if (retval == ENOENT) {
27 + int fd;
29 + if (!explicit_fssize) {
30 + fprintf(stderr,
31 + _("The file %s does not exist and no "
32 + "size was specified.\n"), device_name);
33 + exit(1);
34 + }
35 + fd = ext2fs_open_file(device_name,
36 + O_CREAT | O_WRONLY, 0666);
37 + if (fd < 0) {
38 + retval = errno;
39 + } else {
40 + dev_size = 0;
41 + retval = 0;
42 + printf(_("Creating regular file %s\n"), device_name);
43 + }
44 + }
45 if (retval && (retval != EXT2_ET_UNIMPLEMENTED)) {
46 com_err(program_name, retval, "%s",
47 _("while trying to determine filesystem size"));