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