include-afsconfig-before-param-h-20010712
[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 <afsconfig.h>
15 #include "../afs/param.h"
16
17 RCSID("$Header$");
18
19 #include "../afs/sysincludes.h" /* Standard vendor system headers */
20 #include "../afs/afsincludes.h" /* Afs-based standard headers */
21 #include "../afs/afs_stats.h"   /* statistics stuff */
22
23
24
25 extern int afs_NFSRootOnly;
26 int afs_rootCellIndex = 0;
27 #if !defined(AFS_LINUX20_ENV)
28 /* This is the common part of the vget VFS call. */
29 int afs_osi_vget(struct vcache **avcpp, struct fid *afidp,
30                  struct vrequest *areqp)
31 {
32     struct VenusFid vfid;
33     struct SmallFid Sfid;
34     extern struct cell *afs_GetCellByIndex();
35     register struct cell *tcell;
36     struct vrequest treq;
37     register afs_int32 code = 0, cellindex;
38     afs_int32 ret;
39
40     bcopy(afidp->fid_data, (char *)&Sfid, SIZEOF_SMALLFID);
41 #ifdef AFS_OSF_ENV
42     Sfid.Vnode = afidp->fid_reserved;
43 #endif
44     if (afs_NFSRootOnly &&
45         Sfid.Volume == afs_rootFid.Fid.Volume &&
46         Sfid.Vnode == afs_rootFid.Fid.Vnode &&
47         (Sfid.CellAndUnique & 0xffffff) ==
48         (afs_rootFid.Fid.Unique & 0xffffff) &&
49         ((Sfid.CellAndUnique >> 24) & 0xff) == afs_rootCellIndex) {
50         vfid = afs_rootFid;
51     }
52     else {
53         /* Need to extract fid from SmallFid. Will need a wild card option for
54          * finding the right vcache entry.
55          */
56         struct cell *tcell;
57         cellindex = (Sfid.CellAndUnique >> 24) & 0xff;
58         tcell = afs_GetCellByIndex(cellindex, READ_LOCK);
59         if (!tcell) {
60             return ENOENT;
61         }
62         vfid.Cell = tcell->cell;
63         afs_PutCell(tcell, WRITE_LOCK);
64         vfid.Fid.Volume = Sfid.Volume;
65         vfid.Fid.Vnode = Sfid.Vnode;
66         vfid.Fid.Unique = Sfid.CellAndUnique & 0xffffff;
67     }
68
69
70     /* First attempt to find in cache using wildcard. If that fails,
71      * try the usual route to try to get the vcache from the server.
72      * This could be done better by splitting out afs_FindVCache from
73      * afs_GetVCache.
74      */
75
76     ret = afs_NFSFindVCache(avcpp, &vfid, 1);
77     if (ret > 1) {
78         /* More than one entry matches. */
79         code = ENOENT;
80     }
81     else if (ret == 0) {
82         /* didn't find an entry. */
83         *avcpp = afs_GetVCache(&vfid, &treq, (afs_int32 *)0, (struct vcache*)0, 0);
84     }
85     if (! *avcpp) {
86         code = ENOENT;
87     }
88
89     return code;
90 }
91 #endif /* AFS_LINUX20_ENV */