xref: /linux/include/linux/fileattr.h (revision 9a87ffc99ec8eb8d35eed7c4f816d75f5cc9662e)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _LINUX_FILEATTR_H
4 #define _LINUX_FILEATTR_H
5 
6 /* Flags shared betwen flags/xflags */
7 #define FS_COMMON_FL \
8 	(FS_SYNC_FL | FS_IMMUTABLE_FL | FS_APPEND_FL | \
9 	 FS_NODUMP_FL |	FS_NOATIME_FL | FS_DAX_FL | \
10 	 FS_PROJINHERIT_FL)
11 
12 #define FS_XFLAG_COMMON \
13 	(FS_XFLAG_SYNC | FS_XFLAG_IMMUTABLE | FS_XFLAG_APPEND | \
14 	 FS_XFLAG_NODUMP | FS_XFLAG_NOATIME | FS_XFLAG_DAX | \
15 	 FS_XFLAG_PROJINHERIT)
16 
17 /*
18  * Merged interface for miscellaneous file attributes.  'flags' originates from
19  * ext* and 'fsx_flags' from xfs.  There's some overlap between the two, which
20  * is handled by the VFS helpers, so filesystems are free to implement just one
21  * or both of these sub-interfaces.
22  */
23 struct fileattr {
24 	u32	flags;		/* flags (FS_IOC_GETFLAGS/FS_IOC_SETFLAGS) */
25 	/* struct fsxattr: */
26 	u32	fsx_xflags;	/* xflags field value (get/set) */
27 	u32	fsx_extsize;	/* extsize field value (get/set)*/
28 	u32	fsx_nextents;	/* nextents field value (get)	*/
29 	u32	fsx_projid;	/* project identifier (get/set) */
30 	u32	fsx_cowextsize;	/* CoW extsize field value (get/set)*/
31 	/* selectors: */
32 	bool	flags_valid:1;
33 	bool	fsx_valid:1;
34 };
35 
36 int copy_fsxattr_to_user(const struct fileattr *fa, struct fsxattr __user *ufa);
37 
38 void fileattr_fill_xflags(struct fileattr *fa, u32 xflags);
39 void fileattr_fill_flags(struct fileattr *fa, u32 flags);
40 
41 /**
42  * fileattr_has_fsx - check for extended flags/attributes
43  * @fa:		fileattr pointer
44  *
45  * Return: true if any attributes are present that are not represented in
46  * ->flags.
47  */
fileattr_has_fsx(const struct fileattr * fa)48 static inline bool fileattr_has_fsx(const struct fileattr *fa)
49 {
50 	return fa->fsx_valid &&
51 		((fa->fsx_xflags & ~FS_XFLAG_COMMON) || fa->fsx_extsize != 0 ||
52 		 fa->fsx_projid != 0 ||	fa->fsx_cowextsize != 0);
53 }
54 
55 int vfs_fileattr_get(struct dentry *dentry, struct fileattr *fa);
56 int vfs_fileattr_set(struct mnt_idmap *idmap, struct dentry *dentry,
57 		     struct fileattr *fa);
58 
59 #endif /* _LINUX_FILEATTR_H */
60