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) {
164 mp->mnt_flag &= ~MNT_LOCAL;
173 afs_root(struct mount *mp, struct vnode **vpp)
176 struct vrequest treq;
177 register struct vcache *tvp = 0;
178 struct proc *p = current_proc();
182 cr = *p->p_cred->pc_ucred;
185 AFS_STATCNT(afs_root);
186 if (mp->mnt_data == NULL && afs_globalVp
187 && (afs_globalVp->states & CStatd)) {
190 } else if (mp->mnt_data == (qaddr_t) - 1) {
193 struct VenusFid *rootFid = (mp->mnt_data == NULL)
194 ? &afs_rootFid : (struct VenusFid *)mp->mnt_data;
197 afs_PutVCache(afs_globalVp);
201 if (!(error = afs_InitReq(&treq, &cr)) && !(error = afs_CheckInit())) {
202 tvp = afs_GetVCache(rootFid, &treq, NULL, NULL);
203 /* we really want this to stay around */
205 if (mp->mnt_data == NULL)
214 vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, p);
216 if (mp->mnt_data == NULL) {
220 AFSTOV(tvp)->v_flag |= VROOT;
221 AFSTOV(tvp)->v_vfsp = mp;
224 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *vpp,
225 ICL_TYPE_INT32, error);
231 afs_vget(mp, lfl, vp)
237 printf("vget called. help!\n");
238 if (vp->v_usecount < 0) {
239 vprint("bad usecount", vp);
242 error = vget(vp, lfl, current_proc());
244 insmntque(vp, mp); /* take off free list */
249 afs_statfs(struct mount *mp, struct statfs *abp, struct proc *p)
252 AFS_STATCNT(afs_statfs);
255 abp->f_type = MOUNT_AFS;
257 abp->f_bsize = mp->vfs_bsize;
258 abp->f_iosize = mp->vfs_bsize;
260 /* Fake a high number below to satisfy programs that use the statfs call
261 * to make sure that there's enough space in the device partition before
262 * storing something there.
264 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
265 abp->f_ffree = 2000000;
267 abp->f_fsid.val[0] = mp->mnt_stat.f_fsid.val[0];
268 abp->f_fsid.val[1] = mp->mnt_stat.f_fsid.val[1];
269 if (abp != &mp->mnt_stat) {
270 abp->f_type = mp->mnt_vfc->vfc_typenum;
271 memcpy((caddr_t) & abp->f_mntonname[0],
272 (caddr_t) mp->mnt_stat.f_mntonname, MNAMELEN);
273 memcpy((caddr_t) & abp->f_mntfromname[0],
274 (caddr_t) mp->mnt_stat.f_mntfromname, MNAMELEN);
282 afs_sync(mp, waitfor, cred, p)
291 u_int32_t afs_darwin_realmodes = 0;
293 int afs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
294 void *newp, size_t newlen, struct proc *p)
300 /* nothing defined */
306 case AFS_SC_DARWIN_ALL:
308 case AFS_SC_DARWIN_ALL_REALMODES:
309 return sysctl_int(oldp, oldlenp, newp, newlen,
310 &afs_darwin_realmodes);
313 /* darwin version specific sysctl's goes here */
321 extern int vfs_opv_numops; /* The total number of defined vnode operations */
322 extern struct vnodeopv_desc afs_vnodeop_opv_desc;
324 afs_init(struct vfsconf *vfc)
327 int (**opv_desc_vector) ();
328 struct vnodeopv_entry_desc *opve_descp;
332 MALLOC(afs_vnodeop_p, PFI *, vfs_opv_numops * sizeof(PFI), M_TEMP,
335 memset(afs_vnodeop_p, 0, vfs_opv_numops * sizeof(PFI));
337 opv_desc_vector = afs_vnodeop_p;
338 for (j = 0; afs_vnodeop_opv_desc.opv_desc_ops[j].opve_op; j++) {
339 opve_descp = &(afs_vnodeop_opv_desc.opv_desc_ops[j]);
342 * Sanity check: is this operation listed
343 * in the list of operations? We check this
344 * by seeing if its offest is zero. Since
345 * the default routine should always be listed
346 * first, it should be the only one with a zero
347 * offset. Any other operation with a zero
348 * offset is probably not listed in
349 * vfs_op_descs, and so is probably an error.
351 * A panic here means the layer programmer
352 * has committed the all-too common bug
353 * of adding a new operation to the layer's
354 * list of vnode operations but
355 * not adding the operation to the system-wide
356 * list of supported operations.
358 if (opve_descp->opve_op->vdesc_offset == 0
359 && opve_descp->opve_op->vdesc_offset != VOFFSET(vop_default)) {
360 printf("afs_init: operation %s not listed in %s.\n",
361 opve_descp->opve_op->vdesc_name, "vfs_op_descs");
362 panic("load_afs: bad operation");
365 * Fill in this entry.
367 opv_desc_vector[opve_descp->opve_op->vdesc_offset] =
368 opve_descp->opve_impl;
372 * Finally, go back and replace unfilled routines
373 * with their default. (Sigh, an O(n^3) algorithm. I
374 * could make it better, but that'd be work, and n is small.)
378 * Force every operations vector to have a default routine.
380 opv_desc_vector = afs_vnodeop_p;
381 if (opv_desc_vector[VOFFSET(vop_default)] == NULL) {
382 panic("afs_init: operation vector without default routine.");
384 for (j = 0; j < vfs_opv_numops; j++)
385 if (opv_desc_vector[j] == NULL)
386 opv_desc_vector[j] = opv_desc_vector[VOFFSET(vop_default)];
389 struct vfsops afs_vfsops = {