Home | History | Annotate | Line # | Download | only in coda
coda_venus.c revision 1.23
      1 /*	$NetBSD: coda_venus.c,v 1.23 2006/04/12 00:59:56 christos Exp $	*/
      2 
      3 /*
      4  *
      5  *             Coda: an Experimental Distributed File System
      6  *                              Release 3.1
      7  *
      8  *           Copyright (c) 1987-1998 Carnegie Mellon University
      9  *                          All Rights Reserved
     10  *
     11  * Permission  to  use, copy, modify and distribute this software and its
     12  * documentation is hereby granted,  provided  that  both  the  copyright
     13  * notice  and  this  permission  notice  appear  in  all  copies  of the
     14  * software, derivative works or  modified  versions,  and  any  portions
     15  * thereof, and that both notices appear in supporting documentation, and
     16  * that credit is given to Carnegie Mellon University  in  all  documents
     17  * and publicity pertaining to direct or indirect use of this code or its
     18  * derivatives.
     19  *
     20  * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS  KNOWN  TO  HAVE  BUGS,
     21  * SOME  OF  WHICH MAY HAVE SERIOUS CONSEQUENCES.  CARNEGIE MELLON ALLOWS
     22  * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.   CARNEGIE  MELLON
     23  * DISCLAIMS  ANY  LIABILITY  OF  ANY  KIND  FOR  ANY  DAMAGES WHATSOEVER
     24  * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE  OR  OF
     25  * ANY DERIVATIVE WORK.
     26  *
     27  * Carnegie  Mellon  encourages  users  of  this  software  to return any
     28  * improvements or extensions that  they  make,  and  to  grant  Carnegie
     29  * Mellon the rights to redistribute these changes without encumbrance.
     30  *
     31  * 	@(#) coda/coda_venus.c,v 1.1.1.1 1998/08/29 21:26:45 rvb Exp $
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: coda_venus.c,v 1.23 2006/04/12 00:59:56 christos Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/malloc.h>
     40 #include <sys/proc.h>
     41 #include <sys/select.h>
     42 #include <sys/ioctl.h>
     43 /* for CNV_OFLAGS below */
     44 #include <sys/fcntl.h>
     45 
     46 #include <coda/coda.h>
     47 #include <coda/cnode.h>
     48 #include <coda/coda_venus.h>
     49 #include <coda/coda_pioctl.h>
     50 
     51 #ifdef _KERNEL_OPT
     52 #include "opt_coda_compat.h"
     53 #endif
     54 
     55 /*
     56  * Isize and Osize are the sizes of the input and output arguments.
     57  * SEMI-INVARIANT: name##_size (e.g. coda_readlink_size) is the max of
     58  * the input and output.  This invariant is not well maintained, but
     59  * should be true after ALLOC_*.  Isize is modified after allocation
     60  * by STRCPY below - this is in general unsafe and needs fixing.
     61  */
     62 
     63 #define DECL_NO_IN(name) 				\
     64     struct coda_in_hdr *inp;				\
     65     struct name ## _out *outp;				\
     66     int name ## _size = sizeof (struct coda_in_hdr);	\
     67     int Isize = sizeof (struct coda_in_hdr);		\
     68     int Osize = sizeof (struct name ## _out);		\
     69     int error
     70 
     71 #define DECL(name)					\
     72     struct name ## _in *inp;				\
     73     struct name ## _out *outp;				\
     74     int name ## _size = sizeof (struct name ## _in);	\
     75     int Isize = sizeof (struct name ## _in);		\
     76     int Osize = sizeof (struct name ## _out);		\
     77     int error
     78 
     79 #define DECL_NO_OUT(name)				\
     80     struct name ## _in *inp;				\
     81     struct coda_out_hdr *outp;				\
     82     int name ## _size = sizeof (struct name ## _in);	\
     83     int Isize = sizeof (struct name ## _in);		\
     84     int Osize = sizeof (struct coda_out_hdr);		\
     85     int error
     86 
     87 #define ALLOC_NO_IN(name)				\
     88     if (Osize > name ## _size)				\
     89     	name ## _size = Osize;				\
     90     CODA_ALLOC(inp, struct coda_in_hdr *, name ## _size);\
     91     outp = (struct name ## _out *) inp
     92 
     93 #define ALLOC(name)					\
     94     if (Osize > name ## _size)				\
     95     	name ## _size = Osize;				\
     96     CODA_ALLOC(inp, struct name ## _in *, name ## _size);\
     97     outp = (struct name ## _out *) inp
     98 
     99 #define ALLOC_NO_OUT(name)				\
    100     if (Osize > name ## _size)				\
    101     	name ## _size = Osize;				\
    102     CODA_ALLOC(inp, struct name ## _in *, name ## _size);\
    103     outp = (struct coda_out_hdr *) inp
    104 
    105 #define STRCPY(struc, name, len) \
    106     bcopy(name, (char *)inp + (int)inp->struc, len); \
    107     ((char*)inp + (int)inp->struc)[len++] = 0; \
    108     Isize += len
    109 /* XXX verify that Isize has not overrun available storage */
    110 
    111 #ifdef CODA_COMPAT_5
    112 
    113 #define INIT_IN(in, op, ident, p) \
    114 	  (in)->opcode = (op); \
    115 	  (in)->pid = p ? p->p_pid : -1; \
    116           (in)->pgid = p ? p->p_pgid : -1; \
    117           (in)->sid = (p && p->p_session && p->p_session->s_leader) ? \
    118 		(p->p_session->s_leader->p_pid) : -1; \
    119 	  KASSERT(cred != NULL); \
    120 	  KASSERT(cred != FSCRED); \
    121           if (ident != NOCRED) {                              \
    122 	      (in)->cred.cr_uid = ident->cr_uid;              \
    123 	      (in)->cred.cr_groupid = ident->cr_gid;          \
    124           } else {                                            \
    125 	      memset(&((in)->cred), 0, sizeof(struct coda_cred)); \
    126 	      (in)->cred.cr_uid = -1;                         \
    127 	      (in)->cred.cr_groupid = -1;                     \
    128           }                                                   \
    129 
    130 #else
    131 
    132 #define INIT_IN(in, op, ident, p) 		\
    133 	  (in)->opcode = (op); 			\
    134 	  (in)->pid = p ? p->p_pid : -1;        \
    135           (in)->pgid = p ? p->p_pgid : -1;	\
    136 	  KASSERT(cred != NULL); \
    137 	  KASSERT(cred != FSCRED); \
    138           if (ident != NOCRED) {                \
    139 	      (in)->uid = ident->cr_uid;        \
    140           } else {                              \
    141 	      (in)->uid = -1;                   \
    142           }                                                   \
    143 
    144 #endif
    145 
    146 #define INIT_IN_L(in, op, ident, l)		\
    147 	INIT_IN(in, op, ident, (l ? l->l_proc : NULL))
    148 
    149 #define	CNV_OFLAG(to, from) 				\
    150     do { 						\
    151 	  to = 0;					\
    152 	  if (from & FREAD)   to |= C_O_READ; 		\
    153 	  if (from & FWRITE)  to |= C_O_WRITE; 		\
    154 	  if (from & O_TRUNC) to |= C_O_TRUNC; 		\
    155 	  if (from & O_EXCL)  to |= C_O_EXCL; 		\
    156 	  if (from & O_CREAT) to |= C_O_CREAT;		\
    157     } while (/*CONSTCOND*/ 0)
    158 
    159 #define CNV_VV2V_ATTR(top, fromp) \
    160 	do { \
    161 		(top)->va_type = (fromp)->va_type; \
    162 		(top)->va_mode = (fromp)->va_mode; \
    163 		(top)->va_nlink = (fromp)->va_nlink; \
    164 		(top)->va_uid = (fromp)->va_uid; \
    165 		(top)->va_gid = (fromp)->va_gid; \
    166 		(top)->va_fsid = VNOVAL; \
    167 		(top)->va_fileid = (fromp)->va_fileid; \
    168 		(top)->va_size = (fromp)->va_size; \
    169 		(top)->va_blocksize = (fromp)->va_blocksize; \
    170 		(top)->va_atime = (fromp)->va_atime; \
    171 		(top)->va_mtime = (fromp)->va_mtime; \
    172 		(top)->va_ctime = (fromp)->va_ctime; \
    173 		(top)->va_gen = (fromp)->va_gen; \
    174 		(top)->va_flags = (fromp)->va_flags; \
    175 		(top)->va_rdev = (fromp)->va_rdev; \
    176 		(top)->va_bytes = (fromp)->va_bytes; \
    177 		(top)->va_filerev = (fromp)->va_filerev; \
    178 		(top)->va_vaflags = VNOVAL; \
    179 		(top)->va_spare = VNOVAL; \
    180 	} while (/*CONSTCOND*/ 0)
    181 
    182 #define CNV_V2VV_ATTR(top, fromp) \
    183 	do { \
    184 		(top)->va_type = (fromp)->va_type; \
    185 		(top)->va_mode = (fromp)->va_mode; \
    186 		(top)->va_nlink = (fromp)->va_nlink; \
    187 		(top)->va_uid = (fromp)->va_uid; \
    188 		(top)->va_gid = (fromp)->va_gid; \
    189 		(top)->va_fileid = (fromp)->va_fileid; \
    190 		(top)->va_size = (fromp)->va_size; \
    191 		(top)->va_blocksize = (fromp)->va_blocksize; \
    192 		(top)->va_atime = (fromp)->va_atime; \
    193 		(top)->va_mtime = (fromp)->va_mtime; \
    194 		(top)->va_ctime = (fromp)->va_ctime; \
    195 		(top)->va_gen = (fromp)->va_gen; \
    196 		(top)->va_flags = (fromp)->va_flags; \
    197 		(top)->va_rdev = (fromp)->va_rdev; \
    198 		(top)->va_bytes = (fromp)->va_bytes; \
    199 		(top)->va_filerev = (fromp)->va_filerev; \
    200 	} while (/*CONSTCOND*/ 0)
    201 
    202 
    203 int coda_kernel_version = CODA_KERNEL_VERSION;
    204 
    205 int
    206 venus_root(void *mdp,
    207 	struct ucred *cred, struct proc *p,
    208 /*out*/	CodaFid *VFid)
    209 {
    210     DECL_NO_IN(coda_root);		/* sets Isize & Osize */
    211     ALLOC_NO_IN(coda_root);		/* sets inp & outp */
    212 
    213     /* send the open to venus. */
    214     INIT_IN(inp, CODA_ROOT, cred, p);
    215 
    216     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    217     if (!error)
    218 	*VFid = outp->Fid;
    219 
    220     CODA_FREE(inp, coda_root_size);
    221     return error;
    222 }
    223 
    224 int
    225 venus_open(void *mdp, CodaFid *fid, int flag,
    226 	struct ucred *cred, struct lwp *l,
    227 /*out*/	dev_t *dev, ino_t *inode)
    228 {
    229     int cflag;
    230     DECL(coda_open);			/* sets Isize & Osize */
    231     ALLOC(coda_open);			/* sets inp & outp */
    232 
    233     /* send the open to venus. */
    234     INIT_IN_L(&inp->ih, CODA_OPEN, cred, l);
    235     inp->Fid = *fid;
    236     CNV_OFLAG(cflag, flag);
    237     inp->flags = cflag;
    238 
    239     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    240     KASSERT(outp != NULL);
    241     if (!error) {
    242 	*dev =  outp->dev;
    243 	*inode = outp->inode;
    244     }
    245 
    246     CODA_FREE(inp, coda_open_size);
    247     return error;
    248 }
    249 
    250 int
    251 venus_close(void *mdp, CodaFid *fid, int flag,
    252 	struct ucred *cred, struct lwp *l)
    253 {
    254     int cflag;
    255     DECL_NO_OUT(coda_close);		/* sets Isize & Osize */
    256     ALLOC_NO_OUT(coda_close);		/* sets inp & outp */
    257 
    258     INIT_IN_L(&inp->ih, CODA_CLOSE, cred, l);
    259     inp->Fid = *fid;
    260     CNV_OFLAG(cflag, flag);
    261     inp->flags = cflag;
    262 
    263     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    264 
    265     CODA_FREE(inp, coda_close_size);
    266     return error;
    267 }
    268 
    269 /*
    270  * these two calls will not exist!!!  the container file is read/written
    271  * directly.
    272  */
    273 void
    274 venus_read(void)
    275 {
    276 }
    277 
    278 void
    279 venus_write(void)
    280 {
    281 }
    282 
    283 /*
    284  * this is a bit sad too.  the ioctl's are for the control file, not for
    285  * normal files.
    286  */
    287 int
    288 venus_ioctl(void *mdp, CodaFid *fid,
    289 	int com, int flag, caddr_t data,
    290 	struct ucred *cred, struct lwp *l)
    291 {
    292     DECL(coda_ioctl);			/* sets Isize & Osize */
    293     struct PioctlData *iap = (struct PioctlData *)data;
    294     int tmp;
    295 
    296     coda_ioctl_size = VC_MAXMSGSIZE;
    297     ALLOC(coda_ioctl);			/* sets inp & outp */
    298 
    299     INIT_IN_L(&inp->ih, CODA_IOCTL, cred, l);
    300     inp->Fid = *fid;
    301 
    302     /* command was mutated by increasing its size field to reflect the
    303      * path and follow args. we need to subtract that out before sending
    304      * the command to venus.
    305      */
    306     inp->cmd = (com & ~(IOCPARM_MASK << 16));
    307     tmp = ((com >> 16) & IOCPARM_MASK) - sizeof (char *) - sizeof (int);
    308     inp->cmd |= (tmp & IOCPARM_MASK) <<	16;
    309 
    310     if (iap->vi.in_size < 0 || iap->vi.in_size > VC_MAXMSGSIZE) {
    311 	CODA_FREE(inp, coda_ioctl_size);
    312 	return (EINVAL);
    313     }
    314 
    315     inp->rwflag = flag;
    316     inp->len = iap->vi.in_size;
    317     inp->data = (char *)(sizeof (struct coda_ioctl_in));
    318 
    319     error = copyin(iap->vi.in, (char*)inp + (int)(long)inp->data,
    320 		   iap->vi.in_size);
    321     if (error) {
    322 	CODA_FREE(inp, coda_ioctl_size);
    323 	return(error);
    324     }
    325 
    326     Osize = VC_MAXMSGSIZE;
    327     error = coda_call(mdp, Isize + iap->vi.in_size, &Osize, (char *)inp);
    328 
    329 	/* copy out the out buffer. */
    330     if (!error) {
    331 	if (outp->len > iap->vi.out_size) {
    332 	    error = EINVAL;
    333 	} else {
    334 	    error = copyout((char *)outp + (int)(long)outp->data,
    335 			    iap->vi.out, iap->vi.out_size);
    336 	}
    337     }
    338 
    339     CODA_FREE(inp, coda_ioctl_size);
    340     return error;
    341 }
    342 
    343 int
    344 venus_getattr(void *mdp, CodaFid *fid,
    345 	struct ucred *cred, struct lwp *l,
    346 /*out*/	struct vattr *vap)
    347 {
    348     DECL(coda_getattr);			/* sets Isize & Osize */
    349     ALLOC(coda_getattr);			/* sets inp & outp */
    350 
    351     /* send the open to venus. */
    352     INIT_IN_L(&inp->ih, CODA_GETATTR, cred, l);
    353     inp->Fid = *fid;
    354 
    355     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    356     if (!error) {
    357 	CNV_VV2V_ATTR(vap, &outp->attr);
    358     }
    359 
    360     CODA_FREE(inp, coda_getattr_size);
    361     return error;
    362 }
    363 
    364 int
    365 venus_setattr(void *mdp, CodaFid *fid, struct vattr *vap,
    366 	struct ucred *cred, struct lwp *l)
    367 {
    368     DECL_NO_OUT(coda_setattr);		/* sets Isize & Osize */
    369     ALLOC_NO_OUT(coda_setattr);		/* sets inp & outp */
    370 
    371     /* send the open to venus. */
    372     INIT_IN_L(&inp->ih, CODA_SETATTR, cred, l);
    373     inp->Fid = *fid;
    374     CNV_V2VV_ATTR(&inp->attr, vap);
    375 
    376     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    377 
    378     CODA_FREE(inp, coda_setattr_size);
    379     return error;
    380 }
    381 
    382 int
    383 venus_access(void *mdp, CodaFid *fid, int mode,
    384 	struct ucred *cred, struct lwp *l)
    385 {
    386     DECL_NO_OUT(coda_access);		/* sets Isize & Osize */
    387     ALLOC_NO_OUT(coda_access);		/* sets inp & outp */
    388 
    389     /* send the open to venus. */
    390     INIT_IN_L(&inp->ih, CODA_ACCESS, cred, l);
    391     inp->Fid = *fid;
    392     inp->flags = mode;
    393 
    394     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    395 
    396     CODA_FREE(inp, coda_access_size);
    397     return error;
    398 }
    399 
    400 int
    401 venus_readlink(void *mdp, CodaFid *fid,
    402 	struct ucred *cred, struct lwp *l,
    403 /*out*/	char **str, int *len)
    404 {
    405     DECL(coda_readlink);			/* sets Isize & Osize */
    406     /* XXX coda_readlink_size should not be set here */
    407     coda_readlink_size += CODA_MAXPATHLEN;
    408     Osize += CODA_MAXPATHLEN;
    409     ALLOC(coda_readlink);		/* sets inp & outp */
    410 
    411     /* send the open to venus. */
    412     INIT_IN_L(&inp->ih, CODA_READLINK, cred, l);
    413     inp->Fid = *fid;
    414 
    415     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    416     KASSERT(outp != NULL);
    417     if (error != 0)
    418 	    goto out;
    419 
    420     /* Check count for reasonableness */
    421     if (outp->count <= 0 || outp->count > CODA_MAXPATHLEN) {
    422 	    printf("venus_readlink: bad count %d\n", outp->count);
    423 	    error = EINVAL;
    424 	    goto out;
    425     }
    426 
    427     /*
    428      * Check data pointer for reasonableness.  It must point after
    429      * itself, and within the allocated region.
    430      */
    431     if ((intptr_t) outp->data < sizeof(struct coda_readlink_out) ) {
    432 	    printf("venus_readlink: data pointer %lld too low\n",
    433 		   (long long)((intptr_t) outp->data));
    434 	    error = EINVAL;
    435 	    goto out;
    436     }
    437 
    438     if ((intptr_t) outp->data + outp->count >
    439 	sizeof(struct coda_readlink_out) + CODA_MAXPATHLEN) {
    440 	    printf("venus_readlink: data pointer %lld too high\n",
    441 		   (long long)((intptr_t) outp->data));
    442 	    error = EINVAL;
    443 	    goto out;
    444     }
    445 
    446     if (!error) {
    447 	    CODA_ALLOC(*str, char *, outp->count);
    448 	    *len = outp->count;
    449 	    bcopy((char *)outp + (int)(long)outp->data, *str, *len);
    450     }
    451 
    452 out:
    453     CODA_FREE(inp, coda_readlink_size);
    454     return error;
    455 }
    456 
    457 int
    458 venus_fsync(void *mdp, CodaFid *fid,
    459 	struct ucred *cred, struct lwp *l)
    460 {
    461     DECL_NO_OUT(coda_fsync);		/* sets Isize & Osize */
    462     ALLOC_NO_OUT(coda_fsync);		/* sets inp & outp */
    463 
    464     /* send the open to venus. */
    465     INIT_IN_L(&inp->ih, CODA_FSYNC, cred, l);
    466     inp->Fid = *fid;
    467 
    468     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    469 
    470     CODA_FREE(inp, coda_fsync_size);
    471     return error;
    472 }
    473 
    474 int
    475 venus_lookup(void *mdp, CodaFid *fid,
    476     	const char *nm, int len,
    477 	struct ucred *cred, struct lwp *l,
    478 /*out*/	CodaFid *VFid, int *vtype)
    479 {
    480     DECL(coda_lookup);			/* sets Isize & Osize */
    481     coda_lookup_size += len + 1;
    482     ALLOC(coda_lookup);			/* sets inp & outp */
    483 
    484     /* send the open to venus. */
    485     INIT_IN_L(&inp->ih, CODA_LOOKUP, cred, l);
    486     inp->Fid = *fid;
    487 
    488     /* NOTE:
    489      * Between version 1 and version 2 we have added an extra flag field
    490      * to this structure.  But because the string was at the end and because
    491      * of the weird way we represent strings by having the slot point to
    492      * where the string characters are in the "heap", we can just slip the
    493      * flag parameter in after the string slot pointer and veni that don't
    494      * know better won't see this new flag field ...
    495      * Otherwise we'd need two different venus_lookup functions.
    496      */
    497     inp->name = Isize;
    498     inp->flags = CLU_CASE_SENSITIVE;	/* doesn't really matter for BSD */
    499     /* This is safe because we preallocated len+1 extra. */
    500     STRCPY(name, nm, len);		/* increments Isize */
    501 
    502     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    503     KASSERT(outp != NULL);
    504     if (!error) {
    505 	*VFid = outp->Fid;
    506 	*vtype = outp->vtype;
    507     }
    508 
    509     CODA_FREE(inp, coda_lookup_size);
    510     return error;
    511 }
    512 
    513 int
    514 venus_create(void *mdp, CodaFid *fid,
    515     	const char *nm, int len, int exclusive, int mode, struct vattr *va,
    516 	struct ucred *cred, struct lwp *l,
    517 /*out*/	CodaFid *VFid, struct vattr *attr)
    518 {
    519     DECL(coda_create);			/* sets Isize & Osize */
    520     coda_create_size += len + 1;
    521     ALLOC(coda_create);			/* sets inp & outp */
    522 
    523     /* send the open to venus. */
    524     INIT_IN_L(&inp->ih, CODA_CREATE, cred, l);
    525     inp->Fid = *fid;
    526     inp->excl = exclusive ? C_O_EXCL : 0;
    527     inp->mode = mode<<6;
    528     CNV_V2VV_ATTR(&inp->attr, va);
    529 
    530     inp->name = Isize;
    531     STRCPY(name, nm, len);		/* increments Isize */
    532 
    533     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    534     KASSERT(outp != NULL);
    535     if (!error) {
    536 	*VFid = outp->Fid;
    537 	CNV_VV2V_ATTR(attr, &outp->attr);
    538     }
    539 
    540     CODA_FREE(inp, coda_create_size);
    541     return error;
    542 }
    543 
    544 int
    545 venus_remove(void *mdp, CodaFid *fid,
    546         const char *nm, int len,
    547 	struct ucred *cred, struct lwp *l)
    548 {
    549     DECL_NO_OUT(coda_remove);		/* sets Isize & Osize */
    550     coda_remove_size += len + 1;
    551     ALLOC_NO_OUT(coda_remove);		/* sets inp & outp */
    552 
    553     /* send the open to venus. */
    554     INIT_IN_L(&inp->ih, CODA_REMOVE, cred, l);
    555     inp->Fid = *fid;
    556 
    557     inp->name = Isize;
    558     STRCPY(name, nm, len);		/* increments Isize */
    559 
    560     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    561 
    562     CODA_FREE(inp, coda_remove_size);
    563     return error;
    564 }
    565 
    566 int
    567 venus_link(void *mdp, CodaFid *fid, CodaFid *tfid,
    568         const char *nm, int len,
    569 	struct ucred *cred, struct lwp *l)
    570 {
    571     DECL_NO_OUT(coda_link);		/* sets Isize & Osize */
    572     coda_link_size += len + 1;
    573     ALLOC_NO_OUT(coda_link);		/* sets inp & outp */
    574 
    575     /* send the open to venus. */
    576     INIT_IN_L(&inp->ih, CODA_LINK, cred, l);
    577     inp->sourceFid = *fid;
    578     inp->destFid = *tfid;
    579 
    580     inp->tname = Isize;
    581     STRCPY(tname, nm, len);		/* increments Isize */
    582 
    583     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    584 
    585     CODA_FREE(inp, coda_link_size);
    586     return error;
    587 }
    588 
    589 int
    590 venus_rename(void *mdp, CodaFid *fid, CodaFid *tfid,
    591         const char *nm, int len, const char *tnm, int tlen,
    592 	struct ucred *cred, struct lwp *l)
    593 {
    594     DECL_NO_OUT(coda_rename);		/* sets Isize & Osize */
    595     coda_rename_size += len + 1 + tlen + 1;
    596     ALLOC_NO_OUT(coda_rename);		/* sets inp & outp */
    597 
    598     /* send the open to venus. */
    599     INIT_IN_L(&inp->ih, CODA_RENAME, cred, l);
    600     inp->sourceFid = *fid;
    601     inp->destFid = *tfid;
    602 
    603     inp->srcname = Isize;
    604     STRCPY(srcname, nm, len);		/* increments Isize */
    605 
    606     inp->destname = Isize;
    607     STRCPY(destname, tnm, tlen);	/* increments Isize */
    608 
    609     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    610 
    611     CODA_FREE(inp, coda_rename_size);
    612     return error;
    613 }
    614 
    615 int
    616 venus_mkdir(void *mdp, CodaFid *fid,
    617     	const char *nm, int len, struct vattr *va,
    618 	struct ucred *cred, struct lwp *l,
    619 /*out*/	CodaFid *VFid, struct vattr *ova)
    620 {
    621     DECL(coda_mkdir);			/* sets Isize & Osize */
    622     coda_mkdir_size += len + 1;
    623     ALLOC(coda_mkdir);			/* sets inp & outp */
    624 
    625     /* send the open to venus. */
    626     INIT_IN_L(&inp->ih, CODA_MKDIR, cred, l);
    627     inp->Fid = *fid;
    628     CNV_V2VV_ATTR(&inp->attr, va);
    629 
    630     inp->name = Isize;
    631     STRCPY(name, nm, len);		/* increments Isize */
    632 
    633     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    634     KASSERT(outp != NULL);
    635     if (!error) {
    636 	*VFid = outp->Fid;
    637 	CNV_VV2V_ATTR(ova, &outp->attr);
    638     }
    639 
    640     CODA_FREE(inp, coda_mkdir_size);
    641     return error;
    642 }
    643 
    644 int
    645 venus_rmdir(void *mdp, CodaFid *fid,
    646     	const char *nm, int len,
    647 	struct ucred *cred, struct lwp *l)
    648 {
    649     DECL_NO_OUT(coda_rmdir);		/* sets Isize & Osize */
    650     coda_rmdir_size += len + 1;
    651     ALLOC_NO_OUT(coda_rmdir);		/* sets inp & outp */
    652 
    653     /* send the open to venus. */
    654     INIT_IN_L(&inp->ih, CODA_RMDIR, cred, l);
    655     inp->Fid = *fid;
    656 
    657     inp->name = Isize;
    658     STRCPY(name, nm, len);		/* increments Isize */
    659 
    660     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    661 
    662     CODA_FREE(inp, coda_rmdir_size);
    663     return error;
    664 }
    665 
    666 int
    667 venus_symlink(void *mdp, CodaFid *fid,
    668         const char *lnm, int llen, const char *nm, int len, struct vattr *va,
    669 	struct ucred *cred, struct lwp *l)
    670 {
    671     DECL_NO_OUT(coda_symlink);		/* sets Isize & Osize */
    672     coda_symlink_size += llen + 1 + len + 1;
    673     ALLOC_NO_OUT(coda_symlink);		/* sets inp & outp */
    674 
    675     /* send the open to venus. */
    676     INIT_IN_L(&inp->ih, CODA_SYMLINK, cred, l);
    677     inp->Fid = *fid;
    678     CNV_V2VV_ATTR(&inp->attr, va);
    679 
    680     inp->srcname = Isize;
    681     STRCPY(srcname, lnm, llen);		/* increments Isize */
    682 
    683     inp->tname = Isize;
    684     STRCPY(tname, nm, len);		/* increments Isize */
    685 
    686     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    687 
    688     CODA_FREE(inp, coda_symlink_size);
    689     return error;
    690 }
    691 
    692 int
    693 venus_readdir(void *mdp, CodaFid *fid,
    694     	int count, int offset,
    695 	struct ucred *cred, struct lwp *l,
    696 /*out*/	char *buffer, int *len)
    697 {
    698     DECL(coda_readdir);			/* sets Isize & Osize */
    699     coda_readdir_size = VC_MAXMSGSIZE;
    700     ALLOC(coda_readdir);			/* sets inp & outp */
    701 
    702     /* send the open to venus. */
    703     INIT_IN_L(&inp->ih, CODA_READDIR, cred, l);
    704     inp->Fid = *fid;
    705     inp->count = count;
    706     inp->offset = offset;
    707 
    708     Osize = VC_MAXMSGSIZE;
    709     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    710     KASSERT(outp != NULL);
    711     if (!error) {
    712 	bcopy((char *)outp + (int)(long)outp->data, buffer, outp->size);
    713 	*len = outp->size;
    714     }
    715 
    716     CODA_FREE(inp, coda_readdir_size);
    717     return error;
    718 }
    719 
    720 int
    721 venus_statfs(void *mdp, struct ucred *cred, struct lwp *l,
    722    /*out*/   struct coda_statfs *fsp)
    723 {
    724     DECL(coda_statfs);			/* sets Isize & Osize */
    725     ALLOC(coda_statfs);			/* sets inp & outp */
    726 
    727     /* send the open to venus. */
    728     INIT_IN_L(&inp->ih, CODA_STATFS, cred, l);
    729 
    730     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    731     KASSERT(outp != NULL);
    732     if (!error) {
    733         *fsp = outp->stat;
    734     }
    735 
    736     CODA_FREE(inp, coda_statfs_size);
    737     return error;
    738 }
    739 
    740 int
    741 venus_fhtovp(void *mdp, CodaFid *fid,
    742 	struct ucred *cred, struct proc *p,
    743 /*out*/	CodaFid *VFid, int *vtype)
    744 {
    745     DECL(coda_vget);			/* sets Isize & Osize */
    746     ALLOC(coda_vget);			/* sets inp & outp */
    747 
    748     /* Send the open to Venus. */
    749     INIT_IN(&inp->ih, CODA_VGET, cred, p);
    750     inp->Fid = *fid;
    751 
    752     error = coda_call(mdp, Isize, &Osize, (char *)inp);
    753     KASSERT(outp != NULL);
    754     if (!error) {
    755 	*VFid = outp->Fid;
    756 	*vtype = outp->vtype;
    757     }
    758 
    759     CODA_FREE(inp, coda_vget_size);
    760     return error;
    761 }
    762