Home | History | Annotate | Line # | Download | only in libpuffs
puffs.h revision 1.121
      1 /*	$NetBSD: puffs.h,v 1.121 2012/04/18 00:57:22 manu Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
      5  *
      6  * Development of this software was supported by the
      7  * Google Summer of Code program and the Ulla Tuominen Foundation.
      8  * The Google SoC project was mentored by Bill Studenmund.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     22  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  */
     31 
     32 #ifndef _PUFFS_H_
     33 #define _PUFFS_H_
     34 
     35 #include <sys/param.h>
     36 #include <sys/types.h>
     37 #include <sys/mount.h>
     38 #include <sys/namei.h>
     39 #include <sys/stat.h>
     40 #include <sys/statvfs.h>
     41 #include <sys/time.h>
     42 #include <sys/vnode.h>
     43 
     44 #include <fs/puffs/puffs_msgif.h>
     45 
     46 #include <mntopts.h>
     47 #include <stdbool.h>
     48 #include <string.h>
     49 
     50 /* forwards */
     51 struct puffs_cc;
     52 
     53 struct puffs_getreq;
     54 struct puffs_cred;
     55 struct puffs_newinfo;
     56 
     57 /* paths */
     58 struct puffs_pathobj {
     59 	void 		*po_path;
     60 	size_t		po_len;
     61 	uint32_t	po_hash;
     62 };
     63 
     64 /* for prefix rename */
     65 struct puffs_pathinfo {
     66 	struct puffs_pathobj *pi_old;
     67 	struct puffs_pathobj *pi_new;
     68 };
     69 
     70 /* describes one segment cached in the kernel */
     71 struct puffs_kcache {
     72 	off_t	pkc_start;
     73 	off_t	pkc_end;
     74 
     75 	LIST_ENTRY(puffs_kcache) pkc_entries;
     76 };
     77 
     78 /* XXX: might disappear from here into a private header */
     79 struct puffs_node {
     80 	off_t			pn_size;
     81 	int			pn_flags;
     82 	struct vattr		pn_va;
     83 
     84 	void			*pn_data;	/* private data		*/
     85 
     86 	struct puffs_pathobj	pn_po;		/* PUFFS_FLAG_BUILDPATH */
     87 
     88 	struct puffs_usermount 	*pn_mnt;
     89 	LIST_ENTRY(puffs_node)	pn_entries;
     90 
     91 	LIST_HEAD(,puffs_kcache)pn_cacheinfo;	/* PUFFS_KFLAG_CACHE	*/
     92 };
     93 #define PUFFS_NODE_REMOVED	0x01		/* not on entry list	*/
     94 
     95 
     96 struct puffs_usermount;
     97 
     98 /*
     99  * megaXXX: these are values from inside _KERNEL
    100  * need to work on the translation for ALL the necessary values.
    101  */
    102 #define PUFFS_VNOVAL (-1)
    103 
    104 #define PUFFS_IO_APPEND 0x020
    105 #define PUFFS_IO_NDELAY	0x100
    106 
    107 #define PUFFS_VEXEC	01
    108 #define PUFFS_VWRITE	02
    109 #define PUFFS_VREAD	04
    110 
    111 #define PUFFS_FSYNC_DATAONLY 0x0002
    112 #define PUFFS_FSYNC_CACHE    0x0100
    113 
    114 #define PUFFS_EXTATTR_LIST_LENPREFIX 1
    115 /*
    116  * Magic constants
    117  */
    118 #define PUFFS_CC_STACKSHIFT_DEFAULT 18
    119 
    120 struct puffs_cn {
    121 	struct puffs_kcn	*pcn_pkcnp;	/* kernel input */
    122 	struct puffs_cred	*pcn_cred;	/* cred used for lookup */
    123 
    124 	struct puffs_pathobj	pcn_po_full;	/* PUFFS_FLAG_BUILDPATH */
    125 };
    126 #define pcn_nameiop	pcn_pkcnp->pkcn_nameiop
    127 #define pcn_flags	pcn_pkcnp->pkcn_flags
    128 #define pcn_name	pcn_pkcnp->pkcn_name
    129 #define pcn_namelen	pcn_pkcnp->pkcn_namelen
    130 #define pcn_consume	pcn_pkcnp->pkcn_consume
    131 
    132 /*
    133  * Puffs options to mount
    134  */
    135 /* kernel */
    136 #define	PUFFSMOPT_NAMECACHE	{ "namecache", 1, PUFFS_KFLAG_NOCACHE_NAME, 1 }
    137 #define	PUFFSMOPT_PAGECACHE	{ "pagecache", 1, PUFFS_KFLAG_NOCACHE_PAGE, 1 }
    138 #define	PUFFSMOPT_ATTRCACHE	{ "attrcache", 1, PUFFS_KFLAG_NOCACHE_ATTR, 1 }
    139 #define	PUFFSMOPT_CACHE		{ "cache", 1, PUFFS_KFLAG_NOCACHE, 1 }
    140 #define PUFFSMOPT_ALLOPS	{ "allops", 0, PUFFS_KFLAG_ALLOPS, 1 }
    141 
    142 /* libpuffs */
    143 #define PUFFSMOPT_DUMP		{ "dump", 0, PUFFS_FLAG_OPDUMP, 1 }
    144 
    145 #define PUFFSMOPT_STD							\
    146 	PUFFSMOPT_NAMECACHE,						\
    147 	PUFFSMOPT_PAGECACHE,						\
    148 	PUFFSMOPT_ATTRCACHE,						\
    149 	PUFFSMOPT_CACHE,						\
    150 	PUFFSMOPT_ALLOPS,						\
    151 	PUFFSMOPT_DUMP
    152 
    153 extern const struct mntopt puffsmopts[]; /* puffs.c */
    154 
    155 /* callbacks for operations */
    156 struct puffs_ops {
    157 	int (*puffs_fs_unmount)(struct puffs_usermount *, int);
    158 	int (*puffs_fs_statvfs)(struct puffs_usermount *, struct statvfs *);
    159 	int (*puffs_fs_sync)(struct puffs_usermount *, int,
    160 	    const struct puffs_cred *);
    161 	int (*puffs_fs_fhtonode)(struct puffs_usermount *, void *, size_t,
    162 	    struct puffs_newinfo *);
    163 	int (*puffs_fs_nodetofh)(struct puffs_usermount *, puffs_cookie_t,
    164 	    void *, size_t *);
    165 	int (*puffs_fs_extattrctl)(struct puffs_usermount *, int,
    166 	    puffs_cookie_t, int, int, const char *);
    167 
    168 	int (*puffs_node_lookup)(struct puffs_usermount *,
    169 	    puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *);
    170 	int (*puffs_node_create)(struct puffs_usermount *,
    171 	    puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
    172 	    const struct vattr *);
    173 	int (*puffs_node_mknod)(struct puffs_usermount *,
    174 	    puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
    175 	    const struct vattr *);
    176 	int (*puffs_node_open)(struct puffs_usermount *,
    177 	    puffs_cookie_t, int, const struct puffs_cred *);
    178 	int (*puffs_node_close)(struct puffs_usermount *,
    179 	    puffs_cookie_t, int, const struct puffs_cred *);
    180 	int (*puffs_node_access)(struct puffs_usermount *,
    181 	    puffs_cookie_t, int, const struct puffs_cred *);
    182 	int (*puffs_node_getattr)(struct puffs_usermount *,
    183 	    puffs_cookie_t, struct vattr *, const struct puffs_cred *);
    184 	int (*puffs_node_setattr)(struct puffs_usermount *,
    185 	    puffs_cookie_t, const struct vattr *, const struct puffs_cred *);
    186 	int (*puffs_node_poll)(struct puffs_usermount *, puffs_cookie_t, int *);
    187 	int (*puffs_node_mmap)(struct puffs_usermount *,
    188 	    puffs_cookie_t, vm_prot_t, const struct puffs_cred *);
    189 	int (*puffs_node_fsync)(struct puffs_usermount *,
    190 	    puffs_cookie_t, const struct puffs_cred *, int, off_t, off_t);
    191 	int (*puffs_node_seek)(struct puffs_usermount *,
    192 	    puffs_cookie_t, off_t, off_t, const struct puffs_cred *);
    193 	int (*puffs_node_remove)(struct puffs_usermount *,
    194 	    puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
    195 	int (*puffs_node_link)(struct puffs_usermount *,
    196 	    puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
    197 	int (*puffs_node_rename)(struct puffs_usermount *,
    198 	    puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *,
    199 	    puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
    200 	int (*puffs_node_mkdir)(struct puffs_usermount *,
    201 	    puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
    202 	    const struct vattr *);
    203 	int (*puffs_node_rmdir)(struct puffs_usermount *,
    204 	    puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
    205 	int (*puffs_node_symlink)(struct puffs_usermount *,
    206 	    puffs_cookie_t, struct puffs_newinfo *, const struct puffs_cn *,
    207 	    const struct vattr *,
    208 	    const char *);
    209 	int (*puffs_node_readdir)(struct puffs_usermount *,
    210 	    puffs_cookie_t, struct dirent *, off_t *, size_t *,
    211 	    const struct puffs_cred *, int *, off_t *, size_t *);
    212 	int (*puffs_node_readlink)(struct puffs_usermount *,
    213 	    puffs_cookie_t, const struct puffs_cred *, char *, size_t *);
    214 	int (*puffs_node_reclaim)(struct puffs_usermount *, puffs_cookie_t);
    215 	int (*puffs_node_inactive)(struct puffs_usermount *, puffs_cookie_t);
    216 	int (*puffs_node_print)(struct puffs_usermount *, puffs_cookie_t);
    217 	int (*puffs_node_pathconf)(struct puffs_usermount *,
    218 	    puffs_cookie_t, int, register_t *);
    219 	int (*puffs_node_advlock)(struct puffs_usermount *,
    220 	    puffs_cookie_t, void *, int, struct flock *, int);
    221 	int (*puffs_node_read)(struct puffs_usermount *, puffs_cookie_t,
    222 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
    223 	int (*puffs_node_write)(struct puffs_usermount *, puffs_cookie_t,
    224 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
    225 	int (*puffs_node_abortop)(struct puffs_usermount *, puffs_cookie_t,
    226 	    const struct puffs_cn *);
    227 	int (*puffs_node_getextattr)(struct puffs_usermount *, puffs_cookie_t,
    228 	    int, const char *, size_t *, uint8_t *, size_t *,
    229 	    const struct puffs_cred *);
    230 	int (*puffs_node_setextattr)(struct puffs_usermount *, puffs_cookie_t,
    231 	    int, const char *, uint8_t *, size_t *, const struct puffs_cred *);
    232 	int (*puffs_node_listextattr)(struct puffs_usermount *, puffs_cookie_t,
    233 	    int, size_t *, uint8_t *, size_t *, int, const struct puffs_cred *);
    234 	int (*puffs_node_deleteextattr)(struct puffs_usermount *,
    235 	    puffs_cookie_t, int, const char *, const struct puffs_cred *);
    236 	int (*puffs_node_getattr_ttl)(struct puffs_usermount *,
    237 	    puffs_cookie_t, struct vattr *, const struct puffs_cred *,
    238 	    struct timespec *);
    239 	int (*puffs_node_setattr_ttl)(struct puffs_usermount *,
    240 	    puffs_cookie_t, struct vattr *, const struct puffs_cred *,
    241 	    struct timespec *);
    242 
    243 	void *puffs_ops_spare[30];
    244 };
    245 
    246 typedef	int (*pu_pathbuild_fn)(struct puffs_usermount *,
    247 			       const struct puffs_pathobj *,
    248 			       const struct puffs_pathobj *, size_t,
    249 			       struct puffs_pathobj *);
    250 typedef int (*pu_pathtransform_fn)(struct puffs_usermount *,
    251 				   const struct puffs_pathobj *,
    252 				   const struct puffs_cn *,
    253 				   struct puffs_pathobj *);
    254 typedef int (*pu_pathcmp_fn)(struct puffs_usermount *, struct puffs_pathobj *,
    255 			  struct puffs_pathobj *, size_t, int);
    256 typedef void (*pu_pathfree_fn)(struct puffs_usermount *,
    257 			       struct puffs_pathobj *);
    258 typedef int (*pu_namemod_fn)(struct puffs_usermount *,
    259 			     struct puffs_pathobj *, struct puffs_cn *);
    260 
    261 typedef void (*pu_errnotify_fn)(struct puffs_usermount *,
    262 				uint8_t, int, const char *, puffs_cookie_t);
    263 
    264 typedef void (*pu_prepost_fn)(struct puffs_usermount *);
    265 
    266 typedef struct puffs_node *(*pu_cmap_fn)(struct puffs_usermount *,
    267 					 puffs_cookie_t);
    268 
    269 enum {
    270 	PUFFS_STATE_BEFOREMOUNT,	PUFFS_STATE_RUNNING,
    271 	PUFFS_STATE_UNMOUNTING,		PUFFS_STATE_UNMOUNTED
    272 };
    273 
    274 #define PUFFS_FLAG_BUILDPATH	0x80000000	/* node paths in pnode */
    275 #define PUFFS_FLAG_OPDUMP	0x40000000	/* dump all operations */
    276 #define PUFFS_FLAG_HASHPATH	0x20000000	/* speedup: hash paths */
    277 #define PUFFS_FLAG_MASK		0xe0000000
    278 
    279 #define PUFFS_FLAG_KERN(a)	((a) & PUFFS_KFLAG_MASK)
    280 #define PUFFS_FLAG_LIB(a)	((a) & PUFFS_FLAG_MASK)
    281 
    282 /* blocking mode argument */
    283 #define PUFFSDEV_BLOCK 0
    284 #define PUFFSDEV_NONBLOCK 1
    285 
    286 #define PUFFS_STACKSIZE_DEFAULT (1<<PUFFS_CC_STACKSHIFT_DEFAULT)
    287 #define PUFFS_STACKSIZE_MIN ((size_t)-1)
    288 
    289 #define		DENT_DOT	0
    290 #define		DENT_DOTDOT	1
    291 #define		DENT_ADJ(a)	((a)-2)	/* nth request means dir's n-2th */
    292 
    293 
    294 /*
    295  * protos
    296  */
    297 
    298 #define PUFFSOP_PROTOS(fsname)						\
    299 	int fsname##_fs_unmount(struct puffs_usermount *, int);		\
    300 	int fsname##_fs_statvfs(struct puffs_usermount *,		\
    301 	    struct statvfs *);						\
    302 	int fsname##_fs_sync(struct puffs_usermount *, int,		\
    303 	    const struct puffs_cred *cred);				\
    304 	int fsname##_fs_fhtonode(struct puffs_usermount *, void *,	\
    305 	    size_t, struct puffs_newinfo *);				\
    306 	int fsname##_fs_nodetofh(struct puffs_usermount *,		\
    307 	    puffs_cookie_t, void *, size_t *);				\
    308 	int fsname##_fs_extattrctl(struct puffs_usermount *, int,	\
    309 	    puffs_cookie_t, int, int, const char *);			\
    310 									\
    311 	int fsname##_node_lookup(struct puffs_usermount *,		\
    312 	    puffs_cookie_t, struct puffs_newinfo *,			\
    313 	    const struct puffs_cn *);					\
    314 	int fsname##_node_create(struct puffs_usermount *,		\
    315 	    puffs_cookie_t, struct puffs_newinfo *,			\
    316 	    const struct puffs_cn *, const struct vattr *);		\
    317 	int fsname##_node_mknod(struct puffs_usermount *,		\
    318 	    puffs_cookie_t, struct puffs_newinfo *,			\
    319 	    const struct puffs_cn *, const struct vattr *);		\
    320 	int fsname##_node_open(struct puffs_usermount *,		\
    321 	    puffs_cookie_t, int, const struct puffs_cred *);		\
    322 	int fsname##_node_close(struct puffs_usermount *,		\
    323 	    puffs_cookie_t, int, const struct puffs_cred *);		\
    324 	int fsname##_node_access(struct puffs_usermount *,		\
    325 	    puffs_cookie_t, int, const struct puffs_cred *);		\
    326 	int fsname##_node_getattr(struct puffs_usermount *,		\
    327 	    puffs_cookie_t, struct vattr *, const struct puffs_cred *);	\
    328 	int fsname##_node_setattr(struct puffs_usermount *,		\
    329 	    puffs_cookie_t, const struct vattr *,			\
    330 	    const struct puffs_cred *);					\
    331 	int fsname##_node_poll(struct puffs_usermount *,		\
    332 	    puffs_cookie_t, int *);					\
    333 	int fsname##_node_mmap(struct puffs_usermount *,		\
    334 	    puffs_cookie_t, vm_prot_t, const struct puffs_cred *);	\
    335 	int fsname##_node_fsync(struct puffs_usermount *,		\
    336 	    puffs_cookie_t, const struct puffs_cred *, int,		\
    337 	    off_t, off_t);						\
    338 	int fsname##_node_seek(struct puffs_usermount *,		\
    339 	    puffs_cookie_t, off_t, off_t, const struct puffs_cred *);	\
    340 	int fsname##_node_remove(struct puffs_usermount *,		\
    341 	    puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);	\
    342 	int fsname##_node_link(struct puffs_usermount *,		\
    343 	    puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);	\
    344 	int fsname##_node_rename(struct puffs_usermount *,		\
    345 	    puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *,	\
    346 	    puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);	\
    347 	int fsname##_node_mkdir(struct puffs_usermount *,		\
    348 	    puffs_cookie_t, struct puffs_newinfo *,			\
    349 	    const struct puffs_cn *, const struct vattr *);		\
    350 	int fsname##_node_rmdir(struct puffs_usermount *,		\
    351 	    puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);	\
    352 	int fsname##_node_symlink(struct puffs_usermount *,		\
    353 	    puffs_cookie_t, struct puffs_newinfo *,			\
    354 	    const struct puffs_cn *, const struct vattr *,		\
    355 	    const char *);						\
    356 	int fsname##_node_readdir(struct puffs_usermount *,		\
    357 	    puffs_cookie_t, struct dirent *, off_t *, size_t *,		\
    358 	    const struct puffs_cred *, int *, off_t *, size_t *);	\
    359 	int fsname##_node_readlink(struct puffs_usermount *,		\
    360 	    puffs_cookie_t, const struct puffs_cred *, char *,		\
    361 	    size_t *);							\
    362 	int fsname##_node_reclaim(struct puffs_usermount *,		\
    363 	    puffs_cookie_t);						\
    364 	int fsname##_node_inactive(struct puffs_usermount *,		\
    365 	    puffs_cookie_t);						\
    366 	int fsname##_node_print(struct puffs_usermount *,		\
    367 	    puffs_cookie_t);						\
    368 	int fsname##_node_pathconf(struct puffs_usermount *,		\
    369 	    puffs_cookie_t, int, register_t *);				\
    370 	int fsname##_node_advlock(struct puffs_usermount *,		\
    371 	    puffs_cookie_t, void *, int, struct flock *, int);		\
    372 	int fsname##_node_read(struct puffs_usermount *, puffs_cookie_t,\
    373 	    uint8_t *, off_t, size_t *, const struct puffs_cred *, int);\
    374 	int fsname##_node_write(struct puffs_usermount *,		\
    375 	    puffs_cookie_t, uint8_t *, off_t, size_t *,			\
    376 	    const struct puffs_cred *, int);				\
    377 	int fsname##_node_abortop(struct puffs_usermount *,		\
    378 	    puffs_cookie_t, const struct puffs_cn *);			\
    379 	int fsname##_node_getextattr(struct puffs_usermount *,		\
    380 	    puffs_cookie_t, int, const char *, size_t *, uint8_t *,	\
    381 	    size_t *, const struct puffs_cred *);			\
    382 	int fsname##_node_setextattr(struct puffs_usermount *,		\
    383 	    puffs_cookie_t, int, const char *, uint8_t *, size_t *,	\
    384 	    const struct puffs_cred *);					\
    385 	int fsname##_node_listextattr(struct puffs_usermount *,		\
    386 	    puffs_cookie_t, int, size_t *, uint8_t *, size_t *,		\
    387 	    int, const struct puffs_cred *);				\
    388 	int fsname##_node_deleteextattr(struct puffs_usermount *,	\
    389 	    puffs_cookie_t, int, const char *,				\
    390 	    const struct puffs_cred *);					\
    391 	int fsname##_node_getattr_ttl(struct puffs_usermount *,		\
    392 	    puffs_cookie_t, struct vattr *, const struct puffs_cred *,	\
    393 	    struct timespec *);						\
    394 	int fsname##_node_setattr_ttl(struct puffs_usermount *,		\
    395 	    puffs_cookie_t, struct vattr *, const struct puffs_cred *,	\
    396 	    struct timespec *);
    397 
    398 
    399 #define PUFFSOP_INIT(ops)						\
    400     ops = malloc(sizeof(struct puffs_ops));				\
    401     memset(ops, 0, sizeof(struct puffs_ops))
    402 #define PUFFSOP_SET(ops, fsname, fsornode, opname)			\
    403     (ops)->puffs_##fsornode##_##opname = fsname##_##fsornode##_##opname
    404 #define PUFFSOP_SETFSNOP(ops, opname)					\
    405     (ops)->puffs_fs_##opname = puffs_fsnop_##opname
    406 
    407 PUFFSOP_PROTOS(puffs_null)	/* XXX */
    408 
    409 #define PNPATH(pnode)	((pnode)->pn_po.po_path)
    410 #define PNPLEN(pnode)	((pnode)->pn_po.po_len)
    411 #define PCNPATH(pcnode)	((pcnode)->pcn_po_full.po_path)
    412 #define PCNPLEN(pcnode)	((pcnode)->pcn_po_full.po_len)
    413 #define PCNISDOTDOT(pcnode) \
    414 	((pcnode)->pcn_namelen == 2 && strcmp((pcnode)->pcn_name, "..") == 0)
    415 
    416 #define PUFFS_STORE_DCOOKIE(cp, ncp, off)				\
    417 if (cp)	{								\
    418 	*((cp)++) = off;						\
    419 	(*(ncp))++;							\
    420 }
    421 
    422 /* mainloop */
    423 typedef void (*puffs_ml_loop_fn)(struct puffs_usermount *);
    424 
    425 /* framebuf stuff */
    426 struct puffs_framebuf;
    427 typedef int (*puffs_framev_readframe_fn)(struct puffs_usermount *,
    428 					   struct puffs_framebuf *,
    429 					   int, int *);
    430 typedef	int (*puffs_framev_writeframe_fn)(struct puffs_usermount *,
    431 					    struct puffs_framebuf *,
    432 					    int, int *);
    433 typedef int (*puffs_framev_cmpframe_fn)(struct puffs_usermount *,
    434 					 struct puffs_framebuf *,
    435 					 struct puffs_framebuf *,
    436 					 int *);
    437 typedef void (*puffs_framev_fdnotify_fn)(struct puffs_usermount *, int, int);
    438 typedef void (*puffs_framev_gotframe_fn)(struct puffs_usermount *,
    439 					struct puffs_framebuf *);
    440 typedef void (*puffs_framev_cb)(struct puffs_usermount *,
    441 				struct puffs_framebuf *,
    442 				void *, int);
    443 #define PUFFS_FBIO_READ		0x01
    444 #define PUFFS_FBIO_WRITE	0x02
    445 #define PUFFS_FBIO_ERROR	0x04
    446 
    447 #define PUFFS_FBQUEUE_URGENT	0x01
    448 
    449 
    450 __BEGIN_DECLS
    451 
    452 #define PUFFS_DEFER ((void *)-1)
    453 struct puffs_usermount *puffs_init(struct puffs_ops *, const char *,
    454 				    const char *, void *, uint32_t);
    455 int		puffs_mount(struct puffs_usermount *, const char *, int, void*);
    456 int		puffs_exit(struct puffs_usermount *, int);
    457 void		puffs_cancel(struct puffs_usermount *, int);
    458 int		puffs_mainloop(struct puffs_usermount *);
    459 int		puffs_daemon(struct puffs_usermount *, int, int);
    460 
    461 int		puffs_unmountonsignal(int, bool);
    462 
    463 
    464 int	puffs_getselectable(struct puffs_usermount *);
    465 int	puffs_setblockingmode(struct puffs_usermount *, int);
    466 int	puffs_getstate(struct puffs_usermount *);
    467 void	puffs_setstacksize(struct puffs_usermount *, size_t);
    468 
    469 void	puffs_ml_setloopfn(struct puffs_usermount *, puffs_ml_loop_fn);
    470 void	puffs_ml_settimeout(struct puffs_usermount *, struct timespec *);
    471 
    472 void			puffs_setroot(struct puffs_usermount *,
    473 				      struct puffs_node *);
    474 struct puffs_node 	*puffs_getroot(struct puffs_usermount *);
    475 void			puffs_setrootinfo(struct puffs_usermount *,
    476 					  enum vtype, vsize_t, dev_t);
    477 
    478 void			*puffs_getspecific(struct puffs_usermount *);
    479 void			puffs_setspecific(struct puffs_usermount *, void *);
    480 void			puffs_setmaxreqlen(struct puffs_usermount *, size_t);
    481 size_t			puffs_getmaxreqlen(struct puffs_usermount *);
    482 void			puffs_setfhsize(struct puffs_usermount *, size_t, int);
    483 void			puffs_setmntinfo(struct puffs_usermount *,
    484 					 const char *, const char *);
    485 
    486 void			puffs_setncookiehash(struct puffs_usermount *, int);
    487 
    488 struct puffs_pathobj	*puffs_getrootpathobj(struct puffs_usermount *);
    489 
    490 void			puffs_setback(struct puffs_cc *, int);
    491 
    492 struct puffs_node	*puffs_pn_new(struct puffs_usermount *, void *);
    493 void			puffs_pn_remove(struct puffs_node *);
    494 void			puffs_pn_put(struct puffs_node *);
    495 struct vattr		*puffs_pn_getvap(struct puffs_node *);
    496 void *			puffs_pn_getpriv(struct puffs_node *);
    497 void			puffs_pn_setpriv(struct puffs_node *, void *);
    498 struct puffs_pathobj	*puffs_pn_getpo(struct puffs_node *);
    499 struct puffs_usermount	*puffs_pn_getmnt(struct puffs_node *);
    500 struct timespec		*puffs_pn_getvattl(struct puffs_node *);
    501 struct timespec		*puffs_pn_getcnttl(struct puffs_node *);
    502 
    503 void	puffs_newinfo_setcookie(struct puffs_newinfo *, puffs_cookie_t);
    504 void	puffs_newinfo_setvtype(struct puffs_newinfo *, enum vtype);
    505 void	puffs_newinfo_setsize(struct puffs_newinfo *, voff_t);
    506 void	puffs_newinfo_setrdev(struct puffs_newinfo *, dev_t);
    507 void	puffs_newinfo_setva(struct puffs_newinfo *, struct vattr *);
    508 void	puffs_newinfo_setvattl(struct puffs_newinfo *, struct timespec *);
    509 void	puffs_newinfo_setcnttl(struct puffs_newinfo *, struct timespec *);
    510 
    511 void			*puffs_pn_getmntspecific(struct puffs_node *);
    512 
    513 typedef		void *	(*puffs_nodewalk_fn)(struct puffs_usermount *,
    514 					     struct puffs_node *, void *);
    515 void			*puffs_pn_nodewalk(struct puffs_usermount *,
    516 					   puffs_nodewalk_fn, void *);
    517 
    518 void			puffs_setvattr(struct vattr *, const struct vattr *);
    519 void			puffs_vattr_null(struct vattr *);
    520 
    521 void			puffs_null_setops(struct puffs_ops *);
    522 
    523 int			puffs_dispatch_create(struct puffs_usermount *,
    524 					      struct puffs_framebuf *,
    525 					      struct puffs_cc **);
    526 int			puffs_dispatch_exec(struct puffs_cc *,
    527 					    struct puffs_framebuf **);
    528 
    529 /*
    530  * generic/dummy routines applicable for some file systems
    531  */
    532 int  puffs_fsnop_unmount(struct puffs_usermount *, int);
    533 int  puffs_fsnop_statvfs(struct puffs_usermount *, struct statvfs *);
    534 void puffs_zerostatvfs(struct statvfs *);
    535 int  puffs_fsnop_sync(struct puffs_usermount *, int waitfor,
    536 		      const struct puffs_cred *);
    537 
    538 int  puffs_genfs_node_getattr(struct puffs_usermount *, puffs_cookie_t,
    539 			      struct vattr *, const struct puffs_cred *);
    540 int  puffs_genfs_node_reclaim(struct puffs_usermount *, puffs_cookie_t);
    541 
    542 /*
    543  * Subroutine stuff
    544  */
    545 
    546 int		puffs_gendotdent(struct dirent **, ino_t, int, size_t *);
    547 int		puffs_nextdent(struct dirent **, const char *, ino_t,
    548 			       uint8_t, size_t *);
    549 int		puffs_vtype2dt(enum vtype);
    550 enum vtype	puffs_mode2vt(mode_t);
    551 void		puffs_stat2vattr(struct vattr *va, const struct stat *);
    552 mode_t		puffs_addvtype2mode(mode_t, enum vtype);
    553 
    554 
    555 /*
    556  * credentials & permissions
    557  */
    558 
    559 /* Credential fetch */
    560 int	puffs_cred_getuid(const struct puffs_cred *, uid_t *);
    561 int	puffs_cred_getgid(const struct puffs_cred *, gid_t *);
    562 int	puffs_cred_getgroups(const struct puffs_cred *, gid_t *, short *);
    563 
    564 /* Credential check */
    565 bool	puffs_cred_isuid(const struct puffs_cred *, uid_t);
    566 bool	puffs_cred_hasgroup(const struct puffs_cred *, gid_t);
    567 bool	puffs_cred_isregular(const struct puffs_cred *);
    568 bool	puffs_cred_iskernel(const struct puffs_cred *);
    569 bool	puffs_cred_isfs(const struct puffs_cred *);
    570 bool	puffs_cred_isjuggernaut(const struct puffs_cred *);
    571 
    572 /* misc */
    573 int	puffs_access(enum vtype, mode_t, uid_t, gid_t, mode_t,
    574 		     const struct puffs_cred *);
    575 int	puffs_access_chown(uid_t, gid_t, uid_t, gid_t,
    576 			   const struct puffs_cred *);
    577 int	puffs_access_chmod(uid_t, gid_t, enum vtype, mode_t,
    578 			   const struct puffs_cred *);
    579 int	puffs_access_times(uid_t, gid_t, mode_t, int,
    580 			   const struct puffs_cred *);
    581 
    582 
    583 /*
    584  * Call Context interfaces relevant for user.
    585  */
    586 
    587 void			puffs_cc_yield(struct puffs_cc *);
    588 void			puffs_cc_continue(struct puffs_cc *);
    589 void			puffs_cc_schedule(struct puffs_cc *);
    590 int			puffs_cc_getcaller(struct puffs_cc *,pid_t *,lwpid_t *);
    591 struct puffs_cc		*puffs_cc_getcc(struct puffs_usermount *);
    592 
    593 /*
    594  * Flushing / invalidation routines
    595  */
    596 
    597 int	puffs_inval_namecache_dir(struct puffs_usermount *, puffs_cookie_t);
    598 int	puffs_inval_namecache_all(struct puffs_usermount *);
    599 
    600 int	puffs_inval_pagecache_node(struct puffs_usermount *, puffs_cookie_t);
    601 int	puffs_inval_pagecache_node_range(struct puffs_usermount *,
    602 					 puffs_cookie_t, off_t, off_t);
    603 int	puffs_flush_pagecache_node(struct puffs_usermount *, puffs_cookie_t);
    604 int	puffs_flush_pagecache_node_range(struct puffs_usermount *,
    605 					 puffs_cookie_t, off_t, off_t);
    606 
    607 /*
    608  * Path constructicons
    609  */
    610 
    611 int	puffs_stdpath_buildpath(struct puffs_usermount *,
    612 			     const struct puffs_pathobj *,
    613 			     const struct puffs_pathobj *, size_t,
    614 			     struct puffs_pathobj *);
    615 int	puffs_stdpath_cmppath(struct puffs_usermount *, struct puffs_pathobj *,
    616 			   struct puffs_pathobj *, size_t, int);
    617 void	puffs_stdpath_freepath(struct puffs_usermount *,struct puffs_pathobj *);
    618 
    619 void	*puffs_path_walkcmp(struct puffs_usermount *,
    620 			    struct puffs_node *, void *);
    621 void	*puffs_path_prefixadj(struct puffs_usermount *,
    622 			      struct puffs_node *, void *);
    623 int	puffs_path_pcnbuild(struct puffs_usermount *,
    624 			    struct puffs_cn *, void *);
    625 void	puffs_path_buildhash(struct puffs_usermount *, struct puffs_pathobj *);
    626 void	puffs_set_pathbuild(struct puffs_usermount *, pu_pathbuild_fn); void	puffs_set_pathtransform(struct puffs_usermount *, pu_pathtransform_fn);
    627 void	puffs_set_pathcmp(struct puffs_usermount *, pu_pathcmp_fn);
    628 void	puffs_set_pathfree(struct puffs_usermount *, pu_pathfree_fn);
    629 void	puffs_set_namemod(struct puffs_usermount *, pu_namemod_fn);
    630 
    631 void	puffs_set_errnotify(struct puffs_usermount *, pu_errnotify_fn);
    632 void	puffs_kernerr_log(struct puffs_usermount *, uint8_t, int,
    633 			  const char *, puffs_cookie_t);
    634 __dead void	puffs_kernerr_abort(struct puffs_usermount *, uint8_t, int,
    635 			    const char *, puffs_cookie_t);
    636 void	puffs_set_prepost(struct puffs_usermount *,
    637 			  pu_prepost_fn, pu_prepost_fn);
    638 void	puffs_set_cmap(struct puffs_usermount *, pu_cmap_fn);
    639 
    640 /*
    641  * Suspension
    642  */
    643 
    644 int	puffs_fs_suspend(struct puffs_usermount *);
    645 
    646 /*
    647  * Frame buffering
    648  */
    649 
    650 void	puffs_framev_init(struct puffs_usermount *,
    651 			  puffs_framev_readframe_fn,
    652 			  puffs_framev_writeframe_fn,
    653 			  puffs_framev_cmpframe_fn,
    654 			  puffs_framev_gotframe_fn,
    655 			  puffs_framev_fdnotify_fn);
    656 
    657 struct puffs_framebuf 	*puffs_framebuf_make(void);
    658 void			puffs_framebuf_destroy(struct puffs_framebuf *);
    659 int			puffs_framebuf_dup(struct puffs_framebuf *,
    660 					   struct puffs_framebuf **);
    661 void			puffs_framebuf_recycle(struct puffs_framebuf *);
    662 int			puffs_framebuf_reserve_space(struct puffs_framebuf *,
    663 						     size_t);
    664 
    665 int	puffs_framebuf_putdata(struct puffs_framebuf *, const void *, size_t);
    666 int	puffs_framebuf_putdata_atoff(struct puffs_framebuf *, size_t,
    667 				     const void *, size_t);
    668 int	puffs_framebuf_getdata(struct puffs_framebuf *, void *, size_t);
    669 int	puffs_framebuf_getdata_atoff(struct puffs_framebuf *, size_t,
    670 				     void *, size_t);
    671 
    672 size_t	puffs_framebuf_telloff(struct puffs_framebuf *);
    673 size_t	puffs_framebuf_tellsize(struct puffs_framebuf *);
    674 size_t	puffs_framebuf_remaining(struct puffs_framebuf *);
    675 int	puffs_framebuf_seekset(struct puffs_framebuf *, size_t);
    676 int	puffs_framebuf_getwindow(struct puffs_framebuf *, size_t,
    677 				 void **, size_t *);
    678 
    679 int	puffs_framev_enqueue_cc(struct puffs_cc *, int,
    680 				struct puffs_framebuf *, int);
    681 int	puffs_framev_enqueue_cb(struct puffs_usermount *, int,
    682 				struct puffs_framebuf *,
    683 				puffs_framev_cb, void *, int);
    684 int	puffs_framev_enqueue_justsend(struct puffs_usermount *, int,
    685 				      struct puffs_framebuf *, int, int);
    686 int	puffs_framev_enqueue_directreceive(struct puffs_cc *, int,
    687 					   struct puffs_framebuf *, int);
    688 int	puffs_framev_enqueue_directsend(struct puffs_cc *, int,
    689 					   struct puffs_framebuf *, int);
    690 int	puffs_framev_enqueue_waitevent(struct puffs_cc *, int, int *);
    691 int	puffs_framev_framebuf_ccpromote(struct puffs_framebuf *,
    692 					struct puffs_cc *);
    693 
    694 int	puffs_framev_addfd(struct puffs_usermount *, int, int);
    695 int	puffs_framev_enablefd(struct puffs_usermount *, int, int);
    696 int	puffs_framev_disablefd(struct puffs_usermount *, int, int);
    697 int	puffs_framev_removefd(struct puffs_usermount *, int, int);
    698 void	puffs_framev_removeonclose(struct puffs_usermount *, int, int);
    699 void	puffs_framev_unmountonclose(struct puffs_usermount *, int, int);
    700 
    701 __END_DECLS
    702 
    703 #endif /* _PUFFS_H_ */
    704