fuse.h revision 1.26 1 1.26 pho /* $NetBSD: fuse.h,v 1.26 2022/01/22 07:54:57 pho Exp $ */
2 1.18 xtraeme
3 1.1 agc /*
4 1.1 agc * Copyright 2007 Alistair Crooks. All rights reserved.
5 1.1 agc *
6 1.1 agc * Redistribution and use in source and binary forms, with or without
7 1.1 agc * modification, are permitted provided that the following conditions
8 1.1 agc * are met:
9 1.1 agc * 1. Redistributions of source code must retain the above copyright
10 1.1 agc * notice, this list of conditions and the following disclaimer.
11 1.1 agc * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 agc * notice, this list of conditions and the following disclaimer in the
13 1.1 agc * documentation and/or other materials provided with the distribution.
14 1.1 agc * 3. The name of the author may not be used to endorse or promote
15 1.1 agc * products derived from this software without specific prior written
16 1.1 agc * permission.
17 1.1 agc *
18 1.1 agc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
19 1.1 agc * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 1.1 agc * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 1.1 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
22 1.1 agc * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 1.1 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
24 1.1 agc * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.1 agc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 1.1 agc * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 1.1 agc * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 1.1 agc * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 1.1 agc */
30 1.1 agc #ifndef FUSE_H_
31 1.24 pho #define FUSE_H_ 20211204
32 1.16 agc
33 1.26 pho #include <refuse/buf.h>
34 1.25 pho #include <refuse/session.h>
35 1.25 pho #include <sys/cdefs.h>
36 1.25 pho #include <sys/stat.h>
37 1.25 pho #include <sys/statvfs.h>
38 1.1 agc #include <sys/types.h>
39 1.1 agc #include <utime.h>
40 1.1 agc
41 1.24 pho /* The latest version of FUSE API currently provided by refuse. */
42 1.24 pho #define FUSE_MAJOR_VERSION 2
43 1.24 pho #define FUSE_MINOR_VERSION 6
44 1.24 pho
45 1.24 pho #define FUSE_MAKE_VERSION(maj, min) ((maj) * 10 + (min))
46 1.24 pho #define FUSE_VERSION FUSE_MAKE_VERSION(FUSE_MAJOR_VERSION, FUSE_MINOR_VERSION)
47 1.24 pho
48 1.24 pho /* FUSE_USE_VERSION is expected to be defined by user code to
49 1.24 pho * determine the API to be used. Although defining this macro is
50 1.24 pho * mandatory in the original FUSE implementation, refuse hasn't
51 1.24 pho * required this so we only emit a warning if it's undefined. */
52 1.24 pho #if defined(FUSE_USE_VERSION)
53 1.24 pho # if FUSE_USE_VERSION > FUSE_VERSION
54 1.24 pho # warning "The requested API version is higher than the latest one supported by refuse."
55 1.24 pho # endif
56 1.24 pho #else
57 1.24 pho # warning "User code including <fuse.h> should define FUSE_USE_VERSION before including this header. Defaulting to the latest version."
58 1.24 pho # define FUSE_USE_VERSION FUSE_VERSION
59 1.24 pho #endif
60 1.24 pho
61 1.1 agc #ifdef __cplusplus
62 1.1 agc extern "C" {
63 1.1 agc #endif
64 1.1 agc
65 1.4 agc struct fuse;
66 1.11 agc struct fuse_args; /* XXXsupportme */
67 1.4 agc
68 1.1 agc struct fuse_file_info {
69 1.1 agc int32_t flags;
70 1.1 agc uint32_t fh_old;
71 1.1 agc int32_t writepage;
72 1.1 agc uint32_t direct_io:1;
73 1.1 agc uint32_t keep_cache:1;
74 1.1 agc uint32_t flush:1;
75 1.1 agc uint32_t padding:29;
76 1.1 agc uint64_t fh;
77 1.1 agc uint64_t lock_owner;
78 1.1 agc };
79 1.1 agc
80 1.1 agc struct fuse_conn_info {
81 1.1 agc uint32_t proto_major;
82 1.1 agc uint32_t proto_minor;
83 1.1 agc uint32_t async_read;
84 1.1 agc uint32_t max_write;
85 1.1 agc uint32_t max_readahead;
86 1.1 agc uint32_t reserved[27];
87 1.1 agc };
88 1.1 agc
89 1.3 pooka /* equivalent'ish of puffs_cc */
90 1.3 pooka struct fuse_context {
91 1.3 pooka struct fuse *fuse;
92 1.3 pooka uid_t uid;
93 1.3 pooka gid_t gid;
94 1.3 pooka pid_t pid;
95 1.3 pooka void *private_data;
96 1.3 pooka };
97 1.3 pooka
98 1.1 agc /**
99 1.1 agc * Argument list
100 1.1 agc */
101 1.1 agc struct fuse_args {
102 1.1 agc int argc;
103 1.1 agc char **argv;
104 1.1 agc int allocated;
105 1.1 agc };
106 1.1 agc
107 1.1 agc /**
108 1.1 agc * Initializer for 'struct fuse_args'
109 1.1 agc */
110 1.1 agc #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
111 1.1 agc
112 1.7 pooka typedef struct puffs_fuse_dirh *fuse_dirh_t;
113 1.2 pooka
114 1.1 agc typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t);
115 1.2 pooka typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t);
116 1.1 agc
117 1.1 agc /*
118 1.1 agc * These operations shadow those in puffs_usermount, and are used
119 1.1 agc * as a table of callbacks to make when file system requests come
120 1.1 agc * in.
121 1.5 pooka *
122 1.5 pooka * NOTE: keep same order as fuse
123 1.1 agc */
124 1.1 agc struct fuse_operations {
125 1.1 agc int (*getattr)(const char *, struct stat *);
126 1.1 agc int (*readlink)(const char *, char *, size_t);
127 1.5 pooka int (*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t);
128 1.1 agc int (*mknod)(const char *, mode_t, dev_t);
129 1.1 agc int (*mkdir)(const char *, mode_t);
130 1.1 agc int (*unlink)(const char *);
131 1.1 agc int (*rmdir)(const char *);
132 1.1 agc int (*symlink)(const char *, const char *);
133 1.1 agc int (*rename)(const char *, const char *);
134 1.1 agc int (*link)(const char *, const char *);
135 1.1 agc int (*chmod)(const char *, mode_t);
136 1.1 agc int (*chown)(const char *, uid_t, gid_t);
137 1.1 agc int (*truncate)(const char *, off_t);
138 1.1 agc int (*utime)(const char *, struct utimbuf *);
139 1.1 agc int (*open)(const char *, struct fuse_file_info *);
140 1.1 agc int (*read)(const char *, char *, size_t, off_t, struct fuse_file_info *);
141 1.1 agc int (*write)(const char *, const char *, size_t, off_t, struct fuse_file_info *);
142 1.1 agc int (*statfs)(const char *, struct statvfs *);
143 1.1 agc int (*flush)(const char *, struct fuse_file_info *);
144 1.1 agc int (*release)(const char *, struct fuse_file_info *);
145 1.1 agc int (*fsync)(const char *, int, struct fuse_file_info *);
146 1.1 agc int (*setxattr)(const char *, const char *, const char *, size_t, int);
147 1.1 agc int (*getxattr)(const char *, const char *, char *, size_t);
148 1.1 agc int (*listxattr)(const char *, char *, size_t);
149 1.1 agc int (*removexattr)(const char *, const char *);
150 1.1 agc int (*opendir)(const char *, struct fuse_file_info *);
151 1.1 agc int (*readdir)(const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *);
152 1.1 agc int (*releasedir)(const char *, struct fuse_file_info *);
153 1.1 agc int (*fsyncdir)(const char *, int, struct fuse_file_info *);
154 1.1 agc void *(*init)(struct fuse_conn_info *);
155 1.1 agc void (*destroy)(void *);
156 1.1 agc int (*access)(const char *, int);
157 1.1 agc int (*create)(const char *, mode_t, struct fuse_file_info *);
158 1.1 agc int (*ftruncate)(const char *, off_t, struct fuse_file_info *);
159 1.1 agc int (*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
160 1.1 agc int (*lock)(const char *, struct fuse_file_info *, int, struct flock *);
161 1.1 agc int (*utimens)(const char *, const struct timespec *);
162 1.1 agc int (*bmap)(const char *, size_t , uint64_t *);
163 1.1 agc };
164 1.1 agc
165 1.1 agc
166 1.22 pho struct fuse *fuse_new(struct fuse_args *,
167 1.8 pooka const struct fuse_operations *, size_t, void *);
168 1.8 pooka
169 1.22 pho int fuse_mount(struct fuse *, const char *);
170 1.22 pho void fuse_unmount(struct fuse *);
171 1.22 pho
172 1.22 pho int fuse_daemonize(struct fuse *);
173 1.22 pho
174 1.1 agc int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
175 1.8 pooka int fuse_loop(struct fuse *);
176 1.3 pooka struct fuse_context *fuse_get_context(void);
177 1.4 agc void fuse_exit(struct fuse *);
178 1.8 pooka void fuse_destroy(struct fuse *);
179 1.23 maya int fuse_version(void);
180 1.8 pooka
181 1.8 pooka #if FUSE_USE_VERSION == 22
182 1.8 pooka #define fuse_unmount fuse_unmount_compat22
183 1.8 pooka #endif
184 1.8 pooka
185 1.8 pooka void fuse_unmount_compat22(const char *);
186 1.1 agc
187 1.16 agc #if FUSE_USE_VERSION >= 26
188 1.22 pho #define fuse_main(argc, argv, op, user_data) \
189 1.22 pho fuse_main_real(argc, argv, op, sizeof(*(op)), user_data)
190 1.15 agc #else
191 1.1 agc #define fuse_main(argc, argv, op) \
192 1.1 agc fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
193 1.15 agc #endif
194 1.1 agc
195 1.1 agc #ifdef __cplusplus
196 1.1 agc }
197 1.1 agc #endif
198 1.1 agc
199 1.14 agc #include <fuse_opt.h>
200 1.14 agc
201 1.1 agc #endif
202