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.8 1998/11/03 08:55:05 peter Exp $
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 *cfs_devfs_token[NVCODA];
63 static void *coda_devfs_token[NVCODA];
67 From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
68 Subject: Re: New 3.0 SNAPshot CDROM about ready for production..
69 To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
70 Date: Fri, 20 Feb 1998 15:57:01 -0800
72 > Also I need a character device major number. (and might want to reserve
73 > a block of 10 syscalls.)
75 Just one char device number? No block devices? Very well, cdev 93 is yours!
80 static struct cdevsw codadevsw =
82 vc_nb_open, vc_nb_close, vc_nb_read, vc_nb_write, /*93*/
83 vc_nb_ioctl, nostop, nullreset, nodevtotty,
84 vc_nb_poll, nommap, NULL, "Coda", NULL, -1
88 #define VCDEBUG if (vcdebug) printf
90 #if !defined(VFS_LKM) || defined(VFS_KLD)
93 codadev_modevent(module_t mod, int type, void *data)
99 static struct cdevsw *oldcdevsw;
103 dev = makedev(VC_DEV_NO, 0);
104 cdevsw_add(&dev,&codadevsw, &oldcdevsw);
109 for (i = 0; i < NVCODA; i++) {
111 devfs_add_devswf(&codadevsw, i,
112 DV_CHR, UID_ROOT, GID_WHEEL, 0666,
114 coda_devfs_token[i] =
115 devfs_add_devswf(&codadevsw, i,
116 DV_CHR, UID_ROOT, GID_WHEEL, 0666,
123 for (i = 0; i < NVCODA; i++) {
124 devfs_remove_dev(cfs_devfs_token[i]);
125 devfs_remove_dev(coda_devfs_token[i]);
128 cdevsw_add(&dev, oldcdevsw, NULL);
135 static moduledata_t codadev_mod = {
140 DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+VC_DEV_NO);
145 coda_fbsd_getpages(v)
148 struct vop_getpages_args *ap = v;
153 ret = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
158 struct vnode *vp = ap->a_vp;
159 struct cnode *cp = VTOC(vp);
160 struct vnode *cfvp = cp->c_ovp;
161 int opened_internally = 0;
162 struct ucred *cred = (struct ucred *) 0;
163 struct proc *p = curproc;
170 /* Redirect the request to UFS. */
173 opened_internally = 1;
175 error = VOP_OPEN(vp, FREAD, cred, p);
176 printf("coda_getp: Internally Opening %p\n", vp);
179 printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
182 if (vp->v_type == VREG) {
183 error = vfs_object_create(vp, p, cred, 1);
185 printf("coda_getpage: vfs_object_create() returns %d\n", error);
193 printf("coda_getp: has container %p\n", cfvp);
196 printf("coda_fbsd_getpages: using container ");
198 error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
201 error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
202 ap->a_reqpage, ap->a_offset);
203 printf("error = %d\n", error);
205 /* Do an internal close if necessary. */
206 if (opened_internally) {
207 (void)VOP_CLOSE(vp, FREAD, cred, p);
216 coda_fbsd_putpages(v)
219 struct vop_putpages_args *ap = v;
222 return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
223 ap->a_sync, ap->a_rtvals);
226 #if defined(VFS_LKM) && !defined(VFS_KLD)
228 #include <sys/mount.h>
231 void vcattach __P((void));
232 static dev_t codadev;
237 if (0 == (codadev = makedev(VC_DEV_NO, 0)))
238 VCDEBUG("makedev returned null\n");
240 VCDEBUG("makedev OK.\n");
242 cdevsw_add(&codadev, &codadevsw, NULL);
243 VCDEBUG("coda: codadevsw entry installed at %d.\n", major(codadev));
246 extern struct vfsops coda_vfsops;
248 static struct vfsconf _fs_vfsconf = { &coda_vfsops, "coda", -1, 0, 0 };
250 extern struct linker_set coda_modvnops ;
252 static struct lkm_vfs coda_mod_vfs = {
253 LM_VFS, LKM_VERSION, "coda", 0, &coda_modvnops, &_fs_vfsconf };
255 static struct lkm_dev coda_mod_dev = {
256 LM_DEV, LKM_VERSION, "codadev", VC_DEV_NO, LM_DT_CHAR, (void *) &codadevsw};
258 int coda_mod(struct lkm_table *, int, int);
260 coda_mod(struct lkm_table *lkmtp, int cmd, int ver)
264 if (ver != LKM_VERSION)
269 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_dev;
270 error = lkmdispatch(lkmtp, cmd);
273 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_vfs ;
274 error = lkmdispatch(lkmtp, cmd);
277 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_vfs ;
278 error = lkmdispatch(lkmtp, cmd);
281 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_dev;
282 error = lkmdispatch(lkmtp, cmd);
285 error = lkmdispatch(lkmtp, cmd);