3 * dumpscan - routines for scanning and manipulating AFS volume dumps
5 * Copyright (c) 1998 Carnegie Mellon University
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software_Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie Mellon
26 * the rights to redistribute these changes.
32 /* intNN.h - Sized integer types */
35 typedef short afs_int16
;
36 typedef unsigned short afs_uint16
;
38 typedef long afs_int32
;
39 typedef unsigned long afs_uint32
;
43 /* Support for 64-bit integers.
44 * Presently, only unsigned 64-bit numbers are supported.
46 #define INT64_TEST_STR "0x12345678fedcba98"
47 #define INT64_TEST_HI 0x12345678
48 #define INT64_TEST_LO 0xfedcba98
52 typedef NATIVE_UINT64 dt_uint64
;
54 /* construct/extract/assign */
55 #define mk64(X,H,L) ((X) = ( ((dt_uint64)(H) << 32) \
56 | ((dt_uint64)(L) & 0xffffffff)))
57 #define hi64(Y) ((afs_uint32)(((Y) >> 32) & 0xffffffff))
58 #define lo64(Y) ((afs_uint32)((Y) & 0xffffffff))
59 #define ex64(Y,H,L) ((H) = hi64(Y), (L) = lo64(Y))
60 #define cp64(X,Y) ((X) = (Y))
62 #define set64(X,V) ((X) = (V))
65 #define eq64(X,Y) ((X) == (Y))
66 #define ne64(X,Y) ((X) != (Y))
67 #define lt64(X,Y) ((X) < (Y))
68 #define le64(X,Y) ((X) <= (Y))
69 #define gt64(X,Y) ((X) > (Y))
70 #define ge64(X,Y) ((X) >= (Y))
71 #define zero64(X) (!(X))
74 #define add64_32(X,A,B) ((X) = (A) + (dt_uint64)(B))
75 #define add64_64(X,A,B) ((X) = (A) + (B))
76 #define sub64_32(X,A,B) ((X) = (A) - (dt_uint64)(B))
77 #define sub64_64(X,A,B) ((X) = (A) - (B))
80 #ifdef WORDS_BIGENDIAN
81 #define hton64(X,Y) cp64(X,Y)
82 #define ntoh64(X,Y) cp64(X,Y)
84 #define hton64(X,Y) mk64(X,htonl(lo64(Y)),htonl(hi64(Y)))
85 #define ntoh64(X,Y) mk64(X,ntohl(lo64(Y)),ntohl(hi64(Y)))
88 #else /* !NATIVE_INT64 */
89 /** We have to provide our own 64-bit integers **/
94 /* construct/extract/assign */
95 #define mk64(X,H,L) ((X).hi = (H), (X).lo = (L))
96 #define ex64(Y,H,L) ((H) = (Y).hi, (L) = (Y).lo)
97 #define hi64(Y) ((Y).hi)
98 #define lo64(Y) ((Y).lo)
99 #define cp64(X,Y) ((X).hi = (Y).hi, (X).lo = (Y).lo)
100 #define get64(X) ((X).lo)
101 #define set64(X,V) ((X).hi = 0, (X).lo = (V))
104 #define eq64(A,B) ((A).hi == (B).hi && (A).lo == (B).lo)
105 #define ne64(A,B) ((A).hi != (B).hi || (A).lo != (B).lo)
106 #define lt64(A,B) ((A).hi < (B).hi || ((A).hi == (B).hi && (A).lo < (B).lo))
107 #define le64(A,B) ((A).hi < (B).hi || ((A).hi == (B).hi && (A).lo <= (B).lo))
108 #define gt64(A,B) ((A).hi > (B).hi || ((A).hi == (B).hi && (A).lo > (B).lo))
109 #define ge64(A,B) ((A).hi > (B).hi || ((A).hi == (B).hi && (A).lo >= (B).lo))
110 #define zero64(X) ((X).hi == 0 && (X).lo == 0)
113 #define add64_32(X,A,B) ( \
114 (X).lo = (A).lo + (B), \
116 (((((A).lo & 0x80000000) ^ ((B) & 0x80000000)) && !((X).lo & 0x80000000)) \
117 || (((A).lo & 0x80000000) && ((B) & 0x80000000))) \
119 #define add64_64(X,A,B) (add64_32(X,A,(B).lo), (X).hi += (B).hi)
121 #define sub64_32(X,A,B) ((X).lo = (A).lo - (B), \
122 (X).hi = (A).hi - ((A).lo < (B)))
123 #define sub64_64(X,A,B) (sub64_32(X,A,(B).lo), (X).hi -= (B).hi)
126 #define hton64(X,Y) mk64(X,htonl(hi64(Y)),htonl(lo64(Y)))
127 #define ntoh64(X,Y) mk64(X,ntohl(hi64(Y)),ntohl(lo64(Y)))
129 #endif /* NATIVE_INT64 */
132 /* The following are too complex to be macros: */
134 /* char *hexify_int64(dt_uint64 a, char *buf)
135 * Produces an ASCII representation of a in hexadecimal, and returns
136 * a pointer to the resulting string. If buf is non-NULL, it is taken
137 * to be a pointer to the buffer to be used, which must be at least 17
138 * bytes long. This function is thread-safe iff buf is provided.
140 extern char *hexify_int64(dt_uint64
*, char *);
142 /* char *decimate_int64(dt_uint64 a, char *buf)
143 * Produces an ASCII representation of a in decimal, and returns
144 * a pointer to the resulting string. If buf is non-NULL, it is taken
145 * to be a pointer to the buffer to be used, which must be at least 21
146 * bytes long. This function is thread-safe iff buf is provided.
148 extern char *decimate_int64(dt_uint64
*, char *);
150 /* void shift_int64(dt_uint64 a, int bits)
151 * Shifts the 64-bit integer in a by the specified number of bits.
152 * If bits is positive, the shift is to the left; if negative, the
153 * shift is to the right.
155 extern void shift_int64(dt_uint64
*, int);
157 #endif /* _INTNN_H_ */