diff options
author | kib <kib@FreeBSD.org> | 2014-11-19 10:25:08 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2014-11-19 10:25:08 +0000 |
commit | 4e3006c33ee7bf8081f7e9bf81702b43c558511d (patch) | |
tree | 7d95eb469c07eaa85914f6fac156ca9a264c8f3f /sys/kern | |
parent | 9fcf944d2ab177691803626c24a94fa931a59d01 (diff) | |
download | FreeBSD-src-4e3006c33ee7bf8081f7e9bf81702b43c558511d.zip FreeBSD-src-4e3006c33ee7bf8081f7e9bf81702b43c558511d.tar.gz |
MFC r274438:
For posix_fallocate(2) and posix_fadvise(2), return ESPIPE
when underlying file does not have DFLAG_SEEKABLE set. For
posix_fallocate(2), simplify error handling logic.
Diffstat (limited to 'sys/kern')
-rw-r--r-- | sys/kern/vfs_syscalls.c | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index a2a2cfb..ccc3627a 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -4549,38 +4549,29 @@ kern_posix_fallocate(struct thread *td, int fd, off_t offset, off_t len) off_t olen, ooffset; int error; - fp = NULL; + if (offset < 0 || len <= 0) + return (EINVAL); + /* Check for wrap. */ + if (offset > OFF_MAX - len) + return (EFBIG); error = fget(td, fd, cap_rights_init(&rights, CAP_WRITE), &fp); if (error != 0) - goto out; - - switch (fp->f_type) { - case DTYPE_VNODE: - break; - case DTYPE_PIPE: - case DTYPE_FIFO: + return (error); + if ((fp->f_ops->fo_flags & DFLAG_SEEKABLE) == 0) { error = ESPIPE; goto out; - default: - error = ENODEV; - goto out; } if ((fp->f_flag & FWRITE) == 0) { error = EBADF; goto out; } - vp = fp->f_vnode; - if (vp->v_type != VREG) { + if (fp->f_type != DTYPE_VNODE) { error = ENODEV; goto out; } - if (offset < 0 || len <= 0) { - error = EINVAL; - goto out; - } - /* Check for wrap. */ - if (offset > OFF_MAX - len) { - error = EFBIG; + vp = fp->f_vnode; + if (vp->v_type != VREG) { + error = ENODEV; goto out; } @@ -4617,8 +4608,7 @@ kern_posix_fallocate(struct thread *td, int fd, off_t offset, off_t len) maybe_yield(); } out: - if (fp != NULL) - fdrop(fp, td); + fdrop(fp, td); return (error); } @@ -4668,15 +4658,11 @@ kern_posix_fadvise(struct thread *td, int fd, off_t offset, off_t len, error = fget(td, fd, cap_rights_init(&rights), &fp); if (error != 0) goto out; - - switch (fp->f_type) { - case DTYPE_VNODE: - break; - case DTYPE_PIPE: - case DTYPE_FIFO: + if ((fp->f_ops->fo_flags & DFLAG_SEEKABLE) == 0) { error = ESPIPE; goto out; - default: + } + if (fp->f_type != DTYPE_VNODE) { error = ENODEV; goto out; } |