freebsd-4x-fix-20030707
[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 <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
18 int
19 afs_quotactl()
20 {
21     return EOPNOTSUPP;
22 }
23
24 int
25 afs_fhtovp(mp, fhp, vpp)
26      struct mount *mp;
27      struct fid *fhp;
28      struct vnode **vpp;
29 {
30
31     return (EINVAL);
32 }
33
34 int
35 afs_vptofh(vp, fhp)
36      struct vnode *vp;
37      struct fid *fhp;
38 {
39
40     return (EINVAL);
41 }
42
43 int
44 afs_start(mp, flags, p)
45      struct mount *mp;
46      int flags;
47      struct proc *p;
48 {
49     afs_pbuf_freecnt = nswbuf / 2 + 1;
50     return (0);                 /* nothing to do. ? */
51 }
52
53 int
54 afs_mount(mp, path, data, ndp, p)
55      register struct mount *mp;
56      char *path;
57      caddr_t data;
58      struct nameidata *ndp;
59      struct proc *p;
60 {
61     /* ndp contains the mounted-from device.  Just ignore it.
62      * we also don't care about our proc struct. */
63     size_t size;
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, struct vnode **vpp)
110 {
111     int error;
112     struct vrequest treq;
113     register struct vcache *tvp = 0;
114 #ifdef AFS_FBSD50_ENV
115     struct thread *td = curthread;
116     struct ucred cr = *td->td_ucred;
117 #else
118     struct proc *p = curproc;
119     struct ucred cr = *p->p_cred->pc_ucred;
120 #endif
121
122     AFS_GLOCK();
123     AFS_STATCNT(afs_root);
124     if (afs_globalVp && (afs_globalVp->states & CStatd)) {
125         tvp = afs_globalVp;
126         error = 0;
127     } else {
128         if (afs_globalVp) {
129             afs_PutVCache(afs_globalVp);
130             afs_globalVp = NULL;
131         }
132
133         if (!(error = afs_InitReq(&treq, &cr)) && !(error = afs_CheckInit())) {
134             tvp = afs_GetVCache(&afs_rootFid, &treq, NULL, NULL);
135             /* we really want this to stay around */
136             if (tvp)
137                 afs_globalVp = tvp;
138             else
139                 error = ENOENT;
140         }
141     }
142     if (tvp) {
143         osi_vnhold(tvp, 0);
144         AFS_GUNLOCK();
145 #ifdef AFS_FBSD50_ENV
146         vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, td);
147 #else
148         vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, p);
149 #endif
150         AFS_GLOCK();
151         afs_globalVFS = mp;
152         *vpp = AFSTOV(tvp);
153         tvp->v.v_flag |= VROOT;
154     }
155
156     afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *vpp,
157                ICL_TYPE_INT32, error);
158     AFS_GUNLOCK();
159     return error;
160 }
161
162 int
163 afs_vget(mp, lfl, vp)
164      struct mount *mp;
165      struct vnode *vp;
166      int lfl;
167 {
168 #ifdef AFS_FBSD50_ENV
169     return EOPNOTSUPP;
170 #else
171     int error;
172
173     printf("vget called. help!\n");
174     if (vp->v_usecount < 0) {
175         vprint("bad usecount", vp);
176         panic("afs_vget");
177     }
178     error = vget(vp, lfl, curproc);
179     if (!error)
180         insmntque(vp, afs_globalVFS);   /* take off free list */
181     return error;
182 #endif
183 }
184
185 int
186 afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p)
187 {
188     AFS_GLOCK();
189     AFS_STATCNT(afs_statfs);
190
191 #if 0
192     abp->f_type = MOUNT_AFS;
193 #endif
194     abp->f_bsize = mp->vfs_bsize;
195     abp->f_iosize = mp->vfs_bsize;
196
197     /* Fake a high number below to satisfy programs that use the statfs call
198      * to make sure that there's enough space in the device partition before
199      * storing something there.
200      */
201     abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
202         abp->f_ffree = 2000000;
203
204     abp->f_fsid.val[0] = mp->mnt_stat.f_fsid.val[0];
205     abp->f_fsid.val[1] = mp->mnt_stat.f_fsid.val[1];
206     if (abp != &mp->mnt_stat) {
207         abp->f_type = mp->mnt_vfc->vfc_typenum;
208         memcpy((caddr_t) & abp->f_mntonname[0],
209                (caddr_t) mp->mnt_stat.f_mntonname, MNAMELEN);
210         memcpy((caddr_t) & abp->f_mntfromname[0],
211                (caddr_t) mp->mnt_stat.f_mntfromname, MNAMELEN);
212     }
213
214     AFS_GUNLOCK();
215     return 0;
216 }
217
218 int
219 afs_sync(mp, waitfor, cred, p)
220      struct mount *mp;
221      int waitfor;
222      struct ucred *cred;
223      struct prioc *p;
224 {
225     return 0;
226 }
227
228 int
229 afs_sysctl()
230 {
231     return EOPNOTSUPP;
232 }
233
234
235 int
236 afs_init(struct vfsconf *vfc)
237 {
238     return 0;
239 }
240
241 struct vfsops afs_vfsops = {
242     afs_mount,
243     afs_start,
244     afs_unmount,
245     afs_root,
246     afs_quotactl,
247     afs_statfs,
248     afs_sync,
249     afs_vget,
250     afs_fhtovp,
251 #ifdef AFS_FBSD50_ENV
252     vfs_stdcheckexp,
253 #endif
254     afs_vptofh,
255     afs_init,
256 #ifdef AFS_FBSD50_ENV
257     vfs_stduninit,
258 #endif
259     afs_sysctl
260 };