blob: b8aae1fc5185cd12840c00fbba4c391fb25c8329 [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 Axboe0568b402006-05-01 19:50:48 +02008#define PIPE_BUF_FLAG_LRU 0x01
Jens Axboe3e7ee3e2006-04-02 23:11:04 +02009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010struct pipe_buffer {
11 struct page *page;
12 unsigned int offset, len;
13 struct pipe_buf_operations *ops;
Jens Axboe3e7ee3e2006-04-02 23:11:04 +020014 unsigned int flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -070015};
16
Jens Axboef84d7512006-05-01 19:59:03 +020017/*
18 * Note on the nesting of these functions:
19 *
20 * ->pin()
21 * ->steal()
22 * ...
23 * ->map()
24 * ...
25 * ->unmap()
26 *
27 * That is, ->map() must be called on a pinned buffer, same goes for ->steal().
28 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070029struct pipe_buf_operations {
30 int can_merge;
Jens Axboef84d7512006-05-01 19:59:03 +020031 void * (*map)(struct pipe_inode_info *, struct pipe_buffer *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 void (*unmap)(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboef84d7512006-05-01 19:59:03 +020033 int (*pin)(struct pipe_inode_info *, struct pipe_buffer *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 void (*release)(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboe5abc97a2006-03-30 15:16:46 +020035 int (*steal)(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboe70524492006-04-11 15:51:17 +020036 void (*get)(struct pipe_inode_info *, struct pipe_buffer *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037};
38
39struct pipe_inode_info {
40 wait_queue_head_t wait;
41 unsigned int nrbufs, curbuf;
42 struct pipe_buffer bufs[PIPE_BUFFERS];
43 struct page *tmp_page;
44 unsigned int start;
45 unsigned int readers;
46 unsigned int writers;
47 unsigned int waiting_writers;
48 unsigned int r_counter;
49 unsigned int w_counter;
50 struct fasync_struct *fasync_readers;
51 struct fasync_struct *fasync_writers;
Ingo Molnar3a326a22006-04-10 15:18:35 +020052 struct inode *inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053};
54
55/* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual
56 memory allocation, whereas PIPE_BUF makes atomicity guarantees. */
57#define PIPE_SIZE PAGE_SIZE
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059/* Drop the inode semaphore and wait for a pipe event, atomically */
Ingo Molnar3a326a22006-04-10 15:18:35 +020060void pipe_wait(struct pipe_inode_info *pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Ingo Molnar3a326a22006-04-10 15:18:35 +020062struct pipe_inode_info * alloc_pipe_info(struct inode * inode);
63void free_pipe_info(struct inode * inode);
Jens Axboeb92ce552006-04-11 13:52:07 +020064void __free_pipe_info(struct pipe_inode_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
Jens Axboef84d7512006-05-01 19:59:03 +020066/* Generic pipe buffer ops functions */
67void *generic_pipe_buf_map(struct pipe_inode_info *, struct pipe_buffer *);
68void generic_pipe_buf_unmap(struct pipe_inode_info *, struct pipe_buffer *);
69void generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
70int generic_pipe_buf_pin(struct pipe_inode_info *, struct pipe_buffer *);
71
Jens Axboe5abc97a2006-03-30 15:16:46 +020072/*
73 * splice is tied to pipes as a transport (at least for now), so we'll just
74 * add the splice flags here.
75 */
76#define SPLICE_F_MOVE (0x01) /* move pages instead of copying */
Linus Torvalds29e35092006-04-02 12:46:35 -070077#define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
78 /* we may still block on the fd we splice */
79 /* from/to, of course */
Jens Axboeb2b39fa2006-04-02 23:05:41 +020080#define SPLICE_F_MORE (0x04) /* expect more data */
Jens Axboe5abc97a2006-03-30 15:16:46 +020081
Jens Axboe00522fb2006-04-26 14:39:29 +020082/*
83 * Passed to the actors
84 */
85struct splice_desc {
86 unsigned int len, total_len; /* current and remaining length */
87 unsigned int flags; /* splice flags */
88 struct file *file; /* file to read/write */
89 loff_t pos; /* file position */
90};
91
92typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *,
93 struct splice_desc *);
94
95extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *,
96 loff_t *, size_t, unsigned int,
97 splice_actor *);
98
Linus Torvalds1da177e2005-04-16 15:20:36 -070099#endif