afs: Clarify vcache->mvid accesses
[openafs.git] / src / afs / VNOPS / afs_vnop_readdir.c
index f0572b9..7892982 100644 (file)
@@ -249,7 +249,7 @@ afs_readdir_type(struct vcache *avc, struct DirEntry *ade)
     ObtainReadLock(&afs_xvcache);
     if ((tvc = afs_FindVCache(&tfid, 0, 0))) {
         ReleaseReadLock(&afs_xvcache);
-       if (tvc->mvstat) {
+       if (tvc->mvstat != AFS_MVSTAT_FILE) {
            afs_PutVCache(tvc);
            return DT_DIR;
        } else if (((tvc->f.states) & (CStatd | CTruth))) {
@@ -262,7 +262,7 @@ afs_readdir_type(struct vcache *avc, struct DirEntry *ade)
            else if (vtype == VREG)
                return DT_REG;
            /* Don't do this until we're sure it can't be a mtpt */
-           /* if we're CStatd and CTruth and mvstat==0, it's a link */
+           /* if we're CStatd and CTruth and mvstat==AFS_MVSTAT_FILE, it's a link */
            else if (vtype == VLNK)
                return DT_LNK;
            /* what other types does AFS support? */
@@ -319,7 +319,7 @@ afs_readdir_move(struct DirEntry *de, struct vcache *vc, struct uio *auio,
        if (!FidCmp(&afs_rootFid, &vc->f.fid)) {
            Volume = 0;
            Vnode  = 2;
-       } else if (vc->mvstat == 2) {
+       } else if (vc->mvstat == AFS_MVSTAT_ROOT) {
            tvp = afs_GetVolume(&vc->f.fid, 0, READ_LOCK);
            if (tvp) {
                Volume = tvp->mtpoint.Fid.Volume;
@@ -337,19 +337,19 @@ afs_readdir_move(struct DirEntry *de, struct vcache *vc, struct uio *auio,
            /* We are the root of the AFS root, and thus our own parent */
            Volume = 0;
            Vnode  = 2;
-       } else if (vc->mvstat == 2) {
+       } else if (vc->mvstat == AFS_MVSTAT_ROOT) {
            /* We are a volume root, which means our parent is in another
             * volume.  Luckily, we should have his fid cached... */
-           if (vc->mvid) {
-               if (!FidCmp(&afs_rootFid, vc->mvid)) {
+           if (vc->mvid.parent) {
+               if (!FidCmp(&afs_rootFid, vc->mvid.parent)) {
                    /* Parent directory is the root of the AFS root */
                    Volume = 0;
                    Vnode  = 2;
-               } else if (vc->mvid->Fid.Vnode == 1
-                          && vc->mvid->Fid.Unique == 1) {
+               } else if (vc->mvid.parent->Fid.Vnode == 1
+                          && vc->mvid.parent->Fid.Unique == 1) {
                    /* XXX The above test is evil and probably breaks DFS */
                    /* Parent directory is the target of a mount point */
-                   tvp = afs_GetVolume(vc->mvid, 0, READ_LOCK);
+                   tvp = afs_GetVolume(vc->mvid.parent, 0, READ_LOCK);
                    if (tvp) {
                        Volume = tvp->mtpoint.Fid.Volume;
                        Vnode  = tvp->mtpoint.Fid.Vnode;
@@ -357,8 +357,8 @@ afs_readdir_move(struct DirEntry *de, struct vcache *vc, struct uio *auio,
                    }
                } else {
                    /* Parent directory is not a volume root */
-                   Volume = vc->mvid->Fid.Volume;
-                   Vnode  = vc->mvid->Fid.Vnode;
+                   Volume = vc->mvid.parent->Fid.Volume;
+                   Vnode  = vc->mvid.parent->Fid.Vnode;
                }
            }
        } else if (de->fid.vnode == 1 && de->fid.vunique == 1) {
@@ -455,11 +455,7 @@ afs_readdir_move(struct DirEntry *de, struct vcache *vc, struct uio *auio,
     }
 #else /* AFS_SGI53_ENV */
 #if  defined(AFS_SUN5_ENV) || (defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL))
-#if    defined(AFS_SUN5_ENV)
-    direntp = (struct dirent64 *)osi_AllocLargeSpace(AFS_LRALLOCSIZ);
-#else
-    direntp = (struct dirent *)osi_AllocLargeSpace(AFS_LRALLOCSIZ);
-#endif
+    direntp = osi_AllocLargeSpace(AFS_LRALLOCSIZ);
     direntp->d_ino = afs_calc_inum(vc->f.fid.Cell, Volume, ntohl(Vnode));
 #if defined(AFS_AIX51_ENV) && defined(AFS_64BIT_KERNEL)
     direntp->d_offset = off;
@@ -584,7 +580,7 @@ afs_readdir(OSI_VC_DECL(avc), struct uio *auio, afs_ucred_t *acred)
 #endif
 #endif
 {
-    struct vrequest treq;
+    struct vrequest *treq = NULL;
     struct dcache *tdc;
     afs_size_t origOffset, tlen;
     afs_int32 len;
@@ -605,8 +601,7 @@ afs_readdir(OSI_VC_DECL(avc), struct uio *auio, afs_ucred_t *acred)
      * it is necessary for hpux due to stack problems that seem to occur when coming thru the nfs
      * translator side XXX
      */
-    struct min_direct *sdirEntry =
-       (struct min_direct *)osi_AllocSmallSpace(sizeof(struct min_direct));
+    struct min_direct *sdirEntry = osi_AllocSmallSpace(sizeof(struct min_direct));
     afs_int32 rlen;
 #endif
 
@@ -651,7 +646,7 @@ afs_readdir(OSI_VC_DECL(avc), struct uio *auio, afs_ucred_t *acred)
        return EFBIG;
 #endif
 
-    if ((code = afs_InitReq(&treq, acred))) {
+    if ((code = afs_CreateReq(&treq, acred))) {
 #ifdef AFS_HPUX_ENV
        osi_FreeSmallSpace((char *)sdirEntry);
 #endif
@@ -662,16 +657,15 @@ afs_readdir(OSI_VC_DECL(avc), struct uio *auio, afs_ucred_t *acred)
 
     AFS_DISCON_LOCK();
 
-    code = afs_EvalFakeStat(&avc, &fakestate, &treq);
+    code = afs_EvalFakeStat(&avc, &fakestate, treq);
     if (code)
        goto done;
   tagain:
-    code = afs_VerifyVCache(avc, &treq);
+    code = afs_VerifyVCache(avc, treq);
     if (code)
        goto done;
     /* get a reference to the entire directory */
-    tdc = afs_GetDCache(avc, (afs_size_t) 0, &treq, &origOffset, &tlen, 1);
-    len = tlen;
+    tdc = afs_GetDCache(avc, (afs_size_t) 0, treq, &origOffset, &tlen, 1);
     if (!tdc) {
        code = ENOENT;
        goto done;
@@ -914,6 +908,7 @@ afs_readdir(OSI_VC_DECL(avc), struct uio *auio, afs_ucred_t *acred)
 #endif /* AFS_SGI53_ENV */
        
        DRelease(&oldEntry, 0);
+       oldEntry = nextEntry;
        ode = nde;
        AFS_UIO_SETOFFSET(auio, (afs_int32) ((us + afs_dir_NameBlobs(nde->name)) << 5));
     }
@@ -931,7 +926,8 @@ afs_readdir(OSI_VC_DECL(avc), struct uio *auio, afs_ucred_t *acred)
 #endif
     AFS_DISCON_UNLOCK();
     afs_PutFakeStat(&fakestate);
-    code = afs_CheckCode(code, &treq, 28);
+    code = afs_CheckCode(code, treq, 28);
+    afs_DestroyReq(treq);
     return code;
 }