Annotation of researchv10no/sys/fs/pipe.c, revision 1.1.1.1

1.1       root        1: #include "sys/param.h"
                      2: #include "sys/systm.h"
                      3: #include "sys/user.h"
                      4: #include "sys/inode.h"
                      5: #include "sys/file.h"
                      6: #include "sys/proc.h"
                      7: #include "sys/stream.h"
                      8: #include "sys/stat.h"
                      9: #include "sys/conf.h"
                     10: 
                     11: static struct inode *mkpipend();
                     12: extern struct streamtab nilinfo;
                     13: 
                     14: #define        PIPFSTYP        6               /* until we do it right */
                     15: 
                     16: /*
                     17:  * The sys-pipe entry.
                     18:  * Allocate 2 open inodes, stream them, and splice them together
                     19:  */
                     20: pipe()
                     21: {
                     22:        struct inode *ip1, *ip2;
                     23:        register struct file *rf, *wf;
                     24:        register r;
                     25: 
                     26:        rf = falloc();
                     27:        if(rf == NULL)
                     28:                return;
                     29:        r = u.u_r.r_val1;
                     30:        wf = falloc();
                     31:        if(wf == NULL) {
                     32:                rf->f_count = 0;
                     33:                u.u_ofile[r] = NULL;
                     34:                return;
                     35:        }
                     36:        u.u_r.r_val2 = u.u_r.r_val1;
                     37:        u.u_r.r_val1 = r;
                     38:        if (makepipe(&ip1, &ip2)==0) {
                     39:                rf->f_count = 0;
                     40:                wf->f_count = 0;
                     41:                u.u_ofile[u.u_r.r_val1] = NULL;
                     42:                u.u_ofile[u.u_r.r_val2] = NULL;
                     43:                return;
                     44:        }
                     45:        wf->f_flag = FREAD|FWRITE;
                     46:        wf->f_inode = ip1;
                     47:        rf->f_flag = FREAD|FWRITE;
                     48:        rf->f_inode = ip2;
                     49: }
                     50: 
                     51: /*
                     52:  * also called by connld, unfortunately
                     53:  */
                     54: makepipe(ip1, ip2)
                     55: struct inode **ip1, **ip2;
                     56: {
                     57:        register struct inode *i1, *i2;
                     58: 
                     59:        if (nfstyp <= PIPFSTYP || fstypsw[PIPFSTYP] == NULL) {  /* config error */
                     60:                u.u_error = ENODEV;
                     61:                return (0);
                     62:        }
                     63:        i1 = mkpipend();
                     64:        i2 = mkpipend();
                     65:        if (i1==NULL || i2==NULL) {
                     66:                if (i1)
                     67:                        iput(i1);
                     68:                if (i2)
                     69:                        iput(i2);
                     70:                return(0);
                     71:        }
                     72:        qdetach(RD(i1->i_sptr->wrq->next), 1);
                     73:        i1->i_sptr->wrq->next = RD(i2->i_sptr->wrq);
                     74:        qdetach(RD(i2->i_sptr->wrq->next), 1);
                     75:        i2->i_sptr->wrq->next = RD(i1->i_sptr->wrq);
                     76:        *ip1 = i1;
                     77:        *ip2 = i2;
                     78:        return(1);
                     79: }
                     80: 
                     81: static struct inode *
                     82: mkpipend()
                     83: {
                     84:        register struct inode *ip;
                     85: 
                     86:        if ((ip = iuniq(PIPFSTYP)) == NULL)
                     87:                return(NULL);
                     88:        if ((ip = stopen(&nilinfo, NODEV, 0, ip)) == NULL)
                     89:                return(NULL);
                     90:        ip->i_flag |= IOPEN;            /* white lie */
                     91:        prele(ip);
                     92:        return(ip);
                     93: }
                     94: 
                     95: /*
                     96:  * pipe file system:
                     97:  * exists just so pipe creation is fast
                     98:  * inodes are in-core only
                     99:  * must be configured, but can't be mounted,
                    100:  * which is a little unfortunate
                    101:  * only stat exists
                    102:  */
                    103: 
                    104: static int pipstat();
                    105: struct fstypsw pipfs =
                    106:        fsinit(nulldev, nulldev, nodev, nodev, nodev, pipstat,
                    107:        nullnami, nodev, nodev, nullopen, nodev);
                    108: 
                    109: static
                    110: pipstat(ip, ub)
                    111:        register struct inode *ip;
                    112:        struct stat *ub;
                    113: {
                    114:        struct stat ds;
                    115: 
                    116:        ds.st_dev = ip->i_dev;
                    117:        ds.st_ino = ip->i_number;
                    118:        ds.st_mode = ip->i_mode;
                    119:        ds.st_nlink = 0;
                    120:        ds.st_uid = ip->i_uid;
                    121:        ds.st_gid = ip->i_gid;
                    122:        ds.st_size = 0;
                    123:        ds.st_atime = time;
                    124:        ds.st_mtime = time;
                    125:        ds.st_ctime = time;
                    126:        if (copyout((caddr_t)&ds, (caddr_t)ub, sizeof(ds)) < 0)
                    127:                u.u_error = EFAULT;
                    128: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.