]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
mkfs.cramfs: Consider -i only once
authorTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 22 Apr 2026 19:16:19 +0000 (21:16 +0200)
committerTobias Stoeckmann <tobias@stoeckmann.org>
Wed, 22 Apr 2026 19:38:20 +0000 (21:38 +0200)
If multiple files are specified through -i, all sizes are added to
estimated filesystem size, yet only the last given file will be
added.

Increase fslen_ub only once.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
disk-utils/mkfs.cramfs.c

index f99e8d995cd85ed1f67238f0f2cb0380ce086aad..244cfba16eb8ef3971bc8413e14bb93ebd4e353e 100644 (file)
@@ -761,10 +761,6 @@ int main(int argc, char **argv)
                        break;
                case 'i':
                        opt_image = optarg;
-                       if (lstat(opt_image, &st) < 0)
-                               err(MKFS_EX_USAGE, _("stat of %s failed"), opt_image);
-                       image_length = st.st_size; /* may be padded later */
-                       fslen_ub += (image_length + 3); /* 3 is for padding */
                        break;
                case 'l':
                        lockmode = "1";
@@ -803,6 +799,12 @@ int main(int argc, char **argv)
        dirname = argv[optind];
        outfile = argv[optind + 1];
 
+       if (opt_image != NULL) {
+               if (lstat(opt_image, &st) < 0)
+                       err(MKFS_EX_USAGE, _("stat of %s failed"), opt_image);
+               image_length = st.st_size; /* may be padded later */
+               fslen_ub += (image_length + 3); /* 3 is for padding */
+       }
        fslen_ub += opt_pad;
 
        if (blksize == 0)