]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/coda/coda_fbsd.c
Sync with sys/i386/isa/isa.c revision 1.114.
[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  *  $Id: coda_fbsd.c,v 1.6 1998/09/28 20:52:57 rvb Exp $
31  * 
32  */
33
34 #ifdef  VFS_LKM
35 #define NVCODA 4
36 #else
37 #include "vcoda.h"
38 #include "opt_devfs.h"
39 #endif
40
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/kernel.h>
44 #include <sys/proc.h>
45 #include <sys/malloc.h>
46 #include <sys/fcntl.h>
47 #include <sys/ucred.h>
48 #include <sys/vnode.h>
49 #include <sys/conf.h>
50
51 #include <vm/vm.h>
52 #include <vm/vnode_pager.h>
53
54 #include <coda/coda.h>
55 #include <coda/cnode.h>
56 #include <coda/coda_vnops.h>
57 #include <coda/coda_psdev.h>
58
59 #ifdef DEVFS
60 #include <sys/devfsext.h>
61
62 static  void    *cfs_devfs_token[NVCODA];
63 static  void    *coda_devfs_token[NVCODA];
64 #endif
65
66 /* 
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
71
72    > Also I need a character device major number. (and might want to reserve
73    > a block of 10 syscalls.)
74
75    Just one char device number?  No block devices?  Very well, cdev 93 is yours!
76 */
77
78 #define VC_DEV_NO      93
79
80 static struct cdevsw codadevsw =
81
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 
85 };
86
87 void vcattach __P((void));
88 static dev_t codadev;
89
90 int     vcdebug = 1;
91 #define VCDEBUG if (vcdebug) printf
92
93 void
94 vcattach(void)
95 {
96   /*
97    * In case we are an LKM, set up device switch.
98    */
99   if (0 == (codadev = makedev(VC_DEV_NO, 0)))
100     VCDEBUG("makedev returned null\n");
101   else 
102     VCDEBUG("makedev OK.\n");
103     
104   cdevsw_add(&codadev, &codadevsw, NULL);
105   VCDEBUG("coda: codadevsw entry installed at %d.\n", major(codadev));
106 }
107
108 static vc_devsw_installed = 0;
109 static void     vc_drvinit __P((void *unused));
110
111 static void
112 vc_drvinit(void *unused)
113 {
114         dev_t dev;
115 #ifdef DEVFS
116         int i;
117 #endif
118
119         if( ! vc_devsw_installed ) {
120                 dev = makedev(VC_DEV_NO, 0);
121                 cdevsw_add(&dev,&codadevsw, NULL);
122                 vc_devsw_installed = 1;
123         }
124 #ifdef DEVFS
125         /* tmp */
126 #undef  NVCODA
127 #define NVCODA 1
128         for (i = 0; i < NVCODA; i++) {
129                 cfs_devfs_token[i] =
130                         devfs_add_devswf(&codadevsw, i,
131                                 DV_CHR, UID_ROOT, GID_WHEEL, 0666,
132                                 "cfs%d", i);
133                 coda_devfs_token[i] =
134                         devfs_add_devswf(&codadevsw, i,
135                                 DV_CHR, UID_ROOT, GID_WHEEL, 0666,
136                                 "coda%d", i);
137         }
138 #endif
139 }
140
141 int
142 coda_fbsd_getpages(v)
143         void *v;
144 {
145     struct vop_getpages_args *ap = v;
146     int ret = 0;
147
148 #if     1
149         /* ??? a_offset */
150         ret = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
151                 ap->a_reqpage);
152         return ret;
153 #else
154   {
155     struct vnode *vp = ap->a_vp;
156     struct cnode *cp = VTOC(vp);
157     struct vnode *cfvp = cp->c_ovp;
158     int opened_internally = 0;
159     struct ucred *cred = (struct ucred *) 0;
160     struct proc *p = curproc;
161     int error = 0;
162         
163     if (IS_CTL_VP(vp)) {
164         return(EINVAL);
165     }
166
167     /* Redirect the request to UFS. */
168
169     if (cfvp == NULL) {
170         opened_internally = 1;
171
172         error = VOP_OPEN(vp, FREAD,  cred, p);
173 printf("coda_getp: Internally Opening %p\n", vp);
174
175         if (error) {
176             printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
177                 return (error);
178         }
179         if (vp->v_type == VREG) {
180             error = vfs_object_create(vp, p, cred, 1);
181             if (error != 0) {
182                 printf("coda_getpage: vfs_object_create() returns %d\n", error);
183                 vput(vp);
184                 return(error);
185             }
186         }
187
188         cfvp = cp->c_ovp;
189     } else {
190 printf("coda_getp: has container %p\n", cfvp);
191     }
192
193 printf("coda_fbsd_getpages: using container ");
194 /*
195     error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
196         ap->a_reqpage);
197 */
198     error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
199         ap->a_reqpage, ap->a_offset);
200 printf("error = %d\n", error);
201
202     /* Do an internal close if necessary. */
203     if (opened_internally) {
204         (void)VOP_CLOSE(vp, FREAD, cred, p);
205     }
206
207     return(error);
208   }
209 #endif
210 }
211
212 int
213 coda_fbsd_putpages(v)
214         void *v;
215 {
216         struct vop_putpages_args *ap = v;
217
218         /*??? a_offset */
219         return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
220                 ap->a_sync, ap->a_rtvals);
221 }
222
223
224 SYSINIT(codadev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,vc_drvinit,NULL)
225
226 #ifdef  VFS_LKM
227
228 #include <sys/mount.h>
229 #include <sys/lkm.h>
230
231 extern struct vfsops coda_vfsops;
232
233 static struct vfsconf _fs_vfsconf = { &coda_vfsops, "coda", -1, 0, 0 };
234
235 extern struct linker_set coda_modvnops ;
236
237 static struct lkm_vfs coda_mod_vfs  = {
238         LM_VFS, LKM_VERSION, "coda", 0, &coda_modvnops, &_fs_vfsconf };
239
240 static struct lkm_dev coda_mod_dev = {
241         LM_DEV, LKM_VERSION, "codadev", VC_DEV_NO, LM_DT_CHAR, (void *) &codadevsw};
242
243 int coda_mod(struct lkm_table *, int, int);
244 int
245 coda_mod(struct lkm_table *lkmtp, int cmd, int ver)
246 {
247         int error = 0;
248
249         if (ver != LKM_VERSION)
250                 return EINVAL;
251
252         switch (cmd) {
253         case LKM_E_LOAD:
254                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_dev;
255                 error = lkmdispatch(lkmtp, cmd);
256                 if (error)
257                         break;
258                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_vfs ;
259                 error = lkmdispatch(lkmtp, cmd);
260                 break;
261         case LKM_E_UNLOAD:
262                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_vfs ;
263                 error = lkmdispatch(lkmtp, cmd);
264                 if (error)
265                         break;
266                 lkmtp->private.lkm_any = (struct lkm_any *) &coda_mod_dev;
267                 error = lkmdispatch(lkmtp, cmd);
268                 break;
269         case LKM_E_STAT:
270                 error = lkmdispatch(lkmtp, cmd);
271                 break;
272         }
273         return error;
274 }
275 #endif