]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fallocate: add verbose messages
authorKarel Zak <kzak@redhat.com>
Mon, 27 Sep 2021 13:40:11 +0000 (15:40 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 27 Sep 2021 13:40:11 +0000 (15:40 +0200)
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2003927
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/fallocate.c

index ba97092fcf903a1f7b2265d55a2d4b4d7626e40a..307fbd858b2530b66effa16952be8021d0007538 100644 (file)
@@ -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);