blkflush is no longer used;
[unix-history] / usr / src / sys / kern / uipc_usrreq.c
index ea544ab..15b7f32 100644 (file)
@@ -1,6 +1,4 @@
 /*
 /*
- * Copyright (c) 1982, 1986 Regents of the University of California.
- * All rights reserved.
  *
  * Redistribution and use in source and binary forms are permitted
  * provided that the above copyright notice and this paragraph are
  *
  * Redistribution and use in source and binary forms are permitted
  * provided that the above copyright notice and this paragraph are
  * from this software without specific prior written permission.
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * from this software without specific prior written permission.
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  *
- *     @(#)uipc_usrreq.c       7.7 (Berkeley) %G%
+ *     @(#)uipc_usrreq.c       7.13 (Berkeley) %G%
  */
 
 #include "param.h"
  */
 
 #include "param.h"
-#include "dir.h"
 #include "user.h"
 #include "user.h"
-#include "mbuf.h"
 #include "domain.h"
 #include "protosw.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "unpcb.h"
 #include "un.h"
 #include "domain.h"
 #include "protosw.h"
 #include "socket.h"
 #include "socketvar.h"
 #include "unpcb.h"
 #include "un.h"
-#include "inode.h"
+#include "vnode.h"
+#include "mount.h"
 #include "file.h"
 #include "stat.h"
 #include "file.h"
 #include "stat.h"
+#include "mbuf.h"      /* XXX must appear after mount.h */
 
 /*
  * Unix communications domain.
 
 /*
  * Unix communications domain.
@@ -39,8 +37,8 @@
  *     rethink name space problems
  *     need a proper out-of-band
  */
  *     rethink name space problems
  *     need a proper out-of-band
  */
-struct sockaddr sun_noname = { AF_UNIX };
-ino_t  unp_ino;                        /* prototype for fake inode numbers */
+struct sockaddr sun_noname = { sizeof(sun_noname), AF_UNIX };
+ino_t  unp_vno;                        /* prototype for fake vnode numbers */
 
 /*ARGSUSED*/
 uipc_usrreq(so, req, m, nam, rights)
 
 /*ARGSUSED*/
 uipc_usrreq(so, req, m, nam, rights)
@@ -81,7 +79,7 @@ uipc_usrreq(so, req, m, nam, rights)
                break;
 
        case PRU_LISTEN:
                break;
 
        case PRU_LISTEN:
-               if (unp->unp_inode == 0)
+               if (unp->unp_vnode == 0)
                        error = EINVAL;
                break;
 
                        error = EINVAL;
                break;
 
@@ -236,9 +234,9 @@ uipc_usrreq(so, req, m, nam, rights)
                        ((struct stat *) m)->st_blksize += so2->so_rcv.sb_cc;
                }
                ((struct stat *) m)->st_dev = NODEV;
                        ((struct stat *) m)->st_blksize += so2->so_rcv.sb_cc;
                }
                ((struct stat *) m)->st_dev = NODEV;
-               if (unp->unp_ino == 0)
-                       unp->unp_ino = unp_ino++;
-               ((struct stat *) m)->st_ino = unp->unp_ino;
+               if (unp->unp_vno == 0)
+                       unp->unp_vno = unp_vno++;
+               ((struct stat *) m)->st_ino = unp->unp_vno;
                return (0);
 
        case PRU_RCVOOB:
                return (0);
 
        case PRU_RCVOOB:
@@ -328,10 +326,10 @@ unp_detach(unp)
        register struct unpcb *unp;
 {
        
        register struct unpcb *unp;
 {
        
-       if (unp->unp_inode) {
-               unp->unp_inode->i_socket = 0;
-               irele(unp->unp_inode);
-               unp->unp_inode = 0;
+       if (unp->unp_vnode) {
+               unp->unp_vnode->v_socket = 0;
+               vrele(unp->unp_vnode);
+               unp->unp_vnode = 0;
        }
        if (unp->unp_conn)
                unp_disconnect(unp);
        }
        if (unp->unp_conn)
                unp_disconnect(unp);
@@ -350,36 +348,39 @@ unp_bind(unp, nam)
        struct mbuf *nam;
 {
        struct sockaddr_un *soun = mtod(nam, struct sockaddr_un *);
        struct mbuf *nam;
 {
        struct sockaddr_un *soun = mtod(nam, struct sockaddr_un *);
-       register struct inode *ip;
+       register struct vnode *vp;
        register struct nameidata *ndp = &u.u_nd;
        register struct nameidata *ndp = &u.u_nd;
+       struct vattr vattr;
        int error;
 
        ndp->ni_dirp = soun->sun_path;
        int error;
 
        ndp->ni_dirp = soun->sun_path;
-       if (unp->unp_inode != NULL || nam->m_len == MLEN)
+       if (unp->unp_vnode != NULL)
                return (EINVAL);
                return (EINVAL);
-       *(mtod(nam, caddr_t) + nam->m_len) = 0;
+       if (nam->m_len == MLEN) {
+               if (*(mtod(nam, caddr_t) + nam->m_len - 1) != 0)
+                       return (EINVAL);
+       } else
+               *(mtod(nam, caddr_t) + nam->m_len) = 0;
 /* SHOULD BE ABLE TO ADOPT EXISTING AND wakeup() ALA FIFO's */
 /* SHOULD BE ABLE TO ADOPT EXISTING AND wakeup() ALA FIFO's */
-       ndp->ni_nameiop = CREATE | FOLLOW;
+       ndp->ni_nameiop = CREATE | FOLLOW | LOCKPARENT;
        ndp->ni_segflg = UIO_SYSSPACE;
        ndp->ni_segflg = UIO_SYSSPACE;
-       ip = namei(ndp);
-       if (ip) {
-               iput(ip);
-               return (EADDRINUSE);
-       }
-       if (error = u.u_error) {
-               u.u_error = 0;                  /* XXX */
+       if (error = namei(ndp))
                return (error);
                return (error);
+       vp = ndp->ni_vp;
+       if (vp != NULL) {
+               VOP_ABORTOP(ndp);
+               return (EADDRINUSE);
        }
        }
-       ip = maknode(IFSOCK | 0777, ndp);
-       if (ip == NULL) {
-               error = u.u_error;              /* XXX */
-               u.u_error = 0;                  /* XXX */
+       vattr_null(&vattr);
+       vattr.va_type = VSOCK;
+       vattr.va_mode = 0777;
+       if (error = VOP_CREATE(ndp, &vattr))
                return (error);
                return (error);
-       }
-       ip->i_socket = unp->unp_socket;
-       unp->unp_inode = ip;
+       vp = ndp->ni_vp;
+       vp->v_socket = unp->unp_socket;
+       unp->unp_vnode = vp;
        unp->unp_addr = m_copy(nam, 0, (int)M_COPYALL);
        unp->unp_addr = m_copy(nam, 0, (int)M_COPYALL);
-       iunlock(ip);                    /* but keep reference */
+       VOP_UNLOCK(vp);
        return (0);
 }
 
        return (0);
 }
 
@@ -388,34 +389,30 @@ unp_connect(so, nam)
        struct mbuf *nam;
 {
        register struct sockaddr_un *soun = mtod(nam, struct sockaddr_un *);
        struct mbuf *nam;
 {
        register struct sockaddr_un *soun = mtod(nam, struct sockaddr_un *);
-       register struct inode *ip;
+       register struct vnode *vp;
        register struct socket *so2, *so3;
        register struct nameidata *ndp = &u.u_nd;
        struct unpcb *unp2, *unp3;
        int error;
 
        ndp->ni_dirp = soun->sun_path;
        register struct socket *so2, *so3;
        register struct nameidata *ndp = &u.u_nd;
        struct unpcb *unp2, *unp3;
        int error;
 
        ndp->ni_dirp = soun->sun_path;
-       if (nam->m_len + (nam->m_off - MMINOFF) == MLEN)
-               return (EMSGSIZE);
-       *(mtod(nam, caddr_t) + nam->m_len) = 0;
-       ndp->ni_nameiop = LOOKUP | FOLLOW;
+       if (nam->m_data + nam->m_len == &nam->m_dat[MLEN]) {    /* XXX */
+               if (*(mtod(nam, caddr_t) + nam->m_len - 1) != 0)
+                       return (EMSGSIZE);
+       } else
+               *(mtod(nam, caddr_t) + nam->m_len) = 0;
+       ndp->ni_nameiop = LOOKUP | FOLLOW | LOCKLEAF;
        ndp->ni_segflg = UIO_SYSSPACE;
        ndp->ni_segflg = UIO_SYSSPACE;
-       ip = namei(ndp);
-       if (ip == 0) {
-               error = u.u_error;
-               u.u_error = 0;
-               return (error);         /* XXX */
-       }
-       if (access(ip, IWRITE)) {
-               error = u.u_error;
-               u.u_error = 0;          /* XXX */
-               goto bad;
-       }
-       if ((ip->i_mode&IFMT) != IFSOCK) {
+       if (error = namei(ndp))
+               return (error);
+       vp = ndp->ni_vp;
+       if (vp->v_type != VSOCK) {
                error = ENOTSOCK;
                goto bad;
        }
                error = ENOTSOCK;
                goto bad;
        }
-       so2 = ip->i_socket;
+       if (error = VOP_ACCESS(vp, VWRITE, ndp->ni_cred))
+               goto bad;
+       so2 = vp->v_socket;
        if (so2 == 0) {
                error = ECONNREFUSED;
                goto bad;
        if (so2 == 0) {
                error = ECONNREFUSED;
                goto bad;
@@ -433,12 +430,13 @@ unp_connect(so, nam)
                unp2 = sotounpcb(so2);
                unp3 = sotounpcb(so3);
                if (unp2->unp_addr)
                unp2 = sotounpcb(so2);
                unp3 = sotounpcb(so3);
                if (unp2->unp_addr)
-                       unp3->unp_addr = m_copy(unp2->unp_addr, 0, M_COPYALL);
+                       unp3->unp_addr =
+                                 m_copy(unp2->unp_addr, 0, (int)M_COPYALL);
                so2 = so3;
        }
        error = unp_connect2(so, so2);
 bad:
                so2 = so3;
        }
        error = unp_connect2(so, so2);
 bad:
-       iput(ip);
+       vput(vp);
        return (error);
 }
 
        return (error);
 }
 
@@ -566,8 +564,7 @@ unp_externalize(rights)
                return (EMSGSIZE);
        }
        for (i = 0; i < newfds; i++) {
                return (EMSGSIZE);
        }
        for (i = 0; i < newfds; i++) {
-               f = ufalloc(0);
-               if (f < 0)
+               if (ufalloc(0, &f))
                        panic("unp_externalize");
                fp = *rp;
                u.u_ofile[f] = fp;
                        panic("unp_externalize");
                fp = *rp;
                u.u_ofile[f] = fp;
@@ -583,16 +580,18 @@ unp_internalize(rights)
 {
        register struct file **rp;
        int oldfds = rights->m_len / sizeof (int);
 {
        register struct file **rp;
        int oldfds = rights->m_len / sizeof (int);
-       register int i;
+       register int i, fd;
        register struct file *fp;
 
        rp = mtod(rights, struct file **);
        register struct file *fp;
 
        rp = mtod(rights, struct file **);
-       for (i = 0; i < oldfds; i++)
-               if (getf(*(int *)rp++) == 0)
+       for (i = 0; i < oldfds; i++) {
+               fd = *(int *)rp++;
+               if ((unsigned)fd >= NOFILE || u.u_ofile[fd] == NULL)
                        return (EBADF);
                        return (EBADF);
+       }
        rp = mtod(rights, struct file **);
        for (i = 0; i < oldfds; i++) {
        rp = mtod(rights, struct file **);
        for (i = 0; i < oldfds; i++) {
-               fp = getf(*(int *)rp);
+               fp = u.u_ofile[*(int *)rp];
                *rp++ = fp;
                fp->f_count++;
                fp->f_msgcount++;
                *rp++ = fp;
                fp->f_count++;
                fp->f_msgcount++;
@@ -701,5 +700,5 @@ unp_discard(fp)
 
        fp->f_msgcount--;
        unp_rights--;
 
        fp->f_msgcount--;
        unp_rights--;
-       closef(fp);
+       (void) closef(fp);
 }
 }