]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/coda/coda_fbsd.c
This commit was generated by cvs2svn to compensate for changes in r104349,
[FreeBSD/FreeBSD.git] / sys / coda / coda_fbsd.c
1 /*
2  * 
3  *             Coda: an Experimental Distributed File System
4  *                              Release 3.1
5  * 
6  *           Copyright (c) 1987-1998 Carnegie Mellon University
7  *                          All Rights Reserved
8  * 
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
16  * derivatives.
17  * 
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.
24  * 
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.
28  * 
29  *      @(#) src/sys/coda/coda_fbsd.cr,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
30  * $FreeBSD$
31  * 
32  */
33
34 #include "vcoda.h"
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/conf.h>
39 #include <sys/fcntl.h>
40 #include <sys/kernel.h>
41 #include <sys/lock.h>
42 #include <sys/malloc.h>
43 #include <sys/ucred.h>
44 #include <sys/vnode.h>
45
46 #include <vm/vm.h>
47 #include <vm/vnode_pager.h>
48
49 #include <coda/coda.h>
50 #include <coda/cnode.h>
51 #include <coda/coda_vnops.h>
52 #include <coda/coda_psdev.h>
53
54 /* 
55    From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
56    Subject: Re: New 3.0 SNAPshot CDROM about ready for production.. 
57    To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
58    Date: Fri, 20 Feb 1998 15:57:01 -0800
59
60    > Also I need a character device major number. (and might want to reserve
61    > a block of 10 syscalls.)
62
63    Just one char device number?  No block devices?  Very well, cdev 93 is yours!
64 */
65
66 #define VC_DEV_NO      93
67
68 static struct cdevsw codadevsw = {
69         /* open */      vc_nb_open,
70         /* close */     vc_nb_close,
71         /* read */      vc_nb_read,
72         /* write */     vc_nb_write,
73         /* ioctl */     vc_nb_ioctl,
74         /* poll */      vc_nb_poll,
75         /* mmap */      nommap,
76         /* strategy */  nostrategy,
77         /* name */      "Coda",
78         /* maj */       VC_DEV_NO,
79         /* dump */      nodump,
80         /* psize */     nopsize,
81         /* flags */     0,
82 };
83
84 int     vcdebug = 1;
85 #define VCDEBUG if (vcdebug) printf
86
87 static int
88 codadev_modevent(module_t mod, int type, void *data)
89 {
90
91         switch (type) {
92         case MOD_LOAD:
93                 break;
94         case MOD_UNLOAD:
95                 break;
96         default:
97                 break;
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+VC_DEV_NO);
107
108 int
109 coda_fbsd_getpages(v)
110         void *v;
111 {
112     struct vop_getpages_args *ap = v;
113
114 #if     1
115         return vop_stdgetpages(ap);
116 #else
117   {
118     struct vnode *vp = ap->a_vp;
119     struct cnode *cp = VTOC(vp);
120     struct vnode *cfvp = cp->c_ovp;
121     int opened_internally = 0;
122     struct ucred *cred = (struct ucred *) 0;
123     struct proc *p = curproc;
124     int error = 0;
125         
126     if (IS_CTL_VP(vp)) {
127         return(EINVAL);
128     }
129
130     /* Redirect the request to UFS. */
131
132     if (cfvp == NULL) {
133         opened_internally = 1;
134
135         error = VOP_OPEN(vp, FREAD,  cred, p);
136 printf("coda_getp: Internally Opening %p\n", vp);
137
138         if (error) {
139             printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
140                 return (error);
141         }
142         if (vp->v_type == VREG) {
143             error = vfs_object_create(vp, p, cred);
144             if (error != 0) {
145                 printf("coda_getpage: vfs_object_create() returns %d\n", error);
146                 vput(vp);
147                 return(error);
148             }
149         }
150
151         cfvp = cp->c_ovp;
152     } else {
153 printf("coda_getp: has container %p\n", cfvp);
154     }
155
156 printf("coda_fbsd_getpages: using container ");
157 /*
158     error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
159         ap->a_reqpage);
160 */
161     error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
162         ap->a_reqpage, ap->a_offset);
163 printf("error = %d\n", error);
164
165     /* Do an internal close if necessary. */
166     if (opened_internally) {
167         (void)VOP_CLOSE(vp, FREAD, cred, p);
168     }
169
170     return(error);
171   }
172 #endif
173 }
174
175
176 /* for DEVFS, using bpf & tun drivers as examples*/
177 static void coda_fbsd_drvinit(void *unused);
178 static void coda_fbsd_drvuninit(void *unused);
179 static void coda_fbsd_clone(void *arg, char *name, int namelen, dev_t *dev);
180
181 static void coda_fbsd_clone(arg, name, namelen, dev)
182     void *arg;
183     char *name;
184     int namelen;
185     dev_t *dev;
186 {
187     int u;
188
189     if (*dev != NODEV)
190         return;
191     if (dev_stdclone(name,NULL,"cfs",&u) != 1)
192         return;
193
194     *dev = make_dev(&codadevsw,unit2minor(u),UID_ROOT,GID_WHEEL,0600,"cfs%d",u);
195     coda_mnttbl[unit2minor(u)].dev = *dev;
196   
197 }
198
199 static void coda_fbsd_drvinit(unused)
200     void *unused;
201 {
202     int i;
203
204     EVENTHANDLER_REGISTER(dev_clone,coda_fbsd_clone,0,1000);
205     cdevsw_add(&codadevsw);
206     for(i=0;i<NVCODA;i++)
207         coda_mnttbl[i].dev = NULL; 
208 }
209
210 static void coda_fbsd_drvuninit(unused)
211     void *unused;
212 {
213     int i;
214
215     EVENTHANDLER_DEREGISTER(dev_clone,NULL);
216     for(i=0;i<NVCODA;i++)
217         if(coda_mnttbl[i].dev)
218             destroy_dev(coda_mnttbl[i].dev);
219     cdevsw_remove(&codadevsw);
220 }
221
222 SYSINIT(coda_fbsd_dev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,coda_fbsd_drvinit,NULL);
223
224 SYSUNINIT(coda_fbsd_dev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,coda_fbsd_drvuninit,NULL);