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/coda/coda_fbsd.cr,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
30 * $Id: coda_fbsd.c,v 1.4 1998/09/13 13:57:59 rvb Exp $
34 #ifdef ACTUALLY_LKM_NOT_KERNEL
38 #include "opt_devfs.h"
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
45 #include <sys/malloc.h>
46 #include <sys/fcntl.h>
47 #include <sys/ucred.h>
48 #include <sys/vnode.h>
52 #include <vm/vnode_pager.h>
54 #include <coda/coda.h>
55 #include <coda/cnode.h>
56 #include <coda/coda_vnops.h>
57 #include <coda/coda_psdev.h>
60 #include <sys/devfsext.h>
62 static void *devfs_token[NVCODA];
66 From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
67 Subject: Re: New 3.0 SNAPshot CDROM about ready for production..
68 To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
69 Date: Fri, 20 Feb 1998 15:57:01 -0800
71 > Also I need a character device major number. (and might want to reserve
72 > a block of 10 syscalls.)
74 Just one char device number? No block devices? Very well, cdev 93 is yours!
79 static struct cdevsw codadevsw =
81 vc_nb_open, vc_nb_close, vc_nb_read, vc_nb_write, /*93*/
82 vc_nb_ioctl, nostop, nullreset, nodevtotty,
83 vc_nb_poll, nommap, NULL, "Coda", NULL, -1
86 void vcattach __P((void));
90 #define VCDEBUG if (vcdebug) printf
96 * In case we are an LKM, set up device switch.
98 if (0 == (codadev = makedev(VC_DEV_NO, 0)))
99 VCDEBUG("makedev returned null\n");
101 VCDEBUG("makedev OK.\n");
103 cdevsw_add(&codadev, &codadevsw, NULL);
104 VCDEBUG("coda: codadevsw entry installed at %d.\n", major(codadev));
107 static vc_devsw_installed = 0;
108 static void vc_drvinit __P((void *unused));
111 vc_drvinit(void *unused)
118 if( ! vc_devsw_installed ) {
119 dev = makedev(VC_DEV_NO, 0);
120 cdevsw_add(&dev,&codadevsw, NULL);
121 vc_devsw_installed = 1;
124 for (i = 0; i < NVCODA; i++) {
126 devfs_add_devswf(&codadevsw, i
130 devfs_add_devswf(&codadevsw, i
139 coda_fbsd_getpages(v)
142 struct vop_getpages_args *ap = v;
143 struct vnode *vp = ap->a_vp;
144 struct cnode *cp = VTOC(vp);
149 ret = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
154 struct vnode *vp = ap->a_vp;
155 struct cnode *cp = VTOC(vp);
156 struct vnode *cfvp = cp->c_ovp;
157 int opened_internally = 0;
158 struct ucred *cred = (struct ucred *) 0;
159 struct proc *p = curproc;
166 /* Redirect the request to UFS. */
169 opened_internally = 1;
171 error = VOP_OPEN(vp, FREAD, cred, p);
172 printf("coda_getp: Internally Opening %p\n", vp);
175 printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
178 if (vp->v_type == VREG) {
179 error = vfs_object_create(vp, p, cred, 1);
181 printf("coda_getpage: vfs_object_create() returns %d\n", error);
189 printf("coda_getp: has container %p\n", cfvp);
192 printf("coda_fbsd_getpages: using container ");
194 error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
197 error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
198 ap->a_reqpage, ap->a_offset);
199 printf("error = %d\n", error);
201 /* Do an internal close if necessary. */
202 if (opened_internally) {
203 (void)VOP_CLOSE(vp, FREAD, cred, p);
212 coda_fbsd_putpages(v)
215 struct vop_putpages_args *ap = v;
218 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
219 ap->a_sync, ap->a_rtvals);
223 SYSINIT(codadev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,vc_drvinit,NULL)
225 #ifdef ACTUALLY_LKM_NOT_KERNEL
227 #include <sys/mount.h>
230 extern struct vfsops coda_vfsops;
232 static struct vfsconf _fs_vfsconf = { &coda_vfsops, "coda", -1, 0, 0 };
234 extern struct linker_set coda_modvnops ;
236 static struct lkm_vfs coda_mod_vfs = {
237 LM_VFS, LKM_VERSION, "coda", 0, &coda_modvnops, &_fs_vfsconf };
239 static struct lkm_dev coda_mod_dev = {
240 LM_DEV, LKM_VERSION, "codadev", VC_DEV_NO, LM_DT_CHAR, (void *) &codadevsw};
242 int coda_mod(struct lkm_table *, int, int);
244 coda_mod(struct lkm_table *lkmtp, int cmd, int ver)
248 if (ver != LKM_VERSION)
253 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_dev;
254 error = lkmdispatch(lkmtp, cmd);
257 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_vfs ;
258 error = lkmdispatch(lkmtp, cmd);
261 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_vfs ;
262 error = lkmdispatch(lkmtp, cmd);
265 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_dev;
266 error = lkmdispatch(lkmtp, cmd);
269 error = lkmdispatch(lkmtp, cmd);