mirror of
https://github.com/torvalds/linux.git
synced 2024-11-21 19:41:42 +00:00
introduce "fd_pos" class, convert fdget_pos() users to it.
fdget_pos() for constructor, fdput_pos() for cleanup, all users of fd..._pos() converted trivially. Reviewed-by: Christian Brauner <brauner@kernel.org> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
048181992c
commit
d7a9616ce0
@ -152,7 +152,7 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
|
|||||||
long __user *, basep)
|
long __user *, basep)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
struct fd arg = fdget_pos(fd);
|
CLASS(fd_pos, arg)(fd);
|
||||||
struct osf_dirent_callback buf = {
|
struct osf_dirent_callback buf = {
|
||||||
.ctx.actor = osf_filldir,
|
.ctx.actor = osf_filldir,
|
||||||
.dirent = dirent,
|
.dirent = dirent,
|
||||||
@ -160,7 +160,7 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
|
|||||||
.count = count
|
.count = count
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!fd_file(arg))
|
if (fd_empty(arg))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(fd_file(arg), &buf.ctx);
|
error = iterate_dir(fd_file(arg), &buf.ctx);
|
||||||
@ -169,7 +169,6 @@ SYSCALL_DEFINE4(osf_getdirentries, unsigned int, fd,
|
|||||||
if (count != buf.count)
|
if (count != buf.count)
|
||||||
error = count - buf.count;
|
error = count - buf.count;
|
||||||
|
|
||||||
fdput_pos(arg);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,8 +386,8 @@ EXPORT_SYMBOL(vfs_llseek);
|
|||||||
static off_t ksys_lseek(unsigned int fd, off_t offset, unsigned int whence)
|
static off_t ksys_lseek(unsigned int fd, off_t offset, unsigned int whence)
|
||||||
{
|
{
|
||||||
off_t retval;
|
off_t retval;
|
||||||
struct fd f = fdget_pos(fd);
|
CLASS(fd_pos, f)(fd);
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
retval = -EINVAL;
|
retval = -EINVAL;
|
||||||
@ -397,7 +397,6 @@ static off_t ksys_lseek(unsigned int fd, off_t offset, unsigned int whence)
|
|||||||
if (res != (loff_t)retval)
|
if (res != (loff_t)retval)
|
||||||
retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
|
retval = -EOVERFLOW; /* LFS: should only happen on 32 bit platforms */
|
||||||
}
|
}
|
||||||
fdput_pos(f);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,15 +419,14 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
|
|||||||
unsigned int, whence)
|
unsigned int, whence)
|
||||||
{
|
{
|
||||||
int retval;
|
int retval;
|
||||||
struct fd f = fdget_pos(fd);
|
CLASS(fd_pos, f)(fd);
|
||||||
loff_t offset;
|
loff_t offset;
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
retval = -EINVAL;
|
|
||||||
if (whence > SEEK_MAX)
|
if (whence > SEEK_MAX)
|
||||||
goto out_putf;
|
return -EINVAL;
|
||||||
|
|
||||||
offset = vfs_llseek(fd_file(f), ((loff_t) offset_high << 32) | offset_low,
|
offset = vfs_llseek(fd_file(f), ((loff_t) offset_high << 32) | offset_low,
|
||||||
whence);
|
whence);
|
||||||
@ -439,8 +437,6 @@ SYSCALL_DEFINE5(llseek, unsigned int, fd, unsigned long, offset_high,
|
|||||||
if (!copy_to_user(result, &offset, sizeof(offset)))
|
if (!copy_to_user(result, &offset, sizeof(offset)))
|
||||||
retval = 0;
|
retval = 0;
|
||||||
}
|
}
|
||||||
out_putf:
|
|
||||||
fdput_pos(f);
|
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -700,10 +696,10 @@ static inline loff_t *file_ppos(struct file *file)
|
|||||||
|
|
||||||
ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
|
ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct fd f = fdget_pos(fd);
|
CLASS(fd_pos, f)(fd);
|
||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
if (fd_file(f)) {
|
if (!fd_empty(f)) {
|
||||||
loff_t pos, *ppos = file_ppos(fd_file(f));
|
loff_t pos, *ppos = file_ppos(fd_file(f));
|
||||||
if (ppos) {
|
if (ppos) {
|
||||||
pos = *ppos;
|
pos = *ppos;
|
||||||
@ -712,7 +708,6 @@ ssize_t ksys_read(unsigned int fd, char __user *buf, size_t count)
|
|||||||
ret = vfs_read(fd_file(f), buf, count, ppos);
|
ret = vfs_read(fd_file(f), buf, count, ppos);
|
||||||
if (ret >= 0 && ppos)
|
if (ret >= 0 && ppos)
|
||||||
fd_file(f)->f_pos = pos;
|
fd_file(f)->f_pos = pos;
|
||||||
fdput_pos(f);
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -724,10 +719,10 @@ SYSCALL_DEFINE3(read, unsigned int, fd, char __user *, buf, size_t, count)
|
|||||||
|
|
||||||
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count)
|
ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count)
|
||||||
{
|
{
|
||||||
struct fd f = fdget_pos(fd);
|
CLASS(fd_pos, f)(fd);
|
||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
if (fd_file(f)) {
|
if (!fd_empty(f)) {
|
||||||
loff_t pos, *ppos = file_ppos(fd_file(f));
|
loff_t pos, *ppos = file_ppos(fd_file(f));
|
||||||
if (ppos) {
|
if (ppos) {
|
||||||
pos = *ppos;
|
pos = *ppos;
|
||||||
@ -736,7 +731,6 @@ ssize_t ksys_write(unsigned int fd, const char __user *buf, size_t count)
|
|||||||
ret = vfs_write(fd_file(f), buf, count, ppos);
|
ret = vfs_write(fd_file(f), buf, count, ppos);
|
||||||
if (ret >= 0 && ppos)
|
if (ret >= 0 && ppos)
|
||||||
fd_file(f)->f_pos = pos;
|
fd_file(f)->f_pos = pos;
|
||||||
fdput_pos(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -1075,10 +1069,10 @@ out:
|
|||||||
static ssize_t do_readv(unsigned long fd, const struct iovec __user *vec,
|
static ssize_t do_readv(unsigned long fd, const struct iovec __user *vec,
|
||||||
unsigned long vlen, rwf_t flags)
|
unsigned long vlen, rwf_t flags)
|
||||||
{
|
{
|
||||||
struct fd f = fdget_pos(fd);
|
CLASS(fd_pos, f)(fd);
|
||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
if (fd_file(f)) {
|
if (!fd_empty(f)) {
|
||||||
loff_t pos, *ppos = file_ppos(fd_file(f));
|
loff_t pos, *ppos = file_ppos(fd_file(f));
|
||||||
if (ppos) {
|
if (ppos) {
|
||||||
pos = *ppos;
|
pos = *ppos;
|
||||||
@ -1087,7 +1081,6 @@ static ssize_t do_readv(unsigned long fd, const struct iovec __user *vec,
|
|||||||
ret = vfs_readv(fd_file(f), vec, vlen, ppos, flags);
|
ret = vfs_readv(fd_file(f), vec, vlen, ppos, flags);
|
||||||
if (ret >= 0 && ppos)
|
if (ret >= 0 && ppos)
|
||||||
fd_file(f)->f_pos = pos;
|
fd_file(f)->f_pos = pos;
|
||||||
fdput_pos(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
@ -1099,10 +1092,10 @@ static ssize_t do_readv(unsigned long fd, const struct iovec __user *vec,
|
|||||||
static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec,
|
static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec,
|
||||||
unsigned long vlen, rwf_t flags)
|
unsigned long vlen, rwf_t flags)
|
||||||
{
|
{
|
||||||
struct fd f = fdget_pos(fd);
|
CLASS(fd_pos, f)(fd);
|
||||||
ssize_t ret = -EBADF;
|
ssize_t ret = -EBADF;
|
||||||
|
|
||||||
if (fd_file(f)) {
|
if (!fd_empty(f)) {
|
||||||
loff_t pos, *ppos = file_ppos(fd_file(f));
|
loff_t pos, *ppos = file_ppos(fd_file(f));
|
||||||
if (ppos) {
|
if (ppos) {
|
||||||
pos = *ppos;
|
pos = *ppos;
|
||||||
@ -1111,7 +1104,6 @@ static ssize_t do_writev(unsigned long fd, const struct iovec __user *vec,
|
|||||||
ret = vfs_writev(fd_file(f), vec, vlen, ppos, flags);
|
ret = vfs_writev(fd_file(f), vec, vlen, ppos, flags);
|
||||||
if (ret >= 0 && ppos)
|
if (ret >= 0 && ppos)
|
||||||
fd_file(f)->f_pos = pos;
|
fd_file(f)->f_pos = pos;
|
||||||
fdput_pos(f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
|
28
fs/readdir.c
28
fs/readdir.c
@ -219,20 +219,19 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
|
|||||||
struct old_linux_dirent __user *, dirent, unsigned int, count)
|
struct old_linux_dirent __user *, dirent, unsigned int, count)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
struct fd f = fdget_pos(fd);
|
CLASS(fd_pos, f)(fd);
|
||||||
struct readdir_callback buf = {
|
struct readdir_callback buf = {
|
||||||
.ctx.actor = fillonedir,
|
.ctx.actor = fillonedir,
|
||||||
.dirent = dirent
|
.dirent = dirent
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(fd_file(f), &buf.ctx);
|
error = iterate_dir(fd_file(f), &buf.ctx);
|
||||||
if (buf.result)
|
if (buf.result)
|
||||||
error = buf.result;
|
error = buf.result;
|
||||||
|
|
||||||
fdput_pos(f);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,7 +308,7 @@ efault:
|
|||||||
SYSCALL_DEFINE3(getdents, unsigned int, fd,
|
SYSCALL_DEFINE3(getdents, unsigned int, fd,
|
||||||
struct linux_dirent __user *, dirent, unsigned int, count)
|
struct linux_dirent __user *, dirent, unsigned int, count)
|
||||||
{
|
{
|
||||||
struct fd f;
|
CLASS(fd_pos, f)(fd);
|
||||||
struct getdents_callback buf = {
|
struct getdents_callback buf = {
|
||||||
.ctx.actor = filldir,
|
.ctx.actor = filldir,
|
||||||
.count = count,
|
.count = count,
|
||||||
@ -317,8 +316,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
|
|||||||
};
|
};
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
f = fdget_pos(fd);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(fd_file(f), &buf.ctx);
|
error = iterate_dir(fd_file(f), &buf.ctx);
|
||||||
@ -333,7 +331,6 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
|
|||||||
else
|
else
|
||||||
error = count - buf.count;
|
error = count - buf.count;
|
||||||
}
|
}
|
||||||
fdput_pos(f);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -392,7 +389,7 @@ efault:
|
|||||||
SYSCALL_DEFINE3(getdents64, unsigned int, fd,
|
SYSCALL_DEFINE3(getdents64, unsigned int, fd,
|
||||||
struct linux_dirent64 __user *, dirent, unsigned int, count)
|
struct linux_dirent64 __user *, dirent, unsigned int, count)
|
||||||
{
|
{
|
||||||
struct fd f;
|
CLASS(fd_pos, f)(fd);
|
||||||
struct getdents_callback64 buf = {
|
struct getdents_callback64 buf = {
|
||||||
.ctx.actor = filldir64,
|
.ctx.actor = filldir64,
|
||||||
.count = count,
|
.count = count,
|
||||||
@ -400,8 +397,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
|
|||||||
};
|
};
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
f = fdget_pos(fd);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(fd_file(f), &buf.ctx);
|
error = iterate_dir(fd_file(f), &buf.ctx);
|
||||||
@ -417,7 +413,6 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
|
|||||||
else
|
else
|
||||||
error = count - buf.count;
|
error = count - buf.count;
|
||||||
}
|
}
|
||||||
fdput_pos(f);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -477,20 +472,19 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
|
|||||||
struct compat_old_linux_dirent __user *, dirent, unsigned int, count)
|
struct compat_old_linux_dirent __user *, dirent, unsigned int, count)
|
||||||
{
|
{
|
||||||
int error;
|
int error;
|
||||||
struct fd f = fdget_pos(fd);
|
CLASS(fd_pos, f)(fd);
|
||||||
struct compat_readdir_callback buf = {
|
struct compat_readdir_callback buf = {
|
||||||
.ctx.actor = compat_fillonedir,
|
.ctx.actor = compat_fillonedir,
|
||||||
.dirent = dirent
|
.dirent = dirent
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!fd_file(f))
|
if (fd_empty(f))
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(fd_file(f), &buf.ctx);
|
error = iterate_dir(fd_file(f), &buf.ctx);
|
||||||
if (buf.result)
|
if (buf.result)
|
||||||
error = buf.result;
|
error = buf.result;
|
||||||
|
|
||||||
fdput_pos(f);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,7 +554,7 @@ efault:
|
|||||||
COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
|
COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
|
||||||
struct compat_linux_dirent __user *, dirent, unsigned int, count)
|
struct compat_linux_dirent __user *, dirent, unsigned int, count)
|
||||||
{
|
{
|
||||||
struct fd f;
|
CLASS(fd_pos, f)(fd);
|
||||||
struct compat_getdents_callback buf = {
|
struct compat_getdents_callback buf = {
|
||||||
.ctx.actor = compat_filldir,
|
.ctx.actor = compat_filldir,
|
||||||
.current_dir = dirent,
|
.current_dir = dirent,
|
||||||
@ -568,8 +562,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
|
|||||||
};
|
};
|
||||||
int error;
|
int error;
|
||||||
|
|
||||||
f = fdget_pos(fd);
|
if (fd_empty(f))
|
||||||
if (!fd_file(f))
|
|
||||||
return -EBADF;
|
return -EBADF;
|
||||||
|
|
||||||
error = iterate_dir(fd_file(f), &buf.ctx);
|
error = iterate_dir(fd_file(f), &buf.ctx);
|
||||||
@ -584,7 +577,6 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
|
|||||||
else
|
else
|
||||||
error = count - buf.count;
|
error = count - buf.count;
|
||||||
}
|
}
|
||||||
fdput_pos(f);
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -81,6 +81,7 @@ static inline void fdput_pos(struct fd f)
|
|||||||
|
|
||||||
DEFINE_CLASS(fd, struct fd, fdput(_T), fdget(fd), int fd)
|
DEFINE_CLASS(fd, struct fd, fdput(_T), fdget(fd), int fd)
|
||||||
DEFINE_CLASS(fd_raw, struct fd, fdput(_T), fdget_raw(fd), int fd)
|
DEFINE_CLASS(fd_raw, struct fd, fdput(_T), fdget_raw(fd), int fd)
|
||||||
|
DEFINE_CLASS(fd_pos, struct fd, fdput_pos(_T), fdget_pos(fd), int fd)
|
||||||
|
|
||||||
extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
|
extern int f_dupfd(unsigned int from, struct file *file, unsigned flags);
|
||||||
extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
|
extern int replace_fd(unsigned fd, struct file *file, unsigned flags);
|
||||||
|
Loading…
Reference in New Issue
Block a user