-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinclude.h
More file actions
384 lines (323 loc) · 12.2 KB
/
include.h
File metadata and controls
384 lines (323 loc) · 12.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
/****************************************************************************
* *
* COPYRIGHT (c) 2006 - 2018 *
* This Software Provided *
* By *
* Robin's Nest Software Inc. *
* *
* Permission to use, copy, modify, distribute and sell this software and *
* its documentation for any purpose and without fee is hereby granted, *
* provided that the above copyright notice appear in all copies and that *
* both that copyright notice and this permission notice appear in the *
* supporting documentation, and that the name of the author not be used *
* in advertising or publicity pertaining to distribution of the software *
* without specific, written prior permission. *
* *
* THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, *
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN *
* NO EVENT SHALL HE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL *
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR *
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS *
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF *
* THIS SOFTWARE. *
* *
****************************************************************************/
/*
* Modification History:
*
* February 25th, 2016 by Robin T. Miller
* Increased the args buffer size to accomodate very long command lines.
* What's very long? how about ~45k of pout data! Therefore to support script
* files with lines this long, this size was increased from 32k to 64k!
* Note: This args buffer size is also used for the log file buffer size.
*/
#if !defined(INCLUDE_H)
#define INCLUDE_H 1
#if (defined(__unix__) || defined(_AIX)) && !defined(__unix)
#define __unix
#endif
#if defined(__alpha) || defined(__64BIT__) || defined(_LP64) || defined(__LP64__) || defined(__arch64__) || defined(_WIN64)
# define QuadIsLong
# define MACHINE_64BITS
#else /* assume !64bit compile! */
# define QuadIsLongLong
#endif /* 64bit check */
#define ScriptExtension ".spt"
/*
* These are used to define the max input sizes, but also get
* used for log buffer and string buffer sizes for formatting.
*/
#define ARGS_BUFFER_SIZE 65536 /* Input buffer size. */
#define ARGV_BUFFER_SIZE 4096 /* Maximum arguments. */
/*
* These buffer sizes are mainly for allocating stack space
* for pre-formatting strings to display. Different sizes
* to prevent wasting stack space (my preference).
*/
#define SMALL_BUFFER_SIZE 32 /* Small buffer size. */
#define MEDIUM_BUFFER_SIZE 64 /* Medium buffer size. */
#define LARGE_BUFFER_SIZE 128 /* Large buffer size. */
#define STRING_BUFFER_SIZE 4096 /* String buffer size. */
#define TIME_BUFFER_SIZE 32 /* ctime() buffer size. */
/*
* Note: This should be the largest file path allowed for any Host OS.
* On Linux, "errno = 36 - File name too long" occurs at 4096.
* This will usually be used for short term stack allocated space.
*/
#define PATH_BUFFER_SIZE 8192 /* Max path size. */
#define TRUE 1 /* Boolean TRUE value. */
#define FALSE 0 /* Boolean FALSE value. */
/*
* Declare a boolean data type.
*
* Note: Prefixed with 'h', to avoid redefinitions with OS includes.
* [ Most (not all) OS's have a bool_t or boolean_t (rats!). ]
*/
typedef enum hbool {
False = 0,
True = 1
} hbool_t;
typedef volatile hbool_t vbool_t;
typedef enum open_mode {
OPEN_FOR_READING = 0,
OPEN_FOR_WRITING = 1
} open_mode_t;
#if defined(_WIN32)
//# define HANDLE (void *)
//# define INVALID_HANDLE_VALUE (void *)-1
#else /* !defined(_WIN32) */
# define HANDLE int
# define INVALID_HANDLE_VALUE -1
#endif /* defined(_WIN32) */
/*
* Define Maximum Values for Various Sizes:
*/
#define SVALUE8_MAX 127
#define VALUE8_MAX 255U
#define SVALUE16_MAX 32767
#define VALUE16_MAX 65535U
#if defined(MACHINE_64BITS)
#define SVALUE32_MAX 2147483647
#define VALUE32_MAX 4294967295U
#define SVALUE_MAX 9223372036854775807L
#define VALUE_MAX 18446744073709551615UL
#else /* !defined(MACHINE_64BITS) */
#define SVALUE32_MAX 2147483647L
#define VALUE32_MAX 4294967295UL
/* I love Windows differences like this! NOT! :-( */
#if defined(_WIN32)
# define SVALUE_MAX 9223372036854775807i64
# define VALUE_MAX 18446744073709551615ui64
#else /* !defined(_WIN32) */
# define SVALUE_MAX 9223372036854775807LL
# define VALUE_MAX 18446744073709551615ULL
#endif /* defined(_WIN32) */
#endif /* defined(MACHINE_64BITS) */
/*
* Create some shorthands for volatile storage classes:
*/
typedef volatile char v_char;
typedef volatile short v_short;
typedef volatile int v_int;
typedef volatile long v_long;
#if !defined(DEC)
/* These are defined in sys/types.h on DEC Alpha systems. */
typedef volatile unsigned char vu_char;
typedef volatile unsigned short vu_short;
typedef volatile unsigned int vu_int;
typedef volatile unsigned long vu_long;
#endif /* !defined(__alpha) */
/* Newer *nix support these, Windows does not! */
#if defined(_WIN32)
typedef signed char int8_t;
typedef short int int16_t;
typedef signed int int32_t;
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
//# if defined(_WIN64)
/* Note: Unlike most Unix OS's, 64-bit Windows does *not* make a long 64-bits! */
//typedef long int int64_t;
//typedef unsigned long int uint64_t;
//typedef LONG64 int64_t;
//typedef ULONG64 uint64_t;
//# else /* !defined(_WIN64) */
typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
//# endif
#endif /* defined(_WIN32) */
#if defined(WIN32)
# define S64OF "%I64d"
# define U64OF "%I64u"
# define X64OF "0x%I64x"
# define SLOF "%ld"
# define ULOF "%lu"
# define PTROF "0x%lx"
# if defined(_LP64) || defined(__arch64__) || (_POSIX_V6_LP64_OFF64 - 0) == 1
# define LUF ULOF
# define LDF SLOF
# define LXF "0x%lx"
/* Note: Formats for leading zeros, half or full 64-bits. */
# define LLHXFMT "0x%08I64x"
# define LLFXFMT "0x%016I64x"
/* Note: Replacement for "%p" which differs between OS's, esp. Windows! */
# define LLPXFMT "0x%I64x"
# define LLPX0FMT "0x%016I64x"
# else /* 32-bit Windows */
# define LUF U64OF
# define LDF S64OF
# define LXF X64OF
# define LLHXFMT "0x%08I64x"
# define LLFXFMT "0x%016I64x"
# define LLPXFMT "0x%lx"
# define LLPX0FMT "0x%08lx"
# endif /* defined(_LP64) || defined(__arch64__) || (_POSIX_V6_LP64_OFF64 - 0) == 1 */
#else /* UNIX systems */
# if defined(_LP64) || defined(__arch64__) || (_POSIX_V6_LP64_OFF64 - 0) == 1
# define LUF "%lu"
# define LDF "%ld"
# define LXF "0x%lx"
# define LLHXFMT "0x%08lx"
# define LLFXFMT "0x%016lx"
# define LLPXFMT "0x%lx"
# define LLPX0FMT "0x%016lx"
# else /* !defined(_LP64) && !defined(__arch64__) && !(_POSIX_V6_LP64_OFF64 - 0) == 1 */
/* 32-bit Definitions: */
# define LUF "%llu"
# define LDF "%lld"
# define LXF "0x%#llx"
# define LLHXFMT "0x%08llX"
# define LLFXFMT "0x%016llX"
# define LLPXFMT "0x%x"
# define LLPX0FMT "0x%08x"
# endif /* defined(_LP64) || defined(__arch64__) || (_POSIX_V6_LP64_OFF64 - 0) == 1 */
#endif /* defined(_WIN32) */
/*
* Define some Architecture dependent types:
*/
#if defined(__alpha) || defined(__LP64__) || defined(_WIN64)
#if defined(_WIN64)
//typedef ULONG64 ptr_t;
typedef unsigned __int64 ptr_t;
#else /* defined(_WIN64) */
typedef unsigned long ptr_t;
#endif /* defined(_WIN64) */
typedef unsigned int bool;
typedef volatile unsigned int v_bool;
#else /* !defined(__alpha) && !defined(__LP64__) && !defined(_WIN64) */
typedef unsigned int ptr_t;
//typedef unsigned char bool;
typedef volatile unsigned char v_bool;
#endif /* defined(__alpha) || defined(__LP64__) || defined(_WIN64) */
/*
* For IOT block numbers, use this definition.
* TODO: Extend this to 64-bits in the future!
*/
typedef unsigned int iotlba_t;
#define SUCCESS 0 /* Success status code. */
#define FAILURE -1 /* Failure status code. */
#define WARNING 1 /* Warning status code. */
#define CONTINUE WARNING /* Continue operations. */
#define END_OF_FILE 254 /* End of file status. */
#define END_OF_DATA END_OF_FILE /* End of test data. */
#define RESTART 253 /* Restart operations. */
#define TRUE 1 /* Boolean TRUE value. */
#define FALSE 0 /* Boolean FALSE value. */
#define UNINITIALIZED 255 /* Uninitialized flag. */
#define FATAL_ERROR -1 /* Fatal error code. */
#define MSECS 1000 /* Milliseconds value. */
#define ANY_RADIX 0 /* Any radix string conversion. */
#define DEC_RADIX 10 /* Base for decimal conversion. */
#define HEX_RADIX 16 /* Base for hex str conversion. */
#define BLOCK_SIZE 512 /* Bytes in block. */
#define KBYTE_SIZE 1024 /* Kilobytes value. */
#define MBYTE_SIZE 1048576L /* Megabytes value. */
#define GBYTE_SIZE 1073741824L /* Gigabytes value. */
#if defined(_WIN32)
# define TBYTE_SIZE 1099511627776i64 /* Terabytes value. */
#else /* !defined(_WIN32) */
# define TBYTE_SIZE 1099511627776LL /* Terabytes value. */
#endif /* defined(_WIN32) */
/* Avoid conflict with OS INFINITY definitions! */
//#undef INFINITY
#define MY_INFINITY VALUE_MAX
#define SECS_PER_MIN 60
#define MINS_PER_HOUR 60
#define HOURS_PER_DAY 24
#define SECS_PER_HOUR (SECS_PER_MIN * MINS_PER_HOUR)
#define SECS_PER_DAY (SECS_PER_HOUR * HOURS_PER_DAY)
#define MSECS_PER_HOUR (SECS_PER_HOUR * MSECS)
#define MSECS_PER_DAY (SECS_PER_DAY * MSECS)
#define MSECS_PER_MIN (SECS_PER_MIN * MSECS)
#define MSECS_PER_SEC MSECS
#define MSECS_PER_SEC MSECS
#define mSECS_PER_SEC 1000
#define uSECS_PERmSEC 1000
#define uSECS_PER_SEC 1000000
/*
* Macros to aid with string comparisions.
*/
#define EQ(x,y) (strcmp(x,y) == 0) /* String EQ compare. */
#define EQL(x,y,n) (strncmp(x,y,n) == 0) /* Compare w/length. */
#define EQC(x,y) (strcasecmp(x,y) == 0) /* Case insensitive. */
#define EQLC(x,y,n) (strncasecmp(x,y,n) == 0) /* Compare w/length. */
#define NE(x,y) (strcmp(x,y) != 0) /* String NE compare. */
#define NEL(x,y,n) (strncmp(x,y,n) != 0) /* Compare w/length. */
#define NEC(x,y) (strcasecmp(x,y) != 0) /* Case insensitive. */
#define NELC(x,y,n) (strncasecmp(x,y,n) != 0) /* Compare w/length. */
#define EQS(x,y) (strstr(x,y) != NULL) /* Sub-string equal. */
#define EQSC(x,y) (strcasestr(x,y) != NULL) /* Case insensitive. */
#define NES(x,y) (strstr(x,y) == NULL) /* Sub-string not equal */
#define NESC(x,y) (strcasestr(x,y) == NULL) /* Case insensitive. */
#define EqualString(s1,s2) ( strcmp(s1,s2) == 0 )
#define NotEqualString(s1,s2) ( strcmp(s1,s2) != 0 )
#define EqualStringLength(s1,s2,n) ( strncmp(s1,s2,n) == 0 )
#define NotEqualStringLength(s1,s2,n) ( strncmp(s1,s2,n) != 0 )
#define EqualLength(s1,s2) ( strlen(s1) == strlen(s2) )
#define NotEqualLength(s1,s2) ( strlen(s1) != strlen(s2) )
/*********************************** macros **********************************/
#ifndef max
# define max(a,b) ((a) > (b)? (a): (b))
#endif
#ifndef min
# define min(a,b) ((a) < (b)? (a): (b))
#endif
#ifndef howmany
# define howmany(x, y) (((x)+((y)-1))/(y))
#endif
#ifndef roundup
# define roundup(x, y) ((((x)+((y)-1))/(y))*(y))
#endif
#ifndef rounddown
# define rounddown(x,y) (((x)/(y))*(y))
#endif
#ifndef ispowerof2
# define ispowerof2(x) ((((x)-1)&(x))==0)
#endif
#if !defined(offsetof)
# define offsetof(type, field) ((long) &((type *)0)->field)
#endif /* !defined(offsetof) */
/*
* External Variables:
*/
extern char *OurName;
#if defined(_WIN32)
# include "spt_win.h"
#else /* !defined(_WIN32) */
# include "spt_unix.h"
#endif /* defined(_WIN32) */
/*
* External Declarations:
*/
/* libscsi.c */
extern HANDLE OpenDevice(char *dsf);
extern int CloseDevice(HANDLE fd, char *dsf);
/* utilities.c */
extern uint32_t CvtStrtoValue(char *nstr, char **eptr, int base);
extern uint64_t CvtStrtoLarge(char *nstr, char **eptr, int base);
extern time_t CvtTimetoValue(char *nstr, char **eptr);
extern time_t CvtTimetoMsValue(char *nstr, char **eptr);
extern void InitBuffer( unsigned char *buffer,
size_t count,
uint32_t pattern );
#endif /* !defined(INCLUDE_H) */