1 /* 2 Bacula(R) - The Network Backup Solution 3 4 Copyright (C) 2000-2020 Kern Sibbald 5 6 The original author of Bacula is Kern Sibbald, with contributions 7 from many others, a complete list can be found in the file AUTHORS. 8 9 You may use this file and others of this release according to the 10 license defined in the LICENSE file, which includes the Affero General 11 Public License, v3.0 ("AGPLv3") and some additional permissions and 12 terms pursuant to its AGPLv3 Section 7. 13 14 This notice must be preserved when any source code is 15 conveyed and/or propagated. 16 17 Bacula(R) is a registered trademark of Kern Sibbald. 18 */ 19 /* 20 Define integer types for Bacula -- Kern Sibbald 21 22 Integer types. These types should be be used in all 23 contexts in which the length of an integer stored on 24 removable media must be known regardless of the 25 architecture of the platform. 26 27 Bacula types are: 28 29 int8_t, int16_t, int32_t, int64_t 30 uint8_t, uint16_t, uint32_t, uint64_t 31 32 Also, we define types such as file address lengths. 33 */ 34 35 36 #ifndef __bc_types_INCLUDED 37 #define __bc_types_INCLUDED 38 39 /* 40 * These are the sizes of the current definitions of database 41 * Ids. In general, FileId_t can be set to uint64_t and it 42 * *should* work. Users have reported back that it does work 43 * for PostgreSQL. For the other types, all places in Bacula 44 * have been converted, but no one has actually tested it. 45 * In principle, the only field that really should need to be 46 * 64 bits is the FileId_t 47 */ 48 typedef uint64_t FileId_t; 49 typedef uint32_t DBId_t; /* general DB id type */ 50 typedef uint32_t JobId_t; 51 52 53 typedef char POOLMEM; 54 55 56 /* Types */ 57 58 /* If sys/types.h does not supply intXX_t, supply them ourselves */ 59 /* (or die trying) */ 60 61 #ifndef HAVE_U_INT 62 typedef unsigned int u_int; 63 #endif 64 65 #ifndef HAVE_INTXX_T 66 # if (SIZEOF_CHAR == 1) 67 typedef signed char int8_t; 68 # else 69 # error "8 bit int type not found." 70 # endif 71 # if (SIZEOF_SHORT_INT == 2) 72 typedef short int int16_t; 73 # else 74 # error "16 bit int type not found." 75 # endif 76 # if (SIZEOF_INT == 4) 77 typedef int int32_t; 78 # else 79 # error "32 bit int type not found." 80 # endif 81 #endif 82 83 /* If sys/types.h does not supply u_intXX_t, supply them ourselves */ 84 #ifndef HAVE_U_INTXX_T 85 # ifdef HAVE_UINTXX_T 86 typedef uint8_t u_int8_t; 87 typedef uint16_t u_int16_t; 88 typedef uint32_t u_int32_t; 89 # define HAVE_U_INTXX_T 1 90 # else 91 # if (SIZEOF_CHAR == 1) 92 typedef unsigned char u_int8_t; 93 # else 94 # error "8 bit int type not found. Required!" 95 # endif 96 # if (SIZEOF_SHORT_INT == 2) 97 typedef unsigned short int u_int16_t; 98 # else 99 # error "16 bit int type not found. Required!" 100 # endif 101 # if (SIZEOF_INT == 4) 102 typedef unsigned int u_int32_t; 103 # else 104 # error "32 bit int type not found. Required!" 105 # endif 106 # endif 107 #endif 108 109 /* 64-bit types */ 110 #ifndef HAVE_INT64_T 111 # if (SIZEOF_LONG_LONG_INT == 8) 112 typedef long long int int64_t; 113 # define HAVE_INT64_T 1 114 # else 115 # if (SIZEOF_LONG_INT == 8) 116 typedef long int int64_t; 117 # define HAVE_INT64_T 1 118 # endif 119 # endif 120 #endif 121 122 #ifndef HAVE_INTMAX_T 123 # ifdef HAVE_INT64_T 124 typedef int64_t intmax_t; 125 # else 126 # error "64 bit type not found. Required!" 127 # endif 128 #endif 129 130 #ifndef HAVE_U_INT64_T 131 # if (SIZEOF_LONG_LONG_INT == 8) 132 typedef unsigned long long int u_int64_t; 133 # define HAVE_U_INT64_T 1 134 # else 135 # if (SIZEOF_LONG_INT == 8) 136 typedef unsigned long int u_int64_t; 137 # define HAVE_U_INT64_T 1 138 # else 139 # error "64 bit type not found. Required!" 140 # endif 141 # endif 142 #endif 143 144 #ifndef HAVE_U_INTMAX_T 145 # ifdef HAVE_U_INT64_T 146 typedef u_int64_t u_intmax_t; 147 # else 148 # error "64 bit type not found. Required!" 149 # endif 150 #endif 151 152 #ifndef HAVE_INTPTR_T 153 #define HAVE_INTPTR_T 1 154 # if (SIZEOF_INT_P == 4) 155 typedef int32_t intptr_t; 156 # else 157 # if (SIZEOF_INT_P == 8) 158 typedef int64_t intptr_t; 159 # else 160 # error "Can't find sizeof pointer. Required!" 161 # endif 162 # endif 163 #endif 164 165 #ifndef HAVE_UINTPTR_T 166 #define HAVE_UINTPTR_T 1 167 # if (SIZEOF_INT_P == 4) 168 typedef uint32_t uintptr_t; 169 # else 170 # if (SIZEOF_INT_P == 8) 171 typedef uint64_t uintptr_t; 172 # else 173 # error "Can't find sizeof pointer. Required!" 174 # endif 175 # endif 176 #endif 177 178 /* Limits for the above types. */ 179 #undef INT8_MIN 180 #undef INT8_MAX 181 #undef UINT8_MAX 182 #undef INT16_MIN 183 #undef INT16_MAX 184 #undef UINT16_MAX 185 #undef INT32_MIN 186 #undef INT32_MAX 187 #undef UINT32_MAX 188 189 #define INT8_MIN (-127-1) 190 #define INT8_MAX (127) 191 #define UINT8_MAX (255u) 192 #define INT16_MIN (-32767-1) 193 #define INT16_MAX (32767) 194 #define UINT16_MAX (65535u) 195 #define INT32_MIN (-2147483647-1) 196 #define INT32_MAX (2147483647) 197 #define UINT32_MAX (4294967295u) 198 199 typedef double float64_t; 200 typedef float float32_t; 201 202 203 /* Define the uint versions actually used in Bacula */ 204 #ifndef uint8_t 205 #define uint8_t u_int8_t 206 #define uint16_t u_int16_t 207 #define uint32_t u_int32_t 208 #define uint64_t u_int64_t 209 #define uintmax_t u_intmax_t 210 #endif 211 212 /* Bacula time -- Unix time with microseconds */ 213 #define btime_t int64_t 214 /* Unix time (time_t) widened to 64 bits */ 215 #define utime_t int64_t 216 217 #ifndef HAVE_SOCKLEN_T 218 #define socklen_t int 219 #endif 220 221 #ifndef HAVE_WIN32 222 #ifndef SOCKET_ERROR 223 #define SOCKET_ERROR (-1) 224 #endif 225 #endif 226 227 #ifdef HAVE_OLD_SOCKOPT 228 #define sockopt_val_t char * 229 #else 230 #define sockopt_val_t void * 231 #endif 232 233 /* 234 * Status codes returned by create_file() 235 * Used in findlib, filed, and plugins 236 */ 237 enum { 238 CF_SKIP = 1, /* skip file (not newer or something) */ 239 CF_ERROR, /* error creating file */ 240 CF_EXTRACT, /* file created, data to extract */ 241 CF_CREATED, /* file created, no data to extract */ 242 CF_CORE /* let bacula core handle the file creation */ 243 }; 244 245 #ifndef MAX 246 #define MAX(a, b) ((a) > (b) ? (a) : (b)) 247 #endif 248 #ifndef MIN 249 #define MIN(a, b) ((a) < (b) ? (a) : (b)) 250 #endif 251 252 #endif /* __bc_types_INCLUDED */ 253