1 /*
2   FUSE: Filesystem in Userspace
3   Copyright (C) 2001-2007  Miklos Szeredi <miklos@szeredi.hu>
4 
5   This program can be distributed under the terms of the GNU LGPLv2.
6   See the file COPYING.LIB
7 */
8 
9 #include "fuse.h"
10 #include "fuse_lowlevel.h"
11 
12 struct fuse_chan;
13 struct fuse_ll;
14 
15 struct fuse_session {
16 	struct fuse_session_ops op;
17 
18 	int (*receive_buf)(struct fuse_session *se, struct fuse_buf *buf,
19 			   struct fuse_chan **chp);
20 
21 	void (*process_buf)(void *data, const struct fuse_buf *buf,
22 			    struct fuse_chan *ch);
23 
24 	void *data;
25 
26 	volatile int exited;
27 
28 	struct fuse_chan *ch;
29 };
30 
31 struct fuse_req {
32 	struct fuse_ll *f;
33 	uint64_t unique;
34 	int ctr;
35 	pthread_mutex_t lock;
36 	struct fuse_ctx ctx;
37 	struct fuse_chan *ch;
38 	int interrupted;
39 	unsigned int ioctl_64bit : 1;
40 	union {
41 		struct {
42 			uint64_t unique;
43 		} i;
44 		struct {
45 			fuse_interrupt_func_t func;
46 			void *data;
47 		} ni;
48 	} u;
49 	struct fuse_req *next;
50 	struct fuse_req *prev;
51 };
52 
53 struct fuse_notify_req {
54 	uint64_t unique;
55 	void (*reply)(struct fuse_notify_req *, fuse_req_t, fuse_ino_t,
56 		      const void *, const struct fuse_buf *);
57 	struct fuse_notify_req *next;
58 	struct fuse_notify_req *prev;
59 };
60 
61 struct fuse_ll {
62 	int debug;
63 	int allow_root;
64 	int atomic_o_trunc;
65 	int no_remote_posix_lock;
66 	int no_remote_flock;
67 	int big_writes;
68 	int splice_write;
69 	int splice_move;
70 	int splice_read;
71 	int no_splice_write;
72 	int no_splice_move;
73 	int no_splice_read;
74 	struct fuse_lowlevel_ops op;
75 	int got_init;
76 	struct cuse_data *cuse_data;
77 	void *userdata;
78 	uid_t owner;
79 	struct fuse_conn_info conn;
80 	struct fuse_req list;
81 	struct fuse_req interrupts;
82 	pthread_mutex_t lock;
83 	int got_destroy;
84 	pthread_key_t pipe_key;
85 	int broken_splice_nonblock;
86 	uint64_t notify_ctr;
87 	struct fuse_notify_req notify_list;
88 };
89 
90 struct fuse_cmd {
91 	char *buf;
92 	size_t buflen;
93 	struct fuse_chan *ch;
94 };
95 
96 struct fuse *fuse_new_common(struct fuse_chan *ch, struct fuse_args *args,
97 			     const struct fuse_operations *op,
98 			     size_t op_size, void *user_data, int compat);
99 
100 int fuse_sync_compat_args(struct fuse_args *args);
101 
102 struct fuse_chan *fuse_kern_chan_new(int fd);
103 
104 struct fuse_session *fuse_lowlevel_new_common(struct fuse_args *args,
105 					const struct fuse_lowlevel_ops *op,
106 					size_t op_size, void *userdata);
107 
108 void fuse_kern_unmount_compat22(const char *mountpoint);
109 int fuse_chan_clearfd(struct fuse_chan *ch);
110 
111 void fuse_kern_unmount(const char *mountpoint, int fd);
112 int fuse_kern_mount(const char *mountpoint, struct fuse_args *args);
113 
114 int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
115 			       int count);
116 void fuse_free_req(fuse_req_t req);
117 
118 
119 struct fuse *fuse_setup_common(int argc, char *argv[],
120 			       const struct fuse_operations *op,
121 			       size_t op_size,
122 			       char **mountpoint,
123 			       int *multithreaded,
124 			       int *fd,
125 			       void *user_data,
126 			       int compat);
127 
128 void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeide, const void *inarg);
129 
130 int fuse_start_thread(pthread_t *thread_id, void *(*func)(void *), void *arg);
131