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

"Darrick J. Wong" <[email protected]>
Newsgroups gmane.comp.file-systems.fstests,gmane.linux.scsi
Message-ID <20260821232908.GE839663@frogsfrogsfrogs>
On Fri, Aug 21, 2026 at 07:11:27AM +0200, Christoph Hellwig wrote:
> 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

I wonder if this part should get pulled out into a _sysfs_block_path
helper, since the code is already in _sysfs_queue_path?

--D

> +
> +	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.