blob: 3130977fc6ab4e5ff02a638df841ab75eddc1843 [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
17struct pipe_buf_operations {
18 int can_merge;
19 void * (*map)(struct file *, struct pipe_inode_info *, struct pipe_buffer *);
20 void (*unmap)(struct pipe_inode_info *, struct pipe_buffer *);
21 void (*release)(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboe5abc97a2006-03-30 15:16:46 +020022 int (*steal)(struct pipe_inode_info *, struct pipe_buffer *);
Jens Axboe70524492006-04-11 15:51:17 +020023 void (*get)(struct pipe_inode_info *, struct pipe_buffer *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024};
25
26struct pipe_inode_info {
27 wait_queue_head_t wait;
28 unsigned int nrbufs, curbuf;
29 struct pipe_buffer bufs[PIPE_BUFFERS];
30 struct page *tmp_page;
31 unsigned int start;
32 unsigned int readers;
33 unsigned int writers;
34 unsigned int waiting_writers;
35 unsigned int r_counter;
36 unsigned int w_counter;
37 struct fasync_struct *fasync_readers;
38 struct fasync_struct *fasync_writers;
Ingo Molnar3a326a22006-04-10 15:18:35 +020039 struct inode *inode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040};
41
42/* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual
43 memory allocation, whereas PIPE_BUF makes atomicity guarantees. */
44#define PIPE_SIZE PAGE_SIZE
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046/* Drop the inode semaphore and wait for a pipe event, atomically */
Ingo Molnar3a326a22006-04-10 15:18:35 +020047void pipe_wait(struct pipe_inode_info *pipe);
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Ingo Molnar3a326a22006-04-10 15:18:35 +020049struct pipe_inode_info * alloc_pipe_info(struct inode * inode);
50void free_pipe_info(struct inode * inode);
Jens Axboeb92ce552006-04-11 13:52:07 +020051void __free_pipe_info(struct pipe_inode_info *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Jens Axboe5abc97a2006-03-30 15:16:46 +020053/*
54 * splice is tied to pipes as a transport (at least for now), so we'll just
55 * add the splice flags here.
56 */
57#define SPLICE_F_MOVE (0x01) /* move pages instead of copying */
Linus Torvalds29e35092006-04-02 12:46:35 -070058#define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
59 /* we may still block on the fd we splice */
60 /* from/to, of course */
Jens Axboeb2b39fa2006-04-02 23:05:41 +020061#define SPLICE_F_MORE (0x04) /* expect more data */
Jens Axboe5abc97a2006-03-30 15:16:46 +020062
Jens Axboe00522fb2006-04-26 14:39:29 +020063/*
64 * Passed to the actors
65 */
66struct splice_desc {
67 unsigned int len, total_len; /* current and remaining length */
68 unsigned int flags; /* splice flags */
69 struct file *file; /* file to read/write */
70 loff_t pos; /* file position */
71};
72
73typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *,
74 struct splice_desc *);
75
76extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *,
77 loff_t *, size_t, unsigned int,
78 splice_actor *);
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#endif