-.\" $OpenBSD: file.9,v 1.13 2015/04/30 11:46:16 millert Exp $
+.\" $OpenBSD: file.9,v 1.14 2015/05/06 08:52:17 mpi Exp $
.\"
.\" Copyright (c) 2002 Artur Grabowski <art@openbsd.org>
.\" All rights reserved.
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: April 30 2015 $
+.Dd $Mdocdate: May 6 2015 $
.Dt FILE 9
.Os
.Sh NAME
.Ft struct file *
.Fn fd_getfile "struct filedesc *fdp" "int fd"
.Ft int
-.Fn getsock "struct filedesc *fdp" "int fd" "struct file **fpp"
+.Fn getsock "struct proc *p" "int fd" "struct file **fpp"
.In sys/file.h
.In sys/filedesc.h
.In sys/vnode.h
.Pp
The files are extracted from the file descriptor table using the
functions
-.Fn fd_getfile ,
-.Fn getvnode
+.Fn fd_getfile
and
-.Fn getsock .
+.Fn getvnode .
.Fn fd_getfile
performs all necessary checks to see if the file descriptor number is
within the range of file descriptor table, and if the descriptor is
valid.
-.Fn getsock
-and
.Fn getvnode
-are special cases that besides doing
+is a special case that besides doing
+.Fn fd_getfile
+also checks if the descriptor is a vnode, returns the proper
+errno on error and increases the use count with
+.Fn FREF .
+.Pp
+The files are extracted from the process context using the
+function
+.Fn getsock .
+.Fn getsock
+is a special case that besides doing
.Fn fd_getfile
-also check if the descriptor is a vnode or socket, return the proper
-errno on error and increase the use count with
+also checks if the descriptor is a socket, returns the proper
+errno on error and increases the use count with
.Fn FREF .
.Sh CONCURRENT ACCESS
Since multiple processes can share the same file descriptor table,
-/* $OpenBSD: uipc_syscalls.c,v 1.100 2015/03/14 03:38:51 jsg Exp $ */
+/* $OpenBSD: uipc_syscalls.c,v 1.101 2015/05/06 08:52:17 mpi Exp $ */
/* $NetBSD: uipc_syscalls.c,v 1.19 1996/02/09 19:00:48 christos Exp $ */
/*
struct mbuf *nam;
int error;
- if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
+ if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
return (error);
error = sockargs(&nam, SCARG(uap, name), SCARG(uap, namelen),
MT_SONAME);
struct file *fp;
int error;
- if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
+ if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
return (error);
error = solisten(fp->f_data, SCARG(uap, backlog));
FRELE(fp, p);
if (name && (error = copyin(anamelen, &namelen, sizeof (namelen))))
return (error);
- if ((error = getsock(fdp, sock, &fp)) != 0)
+ if ((error = getsock(p, sock, &fp)) != 0)
return (error);
headfp = fp;
s = splsoftnet();
struct mbuf *nam = NULL;
int error, s;
- if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
+ if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
return (error);
so = fp->f_data;
if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
to = NULL;
- if ((error = getsock(p->p_fd, s, &fp)) != 0)
+ if ((error = getsock(p, s, &fp)) != 0)
return (error);
auio.uio_iov = mp->msg_iov;
auio.uio_iovcnt = mp->msg_iovlen;
int iovlen = 0;
#endif
- if ((error = getsock(p->p_fd, s, &fp)) != 0)
+ if ((error = getsock(p, s, &fp)) != 0)
return (error);
auio.uio_iov = mp->msg_iov;
auio.uio_iovcnt = mp->msg_iovlen;
struct file *fp;
int error;
- if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
+ if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
return (error);
error = soshutdown(fp->f_data, SCARG(uap, how));
FRELE(fp, p);
struct mbuf *m = NULL;
int error;
- if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
+ if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
return (error);
if (SCARG(uap, valsize) > MCLBYTES) {
error = EINVAL;
socklen_t valsize;
int error;
- if ((error = getsock(p->p_fd, SCARG(uap, s), &fp)) != 0)
+ if ((error = getsock(p, SCARG(uap, s), &fp)) != 0)
return (error);
if (SCARG(uap, val)) {
error = copyin(SCARG(uap, avalsize),
socklen_t len;
int error;
- if ((error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) != 0)
+ if ((error = getsock(p, SCARG(uap, fdes), &fp)) != 0)
return (error);
error = copyin(SCARG(uap, alen), &len, sizeof (len));
if (error)
socklen_t len;
int error;
- if ((error = getsock(p->p_fd, SCARG(uap, fdes), &fp)) != 0)
+ if ((error = getsock(p, SCARG(uap, fdes), &fp)) != 0)
return (error);
so = fp->f_data;
if ((so->so_state & SS_ISCONNECTED) == 0) {
}
int
-getsock(struct filedesc *fdp, int fdes, struct file **fpp)
+getsock(struct proc *p, int fdes, struct file **fpp)
{
struct file *fp;
- if ((fp = fd_getfile(fdp, fdes)) == NULL)
+ if ((fp = fd_getfile(p->p_fd, fdes)) == NULL)
return (EBADF);
if (fp->f_type != DTYPE_SOCKET)
return (ENOTSOCK);