]>
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.14 1999-10-07 23:47:11 mcr Exp $ (LBL)";
15 #include <sys/types.h>
25 #include "interface.h"
29 * This routine attempts to parse a file handle (in network byte order),
30 * using heuristics to guess what kind of format it is in. See the
31 * file "fhandle_layouts" for a detailed description of the various
32 * patterns we know about.
34 * The file handle is parsed into our internal representation of a
35 * file-system id, and an internal representation of an inode-number.
52 /* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */
53 #define XFF(x) ((u_int32_t)(x))
58 #define make_uint32(msb,b,c,lsb)\
59 (XFF(lsb) + (XFF(c)<<8) + (XFF(b)<<16) + (XFF(msb)<<24))
61 #define make_uint24(msb,b, lsb)\
62 (XFF(lsb) + (XFF(b)<<8) + (XFF(msb)<<16))
64 #define make_uint16(msb,lsb)\
65 (XFF(lsb) + (XFF(msb)<<8))
68 /* or other 64-bit systems */
69 #define make_uint48(msb,b,c,d,e,lsb)\
70 ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24) + ((b)<<32) + ((msb)<<40))
72 /* on 32-bit systems ignore high-order bits */
73 #define make_uint48(msb,b,c,d,e,lsb)\
74 ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24))
77 static int is_UCX(unsigned char *);
80 Parse_fh(fh
, fsidp
, inop
, osnamep
, fsnamep
, ourself
)
84 char **osnamep
; /* if non-NULL, return OS name here */
85 char **fsnamep
; /* if non-NULL, return server fs name here (for VMS) */
86 int ourself
; /* true if file handle was generated on this host */
88 register unsigned char *fhp
= (unsigned char *)fh
;
90 int fhtype
= FHT_UNKNOWN
;
93 /* File handle generated on this host, no need for guessing */
117 * This is basically a big decision tree
119 else if ((fhp
[0] == 0) && (fhp
[1] == 0)) {
120 /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */
121 /* probably rules out HP-UX, AIX unless they allow major=0 */
122 if ((fhp
[2] == 0) && (fhp
[3] == 0)) {
123 /* bytes[2,3] == (0,0); must be Auspex */
124 /* XXX or could be Ultrix+MASSBUS "hp" disk? */
129 * bytes[2,3] != (0,0); rules out Auspex, could be
130 * DECOSF, SUNOS4, or IRIX4
132 if ((fhp
[4] != 0) && (fhp
[5] == 0) &&
133 (fhp
[8] == 12) && (fhp
[9] == 0)) {
134 /* seems to be DECOSF, with minor == 0 */
138 /* could be SUNOS4 or IRIX4 */
139 /* XXX the test of fhp[5] == 8 could be wrong */
140 if ((fhp
[4] == 0) && (fhp
[5] == 8) && (fhp
[6] == 0) &&
142 /* looks like a length, not a file system typecode */
154 * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4
155 * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5
156 * could be AIX, HP-UX
158 if ((fhp
[2] == 0) && (fhp
[3] == 0)) {
160 * bytes[2,3] == (0,0); rules out OSF, probably not UCX
161 * (unless the exported device name is just one letter!),
162 * could be Ultrix, IRIX5, AIX, or SUNOS5
163 * might be HP-UX (depends on their values for minor devs)
165 /*XXX we probably only need to test of these two bytes */
166 if ((fhp
[21] == 0) && (fhp
[23] == 0)) {
170 /* Could be SUNOS5/IRIX5, maybe AIX */
171 /* XXX no obvious difference between SUNOS5 and IRIX5 */
174 /* XXX what about AIX? */
179 * bytes[2,3] != (0,0); rules out Ultrix, could be
180 * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX
182 if ((fhp
[8] == 12) && (fhp
[9] == 0)) {
185 else if ((fhp
[8] == 0) && (fhp
[9] == 10)) {
186 /* could be SUNOS5/IRIX5, AIX, HP-UX */
187 if ((fhp
[7] == 0) && (fhp
[6] == 0) &&
188 (fhp
[5] == 0) && (fhp
[4] == 0)) {
189 /* XXX is this always true of HP-UX? */
192 else if (fhp
[7] == 2) {
193 /* This would be MNT_NFS on AIX, which is impossible */
194 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
198 * XXX Could be SUNOS5/IRIX5 or AIX. I don't
199 * XXX see any way to disambiguate these, so
200 * XXX I'm going with the more likely guess.
201 * XXX Sorry, Big Blue.
203 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
211 fhtype
= FHT_UNKNOWN
;
217 /* XXX still needs to handle SUNOS3 */
221 fsidp
->Fsid_dev
.Minor
= fhp
[7];
222 fsidp
->Fsid_dev
.Major
= fhp
[6];
223 fsidp
->fsid_code
= 0;
225 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
233 fsidp
->fsid_code
= make_uint32(fhp
[7], fhp
[6], fhp
[5], fhp
[4]);
234 /* XXX could ignore 3 high-order bytes */
236 temp
= make_uint32(fhp
[3], fhp
[2], fhp
[1], fhp
[0]);
237 fsidp
->Fsid_dev
.Minor
= temp
& 0xFFFFF;
238 fsidp
->Fsid_dev
.Major
= (temp
>>20) & 0xFFF;
240 temp
= make_uint32(fhp
[15], fhp
[14], fhp
[13], fhp
[12]);
247 fsidp
->Fsid_dev
.Minor
= fhp
[3];
248 fsidp
->Fsid_dev
.Major
= fhp
[2];
249 fsidp
->fsid_code
= 0;
251 temp
= make_uint32(fhp
[8], fhp
[9], fhp
[10], fhp
[11]);
259 fsidp
->Fsid_dev
.Minor
= make_uint16(fhp
[2], fhp
[3]);
260 fsidp
->Fsid_dev
.Major
= make_uint16(fhp
[0], fhp
[1]);
261 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
263 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
276 fsidp
->Fsid_dev
.Minor
= fhp
[3];
277 fsidp
->Fsid_dev
.Major
= fhp
[2];
278 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
280 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
288 temp
= make_uint16(fhp
[0], fhp
[1]);
289 fsidp
->Fsid_dev
.Major
= (temp
>>2) & 0x3FFF;
290 temp
= make_uint24(fhp
[1], fhp
[2], fhp
[3]);
291 fsidp
->Fsid_dev
.Minor
= temp
& 0x3FFFF;
292 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
294 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
302 fsidp
->fsid_code
= 0;
303 fsidp
->Fsid_dev
.Minor
= fhp
[0];
304 fsidp
->Fsid_dev
.Major
= fhp
[1];
306 temp
= make_uint32(fhp
[7], fhp
[6], fhp
[5], fhp
[4]);
313 /* No numeric file system ID, so hash on the device-name */
314 if (sizeof(*fsidp
) >= 14) {
315 if (sizeof(*fsidp
) > 14)
316 memset((char *)fsidp
, 0, sizeof(*fsidp
));
317 /* just use the whole thing */
318 memcpy((char *)fsidp
, (char *)fh
, 14);
321 u_int32_t tempa
[4]; /* at least 16 bytes, maybe more */
323 memset((char *)tempa
, 0, sizeof(tempa
));
324 memcpy((char *)tempa
, (char *)fh
, 14); /* ensure alignment */
325 fsidp
->Fsid_dev
.Minor
= tempa
[0] + (tempa
[1]<<1);
326 fsidp
->Fsid_dev
.Major
= tempa
[2] + (tempa
[3]<<1);
327 fsidp
->fsid_code
= 0;
330 /* VMS file ID is: (RVN, FidHi, FidLo) */
331 *inop
= make_uint32(fhp
[26], fhp
[27], fhp
[23], fhp
[22]);
333 /* Caller must save (and null-terminate?) this value */
335 *fsnamep
= (char *)&(fhp
[1]);
342 fsidp
->Fsid_dev
.Minor
= make_uint16(fhp
[2], fhp
[3]);
343 fsidp
->Fsid_dev
.Major
= make_uint16(fhp
[0], fhp
[1]);
344 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
346 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
354 fsidp
->Fsid_dev
.Major
= fhp
[0];
355 temp
= make_uint24(fhp
[1], fhp
[2], fhp
[3]);
356 fsidp
->Fsid_dev
.Minor
= temp
;
357 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
359 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
371 for (i
= 0; i
< 32; i
++)
372 (void)fprintf(stderr
, "%x.", fhp
[i
]);
373 (void)fprintf(stderr
, "\n");
376 /* XXX for now, give "bogus" values to aid debugging */
377 fsidp
->fsid_code
= 0;
378 fsidp
->Fsid_dev
.Minor
= 257;
379 fsidp
->Fsid_dev
.Major
= 257;
382 /* display will show this string instead of (257,257) */
384 *fsnamep
= "Unknown";
387 *osnamep
= "Unknown";
394 * Is this a VMS UCX file handle?
396 * (1) leading code byte [XXX not yet]
397 * (2) followed by string of printing chars & spaces
398 * (3) followed by string of nulls
407 for (i
= 1; i
< 14; i
++) {
408 if (isprint(fhp
[i
])) {
414 else if (fhp
[i
] == 0) {