]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
losetup: warn about backing file size
authorKarel Zak <kzak@redhat.com>
Tue, 12 Jun 2012 12:34:16 +0000 (14:34 +0200)
committerKarel Zak <kzak@redhat.com>
Tue, 12 Jun 2012 12:34:16 +0000 (14:34 +0200)
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=730266
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/losetup.c

index 4f44b9b14e9be745280290ab761754ab1884eaae..3c3229989b9221945585a372ae83dd391116cee7 100644 (file)
@@ -183,6 +183,26 @@ static void usage(FILE *out)
        exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
+static void warn_size(const char *filename, uint64_t size)
+{
+       struct stat st;
+
+       if (!size) {
+               if (stat(filename, &st))
+                       return;
+               size = st.st_size;
+       }
+
+       if (size < 512)
+               warnx(_("%s: warning: file smaller than 512 bytes, the loop device "
+                       "maybe be useless or invisible for system tools."),
+                       filename);
+       else if (size % 512)
+               warnx(_("%s: warning: file does not fit into a 512-byte sector "
+                       "the end of the file will be ignored."),
+                       filename);
+}
+
 int main(int argc, char **argv)
 {
        struct loopdev_cxt lc;
@@ -381,8 +401,11 @@ int main(int argc, char **argv)
 
                free(pass);
 
-               if (showdev && res == 0)
-                       printf("%s\n", loopcxt_get_device(&lc));
+               if (res == 0) {
+                       if (showdev)
+                               printf("%s\n", loopcxt_get_device(&lc));
+                       warn_size(file, sizelimit);
+               }
                break;
        }
        case A_DELETE: