blob: c8884f9712285b25cc88ff7518c2e0b79e0bcb39 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef _LINUX_PIPE_FS_I_H
2#define _LINUX_PIPE_FS_I_H
3
4#define PIPEFS_MAGIC 0x50495045
5
6#define PIPE_BUFFERS (16)
7
Jens Axboe14328732006-05-03 10:35:26 +02008#define PIPE_BUF_FLAG_LRU 0x01 /* page is on the LRU */
9#define PIPE_BUF_FLAG_ATOMIC 0x02 /* was atomically mapped */
10#define PIPE_BUF_FLAG_GIFT 0x04 /* page is a gift */
Jens Axboe3e7ee3e2006-04-02 23:11:04 +020011
Linus Torvalds1da177e2005-04-16 15:20:36 -070012struct pipe_buffer {
13 struct page *page;
14 unsigned int offset, len;
Eric Dumazetd4c3cca2006-12-13 00:34:04 -080015 const struct pipe_buf_operations *ops;
Jens Axboe3e7ee3e2006-04-02 23:11:04 +020016 unsigned int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070017};
18
Jens Axboe17374ff2007-06-04 15:03:12 +020019struct pipe_inode_info {
20 wait_queue_head_t wait;
21 unsigned int nrbufs, curbuf;
22 struct page *tmp_page;
23 unsigned int readers;
24 unsigned int writers;
25 unsigned int waiting_writers;
26 unsigned int r_counter;
27 unsigned int w_counter;
28 struct fasync_struct *fasync_readers;
29 struct fasync_struct *fasync_writers;
30 struct inode *inode;
31 struct pipe_buffer bufs[PIPE_BUFFERS];
32};
33
Jens Axboef84d7512006-05-01 19:59:03 +020034/*
35 * Note on the nesting of these functions:
36 *
37 * ->pin()
38 * ->steal()
39 * ...
40 * ->map()
41 * ...
42 * ->unmap()
43 *
44 * That is, ->map() must be called on a pinned buffer, same goes for ->steal().
45 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070046struct pipe_buf_operations {
47 int can_merge;
Jens Axboef6762b72006-05-01 20:02:05 +020048 void * (*map)(struct pipe_inode_info *, struct pipe_buffer *, int);
49 void (*unmap)(struct pipe_inode_info *, struct pipe_buffer *, void *);
Jens Axboef84d7512006-05-01 19:59:03 +020050 int (*pin)(struct pipe_inode_info *, struct pipe_buffer *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 void (*release)(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboe5abc97a2006-03-30 15:16:46 +020052 int (*steal)(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboe70524492006-04-11 15:51:17 +020053 void (*get)(struct pipe_inode_info *, struct pipe_buffer *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070054};
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual
57 memory allocation, whereas PIPE_BUF makes atomicity guarantees. */
58#define PIPE_SIZE PAGE_SIZE
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060/* Drop the inode semaphore and wait for a pipe event, atomically */
Ingo Molnar3a326a22006-04-10 15:18:35 +020061void pipe_wait(struct pipe_inode_info *pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Ingo Molnar3a326a22006-04-10 15:18:35 +020063struct pipe_inode_info * alloc_pipe_info(struct inode * inode);
64void free_pipe_info(struct inode * inode);
Jens Axboeb92ce552006-04-11 13:52:07 +020065void __free_pipe_info(struct pipe_inode_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Jens Axboef84d7512006-05-01 19:59:03 +020067/* Generic pipe buffer ops functions */
Jens Axboef6762b72006-05-01 20:02:05 +020068void *generic_pipe_buf_map(struct pipe_inode_info *, struct pipe_buffer *, int);
69void generic_pipe_buf_unmap(struct pipe_inode_info *, struct pipe_buffer *, void *);
Jens Axboef84d7512006-05-01 19:59:03 +020070void generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
71int generic_pipe_buf_pin(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboe330ab712006-05-02 15:29:57 +020072int generic_pipe_buf_steal(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboef84d7512006-05-01 19:59:03 +020073
Jens Axboe5abc97a2006-03-30 15:16:46 +020074/*
75 * splice is tied to pipes as a transport (at least for now), so we'll just
76 * add the splice flags here.
77 */
78#define SPLICE_F_MOVE (0x01) /* move pages instead of copying */
Linus Torvalds29e35092006-04-02 12:46:35 -070079#define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
80 /* we may still block on the fd we splice */
81 /* from/to, of course */
Jens Axboeb2b39fa2006-04-02 23:05:41 +020082#define SPLICE_F_MORE (0x04) /* expect more data */
Jens Axboe7afa6fd2006-05-01 20:02:33 +020083#define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */
Jens Axboe5abc97a2006-03-30 15:16:46 +020084
Jens Axboe00522fb2006-04-26 14:39:29 +020085/*
86 * Passed to the actors
87 */
88struct splice_desc {
89 unsigned int len, total_len; /* current and remaining length */
90 unsigned int flags; /* splice flags */
91 struct file *file; /* file to read/write */
92 loff_t pos; /* file position */
93};
94
95typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *,
96 struct splice_desc *);
97
98extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *,
99 loff_t *, size_t, unsigned int,
100 splice_actor *);
101
Mark Fasheh40bee44e2007-03-21 13:11:02 +0100102extern ssize_t __splice_from_pipe(struct pipe_inode_info *, struct file *,
103 loff_t *, size_t, unsigned int,
104 splice_actor *);
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#endif