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