~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSDefs.h

Removed reference to aio.h - we don't reference its use anywhere.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
2
 
 *
3
 
 * PrimeBase Media Stream for MySQL
4
 
 *
5
 
 * This program is free software; you can redistribute it and/or modify
6
 
 * it under the terms of the GNU General Public License as published by
7
 
 * the Free Software Foundation; either version 2 of the License, or
8
 
 * (at your option) any later version.
9
 
 *
10
 
 * This program is distributed in the hope that it will be useful,
11
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
 * GNU General Public License for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU General Public License
16
 
 * along with this program; if not, write to the Free Software
17
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
 
 *
19
 
 * Original author: Paul McCullagh (H&G2JCtL)
20
 
 * Continued development: Barry Leslie
21
 
 *
22
 
 * 2007-06-02
23
 
 *
24
 
 * CORE SYSTEM:
25
 
 * Common definitions that may be required be included at the
26
 
 * top of every header file.
27
 
 *
28
 
 */
29
 
 
30
 
#ifndef __CSDEFS_H__
31
 
#define __CSDEFS_H__
32
 
 
33
 
#include <sys/types.h>
34
 
 
35
 
// Use standard portable data types
36
 
#include <stdint.h>
37
 
 
38
 
/*
39
 
 * An unsigned integer, 1 byte long:
40
 
 */
41
 
#ifndef u_char
42
 
#define u_char                  unsigned char
43
 
#endif
44
 
 
45
 
/*
46
 
 * An usigned integer, 1 byte long:
47
 
 */
48
 
#define s_char                  unsigned char
49
 
 
50
 
/* PBMS assumes that off_t is 8 bytes so to ensure this always use  off64_t*/
51
 
#define off64_t                 uint64_t
52
 
 
53
 
 
54
 
/*
55
 
 * A signed integer at least 32 bits long.
56
 
 * The size used is whatever is most
57
 
 * convenient to the machine.
58
 
 */
59
 
#define s_int int_fast32_t
60
 
 
61
 
/* Forward declartion of a thread: */
62
 
class CSThread;
63
 
 
64
 
// Used to avoid warnings about unused parameters.
65
 
#define UNUSED(x) (void)x
66
 
 
67
 
#ifdef OS_WINDOWS
68
 
 
69
 
#define CS_DEFAULT_EOL          "\r\n"
70
 
#define CS_DIR_CHAR                     '\\'
71
 
#define CS_DIR_DELIM            "\\"
72
 
#define IS_DIR_CHAR(ch)         ((ch) == CS_DIR_CHAR || (ch) == '/')
73
 
 
74
 
#else
75
 
 
76
 
#define CS_DEFAULT_EOL          "\n"
77
 
#define CS_DIR_CHAR                     '/'
78
 
#define CS_DIR_DELIM            "/"
79
 
#define IS_DIR_CHAR(ch)         ((ch) == CS_DIR_CHAR)
80
 
 
81
 
#endif // OS_WINDOWS
82
 
 
83
 
#define CS_CALL_STACK_SIZE              100
84
 
#define CS_RELEASE_STACK_SIZE   200
85
 
#define CS_JUMP_STACK_SIZE              20
86
 
 
87
 
/* Fixed length types */
88
 
 
89
 
#ifdef CS_WIN
90
 
 
91
 
#ifndef PATH_MAX
92
 
#define PATH_MAX                MAX_PATH
93
 
#endif
94
 
 
95
 
#ifndef NAME_MAX
96
 
#define NAME_MAX                MAX_PATH
97
 
#endif
98
 
 
99
 
#endif // CS_WIN
100
 
 
101
 
/* C string display width sizes including space for a null terminator and possible sign. */
102
 
#define CS_WIDTH_INT_8  5
103
 
#define CS_WIDTH_INT_16 7
104
 
#define CS_WIDTH_INT_32 12
105
 
#define CS_WIDTH_INT_64 22
106
 
 
107
 
typedef uint8_t                 CSDiskValue1[1];        
108
 
typedef uint8_t                 CSDiskValue2[2];        
109
 
typedef uint8_t                 CSDiskValue3[3];        
110
 
typedef uint8_t                 CSDiskValue4[4];        
111
 
typedef uint8_t                 CSDiskValue6[6];        
112
 
typedef uint8_t                 CSDiskValue8[8];        
113
 
 
114
 
/*
115
 
 * Byte order on the disk is little endian! This is the byte order of the i386.
116
 
 * Little endian byte order starts with the least significan byte.
117
 
 *
118
 
 * The reason for choosing this byte order for the disk is 2-fold:
119
 
 * Firstly the i386 is the cheapest and fasted platform today.
120
 
 * Secondly the i386, unlike RISK chips (with big endian) can address
121
 
 * memory that is not aligned!
122
 
 *
123
 
 * Since the disk image of PrimeBase XT is not aligned, the second point
124
 
 * is significant. A RISK chip needs to access it byte-wise, so we might as
125
 
 * well do the byte swapping at the same time.
126
 
 *
127
 
 * The macros below are of 4 general types:
128
 
 *
129
 
 * GET/SET - Get and set 1,2,4,8 byte values (short, int, long, etc).
130
 
 * Values are swapped only on big endian platforms. This makes these
131
 
 * functions very efficient on little-endian platforms.
132
 
 *
133
 
 * COPY - Transfer data without swapping regardless of platform. This
134
 
 * function is a bit more efficient on little-endian platforms
135
 
 * because alignment is not an issue.
136
 
 *
137
 
 * MOVE - Similar to get and set, but the deals with memory instead
138
 
 * of values. Since no swapping is done on little-endian platforms
139
 
 * this function is identical to COPY on little-endian platforms.
140
 
 *
141
 
 * SWAP - Transfer and swap data regardless of the platform type.
142
 
 * Aligment is not assumed.
143
 
 *
144
 
 * The DISK component of the macro names indicates that alignment of
145
 
 * the value cannot be assumed.
146
 
 *
147
 
 */
148
 
#if BYTE_ORDER == BIG_ENDIAN
149
 
/* The native order of the machine is big endian. Since the native disk
150
 
 * disk order of XT is little endian, all data to and from disk
151
 
 * must be swapped.
152
 
 */
153
 
#define CS_SET_DISK_1(d, s)             ((d)[0] = (uint8_t) (s))
154
 
 
155
 
#define CS_SET_DISK_2(d, s)             do { (d)[0] = (uint8_t)  (((uint16_t) (s))        & 0xFF); (d)[1] = (uint8_t) ((((uint16_t) (s)) >> 8 ) & 0xFF); } while (0)
156
 
 
157
 
#define CS_SET_DISK_3(d, s)             do { (d)[0] = (uint8_t)  (((uint32_t) (s))        & 0xFF); (d)[1] = (uint8_t) ((((uint32_t) (s)) >> 8 ) & 0xFF); \
158
 
                                                                         (d)[2] = (uint8_t) ((((uint32_t) (s)) >> 16) & 0xFF); } while (0)
159
 
 
160
 
#define CS_SET_DISK_4(d, s)             do { (d)[0] = (uint8_t)  (((uint32_t) (s))        & 0xFF); (d)[1] = (uint8_t) ((((uint32_t) (s)) >> 8 ) & 0xFF); \
161
 
                                                                         (d)[2] = (uint8_t) ((((uint32_t) (s)) >> 16) & 0xFF); (d)[3] = (uint8_t) ((((uint32_t) (s)) >> 24) & 0xFF); } while (0)
162
 
 
163
 
#define CS_SET_DISK_6(d, s)             do { (d)[0] = (uint8_t)  (((uint64_t) (s))        & 0xFF); (d)[1] = (uint8_t) ((((uint64_t) (s)) >> 8 ) & 0xFF); \
164
 
                                                                         (d)[2] = (uint8_t) ((((uint64_t) (s)) >> 16) & 0xFF); (d)[3] = (uint8_t) ((((uint64_t) (s)) >> 24) & 0xFF); \
165
 
                                                                         (d)[4] = (uint8_t) ((((uint64_t) (s)) >> 32) & 0xFF); (d)[5] = (uint8_t) ((((uint64_t) (s)) >> 40) & 0xFF); } while (0)
166
 
 
167
 
#define CS_SET_DISK_8(d, s)             do { (d)[0] = (uint8_t)  (((uint64_t) (s))        & 0xFF); (d)[1] = (uint8_t) ((((uint64_t) (s)) >> 8 ) & 0xFF); \
168
 
                                                                         (d)[2] = (uint8_t) ((((uint64_t) (s)) >> 16) & 0xFF); (d)[3] = (uint8_t) ((((uint64_t) (s)) >> 24) & 0xFF); \
169
 
                                                                         (d)[4] = (uint8_t) ((((uint64_t) (s)) >> 32) & 0xFF); (d)[5] = (uint8_t) ((((uint64_t) (s)) >> 40) & 0xFF); \
170
 
                                                                         (d)[6] = (uint8_t) ((((uint64_t) (s)) >> 48) & 0xFF); (d)[7] = (uint8_t) ((((uint64_t) (s)) >> 56) & 0xFF); } while (0)
171
 
 
172
 
#define CS_GET_DISK_1(s)                ((s)[0])
173
 
 
174
 
#define CS_GET_DISK_2(s)                ((uint16_t) (((uint16_t) (s)[0]) | (((uint16_t) (s)[1]) << 8)))
175
 
 
176
 
#define CS_GET_DISK_3(s)                ((uint32_t) (((uint32_t) (s)[0]) | (((uint32_t) (s)[1]) << 8) | (((uint32_t) (s)[2]) << 16)))
177
 
 
178
 
#define CS_GET_DISK_4(s)                (((uint32_t) (s)[0])        | (((uint32_t) (s)[1]) << 8 ) | \
179
 
                                                                (((uint32_t) (s)[2]) << 16) | (((uint32_t) (s)[3]) << 24))
180
 
 
181
 
#define CS_GET_DISK_6(s)                (((uint64_t) (s)[0])        | (((uint64_t) (s)[1]) << 8 ) | \
182
 
                                                                (((uint64_t) (s)[2]) << 16) | (((uint64_t) (s)[3]) << 24) | \
183
 
                                                                (((uint64_t) (s)[4]) << 32) | (((uint64_t) (s)[5]) << 40))
184
 
 
185
 
#define CS_GET_DISK_8(s)                (((uint64_t) (s)[0])        | (((uint64_t) (s)[1]) << 8 ) | \
186
 
                                                                (((uint64_t) (s)[2]) << 16) | (((uint64_t) (s)[3]) << 24) | \
187
 
                                                                (((uint64_t) (s)[4]) << 32) | (((uint64_t) (s)[5]) << 40) | \
188
 
                                                                (((uint64_t) (s)[6]) << 48) | (((uint64_t) (s)[7]) << 56))
189
 
 
190
 
/* Move will copy memory, and swap the bytes on a big endian machine.
191
 
 * On a little endian machine it is the same as COPY.
192
 
 */
193
 
#define CS_MOVE_DISK_1(d, s)    ((d)[0] = (s)[0])
194
 
#define CS_MOVE_DISK_2(d, s)    do { (d)[0] = (s)[1]; (d)[1] = (s)[0]; } while (0)
195
 
#define CS_MOVE_DISK_3(d, s)    do { (d)[0] = (s)[2]; (d)[1] = (s)[1]; (d)[2] = (s)[0]; } while (0)
196
 
#define CS_MOVE_DISK_4(d, s)    do { (d)[0] = (s)[3]; (d)[1] = (s)[2]; (d)[2] = (s)[1]; (d)[3] = (s)[0]; } while (0)
197
 
#define CS_MOVE_DISK_8(d, s)    do { (d)[0] = (s)[7]; (d)[1] = (s)[6]; \
198
 
                                                                         (d)[2] = (s)[5]; (d)[3] = (s)[4]; \
199
 
                                                                         (d)[4] = (s)[3]; (d)[5] = (s)[2]; \
200
 
                                                                         (d)[6] = (s)[1]; (d)[7] = (s)[0]; } while (0)
201
 
 
202
 
/*
203
 
 * Copy just copies the number of bytes assuming the data is not alligned.
204
 
 */
205
 
#define CS_COPY_DISK_1(d, s)    (d)[0] = s
206
 
#define CS_COPY_DISK_2(d, s)    do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; } while (0)
207
 
#define CS_COPY_DISK_3(d, s)    do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; } while (0)
208
 
#define CS_COPY_DISK_4(d, s)    do { (d)[0] = (s)[0]; (d)[1] = (s)[1]; (d)[2] = (s)[2]; (d)[3] = (s)[3]; } while (0)
209
 
#define CS_COPY_DISK_6(d, s)    memcpy(&((d)[0]), &((s)[0]), 6)
210
 
#define CS_COPY_DISK_8(d, s)    memcpy(&((d)[0]), &((s)[0]), 8)
211
 
#define CS_COPY_DISK_10(d, s)   memcpy(&((d)[0]), &((s)[0]), 10)
212
 
 
213
 
#define CS_SET_NULL_DISK_1(d)   CS_SET_DISK_1(d, 0)
214
 
#define CS_SET_NULL_DISK_2(d)   do { (d)[0] = 0; (d)[1] = 0; } while (0)
215
 
#define CS_SET_NULL_DISK_4(d)   do { (d)[0] = 0; (d)[1] = 0; (d)[2] = 0; (d)[3] = 0; } while (0)
216
 
#define CS_SET_NULL_DISK_6(d)   do { (d)[0] = 0; (d)[1] = 0; (d)[2] = 0; (d)[3] = 0; (d)[4] = 0; (d)[5] = 0; } while (0)
217
 
#define CS_SET_NULL_DISK_8(d)   do { (d)[0] = 0; (d)[1] = 0; (d)[2] = 0; (d)[3] = 0; (d)[4] = 0; (d)[5] = 0; (d)[6] = 0; (d)[7] = 0; } while (0)
218
 
 
219
 
#define CS_IS_NULL_DISK_1(d)    (!(CS_GET_DISK_1(d)))
220
 
#define CS_IS_NULL_DISK_4(d)    (!(d)[0] && !(d)[1] && !(d)[2] && !(d)[3])
221
 
#define CS_IS_NULL_DISK_8(d)    (!(d)[0] && !(d)[1] && !(d)[2] && !(d)[3] && !(d)[4] && !(d)[5] && !(d)[6] && !(7)[3])
222
 
 
223
 
#define CS_EQ_DISK_4(d, s)              ((d)[0] == (s)[0] && (d)[1] == (s)[1] && (d)[2] == (s)[2] && (d)[3] == (s)[3])
224
 
#define CS_EQ_DISK_8(d, s)              ((d)[0] == (s)[0] && (d)[1] == (s)[1] && (d)[2] == (s)[2] && (d)[3] == (s)[3] && \
225
 
                                                                (d)[4] == (s)[4] && (d)[5] == (s)[5] && (d)[6] == (s)[6] && (d)[7] == (s)[7])
226
 
 
227
 
#define CS_IS_FF_DISK_4(d)              ((d)[0] == 0xFF && (d)[1] == 0xFF && (d)[2] == 0xFF && (d)[3] == 0xFF)
228
 
#else
229
 
/*
230
 
 * The native order of the machine is little endian. This means the data to
231
 
 * and from disk need not be swapped. In addition to this, since
232
 
 * the i386 can access non-aligned memory we are not required to
233
 
 * handle the data byte-for-byte.
234
 
 */
235
 
#define CS_SET_DISK_1(d, s)             ((d)[0] = (uint8_t) (s))
236
 
#define CS_SET_DISK_2(d, s)             (*((uint16_t *) &((d)[0])) = (uint16_t) (s))
237
 
#define CS_SET_DISK_3(d, s)             do { (*((uint16_t *) &((d)[0])) = (uint16_t) (s));  *((uint8_t *) &((d)[2])) = (uint8_t) (((uint32_t) (s)) >> 16); } while (0)
238
 
#define CS_SET_DISK_4(d, s)             (*((uint32_t *) &((d)[0])) = (uint32_t) (s))
239
 
#define CS_SET_DISK_6(d, s)             do { *((uint32_t *) &((d)[0])) = (uint32_t) (s); *((uint16_t *) &((d)[4])) = (uint16_t) (((uint64_t) (s)) >> 32); } while (0)
240
 
#define CS_SET_DISK_8(d, s)             (*((uint64_t *) &((d)[0])) = (uint64_t) (s))
241
 
 
242
 
#define CS_GET_DISK_1(s)                ((s)[0])
243
 
#define CS_GET_DISK_2(s)                *((uint16_t *) &((s)[0]))
244
 
#define CS_GET_DISK_3(s)                ((uint32_t) *((uint16_t *) &((s)[0])) | (((uint32_t) *((uint8_t *) &((s)[2]))) << 16))
245
 
#define CS_GET_DISK_4(s)                *((uint32_t *) &((s)[0]))
246
 
#define CS_GET_DISK_6(s)                ((uint64_t) *((uint32_t *) &((s)[0])) | (((uint64_t) *((uint16_t *) &((s)[4]))) << 32))
247
 
#define CS_GET_DISK_8(s)                *((uint64_t *) &((s)[0]))
248
 
 
249
 
#define CS_MOVE_DISK_1(d, s)    ((d)[0] = (s)[0])
250
 
#define CS_MOVE_DISK_2(d, s)    CS_COPY_DISK_2(d, s)
251
 
#define CS_MOVE_DISK_3(d, s)    CS_COPY_DISK_3(d, s)
252
 
#define CS_MOVE_DISK_4(d, s)    CS_COPY_DISK_4(d, s)
253
 
#define CS_MOVE_DISK_8(d, s)    CS_COPY_DISK_8(d, s)
254
 
 
255
 
#define CS_COPY_DISK_1(d, s)    (d)[0] = s
256
 
#define CS_COPY_DISK_2(d, s)    (*((uint16_t *) &((d)[0])) = (*((uint16_t *) &((s)[0]))))
257
 
#define CS_COPY_DISK_3(d, s)    do { *((uint16_t *) &((d)[0])) = *((uint16_t *) &((s)[0])); (d)[2] = (s)[2]; } while (0)
258
 
#define CS_COPY_DISK_4(d, s)    (*((uint32_t *) &((d)[0])) = (*((uint32_t *) &((s)[0]))))
259
 
#define CS_COPY_DISK_6(d, s)    do { *((uint32_t *) &((d)[0])) = *((uint32_t *) &((s)[0])); *((uint16_t *) &((d)[4])) = *((uint16_t *) &((s)[4])); } while (0)
260
 
#define CS_COPY_DISK_8(d, s)    (*((uint64_t *) &(d[0])) = (*((uint64_t *) &((s)[0]))))
261
 
#define CS_COPY_DISK_10(d, s)   memcpy(&((d)[0]), &((s)[0]), 10)
262
 
 
263
 
#define CS_SET_NULL_DISK_1(d)   CS_SET_DISK_1(d, 0)
264
 
#define CS_SET_NULL_DISK_2(d)   CS_SET_DISK_2(d, 0)
265
 
#define CS_SET_NULL_DISK_3(d)   CS_SET_DISK_3(d, 0)
266
 
#define CS_SET_NULL_DISK_4(d)   CS_SET_DISK_4(d, 0L)
267
 
#define CS_SET_NULL_DISK_6(d)   CS_SET_DISK_6(d, 0LL)
268
 
#define CS_SET_NULL_DISK_8(d)   CS_SET_DISK_8(d, 0LL)
269
 
 
270
 
#define CS_IS_NULL_DISK_1(d)    (!(CS_GET_DISK_1(d)))
271
 
#define CS_IS_NULL_DISK_2(d)    (!(CS_GET_DISK_2(d)))
272
 
#define CS_IS_NULL_DISK_3(d)    (!(CS_GET_DISK_3(d)))
273
 
#define CS_IS_NULL_DISK_4(d)    (!(CS_GET_DISK_4(d)))
274
 
#define CS_IS_NULL_DISK_8(d)    (!(CS_GET_DISK_8(d)))
275
 
 
276
 
#define CS_EQ_DISK_4(d, s)              (CS_GET_DISK_4(d) == CS_GET_DISK_4(s))
277
 
#define CS_EQ_DISK_8(d, s)              (CS_GET_DISK_8(d) == CS_GET_DISK_8(s))
278
 
 
279
 
#define CS_IS_FF_DISK_4(d)              (CS_GET_DISK_4(d) == 0xFFFFFFFF)
280
 
#endif
281
 
 
282
 
#define CS_CMP_DISK_4(a, b)             ((int32_t) CS_GET_DISK_4(a) - (int32_t) CS_GET_DISK_4(b))
283
 
#define CS_CMP_DISK_8(d, s)             memcmp(&((d)[0]), &((s)[0]), 8)
284
 
//#define CS_CMP_DISK_8(d, s)           (CS_CMP_DISK_4((d).h_number_4, (s).h_number_4) == 0 ? CS_CMP_DISK_4((d).h_file_4, (s).h_file_4) : CS_CMP_DISK_4((d).h_number_4, (s).h_number_4))
285
 
 
286
 
#define CS_SWAP_DISK_2(d, s)    do { (d)[0] = (s)[1]; (d)[1] = (s)[0]; } while (0)
287
 
#define CS_SWAP_DISK_3(d, s)    do { (d)[0] = (s)[2]; (d)[1] = (s)[1]; (d)[2] = (s)[0]; } while (0)
288
 
#define CS_SWAP_DISK_4(d, s)    do { (d)[0] = (s)[3]; (d)[1] = (s)[2]; (d)[2] = (s)[1]; (d)[3] = (s)[0]; } while (0)
289
 
#define CS_SWAP_DISK_8(d, s)    do { (d)[0] = (s)[7]; (d)[1] = (s)[6]; (d)[2] = (s)[5]; (d)[3] = (s)[4]; \
290
 
                                                                         (d)[4] = (s)[3]; (d)[5] = (s)[2]; (d)[6] = (s)[1]; (d)[7] = (s)[0]; } while (0)
291
 
 
292
 
typedef union {
293
 
        CSDiskValue1 val_1;
294
 
        CSDiskValue4 val_4;
295
 
} CSIntRec, *CSIntPtr;
296
 
 
297
 
typedef union {
298
 
                const char *rec_cchars;
299
 
                char *rec_chars;
300
 
                CSIntPtr int_val;
301
 
} CSDiskData;
302
 
        
303
 
#endif