]>
git.saurik.com Git - apple/network_cmds.git/blob - tcpdump.tproj/parsenfsfh.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * "Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.0 (the 'License'). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
25 * parsenfsfh.c - portable parser for NFS file handles
26 * uses all sorts of heuristics
29 * Digital Equipment Corporation
30 * Western Research Laboratory
34 static const char rcsid
[] =
35 "@(#) $Header: /cvs/Darwin/Commands/NeXT/network_cmds/tcpdump.tproj/parsenfsfh.c,v 1.1.1.1 1999/05/02 03:58:32 wsanchez Exp $ (LBL)";
38 #include <sys/types.h>
46 #include "interface.h"
50 * This routine attempts to parse a file handle (in network byte order),
51 * using heuristics to guess what kind of format it is in. See the
52 * file "fhandle_layouts" for a detailed description of the various
53 * patterns we know about.
55 * The file handle is parsed into our internal representation of a
56 * file-system id, and an internal representation of an inode-number.
73 /* Nasty hack to keep the Ultrix C compiler from emitting bogus warnings */
74 #define XFF(x) ((u_int32_t)(x))
79 #define make_uint32(msb,b,c,lsb)\
80 (XFF(lsb) + (XFF(c)<<8) + (XFF(b)<<16) + (XFF(msb)<<24))
82 #define make_uint24(msb,b, lsb)\
83 (XFF(lsb) + (XFF(b)<<8) + (XFF(msb)<<16))
85 #define make_uint16(msb,lsb)\
86 (XFF(lsb) + (XFF(msb)<<8))
89 /* or other 64-bit systems */
90 #define make_uint48(msb,b,c,d,e,lsb)\
91 ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24) + ((b)<<32) + ((msb)<<40))
93 /* on 32-bit systems ignore high-order bits */
94 #define make_uint48(msb,b,c,d,e,lsb)\
95 ((lsb) + ((e)<<8) + ((d)<<16) + ((c)<<24))
98 static int is_UCX(unsigned char *);
101 Parse_fh(fh
, fsidp
, inop
, osnamep
, fsnamep
, ourself
)
102 register caddr_t
*fh
;
105 char **osnamep
; /* if non-NULL, return OS name here */
106 char **fsnamep
; /* if non-NULL, return server fs name here (for VMS) */
107 int ourself
; /* true if file handle was generated on this host */
109 register unsigned char *fhp
= (unsigned char *)fh
;
111 int fhtype
= FHT_UNKNOWN
;
114 /* File handle generated on this host, no need for guessing */
138 * This is basically a big decision tree
140 else if ((fhp
[0] == 0) && (fhp
[1] == 0)) {
141 /* bytes[0,1] == (0,0); rules out Ultrix, IRIX5, SUNOS5 */
142 /* probably rules out HP-UX, AIX unless they allow major=0 */
143 if ((fhp
[2] == 0) && (fhp
[3] == 0)) {
144 /* bytes[2,3] == (0,0); must be Auspex */
145 /* XXX or could be Ultrix+MASSBUS "hp" disk? */
150 * bytes[2,3] != (0,0); rules out Auspex, could be
151 * DECOSF, SUNOS4, or IRIX4
153 if ((fhp
[4] != 0) && (fhp
[5] == 0) &&
154 (fhp
[8] == 12) && (fhp
[9] == 0)) {
155 /* seems to be DECOSF, with minor == 0 */
159 /* could be SUNOS4 or IRIX4 */
160 /* XXX the test of fhp[5] == 8 could be wrong */
161 if ((fhp
[4] == 0) && (fhp
[5] == 8) && (fhp
[6] == 0) &&
163 /* looks like a length, not a file system typecode */
175 * bytes[0,1] != (0,0); rules out Auspex, IRIX4, SUNOS4
176 * could be IRIX5, DECOSF, UCX, Ultrix, SUNOS5
177 * could be AIX, HP-UX
179 if ((fhp
[2] == 0) && (fhp
[3] == 0)) {
181 * bytes[2,3] == (0,0); rules out OSF, probably not UCX
182 * (unless the exported device name is just one letter!),
183 * could be Ultrix, IRIX5, AIX, or SUNOS5
184 * might be HP-UX (depends on their values for minor devs)
186 /*XXX we probably only need to test of these two bytes */
187 if ((fhp
[21] == 0) && (fhp
[23] == 0)) {
191 /* Could be SUNOS5/IRIX5, maybe AIX */
192 /* XXX no obvious difference between SUNOS5 and IRIX5 */
195 /* XXX what about AIX? */
200 * bytes[2,3] != (0,0); rules out Ultrix, could be
201 * DECOSF, SUNOS5, IRIX5, AIX, HP-UX, or UCX
203 if ((fhp
[8] == 12) && (fhp
[9] == 0)) {
206 else if ((fhp
[8] == 0) && (fhp
[9] == 10)) {
207 /* could be SUNOS5/IRIX5, AIX, HP-UX */
208 if ((fhp
[7] == 0) && (fhp
[6] == 0) &&
209 (fhp
[5] == 0) && (fhp
[4] == 0)) {
210 /* XXX is this always true of HP-UX? */
213 else if (fhp
[7] == 2) {
214 /* This would be MNT_NFS on AIX, which is impossible */
215 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
219 * XXX Could be SUNOS5/IRIX5 or AIX. I don't
220 * XXX see any way to disambiguate these, so
221 * XXX I'm going with the more likely guess.
222 * XXX Sorry, Big Blue.
224 fhtype
= FHT_SUNOS5
; /* or maybe IRIX5 */
232 fhtype
= FHT_UNKNOWN
;
238 /* XXX still needs to handle SUNOS3 */
242 fsidp
->Fsid_dev
.Minor
= fhp
[7];
243 fsidp
->Fsid_dev
.Major
= fhp
[6];
244 fsidp
->fsid_code
= 0;
246 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
254 fsidp
->fsid_code
= make_uint32(fhp
[7], fhp
[6], fhp
[5], fhp
[4]);
255 /* XXX could ignore 3 high-order bytes */
257 temp
= make_uint32(fhp
[3], fhp
[2], fhp
[1], fhp
[0]);
258 fsidp
->Fsid_dev
.Minor
= temp
& 0xFFFFF;
259 fsidp
->Fsid_dev
.Major
= (temp
>>20) & 0xFFF;
261 temp
= make_uint32(fhp
[15], fhp
[14], fhp
[13], fhp
[12]);
268 fsidp
->Fsid_dev
.Minor
= fhp
[3];
269 fsidp
->Fsid_dev
.Major
= fhp
[2];
270 fsidp
->fsid_code
= 0;
272 temp
= make_uint32(fhp
[8], fhp
[9], fhp
[10], fhp
[11]);
280 fsidp
->Fsid_dev
.Minor
= make_uint16(fhp
[2], fhp
[3]);
281 fsidp
->Fsid_dev
.Major
= make_uint16(fhp
[0], fhp
[1]);
282 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
284 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
297 fsidp
->Fsid_dev
.Minor
= fhp
[3];
298 fsidp
->Fsid_dev
.Major
= fhp
[2];
299 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
301 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
309 temp
= make_uint16(fhp
[0], fhp
[1]);
310 fsidp
->Fsid_dev
.Major
= (temp
>>2) & 0x3FFF;
311 temp
= make_uint24(fhp
[1], fhp
[2], fhp
[3]);
312 fsidp
->Fsid_dev
.Minor
= temp
& 0x3FFFF;
313 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
315 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
323 fsidp
->fsid_code
= 0;
324 fsidp
->Fsid_dev
.Minor
= fhp
[0];
325 fsidp
->Fsid_dev
.Major
= fhp
[1];
327 temp
= make_uint32(fhp
[7], fhp
[6], fhp
[5], fhp
[4]);
334 /* No numeric file system ID, so hash on the device-name */
335 if (sizeof(*fsidp
) >= 14) {
336 if (sizeof(*fsidp
) > 14)
337 memset((char *)fsidp
, 0, sizeof(*fsidp
));
338 memcpy((char *)fsidp
, fh
, 14); /* just use the whole thing */
341 u_int32_t tempa
[4]; /* at least 16 bytes, maybe more */
343 memset((char *)tempa
, 0, sizeof(tempa
));
344 memcpy((char *)tempa
, fh
, 14); /* ensure alignment */
345 fsidp
->Fsid_dev
.Minor
= tempa
[0] + (tempa
[1]<<1);
346 fsidp
->Fsid_dev
.Major
= tempa
[2] + (tempa
[3]<<1);
347 fsidp
->fsid_code
= 0;
350 /* VMS file ID is: (RVN, FidHi, FidLo) */
351 *inop
= make_uint32(fhp
[26], fhp
[27], fhp
[23], fhp
[22]);
353 /* Caller must save (and null-terminate?) this value */
355 *fsnamep
= (char *)&(fhp
[1]);
362 fsidp
->Fsid_dev
.Minor
= make_uint16(fhp
[2], fhp
[3]);
363 fsidp
->Fsid_dev
.Major
= make_uint16(fhp
[0], fhp
[1]);
364 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
366 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
374 fsidp
->Fsid_dev
.Major
= fhp
[0];
375 temp
= make_uint24(fhp
[1], fhp
[2], fhp
[3]);
376 fsidp
->Fsid_dev
.Minor
= temp
;
377 fsidp
->fsid_code
= make_uint32(fhp
[4], fhp
[5], fhp
[6], fhp
[7]);
379 temp
= make_uint32(fhp
[12], fhp
[13], fhp
[14], fhp
[15]);
391 for (i
= 0; i
< 32; i
++)
392 (void)fprintf(stderr
, "%x.", fhp
[i
]);
393 (void)fprintf(stderr
, "\n");
396 /* XXX for now, give "bogus" values to aid debugging */
397 fsidp
->fsid_code
= 0;
398 fsidp
->Fsid_dev
.Minor
= 257;
399 fsidp
->Fsid_dev
.Major
= 257;
402 /* display will show this string instead of (257,257) */
404 *fsnamep
= "Unknown";
407 *osnamep
= "Unknown";
414 * Is this a VMS UCX file handle?
416 * (1) leading code byte [XXX not yet]
417 * (2) followed by string of printing chars & spaces
418 * (3) followed by string of nulls
427 for (i
= 1; i
< 14; i
++) {
428 if (isprint(fhp
[i
])) {
434 else if (fhp
[i
] == 0) {