]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/fs/coda/coda_fbsd.c
This commit was generated by cvs2svn to compensate for changes in r48146,
[FreeBSD/FreeBSD.git] / sys / fs / 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.14 1999/05/30 16:51:10 phk Exp $
31  * 
32  */
33
34 #include "vcoda.h"
35 #include "opt_devfs.h"
36
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/proc.h>
41 #include <sys/malloc.h>
42 #include <sys/fcntl.h>
43 #include <sys/ucred.h>
44 #include <sys/vnode.h>
45 #include <sys/conf.h>
46
47 #include <vm/vm.h>
48 #include <vm/vnode_pager.h>
49
50 #include <coda/coda.h>
51 #include <coda/cnode.h>
52 #include <coda/coda_vnops.h>
53 #include <coda/coda_psdev.h>
54
55 #ifdef DEVFS
56 #include <sys/devfsext.h>
57
58 static  void    *cfs_devfs_token[NVCODA];
59 static  void    *coda_devfs_token[NVCODA];
60 #endif
61
62 /* 
63    From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
64    Subject: Re: New 3.0 SNAPshot CDROM about ready for production.. 
65    To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
66    Date: Fri, 20 Feb 1998 15:57:01 -0800
67
68    > Also I need a character device major number. (and might want to reserve
69    > a block of 10 syscalls.)
70
71    Just one char device number?  No block devices?  Very well, cdev 93 is yours!
72 */
73
74 #define VC_DEV_NO      93
75
76 static struct cdevsw codadevsw = {
77         /* open */      vc_nb_open,
78         /* close */     vc_nb_close,
79         /* read */      vc_nb_read,
80         /* write */     vc_nb_write,
81         /* ioctl */     vc_nb_ioctl,
82         /* stop */      nostop,
83         /* reset */     noreset,
84         /* devtotty */  nodevtotty,
85         /* poll */      vc_nb_poll,
86         /* mmap */      nommap,
87         /* strategy */  nostrategy,
88         /* name */      "Coda",
89         /* parms */     noparms,
90         /* maj */       VC_DEV_NO,
91         /* dump */      nodump,
92         /* psize */     nopsize,
93         /* flags */     0,
94         /* maxio */     0,
95         /* bmaj */      -1
96 };
97
98 int     vcdebug = 1;
99 #define VCDEBUG if (vcdebug) printf
100
101 static int
102 codadev_modevent(module_t mod, int type, void *data)
103 {
104 #ifdef DEVFS
105         int i;
106 #endif
107         static struct cdevsw *oldcdevsw;
108
109         switch (type) {
110         case MOD_LOAD:
111                 cdevsw_add(&codadevsw);
112 #ifdef DEVFS
113                 /* tmp */
114 #undef  NVCODA
115 #define NVCODA 1
116                 for (i = 0; i < NVCODA; i++) {
117                         cfs_devfs_token[i] =
118                                 devfs_add_devswf(&codadevsw, i,
119                                         DV_CHR, UID_ROOT, GID_WHEEL, 0666,
120                                         "cfs%d", i);
121                         coda_devfs_token[i] =
122                                 devfs_add_devswf(&codadevsw, i,
123                                         DV_CHR, UID_ROOT, GID_WHEEL, 0666,
124                                         "coda%d", i);
125                 }
126 #endif
127                 break;
128         case MOD_UNLOAD:
129 #ifdef DEVFS
130                 for (i = 0; i < NVCODA; i++) {
131                         devfs_remove_dev(cfs_devfs_token[i]);
132                         devfs_remove_dev(coda_devfs_token[i]);
133                 }
134 #endif
135                 cdevsw_add(oldcdevsw);
136                 break;
137         default:
138                 break;
139         }
140         return 0;
141 }
142 static moduledata_t codadev_mod = {
143         "codadev",
144         codadev_modevent,
145         NULL
146 };
147 DECLARE_MODULE(codadev, codadev_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE+VC_DEV_NO);
148
149 int
150 coda_fbsd_getpages(v)
151         void *v;
152 {
153     struct vop_getpages_args *ap = v;
154     int ret = 0;
155
156 #if     1
157         /* ??? a_offset */
158         ret = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
159                 ap->a_reqpage);
160         return ret;
161 #else
162   {
163     struct vnode *vp = ap->a_vp;
164     struct cnode *cp = VTOC(vp);
165     struct vnode *cfvp = cp->c_ovp;
166     int opened_internally = 0;
167     struct ucred *cred = (struct ucred *) 0;
168     struct proc *p = curproc;
169     int error = 0;
170         
171     if (IS_CTL_VP(vp)) {
172         return(EINVAL);
173     }
174
175     /* Redirect the request to UFS. */
176
177     if (cfvp == NULL) {
178         opened_internally = 1;
179
180         error = VOP_OPEN(vp, FREAD,  cred, p);
181 printf("coda_getp: Internally Opening %p\n", vp);
182
183         if (error) {
184             printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
185                 return (error);
186         }
187         if (vp->v_type == VREG) {
188             error = vfs_object_create(vp, p, cred);
189             if (error != 0) {
190                 printf("coda_getpage: vfs_object_create() returns %d\n", error);
191                 vput(vp);
192                 return(error);
193             }
194         }
195
196         cfvp = cp->c_ovp;
197     } else {
198 printf("coda_getp: has container %p\n", cfvp);
199     }
200
201 printf("coda_fbsd_getpages: using container ");
202 /*
203     error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
204         ap->a_reqpage);
205 */
206     error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
207         ap->a_reqpage, ap->a_offset);
208 printf("error = %d\n", error);
209
210     /* Do an internal close if necessary. */
211     if (opened_internally) {
212         (void)VOP_CLOSE(vp, FREAD, cred, p);
213     }
214
215     return(error);
216   }
217 #endif
218 }
219
220 int
221 coda_fbsd_putpages(v)
222         void *v;
223 {
224         struct vop_putpages_args *ap = v;
225
226         /*??? a_offset */
227         return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
228                 ap->a_sync, ap->a_rtvals);
229 }