On 12/9/25 1:51 PM, Sascha Hauer wrote:
> In stat_print() we have to take the filename component of the input path
> and retrieve the cdev from that name. Now that we have the cdevname in
> struct stat we can simplify this.
> 
> Signed-off-by: Sascha Hauer <[email protected]>

Reviewed-by: Ahmad Fatoum <[email protected]>

> ---
>  fs/fs.c | 25 ++++---------------------
>  1 file changed, 4 insertions(+), 21 deletions(-)
> 
> diff --git a/fs/fs.c b/fs/fs.c
> index 
> 9022287dff2f4959f64eac76c544634b3978d238..30fe5db4d2800ebfdc0c44603caea15bdff807aa
>  100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -137,7 +137,6 @@ void stat_print(int dirfd, const char *filename, const 
> struct stat *st)
>       struct fs_device *fdev;
>       struct cdev *cdev = NULL;
>       const char *type = NULL, *typeprefix = "";
> -     bool is_cdev_link = false;
>       char modestr[11];
>  
>       mkmodestr(st->st_mode, modestr);
> @@ -152,23 +151,10 @@ void stat_print(int dirfd, const char *filename, const 
> struct stat *st)
>               case S_IFREG:    type = "regular file"; break;
>       }
>  
> -     if (st->st_mode & S_IFCHR) {
> -             char *path;
> -
> -             path = canonicalize_path(dirfd, filename);
> -             if (path) {
> -                     const char *devicefile = devpath_to_name(path);
> -                     struct cdev *lcdev;
> -
> -                     lcdev = lcdev_by_name(devicefile);
> -                     cdev = cdev_readlink(lcdev);
> -                     if (cdev != lcdev)
> -                             is_cdev_link = true;
> -                     if (cdev)
> -                             bdev = cdev_get_block_device(cdev);
> -
> -                     free(path);
> -             }
> +     if ((st->st_mode & S_IFCHR) && st->st_cdevname) {
> +             cdev = cdev_by_name(st->st_cdevname);
> +             if (cdev)
> +                     bdev = cdev_get_block_device(cdev);
>       }
>  
>       printf("  File: %s", filename);
> @@ -182,9 +168,6 @@ void stat_print(int dirfd, const char *filename, const 
> struct stat *st)
>                       printf(" -> <readlink error %pe>", ERR_PTR(ret));
>               else
>                       printf(" -> %s", realname);
> -     } else if (is_cdev_link) {
> -             printf(" ~> %s", cdev->name);
> -             typeprefix = "cdev link to ";
>       }
>  
>       printf("\nSize: ");
> 

-- 
Pengutronix e.K.                  |                             |
Steuerwalder Str. 21              | http://www.pengutronix.de/  |
31137 Hildesheim, Germany         | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |


Reply via email to