On Fri 21-03-25 20:48:41, Andrey Albershteyn wrote:
> This will be helpful for get/setfsxattrat syscalls to convert
> between fileattr and fsxattr.
> 
> Signed-off-by: Andrey Albershteyn <aalbe...@kernel.org>

Looks good. Feel free to add:

Reviewed-by: Jan Kara <j...@suse.cz>

                                                                Honza

> ---
>  fs/ioctl.c               | 32 +++++++++++++++++++++-----------
>  include/linux/fileattr.h |  2 ++
>  2 files changed, 23 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/ioctl.c b/fs/ioctl.c
> index 
> 4434c97bc5dff5a3e8635e28745cd99404ff353e..840283d8c406623d8d26790f89b62ebcbd39e2de
>  100644
> --- a/fs/ioctl.c
> +++ b/fs/ioctl.c
> @@ -538,6 +538,16 @@ int vfs_fileattr_get(struct dentry *dentry, struct 
> fileattr *fa)
>  }
>  EXPORT_SYMBOL(vfs_fileattr_get);
>  
> +void fileattr_to_fsxattr(const struct fileattr *fa, struct fsxattr *fsx)
> +{
> +     memset(fsx, 0, sizeof(struct fsxattr));
> +     fsx->fsx_xflags = fa->fsx_xflags;
> +     fsx->fsx_extsize = fa->fsx_extsize;
> +     fsx->fsx_nextents = fa->fsx_nextents;
> +     fsx->fsx_projid = fa->fsx_projid;
> +     fsx->fsx_cowextsize = fa->fsx_cowextsize;
> +}
> +
>  /**
>   * copy_fsxattr_to_user - copy fsxattr to userspace.
>   * @fa:              fileattr pointer
> @@ -549,12 +559,7 @@ int copy_fsxattr_to_user(const struct fileattr *fa, 
> struct fsxattr __user *ufa)
>  {
>       struct fsxattr xfa;
>  
> -     memset(&xfa, 0, sizeof(xfa));
> -     xfa.fsx_xflags = fa->fsx_xflags;
> -     xfa.fsx_extsize = fa->fsx_extsize;
> -     xfa.fsx_nextents = fa->fsx_nextents;
> -     xfa.fsx_projid = fa->fsx_projid;
> -     xfa.fsx_cowextsize = fa->fsx_cowextsize;
> +     fileattr_to_fsxattr(fa, &xfa);
>  
>       if (copy_to_user(ufa, &xfa, sizeof(xfa)))
>               return -EFAULT;
> @@ -563,6 +568,15 @@ int copy_fsxattr_to_user(const struct fileattr *fa, 
> struct fsxattr __user *ufa)
>  }
>  EXPORT_SYMBOL(copy_fsxattr_to_user);
>  
> +void fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa)
> +{
> +     fileattr_fill_xflags(fa, fsx->fsx_xflags);
> +     fa->fsx_extsize = fsx->fsx_extsize;
> +     fa->fsx_nextents = fsx->fsx_nextents;
> +     fa->fsx_projid = fsx->fsx_projid;
> +     fa->fsx_cowextsize = fsx->fsx_cowextsize;
> +}
> +
>  static int copy_fsxattr_from_user(struct fileattr *fa,
>                                 struct fsxattr __user *ufa)
>  {
> @@ -571,11 +585,7 @@ static int copy_fsxattr_from_user(struct fileattr *fa,
>       if (copy_from_user(&xfa, ufa, sizeof(xfa)))
>               return -EFAULT;
>  
> -     fileattr_fill_xflags(fa, xfa.fsx_xflags);
> -     fa->fsx_extsize = xfa.fsx_extsize;
> -     fa->fsx_nextents = xfa.fsx_nextents;
> -     fa->fsx_projid = xfa.fsx_projid;
> -     fa->fsx_cowextsize = xfa.fsx_cowextsize;
> +     fsxattr_to_fileattr(&xfa, fa);
>  
>       return 0;
>  }
> diff --git a/include/linux/fileattr.h b/include/linux/fileattr.h
> index 
> 47c05a9851d0600964b644c9c7218faacfd865f8..31888fa2edf10050be134f587299256088344365
>  100644
> --- a/include/linux/fileattr.h
> +++ b/include/linux/fileattr.h
> @@ -33,7 +33,9 @@ struct fileattr {
>       bool    fsx_valid:1;
>  };
>  
> +void fileattr_to_fsxattr(const struct fileattr *fa, struct fsxattr *fsx);
>  int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user 
> *ufa);
> +void fsxattr_to_fileattr(const struct fsxattr *fsx, struct fileattr *fa);
>  
>  void fileattr_fill_xflags(struct fileattr *fa, u32 xflags);
>  void fileattr_fill_flags(struct fileattr *fa, u32 flags);
> 
> -- 
> 2.47.2
> 
-- 
Jan Kara <j...@suse.com>
SUSE Labs, CR

Reply via email to