Home | History | Annotate | Line # | Download | only in puffs
puffs_msgif.h revision 1.8
      1 /*	$NetBSD: puffs_msgif.h,v 1.8 2006/11/18 12:39:48 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 PUFFSFLAG_ALLOWCTL	0x01	/* ioctl/fcntl commands allowed */
     95 #define PUFFSFLAG_NOCACHE	0x02	/* flush page cache immediately	*/
     96 #define PUFFSFLAG_MASK		0x03
     97 
     98 /*
     99  * This is the device minor number for the cloning device.  Make it
    100  * a high number "just in case", even though we don't want to open
    101  * any specific devices currently.
    102  */
    103 #define PUFFS_CLONER 0x7ffff
    104 
    105 /*
    106  * This is the structure that travels on the user-kernel interface.
    107  * It is used to deliver ops to the user server and bring the results back
    108  */
    109 struct puffs_req {
    110 	uint64_t	preq_id;		/* OUT/IN	*/
    111 	uint8_t		preq_opclass;		/* OUT   	*/
    112 	uint8_t		preq_optype;		/* OUT		*/
    113 
    114 	int		preq_rv;		/* IN		*/
    115 
    116 	/*
    117 	 * preq_cookie is the node cookie associated with the request.
    118 	 * It always maps 1:1 to a vnode and should map to a userspace
    119 	 * struct puffs_node.  The cookie usually describes the first
    120 	 * vnode argument of the VOP_POP() in question.
    121 	 */
    122 	void	*preq_cookie;			/* OUT		*/
    123 
    124 	/* these come in from userspace twice (getop and putop) */
    125 	void	*preq_aux;			/* IN/IN	*/
    126 	size_t	preq_auxlen;			/* IN/IN	*/
    127 };
    128 
    129 #define PUFFS_REQFLAG_ADJBUF	0x01
    130 
    131 /*
    132  * Some operations have unknown size requirements.  So as the first
    133  * stab at handling it, do an extra bounce between the kernel and
    134  * userspace.
    135  */
    136 struct puffs_sizeop {
    137 	uint64_t	pso_reqid;
    138 
    139 	uint8_t		*pso_userbuf;
    140 	size_t		pso_bufsize;
    141 };
    142 
    143 /*
    144  * Credentials for an operation.  Can be either struct uucred for
    145  * ops called from a credential context or NOCRED/FSCRED for ops
    146  * called from within the kernel.  It is up to the implementation
    147  * if it makes a difference between these two and the super-user.
    148  */
    149 struct puffs_cred {
    150 	struct uucred	pcr_uuc;
    151 	uint8_t		pcr_type;
    152 	uint8_t		pcr_internal;
    153 };
    154 #define PUFFCRED_TYPE_UUC	1
    155 #define PUFFCRED_TYPE_INTERNAL	2
    156 
    157 #define PUFFCRED_CRED_NOCRED	1
    158 #define PUFFCRED_CRED_FSCRED	2
    159 
    160 
    161 #define PUFFSSTARTOP	_IOWR('p', 1, struct puffs_startreq)
    162 #define PUFFSGETOP	_IOWR('p', 2, struct puffs_req)
    163 #define PUFFSPUTOP	_IOWR('p', 3, struct puffs_req)
    164 #define PUFFSSIZEOP	_IOWR('p', 4, struct puffs_sizeop)
    165 
    166 /*
    167  * 4x MAXPHYS is the max size the system will attempt to copy,
    168  * else treated as garbage
    169  */
    170 #define PUFFS_REQ_MAXSIZE	4*MAXPHYS
    171 #define PUFFS_REQSTRUCT_MAX	4096 /* XXX: approxkludge */
    172 
    173 #define PUFFS_TOMOVE(a,b) (MIN((a), b->pmp_req_maxsize - PUFFS_REQSTRUCT_MAX))
    174 
    175 /* puffs struct componentname, for userspace */
    176 struct puffs_cn {
    177 	/* args */
    178 	u_long			pcn_nameiop;	/* namei operation	*/
    179 	u_long			pcn_flags;	/* flags		*/
    180 	pid_t			pcn_pid;	/* caller pid		*/
    181 	struct puffs_cred	pcn_cred;	/* caller creds		*/
    182 
    183 	/* shared */
    184 	char pcn_name[MAXPATHLEN];		/* path to lookup	*/
    185 	long pcn_namelen;			/* length of path	*/
    186 };
    187 
    188 /*
    189  * XXX: figure out what to do with these, copied from namei.h for now
    190  */
    191 #define	PUFFSLOOKUP_LOOKUP	0	/* perform name lookup only */
    192 #define PUFFSLOOKUP_CREATE	1	/* setup for file creation */
    193 #define PUFFSLOOKUP_DELETE	2	/* setup for file deletion */
    194 #define PUFFSLOOKUP_RENAME	3	/* setup for file renaming */
    195 #define PUFFSLOOKUP_OPMASK	3	/* mask for operation */
    196 
    197 #define PUFFSLOOKUP_FOLLOW	0x04	/* follow symlinks */
    198 #define PUFFSLOOKUP_NOFOLLOW	0x08	/* don't follow symlinks */
    199 #define PUFFSLOOKUP_OPTIONS	0x0c
    200 
    201 
    202 struct puffs_startreq {
    203 	void		*psr_cookie;	/* IN: root node cookie */
    204 	struct statvfs	psr_sb;		/* IN: statvfs buffer */
    205 };
    206 
    207 /*
    208  * aux structures for vfs operations.
    209  */
    210 struct puffs_vfsreq_unmount {
    211 	int			pvfsr_flags;
    212 	pid_t			pvfsr_pid;
    213 };
    214 
    215 struct puffs_vfsreq_statvfs {
    216 	struct statvfs		pvfsr_sb;
    217 	pid_t			pvfsr_pid;
    218 };
    219 
    220 struct puffs_vfsreq_sync {
    221 	struct puffs_cred	pvfsr_cred;
    222 	pid_t			pvfsr_pid;
    223 	int			pvfsr_waitfor;
    224 };
    225 
    226 /*
    227  * aux structures for vnode operations.
    228  */
    229 
    230 struct puffs_vnreq_lookup {
    231 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    232 	void			*pvnr_newnode;		/* IN	*/
    233 	enum vtype		pvnr_vtype;		/* IN	*/
    234 	voff_t			pvnr_size;		/* IN	*/
    235 	dev_t			pvnr_rdev;		/* IN	*/
    236 };
    237 
    238 struct puffs_vnreq_create {
    239 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    240 	struct vattr		pvnr_va;		/* OUT	*/
    241 	void			*pvnr_newnode;		/* IN	*/
    242 };
    243 
    244 struct puffs_vnreq_mknod {
    245 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    246 	struct vattr		pvnr_va;		/* OUT	*/
    247 	void			*pvnr_newnode;		/* IN	*/
    248 };
    249 
    250 struct puffs_vnreq_open {
    251 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    252 	pid_t			pvnr_pid;		/* OUT	*/
    253 	int			pvnr_mode;		/* OUT	*/
    254 };
    255 
    256 struct puffs_vnreq_close {
    257 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    258 	pid_t			pvnr_pid;		/* OUT	*/
    259 	int			pvnr_fflag;		/* OUT	*/
    260 };
    261 
    262 struct puffs_vnreq_access {
    263 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    264 	pid_t			pvnr_pid;		/* OUT	*/
    265 	int			pvnr_mode;		/* OUT	*/
    266 };
    267 
    268 #define puffs_vnreq_setattr puffs_vnreq_setgetattr
    269 #define puffs_vnreq_getattr puffs_vnreq_setgetattr
    270 struct puffs_vnreq_setgetattr {
    271 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    272 	struct vattr		pvnr_va;		/* IN/OUT (op depend) */
    273 	pid_t			pvnr_pid;		/* OUT	*/
    274 };
    275 
    276 #define puffs_vnreq_read puffs_vnreq_readwrite
    277 #define puffs_vnreq_write puffs_vnreq_readwrite
    278 struct puffs_vnreq_readwrite {
    279 	struct puffs_cred	pvnr_cred;		/* OUT	  */
    280 	off_t			pvnr_offset;		/* OUT	  */
    281 	size_t			pvnr_resid;		/* IN/OUT */
    282 	int			pvnr_ioflag;		/* OUT	  */
    283 
    284 	uint8_t			pvnr_data[0];		/* IN/OUT (wr/rd) */
    285 };
    286 
    287 #define puffs_vnreq_ioctl puffs_vnreq_fcnioctl
    288 #define puffs_vnreq_fcntl puffs_vnreq_fcnioctl
    289 struct puffs_vnreq_fcnioctl {
    290 	struct puffs_cred	pvnr_cred;
    291 	u_long			pvnr_command;
    292 	pid_t			pvnr_pid;
    293 	int			pvnr_fflag;
    294 
    295 	void			*pvnr_data;
    296 	size_t			pvnr_datalen;
    297 	int			pvnr_copyback;
    298 };
    299 
    300 struct puffs_vnreq_poll {
    301 	int			pvnr_events;		/* OUT	*/
    302 	pid_t			pvnr_pid;		/* OUT	*/
    303 };
    304 
    305 struct puffs_vnreq_revoke {
    306 	int			pvnr_flags;		/* OUT	*/
    307 };
    308 
    309 struct puffs_vnreq_fsync {
    310 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    311 	off_t			pvnr_offlo;		/* OUT	*/
    312 	off_t			pvnr_offhi;		/* OUT	*/
    313 	pid_t			pvnr_pid;		/* OUT	*/
    314 	int			pvnr_flags;		/* OUT	*/
    315 };
    316 
    317 struct puffs_vnreq_seek {
    318 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    319 	off_t			pvnr_oldoff;		/* OUT	*/
    320 	off_t			pvnr_newoff;		/* OUT	*/
    321 };
    322 
    323 struct puffs_vnreq_remove {
    324 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    325 	void			*pvnr_cookie_targ;	/* OUT	*/
    326 };
    327 
    328 struct puffs_vnreq_mkdir {
    329 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    330 	struct vattr		pvnr_va;		/* OUT	*/
    331 	void			*pvnr_newnode;		/* IN	*/
    332 };
    333 
    334 struct puffs_vnreq_rmdir {
    335 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    336 	void			*pvnr_cookie_targ;	/* OUT	*/
    337 };
    338 
    339 struct puffs_vnreq_link {
    340 	struct puffs_cn		pvnr_cn;		/* OUT */
    341 	void			*pvnr_cookie_targ;	/* OUT */
    342 };
    343 
    344 struct puffs_vnreq_rename {
    345 	struct puffs_cn		pvnr_cn_src;		/* OUT	*/
    346 	struct puffs_cn		pvnr_cn_targ;		/* OUT	*/
    347 	void			*pvnr_cookie_src;	/* OUT	*/
    348 	void			*pvnr_cookie_targ;	/* OUT	*/
    349 	void			*pvnr_cookie_targdir;	/* OUT	*/
    350 };
    351 
    352 struct puffs_vnreq_symlink {
    353 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    354 	struct vattr		pvnr_va;		/* OUT	*/
    355 	void			*pvnr_newnode;		/* IN	*/
    356 	char			pvnr_link[MAXPATHLEN];	/* OUT	*/
    357 };
    358 
    359 struct puffs_vnreq_readdir {
    360 	struct puffs_cred	pvnr_cred;		/* OUT	  */
    361 	off_t			pvnr_offset;		/* IN/OUT */
    362 	size_t			pvnr_resid;		/* IN/OUT */
    363 
    364 	struct dirent		pvnr_dent[0];		/* IN  	   */
    365 };
    366 
    367 struct puffs_vnreq_readlink {
    368 	struct puffs_cred	pvnr_cred;		/* OUT */
    369 	size_t			pvnr_linklen;		/* IN  */
    370 	char			pvnr_link[MAXPATHLEN];	/* IN, XXX  */
    371 };
    372 
    373 struct puffs_vnreq_reclaim {
    374 	pid_t			pvnr_pid;		/* OUT	*/
    375 };
    376 
    377 struct puffs_vnreq_inactive {
    378 	pid_t			pvnr_pid;		/* OUT	*/
    379 	int			pvnr_backendrefs;	/* IN	*/
    380 };
    381 
    382 /* XXX: get rid of alltogether */
    383 struct puffs_vnreq_print {
    384 	/* empty */
    385 };
    386 
    387 struct puffs_vnreq_pathconf {
    388 	int			pvnr_name;		/* OUT	*/
    389 	int			pvnr_retval;		/* IN	*/
    390 };
    391 
    392 struct puffs_vnreq_advlock {
    393 	struct flock		pvnr_fl;		/* OUT	*/
    394 	void			*pvnr_id;		/* OUT	*/
    395 	int			pvnr_op;		/* OUT	*/
    396 	int			pvnr_flags;		/* OUT	*/
    397 };
    398 
    399 /* notyet */
    400 #if 0
    401 struct puffs_vnreq_kqfilter { };
    402 struct puffs_vnreq_islocked { };
    403 struct puffs_vnreq_lease { };
    404 #endif
    405 struct puffs_vnreq_getpages { };
    406 struct puffs_vnreq_putpages { };
    407 struct puffs_vnreq_mmap { };
    408 struct puffs_vnreq_getextattr { };
    409 struct puffs_vnreq_setextattr { };
    410 struct puffs_vnreq_listextattr { };
    411 
    412 #ifdef _KERNEL
    413 #define PUFFS_VFSREQ(a)							\
    414 	struct puffs_vfsreq_##a a##_arg;				\
    415 	memset(&a##_arg, 0, sizeof(struct puffs_vfsreq_##a))
    416 
    417 #define PUFFS_VNREQ(a)							\
    418 	struct puffs_vnreq_##a a##_arg;					\
    419 	memset(&a##_arg, 0, sizeof(struct puffs_vnreq_##a))
    420 #endif
    421 
    422 #endif /* _PUFFS_MSGIF_H_ */
    423