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