fuse.h revision 1.11 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 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 struct fuse;
41 struct fuse_args; /* XXXsupportme */
42
43 struct fuse_file_info {
44 int32_t flags;
45 uint32_t fh_old;
46 int32_t writepage;
47 uint32_t direct_io:1;
48 uint32_t keep_cache:1;
49 uint32_t flush:1;
50 uint32_t padding:29;
51 uint64_t fh;
52 uint64_t lock_owner;
53 };
54
55 struct fuse_conn_info {
56 uint32_t proto_major;
57 uint32_t proto_minor;
58 uint32_t async_read;
59 uint32_t max_write;
60 uint32_t max_readahead;
61 uint32_t reserved[27];
62 };
63
64 /* equivalent'ish of puffs_cc */
65 struct fuse_context {
66 struct fuse *fuse;
67 uid_t uid;
68 gid_t gid;
69 pid_t pid;
70 void *private_data;
71 };
72
73 /**
74 * Argument list
75 */
76 struct fuse_args {
77 int argc;
78 char **argv;
79 int allocated;
80 };
81
82 /**
83 * Initializer for 'struct fuse_args'
84 */
85 #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
86
87 typedef struct puffs_fuse_dirh *fuse_dirh_t;
88
89 typedef int (*fuse_fill_dir_t)(void *, const char *, const struct stat *, off_t);
90 typedef int (*fuse_dirfil_t)(fuse_dirh_t, const char *, int, ino_t);
91
92 #define FUSE_VERSION 26
93 #define FUSE_MAJOR_VERSION 2
94 #define FUSE_MINOR_VERSION 6
95
96 /*
97 * These operations shadow those in puffs_usermount, and are used
98 * as a table of callbacks to make when file system requests come
99 * in.
100 *
101 * NOTE: keep same order as fuse
102 */
103 struct fuse_operations {
104 int (*getattr)(const char *, struct stat *);
105 int (*readlink)(const char *, char *, size_t);
106 int (*getdir)(const char *, fuse_dirh_t, fuse_dirfil_t);
107 int (*mknod)(const char *, mode_t, dev_t);
108 int (*mkdir)(const char *, mode_t);
109 int (*unlink)(const char *);
110 int (*rmdir)(const char *);
111 int (*symlink)(const char *, const char *);
112 int (*rename)(const char *, const char *);
113 int (*link)(const char *, const char *);
114 int (*chmod)(const char *, mode_t);
115 int (*chown)(const char *, uid_t, gid_t);
116 int (*truncate)(const char *, off_t);
117 int (*utime)(const char *, struct utimbuf *);
118 int (*open)(const char *, struct fuse_file_info *);
119 int (*read)(const char *, char *, size_t, off_t, struct fuse_file_info *);
120 int (*write)(const char *, const char *, size_t, off_t, struct fuse_file_info *);
121 int (*statfs)(const char *, struct statvfs *);
122 int (*flush)(const char *, struct fuse_file_info *);
123 int (*release)(const char *, struct fuse_file_info *);
124 int (*fsync)(const char *, int, struct fuse_file_info *);
125 int (*setxattr)(const char *, const char *, const char *, size_t, int);
126 int (*getxattr)(const char *, const char *, char *, size_t);
127 int (*listxattr)(const char *, char *, size_t);
128 int (*removexattr)(const char *, const char *);
129 int (*opendir)(const char *, struct fuse_file_info *);
130 int (*readdir)(const char *, void *, fuse_fill_dir_t, off_t, 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 struct puffs_ops puffs_ops; /* pointer to puffs operations */
143 };
144
145
146 struct fuse_chan *fuse_mount(const char *, struct fuse_args *);
147 struct fuse *fuse_new(struct fuse_chan *, struct fuse_args *,
148 const struct fuse_operations *, size_t, void *);
149
150 int fuse_main_real(int, char **, const struct fuse_operations *, size_t, void *);
151 int fuse_loop(struct fuse *);
152 struct fuse_context *fuse_get_context(void);
153 void fuse_exit(struct fuse *);
154 void fuse_destroy(struct fuse *);
155
156 void fuse_unmount(const char *, struct fuse_chan *);
157
158 #if FUSE_USE_VERSION == 22
159 #define fuse_unmount fuse_unmount_compat22
160 #endif
161
162 void fuse_unmount_compat22(const char *);
163
164 #define fuse_main(argc, argv, op) \
165 fuse_main_real(argc, argv, op, sizeof(*(op)), NULL)
166
167 #ifdef __cplusplus
168 }
169 #endif
170
171 #endif
172