+ path.dentry->d_op = &pipefs_dentry_operations;
+ d_instantiate(path.dentry, inode);
+
+ err = -ENFILE;
+ f = alloc_file(&path, FMODE_WRITE, &write_pipefifo_fops);
+ if (!f)
+ goto err_dentry;
+ f->f_mapping = inode->i_mapping;
+
+ f->f_flags = O_WRONLY | (flags & O_NONBLOCK);
+ f->f_version = 0;
+
+ return f;
+
+ err_dentry:
+ free_pipe_info(inode);
+ path_put(&path);
+ return ERR_PTR(err);
+
+ err_inode:
+ free_pipe_info(inode);
+ iput(inode);
+ err:
+ return ERR_PTR(err);
+}
+
+void free_write_pipe(struct file *f)
+{
+ free_pipe_info(f->f_dentry->d_inode);
+ path_put(&f->f_path);
+ put_filp(f);
+}
+
+struct file *create_read_pipe(struct file *wrf, int flags)
+{
+ /* Grab pipe from the writer */
+ struct file *f = alloc_file(&wrf->f_path, FMODE_READ,
+ &read_pipefifo_fops);
+ if (!f)
+ return ERR_PTR(-ENFILE);
+
+ path_get(&wrf->f_path);
+ f->f_flags = O_RDONLY | (flags & O_NONBLOCK);
+
+ return f;
+}
+
+int do_pipe_flags(int *fd, int flags)
+{
+ struct file *fw, *fr;
+ int error;
+ int fdw, fdr;
+
+ if (flags & ~(O_CLOEXEC | O_NONBLOCK))
+ return -EINVAL;
+
+ fw = create_write_pipe(flags);
+ if (IS_ERR(fw))
+ return PTR_ERR(fw);
+ fr = create_read_pipe(fw, flags);
+ error = PTR_ERR(fr);
+ if (IS_ERR(fr))
+ goto err_write_pipe;
+
+ error = get_unused_fd_flags(flags);