@@ -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;
}
@@ -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);
This will be helpful for get/setfsxattrat syscalls to convert between fileattr and fsxattr. Signed-off-by: Andrey Albershteyn <aalbersh@kernel.org> --- fs/ioctl.c | 32 +++++++++++++++++++++----------- include/linux/fileattr.h | 2 ++ 2 files changed, 23 insertions(+), 11 deletions(-)