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