blob: cc09fe89bf0740795e65b9b33499378e95013877 [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;
Jens Axboe497f9622007-06-11 12:00:45 +020017 unsigned long private;
Linus Torvalds1da177e2005-04-16 15:20:36 -070018};
19
Jens Axboe17374ff2007-06-04 15:03:12 +020020struct pipe_inode_info {
21 wait_queue_head_t wait;
22 unsigned int nrbufs, curbuf;
23 struct page *tmp_page;
24 unsigned int readers;
25 unsigned int writers;
26 unsigned int waiting_writers;
27 unsigned int r_counter;
28 unsigned int w_counter;
29 struct fasync_struct *fasync_readers;
30 struct fasync_struct *fasync_writers;
31 struct inode *inode;
32 struct pipe_buffer bufs[PIPE_BUFFERS];
33};
34
Jens Axboef84d7512006-05-01 19:59:03 +020035/*
36 * Note on the nesting of these functions:
37 *
Jens Axboecac36bb02007-06-14 13:10:48 +020038 * ->confirm()
Jens Axboef84d7512006-05-01 19:59:03 +020039 * ->steal()
40 * ...
41 * ->map()
42 * ...
43 * ->unmap()
44 *
Jens Axboecac36bb02007-06-14 13:10:48 +020045 * That is, ->map() must be called on a confirmed buffer,
46 * same goes for ->steal().
Jens Axboef84d7512006-05-01 19:59:03 +020047 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048struct pipe_buf_operations {
49 int can_merge;
Jens Axboef6762b72006-05-01 20:02:05 +020050 void * (*map)(struct pipe_inode_info *, struct pipe_buffer *, int);
51 void (*unmap)(struct pipe_inode_info *, struct pipe_buffer *, void *);
Jens Axboecac36bb02007-06-14 13:10:48 +020052 int (*confirm)(struct pipe_inode_info *, struct pipe_buffer *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 void (*release)(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboe5abc97a2006-03-30 15:16:46 +020054 int (*steal)(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboe70524492006-04-11 15:51:17 +020055 void (*get)(struct pipe_inode_info *, struct pipe_buffer *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056};
57
Linus Torvalds1da177e2005-04-16 15:20:36 -070058/* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual
59 memory allocation, whereas PIPE_BUF makes atomicity guarantees. */
60#define PIPE_SIZE PAGE_SIZE
61
Linus Torvalds1da177e2005-04-16 15:20:36 -070062/* Drop the inode semaphore and wait for a pipe event, atomically */
Ingo Molnar3a326a22006-04-10 15:18:35 +020063void pipe_wait(struct pipe_inode_info *pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Ingo Molnar3a326a22006-04-10 15:18:35 +020065struct pipe_inode_info * alloc_pipe_info(struct inode * inode);
66void free_pipe_info(struct inode * inode);
Jens Axboeb92ce552006-04-11 13:52:07 +020067void __free_pipe_info(struct pipe_inode_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Jens Axboef84d7512006-05-01 19:59:03 +020069/* Generic pipe buffer ops functions */
Jens Axboef6762b72006-05-01 20:02:05 +020070void *generic_pipe_buf_map(struct pipe_inode_info *, struct pipe_buffer *, int);
71void generic_pipe_buf_unmap(struct pipe_inode_info *, struct pipe_buffer *, void *);
Jens Axboef84d7512006-05-01 19:59:03 +020072void generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboecac36bb02007-06-14 13:10:48 +020073int generic_pipe_buf_confirm(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboe330ab712006-05-02 15:29:57 +020074int generic_pipe_buf_steal(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboef84d7512006-05-01 19:59:03 +020075
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#endif