0001
0002 #ifndef _LINUX_PIPE_FS_I_H
0003 #define _LINUX_PIPE_FS_I_H
0004
0005 #define PIPE_DEF_BUFFERS 16
0006
0007 #define PIPE_BUF_FLAG_LRU 0x01
0008 #define PIPE_BUF_FLAG_ATOMIC 0x02
0009 #define PIPE_BUF_FLAG_GIFT 0x04
0010 #define PIPE_BUF_FLAG_PACKET 0x08
0011 #define PIPE_BUF_FLAG_CAN_MERGE 0x10
0012 #define PIPE_BUF_FLAG_WHOLE 0x20
0013 #ifdef CONFIG_WATCH_QUEUE
0014 #define PIPE_BUF_FLAG_LOSS 0x40
0015 #endif
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 struct pipe_buffer {
0027 struct page *page;
0028 unsigned int offset, len;
0029 const struct pipe_buf_operations *ops;
0030 unsigned int flags;
0031 unsigned long private;
0032 };
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 struct pipe_inode_info {
0059 struct mutex mutex;
0060 wait_queue_head_t rd_wait, wr_wait;
0061 unsigned int head;
0062 unsigned int tail;
0063 unsigned int max_usage;
0064 unsigned int ring_size;
0065 #ifdef CONFIG_WATCH_QUEUE
0066 bool note_loss;
0067 #endif
0068 unsigned int nr_accounted;
0069 unsigned int readers;
0070 unsigned int writers;
0071 unsigned int files;
0072 unsigned int r_counter;
0073 unsigned int w_counter;
0074 bool poll_usage;
0075 struct page *tmp_page;
0076 struct fasync_struct *fasync_readers;
0077 struct fasync_struct *fasync_writers;
0078 struct pipe_buffer *bufs;
0079 struct user_struct *user;
0080 #ifdef CONFIG_WATCH_QUEUE
0081 struct watch_queue *watch_queue;
0082 #endif
0083 };
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095 struct pipe_buf_operations {
0096
0097
0098
0099
0100
0101
0102
0103 int (*confirm)(struct pipe_inode_info *, struct pipe_buffer *);
0104
0105
0106
0107
0108
0109 void (*release)(struct pipe_inode_info *, struct pipe_buffer *);
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119 bool (*try_steal)(struct pipe_inode_info *, struct pipe_buffer *);
0120
0121
0122
0123
0124 bool (*get)(struct pipe_inode_info *, struct pipe_buffer *);
0125 };
0126
0127
0128
0129
0130
0131
0132 static inline bool pipe_empty(unsigned int head, unsigned int tail)
0133 {
0134 return head == tail;
0135 }
0136
0137
0138
0139
0140
0141
0142 static inline unsigned int pipe_occupancy(unsigned int head, unsigned int tail)
0143 {
0144 return head - tail;
0145 }
0146
0147
0148
0149
0150
0151
0152
0153 static inline bool pipe_full(unsigned int head, unsigned int tail,
0154 unsigned int limit)
0155 {
0156 return pipe_occupancy(head, tail) >= limit;
0157 }
0158
0159
0160
0161
0162
0163
0164
0165
0166 static inline __must_check bool pipe_buf_get(struct pipe_inode_info *pipe,
0167 struct pipe_buffer *buf)
0168 {
0169 return buf->ops->get(pipe, buf);
0170 }
0171
0172
0173
0174
0175
0176
0177 static inline void pipe_buf_release(struct pipe_inode_info *pipe,
0178 struct pipe_buffer *buf)
0179 {
0180 const struct pipe_buf_operations *ops = buf->ops;
0181
0182 buf->ops = NULL;
0183 ops->release(pipe, buf);
0184 }
0185
0186
0187
0188
0189
0190
0191 static inline int pipe_buf_confirm(struct pipe_inode_info *pipe,
0192 struct pipe_buffer *buf)
0193 {
0194 if (!buf->ops->confirm)
0195 return 0;
0196 return buf->ops->confirm(pipe, buf);
0197 }
0198
0199
0200
0201
0202
0203
0204 static inline bool pipe_buf_try_steal(struct pipe_inode_info *pipe,
0205 struct pipe_buffer *buf)
0206 {
0207 if (!buf->ops->try_steal)
0208 return false;
0209 return buf->ops->try_steal(pipe, buf);
0210 }
0211
0212 static inline void pipe_discard_from(struct pipe_inode_info *pipe,
0213 unsigned int old_head)
0214 {
0215 unsigned int mask = pipe->ring_size - 1;
0216
0217 while (pipe->head > old_head)
0218 pipe_buf_release(pipe, &pipe->bufs[--pipe->head & mask]);
0219 }
0220
0221
0222
0223 #define PIPE_SIZE PAGE_SIZE
0224
0225
0226 void pipe_lock(struct pipe_inode_info *);
0227 void pipe_unlock(struct pipe_inode_info *);
0228 void pipe_double_lock(struct pipe_inode_info *, struct pipe_inode_info *);
0229
0230
0231 void pipe_wait_readable(struct pipe_inode_info *);
0232 void pipe_wait_writable(struct pipe_inode_info *);
0233
0234 struct pipe_inode_info *alloc_pipe_info(void);
0235 void free_pipe_info(struct pipe_inode_info *);
0236
0237
0238 bool generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
0239 bool generic_pipe_buf_try_steal(struct pipe_inode_info *, struct pipe_buffer *);
0240 void generic_pipe_buf_release(struct pipe_inode_info *, struct pipe_buffer *);
0241
0242 extern const struct pipe_buf_operations nosteal_pipe_buf_ops;
0243
0244 #ifdef CONFIG_WATCH_QUEUE
0245 unsigned long account_pipe_buffers(struct user_struct *user,
0246 unsigned long old, unsigned long new);
0247 bool too_many_pipe_buffers_soft(unsigned long user_bufs);
0248 bool too_many_pipe_buffers_hard(unsigned long user_bufs);
0249 bool pipe_is_unprivileged_user(void);
0250 #endif
0251
0252
0253 #ifdef CONFIG_WATCH_QUEUE
0254 int pipe_resize_ring(struct pipe_inode_info *pipe, unsigned int nr_slots);
0255 #endif
0256 long pipe_fcntl(struct file *, unsigned int, unsigned long arg);
0257 struct pipe_inode_info *get_pipe_info(struct file *file, bool for_splice);
0258
0259 int create_pipe_files(struct file **, int);
0260 unsigned int round_pipe_size(unsigned long size);
0261
0262 #endif