xref: /openbsd-src/lib/libfuse/fuse.h (revision f2da64fbbbf1b03f09f390ab01267c93dfd77c4c)
1 /* $OpenBSD: fuse.h,v 1.12 2014/01/20 15:01:59 syl Exp $ */
2 /*
3  * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef _FUSE_H_
19 #define _FUSE_H_
20 
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <sys/statvfs.h>
24 
25 #include <fcntl.h>
26 #include <utime.h>
27 
28 #include <fuse_opt.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 struct fuse_chan;
35 struct fuse_args;
36 struct fuse_session;
37 
38 struct fuse_file_info {
39 	int32_t		flags;		/* open(2) flags */
40 	uint32_t	fh_old;		/* old file handle */
41 	int32_t		writepage;
42 	uint32_t	direct_io:1;
43 	uint32_t	keep_cache:1;
44 	uint32_t	flush:1;
45 	uint32_t	nonseekable:1;
46 	uint32_t	__padd:27;
47 	uint32_t	flock_release : 1;
48 	uint64_t	fh;		/* file handle */
49 	uint64_t	lock_owner;
50 };
51 
52 /* unused but needed for gvfs compilation */
53 #define FUSE_CAP_ASYNC_READ	(1 << 0)
54 #define FUSE_CAP_POSIX_LOCKS	(1 << 1)
55 #define FUSE_CAP_ATOMIC_O_TRUNC	(1 << 3)
56 #define FUSE_CAP_EXPORT_SUPPORT	(1 << 4)
57 #define FUSE_CAP_BIG_WRITES	(1 << 5)
58 #define FUSE_CAP_DONT_MASK	(1 << 6)
59 #define FUSE_CAP_SPLICE_WRITE	(1 << 7)
60 #define FUSE_CAP_SPLICE_MOVE	(1 << 8)
61 #define FUSE_CAP_SPLICE_READ	(1 << 9)
62 #define FUSE_CAP_FLOCK_LOCKS	(1 << 10)
63 #define FUSE_CAP_IOCTL_DIR	(1 << 11)
64 
65 struct fuse_conn_info {
66 	uint32_t	proto_major;
67 	uint32_t	proto_minor;
68 	uint32_t	async_read;
69 	uint32_t	max_write;
70 	uint32_t	max_readahead;
71 	uint32_t	capable;
72 	uint32_t	want;
73 	uint32_t	max_background;
74 	uint32_t	congestion_threshold;
75 	uint32_t	reserved[23];
76 };
77 
78 struct fuse_context {
79 	struct fuse *	fuse;
80 	uid_t		uid;
81 	gid_t		gid;
82 	pid_t		pid;
83 	void		*private_data;
84 	mode_t		umask;
85 };
86 
87 typedef ino_t fuse_ino_t;
88 typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *,
89     off_t);
90 
91 typedef struct fuse_dirhandle {
92 	fuse_fill_dir_t filler;
93 	void *buf;
94 	int filled;
95 	int full;
96 	int isgetdir;
97 	uint32_t size;
98 	uint32_t start;
99 	uint32_t idx;
100 	off_t off;
101 } *fuse_dirh_t;
102 
103 typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t);
104 
105 /*
106  * Fuse operations work in the same way as their UNIX file system
107  * counterparts. A major exception is that these routines return
108  * a negated errno value (-errno) on failure.
109  */
110 struct fuse_operations {
111 	int	(*getattr)(const char *, struct stat *);
112 	int	(*readlink)(const char *, char *, size_t);
113 	int	(*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t);
114 	int	(*mknod)(const char *, mode_t, dev_t);
115 	int	(*mkdir)(const char *, mode_t);
116 	int	(*unlink)(const char *);
117 	int	(*rmdir)(const char *);
118 	int	(*symlink)(const char *, const char *);
119 	int	(*rename)(const char *, const char *);
120 	int	(*link)(const char *, const char *);
121 	int	(*chmod)(const char *, mode_t);
122 	int	(*chown)(const char *, uid_t, gid_t);
123 	int	(*truncate)(const char *, off_t);
124 	int	(*utime)(const char *, struct utimbuf *);
125 	int	(*open)(const char *, struct fuse_file_info *);
126 	int	(*read)(const char *, char *, size_t, off_t,
127 		struct fuse_file_info *);
128 	int	(*write)(const char *, const char *, size_t, off_t,
129 		struct fuse_file_info *);
130 	int	(*statfs)(const char *, struct statvfs *);
131 	int	(*flush)(const char *, struct fuse_file_info *);
132 	int	(*release)(const char *, struct fuse_file_info *);
133 	int	(*fsync)(const char *, int, struct fuse_file_info *);
134 	int	(*setxattr)(const char *, const char *, const char *, size_t,
135 		int);
136 	int	(*getxattr)(const char *, const char *, char *, size_t);
137 	int	(*listxattr)(const char *, char *, size_t);
138 	int	(*removexattr)(const char *, const char *);
139 	int	(*opendir)(const char *, struct fuse_file_info *);
140 	int	(*readdir)(const char *, void *, fuse_fill_dir_t, off_t,
141 		struct fuse_file_info *);
142 	int	(*releasedir)(const char *, struct fuse_file_info *);
143 	int	(*fsyncdir)(const char *, int, struct fuse_file_info *);
144 	void	*(*init)(struct fuse_conn_info *);
145 	void	(*destroy)(void *);
146 	int	(*access)(const char *, int);
147 	int	(*create)(const char *, mode_t, struct fuse_file_info *);
148 	int	(*ftruncate)(const char *, off_t, struct fuse_file_info *);
149 	int	(*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
150 	int	(*lock)(const char *, struct fuse_file_info *, int, struct flock *);
151 	int	(*utimens)(const char *, const struct timespec *);
152 	int	(*bmap)(const char *, size_t , uint64_t *);
153 };
154 
155 #ifndef FUSE_USE_VERSION
156 #define FUSE_USE_VERSION 26
157 #endif
158 
159 #if FUSE_USE_VERSION >= 26
160 #define FUSE_VERSION 26
161 #else
162 #error "Fuse version < 26 not supported"
163 #endif
164 
165 #define	FUSE_MAJOR_VERSION 2
166 #define	FUSE_MINOR_VERSION 6
167 
168 /*
169  * API prototypes
170  */
171 int fuse_version(void);
172 int fuse_main(int, char **, const struct fuse_operations *, void *);
173 struct fuse *fuse_new(struct fuse_chan *, struct fuse_args *,
174     const struct fuse_operations *, size_t, void *);
175 struct fuse *fuse_setup(int, char **, const struct fuse_operations *,
176     size_t, char **, int *, void *);
177 int fuse_parse_cmdline(struct fuse_args *, char **, int *, int *);
178 struct fuse_chan *fuse_mount(const char *, struct fuse_args *);
179 void fuse_remove_signal_handlers(struct fuse_session *);
180 int fuse_set_signal_handlers(struct fuse_session *);
181 struct fuse_session *fuse_get_session(struct fuse *);
182 struct fuse_context *fuse_get_context(void);
183 int fuse_is_lib_option(const char *);
184 int fuse_loop(struct fuse *);
185 int fuse_loop_mt(struct fuse *);
186 int fuse_chan_fd(struct fuse_chan *);
187 void fuse_unmount(const char *, struct fuse_chan *);
188 int fuse_daemonize(int);
189 void fuse_destroy(struct fuse *);
190 void fuse_teardown(struct fuse *, char *);
191 int fuse_invalidate(struct fuse *, const char *);
192 
193 #ifdef __cplusplus
194 }
195 #endif
196 
197 #endif /* _FUSE_H_ */
198