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 #ifndef AFS_DARWIN80_ENV
17 #include <sys/syscall.h>
19 #include <sys/sysctl.h>
20 #include "../afs/sysctl.h"
23 #define M_UFSMNT M_TEMP /* DARWIN80 MALLOC doesn't look at the type anyway */
26 struct vcache *afs_globalVp = 0;
27 struct mount *afs_globalVFS = 0;
37 afs_fhtovp(mp, fhp, vpp)
55 #ifdef AFS_DARWIN80_ENV
56 #define CTX_TYPE vfs_context_t
57 #define CTX_PROC_CONVERT(C) vfs_context_proc((C))
58 #define STATFS_TYPE struct vfsstatfs
60 #define CTX_TYPE struct proc *
61 #define CTX_PROC_CONVERT(C) (C)
62 #define STATFS_TYPE struct statfs
63 #define vfs_statfs(VFS) &(VFS)->mnt_stat
65 #define PROC_DECL(out,in) struct proc *out = CTX_PROC_CONVERT(in)
68 afs_start(mp, flags, p)
73 return (0); /* nothing to do. ? */
77 afs_statfs(struct mount *mp, STATFS_TYPE *abp, CTX_TYPE ctx);
78 #ifdef AFS_DARWIN80_ENV
80 afs_mount(mp, devvp, data, ctx)
81 register struct mount *mp;
87 afs_mount(mp, path, data, ndp, ctx)
88 register struct mount *mp;
91 struct nameidata *ndp;
95 /* ndp contains the mounted-from device. Just ignore it.
96 * we also don't care about our proc struct. */
99 #ifdef AFS_DARWIN80_ENV
100 struct vfsioattr ioattr;
101 /* vfs_statfs advertised as RO, but isn't */
102 /* new api will be needed to initialize this information (nfs needs to
103 set mntfromname too) */
105 STATFS_TYPE *mnt_stat = vfs_statfs(mp);
107 if (vfs_isupdate(mp))
111 AFS_STATCNT(afs_mount);
113 if (data == 0 && afs_globalVFS) { /* Don't allow remounts. */
119 #ifdef AFS_DARWIN80_ENV
120 vfs_ioattr(mp, &ioattr);
121 ioattr.io_devblocksize = 8192;
122 vfs_setioattr(mp, &ioattr);
123 /* f_iosize is handled in VFS_GETATTR */
125 mp->vfs_bsize = 8192;
126 mp->mnt_stat.f_iosize = 8192;
130 #ifndef AFS_DARWIN80_ENV
131 (void)copyinstr(path, mp->mnt_stat.f_mntonname, MNAMELEN - 1, &size);
132 memset(mp->mnt_stat.f_mntonname + size, 0, MNAMELEN - size);
134 memset(mnt_stat->f_mntfromname, 0, MNAMELEN);
137 strcpy(mnt_stat->f_mntfromname, "AFS");
138 /* null terminated string "AFS" will fit, just leave it be. */
139 vfs_setfsprivate(mp, NULL);
141 struct VenusFid *rootFid = NULL;
143 char volName[MNAMELEN];
145 (void)copyinstr(data, volName, MNAMELEN - 1, &size);
146 memset(volName + size, 0, MNAMELEN - size);
148 if (volName[0] == 0) {
149 strcpy(mnt_stat->f_mntfromname, "AFS");
150 vfs_setfsprivate(mp, &afs_rootFid);
152 struct cell *localcell = afs_GetPrimaryCell(READ_LOCK);
153 if (localcell == NULL) {
158 /* Set the volume identifier to "AFS:volume.name" */
159 snprintf(mnt_stat->f_mntfromname, MNAMELEN - 1, "AFS:%s",
162 afs_GetVolumeByName(volName, localcell->cellNum, 1,
163 (struct vrequest *)0, READ_LOCK);
166 int volid = (tvp->roVol ? tvp->roVol : tvp->volume);
167 MALLOC(rootFid, struct VenusFid *, sizeof(*rootFid), M_UFSMNT,
169 rootFid->Cell = localcell->cellNum;
170 rootFid->Fid.Volume = volid;
171 rootFid->Fid.Vnode = 1;
172 rootFid->Fid.Unique = 1;
178 vfs_setfsprivate(mp, &rootFid);
181 #ifdef AFS_DARWIN80_ENV
182 afs_vfs_typenum=vfs_typenum(mp);
183 vfs_setauthopaque(mp);
184 vfs_setauthopaqueaccess(mp);
186 strcpy(mp->mnt_stat.f_fstypename, "afs");
189 (void)afs_statfs(mp, mnt_stat, ctx);
194 afs_unmount(mp, flags, ctx)
199 void *mdata = vfs_fsprivate(mp);
201 AFS_STATCNT(afs_unmount);
203 if (mdata != (qaddr_t) - 1) {
205 vfs_setfsprivate(mp, (qaddr_t) - 1);
206 FREE(mdata, M_UFSMNT);
208 if (flags & MNT_FORCE) {
210 #ifdef AFS_DARWIN80_ENV
211 afs_PutVCache(afs_globalVp);
214 vrele(AFSTOV(afs_globalVp));
220 vflush(mp, NULLVP, FORCECLOSE/*0*/);
229 vfs_clearflags(mp, MNT_LOCAL);
237 #ifdef AFS_DARWIN80_ENV
239 afs_root(struct mount *mp, struct vnode **vpp, vfs_context_t ctx)
242 afs_root(struct mount *mp, struct vnode **vpp)
245 void *mdata = vfs_fsprivate(mp);
247 struct vrequest treq;
248 register struct vcache *tvp = 0;
249 #ifdef AFS_DARWIN80_ENV
250 struct ucred *cr = vfs_context_ucred(ctx);
253 struct proc *p = current_proc();
255 struct ucred *cr = &_cr;
258 _cr = *p->p_cred->pc_ucred;
262 AFS_STATCNT(afs_root);
263 if (mdata == NULL && afs_globalVp
264 && (afs_globalVp->states & CStatd)) {
267 #ifdef AFS_DARWIN80_ENV
270 } else if (mdata == (qaddr_t) - 1) {
273 struct VenusFid *rootFid = (mdata == NULL)
274 ? &afs_rootFid : (struct VenusFid *)mdata;
276 if (!(error = afs_InitReq(&treq, cr)) && !(error = afs_CheckInit())) {
277 tvp = afs_GetVCache(rootFid, &treq, NULL, NULL);
278 #ifdef AFS_DARWIN80_ENV
281 error = afs_darwin_finalizevnode(tvp, NULL, NULL, 1);
286 /* re-acquire the usecount that finalizevnode disposed of */
287 vnode_ref(AFSTOV(tvp));
290 /* we really want this to stay around */
294 afs_PutVCache(afs_globalVp);
298 #ifdef AFS_DARWIN80_ENV
307 #ifndef AFS_DARWIN80_ENV /* DARWIN80 caller does not need a usecount reference */
310 vn_lock(AFSTOV(tvp), LK_EXCLUSIVE | LK_RETRY, p);
313 #ifdef AFS_DARWIN80_ENV
314 if (needref) /* this iocount is for the caller. the initial iocount
315 is for the eventual afs_PutVCache. for mdata != null,
316 there will not be a PutVCache, so the caller gets the
317 initial (from GetVCache or finalizevnode) iocount*/
318 vnode_get(AFSTOV(tvp));
324 #ifndef AFS_DARWIN80_ENV
325 AFSTOV(tvp)->v_flag |= VROOT;
326 AFSTOV(tvp)->v_vfsp = mp;
330 afs_Trace2(afs_iclSetp, CM_TRACE_VFSROOT, ICL_TYPE_POINTER, *vpp,
331 ICL_TYPE_INT32, error);
336 #ifndef AFS_DARWIN80_ENV /* vget vfsop never had this prototype AFAIK */
338 afs_vget(mp, lfl, vp)
344 //printf("vget called. help!\n");
345 if (vp->v_usecount < 0) {
346 vprint("bad usecount", vp);
349 error = vget(vp, lfl, current_proc());
351 insmntque(vp, mp); /* take off free list */
355 int afs_vfs_vget(struct mount *mp, void *ino, struct vnode **vpp)
357 return ENOENT; /* cannot implement */
363 afs_statfs(struct mount *mp, STATFS_TYPE *abp, CTX_TYPE ctx)
365 STATFS_TYPE *sysstat = vfs_statfs(mp);
367 AFS_STATCNT(afs_statfs);
370 abp->f_type = MOUNT_AFS;
372 #ifdef AFS_DARWIN80_ENV
373 abp->f_bsize = abp->f_iosize = vfs_devblocksize(mp);
375 abp->f_bsize = mp->vfs_bsize;
376 abp->f_iosize = mp->vfs_bsize;
379 /* Fake a high number below to satisfy programs that use the statfs call
380 * to make sure that there's enough space in the device partition before
381 * storing something there.
383 abp->f_blocks = abp->f_bfree = abp->f_bavail = abp->f_files =
384 abp->f_ffree = 2000000;
386 if (abp != sysstat) {
387 abp->f_fsid.val[0] = sysstat->f_fsid.val[0];
388 abp->f_fsid.val[1] = sysstat->f_fsid.val[1];
389 #ifndef AFS_DARWIN80_ENV
390 abp->f_type = vfs_typenum(mp);
392 memcpy((caddr_t) & abp->f_mntonname[0],
393 (caddr_t) sysstat->f_mntonname, MNAMELEN);
394 memcpy((caddr_t) & abp->f_mntfromname[0],
395 (caddr_t) sysstat->f_mntfromname, MNAMELEN);
402 #ifdef AFS_DARWIN80_ENV
404 afs_vfs_getattr(struct mount *mp, struct vfs_attr *outattrs,
405 vfs_context_t context)
407 VFSATTR_RETURN(outattrs, f_bsize, vfs_devblocksize(mp));
408 VFSATTR_RETURN(outattrs, f_iosize, vfs_devblocksize(mp));
409 VFSATTR_RETURN(outattrs, f_blocks, 2000000);
410 VFSATTR_RETURN(outattrs, f_bfree, 2000000);
411 VFSATTR_RETURN(outattrs, f_bavail, 2000000);
412 VFSATTR_RETURN(outattrs, f_files, 2000000);
413 VFSATTR_RETURN(outattrs, f_ffree, 2000000);
414 if ( VFSATTR_IS_ACTIVE(outattrs, f_capabilities) )
416 vol_capabilities_attr_t *vcapattrptr;
417 vcapattrptr = &outattrs->f_capabilities;
418 vcapattrptr->capabilities[VOL_CAPABILITIES_FORMAT] =
419 VOL_CAP_FMT_SYMBOLICLINKS |
420 VOL_CAP_FMT_HARDLINKS |
421 VOL_CAP_FMT_ZERO_RUNS |
422 VOL_CAP_FMT_CASE_SENSITIVE |
423 VOL_CAP_FMT_CASE_PRESERVING |
424 VOL_CAP_FMT_FAST_STATFS;
425 vcapattrptr->capabilities[VOL_CAPABILITIES_INTERFACES] =
426 VOL_CAP_INT_ADVLOCK |
428 vcapattrptr->capabilities[VOL_CAPABILITIES_RESERVED1] = 0;
429 vcapattrptr->capabilities[VOL_CAPABILITIES_RESERVED2] = 0;
431 /* Capabilities we know about: */
432 vcapattrptr->valid[VOL_CAPABILITIES_FORMAT] =
433 VOL_CAP_FMT_PERSISTENTOBJECTIDS |
434 VOL_CAP_FMT_SYMBOLICLINKS |
435 VOL_CAP_FMT_HARDLINKS |
436 VOL_CAP_FMT_JOURNAL |
437 VOL_CAP_FMT_JOURNAL_ACTIVE |
438 VOL_CAP_FMT_NO_ROOT_TIMES |
439 VOL_CAP_FMT_SPARSE_FILES |
440 VOL_CAP_FMT_ZERO_RUNS |
441 VOL_CAP_FMT_CASE_SENSITIVE |
442 VOL_CAP_FMT_CASE_PRESERVING |
443 VOL_CAP_FMT_FAST_STATFS;
444 vcapattrptr->valid[VOL_CAPABILITIES_INTERFACES] =
445 VOL_CAP_INT_SEARCHFS |
446 VOL_CAP_INT_ATTRLIST |
447 VOL_CAP_INT_NFSEXPORT |
448 VOL_CAP_INT_READDIRATTR |
449 VOL_CAP_INT_EXCHANGEDATA |
450 VOL_CAP_INT_COPYFILE |
451 VOL_CAP_INT_ALLOCATE |
452 VOL_CAP_INT_VOL_RENAME |
453 VOL_CAP_INT_ADVLOCK |
455 vcapattrptr->valid[VOL_CAPABILITIES_RESERVED1] = 0;
456 vcapattrptr->valid[VOL_CAPABILITIES_RESERVED2] = 0;
458 VFSATTR_SET_SUPPORTED(outattrs, f_capabilities);
464 #ifdef AFS_DARWIN80_ENV
466 afs_sync(mp, waitfor, ctx)
472 afs_sync(mp, waitfor, cred, p)
482 u_int32_t afs_darwin_realmodes = 0;
484 #ifdef AFS_DARWIN80_ENV
485 int afs_sysctl(int *name, u_int namelen, user_addr_t oldp, size_t *oldlenp,
486 user_addr_t newp, size_t newlen, vfs_context_t context)
488 int afs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp,
489 void *newp, size_t newlen, struct proc *p)
496 /* nothing defined */
502 case AFS_SC_DARWIN_ALL:
504 case AFS_SC_DARWIN_ALL_REALMODES:
505 #ifdef AFS_DARWIN80_ENV
506 if (oldp != USER_ADDR_NULL && oldlenp == NULL)
508 if (oldp && *oldlenp < sizeof(u_int32_t))
510 if (newp && newlen != sizeof(u_int32_t))
512 *oldlenp = sizeof(u_int32_t);
514 if ((error = copyout(&afs_darwin_realmodes,
515 oldp, sizeof(u_int32_t)))) {
520 return copyin(newp, &afs_darwin_realmodes,
524 return sysctl_int(oldp, oldlenp, newp, newlen,
525 &afs_darwin_realmodes);
529 /* darwin version specific sysctl's goes here */
537 extern int vfs_opv_numops; /* The total number of defined vnode operations */
538 extern struct vnodeopv_desc afs_vnodeop_opv_desc;
540 afs_init(struct vfsconf *vfc)
542 #ifndef AFS_DARWIN80_ENV /* vfs_fsadd does all this junk */
544 int (**opv_desc_vector) ();
545 struct vnodeopv_entry_desc *opve_descp;
549 MALLOC(afs_vnodeop_p, PFI *, vfs_opv_numops * sizeof(PFI), M_TEMP,
552 memset(afs_vnodeop_p, 0, vfs_opv_numops * sizeof(PFI));
554 opv_desc_vector = afs_vnodeop_p;
555 for (j = 0; afs_vnodeop_opv_desc.opv_desc_ops[j].opve_op; j++) {
556 opve_descp = &(afs_vnodeop_opv_desc.opv_desc_ops[j]);
559 * Sanity check: is this operation listed
560 * in the list of operations? We check this
561 * by seeing if its offest is zero. Since
562 * the default routine should always be listed
563 * first, it should be the only one with a zero
564 * offset. Any other operation with a zero
565 * offset is probably not listed in
566 * vfs_op_descs, and so is probably an error.
568 * A panic here means the layer programmer
569 * has committed the all-too common bug
570 * of adding a new operation to the layer's
571 * list of vnode operations but
572 * not adding the operation to the system-wide
573 * list of supported operations.
575 if (opve_descp->opve_op->vdesc_offset == 0
576 && opve_descp->opve_op->vdesc_offset != VOFFSET(vop_default)) {
577 printf("afs_init: operation %s not listed in %s.\n",
578 opve_descp->opve_op->vdesc_name, "vfs_op_descs");
579 panic("load_afs: bad operation");
582 * Fill in this entry.
584 opv_desc_vector[opve_descp->opve_op->vdesc_offset] =
585 opve_descp->opve_impl;
589 * Finally, go back and replace unfilled routines
590 * with their default. (Sigh, an O(n^3) algorithm. I
591 * could make it better, but that'd be work, and n is small.)
595 * Force every operations vector to have a default routine.
597 opv_desc_vector = afs_vnodeop_p;
598 if (opv_desc_vector[VOFFSET(vop_default)] == NULL) {
599 panic("afs_init: operation vector without default routine.");
601 for (j = 0; j < vfs_opv_numops; j++)
602 if (opv_desc_vector[j] == NULL)
603 opv_desc_vector[j] = opv_desc_vector[VOFFSET(vop_default)];
608 struct vfsops afs_vfsops = {
613 #ifdef AFS_DARWIN80_ENV
621 #ifdef AFS_DARWIN80_ENV
630 #ifdef AFS_DARWIN80_ENV