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$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
37 #include <sys/fcntl.h>
38 #include <sys/kernel.h>
40 #include <sys/malloc.h>
41 #include <sys/module.h>
42 #include <sys/ucred.h>
43 #include <sys/vnode.h>
46 #include <vm/vnode_pager.h>
48 #include <fs/coda/coda.h>
49 #include <fs/coda/cnode.h>
50 #include <fs/coda/coda_vnops.h>
51 #include <fs/coda/coda_psdev.h>
53 static struct cdevsw codadevsw = {
54 .d_version = D_VERSION,
55 .d_flags = D_NEEDGIANT,
65 static eventhandler_tag clonetag;
67 static LIST_HEAD(, coda_mntinfo) coda_mnttbl;
70 * For DEVFS, using bpf & tun drivers as examples.
72 * XXX: Why use a cloned interface, aren't we really just interested in
73 * having a single /dev/cfs0? It's not clear the coda module knows what to
74 * do with more than one.
76 static void coda_fbsd_clone(void *arg, struct ucred *cred, char *name,
77 int namelen, struct cdev **dev);
80 codadev_modevent(module_t mod, int type, void *data)
82 struct coda_mntinfo *mnt;
86 LIST_INIT(&coda_mnttbl);
87 clonetag = EVENTHANDLER_REGISTER(dev_clone, coda_fbsd_clone,
93 * XXXRW: At the very least, a busy check should occur here
94 * to prevent untimely unload. Much more serious collection
95 * of allocated memory needs to take place; right now we leak
98 EVENTHANDLER_DEREGISTER(dev_clone, clonetag);
99 while ((mnt = LIST_FIRST(&coda_mnttbl)) != NULL) {
100 LIST_REMOVE(mnt, mi_list);
101 destroy_dev(mnt->dev);
112 static moduledata_t codadev_mod = {
117 DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
120 coda_fbsd_clone(void *arg, struct ucred *cred, char *name, int namelen,
123 struct coda_mntinfo *mnt;
128 if (dev_stdclone(name, NULL, "cfs", &u) != 1)
130 *dev = make_dev(&codadevsw, u, UID_ROOT, GID_WHEEL, 0600,
133 mnt = malloc(sizeof(struct coda_mntinfo), M_CODA, M_WAITOK|M_ZERO);
134 LIST_INSERT_HEAD(&coda_mnttbl, mnt, mi_list);
138 struct coda_mntinfo *
139 dev2coda_mntinfo(struct cdev *dev)
141 struct coda_mntinfo *mnt;
143 LIST_FOREACH(mnt, &coda_mnttbl, mi_list) {