pipe_fs_i.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #ifndef _LINUX_PIPE_FS_I_H
  2. #define _LINUX_PIPE_FS_I_H
  3. #define PIPEFS_MAGIC 0x50495045
  4. #define PIPE_BUFFERS (16)
  5. #define PIPE_BUF_FLAG_LRU 0x01 /* page is on the LRU */
  6. #define PIPE_BUF_FLAG_ATOMIC 0x02 /* was atomically mapped */
  7. #define PIPE_BUF_FLAG_GIFT 0x04 /* page is a gift */
  8. struct pipe_buffer {
  9. struct page *page;
  10. unsigned int offset, len;
  11. struct pipe_buf_operations *ops;
  12. unsigned int flags;
  13. };
  14. /*
  15. * Note on the nesting of these functions:
  16. *
  17. * ->pin()
  18. * ->steal()
  19. * ...
  20. * ->map()
  21. * ...
  22. * ->unmap()
  23. *
  24. * That is, ->map() must be called on a pinned buffer, same goes for ->steal().
  25. */
  26. struct pipe_buf_operations {
  27. int can_merge;
  28. void * (*map)(struct pipe_inode_info *, struct pipe_buffer *, int);
  29. void (*unmap)(struct pipe_inode_info *, struct pipe_buffer *, void *);
  30. int (*pin)(struct pipe_inode_info *, struct pipe_buffer *);
  31. void (*release)(struct pipe_inode_info *, struct pipe_buffer *);
  32. int (*steal)(struct pipe_inode_info *, struct pipe_buffer *);
  33. void (*get)(struct pipe_inode_info *, struct pipe_buffer *);
  34. };
  35. struct pipe_inode_info {
  36. wait_queue_head_t wait;
  37. unsigned int nrbufs, curbuf;
  38. struct pipe_buffer bufs[PIPE_BUFFERS];
  39. struct page *tmp_page;
  40. unsigned int start;
  41. unsigned int readers;
  42. unsigned int writers;
  43. unsigned int waiting_writers;
  44. unsigned int r_counter;
  45. unsigned int w_counter;
  46. struct fasync_struct *fasync_readers;
  47. struct fasync_struct *fasync_writers;
  48. struct inode *inode;
  49. };
  50. /* Differs from PIPE_BUF in that PIPE_SIZE is the length of the actual
  51. memory allocation, whereas PIPE_BUF makes atomicity guarantees. */
  52. #define PIPE_SIZE PAGE_SIZE
  53. /* Drop the inode semaphore and wait for a pipe event, atomically */
  54. void pipe_wait(struct pipe_inode_info *pipe);
  55. struct pipe_inode_info * alloc_pipe_info(struct inode * inode);
  56. void free_pipe_info(struct inode * inode);
  57. void __free_pipe_info(struct pipe_inode_info *);
  58. /* Generic pipe buffer ops functions */
  59. void *generic_pipe_buf_map(struct pipe_inode_info *, struct pipe_buffer *, int);
  60. void generic_pipe_buf_unmap(struct pipe_inode_info *, struct pipe_buffer *, void *);
  61. void generic_pipe_buf_get(struct pipe_inode_info *, struct pipe_buffer *);
  62. int generic_pipe_buf_pin(struct pipe_inode_info *, struct pipe_buffer *);
  63. int generic_pipe_buf_steal(struct pipe_inode_info *, struct pipe_buffer *);
  64. /*
  65. * splice is tied to pipes as a transport (at least for now), so we'll just
  66. * add the splice flags here.
  67. */
  68. #define SPLICE_F_MOVE (0x01) /* move pages instead of copying */
  69. #define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
  70. /* we may still block on the fd we splice */
  71. /* from/to, of course */
  72. #define SPLICE_F_MORE (0x04) /* expect more data */
  73. #define SPLICE_F_GIFT (0x08) /* pages passed in are a gift */
  74. /*
  75. * Passed to the actors
  76. */
  77. struct splice_desc {
  78. unsigned int len, total_len; /* current and remaining length */
  79. unsigned int flags; /* splice flags */
  80. struct file *file; /* file to read/write */
  81. loff_t pos; /* file position */
  82. };
  83. typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *,
  84. struct splice_desc *);
  85. extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *,
  86. loff_t *, size_t, unsigned int,
  87. splice_actor *);
  88. #endif