[PATCH RFC 3/5] fs: Add fallocate2() syscall

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This introduces a new syscall and propagates @physical there.
Also, architecture-dependent definitions for x86 are added.

Signed-off-by: Kirill Tkhai <ktkhai@xxxxxxxxxxxxx>
---
 arch/x86/entry/syscalls/syscall_32.tbl |    1 +
 arch/x86/entry/syscalls/syscall_64.tbl |    1 +
 arch/x86/ia32/sys_ia32.c               |   10 ++++++++++
 fs/open.c                              |   16 +++++++++++++---
 include/linux/syscalls.h               |    8 +++++++-
 5 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/arch/x86/entry/syscalls/syscall_32.tbl b/arch/x86/entry/syscalls/syscall_32.tbl
index c17cb77eb150..62b3692df584 100644
--- a/arch/x86/entry/syscalls/syscall_32.tbl
+++ b/arch/x86/entry/syscalls/syscall_32.tbl
@@ -442,3 +442,4 @@
 435	i386	clone3			sys_clone3			__ia32_sys_clone3
 437	i386	openat2			sys_openat2			__ia32_sys_openat2
 438	i386	pidfd_getfd		sys_pidfd_getfd			__ia32_sys_pidfd_getfd
+486	i386	fallocate2		sys_fallocate2			__ia32_compat_sys_x86_fallocate2
diff --git a/arch/x86/entry/syscalls/syscall_64.tbl b/arch/x86/entry/syscalls/syscall_64.tbl
index 44d510bc9b78..b106a39509ee 100644
--- a/arch/x86/entry/syscalls/syscall_64.tbl
+++ b/arch/x86/entry/syscalls/syscall_64.tbl
@@ -359,6 +359,7 @@
 435	common	clone3			__x64_sys_clone3/ptregs
 437	common	openat2			__x64_sys_openat2
 438	common	pidfd_getfd		__x64_sys_pidfd_getfd
+486	common	fallocate2		__x64_sys_fallocate2
 
 #
 # x32-specific system call numbers start at 512 to avoid cache impact
diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
index 21790307121e..1757bfe1a19c 100644
--- a/arch/x86/ia32/sys_ia32.c
+++ b/arch/x86/ia32/sys_ia32.c
@@ -230,6 +230,16 @@ COMPAT_SYSCALL_DEFINE6(x86_fallocate, int, fd, int, mode,
 			      ((u64)len_hi << 32) | len_lo);
 }
 
+COMPAT_SYSCALL_DEFINE6(x86_fallocate2, int, fd, int, mode,
+		       unsigned int, offset_lo, unsigned int, offset_hi,
+		       unsigned int, len_lo, unsigned int, len_hi,
+		       unsigned int physical_lo, unsigned int physical_hi)
+{
+	return ksys_fallocate2(fd, mode, ((u64)offset_hi << 32) | offset_lo,
+			      ((u64)len_hi << 32) | len_lo,
+			      ((u64)physical_hi << 32) | physical_lo);
+}
+
 /*
  * The 32-bit clone ABI is CONFIG_CLONE_BACKWARDS
  */
diff --git a/fs/open.c b/fs/open.c
index 596fd3dc3988..1b964a37ecc2 100644
--- a/fs/open.c
+++ b/fs/open.c
@@ -290,6 +290,10 @@ int vfs_fallocate(struct file *file, int mode,
 	if (ret)
 		return ret;
 
+	if (physical != (u64)-1 &&
+	    !ns_capable(inode->i_sb->s_user_ns, CAP_FOWNER))
+		return -EPERM;
+
 	if (S_ISFIFO(inode->i_mode))
 		return -ESPIPE;
 
@@ -324,13 +328,13 @@ int vfs_fallocate(struct file *file, int mode,
 }
 EXPORT_SYMBOL_GPL(vfs_fallocate);
 
-int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len)
+int ksys_fallocate2(int fd, int mode, loff_t offset, loff_t len, u64 physical)
 {
 	struct fd f = fdget(fd);
 	int error = -EBADF;
 
 	if (f.file) {
-		error = vfs_fallocate(f.file, mode, offset, len, (u64)-1);
+		error = vfs_fallocate(f.file, mode, offset, len, physical);
 		fdput(f);
 	}
 	return error;
@@ -338,7 +342,13 @@ int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len)
 
 SYSCALL_DEFINE4(fallocate, int, fd, int, mode, loff_t, offset, loff_t, len)
 {
-	return ksys_fallocate(fd, mode, offset, len);
+	return ksys_fallocate2(fd, mode, offset, len, (u64)-1);
+}
+
+SYSCALL_DEFINE5(fallocate2, int, fd, int, mode, loff_t, offset, loff_t, len,
+		unsigned long long, physical)
+{
+	return ksys_fallocate2(fd, mode, offset, len, physical);
 }
 
 /*
diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
index 1815065d52f3..1999493b03e9 100644
--- a/include/linux/syscalls.h
+++ b/include/linux/syscalls.h
@@ -427,6 +427,8 @@ asmlinkage long sys_truncate64(const char __user *path, loff_t length);
 asmlinkage long sys_ftruncate64(unsigned int fd, loff_t length);
 #endif
 asmlinkage long sys_fallocate(int fd, int mode, loff_t offset, loff_t len);
+asmlinkage long sys_fallocate2(int fd, int mode, loff_t offset, loff_t len,
+			       unsigned long long physical);
 asmlinkage long sys_faccessat(int dfd, const char __user *filename, int mode);
 asmlinkage long sys_chdir(const char __user *filename);
 asmlinkage long sys_fchdir(unsigned int fd);
@@ -1255,7 +1257,11 @@ ssize_t ksys_pread64(unsigned int fd, char __user *buf, size_t count,
 		     loff_t pos);
 ssize_t ksys_pwrite64(unsigned int fd, const char __user *buf,
 		      size_t count, loff_t pos);
-int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len);
+int ksys_fallocate2(int fd, int mode, loff_t offset, loff_t len, u64 physical);
+static inline int ksys_fallocate(int fd, int mode, loff_t offset, loff_t len)
+{
+	return ksys_fallocate2(fd, mode, offset, len, (u64)-1);
+}
 #ifdef CONFIG_ADVISE_SYSCALLS
 int ksys_fadvise64_64(int fd, loff_t offset, loff_t len, int advice);
 #else





[Index of Archives]     [Reiser Filesystem Development]     [Ceph FS]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite National Park]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Device Mapper]     [Linux Media]

  Powered by Linux