3 * Coda: an Experimental Distributed File System
6 * Copyright (c) 1987-1998 Carnegie Mellon University
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation, and
14 * that credit is given to Carnegie Mellon University in all documents
15 * and publicity pertaining to direct or indirect use of this code or its
18 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
19 * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
20 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
21 * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
22 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
23 * ANY DERIVATIVE WORK.
25 * Carnegie Mellon encourages users of this software to return any
26 * improvements or extensions that they make, and to grant Carnegie
27 * Mellon the rights to redistribute these changes without encumbrance.
29 * @(#) src/sys/cfs/coda_venus.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
30 * $FreeBSD: src/sys/coda/coda_venus.c,v 1.9 1999/08/28 00:40:56 peter Exp $
31 * $DragonFly: src/sys/vfs/coda/Attic/coda_venus.c,v 1.5 2004/01/08 18:48:07 asmodai Exp $
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/malloc.h>
39 #include <sys/select.h>
40 #include <sys/ioccom.h>
41 #include <sys/fcntl.h>
45 #include "coda_venus.h"
46 #include "coda_pioctl.h"
48 #define DECL_NO_IN(name) \
49 struct coda_in_hdr *inp; \
50 struct name ## _out *outp; \
51 int name ## _size = sizeof (struct coda_in_hdr); \
52 int Isize = sizeof (struct coda_in_hdr); \
53 int Osize = sizeof (struct name ## _out); \
57 struct name ## _in *inp; \
58 struct name ## _out *outp; \
59 int name ## _size = sizeof (struct name ## _in); \
60 int Isize = sizeof (struct name ## _in); \
61 int Osize = sizeof (struct name ## _out); \
64 #define DECL_NO_OUT(name) \
65 struct name ## _in *inp; \
66 struct coda_out_hdr *outp; \
67 int name ## _size = sizeof (struct name ## _in); \
68 int Isize = sizeof (struct name ## _in); \
69 int Osize = sizeof (struct coda_out_hdr); \
72 #define ALLOC_NO_IN(name) \
73 if (Osize > name ## _size) \
74 name ## _size = Osize; \
75 CODA_ALLOC(inp, struct coda_in_hdr *, name ## _size);\
76 outp = (struct name ## _out *) inp
79 if (Osize > name ## _size) \
80 name ## _size = Osize; \
81 CODA_ALLOC(inp, struct name ## _in *, name ## _size);\
82 outp = (struct name ## _out *) inp
84 #define ALLOC_NO_OUT(name) \
85 if (Osize > name ## _size) \
86 name ## _size = Osize; \
87 CODA_ALLOC(inp, struct name ## _in *, name ## _size);\
88 outp = (struct coda_out_hdr *) inp
90 #define STRCPY(struc, name, len) \
91 bcopy(name, (char *)inp + (int)inp->struc, len); \
92 ((char*)inp + (int)inp->struc)[len++] = 0; \
95 #define INIT_IN(in, op, ident, td) \
96 do { struct proc *p = (td)->td_proc; \
97 (in)->opcode = (op); \
98 (in)->pid = p ? p->p_pid : -1; \
99 (in)->pgid = p ? p->p_pgid : -1; \
100 (in)->sid = (p && p->p_session && p->p_session->s_leader) ? (p->p_session->s_leader->p_pid) : -1; \
101 if (ident != NOCRED) { \
102 (in)->cred.cr_uid = ident->cr_uid; \
103 (in)->cred.cr_groupid = ident->cr_gid; \
105 bzero(&((in)->cred),sizeof(struct coda_cred)); \
106 (in)->cred.cr_uid = -1; \
107 (in)->cred.cr_groupid = -1; \
111 #define CNV_OFLAG(to, from) \
114 if (from & FREAD) to |= C_O_READ; \
115 if (from & FWRITE) to |= C_O_WRITE; \
116 if (from & O_TRUNC) to |= C_O_TRUNC; \
117 if (from & O_EXCL) to |= C_O_EXCL; \
118 if (from & O_CREAT) to |= C_O_CREAT; \
121 #define CNV_VV2V_ATTR(top, fromp) \
123 (top)->va_type = (fromp)->va_type; \
124 (top)->va_mode = (fromp)->va_mode; \
125 (top)->va_nlink = (fromp)->va_nlink; \
126 (top)->va_uid = (fromp)->va_uid; \
127 (top)->va_gid = (fromp)->va_gid; \
128 (top)->va_fsid = VNOVAL; \
129 (top)->va_fileid = (fromp)->va_fileid; \
130 (top)->va_size = (fromp)->va_size; \
131 (top)->va_blocksize = (fromp)->va_blocksize; \
132 (top)->va_atime = (fromp)->va_atime; \
133 (top)->va_mtime = (fromp)->va_mtime; \
134 (top)->va_ctime = (fromp)->va_ctime; \
135 (top)->va_gen = (fromp)->va_gen; \
136 (top)->va_flags = (fromp)->va_flags; \
137 (top)->va_rdev = (fromp)->va_rdev; \
138 (top)->va_bytes = (fromp)->va_bytes; \
139 (top)->va_filerev = (fromp)->va_filerev; \
140 (top)->va_vaflags = VNOVAL; \
141 (top)->va_spare = VNOVAL; \
144 #define CNV_V2VV_ATTR(top, fromp) \
146 (top)->va_type = (fromp)->va_type; \
147 (top)->va_mode = (fromp)->va_mode; \
148 (top)->va_nlink = (fromp)->va_nlink; \
149 (top)->va_uid = (fromp)->va_uid; \
150 (top)->va_gid = (fromp)->va_gid; \
151 (top)->va_fileid = (fromp)->va_fileid; \
152 (top)->va_size = (fromp)->va_size; \
153 (top)->va_blocksize = (fromp)->va_blocksize; \
154 (top)->va_atime = (fromp)->va_atime; \
155 (top)->va_mtime = (fromp)->va_mtime; \
156 (top)->va_ctime = (fromp)->va_ctime; \
157 (top)->va_gen = (fromp)->va_gen; \
158 (top)->va_flags = (fromp)->va_flags; \
159 (top)->va_rdev = (fromp)->va_rdev; \
160 (top)->va_bytes = (fromp)->va_bytes; \
161 (top)->va_filerev = (fromp)->va_filerev; \
165 int coda_kernel_version = CODA_KERNEL_VERSION;
168 venus_root(void *mdp,
169 struct ucred *cred, struct thread *td,
170 /*out*/ ViceFid *VFid)
172 DECL_NO_IN(coda_root); /* sets Isize & Osize */
173 ALLOC_NO_IN(coda_root); /* sets inp & outp */
175 /* send the open to venus. */
176 INIT_IN(inp, CODA_ROOT, cred, td);
178 error = coda_call(mdp, Isize, &Osize, (char *)inp);
182 CODA_FREE(inp, coda_root_size);
187 venus_open(void *mdp, ViceFid *fid, int flag,
188 struct ucred *cred, struct thread *td,
189 /*out*/ dev_t *dev, ino_t *inode)
192 DECL(coda_open); /* sets Isize & Osize */
193 ALLOC(coda_open); /* sets inp & outp */
195 /* send the open to venus. */
196 INIT_IN(&inp->ih, CODA_OPEN, cred, td);
198 CNV_OFLAG(cflag, flag);
201 error = coda_call(mdp, Isize, &Osize, (char *)inp);
203 /* 5/11 *dev = udev2dev(outp->dev, 2); */
204 *dev = udev2dev(outp->dev, 0);
205 *inode = outp->inode;
208 CODA_FREE(inp, coda_open_size);
213 venus_close(void *mdp, ViceFid *fid, int flag,
214 struct ucred *cred, struct thread *td)
217 DECL_NO_OUT(coda_close); /* sets Isize & Osize */
218 ALLOC_NO_OUT(coda_close); /* sets inp & outp */
220 INIT_IN(&inp->ih, CODA_CLOSE, cred, td);
222 CNV_OFLAG(cflag, flag);
225 error = coda_call(mdp, Isize, &Osize, (char *)inp);
227 CODA_FREE(inp, coda_close_size);
232 * these two calls will not exist!!! the container file is read/written
246 * this is a bit sad too. the ioctl's are for the control file, not for
250 venus_ioctl(void *mdp, ViceFid *fid,
251 int com, int flag, caddr_t data,
252 struct ucred *cred, struct thread *td)
254 DECL(coda_ioctl); /* sets Isize & Osize */
255 struct PioctlData *iap = (struct PioctlData *)data;
258 coda_ioctl_size = VC_MAXMSGSIZE;
259 ALLOC(coda_ioctl); /* sets inp & outp */
261 INIT_IN(&inp->ih, CODA_IOCTL, cred, td);
264 /* command was mutated by increasing its size field to reflect the
265 * path and follow args. we need to subtract that out before sending
266 * the command to venus.
268 inp->cmd = (com & ~(IOCPARM_MASK << 16));
269 tmp = ((com >> 16) & IOCPARM_MASK) - sizeof (char *) - sizeof (int);
270 inp->cmd |= (tmp & IOCPARM_MASK) << 16;
273 inp->len = iap->vi.in_size;
274 inp->data = (char *)(sizeof (struct coda_ioctl_in));
276 error = copyin(iap->vi.in, (char*)inp + (int)inp->data,
279 CODA_FREE(inp, coda_ioctl_size);
283 Osize = VC_MAXMSGSIZE;
284 error = coda_call(mdp, Isize + iap->vi.in_size, &Osize, (char *)inp);
286 /* copy out the out buffer. */
288 if (outp->len > iap->vi.out_size) {
291 error = copyout((char *)outp + (int)outp->data,
292 iap->vi.out, iap->vi.out_size);
296 CODA_FREE(inp, coda_ioctl_size);
301 venus_getattr(void *mdp, ViceFid *fid,
302 struct ucred *cred, struct thread *td,
303 /*out*/ struct vattr *vap)
305 DECL(coda_getattr); /* sets Isize & Osize */
306 ALLOC(coda_getattr); /* sets inp & outp */
308 /* send the open to venus. */
309 INIT_IN(&inp->ih, CODA_GETATTR, cred, td);
312 error = coda_call(mdp, Isize, &Osize, (char *)inp);
314 CNV_VV2V_ATTR(vap, &outp->attr);
317 CODA_FREE(inp, coda_getattr_size);
322 venus_setattr(void *mdp, ViceFid *fid, struct vattr *vap,
323 struct ucred *cred, struct thread *td)
325 DECL_NO_OUT(coda_setattr); /* sets Isize & Osize */
326 ALLOC_NO_OUT(coda_setattr); /* sets inp & outp */
328 /* send the open to venus. */
329 INIT_IN(&inp->ih, CODA_SETATTR, cred, td);
331 CNV_V2VV_ATTR(&inp->attr, vap);
333 error = coda_call(mdp, Isize, &Osize, (char *)inp);
335 CODA_FREE(inp, coda_setattr_size);
340 venus_access(void *mdp, ViceFid *fid, int mode,
341 struct ucred *cred, struct thread *td)
343 DECL_NO_OUT(coda_access); /* sets Isize & Osize */
344 ALLOC_NO_OUT(coda_access); /* sets inp & outp */
346 /* send the open to venus. */
347 INIT_IN(&inp->ih, CODA_ACCESS, cred, td);
350 * NetBSD and Venus internals use the "data" in the low 3 bits.
351 * Hence, the conversion.
353 inp->flags = mode>>6;
355 error = coda_call(mdp, Isize, &Osize, (char *)inp);
357 CODA_FREE(inp, coda_access_size);
362 venus_readlink(void *mdp, ViceFid *fid,
363 struct ucred *cred, struct thread *td,
364 /*out*/ char **str, int *len)
366 DECL(coda_readlink); /* sets Isize & Osize */
367 coda_readlink_size += CODA_MAXPATHLEN;
368 ALLOC(coda_readlink); /* sets inp & outp */
370 /* send the open to venus. */
371 INIT_IN(&inp->ih, CODA_READLINK, cred, td);
374 Osize += CODA_MAXPATHLEN;
375 error = coda_call(mdp, Isize, &Osize, (char *)inp);
377 CODA_ALLOC(*str, char *, outp->count);
379 bcopy((char *)outp + (int)outp->data, *str, *len);
382 CODA_FREE(inp, coda_readlink_size);
387 venus_fsync(void *mdp, ViceFid *fid,
388 struct ucred *cred, struct thread *td)
390 DECL_NO_OUT(coda_fsync); /* sets Isize & Osize */
391 ALLOC_NO_OUT(coda_fsync); /* sets inp & outp */
393 /* send the open to venus. */
394 INIT_IN(&inp->ih, CODA_FSYNC, cred, td);
397 error = coda_call(mdp, Isize, &Osize, (char *)inp);
399 CODA_FREE(inp, coda_fsync_size);
404 venus_lookup(void *mdp, ViceFid *fid,
405 const char *nm, int len,
406 struct ucred *cred, struct thread *td,
407 /*out*/ ViceFid *VFid, int *vtype)
409 DECL(coda_lookup); /* sets Isize & Osize */
410 coda_lookup_size += len + 1;
411 ALLOC(coda_lookup); /* sets inp & outp */
413 /* send the open to venus. */
414 INIT_IN(&inp->ih, CODA_LOOKUP, cred, td);
418 * Between version 1 and version 2 we have added an extra flag field
419 * to this structure. But because the string was at the end and because
420 * of the weird way we represent strings by having the slot point to
421 * where the string characters are in the "heap", we can just slip the
422 * flag parameter in after the string slot pointer and veni that don't
423 * know better won't see this new flag field ...
424 * Otherwise we'd need two different venus_lookup functions.
427 inp->flags = CLU_CASE_SENSITIVE; /* doesn't really matter for BSD */
428 STRCPY(name, nm, len); /* increments Isize */
430 error = coda_call(mdp, Isize, &Osize, (char *)inp);
433 *vtype = outp->vtype;
436 CODA_FREE(inp, coda_lookup_size);
441 venus_create(void *mdp, ViceFid *fid,
442 const char *nm, int len, int exclusive, int mode, struct vattr *va,
443 struct ucred *cred, struct thread *td,
444 /*out*/ ViceFid *VFid, struct vattr *attr)
446 DECL(coda_create); /* sets Isize & Osize */
447 coda_create_size += len + 1;
448 ALLOC(coda_create); /* sets inp & outp */
450 /* send the open to venus. */
451 INIT_IN(&inp->ih, CODA_CREATE, cred, td);
453 inp->excl = exclusive ? C_O_EXCL : 0;
455 CNV_V2VV_ATTR(&inp->attr, va);
458 STRCPY(name, nm, len); /* increments Isize */
460 error = coda_call(mdp, Isize, &Osize, (char *)inp);
463 CNV_VV2V_ATTR(attr, &outp->attr);
466 CODA_FREE(inp, coda_create_size);
471 venus_remove(void *mdp, ViceFid *fid,
472 const char *nm, int len,
473 struct ucred *cred, struct thread *td)
475 DECL_NO_OUT(coda_remove); /* sets Isize & Osize */
476 coda_remove_size += len + 1;
477 ALLOC_NO_OUT(coda_remove); /* sets inp & outp */
479 /* send the open to venus. */
480 INIT_IN(&inp->ih, CODA_REMOVE, cred, td);
484 STRCPY(name, nm, len); /* increments Isize */
486 error = coda_call(mdp, Isize, &Osize, (char *)inp);
488 CODA_FREE(inp, coda_remove_size);
493 venus_link(void *mdp, ViceFid *fid, ViceFid *tfid,
494 const char *nm, int len,
495 struct ucred *cred, struct thread *td)
497 DECL_NO_OUT(coda_link); /* sets Isize & Osize */
498 coda_link_size += len + 1;
499 ALLOC_NO_OUT(coda_link); /* sets inp & outp */
501 /* send the open to venus. */
502 INIT_IN(&inp->ih, CODA_LINK, cred, td);
503 inp->sourceFid = *fid;
504 inp->destFid = *tfid;
507 STRCPY(tname, nm, len); /* increments Isize */
509 error = coda_call(mdp, Isize, &Osize, (char *)inp);
511 CODA_FREE(inp, coda_link_size);
516 venus_rename(void *mdp, ViceFid *fid, ViceFid *tfid,
517 const char *nm, int len, const char *tnm, int tlen,
518 struct ucred *cred, struct thread *td)
520 DECL_NO_OUT(coda_rename); /* sets Isize & Osize */
521 coda_rename_size += len + 1 + tlen + 1;
522 ALLOC_NO_OUT(coda_rename); /* sets inp & outp */
524 /* send the open to venus. */
525 INIT_IN(&inp->ih, CODA_RENAME, cred, td);
526 inp->sourceFid = *fid;
527 inp->destFid = *tfid;
529 inp->srcname = Isize;
530 STRCPY(srcname, nm, len); /* increments Isize */
532 inp->destname = Isize;
533 STRCPY(destname, tnm, tlen); /* increments Isize */
535 error = coda_call(mdp, Isize, &Osize, (char *)inp);
537 CODA_FREE(inp, coda_rename_size);
542 venus_mkdir(void *mdp, ViceFid *fid,
543 const char *nm, int len, struct vattr *va,
544 struct ucred *cred, struct thread *td,
545 /*out*/ ViceFid *VFid, struct vattr *ova)
547 DECL(coda_mkdir); /* sets Isize & Osize */
548 coda_mkdir_size += len + 1;
549 ALLOC(coda_mkdir); /* sets inp & outp */
551 /* send the open to venus. */
552 INIT_IN(&inp->ih, CODA_MKDIR, cred, td);
554 CNV_V2VV_ATTR(&inp->attr, va);
557 STRCPY(name, nm, len); /* increments Isize */
559 error = coda_call(mdp, Isize, &Osize, (char *)inp);
562 CNV_VV2V_ATTR(ova, &outp->attr);
565 CODA_FREE(inp, coda_mkdir_size);
570 venus_rmdir(void *mdp, ViceFid *fid,
571 const char *nm, int len,
572 struct ucred *cred, struct thread *td)
574 DECL_NO_OUT(coda_rmdir); /* sets Isize & Osize */
575 coda_rmdir_size += len + 1;
576 ALLOC_NO_OUT(coda_rmdir); /* sets inp & outp */
578 /* send the open to venus. */
579 INIT_IN(&inp->ih, CODA_RMDIR, cred, td);
583 STRCPY(name, nm, len); /* increments Isize */
585 error = coda_call(mdp, Isize, &Osize, (char *)inp);
587 CODA_FREE(inp, coda_rmdir_size);
592 venus_symlink(void *mdp, ViceFid *fid,
593 const char *lnm, int llen, const char *nm, int len, struct vattr *va,
594 struct ucred *cred, struct thread *td)
596 DECL_NO_OUT(coda_symlink); /* sets Isize & Osize */
597 coda_symlink_size += llen + 1 + len + 1;
598 ALLOC_NO_OUT(coda_symlink); /* sets inp & outp */
600 /* send the open to venus. */
601 INIT_IN(&inp->ih, CODA_SYMLINK, cred, td);
603 CNV_V2VV_ATTR(&inp->attr, va);
605 inp->srcname = Isize;
606 STRCPY(srcname, lnm, llen); /* increments Isize */
609 STRCPY(tname, nm, len); /* increments Isize */
611 error = coda_call(mdp, Isize, &Osize, (char *)inp);
613 CODA_FREE(inp, coda_symlink_size);
618 venus_readdir(void *mdp, ViceFid *fid,
619 int count, int offset,
620 struct ucred *cred, struct thread *td,
621 /*out*/ char *buffer, int *len)
623 DECL(coda_readdir); /* sets Isize & Osize */
624 coda_readdir_size = VC_MAXMSGSIZE;
625 ALLOC(coda_readdir); /* sets inp & outp */
627 /* send the open to venus. */
628 INIT_IN(&inp->ih, CODA_READDIR, cred, td);
631 inp->offset = offset;
633 Osize = VC_MAXMSGSIZE;
634 error = coda_call(mdp, Isize, &Osize, (char *)inp);
636 bcopy((char *)outp + (int)outp->data, buffer, outp->size);
640 CODA_FREE(inp, coda_readdir_size);
645 venus_fhtovp(void *mdp, ViceFid *fid,
646 struct ucred *cred, struct thread *td,
647 /*out*/ ViceFid *VFid, int *vtype)
649 DECL(coda_vget); /* sets Isize & Osize */
650 ALLOC(coda_vget); /* sets inp & outp */
652 /* Send the open to Venus. */
653 INIT_IN(&inp->ih, CODA_VGET, cred, td);
656 error = coda_call(mdp, Isize, &Osize, (char *)inp);
659 *vtype = outp->vtype;
662 CODA_FREE(inp, coda_vget_size);