support-dux-51-20010305
[openafs.git] / src / afs / afs_osi_vget.c
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 /*
11  * System independent part of vget VFS call.
12  */
13
14 #include "../afs/param.h"       /* Should be always first */
15 #include "../afs/sysincludes.h" /* Standard vendor system headers */
16 #include "../afs/afsincludes.h" /* Afs-based standard headers */
17 #include "../afs/afs_stats.h"   /* statistics stuff */
18
19
20
21 extern int afs_NFSRootOnly;
22 int afs_rootCellIndex = 0;
23 #if !defined(AFS_LINUX20_ENV)
24 /* This is the common part of the vget VFS call. */
25 int afs_osi_vget(struct vcache **avcpp, struct fid *afidp,
26                  struct vrequest *areqp)
27 {
28     struct VenusFid vfid;
29     struct SmallFid Sfid;
30     extern struct cell *afs_GetCellByIndex();
31     register struct cell *tcell;
32     struct vrequest treq;
33     register afs_int32 code = 0, cellindex;
34     afs_int32 ret;
35
36     bcopy(afidp->fid_data, (char *)&Sfid, SIZEOF_SMALLFID);
37 #ifdef AFS_OSF_ENV
38     Sfid.Vnode = afidp->fid_reserved;
39 #endif
40     if (afs_NFSRootOnly &&
41         Sfid.Volume == afs_rootFid.Fid.Volume &&
42         Sfid.Vnode == afs_rootFid.Fid.Vnode &&
43         (Sfid.CellAndUnique & 0xffffff) ==
44         (afs_rootFid.Fid.Unique & 0xffffff) &&
45         ((Sfid.CellAndUnique >> 24) & 0xff) == afs_rootCellIndex) {
46         vfid = afs_rootFid;
47     }
48     else {
49         /* Need to extract fid from SmallFid. Will need a wild card option for
50          * finding the right vcache entry.
51          */
52         struct cell *tcell;
53         cellindex = (Sfid.CellAndUnique >> 24) & 0xff;
54         tcell = afs_GetCellByIndex(cellindex, READ_LOCK);
55         if (!tcell) {
56             return ENOENT;
57         }
58         vfid.Cell = tcell->cell;
59         afs_PutCell(tcell, WRITE_LOCK);
60         vfid.Fid.Volume = Sfid.Volume;
61         vfid.Fid.Vnode = Sfid.Vnode;
62         vfid.Fid.Unique = Sfid.CellAndUnique & 0xffffff;
63     }
64
65
66     /* First attempt to find in cache using wildcard. If that fails,
67      * try the usual route to try to get the vcache from the server.
68      * This could be done better by splitting out afs_FindVCache from
69      * afs_GetVCache.
70      */
71
72     ret = afs_NFSFindVCache(avcpp, &vfid, 1);
73     if (ret > 1) {
74         /* More than one entry matches. */
75         code = ENOENT;
76     }
77     else if (ret == 0) {
78         /* didn't find an entry. */
79         *avcpp = afs_GetVCache(&vfid, &treq, (afs_int32 *)0, (struct vcache*)0, 0);
80     }
81     if (! *avcpp) {
82         code = ENOENT;
83     }
84
85     return code;
86 }
87 #endif /* AFS_LINUX20_ENV */