diff options
Diffstat (limited to 'fs/pipe.c')
-rw-r--r-- | fs/pipe.c | 86 |
1 files changed, 32 insertions, 54 deletions
@@ -777,45 +777,10 @@ pipe_rdwr_open(struct inode *inode, struct file *filp) | |||
777 | /* | 777 | /* |
778 | * The file_operations structs are not static because they | 778 | * The file_operations structs are not static because they |
779 | * are also used in linux/fs/fifo.c to do operations on FIFOs. | 779 | * are also used in linux/fs/fifo.c to do operations on FIFOs. |
780 | * | ||
781 | * Pipes reuse fifos' file_operations structs. | ||
780 | */ | 782 | */ |
781 | const struct file_operations read_fifo_fops = { | 783 | const struct file_operations read_pipefifo_fops = { |
782 | .llseek = no_llseek, | ||
783 | .read = do_sync_read, | ||
784 | .aio_read = pipe_read, | ||
785 | .write = bad_pipe_w, | ||
786 | .poll = pipe_poll, | ||
787 | .unlocked_ioctl = pipe_ioctl, | ||
788 | .open = pipe_read_open, | ||
789 | .release = pipe_read_release, | ||
790 | .fasync = pipe_read_fasync, | ||
791 | }; | ||
792 | |||
793 | const struct file_operations write_fifo_fops = { | ||
794 | .llseek = no_llseek, | ||
795 | .read = bad_pipe_r, | ||
796 | .write = do_sync_write, | ||
797 | .aio_write = pipe_write, | ||
798 | .poll = pipe_poll, | ||
799 | .unlocked_ioctl = pipe_ioctl, | ||
800 | .open = pipe_write_open, | ||
801 | .release = pipe_write_release, | ||
802 | .fasync = pipe_write_fasync, | ||
803 | }; | ||
804 | |||
805 | const struct file_operations rdwr_fifo_fops = { | ||
806 | .llseek = no_llseek, | ||
807 | .read = do_sync_read, | ||
808 | .aio_read = pipe_read, | ||
809 | .write = do_sync_write, | ||
810 | .aio_write = pipe_write, | ||
811 | .poll = pipe_poll, | ||
812 | .unlocked_ioctl = pipe_ioctl, | ||
813 | .open = pipe_rdwr_open, | ||
814 | .release = pipe_rdwr_release, | ||
815 | .fasync = pipe_rdwr_fasync, | ||
816 | }; | ||
817 | |||
818 | static const struct file_operations read_pipe_fops = { | ||
819 | .llseek = no_llseek, | 784 | .llseek = no_llseek, |
820 | .read = do_sync_read, | 785 | .read = do_sync_read, |
821 | .aio_read = pipe_read, | 786 | .aio_read = pipe_read, |
@@ -827,7 +792,7 @@ static const struct file_operations read_pipe_fops = { | |||
827 | .fasync = pipe_read_fasync, | 792 | .fasync = pipe_read_fasync, |
828 | }; | 793 | }; |
829 | 794 | ||
830 | static const struct file_operations write_pipe_fops = { | 795 | const struct file_operations write_pipefifo_fops = { |
831 | .llseek = no_llseek, | 796 | .llseek = no_llseek, |
832 | .read = bad_pipe_r, | 797 | .read = bad_pipe_r, |
833 | .write = do_sync_write, | 798 | .write = do_sync_write, |
@@ -839,7 +804,7 @@ static const struct file_operations write_pipe_fops = { | |||
839 | .fasync = pipe_write_fasync, | 804 | .fasync = pipe_write_fasync, |
840 | }; | 805 | }; |
841 | 806 | ||
842 | static const struct file_operations rdwr_pipe_fops = { | 807 | const struct file_operations rdwr_pipefifo_fops = { |
843 | .llseek = no_llseek, | 808 | .llseek = no_llseek, |
844 | .read = do_sync_read, | 809 | .read = do_sync_read, |
845 | .aio_read = pipe_read, | 810 | .aio_read = pipe_read, |
@@ -927,7 +892,7 @@ static struct inode * get_pipe_inode(void) | |||
927 | inode->i_pipe = pipe; | 892 | inode->i_pipe = pipe; |
928 | 893 | ||
929 | pipe->readers = pipe->writers = 1; | 894 | pipe->readers = pipe->writers = 1; |
930 | inode->i_fop = &rdwr_pipe_fops; | 895 | inode->i_fop = &rdwr_pipefifo_fops; |
931 | 896 | ||
932 | /* | 897 | /* |
933 | * Mark the inode dirty from the very beginning, | 898 | * Mark the inode dirty from the very beginning, |
@@ -950,7 +915,7 @@ fail_inode: | |||
950 | return NULL; | 915 | return NULL; |
951 | } | 916 | } |
952 | 917 | ||
953 | struct file *create_write_pipe(void) | 918 | struct file *create_write_pipe(int flags) |
954 | { | 919 | { |
955 | int err; | 920 | int err; |
956 | struct inode *inode; | 921 | struct inode *inode; |
@@ -978,12 +943,12 @@ struct file *create_write_pipe(void) | |||
978 | d_instantiate(dentry, inode); | 943 | d_instantiate(dentry, inode); |
979 | 944 | ||
980 | err = -ENFILE; | 945 | err = -ENFILE; |
981 | f = alloc_file(pipe_mnt, dentry, FMODE_WRITE, &write_pipe_fops); | 946 | f = alloc_file(pipe_mnt, dentry, FMODE_WRITE, &write_pipefifo_fops); |
982 | if (!f) | 947 | if (!f) |
983 | goto err_dentry; | 948 | goto err_dentry; |
984 | f->f_mapping = inode->i_mapping; | 949 | f->f_mapping = inode->i_mapping; |
985 | 950 | ||
986 | f->f_flags = O_WRONLY; | 951 | f->f_flags = O_WRONLY | (flags & O_NONBLOCK); |
987 | f->f_version = 0; | 952 | f->f_version = 0; |
988 | 953 | ||
989 | return f; | 954 | return f; |
@@ -1007,7 +972,7 @@ void free_write_pipe(struct file *f) | |||
1007 | put_filp(f); | 972 | put_filp(f); |
1008 | } | 973 | } |
1009 | 974 | ||
1010 | struct file *create_read_pipe(struct file *wrf) | 975 | struct file *create_read_pipe(struct file *wrf, int flags) |
1011 | { | 976 | { |
1012 | struct file *f = get_empty_filp(); | 977 | struct file *f = get_empty_filp(); |
1013 | if (!f) | 978 | if (!f) |
@@ -1019,34 +984,37 @@ struct file *create_read_pipe(struct file *wrf) | |||
1019 | f->f_mapping = wrf->f_path.dentry->d_inode->i_mapping; | 984 | f->f_mapping = wrf->f_path.dentry->d_inode->i_mapping; |
1020 | 985 | ||
1021 | f->f_pos = 0; | 986 | f->f_pos = 0; |
1022 | f->f_flags = O_RDONLY; | 987 | f->f_flags = O_RDONLY | (flags & O_NONBLOCK); |
1023 | f->f_op = &read_pipe_fops; | 988 | f->f_op = &read_pipefifo_fops; |
1024 | f->f_mode = FMODE_READ; | 989 | f->f_mode = FMODE_READ; |
1025 | f->f_version = 0; | 990 | f->f_version = 0; |
1026 | 991 | ||
1027 | return f; | 992 | return f; |
1028 | } | 993 | } |
1029 | 994 | ||
1030 | int do_pipe(int *fd) | 995 | int do_pipe_flags(int *fd, int flags) |
1031 | { | 996 | { |
1032 | struct file *fw, *fr; | 997 | struct file *fw, *fr; |
1033 | int error; | 998 | int error; |
1034 | int fdw, fdr; | 999 | int fdw, fdr; |
1035 | 1000 | ||
1036 | fw = create_write_pipe(); | 1001 | if (flags & ~(O_CLOEXEC | O_NONBLOCK)) |
1002 | return -EINVAL; | ||
1003 | |||
1004 | fw = create_write_pipe(flags); | ||
1037 | if (IS_ERR(fw)) | 1005 | if (IS_ERR(fw)) |
1038 | return PTR_ERR(fw); | 1006 | return PTR_ERR(fw); |
1039 | fr = create_read_pipe(fw); | 1007 | fr = create_read_pipe(fw, flags); |
1040 | error = PTR_ERR(fr); | 1008 | error = PTR_ERR(fr); |
1041 | if (IS_ERR(fr)) | 1009 | if (IS_ERR(fr)) |
1042 | goto err_write_pipe; | 1010 | goto err_write_pipe; |
1043 | 1011 | ||
1044 | error = get_unused_fd(); | 1012 | error = get_unused_fd_flags(flags); |
1045 | if (error < 0) | 1013 | if (error < 0) |
1046 | goto err_read_pipe; | 1014 | goto err_read_pipe; |
1047 | fdr = error; | 1015 | fdr = error; |
1048 | 1016 | ||
1049 | error = get_unused_fd(); | 1017 | error = get_unused_fd_flags(flags); |
1050 | if (error < 0) | 1018 | if (error < 0) |
1051 | goto err_fdr; | 1019 | goto err_fdr; |
1052 | fdw = error; | 1020 | fdw = error; |
@@ -1074,16 +1042,21 @@ int do_pipe(int *fd) | |||
1074 | return error; | 1042 | return error; |
1075 | } | 1043 | } |
1076 | 1044 | ||
1045 | int do_pipe(int *fd) | ||
1046 | { | ||
1047 | return do_pipe_flags(fd, 0); | ||
1048 | } | ||
1049 | |||
1077 | /* | 1050 | /* |
1078 | * sys_pipe() is the normal C calling standard for creating | 1051 | * sys_pipe() is the normal C calling standard for creating |
1079 | * a pipe. It's not the way Unix traditionally does this, though. | 1052 | * a pipe. It's not the way Unix traditionally does this, though. |
1080 | */ | 1053 | */ |
1081 | asmlinkage long __weak sys_pipe(int __user *fildes) | 1054 | asmlinkage long __weak sys_pipe2(int __user *fildes, int flags) |
1082 | { | 1055 | { |
1083 | int fd[2]; | 1056 | int fd[2]; |
1084 | int error; | 1057 | int error; |
1085 | 1058 | ||
1086 | error = do_pipe(fd); | 1059 | error = do_pipe_flags(fd, flags); |
1087 | if (!error) { | 1060 | if (!error) { |
1088 | if (copy_to_user(fildes, fd, sizeof(fd))) { | 1061 | if (copy_to_user(fildes, fd, sizeof(fd))) { |
1089 | sys_close(fd[0]); | 1062 | sys_close(fd[0]); |
@@ -1094,6 +1067,11 @@ asmlinkage long __weak sys_pipe(int __user *fildes) | |||
1094 | return error; | 1067 | return error; |
1095 | } | 1068 | } |
1096 | 1069 | ||
1070 | asmlinkage long __weak sys_pipe(int __user *fildes) | ||
1071 | { | ||
1072 | return sys_pipe2(fildes, 0); | ||
1073 | } | ||
1074 | |||
1097 | /* | 1075 | /* |
1098 | * pipefs should _never_ be mounted by userland - too much of security hassle, | 1076 | * pipefs should _never_ be mounted by userland - too much of security hassle, |
1099 | * no real gain from having the whole whorehouse mounted. So we don't need | 1077 | * no real gain from having the whole whorehouse mounted. So we don't need |