perfuse_if.h revision 1.1 1 /* $NetBSD: perfuse_if.h,v 1.1 2010/08/25 07:16:00 manu Exp $ */
2
3 /*-
4 * Copyright (c) 2010 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 _REFUSE_PERFUSE_H
29 #define _REFUSE_PERFUSE_H
30
31 #define _PATH_FUSE "/dev/fuse"
32 #define FUSE_COMMFD_ENV "_FUSE_COMMFD"
33 #define PERFUSE_MOUNT_MAGIC "noFuseRq"
34 #define PERFUSE_UNKNOWN_INO 0xffffffff
35
36 /*
37 * Diagnostic flags. This global is used only for DPRINTF/DERR/DWARN
38 */
39 extern int perfuse_diagflags;
40 #define PDF_FOREGROUND 0x001 /* we run in foreground */
41 #define PDF_FUSE 0x002 /* Display FUSE reqeusts and reply */
42 #define PDF_DUMP 0x004 /* Dump FUSE frames */
43 #define PDF_PUFFS 0x008 /* Display PUFFS requets and reply */
44 #define PDF_FH 0x010 /* File handles */
45 #define PDF_RECLAIM 0x020 /* Reclaimed files */
46 #define PDF_READDIR 0x040 /* readdir operations */
47 #define PDF_REQUEUE 0x080 /* reueued messages */
48 #define PDF_MISC 0x100 /* Miscelaneous messages */
49 #define PDF_SYSLOG 0x200 /* use syslog */
50
51 /*
52 * Diagnostic functions
53 */
54 #define DPRINTF(fmt, ...) do { \
55 if (perfuse_diagflags & PDF_FOREGROUND) \
56 (void)printf(fmt, ## __VA_ARGS__); \
57 } while (0 /* CONSTCOND */)
58
59 #define DERRX(status, fmt, ...) do { \
60 if (perfuse_diagflags & PDF_SYSLOG) \
61 syslog(LOG_ERR, fmt, ## __VA_ARGS__); \
62 \
63 if (perfuse_diagflags & PDF_FOREGROUND) { \
64 (void)fprintf(stderr, fmt, ## __VA_ARGS__); \
65 abort(); \
66 } else { \
67 errx(status, fmt, ## __VA_ARGS__); \
68 } \
69 } while (0 /* CONSTCOND */)
70
71 #define DERR(status, fmt, ...) do { \
72 char fmterr[BUFSIZ]; \
73 char strerrbuf[BUFSIZ]; \
74 \
75 (void)strerror_r(errno, strerrbuf, sizeof(strerrbuf)); \
76 (void)sprintf(fmterr, "%s: %s\n", fmt, strerrbuf); \
77 \
78 if (perfuse_diagflags & PDF_SYSLOG) \
79 syslog(LOG_ERR, fmterr, ## __VA_ARGS__); \
80 \
81 if (perfuse_diagflags & PDF_FOREGROUND) { \
82 (void)fprintf(stderr, fmterr, ## __VA_ARGS__); \
83 abort(); \
84 } else { \
85 errx(status, fmt, ## __VA_ARGS__); \
86 } \
87 } while (0 /* CONSTCOND */)
88
89 #define DWARNX(fmt, ...) do { \
90 if (perfuse_diagflags & PDF_SYSLOG) \
91 syslog(LOG_WARNING, fmt, ## __VA_ARGS__); \
92 \
93 warnx(fmt, ## __VA_ARGS__); \
94 } while (0 /* CONSTCOND */)
95
96 #define DWARN(fmt, ...) do { \
97 char fmterr[BUFSIZ]; \
98 char strerrbuf[BUFSIZ]; \
99 \
100 (void)strerror_r(errno, strerrbuf, sizeof(strerrbuf)); \
101 (void)sprintf(fmterr, "%s: %s\n", fmt, strerrbuf); \
102 \
103 if (perfuse_diagflags & PDF_SYSLOG) \
104 syslog(LOG_WARNING, fmterr, ## __VA_ARGS__); \
105 \
106 warn(fmterr, ## __VA_ARGS__); \
107 } while (0 /* CONSTCOND */)
108
109 /*
110 * frame handling callbacks
111 */
112 #ifndef PEFUSE_MSG_T
113 #define PEFUSE_MSG_T struct perfuse_framebuf
114 #endif
115 typedef PEFUSE_MSG_T perfuse_msg_t;
116
117 #define PERFUSE_UNSPEC_REPLY_LEN (size_t)-1
118
119 enum perfuse_xchg_pb_reply { wait_reply, no_reply };
120 typedef perfuse_msg_t *(*perfuse_new_msg_fn)(struct puffs_usermount *,
121 puffs_cookie_t, int, size_t, const struct puffs_cred *);
122 typedef int (*perfuse_xchg_msg_fn)(struct puffs_usermount *,
123 perfuse_msg_t *, size_t, enum perfuse_xchg_pb_reply);
124 typedef void (*perfuse_destroy_msg_fn)(perfuse_msg_t *);
125 typedef struct fuse_out_header *(*perfuse_get_outhdr_fn)(perfuse_msg_t *);
126 typedef struct fuse_in_header *(*perfuse_get_inhdr_fn)(perfuse_msg_t *);
127 typedef char *(*perfuse_get_inpayload_fn)(perfuse_msg_t *);
128 typedef char *(*perfuse_get_outpayload_fn)(perfuse_msg_t *);
129
130 struct perfuse_callbacks {
131 perfuse_new_msg_fn pc_new_msg;
132 perfuse_xchg_msg_fn pc_xchg_msg;
133 perfuse_destroy_msg_fn pc_destroy_msg;
134 perfuse_get_inhdr_fn pc_get_inhdr;
135 perfuse_get_inpayload_fn pc_get_inpayload;
136 perfuse_get_outhdr_fn pc_get_outhdr;
137 perfuse_get_outpayload_fn pc_get_outpayload;
138 };
139
140 /*
141 * mount request
142 */
143 struct perfuse_mount_out {
144 uint32_t pmo_len;
145 int32_t pmo_error;
146 uint64_t pmo_unique;
147 char pmo_magic[sizeof(PERFUSE_MOUNT_MAGIC)];
148 size_t pmo_source_len;
149 size_t pmo_target_len;
150 size_t pmo_filesystemtype_len;
151 int pmo_mountflags;
152 size_t pmo_data_len;
153 };
154
155 struct perfuse_mount_info {
156 const char *pmi_source;
157 const char *pmi_target;
158 const char *pmi_filesystemtype;
159 int pmi_mountflags;
160 void *pmi_data;
161 uid_t pmi_uid;
162 };
163
164 /*
165 * Duplicated fro fuse.h to avoid making it public
166 */
167 #define FUSE_MIN_BUFSIZE 0x21000
168 #define FUSE_PREF_BUFSIZE (PAGE_SIZE + 0x1000)
169 #define FUSE_BUFSIZE MAX(FUSE_PREF_BUFSIZE, FUSE_MIN_BUFSIZE)
170
171 struct fuse_in_header {
172 uint32_t len;
173 uint32_t opcode;
174 uint64_t unique;
175 uint64_t nodeid;
176 uint32_t uid;
177 uint32_t gid;
178 uint32_t pid;
179 uint32_t padding;
180 };
181
182 struct fuse_out_header {
183 uint32_t len;
184 int32_t error;
185 uint64_t unique;
186 };
187
188 __BEGIN_DECLS
189
190 struct puffs_usermount *perfuse_init(struct perfuse_callbacks *,
191 struct perfuse_mount_info *);
192 void perfuse_setspecific(struct puffs_usermount *, void *);
193 void *perfuse_getspecific(struct puffs_usermount *);
194 uint64_t perfuse_next_unique(struct puffs_usermount *);
195 uint64_t perfuse_get_ino(struct puffs_usermount *, puffs_cookie_t);
196 int perfuse_inloop(struct puffs_usermount *);
197 const char *perfuse_opname(int);
198 void perfuse_fs_init(struct puffs_usermount *);
199 int perfuse_mainloop(struct puffs_usermount *);
200
201 #endif /* _REFUSE_PERFUSE_H */
202