Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Function declerations and data structures related to the splice
0004  * implementation.
0005  *
0006  * Copyright (C) 2007 Jens Axboe <jens.axboe@oracle.com>
0007  *
0008  */
0009 #ifndef SPLICE_H
0010 #define SPLICE_H
0011 
0012 #include <linux/pipe_fs_i.h>
0013 
0014 /*
0015  * Flags passed in from splice/tee/vmsplice
0016  */
0017 #define SPLICE_F_MOVE   (0x01)  /* move pages instead of copying */
0018 #define SPLICE_F_NONBLOCK (0x02) /* don't block on the pipe splicing (but */
0019                  /* we may still block on the fd we splice */
0020                  /* from/to, of course */
0021 #define SPLICE_F_MORE   (0x04)  /* expect more data */
0022 #define SPLICE_F_GIFT   (0x08)  /* pages passed in are a gift */
0023 
0024 #define SPLICE_F_ALL (SPLICE_F_MOVE|SPLICE_F_NONBLOCK|SPLICE_F_MORE|SPLICE_F_GIFT)
0025 
0026 /*
0027  * Passed to the actors
0028  */
0029 struct splice_desc {
0030     size_t total_len;       /* remaining length */
0031     unsigned int len;       /* current length */
0032     unsigned int flags;     /* splice flags */
0033     /*
0034      * actor() private data
0035      */
0036     union {
0037         void __user *userptr;   /* memory to write to */
0038         struct file *file;  /* file to read/write */
0039         void *data;     /* cookie */
0040     } u;
0041     loff_t pos;         /* file position */
0042     loff_t *opos;           /* sendfile: output position */
0043     size_t num_spliced;     /* number of bytes already spliced */
0044     bool need_wakeup;       /* need to wake up writer */
0045 };
0046 
0047 struct partial_page {
0048     unsigned int offset;
0049     unsigned int len;
0050     unsigned long private;
0051 };
0052 
0053 /*
0054  * Passed to splice_to_pipe
0055  */
0056 struct splice_pipe_desc {
0057     struct page **pages;        /* page map */
0058     struct partial_page *partial;   /* pages[] may not be contig */
0059     int nr_pages;           /* number of populated pages in map */
0060     unsigned int nr_pages_max;  /* pages[] & partial[] arrays size */
0061     const struct pipe_buf_operations *ops;/* ops associated with output pipe */
0062     void (*spd_release)(struct splice_pipe_desc *, unsigned int);
0063 };
0064 
0065 typedef int (splice_actor)(struct pipe_inode_info *, struct pipe_buffer *,
0066                struct splice_desc *);
0067 typedef int (splice_direct_actor)(struct pipe_inode_info *,
0068                   struct splice_desc *);
0069 
0070 extern ssize_t splice_from_pipe(struct pipe_inode_info *, struct file *,
0071                 loff_t *, size_t, unsigned int,
0072                 splice_actor *);
0073 extern ssize_t __splice_from_pipe(struct pipe_inode_info *,
0074                   struct splice_desc *, splice_actor *);
0075 extern ssize_t splice_to_pipe(struct pipe_inode_info *,
0076                   struct splice_pipe_desc *);
0077 extern ssize_t add_to_pipe(struct pipe_inode_info *,
0078                   struct pipe_buffer *);
0079 extern ssize_t splice_direct_to_actor(struct file *, struct splice_desc *,
0080                       splice_direct_actor *);
0081 extern long do_splice(struct file *in, loff_t *off_in,
0082               struct file *out, loff_t *off_out,
0083               size_t len, unsigned int flags);
0084 
0085 extern long do_tee(struct file *in, struct file *out, size_t len,
0086            unsigned int flags);
0087 
0088 /*
0089  * for dynamic pipe sizing
0090  */
0091 extern int splice_grow_spd(const struct pipe_inode_info *, struct splice_pipe_desc *);
0092 extern void splice_shrink_spd(struct splice_pipe_desc *);
0093 
0094 extern const struct pipe_buf_operations page_cache_pipe_buf_ops;
0095 extern const struct pipe_buf_operations default_pipe_buf_ops;
0096 #endif