freebsd-almost-working-client-20020216
[openafs.git] / src / afs / FBSD / osi_vfsops.c
1 #include <afsconfig.h>
2 #include <afs/param.h>
3
4 RCSID("$Header$");
5
6 #include <afs/sysincludes.h>            /* Standard vendor system headers */
7 #include <afs/afsincludes.h>            /* Afs-based standard headers */
8 #include <afs/afs_stats.h>              /* statistics */
9 #include <sys/malloc.h>
10 #include <sys/namei.h>
11 #include <sys/conf.h>
12 #include <sys/syscall.h>
13
14 struct vcache *afs_globalVp = 0;
15 struct mount *afs_globalVFS = 0;
16 int afs_pbuf_freecnt=-1;
17 int
18 afs_quotactl()
19 {
20         return EOPNOTSUPP;
21 }
22
23 int
24 afs_fhtovp(mp, fhp, vpp)
25 struct mount *mp;
26 struct fid *fhp;
27 struct vnode **vpp;
28 {
29
30         return (EINVAL);
31 }
32
33 int
34 afs_vptofh(vp, fhp)
35 struct vnode *vp;
36 struct fid *fhp;
37 {
38
39         return (EINVAL);
40 }
41
42 int
43 afs_start(mp, flags, p)
44 struct mount *mp;
45 int flags;
46 struct proc *p;
47 {
48     afs_pbuf_freecnt = nswbuf / 2 + 1;
49     return (0);                         /* nothing to do. ? */
50 }
51
52 int
53 afs_mount(mp, path, data, ndp, p)
54 register struct mount *mp;
55 char *path;
56 caddr_t data;
57 struct nameidata *ndp;
58 struct proc *p;
59 {
60     /* ndp contains the mounted-from device.  Just ignore it.
61        we also don't care about our proc struct. */
62     size_t size;
63     int error;
64
65     if (mp->mnt_flag & MNT_UPDATE)
66         return EINVAL;
67
68     AFS_GLOCK();
69     AFS_STATCNT(afs_mount);
70
71     if (afs_globalVFS) { /* Don't allow remounts. */
72         AFS_GUNLOCK();
73         return (EBUSY);
74     }
75
76     afs_globalVFS = mp;
77     mp->vfs_bsize = 8192;
78     vfs_getnewfsid(mp);
79     mp->mnt_stat.f_iosize=8192;
80     
81     (void) copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN-1, &size);
82     memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
83     memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
84     strcpy(mp->mnt_stat.f_mntfromname, "AFS");
85     /* null terminated string "AFS" will fit, just leave it be. */
86     strcpy(mp->mnt_stat.f_fstypename, "afs");
87     AFS_GUNLOCK();
88     (void) afs_statfs(mp, &mp->mnt_stat, p);
89     return 0;
90 }
91
92 int
93 afs_unmount(mp, flags, p)
94 struct mount *mp;
95 int flags;
96 struct proc *p;
97 {
98     
99     AFS_GLOCK();
100     AFS_STATCNT(afs_unmount);
101     afs_globalVFS = 0;
102     afs_shutdown();
103     AFS_GUNLOCK();
104
105     return 0;
106 }
107
108 int
109 afs_root(struct mount *mp,
110               struct vnode **vpp)
111 {
112     int error;
113     struct vrequest treq;
114     register struct vcache *tvp=0;
115     struct proc *p=curproc;
116     struct ucred cr;
117
118     cr=*p->p_cred->pc_ucred;
119     AFS_GLOCK();
120     AFS_STATCNT(afs_root);
121     if (afs_globalVp && (afs_globalVp->states & CStatd)) {
122         tvp = afs_globalVp;
123         error=0;
124     } else {
125         
126         if (!(error = afs_InitReq(&treq, &cr)) &&
127             !(error = afs_CheckInit())) {
128             tvp = afs_GetVCache(&afs_rootFid, &treq, (afs_int32 *)0,
129                                 (struct vcache*)0, WRITE_LOCK);
130             /* we really want this to stay around */
131             if (tvp) {
132                 afs_globalVp = tvp;
133             } else
134                 error = ENOENT;
135         }
136     }
137     if (tvp) {
138         osi_vnhold(tvp,0);
139     AFS_GUNLOCK();
140         vn_lock((struct vnode *)tvp, LK_EXCLUSIVE | LK_RETRY, p);
141     AFS_GLOCK();
142         afs_globalVFS = mp;
143         *vpp = (struct vnode *) tvp;
144         tvp->v.v_flag |= VROOT;
145     }
146
147     afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *vpp,
148                ICL_TYPE_INT32, error);
149     AFS_GUNLOCK();
150     return error;
151 }
152
153 int
154 afs_vget(mp, lfl, vp)
155 struct mount *mp;
156 struct vnode *vp;
157 int lfl;
158 {
159     int error;
160     printf("vget called. help!\n");
161     if (vp->v_usecount < 0) {
162         vprint("bad usecount", vp);
163         panic("afs_vget");
164     }
165     error = vget(vp, lfl, curproc);
166     if (!error)
167         insmntque(vp, afs_globalVFS);   /* take off free list */
168     return error;
169 }
170
171 int afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p)
172 {
173     AFS_GLOCK();
174     AFS_STATCNT(afs_statfs);
175
176 #if 0
177     abp->f_type = MOUNT_AFS;
178 #endif
179     abp->f_bsize = mp->vfs_bsize;
180     abp->f_iosize = mp->vfs_bsize;
181
182     /* Fake a high number below to satisfy programs that use the statfs call
183      * to make sure that there's enough space in the device partition before
184      * storing something there.
185      */
186     abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
187         abp->f_ffree  = 2000000;
188
189     abp->f_fsid.val[0] = mp->mnt_stat.f_fsid.val[0];
190     abp->f_fsid.val[1] = mp->mnt_stat.f_fsid.val[1];
191     if (abp != &mp->mnt_stat) {
192         abp->f_type = mp->mnt_vfc->vfc_typenum;
193         memcpy((caddr_t)&abp->f_mntonname[0], (caddr_t)mp->mnt_stat.f_mntonname, MNAMELEN);
194         memcpy((caddr_t)&abp->f_mntfromname[0], (caddr_t)mp->mnt_stat.f_mntfromname, MNAMELEN);
195     }
196
197     AFS_GUNLOCK();
198     return 0;
199 }
200
201 int afs_sync(mp, waitfor, cred, p) 
202 struct mount *mp;
203 int waitfor;
204 struct ucred *cred;
205 struct prioc *p;
206 {
207 return 0;
208 }
209
210 int afs_sysctl() {
211    return EOPNOTSUPP;
212 }
213
214
215 int afs_init(struct vfsconf *vfc) {
216    return 0;
217 }
218
219 struct vfsops afs_vfsops = {
220   afs_mount,
221   afs_start,
222   afs_unmount,
223   afs_root,
224   afs_quotactl,
225   afs_statfs,
226   afs_sync,
227   afs_vget,
228   afs_fhtovp,
229   afs_vptofh,
230   afs_init,
231   afs_sysctl
232 };