9 #include <linux/poll.h>
10 #include <linux/slab.h>
11 #include <linux/module.h>
16 #include <linux/magic.h>
18 #include <linux/uio.h>
21 #include <linux/audit.h>
23 #include <linux/fcntl.h>
25 #include <asm/uaccess.h>
26 #include <asm/ioctls.h>
107 pipe_iov_copy_from_user(
void *to,
struct iovec *iov,
unsigned long len,
133 pipe_iov_copy_to_user(
struct iovec *iov,
const void *
from,
unsigned long len,
162 static int iov_fault_in_pages_write(
struct iovec *iov,
unsigned long len)
168 unsigned long this_len;
171 if (fault_in_pages_writeable(iov->
iov_base, this_len))
184 static void iov_fault_in_pages_read(
struct iovec *iov,
unsigned long len)
190 unsigned long this_len;
193 fault_in_pages_readable(iov->
iov_base, this_len);
209 if (page_count(page) == 1 && !pipe->
tmp_page)
276 struct page *page = buf->
page;
283 if (page_count(page) == 1) {
344 .release = anon_pipe_buf_release,
354 .release = anon_pipe_buf_release,
361 unsigned long nr_segs, loff_t
pos)
371 total_len = iov_length(iov, nr_segs);
383 int curbuf = pipe->
curbuf;
387 size_t chars = buf->
len;
390 if (chars > total_len)
393 error = ops->
confirm(pipe, buf);
400 atomic = !iov_fault_in_pages_write(iov, chars);
402 addr = ops->
map(pipe, buf, atomic);
403 error = pipe_iov_copy_to_user(iov, addr + buf->
offset, chars, atomic);
404 ops->
unmap(pipe, buf, addr);
430 curbuf = (curbuf + 1) & (pipe->
buffers - 1);
479 static inline int is_packetized(
struct file *
file)
485 pipe_write(
struct kiocb *iocb,
const struct iovec *_iov,
486 unsigned long nr_segs, loff_t ppos)
488 struct file *filp = iocb->
ki_filp;
489 struct inode *inode = filp->
f_path.dentry->d_inode;
497 total_len = iov_length(iov, nr_segs);
515 if (pipe->
nrbufs && chars != 0) {
523 int error, atomic = 1;
526 error = ops->
confirm(pipe, buf);
530 iov_fault_in_pages_read(iov, chars);
532 addr = ops->
map(pipe, buf, atomic);
533 error = pipe_iov_copy_from_user(offset + addr, iov,
535 ops->
unmap(pipe, buf, addr);
563 if (bufs < pipe->buffers) {
568 int error, atomic = 1;
585 if (chars > total_len)
588 iov_fault_in_pages_read(iov, chars);
595 error = pipe_iov_copy_from_user(src, iov, chars,
615 buf->
ops = &anon_pipe_buf_ops;
619 if (is_packetized(filp)) {
620 buf->
ops = &packet_pipe_buf_ops;
630 if (bufs < pipe->buffers)
666 bad_pipe_r(
struct file *filp,
char __user *buf,
size_t count, loff_t *ppos)
672 bad_pipe_w(
struct file *filp,
const char __user *buf,
size_t count,
678 static long pipe_ioctl(
struct file *filp,
unsigned int cmd,
unsigned long arg)
680 struct inode *inode = filp->
f_path.dentry->d_inode;
691 while (--nrbufs >= 0) {
693 buf = (buf+1) & (pipe->
buffers - 1);
697 return put_user(count, (
int __user *)arg);
708 struct inode *inode = filp->
f_path.dentry->d_inode;
712 poll_wait(filp, &pipe->
wait, wait);
737 pipe_release(
struct inode *inode,
int decr,
int decw)
759 pipe_read_fasync(
int fd,
struct file *filp,
int on)
761 struct inode *inode = filp->
f_path.dentry->d_inode;
773 pipe_write_fasync(
int fd,
struct file *filp,
int on)
775 struct inode *inode = filp->
f_path.dentry->d_inode;
787 pipe_rdwr_fasync(
int fd,
struct file *filp,
int on)
789 struct inode *inode = filp->
f_path.dentry->d_inode;
806 pipe_read_release(
struct inode *inode,
struct file *filp)
808 return pipe_release(inode, 1, 0);
812 pipe_write_release(
struct inode *inode,
struct file *filp)
814 return pipe_release(inode, 0, 1);
818 pipe_rdwr_release(
struct inode *inode,
struct file *filp)
824 return pipe_release(inode, decr, decw);
828 pipe_read_open(
struct inode *inode,
struct file *filp)
845 pipe_write_open(
struct inode *inode,
struct file *filp)
862 pipe_rdwr_open(
struct inode *inode,
struct file *filp)
890 .aio_read = pipe_read,
893 .unlocked_ioctl = pipe_ioctl,
894 .open = pipe_read_open,
895 .release = pipe_read_release,
896 .fasync = pipe_read_fasync,
903 .aio_write = pipe_write,
905 .unlocked_ioctl = pipe_ioctl,
906 .open = pipe_write_open,
907 .release = pipe_write_release,
908 .fasync = pipe_write_fasync,
914 .aio_read = pipe_read,
916 .aio_write = pipe_write,
918 .unlocked_ioctl = pipe_ioctl,
919 .open = pipe_rdwr_open,
920 .release = pipe_rdwr_release,
921 .fasync = pipe_rdwr_fasync,
948 for (i = 0; i < pipe->
buffers; i++) {
951 buf->
ops->release(pipe, buf);
977 .d_dname = pipefs_dname,
980 static struct inode * get_pipe_inode(
void)
1022 struct inode *inode = get_pipe_inode();
1025 static struct qstr name = { .
name =
"" };
1067 static int __do_pipe_flags(
int *fd,
struct file **
files,
int flags)
1089 audit_fd_pair(fdr, fdw);
1104 struct file *files[2];
1105 int error = __do_pipe_flags(fd, files, flags);
1119 struct file *files[2];
1123 error = __do_pipe_flags(fd, files, flags);
1148 static long pipe_set_size(
struct pipe_inode_info *pipe,
unsigned long nr_pages)
1158 if (nr_pages < pipe->nrbufs)
1174 if (tail < pipe->buffers)
1197 static inline unsigned int round_pipe_size(
unsigned int size)
1199 unsigned long nr_pages;
1210 size_t *lenp, loff_t *ppos)
1215 if (ret < 0 || !write)
1229 struct inode *
i = file->
f_path.dentry->d_inode;
1234 long pipe_fcntl(
struct file *file,
unsigned int cmd,
unsigned long arg)
1247 unsigned int size, nr_pages;
1249 size = round_pipe_size(arg);
1260 ret = pipe_set_size(pipe, nr_pages);
1288 int flags,
const char *dev_name,
void *
data)
1296 .mount = pipefs_mount,
1300 static int __init init_pipe_fs(
void)
1306 if (IS_ERR(pipe_mnt)) {
1307 err = PTR_ERR(pipe_mnt);