Remove the RCSID macro
[openafs.git] / src / afs / VNOPS / afs_vnop_fid.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  * Implements:
12  * afs_fid
13  *
14  * afs_vptofh (DUX) is now in DUX/osi_vfsops.c
15  */
16
17 #include <afsconfig.h>
18 #include "afs/param.h"
19
20
21 #if !defined(AFS_DUX40_ENV) && !defined(AFS_LINUX20_ENV) && !defined(AFS_DARWIN_ENV) && !defined(AFS_OBSD_ENV)
22 #include "afs/sysincludes.h"    /* Standard vendor system headers */
23 #include "afsincludes.h"        /* Afs-based standard headers */
24 #include "afs/afs_stats.h"      /* statistics */
25 #include "afs/afs_cbqueue.h"
26 #include "afs/nfsclient.h"
27 #include "afs/afs_osidnlc.h"
28
29
30
31 int afs_fid_vnodeoverflow = 0, afs_fid_uniqueoverflow = 0;
32
33 /*
34  *  afs_fid
35  * 
36  * afs_fid can return two flavors of NFS fid, depending on if submounts are
37  * allowed. The reason for this is that we can't guarantee that we found all 
38  * the entry points any OS might use to get the fid for the NFS mountd.
39  * Hence we return a "magic" fid for all but /afs. If it goes through the
40  * translator code, it will get transformed into a SmallFid that we recognize.
41  * So, if submounts are disallowed, and an NFS client tries a submount, it will
42  * get a fid which we don't recognize and the mount will either fail or we
43  * will ignore subsequent requests for that mount.
44  *
45  * The Alpha fid is organized differently than for other platforms. Their
46  * intention was to have the data portion of the fid aligned on a 4 byte
47  * boundary. To do so, the fid is organized as:
48  * u_short reserved
49  * u_short len
50  * char data[8]
51  * The len field is the length of the entire fid, from reserved through data.
52  * This length is used by fid_copy to include copying the reserved field. 
53  * Alpha's zero the reserved field before handing us the fid, but they use
54  * it in fid_cmp. We use the reserved field to store the 16 bits of the Vnode.
55  *
56  * Note that the SmallFid only allows for 8 bits of the cell index and
57  * 16 bits of the vnode. 
58  */
59
60 #ifdef AFS_AIX41_ENV
61 int afs_iauth_initd = 0;
62 #define USE_SMALLFID(C) (afs_iauth_initd && AFS_NFSXLATORREQ(C))
63 #endif
64
65
66 extern int afs_NFSRootOnly;     /* 1 => only allow NFS mounts of /afs. */
67
68 #if !defined(AFS_ATHENA_ENV)
69 int
70 #ifdef AFS_AIX41_ENV
71 afs_fid(OSI_VC_DECL(avc), struct fid *fidpp, struct ucred *credp)
72 #elif defined(AFS_OSF_ENV) || defined(AFS_SUN54_ENV)
73 afs_fid(OSI_VC_DECL(avc), struct fid *fidpp)
74 #else
75 afs_fid(OSI_VC_DECL(avc), struct fid **fidpp)
76 #endif                          /* AFS_AIX41_ENV */
77 {
78     struct SmallFid Sfid;
79     long addr[2];
80     register struct cell *tcell;
81     extern struct vcache *afs_globalVp;
82     int SizeOfSmallFid = SIZEOF_SMALLFID;
83     int rootvp = 0;
84     OSI_VC_CONVERT(avc);
85
86     AFS_STATCNT(afs_fid);
87
88     if (afs_shuttingdown)
89         return EIO;
90
91     if (afs_NFSRootOnly && (avc == afs_globalVp))
92         rootvp = 1;
93     if (!afs_NFSRootOnly || rootvp
94 #ifdef AFS_AIX41_ENV
95         || USE_SMALLFID(credp)
96 #endif
97         ) {
98         tcell = afs_GetCell(avc->f.fid.Cell, READ_LOCK);
99         Sfid.Volume = avc->f.fid.Fid.Volume;
100         Sfid.Vnode = avc->f.fid.Fid.Vnode;
101         Sfid.CellAndUnique =
102             ((tcell->cellIndex << 24) + (avc->f.fid.Fid.Unique & 0xffffff));
103         afs_PutCell(tcell, READ_LOCK);
104         if (avc->f.fid.Fid.Vnode > 0xffff)
105             afs_fid_vnodeoverflow++;
106         if (avc->f.fid.Fid.Unique > 0xffffff)
107             afs_fid_uniqueoverflow++;
108     } else {
109 #if defined(AFS_SUN57_64BIT_ENV) || (defined(AFS_SGI61_ENV) && (_MIPS_SZPTR == 64))
110         addr[1] = (long)AFS_XLATOR_MAGIC << 48;
111 #else /* defined(AFS_SGI61_ENV) && (_MIPS_SZPTR == 64) */
112         addr[1] = AFS_XLATOR_MAGIC;
113         SizeOfSmallFid = sizeof(addr);
114 #endif /* defined(AFS_SGI61_ENV) && (_MIPS_SZPTR == 64) */
115         addr[0] = (long)avc;
116 #ifndef AFS_AIX41_ENV
117         /* No post processing, so don't hold ref count. */
118         VN_HOLD(AFSTOV(avc));
119 #endif
120     }
121 #if     defined(AFS_AIX_ENV) || defined(AFS_SUN54_ENV)
122     /* Use the fid pointer passed to us. */
123     fidpp->fid_len = SizeOfSmallFid;
124
125     if (afs_NFSRootOnly) {
126         if (rootvp
127 #ifdef AFS_AIX41_ENV
128             || USE_SMALLFID(credp)
129 #endif
130             ) {
131             memcpy(fidpp->fid_data, (caddr_t) & Sfid, SizeOfSmallFid);
132         } else {
133             memcpy(fidpp->fid_data, (caddr_t) addr, SizeOfSmallFid);
134         }
135     } else {
136         memcpy(fidpp->fid_data, (caddr_t) & Sfid, SizeOfSmallFid);
137     }
138 #else
139     /* malloc a fid pointer ourselves. */
140     *fidpp = (struct fid *)AFS_KALLOC(SizeOfSmallFid + 2);
141     (*fidpp)->fid_len = SizeOfSmallFid;
142     if (afs_NFSRootOnly) {
143         if (rootvp) {
144             memcpy((*fidpp)->fid_data, (char *)&Sfid, SizeOfSmallFid);
145         } else {
146             memcpy((*fidpp)->fid_data, (char *)addr, SizeOfSmallFid);
147         }
148     } else {
149         memcpy((*fidpp)->fid_data, (char *)&Sfid, SizeOfSmallFid);
150     }
151 #endif
152     return (0);
153 }
154 #endif
155
156
157 #endif /* !AFS_DUX40_ENV && !AFS_LINUX20_ENV */