summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Roesch <shr@fb.com>2021-12-21 08:40:03 -0800
committerJens Axboe <axboe@kernel.dk>2021-12-21 12:15:40 -0700
commit54d460de2423434e7aa9f7fcb9656230de53b85e (patch)
treecbb57386f16382a06908aaf022248a19fe20aded
parent1533c1b579e1e866465fd9d04c8a5ebb1e25ba28 (diff)
fs: split off vfs_getdents function of getdents64 syscall
This splits off the vfs_getdents function from the getdents64 system call. This allows io_uring to call the vfs_getdents function. Signed-off-by: Stefan Roesch <shr@fb.com> Acked-by: Christian Brauner <christian.brauner@ubuntu.com> Link: https://lore.kernel.org/r/20211221164004.119663-3-shr@fb.com Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--fs/internal.h8
-rw-r--r--fs/readdir.c36
2 files changed, 36 insertions, 8 deletions
diff --git a/fs/internal.h b/fs/internal.h
index 7979ff8d168c..432ea3ce76ec 100644
--- a/fs/internal.h
+++ b/fs/internal.h
@@ -194,3 +194,11 @@ long splice_file_to_pipe(struct file *in,
struct pipe_inode_info *opipe,
loff_t *offset,
size_t len, unsigned int flags);
+
+/*
+ * fs/readdir.c
+ */
+struct linux_dirent64;
+
+int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent,
+ unsigned int count, loff_t *pos);
diff --git a/fs/readdir.c b/fs/readdir.c
index c1e6612e0f47..1b1fade87525 100644
--- a/fs/readdir.c
+++ b/fs/readdir.c
@@ -21,6 +21,7 @@
#include <linux/unistd.h>
#include <linux/compat.h>
#include <linux/uaccess.h>
+#include "internal.h"
#include <asm/unaligned.h>
@@ -359,22 +360,25 @@ efault:
return -EFAULT;
}
-SYSCALL_DEFINE3(getdents64, unsigned int, fd,
- struct linux_dirent64 __user *, dirent, unsigned int, count)
+/**
+ * vfs_getdents - getdents without fdget
+ * @file : pointer to file struct of directory
+ * @dirent : pointer to user directory structure
+ * @count : size of buffer
+ * @pos : file pos
+ */
+int vfs_getdents(struct file *file, struct linux_dirent64 __user *dirent,
+ unsigned int count, loff_t *pos)
{
- struct fd f;
struct getdents_callback64 buf = {
.ctx.actor = filldir64,
+ .ctx.pos = *pos,
.count = count,
.current_dir = dirent
};
int error;
- f = fdget_pos(fd);
- if (!f.file)
- return -EBADF;
-
- error = iterate_dir(f.file, &buf.ctx, &f.file->f_pos);
+ error = iterate_dir(file, &buf.ctx, pos);
if (error >= 0)
error = buf.error;
if (buf.prev_reclen) {
@@ -391,6 +395,22 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
return error;
}
+SYSCALL_DEFINE3(getdents64, unsigned int, fd,
+ struct linux_dirent64 __user *, dirent, unsigned int, count)
+{
+ struct fd f;
+ int error;
+
+ f = fdget_pos(fd);
+ if (!f.file)
+ return -EBADF;
+
+ error = vfs_getdents(f.file, dirent, count, &f.file->f_pos);
+
+ fdput_pos(f);
+ return error;
+ }
+
#ifdef CONFIG_COMPAT
struct compat_old_linux_dirent {
compat_ulong_t d_ino;