Create testappimage
[appimagekit/gsi.git] / squashfuse_dlopen.h
blobda3c34ff80c8081f4b631ea2c0653be1ea449119
1 #ifndef SQFS_DLOPEN_H
2 #define SQFS_DLOPEN_H
4 //#define ENABLE_DLOPEN
6 #ifdef ENABLE_DLOPEN
8 #include <dlfcn.h>
10 #include <time.h>
11 #include <utime.h>
12 #include <fcntl.h>
13 #include <inttypes.h>
14 #include <stdlib.h>
15 #include <stdio.h>
16 #include <sys/types.h>
17 #include <sys/stat.h>
18 #include <sys/statvfs.h>
19 #include <sys/uio.h>
22 /*** dlopen() stuff ***/
24 #define LIBNAME "libfuse.so.2"
26 void *libhandle;
27 int have_libloaded;
28 const char *load_library_errmsg;
30 #define LOAD_LIBRARY \
31 if (have_libloaded != 1) { \
32 if (!(libhandle = dlopen(LIBNAME, RTLD_LAZY))) { \
33 fprintf(stderr, "dlopen(): error loading " LIBNAME "\n\n%s", load_library_errmsg ); \
34 exit(1); \
35 } else { \
36 have_libloaded = 1; \
37 } \
40 #define STRINGIFY(x) #x
42 #define LOAD_SYMBOL(type,x,param) \
43 type (*dl_##x) param; \
44 *(void **) (&dl_##x) = dlsym(libhandle, STRINGIFY(x)); \
45 if (dlerror()) { \
46 fprintf(stderr, "dlsym(): error loading symbol from " LIBNAME "\n\n%s", load_library_errmsg ); \
47 CLOSE_LIBRARY; \
48 exit(1); \
51 #define DL(x) dl_##x
52 #define CLOSE_LIBRARY dlclose(libhandle);
55 /*** libfuse stuff ***/
57 #define FUSE_ROOT_ID 1
58 #define FUSE_ARGS_INIT(argc, argv) { argc, argv, 0 }
59 #define FUSE_OPT_KEY(templ, key) { templ, -1U, key }
60 #define FUSE_OPT_KEY_OPT -1
61 #define FUSE_OPT_KEY_NONOPT -2
62 #define FUSE_OPT_END { NULL, 0, 0 }
64 enum fuse_buf_flags {
65 FUSE_BUF_IS_FD = (1 << 1),
66 FUSE_BUF_FD_SEEK = (1 << 2),
67 FUSE_BUF_FD_RETRY = (1 << 3),
70 typedef unsigned long fuse_ino_t;
71 typedef struct fuse_req *fuse_req_t;
73 struct fuse_chan;
74 struct fuse_pollhandle;
76 struct fuse_args {
77 int argc;
78 char **argv;
79 int allocated;
82 typedef int (*fuse_fill_dir_t) (void *buf, const char *name, const struct stat *stbuf, off_t off);
83 typedef int (*fuse_opt_proc_t)(void *data, const char *arg, int key, struct fuse_args *outargs);
84 typedef struct fuse_dirhandle *fuse_dirh_t;
85 typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type, ino_t ino);
87 struct fuse_file_info {
88 int flags;
89 unsigned long fh_old;
90 int writepage;
91 unsigned int direct_io : 1;
92 unsigned int keep_cache : 1;
93 unsigned int flush : 1;
94 unsigned int nonseekable : 1;
95 unsigned int flock_release : 1;
96 unsigned int padding : 27;
97 uint64_t fh;
98 uint64_t lock_owner;
101 struct fuse_entry_param {
102 fuse_ino_t ino;
103 unsigned long generation;
104 struct stat attr;
105 double attr_timeout;
106 double entry_timeout;
109 struct fuse_opt {
110 const char *templ;
111 unsigned long offset;
112 int value;
115 struct fuse_forget_data {
116 uint64_t ino;
117 uint64_t nlookup;
120 struct fuse_conn_info {
121 unsigned proto_major;
122 unsigned proto_minor;
123 unsigned async_read;
124 unsigned max_write;
125 unsigned max_readahead;
126 unsigned capable;
127 unsigned want;
128 unsigned max_background;
129 unsigned congestion_threshold;
130 unsigned reserved[23];
133 struct fuse_buf {
134 size_t size;
135 enum fuse_buf_flags flags;
136 void *mem;
137 int fd;
138 off_t pos;
141 struct fuse_bufvec {
142 size_t count;
143 size_t idx;
144 size_t off;
145 struct fuse_buf buf[1];
148 struct fuse_context {
149 struct fuse *fuse;
150 uid_t uid;
151 gid_t gid;
152 pid_t pid;
153 void *private_data;
154 mode_t umask;
157 struct fuse_operations {
158 int (*getattr) (const char *, struct stat *);
159 int (*readlink) (const char *, char *, size_t);
160 int (*getdir) (const char *, fuse_dirh_t, fuse_dirfil_t);
161 int (*mknod) (const char *, mode_t, dev_t);
162 int (*mkdir) (const char *, mode_t);
163 int (*unlink) (const char *);
164 int (*rmdir) (const char *);
165 int (*symlink) (const char *, const char *);
166 int (*rename) (const char *, const char *);
167 int (*link) (const char *, const char *);
168 int (*chmod) (const char *, mode_t);
169 int (*chown) (const char *, uid_t, gid_t);
170 int (*truncate) (const char *, off_t);
171 int (*utime) (const char *, struct utimbuf *);
172 int (*open) (const char *, struct fuse_file_info *);
173 int (*read) (const char *, char *, size_t, off_t, struct fuse_file_info *);
174 int (*write) (const char *, const char *, size_t, off_t, struct fuse_file_info *);
175 int (*statfs) (const char *, struct statvfs *);
176 int (*flush) (const char *, struct fuse_file_info *);
177 int (*release) (const char *, struct fuse_file_info *);
178 int (*fsync) (const char *, int, struct fuse_file_info *);
179 int (*setxattr) (const char *, const char *, const char *, size_t, int);
180 int (*getxattr) (const char *, const char *, char *, size_t);
181 int (*listxattr) (const char *, char *, size_t);
182 int (*removexattr) (const char *, const char *);
183 int (*opendir) (const char *, struct fuse_file_info *);
184 int (*readdir) (const char *, void *, fuse_fill_dir_t, off_t, struct fuse_file_info *);
185 int (*releasedir) (const char *, struct fuse_file_info *);
186 int (*fsyncdir) (const char *, int, struct fuse_file_info *);
187 void *(*init) (struct fuse_conn_info *conn);
188 void (*destroy) (void *);
189 int (*access) (const char *, int);
190 int (*create) (const char *, mode_t, struct fuse_file_info *);
191 int (*ftruncate) (const char *, off_t, struct fuse_file_info *);
192 int (*fgetattr) (const char *, struct stat *, struct fuse_file_info *);
193 int (*lock) (const char *, struct fuse_file_info *, int cmd, struct flock *);
194 int (*utimens) (const char *, const struct timespec tv[2]);
195 int (*bmap) (const char *, size_t blocksize, uint64_t *idx);
196 unsigned int flag_nullpath_ok:1;
197 unsigned int flag_nopath:1;
198 unsigned int flag_utime_omit_ok:1;
199 unsigned int flag_reserved:29;
200 int (*ioctl) (const char *, int cmd, void *arg, struct fuse_file_info *, unsigned int flags, void *data);
201 int (*poll) (const char *, struct fuse_file_info *, struct fuse_pollhandle *ph, unsigned *reventsp);
202 int (*write_buf) (const char *, struct fuse_bufvec *buf, off_t off, struct fuse_file_info *);
203 int (*read_buf) (const char *, struct fuse_bufvec **bufp, size_t size, off_t off, struct fuse_file_info *);
204 int (*flock) (const char *, struct fuse_file_info *, int op);
205 int (*fallocate) (const char *, int, off_t, off_t, struct fuse_file_info *);
208 struct fuse_lowlevel_ops {
209 void (*init) (void *userdata, struct fuse_conn_info *conn);
210 void (*destroy) (void *userdata);
211 void (*lookup) (fuse_req_t req, fuse_ino_t parent, const char *name);
212 void (*forget) (fuse_req_t req, fuse_ino_t ino, unsigned long nlookup);
213 void (*getattr) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
214 void (*setattr) (fuse_req_t req, fuse_ino_t ino, struct stat *attr, int to_set, struct fuse_file_info *fi);
215 void (*readlink) (fuse_req_t req, fuse_ino_t ino);
216 void (*mknod) (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, dev_t rdev);
217 void (*mkdir) (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode);
218 void (*unlink) (fuse_req_t req, fuse_ino_t parent, const char *name);
219 void (*rmdir) (fuse_req_t req, fuse_ino_t parent, const char *name);
220 void (*symlink) (fuse_req_t req, const char *link, fuse_ino_t parent, const char *name);
221 void (*rename) (fuse_req_t req, fuse_ino_t parent, const char *name, fuse_ino_t newparent, const char *newname);
222 void (*link) (fuse_req_t req, fuse_ino_t ino, fuse_ino_t newparent, const char *newname);
223 void (*open) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
224 void (*read) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi);
225 void (*write) (fuse_req_t req, fuse_ino_t ino, const char *buf, size_t size, off_t off, struct fuse_file_info *fi);
226 void (*flush) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
227 void (*release) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
228 void (*fsync) (fuse_req_t req, fuse_ino_t ino, int datasync, struct fuse_file_info *fi);
229 void (*opendir) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
230 void (*readdir) (fuse_req_t req, fuse_ino_t ino, size_t size, off_t off, struct fuse_file_info *fi);
231 void (*releasedir) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi);
232 void (*fsyncdir) (fuse_req_t req, fuse_ino_t ino, int datasync, struct fuse_file_info *fi);
233 void (*statfs) (fuse_req_t req, fuse_ino_t ino);
234 void (*setxattr) (fuse_req_t req, fuse_ino_t ino, const char *name, const char *value, size_t size, int flags);
235 void (*getxattr) (fuse_req_t req, fuse_ino_t ino, const char *name, size_t size);
236 void (*listxattr) (fuse_req_t req, fuse_ino_t ino, size_t size);
237 void (*removexattr) (fuse_req_t req, fuse_ino_t ino, const char *name);
238 void (*access) (fuse_req_t req, fuse_ino_t ino, int mask);
239 void (*create) (fuse_req_t req, fuse_ino_t parent, const char *name, mode_t mode, struct fuse_file_info *fi);
240 void (*getlk) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct flock *lock);
241 void (*setlk) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct flock *lock, int sleep);
242 void (*bmap) (fuse_req_t req, fuse_ino_t ino, size_t blocksize, uint64_t idx);
243 void (*ioctl) (fuse_req_t req, fuse_ino_t ino, int cmd, void *arg, struct fuse_file_info *fi, unsigned flags, const void *in_buf, size_t in_bufsz, size_t out_bufsz);
244 void (*poll) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, struct fuse_pollhandle *ph);
245 void (*write_buf) (fuse_req_t req, fuse_ino_t ino, struct fuse_bufvec *bufv, off_t off, struct fuse_file_info *fi);
246 void (*retrieve_reply) (fuse_req_t req, void *cookie, fuse_ino_t ino, off_t offset, struct fuse_bufvec *bufv);
247 void (*forget_multi) (fuse_req_t req, size_t count, struct fuse_forget_data *forgets);
248 void (*flock) (fuse_req_t req, fuse_ino_t ino, struct fuse_file_info *fi, int op);
249 void (*fallocate) (fuse_req_t req, fuse_ino_t ino, int mode, off_t offset, off_t length, struct fuse_file_info *fi);
252 #else /* !ENABLE_DLOPEN */
254 #define LOAD_LIBRARY
255 #define LOAD_SYMBOL(x)
256 #define DL(x)
257 #define CLOSE_LIBRARY
259 #endif /* !ENABLE_DLOPEN */
261 #endif /* SQFS_DLOPEN_H */