]>
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.18 2000-07-01 03:39:00 assar Exp $ (LBL)";
19 #include <sys/types.h>
26 #include "interface.h"
30 * This routine attempts to parse a file handle (in network byte order),
31 * using heuristics to guess what kind of format it is in. See the
32 * file "fhandle_layouts" for a detailed description of the various
33 * patterns we know about.
35 * The file handle is parsed into our internal representation of a
36 * file-system id, and an internal representation of an inode-number.
53 /* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */
54 #define XFF(x) ((u_int32_t)(x))
59 #define make_uint32(msb,b,c,lsb)\
60 (XFF(lsb) + (XFF(c)<<8) + (XFF(b)<<16) + (XFF(msb)<<24))
62 #define make_uint24(msb,b, lsb)\
63 (XFF(lsb) + (XFF(b)<<8) + (XFF(msb)<<16))
65 #define make_uint16(msb,lsb)\
66 (XFF(lsb) + (XFF(msb)<<8))
69 /* or other 64-bit systems */
70 #define make_uint48(msb,b,c,d,e,lsb)\
71 ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24) + ((b)<<32) + ((msb)<<40))
73 /* on 32-bit systems ignore high-order bits */
74 #define make_uint48(msb,b,c,d,e,lsb)\
75 ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24))
78 static int is_UCX(unsigned char *);
81 Parse_fh(fh
, len
, fsidp
, inop
, osnamep
, fsnamep
, ourself
)
86 char **osnamep
; /* if non-NULL, return OS name here */
87 char **fsnamep
; /* if non-NULL, return server fs name here (for VMS) */
88 int ourself
; /* true if file handle was generated on this host */
90 register unsigned char *fhp
= (unsigned char *)fh
;
92 int fhtype
= FHT_UNKNOWN
;
96 /* File handle generated on this host, no need for guessing */
120 * This is basically a big decision tree
122 else if ((fhp
[0] == 0) && (fhp
[1] == 0)) {
123 /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */
124 /* probably rules out HP-UX, AIX unless they allow major=0 */
125 if ((fhp
[2] == 0) && (fhp
[3] == 0)) {
126 /* bytes[2,3] == (0,0); must be Auspex */
127 /* XXX or could be Ultrix+MASSBUS "hp" disk? */
132 * bytes[2,3] != (0,0); rules out Auspex, could be
133 * DECOSF, SUNOS4, or IRIX4
135 if ((fhp
[4] != 0) && (fhp
[5] == 0) &&
136 (fhp
[8] == 12) && (fhp
[9] == 0)) {
137 /* seems to be DECOSF, with minor == 0 */
141 /* could be SUNOS4 or IRIX4 */
142 /* XXX the test of fhp[5] == 8 could be wrong */
143 if ((fhp
[4] == 0) && (fhp
[5] == 8) && (fhp
[6] == 0) &&
145 /* looks like a length, not a file system typecode */
157 * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4
158 * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5
159 * could be AIX, HP-UX
161 if ((fhp
[2] == 0) && (fhp
[3] == 0)) {
163 * bytes[2,3] == (0,0); rules out OSF, probably not UCX
164 * (unless the exported device name is just one letter!),
165 * could be Ultrix, IRIX5, AIX, or SUNOS5
166 * might be HP-UX (depends on their values for minor devs)
168 /*XXX we probably only need to test of these two bytes */
169 if ((fhp
[21] == 0) && (fhp
[23] == 0)) {
173 /* Could be SUNOS5/IRIX5, maybe AIX */
174 /* XXX no obvious difference between SUNOS5 and IRIX5 */
177 /* XXX what about AIX? */
182 * bytes[2,3] != (0,0); rules out Ultrix, could be
183 * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX
185 if ((fhp
[8] == 12) && (fhp
[9] == 0)) {
188 else if ((fhp
[8] == 0) && (fhp
[9] == 10)) {
189 /* could be SUNOS5/IRIX5, AIX, HP-UX */
190 if ((fhp
[7] == 0) && (fhp
[6] == 0) &&
191 (fhp
[5] == 0) && (fhp
[4] == 0)) {
192 /* XXX is this always true of HP-UX? */
195 else if (fhp
[7] == 2) {
196 /* This would be MNT_NFS on AIX, which is impossible */
197 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
201 * XXX Could be SUNOS5/IRIX5 or AIX. I don't
202 * XXX see any way to disambiguate these, so
203 * XXX I'm going with the more likely guess.
204 * XXX Sorry, Big Blue.
206 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
214 fhtype
= FHT_UNKNOWN
;
220 /* XXX still needs to handle SUNOS3 */
224 fsidp
->Fsid_dev
.Minor
= fhp
[7];
225 fsidp
->Fsid_dev
.Major
= fhp
[6];
226 fsidp
->fsid_code
= 0;
228 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
236 fsidp
->fsid_code
= make_uint32(fhp
[7], fhp
[6], fhp
[5], fhp
[4]);
237 /* XXX could ignore 3 high-order bytes */
239 temp
= make_uint32(fhp
[3], fhp
[2], fhp
[1], fhp
[0]);
240 fsidp
->Fsid_dev
.Minor
= temp
& 0xFFFFF;
241 fsidp
->Fsid_dev
.Major
= (temp
>>20) & 0xFFF;
243 temp
= make_uint32(fhp
[15], fhp
[14], fhp
[13], fhp
[12]);
250 fsidp
->Fsid_dev
.Minor
= fhp
[3];
251 fsidp
->Fsid_dev
.Major
= fhp
[2];
252 fsidp
->fsid_code
= 0;
254 temp
= make_uint32(fhp
[8], fhp
[9], fhp
[10], fhp
[11]);
262 fsidp
->Fsid_dev
.Minor
= make_uint16(fhp
[2], fhp
[3]);
263 fsidp
->Fsid_dev
.Major
= make_uint16(fhp
[0], fhp
[1]);
264 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
266 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
279 fsidp
->Fsid_dev
.Minor
= fhp
[3];
280 fsidp
->Fsid_dev
.Major
= fhp
[2];
281 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
283 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
291 temp
= make_uint16(fhp
[0], fhp
[1]);
292 fsidp
->Fsid_dev
.Major
= (temp
>>2) & 0x3FFF;
293 temp
= make_uint24(fhp
[1], fhp
[2], fhp
[3]);
294 fsidp
->Fsid_dev
.Minor
= temp
& 0x3FFFF;
295 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
297 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
305 fsidp
->fsid_code
= 0;
306 fsidp
->Fsid_dev
.Minor
= fhp
[0];
307 fsidp
->Fsid_dev
.Major
= fhp
[1];
309 temp
= make_uint32(fhp
[7], fhp
[6], fhp
[5], fhp
[4]);
316 /* No numeric file system ID, so hash on the device-name */
317 if (sizeof(*fsidp
) >= 14) {
318 if (sizeof(*fsidp
) > 14)
319 memset((char *)fsidp
, 0, sizeof(*fsidp
));
320 /* just use the whole thing */
321 memcpy((char *)fsidp
, (char *)fh
, 14);
324 u_int32_t tempa
[4]; /* at least 16 bytes, maybe more */
326 memset((char *)tempa
, 0, sizeof(tempa
));
327 memcpy((char *)tempa
, (char *)fh
, 14); /* ensure alignment */
328 fsidp
->Fsid_dev
.Minor
= tempa
[0] + (tempa
[1]<<1);
329 fsidp
->Fsid_dev
.Major
= tempa
[2] + (tempa
[3]<<1);
330 fsidp
->fsid_code
= 0;
333 /* VMS file ID is: (RVN, FidHi, FidLo) */
334 *inop
= make_uint32(fhp
[26], fhp
[27], fhp
[23], fhp
[22]);
336 /* Caller must save (and null-terminate?) this value */
338 *fsnamep
= (char *)&(fhp
[1]);
345 fsidp
->Fsid_dev
.Minor
= make_uint16(fhp
[2], fhp
[3]);
346 fsidp
->Fsid_dev
.Major
= make_uint16(fhp
[0], fhp
[1]);
347 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
349 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
357 fsidp
->Fsid_dev
.Major
= fhp
[0];
358 temp
= make_uint24(fhp
[1], fhp
[2], fhp
[3]);
359 fsidp
->Fsid_dev
.Minor
= temp
;
360 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
362 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
373 for (i
= 0; i
< 32; i
++)
374 (void)fprintf(stderr
, "%x.", fhp
[i
]);
375 (void)fprintf(stderr
, "\n");
377 /* XXX for now, give "bogus" values to aid debugging */
379 /* Save the actual handle, so it can be display with -u */
380 for (i
= 0; i
< 32; i
++)
381 (void)sprintf(&(fsidp
->Opaque_Handle
[i
*2]), "%.2X", fhp
[i
]);
383 fsidp
->fsid_code
= 0;
384 fsidp
->Fsid_dev
.Minor
= 257;
385 fsidp
->Fsid_dev
.Major
= 257;
388 /* display will show this string instead of (257,257) */
390 *fsnamep
= "Unknown";
393 *osnamep
= "Unknown";
400 * Is this a VMS UCX file handle?
402 * (1) leading code byte [XXX not yet]
403 * (2) followed by string of printing chars & spaces
404 * (3) followed by string of nulls
413 for (i
= 1; i
< 14; i
++) {
414 if (isprint(fhp
[i
])) {
420 else if (fhp
[i
] == 0) {