pipe_fs_i.h 3.3 KB

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