Home | History | Annotate | Line # | Download | only in puffs
puffs_msgif.h revision 1.6
      1 /*	$NetBSD: puffs_msgif.h,v 1.6 2006/11/09 13:09:34 pooka Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2005, 2006  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  * 3. The name of the company nor the name of the author may be used to
     19  *    endorse or promote products derived from this software without specific
     20  *    prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     23  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  */
     34 
     35 #ifndef _PUFFS_MSGIF_H_
     36 #define _PUFFS_MSGIF_H_
     37 
     38 #include <sys/param.h>
     39 #include <sys/time.h>
     40 #include <sys/ioccom.h>
     41 #include <sys/uio.h>
     42 #include <sys/vnode.h>
     43 #include <sys/ucred.h>
     44 #include <sys/statvfs.h>
     45 #include <sys/dirent.h>
     46 #include <sys/fcntl.h>
     47 
     48 #define PUFFSOP_VFS	1
     49 #define PUFFSOP_VN	2
     50 #define PUFFSOPFLAG_FAF	0x10	/* fire-and-forget */
     51 
     52 #define PUFFSOP_OPCMASK		0x03
     53 #define PUFFSOP_OPCLASS(a)	((a) & PUFFSOP_OPCMASK)
     54 #define PUFFSOP_WANTREPLY(a)	(((a) & PUFFSOPFLAG_FAF) == 0)
     55 
     56 enum {
     57 	PUFFS_VFS_MOUNT,	PUFFS_VFS_START,	PUFFS_VFS_UNMOUNT,
     58 	PUFFS_VFS_ROOT,		PUFFS_VFS_STATVFS,	PUFFS_VFS_SYNC,
     59 	PUFFS_VFS_VGET,		PUFFS_VFS_FHTOVP,	PUFFS_VFS_VPTOFH,
     60 	PUFFS_VFS_INIT,		PUFFS_VFS_DONE,		PUFFS_VFS_SNAPSHOT,
     61 	PUFFS_VFS_EXTATTCTL
     62 };
     63 #define PUFFS_VFS_MAX PUFFS_VFS_EXTATTCTL
     64 
     65 enum {
     66 	PUFFS_VN_LOOKUP,	PUFFS_VN_CREATE,	PUFFS_VN_MKNOD,
     67 	PUFFS_VN_OPEN,		PUFFS_VN_CLOSE,		PUFFS_VN_ACCESS,
     68 	PUFFS_VN_GETATTR,	PUFFS_VN_SETATTR,	PUFFS_VN_READ,
     69 	PUFFS_VN_WRITE,		PUFFS_VN_IOCTL,		PUFFS_VN_FCNTL,
     70 	PUFFS_VN_POLL,		PUFFS_VN_KQFILTER,	PUFFS_VN_REVOKE,
     71 	PUFFS_VN_MMAP,		PUFFS_VN_FSYNC,		PUFFS_VN_SEEK,
     72 	PUFFS_VN_REMOVE,	PUFFS_VN_LINK,		PUFFS_VN_RENAME,
     73 	PUFFS_VN_MKDIR,		PUFFS_VN_RMDIR,		PUFFS_VN_SYMLINK,
     74 	PUFFS_VN_READDIR,	PUFFS_VN_READLINK,	PUFFS_VN_ABORTOP,
     75 	PUFFS_VN_INACTIVE,	PUFFS_VN_RECLAIM,	PUFFS_VN_LOCK,
     76 	PUFFS_VN_UNLOCK,	PUFFS_VN_BMAP,		PUFFS_VN_STRATEGY,
     77 	PUFFS_VN_PRINT,		PUFFS_VN_ISLOCKED,	PUFFS_VN_PATHCONF,
     78 	PUFFS_VN_ADVLOCK,	PUFFS_VN_LEASE,		PUFFS_VN_WHITEOUT,
     79 	PUFFS_VN_GETPAGES,	PUFFS_VN_PUTPAGES,	PUFFS_VN_GETEXTATTR,
     80 	PUFFS_VN_LISTEXTATTR,	PUFFS_VN_OPENEXTATTR,	PUFFS_VN_DELETEEXTATTR,
     81 	PUFFS_VN_SETEXTATTR
     82 };
     83 #define PUFFS_VN_MAX PUFFS_VN_SETEXTATTR
     84 
     85 #define PUFFSVERSION	0	/* meaning: *NO* versioning yet */
     86 #define PUFFSNAMESIZE	32
     87 struct puffs_args {
     88 	int		pa_vers;
     89 	int		pa_fd;
     90 	unsigned int	pa_flags;
     91 	size_t		pa_maxreqlen;
     92 	char		pa_name[PUFFSNAMESIZE];	/* name for puffs type	*/
     93 };
     94 #define PUFFS_FLAG_ALLOWCTL	0x01	/* ioctl/fcntl commands allowed */
     95 #define PUFFS_FLAG_MASK		0x01
     96 
     97 /*
     98  * This is the device minor number for the cloning device.  Make it
     99  * a high number "just in case", even though we don't want to open
    100  * any specific devices currently.
    101  */
    102 #define PUFFS_CLONER 0x7ffff
    103 
    104 /*
    105  * This is the structure that travels on the user-kernel interface.
    106  * It is used to deliver ops to the user server and bring the results back
    107  */
    108 struct puffs_req {
    109 	uint64_t	preq_id;		/* OUT/IN	*/
    110 	uint8_t		preq_opclass;		/* OUT   	*/
    111 	uint8_t		preq_optype;		/* OUT		*/
    112 
    113 	int		preq_rv;		/* IN		*/
    114 
    115 	/*
    116 	 * preq_cookie is the node cookie associated with the request.
    117 	 * It always maps 1:1 to a vnode and should map to a userspace
    118 	 * struct puffs_node.  The cookie usually describes the first
    119 	 * vnode argument of the VOP_POP() in question.
    120 	 */
    121 	void	*preq_cookie;			/* OUT		*/
    122 
    123 	/* these come in from userspace twice (getop and putop) */
    124 	void	*preq_aux;			/* IN/IN	*/
    125 	size_t	preq_auxlen;			/* IN/IN	*/
    126 };
    127 
    128 #define PUFFS_REQFLAG_ADJBUF	0x01
    129 
    130 /*
    131  * Some operations have unknown size requirements.  So as the first
    132  * stab at handling it, do an extra bounce between the kernel and
    133  * userspace.
    134  */
    135 struct puffs_sizeop {
    136 	uint64_t	pso_reqid;
    137 
    138 	uint8_t		*pso_userbuf;
    139 	size_t		pso_bufsize;
    140 };
    141 
    142 /*
    143  * Credentials for an operation.  Can be either struct uucred for
    144  * ops called from a credential context or NOCRED/FSCRED for ops
    145  * called from within the kernel.  It is up to the implementation
    146  * if it makes a difference between these two and the super-user.
    147  */
    148 struct puffs_cred {
    149 	struct uucred	pcr_uuc;
    150 	uint8_t		pcr_type;
    151 	uint8_t		pcr_internal;
    152 };
    153 #define PUFFCRED_TYPE_UUC	1
    154 #define PUFFCRED_TYPE_INTERNAL	2
    155 
    156 #define PUFFCRED_CRED_NOCRED	1
    157 #define PUFFCRED_CRED_FSCRED	2
    158 
    159 
    160 #define PUFFSSTARTOP	_IOWR('p', 1, struct puffs_startreq)
    161 #define PUFFSGETOP	_IOWR('p', 2, struct puffs_req)
    162 #define PUFFSPUTOP	_IOWR('p', 3, struct puffs_req)
    163 #define PUFFSSIZEOP	_IOWR('p', 4, struct puffs_sizeop)
    164 
    165 /*
    166  * 4x MAXPHYS is the max size the system will attempt to copy,
    167  * else treated as garbage
    168  */
    169 #define PUFFS_REQ_MAXSIZE	4*MAXPHYS
    170 #define PUFFS_REQSTRUCT_MAX	4096 /* XXX: approxkludge */
    171 
    172 #define PUFFS_TOMOVE(a,b) (MIN((a), b->pmp_req_maxsize - PUFFS_REQSTRUCT_MAX))
    173 
    174 /* puffs struct componentname, for userspace */
    175 struct puffs_cn {
    176 	/* args */
    177 	u_long			pcn_nameiop;	/* namei operation	*/
    178 	u_long			pcn_flags;	/* flags		*/
    179 	pid_t			pcn_pid;	/* caller pid		*/
    180 	struct puffs_cred	pcn_cred;	/* caller creds		*/
    181 
    182 	/* shared */
    183 	char pcn_name[MAXPATHLEN];		/* path to lookup	*/
    184 	long pcn_namelen;			/* length of path	*/
    185 };
    186 
    187 /*
    188  * XXX: figure out what to do with these, copied from namei.h for now
    189  */
    190 #define	PUFFSLOOKUP_LOOKUP	0	/* perform name lookup only */
    191 #define PUFFSLOOKUP_CREATE	1	/* setup for file creation */
    192 #define PUFFSLOOKUP_DELETE	2	/* setup for file deletion */
    193 #define PUFFSLOOKUP_RENAME	3	/* setup for file renaming */
    194 #define PUFFSLOOKUP_OPMASK	3	/* mask for operation */
    195 
    196 #define PUFFSLOOKUP_FOLLOW	0x04	/* follow symlinks */
    197 #define PUFFSLOOKUP_NOFOLLOW	0x08	/* don't follow symlinks */
    198 #define PUFFSLOOKUP_OPTIONS	0x0c
    199 
    200 
    201 struct puffs_startreq {
    202 	void	*psr_cookie;		/* IN:  root node cookie */
    203 	fsid_t	psr_fsidx;		/* OUT: fsid value */
    204 };
    205 
    206 /*
    207  * aux structures for vfs operations.
    208  */
    209 struct puffs_vfsreq_unmount {
    210 	int			pvfsr_flags;
    211 	pid_t			pvfsr_pid;
    212 };
    213 
    214 struct puffs_vfsreq_statvfs {
    215 	struct statvfs		pvfsr_sb;
    216 	pid_t			pvfsr_pid;
    217 };
    218 
    219 struct puffs_vfsreq_sync {
    220 	struct puffs_cred	pvfsr_cred;
    221 	pid_t			pvfsr_pid;
    222 	int			pvfsr_waitfor;
    223 };
    224 
    225 /*
    226  * aux structures for vnode operations.
    227  */
    228 
    229 struct puffs_vnreq_lookup {
    230 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    231 	void			*pvnr_newnode;		/* IN	*/
    232 	enum vtype		pvnr_vtype;		/* IN	*/
    233 	voff_t			pvnr_size;		/* IN	*/
    234 	dev_t			pvnr_rdev;		/* IN	*/
    235 };
    236 
    237 struct puffs_vnreq_create {
    238 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    239 	struct vattr		pvnr_va;		/* OUT	*/
    240 	void			*pvnr_newnode;		/* IN	*/
    241 };
    242 
    243 struct puffs_vnreq_mknod {
    244 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    245 	struct vattr		pvnr_va;		/* OUT	*/
    246 	void			*pvnr_newnode;		/* IN	*/
    247 };
    248 
    249 struct puffs_vnreq_open {
    250 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    251 	pid_t			pvnr_pid;		/* OUT	*/
    252 	int			pvnr_mode;		/* OUT	*/
    253 };
    254 
    255 struct puffs_vnreq_close {
    256 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    257 	pid_t			pvnr_pid;		/* OUT	*/
    258 	int			pvnr_fflag;		/* OUT	*/
    259 };
    260 
    261 struct puffs_vnreq_access {
    262 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    263 	pid_t			pvnr_pid;		/* OUT	*/
    264 	int			pvnr_mode;		/* OUT	*/
    265 };
    266 
    267 #define puffs_vnreq_setattr puffs_vnreq_setgetattr
    268 #define puffs_vnreq_getattr puffs_vnreq_setgetattr
    269 struct puffs_vnreq_setgetattr {
    270 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    271 	struct vattr		pvnr_va;		/* IN/OUT (op depend) */
    272 	pid_t			pvnr_pid;		/* OUT	*/
    273 };
    274 
    275 #define puffs_vnreq_read puffs_vnreq_readwrite
    276 #define puffs_vnreq_write puffs_vnreq_readwrite
    277 struct puffs_vnreq_readwrite {
    278 	struct puffs_cred	pvnr_cred;		/* OUT	  */
    279 	off_t			pvnr_offset;		/* OUT	  */
    280 	size_t			pvnr_resid;		/* IN/OUT */
    281 	int			pvnr_ioflag;		/* OUT	  */
    282 
    283 	uint8_t			pvnr_data[0];		/* IN/OUT (wr/rd) */
    284 };
    285 
    286 #define puffs_vnreq_ioctl puffs_vnreq_fcnioctl
    287 #define puffs_vnreq_fcntl puffs_vnreq_fcnioctl
    288 struct puffs_vnreq_fcnioctl {
    289 	struct puffs_cred	pvnr_cred;
    290 	u_long			pvnr_command;
    291 	pid_t			pvnr_pid;
    292 	int			pvnr_fflag;
    293 
    294 	void			*pvnr_data;
    295 	size_t			pvnr_datalen;
    296 	int			pvnr_copyback;
    297 };
    298 
    299 struct puffs_vnreq_poll {
    300 	int			pvnr_events;		/* OUT	*/
    301 	pid_t			pvnr_pid;		/* OUT	*/
    302 };
    303 
    304 struct puffs_vnreq_revoke {
    305 	int			pvnr_flags;		/* OUT	*/
    306 };
    307 
    308 struct puffs_vnreq_fsync {
    309 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    310 	off_t			pvnr_offlo;		/* OUT	*/
    311 	off_t			pvnr_offhi;		/* OUT	*/
    312 	pid_t			pvnr_pid;		/* OUT	*/
    313 	int			pvnr_flags;		/* OUT	*/
    314 };
    315 
    316 struct puffs_vnreq_seek {
    317 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    318 	off_t			pvnr_oldoff;		/* OUT	*/
    319 	off_t			pvnr_newoff;		/* OUT	*/
    320 };
    321 
    322 struct puffs_vnreq_remove {
    323 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    324 	void			*pvnr_cookie_targ;	/* OUT	*/
    325 };
    326 
    327 struct puffs_vnreq_mkdir {
    328 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    329 	struct vattr		pvnr_va;		/* OUT	*/
    330 	void			*pvnr_newnode;		/* IN	*/
    331 };
    332 
    333 struct puffs_vnreq_rmdir {
    334 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    335 	void			*pvnr_cookie_targ;	/* OUT	*/
    336 };
    337 
    338 struct puffs_vnreq_link {
    339 	struct puffs_cn		pvnr_cn;		/* OUT */
    340 	void			*pvnr_cookie_targ;	/* OUT */
    341 };
    342 
    343 struct puffs_vnreq_rename {
    344 	struct puffs_cn		pvnr_cn_src;		/* OUT	*/
    345 	struct puffs_cn		pvnr_cn_targ;		/* OUT	*/
    346 	void			*pvnr_cookie_src;	/* OUT	*/
    347 	void			*pvnr_cookie_targ;	/* OUT	*/
    348 	void			*pvnr_cookie_targdir;	/* OUT	*/
    349 };
    350 
    351 struct puffs_vnreq_symlink {
    352 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    353 	struct vattr		pvnr_va;		/* OUT	*/
    354 	void			*pvnr_newnode;		/* IN	*/
    355 	char			pvnr_link[MAXPATHLEN];	/* OUT	*/
    356 };
    357 
    358 struct puffs_vnreq_readdir {
    359 	struct puffs_cred	pvnr_cred;		/* OUT	  */
    360 	off_t			pvnr_offset;		/* IN/OUT */
    361 	size_t			pvnr_resid;		/* IN/OUT */
    362 
    363 	struct dirent		pvnr_dent[0];		/* IN  	   */
    364 };
    365 
    366 struct puffs_vnreq_readlink {
    367 	struct puffs_cred	pvnr_cred;		/* OUT */
    368 	size_t			pvnr_linklen;		/* IN  */
    369 	char			pvnr_link[MAXPATHLEN];	/* IN, XXX  */
    370 };
    371 
    372 struct puffs_vnreq_reclaim {
    373 	pid_t			pvnr_pid;		/* OUT	*/
    374 };
    375 
    376 struct puffs_vnreq_inactive {
    377 	pid_t			pvnr_pid;		/* OUT	*/
    378 	int			pvnr_backendrefs;	/* IN	*/
    379 };
    380 
    381 /* XXX: get rid of alltogether */
    382 struct puffs_vnreq_print {
    383 	/* empty */
    384 };
    385 
    386 struct puffs_vnreq_pathconf {
    387 	int			pvnr_name;		/* OUT	*/
    388 	int			pvnr_retval;		/* IN	*/
    389 };
    390 
    391 struct puffs_vnreq_advlock {
    392 	struct flock		pvnr_fl;		/* OUT	*/
    393 	void			*pvnr_id;		/* OUT	*/
    394 	int			pvnr_op;		/* OUT	*/
    395 	int			pvnr_flags;		/* OUT	*/
    396 };
    397 
    398 /* notyet */
    399 #if 0
    400 struct puffs_vnreq_kqfilter { };
    401 struct puffs_vnreq_islocked { };
    402 struct puffs_vnreq_lease { };
    403 #endif
    404 struct puffs_vnreq_getpages { };
    405 struct puffs_vnreq_putpages { };
    406 struct puffs_vnreq_mmap { };
    407 struct puffs_vnreq_getextattr { };
    408 struct puffs_vnreq_setextattr { };
    409 struct puffs_vnreq_listextattr { };
    410 
    411 #ifdef _KERNEL
    412 #define PUFFS_VFSREQ(a)							\
    413 	struct puffs_vfsreq_##a a##_arg;				\
    414 	memset(&a##_arg, 0, sizeof(struct puffs_vfsreq_##a))
    415 
    416 #define PUFFS_VNREQ(a)							\
    417 	struct puffs_vnreq_##a a##_arg;					\
    418 	memset(&a##_arg, 0, sizeof(struct puffs_vnreq_##a))
    419 #endif
    420 
    421 #endif /* _PUFFS_MSGIF_H_ */
    422