common/filter: add _filter_xfs_io_fiemap()
authorEric Biggers <ebiggers@google.com>
Mon, 30 Sep 2019 21:15:46 +0000 (14:15 -0700)
committerEryu Guan <guaneryu@gmail.com>
Sun, 13 Oct 2019 13:01:20 +0000 (21:01 +0800)
Add _filter_xfs_io_fiemap() to clean up the output of
'xfs_io -c fiemap'.  This will be used by a function in common/verity.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/filter

index 26fc21322d1cac349acfc2ffc40c4c8c7e0bf589..2477f3860151cc3bcbc7d0247109699514b5b068 100644 (file)
@@ -541,6 +541,30 @@ _filter_filefrag()
              $flags, "\n"'
 }
 
+# Clean up the extents list output of 'xfs_io -c fiemap', e.g.
+#
+#      file:
+#              0: [0..79]: 628365312..628365391
+#              1: [80..159]: hole
+#              2: [160..319]: 628365472..628365631
+# =>
+#      0  79   628365312  628365391
+#      160  319   628365472  628365631
+#
+# The fields are:
+#
+#      first_logical_block last_logical_block first_physical_block last_physical_block
+#
+# Blocks are 512 bytes, and holes are omitted.
+#
+_filter_xfs_io_fiemap()
+{
+        grep -E '^[[:space:]]+[0-9]+:' \
+                | grep -v '\<hole\>' \
+                | sed -E 's/^[[:space:]]+[0-9]+://' \
+                | tr '][.:' ' '
+}
+
 # We generate WARNINGs on purpose when applications mix buffered/mmap IO with
 # direct IO on the same file. This is a helper for _check_dmesg() to filter out
 # such warnings.