Skip to content

Commit

Permalink
fs: add ksys_getdents64() helper; remove in-kernel calls to sys_getde…
Browse files Browse the repository at this point in the history
…nts64()

Using this helper allows us to avoid the in-kernel calls to the
sys_getdents64() syscall. The ksys_ prefix denotes that this function
is meant as a drop-in replacement for the syscall. In particular, it
uses the same calling convention as sys_getdents64().

This patch is part of a series which removes in-kernel calls to syscalls.
On this basis, the syscall entry path can be streamlined. For details, see
http://lkml.kernel.org/r/[email protected]

Cc: Alexander Viro <[email protected]>
Signed-off-by: Dominik Brodowski <[email protected]>
  • Loading branch information
Dominik Brodowski committed Apr 2, 2018
1 parent bae217e commit 454dab3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
11 changes: 9 additions & 2 deletions fs/readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ static int filldir64(struct dir_context *ctx, const char *name, int namlen,
return -EFAULT;
}

SYSCALL_DEFINE3(getdents64, unsigned int, fd,
struct linux_dirent64 __user *, dirent, unsigned int, count)
int ksys_getdents64(unsigned int fd, struct linux_dirent64 __user *dirent,
unsigned int count)
{
struct fd f;
struct linux_dirent64 __user * lastdirent;
Expand Down Expand Up @@ -326,6 +326,13 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
return error;
}


SYSCALL_DEFINE3(getdents64, unsigned int, fd,
struct linux_dirent64 __user *, dirent, unsigned int, count)
{
return ksys_getdents64(fd, dirent, count);
}

#ifdef CONFIG_COMPAT
struct compat_old_linux_dirent {
compat_ulong_t d_ino;
Expand Down
2 changes: 2 additions & 0 deletions include/linux/syscalls.h
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,8 @@ ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count);
int ksys_chdir(const char __user *filename);
int ksys_fchmod(unsigned int fd, umode_t mode);
int ksys_fchown(unsigned int fd, uid_t user, gid_t group);
int ksys_getdents64(unsigned int fd, struct linux_dirent64 __user *dirent,
unsigned int count);

/*
* The following kernel syscall equivalents are just wrappers to fs-internal
Expand Down
4 changes: 2 additions & 2 deletions init/initramfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ static void __init clean_rootfs(void)
}

dirp = buf;
num = sys_getdents64(fd, dirp, BUF_SIZE);
num = ksys_getdents64(fd, dirp, BUF_SIZE);
while (num > 0) {
while (num > 0) {
struct kstat st;
Expand All @@ -599,7 +599,7 @@ static void __init clean_rootfs(void)
}
dirp = buf;
memset(buf, 0, BUF_SIZE);
num = sys_getdents64(fd, dirp, BUF_SIZE);
num = ksys_getdents64(fd, dirp, BUF_SIZE);
}

ksys_close(fd);
Expand Down

0 comments on commit 454dab3

Please sign in to comment.