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