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