Annotation of linux/fs/pipe.c, revision 1.1

1.1     ! root        1: #include <signal.h>
        !             2: 
        !             3: #include <linux/sched.h>
        !             4: #include <linux/mm.h>  /* for get_free_page */
        !             5: #include <asm/segment.h>
        !             6: 
        !             7: int read_pipe(struct m_inode * inode, char * buf, int count)
        !             8: {
        !             9:        char * b=buf;
        !            10: 
        !            11:        while (PIPE_EMPTY(*inode)) {
        !            12:                wake_up(&inode->i_wait);
        !            13:                if (inode->i_count != 2) /* are there any writers left? */
        !            14:                        return 0;
        !            15:                sleep_on(&inode->i_wait);
        !            16:        }
        !            17:        while (count>0 && !(PIPE_EMPTY(*inode))) {
        !            18:                count --;
        !            19:                put_fs_byte(((char *)inode->i_size)[PIPE_TAIL(*inode)],b++);
        !            20:                INC_PIPE( PIPE_TAIL(*inode) );
        !            21:        }
        !            22:        wake_up(&inode->i_wait);
        !            23:        return b-buf;
        !            24: }
        !            25:        
        !            26: int write_pipe(struct m_inode * inode, char * buf, int count)
        !            27: {
        !            28:        char * b=buf;
        !            29: 
        !            30:        wake_up(&inode->i_wait);
        !            31:        if (inode->i_count != 2) { /* no readers */
        !            32:                current->signal |= (1<<(SIGPIPE-1));
        !            33:                return -1;
        !            34:        }
        !            35:        while (count-->0) {
        !            36:                while (PIPE_FULL(*inode)) {
        !            37:                        wake_up(&inode->i_wait);
        !            38:                        if (inode->i_count != 2) {
        !            39:                                current->signal |= (1<<(SIGPIPE-1));
        !            40:                                return b-buf;
        !            41:                        }
        !            42:                        sleep_on(&inode->i_wait);
        !            43:                }
        !            44:                ((char *)inode->i_size)[PIPE_HEAD(*inode)] = get_fs_byte(b++);
        !            45:                INC_PIPE( PIPE_HEAD(*inode) );
        !            46:                wake_up(&inode->i_wait);
        !            47:        }
        !            48:        wake_up(&inode->i_wait);
        !            49:        return b-buf;
        !            50: }
        !            51: 
        !            52: int sys_pipe(unsigned long * fildes)
        !            53: {
        !            54:        struct m_inode * inode;
        !            55:        struct file * f[2];
        !            56:        int fd[2];
        !            57:        int i,j;
        !            58: 
        !            59:        j=0;
        !            60:        for(i=0;j<2 && i<NR_FILE;i++)
        !            61:                if (!file_table[i].f_count)
        !            62:                        (f[j++]=i+file_table)->f_count++;
        !            63:        if (j==1)
        !            64:                f[0]->f_count=0;
        !            65:        if (j<2)
        !            66:                return -1;
        !            67:        j=0;
        !            68:        for(i=0;j<2 && i<NR_OPEN;i++)
        !            69:                if (!current->filp[i]) {
        !            70:                        current->filp[ fd[j]=i ] = f[j];
        !            71:                        j++;
        !            72:                }
        !            73:        if (j==1)
        !            74:                current->filp[fd[0]]=NULL;
        !            75:        if (j<2) {
        !            76:                f[0]->f_count=f[1]->f_count=0;
        !            77:                return -1;
        !            78:        }
        !            79:        if (!(inode=get_pipe_inode())) {
        !            80:                current->filp[fd[0]] =
        !            81:                        current->filp[fd[1]] = NULL;
        !            82:                f[0]->f_count = f[1]->f_count = 0;
        !            83:                return -1;
        !            84:        }
        !            85:        f[0]->f_inode = f[1]->f_inode = inode;
        !            86:        f[0]->f_pos = f[1]->f_pos = 0;
        !            87:        f[0]->f_mode = 1;               /* read */
        !            88:        f[1]->f_mode = 2;               /* write */
        !            89:        put_fs_long(fd[0],0+fildes);
        !            90:        put_fs_long(fd[1],1+fildes);
        !            91:        return 0;
        !            92: }

unix.superglobalmegacorp.com

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