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