summaryrefslogtreecommitdiffstats
path: root/sys-utils/losetup.c
diff options
context:
space:
mode:
authorKarel Zak2012-06-12 14:34:16 +0200
committerKarel Zak2012-06-12 14:34:16 +0200
commit3554545636f639fbd65d92cc7643e89f3c0ff7a5 (patch)
tree6555416094aff829e30c31197fc9f40e4b6f8311 /sys-utils/losetup.c
parentbuild-sys: add compiler warnings (diff)
downloadkernel-qcow2-util-linux-3554545636f639fbd65d92cc7643e89f3c0ff7a5.tar.gz
kernel-qcow2-util-linux-3554545636f639fbd65d92cc7643e89f3c0ff7a5.tar.xz
kernel-qcow2-util-linux-3554545636f639fbd65d92cc7643e89f3c0ff7a5.zip
losetup: warn about backing file size
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=730266 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/losetup.c')
-rw-r--r--sys-utils/losetup.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 4f44b9b14..3c3229989 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -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: