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