buf.h revision 1.1 1 1.1 pho /* $NetBSD: buf.h,v 1.1 2022/01/22 07:54:57 pho Exp $ */
2 1.1 pho
3 1.1 pho /*
4 1.1 pho * Copyright (c) 2021 The NetBSD Foundation, Inc.
5 1.1 pho * All rights reserved.
6 1.1 pho *
7 1.1 pho * Redistribution and use in source and binary forms, with or without
8 1.1 pho * modification, are permitted provided that the following conditions
9 1.1 pho * are met:
10 1.1 pho * 1. Redistributions of source code must retain the above copyright
11 1.1 pho * notice, this list of conditions and the following disclaimer.
12 1.1 pho * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 pho * notice, this list of conditions and the following disclaimer in the
14 1.1 pho * documentation and/or other materials provided with the distribution.
15 1.1 pho * 3. The name of the author may not be used to endorse or promote
16 1.1 pho * products derived from this software without specific prior written
17 1.1 pho * permission.
18 1.1 pho *
19 1.1 pho * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 1.1 pho * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 1.1 pho * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 1.1 pho * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
23 1.1 pho * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 pho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 1.1 pho * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 pho * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 1.1 pho * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 1.1 pho * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 1.1 pho * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1 pho */
31 1.1 pho #if !defined(_FUSE_BUF_H_)
32 1.1 pho #define _FUSE_BUF_H_
33 1.1 pho
34 1.1 pho #include <sys/types.h>
35 1.1 pho
36 1.1 pho /* Data buffer API, appeared on FUSE 2.9. */
37 1.1 pho
38 1.1 pho #if !defined(FUSE_H_)
39 1.1 pho # error Do not include this header directly. Include <fuse.h> instead.
40 1.1 pho #endif
41 1.1 pho
42 1.1 pho #ifdef __cplusplus
43 1.1 pho extern "C" {
44 1.1 pho #endif
45 1.1 pho
46 1.1 pho enum fuse_buf_flags {
47 1.1 pho /* The buffer is actually an fd: .mem is invalid but .fd and
48 1.1 pho * .pos have valid values. */
49 1.1 pho FUSE_BUF_IS_FD = (1 << 1),
50 1.1 pho /* The fd is seekable. */
51 1.1 pho FUSE_BUF_FD_SEEK = (1 << 2),
52 1.1 pho /* Keep reading from/writing to the fd until reaching EOF. */
53 1.1 pho FUSE_BUF_FD_RETRY = (1 << 3),
54 1.1 pho };
55 1.1 pho enum fuse_buf_copy_flags {
56 1.1 pho /* These flags are always ignored because splice(2) is a
57 1.1 pho * Linux-specific syscall and there are no alternatives on
58 1.1 pho * NetBSD atm. */
59 1.1 pho FUSE_BUF_NO_SPLICE = (1 << 1),
60 1.1 pho FUSE_BUF_FORCE_SPLICE = (1 << 2),
61 1.1 pho FUSE_BUF_SPLICE_MOVE = (1 << 3),
62 1.1 pho FUSE_BUF_SPLICE_NONBLOCK = (1 << 4),
63 1.1 pho };
64 1.1 pho struct fuse_buf {
65 1.1 pho size_t size;
66 1.1 pho enum fuse_buf_flags flags;
67 1.1 pho void *mem;
68 1.1 pho int fd;
69 1.1 pho off_t pos;
70 1.1 pho };
71 1.1 pho struct fuse_bufvec {
72 1.1 pho /* The number of buffers in the vector. */
73 1.1 pho size_t count;
74 1.1 pho /* The index of the current buffer in the vector. */
75 1.1 pho size_t idx;
76 1.1 pho /* The current offset in the current buffer. */
77 1.1 pho size_t off;
78 1.1 pho /* The vector of buffers. */
79 1.1 pho struct fuse_buf buf[1];
80 1.1 pho };
81 1.1 pho #define FUSE_BUFVEC_INIT(size_) \
82 1.1 pho ((struct fuse_bufvec) { \
83 1.1 pho /* .count = */ 1, \
84 1.1 pho /* .idx = */ 0, \
85 1.1 pho /* .off = */ 0, \
86 1.1 pho /* .buf = */ { \
87 1.1 pho /* [0] = */ { \
88 1.1 pho /* .size = */ (size_) \
89 1.1 pho /* .flags = */ (enum fuse_buf_flags)0, \
90 1.1 pho /* .mem = */ NULL, \
91 1.1 pho /* .fd = */ -1, \
92 1.1 pho /* .pos = */ 0, \
93 1.1 pho } \
94 1.1 pho } \
95 1.1 pho })
96 1.1 pho
97 1.1 pho /* Get the total size of data in a buffer vector. */
98 1.1 pho size_t fuse_buf_size(const struct fuse_bufvec *bufv);
99 1.1 pho
100 1.1 pho /* Copy data from one buffer vector to another, and return the number
101 1.1 pho * of octets that have been copied. */
102 1.1 pho ssize_t fuse_buf_copy(struct fuse_bufvec *dstv, struct fuse_bufvec *srcv,
103 1.1 pho enum fuse_buf_copy_flags flags);
104 1.1 pho
105 1.1 pho #ifdef __cplusplus
106 1.1 pho }
107 1.1 pho #endif
108 1.1 pho
109 1.1 pho #endif
110