Annotation of linux/fs/fifo.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  *  linux/fs/fifo.c
                      3:  *
                      4:  *  written by Paul H. Hargrove
                      5:  */
                      6: 
                      7: #include <errno.h>
                      8: 
                      9: #include <linux/fcntl.h>
                     10: #include <linux/sched.h>
                     11: #include <linux/kernel.h>
                     12: 
                     13: extern struct file_operations read_pipe_fops;
                     14: extern struct file_operations write_pipe_fops;
                     15: extern struct file_operations rdwr_pipe_fops;
                     16: 
                     17: static int fifo_open(struct inode * inode,struct file * filp)
                     18: {
                     19:        int retval = 0;
                     20:        unsigned long page;
                     21: 
                     22:        switch( filp->f_mode ) {
                     23: 
                     24:        case 1:
                     25:        /*
                     26:         *  O_RDONLY
                     27:         *  POSIX.1 says that O_NONBLOCK means return with the FIFO
                     28:         *  opened, even when there is no process writing the FIFO.
                     29:         */
                     30:                filp->f_op = &read_pipe_fops;
                     31:                PIPE_READERS(*inode)++;
                     32:                if (!(filp->f_flags & O_NONBLOCK))
                     33:                        while (!PIPE_WRITERS(*inode)) {
                     34:                                if (PIPE_HEAD(*inode) != PIPE_TAIL(*inode))
                     35:                                        break;
                     36:                                if (current->signal & ~current->blocked) {
                     37:                                        retval = -ERESTARTSYS;
                     38:                                        break;
                     39:                                }
                     40:                                interruptible_sleep_on(&PIPE_READ_WAIT(*inode));
                     41:                        }
                     42:                if (retval)
                     43:                        PIPE_READERS(*inode)--;
                     44:                break;
                     45:        
                     46:        case 2:
                     47:        /*
                     48:         *  O_WRONLY
                     49:         *  POSIX.1 says that O_NONBLOCK means return -1 with
                     50:         *  errno=ENXIO when there is no process reading the FIFO.
                     51:         */
                     52:                if ((filp->f_flags & O_NONBLOCK) && !PIPE_READERS(*inode)) {
                     53:                        retval = -ENXIO;
                     54:                        break;
                     55:                }
                     56:                filp->f_op = &write_pipe_fops;
                     57:                PIPE_WRITERS(*inode)++;
                     58:                while (!PIPE_READERS(*inode)) {
                     59:                        if (current->signal & ~current->blocked) {
                     60:                                retval = -ERESTARTSYS;
                     61:                                break;
                     62:                        }
                     63:                        interruptible_sleep_on(&PIPE_WRITE_WAIT(*inode));
                     64:                }
                     65:                if (retval)
                     66:                        PIPE_WRITERS(*inode)--;
                     67:                break;
                     68:        
                     69:        case 3:
                     70:        /*
                     71:         *  O_RDWR
                     72:         *  POSIX.1 leaves this case "undefined" when O_NONBLOCK is set.
                     73:         *  This implementation will NEVER block on a O_RDWR open, since
                     74:         *  the process can at least talk to itself.
                     75:         */
                     76:                filp->f_op = &rdwr_pipe_fops;
                     77:                PIPE_WRITERS(*inode) += 1;
                     78:                PIPE_READERS(*inode) += 1;
                     79:                break;
                     80: 
                     81:        default:
                     82:                retval = -EINVAL;
                     83:        }
                     84:        if (PIPE_WRITERS(*inode))
                     85:                wake_up(&PIPE_READ_WAIT(*inode));
                     86:        if (PIPE_READERS(*inode))
                     87:                wake_up(&PIPE_WRITE_WAIT(*inode));
                     88:        if (retval || inode->i_size)
                     89:                return retval;
                     90:        page = get_free_page();
                     91:        if (inode->i_size) {
                     92:                free_page(page);
                     93:                return 0;
                     94:        }
                     95:        if (!page)
                     96:                return -ENOMEM;
                     97:        inode->i_size = page;
                     98:        return 0;
                     99: }
                    100: 
                    101: /*
                    102:  * Dummy default file-operations: the only thing this does
                    103:  * is contain the open that then fills in the correct operations
                    104:  * depending on the access mode of the file...
                    105:  */
                    106: struct file_operations def_fifo_fops = {
                    107:        NULL,
                    108:        NULL,
                    109:        NULL,
                    110:        NULL,
                    111:        NULL,
                    112:        NULL,
                    113:        fifo_open,              /* will set read or write pipe_fops */
                    114:        NULL
                    115: };

unix.superglobalmegacorp.com

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