History

fs: introduce file_getattr and file_setattr syscalls

Introduce file_getattr() and file_setattr() syscalls to manipulate inode extended attributes. The syscalls takes pair of file descriptor and pathname. Then it operates on inode opened accroding to openat() semantics. The struct file_attr is passed to obtain/change extended attributes. This is an alternative to FS_IOC_FSSETXATTR ioctl with a difference that file don't need to be open as we can reference it with a path instead of fd. By having this we can manipulated inode extended attributes not only on regular files but also on special ones. This is not possible with FS_IOC_FSSETXATTR ioctl as with special files we can not call ioctl() directly on the filesystem inode using fd. This patch adds two new syscalls which allows userspace to get/set extended inode attributes on special files by using parent directory and a path - *at() like syscall.

Andrey Albershteyn committed 1 year ago

Commit be7efb21 parent 276e13621 files · +218 −1Browse files

Showing the changes to include/uapi (2 of 21 files). Show all

Unified · Split

2 files
  1. include/uapi/asm-generic/unistd.h +7 −1
  2. include/uapi/linux/fs.h +18 −0
include/uapi/asm-generic/unistd.h+7−1
@@ -852,8 +852,14 @@ __SYSCALL(__NR_removexattrat, sys_removexattrat) · 851 unmodified lines
852852 #define __NR_open_tree_attr 467
853853 __SYSCALL(__NR_open_tree_attr, sys_open_tree_attr)
854854
855+/* fs/inode.c */
856+#define __NR_file_getattr 468
857+__SYSCALL(__NR_file_getattr, sys_file_getattr)
858+#define __NR_file_setattr 469
859+__SYSCALL(__NR_file_setattr, sys_file_setattr)
860+
855861 #undef __NR_syscalls
856−#define __NR_syscalls 468
862+#define __NR_syscalls 470
857863
858864 /*
859865 * 32 bit systems traditionally used different
include/uapi/linux/fs.h+18−0
@@ -148,6 +148,24 @@ struct fsxattr { · 147 unmodified lines
148148 unsigned char fsx_pad[8];
149149 };
150150
151+/*
152+ * Variable size structure for file_[sg]et_attr().
153+ *
154+ * Note. This is alternative to the structure 'struct fileattr'/'struct fsxattr'.
155+ * As this structure is passed to/from userspace with its size, this can
156+ * be versioned based on the size.
157+ */
158+struct file_attr {
159+ __u64 fa_xflags; /* xflags field value (get/set) */
160+ __u32 fa_extsize; /* extsize field value (get/set)*/
161+ __u32 fa_nextents; /* nextents field value (get) */
162+ __u32 fa_projid; /* project identifier (get/set) */
163+ __u32 fa_cowextsize; /* CoW extsize field value (get/set) */
164+};
165+
166+#define FILE_ATTR_SIZE_VER0 24
167+#define FILE_ATTR_SIZE_LATEST FILE_ATTR_SIZE_VER0
168+
151169 /*
152170 * Flags for the fsx_xflags field
153171 */