]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/coda/coda_fbsd.c
This commit was generated by cvs2svn to compensate for changes in r39092,
[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/cfs/cfs_fbsd.c,v 1.1.1.1 1998/08/29 21:14:52 rvb Exp $
30  *  $Id: cfs_fbsd.c,v 1.2 1998/09/02 19:09:53 rvb Exp $
31  * 
32  */
33
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/proc.h>
38 #include <sys/malloc.h>
39 #include <sys/fcntl.h>
40 #include <sys/ucred.h>
41 #include <sys/vnode.h>
42 #include <sys/conf.h>
43
44 #include <vm/vm.h>
45 #include <vm/vnode_pager.h>
46
47 #include <cfs/coda.h>
48 #include <cfs/cnode.h>
49 #include <cfs/cfs_vnodeops.h>
50
51 #ifdef DEVFS
52 #include <sys/devfsext.h>
53 #endif
54
55 /* 
56    From: "Jordan K. Hubbard" <jkh@time.cdrom.com>
57    Subject: Re: New 3.0 SNAPshot CDROM about ready for production.. 
58    To: "Robert.V.Baron" <rvb@GLUCK.CODA.CS.CMU.EDU>
59    Date: Fri, 20 Feb 1998 15:57:01 -0800
60
61    > Also I need a character device major number. (and might want to reserve
62    > a block of 10 syscalls.)
63
64    Just one char device number?  No block devices?  Very well, cdev 93 is yours!
65 */
66
67 #define VC_DEV_NO      93
68
69 /* Type of device methods. */
70 extern d_open_t  vc_nb_open;
71 extern d_close_t vc_nb_close;
72 extern d_read_t  vc_nb_read;
73 extern d_write_t vc_nb_write;
74 extern d_ioctl_t vc_nb_ioctl;
75 extern d_poll_t  vc_nb_poll;
76
77 static struct cdevsw vccdevsw =
78
79   vc_nb_open,      vc_nb_close,    vc_nb_read,        vc_nb_write,      /*93*/
80   vc_nb_ioctl,     nostop,         nullreset,         nodevtotty,
81   vc_nb_poll,      nommap,         NULL,              "Coda", NULL, -1 
82 };
83
84 void vcattach __P((void));
85 static dev_t vccdev;
86
87 int     vcdebug = 1;
88 #define VCDEBUG if (vcdebug) printf
89
90 void
91 vcattach(void)
92 {
93   /*
94    * In case we are an LKM, set up device switch.
95    */
96   if (0 == (vccdev = makedev(VC_DEV_NO, 0)))
97     VCDEBUG("makedev returned null\n");
98   else 
99     VCDEBUG("makedev OK.\n");
100     
101   cdevsw_add(&vccdev, &vccdevsw, NULL);
102   VCDEBUG("coda: vccdevsw entry installed at %d.\n", major(vccdev));
103 }
104
105 static vc_devsw_installed = 0;
106 static void     vc_drvinit __P((void *unused));
107
108 static void
109 vc_drvinit(void *unused)
110 {
111         dev_t dev;
112
113         if( ! vc_devsw_installed ) {
114                 dev = makedev(VC_DEV_NO, 0);
115                 cdevsw_add(&dev,&vccdevsw, NULL);
116                 vc_devsw_installed = 1;
117         }
118 }
119
120 int
121 coda_fbsd_getpages(v)
122         void *v;
123 {
124     struct vop_getpages_args *ap = v;
125     struct vnode *vp = ap->a_vp;
126     struct cnode *cp = VTOC(vp);
127     int ret = 0;
128
129 #if     1
130         /*??? a_offset */
131         ret = vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
132                 ap->a_reqpage);
133         return ret;
134 #else
135   {
136     struct vnode *vp = ap->a_vp;
137     struct cnode *cp = VTOC(vp);
138     struct vnode *cfvp = cp->c_ovp;
139     int opened_internally = 0;
140     struct ucred *cred = (struct ucred *) 0;
141     struct proc *p = curproc;
142     int error = 0;
143         
144     if (IS_CTL_VP(vp)) {
145         return(EINVAL);
146     }
147
148     /* Redirect the request to UFS. */
149
150     if (cfvp == NULL) {
151         opened_internally = 1;
152
153         error = VOP_OPEN(vp, FREAD,  cred, p);
154 printf("coda_getp: Internally Opening %p\n", vp);
155
156         if (error) {
157             printf("coda_getpage: VOP_OPEN on container failed %d\n", error);
158                 return (error);
159         }
160         if (vp->v_type == VREG) {
161             error = vfs_object_create(vp, p, cred, 1);
162             if (error != 0) {
163                 printf("coda_getpage: vfs_object_create() returns %d\n", error);
164                 vput(vp);
165                 return(error);
166             }
167         }
168
169         cfvp = cp->c_ovp;
170     } else {
171 printf("coda_getp: has container %p\n", cfvp);
172     }
173
174 printf("coda_fbsd_getpages: using container ");
175 /*
176     error = vnode_pager_generic_getpages(cfvp, ap->a_m, ap->a_count,
177         ap->a_reqpage);
178 */
179     error = VOP_GETPAGES(cfvp, ap->a_m, ap->a_count,
180         ap->a_reqpage, ap->a_offset);
181 printf("error = %d\n", error);
182
183     /* Do an internal close if necessary. */
184     if (opened_internally) {
185         (void)VOP_CLOSE(vp, FREAD, cred, p);
186     }
187
188     return(error);
189   }
190 #endif
191 }
192
193 int
194 coda_fbsd_putpages(v)
195         void *v;
196 {
197         struct vop_putpages_args *ap = v;
198
199         /*??? a_offset */
200         return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
201                 ap->a_sync, ap->a_rtvals);
202 }
203
204
205 SYSINIT(vccdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+VC_DEV_NO,vc_drvinit,NULL)