diff mbox series

[V2] btrfs-progs: allow autodetect_object_types() to handle link.

Message ID da4a4e0cf18df259e63c19872093bf12635da576.1641415488.git.kreijack@inwind.it (mailing list archive)
State New, archived
Headers show
Series [V2] btrfs-progs: allow autodetect_object_types() to handle link. | expand

Commit Message

Goffredo Baroncelli Jan. 5, 2022, 8:45 p.m. UTC
From: Goffredo Baroncelli <kreijack@inwind.it>

The function autodetect_object_types() tries to detect the type of
btrfs object passed. If it is an "inode" type (e.g. file) this function
returns the type as "inode". If it is a block device, it return it as
"block device".
However it doesn't handle the case where the object passed is a link
to a block device (which could be a valid btrfs device). For example
LVM/DM creates link to block devices. In this case it should return
the type as "block device".

This patch replace the lstat() call with a stat().

Reported-by: Boris Burkov <boris@bur.io>
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
---
 cmds/property.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Boris Burkov Jan. 5, 2022, 8:48 p.m. UTC | #1
On Wed, Jan 05, 2022 at 09:45:52PM +0100, Goffredo Baroncelli wrote:
> From: Goffredo Baroncelli <kreijack@inwind.it>
> 
> The function autodetect_object_types() tries to detect the type of
> btrfs object passed. If it is an "inode" type (e.g. file) this function
> returns the type as "inode". If it is a block device, it return it as
> "block device".
> However it doesn't handle the case where the object passed is a link
> to a block device (which could be a valid btrfs device). For example
> LVM/DM creates link to block devices. In this case it should return
> the type as "block device".
> 
> This patch replace the lstat() call with a stat().
> 
> Reported-by: Boris Burkov <boris@bur.io>
Reviewed-by: Boris Burkov <boris@bur.io>
> Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
> ---
>  cmds/property.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/cmds/property.c b/cmds/property.c
> index 59ef997c..b3ccc0ff 100644
> --- a/cmds/property.c
> +++ b/cmds/property.c
> @@ -373,7 +373,7 @@ static int autodetect_object_types(const char *object, int *types_out)
>  
>  	is_btrfs_object = check_btrfs_object(object);
>  
> -	ret = lstat(object, &st);
> +	ret = stat(object, &st);
>  	if (ret < 0) {
>  		ret = -errno;
>  		goto out;
> -- 
> 2.34.1
>
David Sterba Jan. 6, 2022, 2:49 p.m. UTC | #2
On Wed, Jan 05, 2022 at 09:45:52PM +0100, Goffredo Baroncelli wrote:
> From: Goffredo Baroncelli <kreijack@inwind.it>
> 
> The function autodetect_object_types() tries to detect the type of
> btrfs object passed. If it is an "inode" type (e.g. file) this function
> returns the type as "inode". If it is a block device, it return it as
> "block device".
> However it doesn't handle the case where the object passed is a link
> to a block device (which could be a valid btrfs device). For example
> LVM/DM creates link to block devices. In this case it should return
> the type as "block device".
> 
> This patch replace the lstat() call with a stat().
> 
> Reported-by: Boris Burkov <boris@bur.io>
> Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>

Added to devel, thanks.
diff mbox series

Patch

diff --git a/cmds/property.c b/cmds/property.c
index 59ef997c..b3ccc0ff 100644
--- a/cmds/property.c
+++ b/cmds/property.c
@@ -373,7 +373,7 @@  static int autodetect_object_types(const char *object, int *types_out)
 
 	is_btrfs_object = check_btrfs_object(object);
 
-	ret = lstat(object, &st);
+	ret = stat(object, &st);
 	if (ret < 0) {
 		ret = -errno;
 		goto out;