-/* $OpenBSD: linux_cdrom.c,v 1.11 2014/03/26 05:23:42 guenther Exp $ */
+/* $OpenBSD: linux_cdrom.c,v 1.12 2015/04/30 09:20:51 mpi Exp $ */
/*
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
* All rights reserved.
fdp = p->p_fd;
- if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
+ if ((fp = fd_getfile_mode(fdp, SCARG(uap, fd), FREAD|FWRITE)) == NULL)
return (EBADF);
FREF(fp);
- if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
- error = EBADF;
- goto out;
- }
-
com = SCARG(uap, com);
retval[0] = 0;
-/* $OpenBSD: linux_termios.c,v 1.17 2014/03/26 05:23:42 guenther Exp $ */
+/* $OpenBSD: linux_termios.c,v 1.18 2015/04/30 09:20:51 mpi Exp $ */
/* $NetBSD: linux_termios.c,v 1.3 1996/04/05 00:01:54 christos Exp $ */
/*
int error = 0;
fdp = p->p_fd;
- if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
+ if ((fp = fd_getfile_mode(fdp, SCARG(uap, fd), FREAD|FWRITE)) == NULL)
return (EBADF);
FREF(fp);
- if ((fp->f_flag & (FREAD | FWRITE)) == 0) {
- error = EBADF;
- goto out;
- }
-
com = SCARG(uap, com);
retval[0] = 0;
-/* $OpenBSD: kern_descrip.c,v 1.117 2015/03/14 03:38:50 jsg Exp $ */
+/* $OpenBSD: kern_descrip.c,v 1.118 2015/04/30 09:20:51 mpi Exp $ */
/* $NetBSD: kern_descrip.c,v 1.42 1996/03/30 22:24:38 christos Exp $ */
/*
return (fp);
}
+struct file *
+fd_getfile_mode(struct filedesc *fdp, int fd, int mode)
+{
+ struct file *fp;
+
+ KASSERT(mode != 0);
+
+ fp = fd_getfile(fdp, fd);
+
+ if ((fp->f_flag & mode) == 0)
+ return (NULL);
+
+ return (fp);
+}
+
/*
* System calls on descriptors.
*/
-/* $OpenBSD: sys_generic.c,v 1.96 2015/02/12 22:27:04 millert Exp $ */
+/* $OpenBSD: sys_generic.c,v 1.97 2015/04/30 09:20:51 mpi Exp $ */
/* $NetBSD: sys_generic.c,v 1.24 1996/03/29 00:25:32 cgd Exp $ */
/*
struct file *fp;
struct filedesc *fdp = p->p_fd;
- if ((fp = fd_getfile(fdp, fd)) == NULL)
- return (EBADF);
- if ((fp->f_flag & FREAD) == 0)
+ if ((fp = fd_getfile_mode(fdp, fd, FREAD)) == NULL)
return (EBADF);
iov.iov_base = SCARG(uap, buf);
struct file *fp;
struct filedesc *fdp = p->p_fd;
- if ((fp = fd_getfile(fdp, fd)) == NULL)
- return (EBADF);
- if ((fp->f_flag & FREAD) == 0)
+ if ((fp = fd_getfile_mode(fdp, fd, FREAD)) == NULL)
return (EBADF);
-
FREF(fp);
/* dofilereadv() will FRELE the descriptor for us */
struct file *fp;
struct filedesc *fdp = p->p_fd;
- if ((fp = fd_getfile(fdp, fd)) == NULL)
- return (EBADF);
- if ((fp->f_flag & FWRITE) == 0)
+ if ((fp = fd_getfile_mode(fdp, fd, FWRITE)) == NULL)
return (EBADF);
iov.iov_base = (void *)SCARG(uap, buf);
struct file *fp;
struct filedesc *fdp = p->p_fd;
- if ((fp = fd_getfile(fdp, fd)) == NULL)
+ if ((fp = fd_getfile_mode(fdp, fd, FWRITE)) == NULL)
return (EBADF);
- if ((fp->f_flag & FWRITE) == 0)
- return (EBADF);
-
FREF(fp);
/* dofilewritev() will FRELE the descriptor for us */
long long stkbuf[STK_PARAMS / sizeof(long long)];
fdp = p->p_fd;
- if ((fp = fd_getfile(fdp, SCARG(uap, fd))) == NULL)
- return (EBADF);
-
- if ((fp->f_flag & (FREAD | FWRITE)) == 0)
+ if ((fp = fd_getfile_mode(fdp, SCARG(uap, fd), FREAD|FWRITE)) == NULL)
return (EBADF);
switch (com = SCARG(uap, com)) {
-/* $OpenBSD: vfs_syscalls.c,v 1.218 2015/04/17 04:43:20 guenther Exp $ */
+/* $OpenBSD: vfs_syscalls.c,v 1.219 2015/04/30 09:20:51 mpi Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.71 1996/04/23 10:29:02 mycroft Exp $ */
/*
off_t offset;
int fd = SCARG(uap, fd);
- if ((fp = fd_getfile(fdp, fd)) == NULL)
- return (EBADF);
- if ((fp->f_flag & FREAD) == 0)
+ if ((fp = fd_getfile_mode(fdp, fd, FREAD)) == NULL)
return (EBADF);
vp = (struct vnode *)fp->f_data;
off_t offset;
int fd = SCARG(uap, fd);
- if ((fp = fd_getfile(fdp, fd)) == NULL)
- return (EBADF);
- if ((fp->f_flag & FREAD) == 0)
+ if ((fp = fd_getfile_mode(fdp, fd, FREAD)) == NULL)
return (EBADF);
vp = (struct vnode *)fp->f_data;
off_t offset;
int fd = SCARG(uap, fd);
- if ((fp = fd_getfile(fdp, fd)) == NULL)
- return (EBADF);
- if ((fp->f_flag & FWRITE) == 0)
+ if ((fp = fd_getfile_mode(fdp, fd, FWRITE)) == NULL)
return (EBADF);
vp = (struct vnode *)fp->f_data;
off_t offset;
int fd = SCARG(uap, fd);
- if ((fp = fd_getfile(fdp, fd)) == NULL)
- return (EBADF);
- if ((fp->f_flag & FWRITE) == 0)
+ if ((fp = fd_getfile_mode(fdp, fd, FWRITE)) == NULL)
return (EBADF);
vp = (struct vnode *)fp->f_data;
-/* $OpenBSD: filedesc.h,v 1.28 2014/05/15 03:52:25 guenther Exp $ */
+/* $OpenBSD: filedesc.h,v 1.29 2015/04/30 09:20:51 mpi Exp $ */
/* $NetBSD: filedesc.h,v 1.14 1996/04/09 20:55:28 cgd Exp $ */
/*
int fdrelease(struct proc *p, int);
void fdremove(struct filedesc *, int);
void fdcloseexec(struct proc *);
-struct file *fd_getfile(struct filedesc *, int fd);
+struct file *fd_getfile(struct filedesc *, int);
+struct file *fd_getfile_mode(struct filedesc *, int, int);
int closef(struct file *, struct proc *);
int getsock(struct filedesc *, int, struct file **);