From: Karel Zak Date: Mon, 27 Sep 2021 13:40:11 +0000 (+0200) Subject: fallocate: add verbose messages X-Git-Tag: v2.38-rc1~238 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0f246b73e268719446cf961d427eb123a2a34e97;p=thirdparty%2Futil-linux.git fallocate: add verbose messages Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2003927 Signed-off-by: Karel Zak --- diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c index ba97092fcf..307fbd858b 100644 --- a/sys-utils/fallocate.c +++ b/sys-utils/fallocate.c @@ -406,12 +406,35 @@ int main(int argc, char **argv) if (dig) dig_holes(fd, offset, length); + else { #ifdef HAVE_POSIX_FALLOCATE - else if (posix) - xposix_fallocate(fd, offset, length); + if (posix) + xposix_fallocate(fd, offset, length); + else #endif - else - xfallocate(fd, mode, offset, length); + xfallocate(fd, mode, offset, length); + + if (verbose) { + char *str = size_to_human_string(SIZE_SUFFIX_3LETTER | SIZE_SUFFIX_SPACE, length); + + if (mode & FALLOC_FL_PUNCH_HOLE) + fprintf(stdout, _("%s: %s (%ju bytes) hole created.\n"), + filename, str, length); + else if (mode & FALLOC_FL_COLLAPSE_RANGE) + fprintf(stdout, _("%s: %s (%ju bytes) removed.\n"), + filename, str, length); + else if (mode & FALLOC_FL_INSERT_RANGE) + fprintf(stdout, _("%s: %s (%ju bytes) inserted.\n"), + filename, str, length); + else if (mode & FALLOC_FL_ZERO_RANGE) + fprintf(stdout, _("%s: %s (%ju bytes) zeroed.\n"), + filename, str, length); + else + fprintf(stdout, _("%s: %s (%ju bytes) allocated.\n"), + filename, str, length); + free(str); + } + } if (close_fd(fd) != 0) err(EXIT_FAILURE, _("write failed: %s"), filename);