Home | History | Annotate | Line # | Download | only in puffs
puffs_msgif.h revision 1.1
      1 /*	$NetBSD: puffs_msgif.h,v 1.1 2006/10/22 22:43:23 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	1024 /* 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 };
    228 
    229 struct puffs_vnreq_create {
    230 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    231 	struct vattr		pvnr_va;		/* OUT	*/
    232 	void			*pvnr_newnode;		/* IN	*/
    233 };
    234 
    235 struct puffs_vnreq_mknod {
    236 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    237 	struct vattr		pvnr_va;		/* OUT	*/
    238 	void			*pvnr_newnode;		/* IN	*/
    239 };
    240 
    241 struct puffs_vnreq_open {
    242 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    243 	pid_t			pvnr_pid;		/* OUT	*/
    244 	int			pvnr_mode;		/* OUT	*/
    245 };
    246 
    247 struct puffs_vnreq_close {
    248 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    249 	pid_t			pvnr_pid;		/* OUT	*/
    250 	int			pvnr_fflag;		/* OUT	*/
    251 };
    252 
    253 struct puffs_vnreq_access {
    254 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    255 	pid_t			pvnr_pid;		/* OUT	*/
    256 	int			pvnr_mode;		/* OUT	*/
    257 };
    258 
    259 #define puffs_vnreq_setattr puffs_vnreq_setgetattr
    260 #define puffs_vnreq_getattr puffs_vnreq_setgetattr
    261 struct puffs_vnreq_setgetattr {
    262 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    263 	struct vattr		pvnr_va;		/* IN/OUT (op depend) */
    264 	pid_t			pvnr_pid;		/* OUT	*/
    265 };
    266 
    267 #define puffs_vnreq_read puffs_vnreq_readwrite
    268 #define puffs_vnreq_write puffs_vnreq_readwrite
    269 struct puffs_vnreq_readwrite {
    270 	struct puffs_cred	pvnr_cred;		/* OUT	  */
    271 	off_t			pvnr_offset;		/* OUT	  */
    272 	size_t			pvnr_resid;		/* IN/OUT */
    273 	int			pvnr_ioflag;		/* OUT	  */
    274 
    275 	uint8_t			pvnr_data[0];		/* IN/OUT (wr/rd) */
    276 };
    277 
    278 #define puffs_vnreq_ioctl puffs_vnreq_fcnioctl
    279 #define puffs_vnreq_fcntl puffs_vnreq_fcnioctl
    280 struct puffs_vnreq_fcnioctl {
    281 	struct puffs_cred	pvnr_cred;
    282 	u_long			pvnr_command;
    283 	pid_t			pvnr_pid;
    284 	int			pvnr_fflag;
    285 
    286 	void			*pvnr_data;
    287 	size_t			pvnr_datalen;
    288 	int			pvnr_copyback;
    289 };
    290 
    291 struct puffs_vnreq_poll {
    292 	int			pvnr_events;		/* OUT	*/
    293 	pid_t			pvnr_pid;		/* OUT	*/
    294 };
    295 
    296 struct puffs_vnreq_revoke {
    297 	int			pvnr_flags;		/* OUT	*/
    298 };
    299 
    300 struct puffs_vnreq_fsync {
    301 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    302 	off_t			pvnr_offlo;		/* OUT	*/
    303 	off_t			pvnr_offhi;		/* OUT	*/
    304 	pid_t			pvnr_pid;		/* OUT	*/
    305 	int			pvnr_flags;		/* OUT	*/
    306 };
    307 
    308 struct puffs_vnreq_seek {
    309 	struct puffs_cred	pvnr_cred;		/* OUT	*/
    310 	off_t			pvnr_oldoff;		/* OUT	*/
    311 	off_t			pvnr_newoff;		/* OUT	*/
    312 };
    313 
    314 struct puffs_vnreq_remove {
    315 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    316 	void			*pvnr_cookie_targ;	/* OUT	*/
    317 };
    318 
    319 struct puffs_vnreq_mkdir {
    320 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    321 	struct vattr		pvnr_va;		/* OUT	*/
    322 	void			*pvnr_newnode;		/* IN	*/
    323 };
    324 
    325 struct puffs_vnreq_rmdir {
    326 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    327 	void			*pvnr_cookie_targ;	/* OUT	*/
    328 };
    329 
    330 struct puffs_vnreq_link {
    331 	struct puffs_cn		pvnr_cn;		/* OUT */
    332 	void			*pvnr_cookie_targ;	/* OUT */
    333 };
    334 
    335 struct puffs_vnreq_rename {
    336 	struct puffs_cn		pvnr_cn_src;		/* OUT	*/
    337 	struct puffs_cn		pvnr_cn_targ;		/* OUT	*/
    338 	void			*pvnr_cookie_src;	/* OUT	*/
    339 	void			*pvnr_cookie_targ;	/* OUT	*/
    340 	void			*pvnr_cookie_targdir;	/* OUT	*/
    341 };
    342 
    343 struct puffs_vnreq_symlink {
    344 	struct puffs_cn		pvnr_cn;		/* OUT	*/
    345 	struct vattr		pvnr_va;		/* OUT	*/
    346 	void			*pvnr_newnode;		/* IN	*/
    347 	char			pvnr_link[MAXPATHLEN];	/* OUT	*/
    348 };
    349 
    350 struct puffs_vnreq_readdir {
    351 	struct puffs_cred	pvnr_cred;		/* OUT	  */
    352 	off_t			pvnr_offset;		/* IN/OUT */
    353 	size_t			pvnr_resid;		/* IN/OUT */
    354 
    355 	struct dirent		pvnr_dent[0];		/* IN  	   */
    356 };
    357 
    358 struct puffs_vnreq_readlink {
    359 	struct puffs_cred	pvnr_cred;		/* OUT */
    360 	size_t			pvnr_linklen;		/* IN  */
    361 	char			pvnr_link[MAXPATHLEN];	/* IN, XXX  */
    362 };
    363 
    364 struct puffs_vnreq_reclaim {
    365 	pid_t			pvnr_pid;		/* OUT	*/
    366 };
    367 
    368 /* XXX: get rid of alltogether */
    369 struct puffs_vnreq_print {
    370 	/* empty */
    371 };
    372 
    373 struct puffs_vnreq_pathconf {
    374 	int			pvnr_name;		/* OUT	*/
    375 	int			pvnr_retval;		/* IN	*/
    376 };
    377 
    378 struct puffs_vnreq_advlock {
    379 	struct flock		pvnr_fl;		/* OUT	*/
    380 	void			*pvnr_id;		/* OUT	*/
    381 	int			pvnr_op;		/* OUT	*/
    382 	int			pvnr_flags;		/* OUT	*/
    383 };
    384 
    385 /* notyet */
    386 #if 0
    387 struct puffs_vnreq_kqfilter { };
    388 struct puffs_vnreq_islocked { };
    389 struct puffs_vnreq_lease { };
    390 #endif
    391 struct puffs_vnreq_getpages { };
    392 struct puffs_vnreq_putpages { };
    393 struct puffs_vnreq_mmap { };
    394 struct puffs_vnreq_getextattr { };
    395 struct puffs_vnreq_setextattr { };
    396 struct puffs_vnreq_listextattr { };
    397 
    398 #ifdef _KERNEL
    399 #define PUFFS_VFSREQ(a)							\
    400 	struct puffs_vfsreq_##a a##_arg;				\
    401 	memset(&a##_arg, 0, sizeof(struct puffs_vfsreq_##a))
    402 
    403 #define PUFFS_VNREQ(a)							\
    404 	struct puffs_vnreq_##a a##_arg;					\
    405 	memset(&a##_arg, 0, sizeof(struct puffs_vnreq_##a))
    406 #endif
    407 
    408 #endif /* _PUFFS_MSGIF_H_ */
    409