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

Christoph Hellwig <[email protected]>
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 02bdb31a76a6..61a899da3bd7 100644
--- a/common/rc
+++ b/common/rc
@@ -5257,6 +5257,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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.