Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #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 Axboe | 1432873 | 2006-05-03 10:35:26 +0200 | [diff] [blame] | 8 | #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 Axboe | 3e7ee3e | 2006-04-02 23:11:04 +0200 | [diff] [blame] | 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | struct pipe_buffer { |
| 13 | struct page *page; |
| 14 | unsigned int offset, len; |
Eric Dumazet | d4c3cca | 2006-12-13 00:34:04 -0800 | [diff] [blame] | 15 | const struct pipe_buf_operations *ops; |
Jens Axboe | 3e7ee3e | 2006-04-02 23:11:04 +0200 | [diff] [blame] | 16 | unsigned int flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | }; |
| 18 | |
Jens Axboe | f84d751 | 2006-05-01 19:59:03 +0200 | [diff] [blame] | 19 | /* |
| 20 | * Note on the nesting of these functions: |
| 21 | * |
| 22 | * ->pin() |
| 23 | * ->steal() |
| 24 | * ... |
| 25 | * ->map() |
| 26 | * ... |
| 27 | * ->unmap() |
| 28 | * |
| 29 | * That is, ->map() must be called on a pinned buffer, same goes for ->steal(). |
| 30 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | struct pipe_buf_operations { |
| 32 | int can_merge; |
Jens Axboe | f6762b7 | 2006-05-01 20:02:05 +0200 | [diff] [blame] | 33 | void * (*map)(struct pipe_inode_info *, struct pipe_buffer *, int); |
| 34 | void (*unmap)(struct pipe_inode_info *, struct pipe_buffer *, void *); |
Jens Axboe | f84d751 | 2006-05-01 19:59:03 +0200 | [diff] [blame] | 35 | int (*pin)(struct pipe_inode_info *, struct pipe_buffer *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | void (*release)(struct pipe_inode_info *, struct pipe_buffer *); |
Jens Axboe | 5abc97a | 2006-03-30 15:16:46 +0200 | [diff] [blame] | 37 | int (*steal)(struct pipe_inode_info *, struct pipe_buffer *); |
Jens Axboe | 7052449 | 2006-04-11 15:51:17 +0200 | [diff] [blame] | 38 | void (*get)(struct pipe_inode_info *, struct pipe_buffer *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
| 41 | struct pipe_inode_info { |
| 42 | wait_queue_head_t wait; |
| 43 | unsigned int nrbufs, curbuf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | struct page *tmp_page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 Molnar | 3a326a2 | 2006-04-10 15:18:35 +0200 | [diff] [blame] | 52 | struct inode *inode; |
Eric Dumazet | 6a8ba9d | 2006-12-13 00:34:10 -0800 | [diff] [blame] | 53 | struct pipe_buffer bufs[PIPE_BUFFERS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | /* 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* Drop the inode semaphore and wait for a pipe event, atomically */ |
Ingo Molnar | 3a326a2 | 2006-04-10 15:18:35 +0200 | [diff] [blame] | 61 | void pipe_wait(struct pipe_inode_info *pipe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Ingo Molnar | 3a326a2 | 2006-04-10 15:18:35 +0200 | [diff] [blame] | 63 | struct pipe_inode_info * alloc_pipe_info(struct inode * inode); |
| 64 | void free_pipe_info(struct inode * inode); |
Jens Axboe | b92ce55 | 2006-04-11 13:52:07 +0200 | [diff] [blame] | 65 | void __free_pipe_info(struct pipe_inode_info *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Jens Axboe | f84d751 | 2006-05-01 19:59:03 +0200 | [diff] [blame] | 67 | /* Generic pipe buffer ops functions */ |
Jens Axboe | f6762b7 | 2006-05-01 20:02:05 +0200 | [diff] [blame] | 68 | void *generic_pipe_buf_map(struct pipe_inode_info *, struct pipe_buffer *, int); |
| 69 | void generic_pipe_buf_unmap(struct pipe_inode_info *, struct pipe_buffer *, void *); |
Jens Axboe | f84d751 | 2006-05-01 19:59:03 +0200 | [diff] [blame] | 70 | void generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *); |
| 71 | int generic_pipe_buf_pin(struct pipe_inode_info *, struct pipe_buffer *); |
Jens Axboe | 330ab71 | 2006-05-02 15:29:57 +0200 | [diff] [blame] | 72 | int generic_pipe_buf_steal(struct pipe_inode_info *, struct pipe_buffer *); |
Jens Axboe | f84d751 | 2006-05-01 19:59:03 +0200 | [diff] [blame] | 73 | |
Jens Axboe | 5abc97a | 2006-03-30 15:16:46 +0200 | [diff] [blame] | 74 | /* |
| 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 Torvalds | 29e3509 | 2006-04-02 12:46:35 -0700 | [diff] [blame] | 79 | #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 Axboe | b2b39fa | 2006-04-02 23:05:41 +0200 | [diff] [blame] | 82 | #define SPLICE_F_MORE (0x04) /* expect more data */ |
Jens Axboe | 7afa6fd | 2006-05-01 20:02:33 +0200 | [diff] [blame] | 83 | #define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */ |
Jens Axboe | 5abc97a | 2006-03-30 15:16:46 +0200 | [diff] [blame] | 84 | |
Jens Axboe | 00522fb | 2006-04-26 14:39:29 +0200 | [diff] [blame] | 85 | /* |
| 86 | * Passed to the actors |
| 87 | */ |
| 88 | struct 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 | |
| 95 | typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *, |
| 96 | struct splice_desc *); |
| 97 | |
| 98 | extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *, |
| 99 | loff_t *, size_t, unsigned int, |
| 100 | splice_actor *); |
| 101 | |
Mark Fasheh | 40bee44 | 2007-03-21 13:11:02 +0100 | [diff] [blame] | 102 | extern ssize_t __splice_from_pipe(struct pipe_inode_info *, struct file *, |
| 103 | loff_t *, size_t, unsigned int, |
| 104 | splice_actor *); |
| 105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | #endif |