1/* $OpenBSD: fuse.h,v 1.14 2018/05/16 13:09:17 helg 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
31extern "C" {
32#endif
33
34struct fuse_chan;
35struct fuse_args;
36struct fuse_session;
37
38struct 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
65struct 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
78struct 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
87typedef ino_t fuse_ino_t;
88typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *,
89    off_t);
90
91typedef struct fuse_dirhandle *fuse_dirh_t;
92typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t);
93
94/*
95 * Fuse operations work in the same way as their UNIX file system
96 * counterparts. A major exception is that these routines return
97 * a negated errno value (-errno) on failure.
98 */
99struct fuse_operations {
100	int	(*getattr)(const char *, struct stat *);
101	int	(*readlink)(const char *, char *, size_t);
102	int	(*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t);
103	int	(*mknod)(const char *, mode_t, dev_t);
104	int	(*mkdir)(const char *, mode_t);
105	int	(*unlink)(const char *);
106	int	(*rmdir)(const char *);
107	int	(*symlink)(const char *, const char *);
108	int	(*rename)(const char *, const char *);
109	int	(*link)(const char *, const char *);
110	int	(*chmod)(const char *, mode_t);
111	int	(*chown)(const char *, uid_t, gid_t);
112	int	(*truncate)(const char *, off_t);
113	int	(*utime)(const char *, struct utimbuf *);
114	int	(*open)(const char *, struct fuse_file_info *);
115	int	(*read)(const char *, char *, size_t, off_t,
116		struct fuse_file_info *);
117	int	(*write)(const char *, const char *, size_t, off_t,
118		struct fuse_file_info *);
119	int	(*statfs)(const char *, struct statvfs *);
120	int	(*flush)(const char *, struct fuse_file_info *);
121	int	(*release)(const char *, struct fuse_file_info *);
122	int	(*fsync)(const char *, int, struct fuse_file_info *);
123	int	(*setxattr)(const char *, const char *, const char *, size_t,
124		int);
125	int	(*getxattr)(const char *, const char *, char *, size_t);
126	int	(*listxattr)(const char *, char *, size_t);
127	int	(*removexattr)(const char *, const char *);
128	int	(*opendir)(const char *, struct fuse_file_info *);
129	int	(*readdir)(const char *, void *, fuse_fill_dir_t, off_t,
130		struct fuse_file_info *);
131	int	(*releasedir)(const char *, struct fuse_file_info *);
132	int	(*fsyncdir)(const char *, int, struct fuse_file_info *);
133	void	*(*init)(struct fuse_conn_info *);
134	void	(*destroy)(void *);
135	int	(*access)(const char *, int);
136	int	(*create)(const char *, mode_t, struct fuse_file_info *);
137	int	(*ftruncate)(const char *, off_t, struct fuse_file_info *);
138	int	(*fgetattr)(const char *, struct stat *, struct fuse_file_info *);
139	int	(*lock)(const char *, struct fuse_file_info *, int, struct flock *);
140	int	(*utimens)(const char *, const struct timespec *);
141	int	(*bmap)(const char *, size_t , uint64_t *);
142};
143
144#ifndef FUSE_USE_VERSION
145#define FUSE_USE_VERSION 26
146#endif
147
148#if FUSE_USE_VERSION >= 26
149#define FUSE_VERSION 26
150#else
151#error "Fuse version < 26 not supported"
152#endif
153
154#define	FUSE_MAJOR_VERSION 2
155#define	FUSE_MINOR_VERSION 6
156
157/*
158 * API prototypes
159 */
160int fuse_version(void);
161int fuse_main(int, char **, const struct fuse_operations *, void *);
162struct fuse *fuse_new(struct fuse_chan *, struct fuse_args *,
163    const struct fuse_operations *, size_t, void *);
164struct fuse *fuse_setup(int, char **, const struct fuse_operations *,
165    size_t, char **, int *, void *);
166int fuse_parse_cmdline(struct fuse_args *, char **, int *, int *);
167struct fuse_chan *fuse_mount(const char *, struct fuse_args *);
168void fuse_remove_signal_handlers(struct fuse_session *);
169int fuse_set_signal_handlers(struct fuse_session *);
170struct fuse_session *fuse_get_session(struct fuse *);
171struct fuse_context *fuse_get_context(void);
172int fuse_is_lib_option(const char *);
173int fuse_loop(struct fuse *);
174int fuse_loop_mt(struct fuse *);
175int fuse_chan_fd(struct fuse_chan *);
176void fuse_unmount(const char *, struct fuse_chan *);
177int fuse_daemonize(int);
178void fuse_destroy(struct fuse *);
179void fuse_teardown(struct fuse *, char *);
180int fuse_invalidate(struct fuse *, const char *);
181
182#ifdef __cplusplus
183}
184#endif
185
186#endif /* _FUSE_H_ */
187