perfuse_if.h revision 1.22 1 /* $NetBSD: perfuse_if.h,v 1.22 2016/10/19 01:30:35 christos Exp $ */
2
3 /*-
4 * Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
19 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef _PERFUSE_IF_H
29 #define _PERFUSE_IF_H
30
31 #ifndef _PATH_PERFUSED
32 #define _PATH_PERFUSED "/usr/sbin/perfused"
33 #endif /* _PATH_PERFUSED */
34 #define _PATH_FUSE "/dev/fuse"
35 #define FUSE_COMMFD_ENV "_FUSE_COMMFD"
36 #define PERFUSE_MOUNT_MAGIC "noFuseRq"
37 #define PERFUSE_UNKNOWN_INO 0xffffffff
38 #define PERFUSE_UNKNOWN_NODEID 0xffffffff
39
40 /*
41 * Diagnostic flags. This global is used only for DPRINTF/DERR/DWARN
42 */
43 extern int perfuse_diagflags;
44 #define PDF_FOREGROUND 0x0001 /* we run in foreground */
45 #define PDF_FUSE 0x0002 /* Display FUSE reqeusts and reply */
46 #define PDF_DUMP 0x0004 /* Dump FUSE frames */
47 #define PDF_PUFFS 0x0008 /* Display PUFFS requets and reply */
48 #define PDF_FH 0x0010 /* File handles */
49 #define PDF_RECLAIM 0x0020 /* Reclaimed files */
50 #define PDF_READDIR 0x0040 /* readdir operations */
51 #define PDF_REQUEUE 0x0080 /* reueued messages */
52 #define PDF_SYNC 0x0100 /* fsync and dirty flags */
53 #define PDF_MISC 0x0200 /* Miscelaneous messages */
54 #define PDF_SYSLOG 0x0400 /* use syslog */
55 #define PDF_FILENAME 0x0800 /* File names */
56 #define PDF_RESIZE 0x1000 /* Resize operations */
57 #define PDF_TRACE 0x2000 /* Trace FUSE calls */
58
59 /*
60 * Diagnostic functions
61 */
62 #define DPRINTF(fmt, ...) do { \
63 if (perfuse_diagflags & PDF_SYSLOG) \
64 syslog(LOG_INFO, fmt, ## __VA_ARGS__); \
65 \
66 if (perfuse_diagflags & PDF_FOREGROUND) \
67 (void)printf(fmt, ## __VA_ARGS__); \
68 } while (0 /* CONSTCOND */)
69
70 #define DERRX(status, fmt, ...) do { \
71 if (perfuse_diagflags & PDF_SYSLOG) \
72 syslog(LOG_ERR, fmt, ## __VA_ARGS__); \
73 \
74 if (perfuse_diagflags & PDF_FOREGROUND) { \
75 (void)fprintf(stderr, fmt, ## __VA_ARGS__); \
76 abort(); \
77 } else { \
78 errx(status, fmt, ## __VA_ARGS__); \
79 } \
80 } while (0 /* CONSTCOND */)
81
82 #define DERR(status, fmt, ...) do { \
83 if (perfuse_diagflags & PDF_SYSLOG) \
84 syslog(LOG_ERR, fmt ": %m", ## __VA_ARGS__); \
85 \
86 if (perfuse_diagflags & PDF_FOREGROUND) { \
87 char strerrbuf[BUFSIZ]; \
88 \
89 (void)strerror_r(errno, strerrbuf, sizeof(strerrbuf)); \
90 (void)fprintf(stderr, fmt ": %s", ## __VA_ARGS__, \
91 strerrbuf); \
92 abort(); \
93 } else { \
94 err(status, fmt, ## __VA_ARGS__); \
95 } \
96 } while (0 /* CONSTCOND */)
97
98 #define DWARNX(fmt, ...) do { \
99 if (perfuse_diagflags & PDF_SYSLOG) \
100 syslog(LOG_WARNING, fmt, ## __VA_ARGS__); \
101 \
102 warnx(fmt, ## __VA_ARGS__); \
103 } while (0 /* CONSTCOND */)
104
105 #define DWARN(fmt, ...) do { \
106 if (perfuse_diagflags & PDF_SYSLOG) \
107 syslog(LOG_WARNING, fmt ": %m", ## __VA_ARGS__); \
108 \
109 warn(fmt, ## __VA_ARGS__); \
110 } while (0 /* CONSTCOND */)
111
112 #define DWARNC(e, fmt, ...) do { \
113 if (perfuse_diagflags & PDF_SYSLOG) { \
114 errno = e; \
115 syslog(LOG_WARNING, fmt ": %m", ## __VA_ARGS__); \
116 } \
117 warnc(e, fmt, ## __VA_ARGS__); \
118 } while (0 /* CONSTCOND */)
119
120 /*
121 * frame handling callbacks
122 */
123 #ifndef PEFUSE_MSG_T
124 #define PEFUSE_MSG_T struct puffs_framebuf
125 #endif
126 typedef PEFUSE_MSG_T perfuse_msg_t;
127
128 #define PERFUSE_UNSPEC_REPLY_LEN (size_t)-1
129
130 enum perfuse_xchg_pb_reply { wait_reply, no_reply };
131 typedef perfuse_msg_t *(*perfuse_new_msg_fn)(struct puffs_usermount *,
132 puffs_cookie_t, int, size_t, const struct puffs_cred *);
133 typedef int (*perfuse_xchg_msg_fn)(struct puffs_usermount *,
134 perfuse_msg_t *, size_t, enum perfuse_xchg_pb_reply);
135 typedef void (*perfuse_destroy_msg_fn)(perfuse_msg_t *);
136 typedef struct fuse_out_header *(*perfuse_get_outhdr_fn)(perfuse_msg_t *);
137 typedef struct fuse_in_header *(*perfuse_get_inhdr_fn)(perfuse_msg_t *);
138 typedef char *(*perfuse_get_inpayload_fn)(perfuse_msg_t *);
139 typedef char *(*perfuse_get_outpayload_fn)(perfuse_msg_t *);
140 typedef void (*perfuse_umount_fn)(struct puffs_usermount *);
141 typedef void (*perfuse_fsreq_fn)(struct puffs_usermount *, perfuse_msg_t *);
142
143 struct perfuse_callbacks {
144 perfuse_new_msg_fn pc_new_msg;
145 perfuse_xchg_msg_fn pc_xchg_msg;
146 perfuse_destroy_msg_fn pc_destroy_msg;
147 perfuse_get_inhdr_fn pc_get_inhdr;
148 perfuse_get_inpayload_fn pc_get_inpayload;
149 perfuse_get_outhdr_fn pc_get_outhdr;
150 perfuse_get_outpayload_fn pc_get_outpayload;
151 perfuse_umount_fn pc_umount;
152 perfuse_fsreq_fn pc_fsreq;
153 void *pc_reserved[15];
154 };
155
156 /*
157 * mount request
158 */
159 struct perfuse_mount_out {
160 uint32_t pmo_len;
161 int32_t pmo_error;
162 uint64_t pmo_unique;
163 char pmo_magic[sizeof(PERFUSE_MOUNT_MAGIC)];
164 uint32_t pmo_source_len;
165 uint32_t pmo_target_len;
166 uint32_t pmo_filesystemtype_len;
167 uint32_t pmo_mountflags;
168 uint32_t pmo_data_len;
169 uint32_t pmo_sock_len;
170 };
171
172 struct perfuse_mount_info {
173 const char *pmi_source;
174 const char *pmi_target;
175 const char *pmi_filesystemtype;
176 int pmi_mountflags;
177 void *pmi_data;
178 uid_t pmi_uid;
179 };
180
181 /*
182 * Duplicated from fuse.h to avoid making it public
183 */
184 #ifndef FUSE_BUFSIZE
185 #define FUSE_MIN_BUFSIZE 0x21000
186 #define FUSE_PREF_BUFSIZE (sysconf(_SC_PAGESIZE) + 0x1000)
187 #define FUSE_BUFSIZE MAX(FUSE_PREF_BUFSIZE /* CONSTCOND */, FUSE_MIN_BUFSIZE)
188 #endif /* FUSE_BUFSIZE */
189
190 struct fuse_in_header {
191 uint32_t len;
192 uint32_t opcode;
193 uint64_t unique;
194 uint64_t nodeid;
195 uint32_t uid;
196 uint32_t gid;
197 uint32_t pid;
198 uint32_t padding;
199 };
200
201 struct fuse_out_header {
202 uint32_t len;
203 int32_t error;
204 uint64_t unique;
205 };
206
207 __BEGIN_DECLS
208
209 struct puffs_usermount *perfuse_init(struct perfuse_callbacks *,
210 struct perfuse_mount_info *);
211 void perfuse_setspecific(struct puffs_usermount *, void *);
212 void *perfuse_getspecific(struct puffs_usermount *);
213 uint64_t perfuse_next_unique(struct puffs_usermount *);
214 uint64_t perfuse_get_nodeid(struct puffs_usermount *, puffs_cookie_t);
215 int perfuse_inloop(struct puffs_usermount *);
216 const char *perfuse_opname(int);
217 void perfuse_fs_init(struct puffs_usermount *);
218 int perfuse_mainloop(struct puffs_usermount *);
219 int perfuse_unmount(struct puffs_usermount *);
220 void perfuse_trace_dump(struct puffs_usermount *, FILE *);
221 void perfuse_fsreq(struct puffs_usermount *, perfuse_msg_t *);
222 uint32_t perfuse_bufvar_from_env(const char *, uint32_t);
223
224 #endif /* _PERFUSE_IF_H */
225