2 * Coda: an Experimental Distributed File System
5 * Copyright (c) 1987-1998 Carnegie Mellon University
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation, and
13 * that credit is given to Carnegie Mellon University in all documents
14 * and publicity pertaining to direct or indirect use of this code or its
17 * CODA IS AN EXPERIMENTAL SOFTWARE SYSTEM AND IS KNOWN TO HAVE BUGS,
18 * SOME OF WHICH MAY HAVE SERIOUS CONSEQUENCES. CARNEGIE MELLON ALLOWS
19 * FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION. CARNEGIE MELLON
20 * DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER
21 * RESULTING DIRECTLY OR INDIRECTLY FROM THE USE OF THIS SOFTWARE OR OF
22 * ANY DERIVATIVE WORK.
24 * Carnegie Mellon encourages users of this software to return any
25 * improvements or extensions that they make, and to grant Carnegie
26 * Mellon the rights to redistribute these changes without encumbrance.
28 * @(#) src/sys/coda/coda_fbsd.cr,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
37 #include <sys/systm.h>
39 #include <sys/fcntl.h>
40 #include <sys/kernel.h>
42 #include <sys/malloc.h>
43 #include <sys/module.h>
44 #include <sys/ucred.h>
45 #include <sys/vnode.h>
48 #include <vm/vnode_pager.h>
50 #include <coda/coda.h>
51 #include <coda/cnode.h>
52 #include <coda/coda_vnops.h>
53 #include <coda/coda_psdev.h>
56 From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
57 Subject: Re: New 3.0 SNAPshot CDROM about ready for production..
58 To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
59 Date: Fri, 20 Feb 1998 15:57:01 -0800
61 > Also I need a character device major number. (and might want to reserve
62 > a block of 10 syscalls.)
64 Just one char device number? No block devices? Very well, cdev 93 is yours!
69 static struct cdevsw codadevsw = {
70 .d_version = D_VERSION,
71 .d_flags = D_NEEDGIANT,
73 .d_close = vc_nb_close,
75 .d_write = vc_nb_write,
76 .d_ioctl = vc_nb_ioctl,
83 #define VCDEBUG if (vcdebug) printf
86 codadev_modevent(module_t mod, int type, void *data)
99 static moduledata_t codadev_mod = {
104 DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+VC_DEV_NO);
107 coda_fbsd_getpages(v)
110 struct vop_getpages_args *ap = v;
113 return vop_stdgetpages(ap);
116 struct vnode *vp = ap->a_vp;
117 struct cnode *cp = VTOC(vp);
118 struct vnode *cfvp = cp->c_ovp;
119 int opened_internally = 0;
120 struct ucred *cred = (struct ucred *) 0;
121 struct proc *p = curproc;
128 /* Redirect the request to UFS. */
131 opened_internally = 1;
133 error = VOP_OPEN(vp, FREAD, cred, p, -1);
134 printf("coda_getp: Internally Opening %p\n", vp);
137 printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
140 if (vp->v_type == VREG) {
141 error = vfs_object_create(vp, p, cred);
143 printf("coda_getpage: vfs_object_create() returns %d\n", error);
151 printf("coda_getp: has container %p\n", cfvp);
154 printf("coda_fbsd_getpages: using container ");
156 error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
159 error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
160 ap->a_reqpage, ap->a_offset);
161 printf("error = %d\n", error);
163 /* Do an internal close if necessary. */
164 if (opened_internally) {
165 (void)VOP_CLOSE(vp, FREAD, cred, p);
174 /* for DEVFS, using bpf & tun drivers as examples*/
175 static void coda_fbsd_drvinit(void *unused);
176 static void coda_fbsd_drvuninit(void *unused);
177 static void coda_fbsd_clone(void *arg, char *name, int namelen, dev_t *dev);
179 static eventhandler_tag clonetag;
181 static void coda_fbsd_clone(arg, name, namelen, dev)
191 if (dev_stdclone(name,NULL,"cfs",&u) != 1)
194 *dev = make_dev(&codadevsw,unit2minor(u),UID_ROOT,GID_WHEEL,0600,"cfs%d",u);
195 coda_mnttbl[unit2minor(u)].dev = *dev;
199 static void coda_fbsd_drvinit(unused)
204 clonetag = EVENTHANDLER_REGISTER(dev_clone,coda_fbsd_clone,0,1000);
205 for(i=0;i<NVCODA;i++)
206 coda_mnttbl[i].dev = NULL;
209 static void coda_fbsd_drvuninit(unused)
214 EVENTHANDLER_DEREGISTER(dev_clone,clonetag);
215 for(i=0;i<NVCODA;i++)
216 if(coda_mnttbl[i].dev)
217 destroy_dev(coda_mnttbl[i].dev);
220 SYSINIT(coda_fbsd_dev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,coda_fbsd_drvinit,NULL);
222 SYSUNINIT(coda_fbsd_dev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,coda_fbsd_drvuninit,NULL);