2 * Portions Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
10 #include <afs/sysincludes.h> /* Standard vendor system headers */
11 #include <afsincludes.h> /* Afs-based standard headers */
12 #include <afs/afs_stats.h> /* statistics */
13 #include <sys/malloc.h>
14 #include <sys/namei.h>
16 #include <sys/syscall.h>
17 #include <sys/sysctl.h>
18 #include "../afs/sysctl.h"
20 struct vcache *afs_globalVp = 0;
21 struct mount *afs_globalVFS = 0;
30 afs_fhtovp(mp, fhp, vpp)
49 afs_start(mp, flags, p)
54 return (0); /* nothing to do. ? */
58 afs_mount(mp, path, data, ndp, p)
59 register struct mount *mp;
62 struct nameidata *ndp;
65 /* ndp contains the mounted-from device. Just ignore it.
66 * we also don't care about our proc struct. */
70 if (mp->mnt_flag & MNT_UPDATE)
74 AFS_STATCNT(afs_mount);
76 if (data == NULL && afs_globalVFS) { /* Don't allow remounts. */
84 mp->mnt_stat.f_iosize = 8192;
86 (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
87 memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
88 memset(mp->mnt_stat.f_mntfromname, 0, MNAMELEN);
91 strcpy(mp->mnt_stat.f_mntfromname, "AFS");
92 /* null terminated string "AFS" will fit, just leave it be. */
93 mp->mnt_data = (qaddr_t) NULL;
95 struct VenusFid *rootFid = NULL;
97 char volName[MNAMELEN];
99 (void)copyinstr((char *)data, volName, MNAMELEN - 1, &size);
100 memset(volName + size, 0, MNAMELEN - size);
102 if (volName[0] == 0) {
103 strcpy(mp->mnt_stat.f_mntfromname, "AFS");
104 mp->mnt_data = (qaddr_t) & afs_rootFid;
106 struct cell *localcell = afs_GetPrimaryCell(READ_LOCK);
107 if (localcell == NULL) {
112 /* Set the volume identifier to "AFS:volume.name" */
113 snprintf(mp->mnt_stat.f_mntfromname, MNAMELEN - 1, "AFS:%s",
116 afs_GetVolumeByName(volName, localcell->cellNum, 1,
117 (struct vrequest *)0, READ_LOCK);
120 int volid = (tvp->roVol ? tvp->roVol : tvp->volume);
121 MALLOC(rootFid, struct VenusFid *, sizeof(*rootFid), M_UFSMNT,
123 rootFid->Cell = localcell->cellNum;
124 rootFid->Fid.Volume = volid;
125 rootFid->Fid.Vnode = 1;
126 rootFid->Fid.Unique = 1;
132 mp->mnt_data = (qaddr_t) rootFid;
135 strcpy(mp->mnt_stat.f_fstypename, "afs");
137 (void)afs_statfs(mp, &mp->mnt_stat, p);
142 afs_unmount(mp, flags, p)
149 AFS_STATCNT(afs_unmount);
151 if (mp->mnt_data != (qaddr_t) - 1) {
152 if (mp->mnt_data != NULL) {
153 FREE(mp->mnt_data, M_UFSMNT);
154 mp->mnt_data = (qaddr_t) - 1;
156 if (flags & MNT_FORCE) {
159 #ifdef AFS_DARWIN80_ENV
160 vnode_rele(AFSTOV(afs_globalVp));
162 vrele(AFSTOV(afs_globalVp));
168 vflush(mp, NULLVP, FORCECLOSE/*0*/);
177 mp->mnt_flag &= ~MNT_LOCAL;
186 afs_root(struct mount *mp, struct vnode **vpp)
189 struct vrequest treq;
190 register struct vcache *tvp = 0;
191 struct proc *p = current_proc();
195 cr = *p->p_cred->pc_ucred;
198 AFS_STATCNT(afs_root);
199 if (mp->mnt_data == NULL && afs_globalVp
200 && (afs_globalVp->states & CStatd)) {
203 } else if (mp->mnt_data == (qaddr_t) - 1) {
206 struct VenusFid *rootFid = (mp->mnt_data == NULL)
207 ? &afs_rootFid : (struct VenusFid *)mp->mnt_data;
210 afs_PutVCache(afs_globalVp);
214 if (!(error = afs_InitReq(&treq, &cr)) && !(error = afs_CheckInit())) {
215 tvp = afs_GetVCache(rootFid, &treq, NULL, NULL);
216 /* we really want this to stay around */
218 if (mp->mnt_data == NULL)
227 vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, p);
229 if (mp->mnt_data == NULL) {
233 AFSTOV(tvp)->v_flag |= VROOT;
234 AFSTOV(tvp)->v_vfsp = mp;
237 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *vpp,
238 ICL_TYPE_INT32, error);
244 afs_vget(mp, lfl, vp)
250 //printf("vget called. help!\n");
251 if (vp->v_usecount < 0) {
252 vprint("bad usecount", vp);
255 #ifdef AFS_DARWIN80_ENV
256 error = vnode_get(vp);
258 error = vget(vp, lfl, current_proc());
261 insmntque(vp, mp); /* take off free list */
266 afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p)
269 AFS_STATCNT(afs_statfs);
272 abp->f_type = MOUNT_AFS;
274 abp->f_bsize = mp->vfs_bsize;
275 abp->f_iosize = mp->vfs_bsize;
277 /* Fake a high number below to satisfy programs that use the statfs call
278 * to make sure that there's enough space in the device partition before
279 * storing something there.
281 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
282 abp->f_ffree = 2000000;
284 abp->f_fsid.val[0] = mp->mnt_stat.f_fsid.val[0];
285 abp->f_fsid.val[1] = mp->mnt_stat.f_fsid.val[1];
286 if (abp != &mp->mnt_stat) {
287 abp->f_type = mp->mnt_vfc->vfc_typenum;
288 memcpy((caddr_t) & abp->f_mntonname[0],
289 (caddr_t) mp->mnt_stat.f_mntonname, MNAMELEN);
290 memcpy((caddr_t) & abp->f_mntfromname[0],
291 (caddr_t) mp->mnt_stat.f_mntfromname, MNAMELEN);
299 afs_sync(mp, waitfor, cred, p)
308 u_int32_t afs_darwin_realmodes = 0;
310 int afs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
311 void *newp, size_t newlen, struct proc *p)
317 /* nothing defined */
323 case AFS_SC_DARWIN_ALL:
325 case AFS_SC_DARWIN_ALL_REALMODES:
326 return sysctl_int(oldp, oldlenp, newp, newlen,
327 &afs_darwin_realmodes);
330 /* darwin version specific sysctl's goes here */
338 extern int vfs_opv_numops; /* The total number of defined vnode operations */
339 extern struct vnodeopv_desc afs_vnodeop_opv_desc;
341 afs_init(struct vfsconf *vfc)
344 int (**opv_desc_vector) ();
345 struct vnodeopv_entry_desc *opve_descp;
349 MALLOC(afs_vnodeop_p, PFI *, vfs_opv_numops * sizeof(PFI), M_TEMP,
352 memset(afs_vnodeop_p, 0, vfs_opv_numops * sizeof(PFI));
354 opv_desc_vector = afs_vnodeop_p;
355 for (j = 0; afs_vnodeop_opv_desc.opv_desc_ops[j].opve_op; j++) {
356 opve_descp = &(afs_vnodeop_opv_desc.opv_desc_ops[j]);
359 * Sanity check: is this operation listed
360 * in the list of operations? We check this
361 * by seeing if its offest is zero. Since
362 * the default routine should always be listed
363 * first, it should be the only one with a zero
364 * offset. Any other operation with a zero
365 * offset is probably not listed in
366 * vfs_op_descs, and so is probably an error.
368 * A panic here means the layer programmer
369 * has committed the all-too common bug
370 * of adding a new operation to the layer's
371 * list of vnode operations but
372 * not adding the operation to the system-wide
373 * list of supported operations.
375 if (opve_descp->opve_op->vdesc_offset == 0
376 && opve_descp->opve_op->vdesc_offset != VOFFSET(vop_default)) {
377 printf("afs_init: operation %s not listed in %s.\n",
378 opve_descp->opve_op->vdesc_name, "vfs_op_descs");
379 panic("load_afs: bad operation");
382 * Fill in this entry.
384 opv_desc_vector[opve_descp->opve_op->vdesc_offset] =
385 opve_descp->opve_impl;
389 * Finally, go back and replace unfilled routines
390 * with their default. (Sigh, an O(n^3) algorithm. I
391 * could make it better, but that'd be work, and n is small.)
395 * Force every operations vector to have a default routine.
397 opv_desc_vector = afs_vnodeop_p;
398 if (opv_desc_vector[VOFFSET(vop_default)] == NULL) {
399 panic("afs_init: operation vector without default routine.");
401 for (j = 0; j < vfs_opv_numops; j++)
402 if (opv_desc_vector[j] == NULL)
403 opv_desc_vector[j] = opv_desc_vector[VOFFSET(vop_default)];
406 struct vfsops afs_vfsops = {