[PATCH 01/11] common/xfs: Add a helper to get an inode fork's extent count

Chandan Babu R
2020-11-13T11:27:58Z

This commit adds the helper _scratch_get_iext_count() which returns an
inode fork's extent count.

Signed-off-by: Chandan Babu R <chandanrlinux@gmail.com>
---
common/xfs | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)

diff --git a/common/xfs b/common/xfs
index 79dab058..45cd329c 100644
--- a/common/xfs
+++ b/common/xfs
@@ -883,6 +883,28 @@ _scratch_get_bmx_prefix() {
return 1
}

+_scratch_get_iext_count()
+{
+ ino=$1
+ whichfork=$2
+
+ case $whichfork in
+ "attr")
+ field=core.naextents
+ ;;
+ "data")
+ field=core.nextents
+ ;;
+ *)
+ return 1
+ esac
+
+ nextents=$(_scratch_xfs_db -c "inode $ino" -c "print $field")
+ nextents=${nextents##${field} = }
+
+ echo $nextents
+}
+
#
# Ensures that we don't pass any mount options incompatible with XFS v4
#
--
2.28.0