[COMMIT osv master] vfs: implement subset of copy_file_range()

1 view
Skip to first unread message

Commit Bot

unread,
Mar 18, 2024, 12:36:12 PMMar 18
to osv...@googlegroups.com, Waldemar Kozaczuk
From: Waldemar Kozaczuk <jwkoz...@gmail.com>
Committer: WALDEMAR KOZACZUK <jwkoz...@gmail.com>
Branch: master

vfs: implement subset of copy_file_range()

This patch implements subset of copy_file_range() needed
by the GNU cp utility to function.

The implementation delagates to sendfile() and accepts
calls with off_out equal to 0 only.

Signed-off-by: Waldemar Kozaczuk <jwkoz...@gmail.com>

---
diff --git a/fs/vfs/main.cc b/fs/vfs/main.cc
--- a/fs/vfs/main.cc
+++ b/fs/vfs/main.cc
@@ -2345,6 +2345,27 @@ ssize_t sendfile(int out_fd, int in_fd, off_t *_offset, size_t count)
#undef sendfile64
LFS64(sendfile);

+extern "C" OSV_LIBC_API
+ssize_t copy_file_range(int fd_in, off_t *off_in,
+ int fd_out, off_t *off_out,
+ size_t len, unsigned int flags)
+{
+ //Non-zero flags are rejected according to the manual
+ if (flags != 0) {
+ errno = EINVAL;
+ return -1;
+ }
+ //We do not support writing to a file at specified offset because
+ //we delegate to sendfile() which assumes current position of the output
+ //file
+ if (off_out) {
+ WARN("copy_file_range() does not support non-zero off_out\n");
+ errno = EINVAL;
+ return -1;
+ }
+ return sendfile(fd_out, fd_in, off_in, len);
+}
+
NO_SYS(OSV_LIBC_API int fchmodat(int dirfd, const char *pathname, mode_t mode, int flags));

OSV_LIBC_API
Reply all
Reply to author
Forward
0 new messages