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