FreeBSD/Linux Kernel Cross Reference
sys/coda/coda_fbsd.c
1 /*-
2 * Coda: an Experimental Distributed File System
3 * Release 3.1
4 *
5 * Copyright (c) 1987-1998 Carnegie Mellon University
6 * All Rights Reserved
7 *
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
15 * derivatives.
16 *
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.
23 *
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.
27 *
28 * @(#) src/sys/coda/coda_fbsd.cr,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
29 */
30
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD: releng/6.2/sys/coda/coda_fbsd.c 149038 2005-08-13 21:24:18Z rwatson $");
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/conf.h>
37 #include <sys/fcntl.h>
38 #include <sys/kernel.h>
39 #include <sys/lock.h>
40 #include <sys/malloc.h>
41 #include <sys/module.h>
42 #include <sys/ucred.h>
43 #include <sys/vnode.h>
44
45 #include <vm/vm.h>
46 #include <vm/vnode_pager.h>
47
48 #include <coda/coda.h>
49 #include <coda/cnode.h>
50 #include <coda/coda_vnops.h>
51 #include <coda/coda_psdev.h>
52
53 static struct cdevsw codadevsw = {
54 .d_version = D_VERSION,
55 .d_flags = D_NEEDGIANT,
56 .d_open = vc_nb_open,
57 .d_close = vc_nb_close,
58 .d_read = vc_nb_read,
59 .d_write = vc_nb_write,
60 .d_ioctl = vc_nb_ioctl,
61 .d_poll = vc_nb_poll,
62 .d_name = "Coda",
63 };
64
65 static eventhandler_tag clonetag;
66
67 static LIST_HEAD(, coda_mntinfo) coda_mnttbl;
68
69 int vcdebug = 1;
70 #define VCDEBUG if (vcdebug) printf
71
72 /* for DEVFS, using bpf & tun drivers as examples*/
73 static void coda_fbsd_clone(void *arg, struct ucred *cred, char *name,
74 int namelen, struct cdev **dev);
75
76 static int
77 codadev_modevent(module_t mod, int type, void *data)
78 {
79 struct coda_mntinfo *mnt;
80
81 switch (type) {
82 case MOD_LOAD:
83 LIST_INIT(&coda_mnttbl);
84 clonetag = EVENTHANDLER_REGISTER(dev_clone, coda_fbsd_clone,
85 0, 1000);
86 break;
87 case MOD_UNLOAD:
88 EVENTHANDLER_DEREGISTER(dev_clone, clonetag);
89 while ((mnt = LIST_FIRST(&coda_mnttbl)) != NULL) {
90 LIST_REMOVE(mnt, mi_list);
91 destroy_dev(mnt->dev);
92 free(mnt, M_CODA);
93 }
94 break;
95
96 default:
97 return (EOPNOTSUPP);
98 }
99 return 0;
100 }
101 static moduledata_t codadev_mod = {
102 "codadev",
103 codadev_modevent,
104 NULL
105 };
106 DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
107
108 static void coda_fbsd_clone(arg, cred, name, namelen, dev)
109 void *arg;
110 struct ucred *cred;
111 char *name;
112 int namelen;
113 struct cdev **dev;
114 {
115 int u;
116 struct coda_mntinfo *mnt;
117
118 if (*dev != NULL)
119 return;
120 if (dev_stdclone(name,NULL,"cfs",&u) != 1)
121 return;
122
123 *dev = make_dev(&codadevsw,unit2minor(u),UID_ROOT,GID_WHEEL,0600,"cfs%d",u);
124 dev_ref(*dev);
125 mnt = malloc(sizeof(struct coda_mntinfo), M_CODA, M_WAITOK|M_ZERO);
126 LIST_INSERT_HEAD(&coda_mnttbl, mnt, mi_list);
127 }
128
129 struct coda_mntinfo *
130 dev2coda_mntinfo(struct cdev *dev)
131 {
132 struct coda_mntinfo *mnt;
133
134 LIST_FOREACH(mnt, &coda_mnttbl, mi_list) {
135 if (mnt->dev == dev)
136 break;
137 }
138
139 return mnt;
140 }
Cache object: 4bdfedefd7227fd28480cc6292d2db4c
|