]>
The Tcpdump Group git mirrors - tcpdump/blob - parsenfsfh.c
2 * parsenfsfh.c - portable parser for NFS file handles
3 * uses all sorts of heuristics
6 * Digital Equipment Corporation
7 * Western Research Laboratory
11 static const char rcsid
[] =
12 "@(#) $Header: /tcpdump/master/tcpdump/parsenfsfh.c,v 1.16 1999-11-21 09:36:47 fenner Exp $ (LBL)";
19 #include <sys/types.h>
29 #include "interface.h"
33 * This routine attempts to parse a file handle (in network byte order),
34 * using heuristics to guess what kind of format it is in. See the
35 * file "fhandle_layouts" for a detailed description of the various
36 * patterns we know about.
38 * The file handle is parsed into our internal representation of a
39 * file-system id, and an internal representation of an inode-number.
56 /* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */
57 #define XFF(x) ((u_int32_t)(x))
62 #define make_uint32(msb,b,c,lsb)\
63 (XFF(lsb) + (XFF(c)<<8) + (XFF(b)<<16) + (XFF(msb)<<24))
65 #define make_uint24(msb,b, lsb)\
66 (XFF(lsb) + (XFF(b)<<8) + (XFF(msb)<<16))
68 #define make_uint16(msb,lsb)\
69 (XFF(lsb) + (XFF(msb)<<8))
72 /* or other 64-bit systems */
73 #define make_uint48(msb,b,c,d,e,lsb)\
74 ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24) + ((b)<<32) + ((msb)<<40))
76 /* on 32-bit systems ignore high-order bits */
77 #define make_uint48(msb,b,c,d,e,lsb)\
78 ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24))
81 static int is_UCX(unsigned char *);
84 Parse_fh(fh
, len
, fsidp
, inop
, osnamep
, fsnamep
, ourself
)
89 char **osnamep
; /* if non-NULL, return OS name here */
90 char **fsnamep
; /* if non-NULL, return server fs name here (for VMS) */
91 int ourself
; /* true if file handle was generated on this host */
93 register unsigned char *fhp
= (unsigned char *)fh
;
95 int fhtype
= FHT_UNKNOWN
;
98 /* File handle generated on this host, no need for guessing */
122 * This is basically a big decision tree
124 else if ((fhp
[0] == 0) && (fhp
[1] == 0)) {
125 /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */
126 /* probably rules out HP-UX, AIX unless they allow major=0 */
127 if ((fhp
[2] == 0) && (fhp
[3] == 0)) {
128 /* bytes[2,3] == (0,0); must be Auspex */
129 /* XXX or could be Ultrix+MASSBUS "hp" disk? */
134 * bytes[2,3] != (0,0); rules out Auspex, could be
135 * DECOSF, SUNOS4, or IRIX4
137 if ((fhp
[4] != 0) && (fhp
[5] == 0) &&
138 (fhp
[8] == 12) && (fhp
[9] == 0)) {
139 /* seems to be DECOSF, with minor == 0 */
143 /* could be SUNOS4 or IRIX4 */
144 /* XXX the test of fhp[5] == 8 could be wrong */
145 if ((fhp
[4] == 0) && (fhp
[5] == 8) && (fhp
[6] == 0) &&
147 /* looks like a length, not a file system typecode */
159 * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4
160 * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5
161 * could be AIX, HP-UX
163 if ((fhp
[2] == 0) && (fhp
[3] == 0)) {
165 * bytes[2,3] == (0,0); rules out OSF, probably not UCX
166 * (unless the exported device name is just one letter!),
167 * could be Ultrix, IRIX5, AIX, or SUNOS5
168 * might be HP-UX (depends on their values for minor devs)
170 /*XXX we probably only need to test of these two bytes */
171 if ((fhp
[21] == 0) && (fhp
[23] == 0)) {
175 /* Could be SUNOS5/IRIX5, maybe AIX */
176 /* XXX no obvious difference between SUNOS5 and IRIX5 */
179 /* XXX what about AIX? */
184 * bytes[2,3] != (0,0); rules out Ultrix, could be
185 * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX
187 if ((fhp
[8] == 12) && (fhp
[9] == 0)) {
190 else if ((fhp
[8] == 0) && (fhp
[9] == 10)) {
191 /* could be SUNOS5/IRIX5, AIX, HP-UX */
192 if ((fhp
[7] == 0) && (fhp
[6] == 0) &&
193 (fhp
[5] == 0) && (fhp
[4] == 0)) {
194 /* XXX is this always true of HP-UX? */
197 else if (fhp
[7] == 2) {
198 /* This would be MNT_NFS on AIX, which is impossible */
199 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
203 * XXX Could be SUNOS5/IRIX5 or AIX. I don't
204 * XXX see any way to disambiguate these, so
205 * XXX I'm going with the more likely guess.
206 * XXX Sorry, Big Blue.
208 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
216 fhtype
= FHT_UNKNOWN
;
222 /* XXX still needs to handle SUNOS3 */
226 fsidp
->Fsid_dev
.Minor
= fhp
[7];
227 fsidp
->Fsid_dev
.Major
= fhp
[6];
228 fsidp
->fsid_code
= 0;
230 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
238 fsidp
->fsid_code
= make_uint32(fhp
[7], fhp
[6], fhp
[5], fhp
[4]);
239 /* XXX could ignore 3 high-order bytes */
241 temp
= make_uint32(fhp
[3], fhp
[2], fhp
[1], fhp
[0]);
242 fsidp
->Fsid_dev
.Minor
= temp
& 0xFFFFF;
243 fsidp
->Fsid_dev
.Major
= (temp
>>20) & 0xFFF;
245 temp
= make_uint32(fhp
[15], fhp
[14], fhp
[13], fhp
[12]);
252 fsidp
->Fsid_dev
.Minor
= fhp
[3];
253 fsidp
->Fsid_dev
.Major
= fhp
[2];
254 fsidp
->fsid_code
= 0;
256 temp
= make_uint32(fhp
[8], fhp
[9], fhp
[10], fhp
[11]);
264 fsidp
->Fsid_dev
.Minor
= make_uint16(fhp
[2], fhp
[3]);
265 fsidp
->Fsid_dev
.Major
= make_uint16(fhp
[0], fhp
[1]);
266 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
268 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
281 fsidp
->Fsid_dev
.Minor
= fhp
[3];
282 fsidp
->Fsid_dev
.Major
= fhp
[2];
283 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
285 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
293 temp
= make_uint16(fhp
[0], fhp
[1]);
294 fsidp
->Fsid_dev
.Major
= (temp
>>2) & 0x3FFF;
295 temp
= make_uint24(fhp
[1], fhp
[2], fhp
[3]);
296 fsidp
->Fsid_dev
.Minor
= temp
& 0x3FFFF;
297 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
299 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
307 fsidp
->fsid_code
= 0;
308 fsidp
->Fsid_dev
.Minor
= fhp
[0];
309 fsidp
->Fsid_dev
.Major
= fhp
[1];
311 temp
= make_uint32(fhp
[7], fhp
[6], fhp
[5], fhp
[4]);
318 /* No numeric file system ID, so hash on the device-name */
319 if (sizeof(*fsidp
) >= 14) {
320 if (sizeof(*fsidp
) > 14)
321 memset((char *)fsidp
, 0, sizeof(*fsidp
));
322 /* just use the whole thing */
323 memcpy((char *)fsidp
, (char *)fh
, 14);
326 u_int32_t tempa
[4]; /* at least 16 bytes, maybe more */
328 memset((char *)tempa
, 0, sizeof(tempa
));
329 memcpy((char *)tempa
, (char *)fh
, 14); /* ensure alignment */
330 fsidp
->Fsid_dev
.Minor
= tempa
[0] + (tempa
[1]<<1);
331 fsidp
->Fsid_dev
.Major
= tempa
[2] + (tempa
[3]<<1);
332 fsidp
->fsid_code
= 0;
335 /* VMS file ID is: (RVN, FidHi, FidLo) */
336 *inop
= make_uint32(fhp
[26], fhp
[27], fhp
[23], fhp
[22]);
338 /* Caller must save (and null-terminate?) this value */
340 *fsnamep
= (char *)&(fhp
[1]);
347 fsidp
->Fsid_dev
.Minor
= make_uint16(fhp
[2], fhp
[3]);
348 fsidp
->Fsid_dev
.Major
= make_uint16(fhp
[0], fhp
[1]);
349 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
351 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
359 fsidp
->Fsid_dev
.Major
= fhp
[0];
360 temp
= make_uint24(fhp
[1], fhp
[2], fhp
[3]);
361 fsidp
->Fsid_dev
.Minor
= temp
;
362 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
364 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
376 for (i
= 0; i
< 32; i
++)
377 (void)fprintf(stderr
, "%x.", fhp
[i
]);
378 (void)fprintf(stderr
, "\n");
381 /* XXX for now, give "bogus" values to aid debugging */
382 fsidp
->fsid_code
= 0;
383 fsidp
->Fsid_dev
.Minor
= 257;
384 fsidp
->Fsid_dev
.Major
= 257;
387 /* display will show this string instead of (257,257) */
389 *fsnamep
= "Unknown";
392 *osnamep
= "Unknown";
399 * Is this a VMS UCX file handle?
401 * (1) leading code byte [XXX not yet]
402 * (2) followed by string of printing chars & spaces
403 * (3) followed by string of nulls
412 for (i
= 1; i
< 14; i
++) {
413 if (isprint(fhp
[i
])) {
419 else if (fhp
[i
] == 0) {