From 3554545636f639fbd65d92cc7643e89f3c0ff7a5 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 12 Jun 2012 14:34:16 +0200 Subject: losetup: warn about backing file size Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=730266 Signed-off-by: Karel Zak --- sys-utils/losetup.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'sys-utils/losetup.c') 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: -- cgit v1.2.3-55-g7522