[PATCH 2/4] common: add a _sysfs_block_integrity_path helper

Christoph Hellwig <[email protected]> Thu, 23 Jul 2026 16:28:45 +0200
Newsgroups org.kernel.vger.fstests,org.kernel.vger.linux-scsi
Message-ID <[email protected]>
Add a helper function to find the sysfs integrity directory for a given
block device.

Signed-off-by: Christoph Hellwig <[email protected]>
---
 common/rc | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/common/rc b/common/rc
index 106f044adc2d..96e74cfd4e5b 100644
--- a/common/rc
+++ b/common/rc
@@ -5254,6 +5254,31 @@ _sysfs_queue_path()
 	fi
 }
 
+# Get the sysfs block device integrity/ path for a block device, handling
+# partitions correctly.
+_sysfs_block_integrity_path()
+{
+	local dev parent
+	dev=$(_short_dev "$1")
+
+	# For partitions, integrity details are in the parent device's sysfs dir
+	if [ -e "/sys/class/block/$dev/partition" ]; then
+		parent=$(basename "$(readlink -f /sys/class/block/$dev/..)")
+	else
+		parent="$dev"
+	fi
+
+	local integrity_path="/sys/block/$parent/integrity"
+
+	# Verify the path exists before returning
+	if [ -e "$integrity_path" ]; then
+		echo "$integrity_path"
+		return 0
+	fi
+
+	return 1
+}
+
 # Get the minimum block size of a file.  Usually this is the
 # minimum fs block size, but some filesystems (ocfs2) do block
 # mappings in larger units.
-- 
2.53.0