101
** The default size of a disk sector
103
#ifndef SQLITE_DEFAULT_SECTOR_SIZE
104
# define SQLITE_DEFAULT_SECTOR_SIZE 512
77
108
** Temporary files are named starting with this prefix followed by 16 random
78
109
** alphanumeric characters, and no file extension. They are stored in the
79
110
** OS's standard temporary file directory, and are deleted prior to exit.
80
111
** If sqlite is being embedded in another program, you may wish to change the
81
112
** prefix to reflect your program's name, so that if your program exits
82
113
** prematurely, old temporary files can be easily identified. This can be done
83
** using -DTEMP_FILE_PREFIX=myprefix_ on the compiler command line.
85
#ifndef TEMP_FILE_PREFIX
86
# define TEMP_FILE_PREFIX "sqlite_"
90
** Define the interfaces for Unix, Windows, and OS/2.
93
#define sqlite3OsOpenReadWrite sqlite3UnixOpenReadWrite
94
#define sqlite3OsOpenExclusive sqlite3UnixOpenExclusive
95
#define sqlite3OsOpenReadOnly sqlite3UnixOpenReadOnly
96
#define sqlite3OsDelete sqlite3UnixDelete
97
#define sqlite3OsFileExists sqlite3UnixFileExists
98
#define sqlite3OsFullPathname sqlite3UnixFullPathname
99
#define sqlite3OsIsDirWritable sqlite3UnixIsDirWritable
100
#define sqlite3OsSyncDirectory sqlite3UnixSyncDirectory
101
#define sqlite3OsTempFileName sqlite3UnixTempFileName
102
#define sqlite3OsRandomSeed sqlite3UnixRandomSeed
103
#define sqlite3OsSleep sqlite3UnixSleep
104
#define sqlite3OsCurrentTime sqlite3UnixCurrentTime
105
#define sqlite3OsEnterMutex sqlite3UnixEnterMutex
106
#define sqlite3OsLeaveMutex sqlite3UnixLeaveMutex
107
#define sqlite3OsInMutex sqlite3UnixInMutex
108
#define sqlite3OsThreadSpecificData sqlite3UnixThreadSpecificData
109
#define sqlite3OsMalloc sqlite3GenericMalloc
110
#define sqlite3OsRealloc sqlite3GenericRealloc
111
#define sqlite3OsFree sqlite3GenericFree
112
#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
115
#define sqlite3OsOpenReadWrite sqlite3WinOpenReadWrite
116
#define sqlite3OsOpenExclusive sqlite3WinOpenExclusive
117
#define sqlite3OsOpenReadOnly sqlite3WinOpenReadOnly
118
#define sqlite3OsDelete sqlite3WinDelete
119
#define sqlite3OsFileExists sqlite3WinFileExists
120
#define sqlite3OsFullPathname sqlite3WinFullPathname
121
#define sqlite3OsIsDirWritable sqlite3WinIsDirWritable
122
#define sqlite3OsSyncDirectory sqlite3WinSyncDirectory
123
#define sqlite3OsTempFileName sqlite3WinTempFileName
124
#define sqlite3OsRandomSeed sqlite3WinRandomSeed
125
#define sqlite3OsSleep sqlite3WinSleep
126
#define sqlite3OsCurrentTime sqlite3WinCurrentTime
127
#define sqlite3OsEnterMutex sqlite3WinEnterMutex
128
#define sqlite3OsLeaveMutex sqlite3WinLeaveMutex
129
#define sqlite3OsInMutex sqlite3WinInMutex
130
#define sqlite3OsThreadSpecificData sqlite3WinThreadSpecificData
131
#define sqlite3OsMalloc sqlite3GenericMalloc
132
#define sqlite3OsRealloc sqlite3GenericRealloc
133
#define sqlite3OsFree sqlite3GenericFree
134
#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
137
#define sqlite3OsOpenReadWrite sqlite3Os2OpenReadWrite
138
#define sqlite3OsOpenExclusive sqlite3Os2OpenExclusive
139
#define sqlite3OsOpenReadOnly sqlite3Os2OpenReadOnly
140
#define sqlite3OsDelete sqlite3Os2Delete
141
#define sqlite3OsFileExists sqlite3Os2FileExists
142
#define sqlite3OsFullPathname sqlite3Os2FullPathname
143
#define sqlite3OsIsDirWritable sqlite3Os2IsDirWritable
144
#define sqlite3OsSyncDirectory sqlite3Os2SyncDirectory
145
#define sqlite3OsTempFileName sqlite3Os2TempFileName
146
#define sqlite3OsRandomSeed sqlite3Os2RandomSeed
147
#define sqlite3OsSleep sqlite3Os2Sleep
148
#define sqlite3OsCurrentTime sqlite3Os2CurrentTime
149
#define sqlite3OsEnterMutex sqlite3Os2EnterMutex
150
#define sqlite3OsLeaveMutex sqlite3Os2LeaveMutex
151
#define sqlite3OsInMutex sqlite3Os2InMutex
152
#define sqlite3OsThreadSpecificData sqlite3Os2ThreadSpecificData
153
#define sqlite3OsMalloc sqlite3GenericMalloc
154
#define sqlite3OsRealloc sqlite3GenericRealloc
155
#define sqlite3OsFree sqlite3GenericFree
156
#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
163
** If using an alternative OS interface, then we must have an "os_other.h"
164
** header file available for that interface. Presumably the "os_other.h"
165
** header file contains #defines similar to those above.
168
# include "os_other.h"
174
** Forward declarations
176
typedef struct OsFile OsFile;
177
typedef struct IoMethod IoMethod;
180
** An instance of the following structure contains pointers to all
181
** methods on an OsFile object.
184
int (*xClose)(OsFile**);
185
int (*xOpenDirectory)(OsFile*, const char*);
186
int (*xRead)(OsFile*, void*, int amt);
187
int (*xWrite)(OsFile*, const void*, int amt);
188
int (*xSeek)(OsFile*, i64 offset);
189
int (*xTruncate)(OsFile*, i64 size);
190
int (*xSync)(OsFile*, int);
191
void (*xSetFullSync)(OsFile *id, int setting);
192
int (*xFileHandle)(OsFile *id);
193
int (*xFileSize)(OsFile*, i64 *pSize);
194
int (*xLock)(OsFile*, int);
195
int (*xUnlock)(OsFile*, int);
196
int (*xLockState)(OsFile *id);
197
int (*xCheckReservedLock)(OsFile *id);
201
** The OsFile object describes an open disk file in an OS-dependent way.
202
** The version of OsFile defined here is a generic version. Each OS
203
** implementation defines its own subclass of this structure that contains
204
** additional information needed to handle file I/O. But the pMethod
205
** entry (pointing to the virtual function table) always occurs first
206
** so that we can always find the appropriate methods.
209
IoMethod const *pMethod;
114
** using -DSQLITE_TEMP_FILE_PREFIX=myprefix_ on the compiler command line.
116
** 2006-10-31: The default prefix used to be "sqlite_". But then
117
** Mcafee started using SQLite in their anti-virus product and it
118
** started putting files with the "sqlite" name in the c:/temp folder.
119
** This annoyed many windows users. Those users would then do a
120
** Google search for "sqlite", find the telephone numbers of the
121
** developers and call to wake them up at night and complain.
122
** For this reason, the default name prefix is changed to be "sqlite"
123
** spelled backwards. So the temp files are still identified, but
124
** anybody smart enough to figure out the code is also likely smart
125
** enough to know that calling the developer will not help get rid
128
#ifndef SQLITE_TEMP_FILE_PREFIX
129
# define SQLITE_TEMP_FILE_PREFIX "etilqs_"
213
133
** The following values may be passed as the second argument to
300
220
#define SHARED_FIRST (PENDING_BYTE+2)
301
221
#define SHARED_SIZE 510
304
** Prototypes for operating system interface routines.
306
int sqlite3OsClose(OsFile**);
307
int sqlite3OsOpenDirectory(OsFile*, const char*);
308
int sqlite3OsRead(OsFile*, void*, int amt);
309
int sqlite3OsWrite(OsFile*, const void*, int amt);
310
int sqlite3OsSeek(OsFile*, i64 offset);
311
int sqlite3OsTruncate(OsFile*, i64 size);
312
int sqlite3OsSync(OsFile*, int);
313
void sqlite3OsSetFullSync(OsFile *id, int setting);
314
int sqlite3OsFileHandle(OsFile *id);
315
int sqlite3OsFileSize(OsFile*, i64 *pSize);
316
int sqlite3OsLock(OsFile*, int);
317
int sqlite3OsUnlock(OsFile*, int);
318
int sqlite3OsLockState(OsFile *id);
319
int sqlite3OsCheckReservedLock(OsFile *id);
320
int sqlite3OsOpenReadWrite(const char*, OsFile**, int*);
321
int sqlite3OsOpenExclusive(const char*, OsFile**, int);
322
int sqlite3OsOpenReadOnly(const char*, OsFile**);
323
int sqlite3OsDelete(const char*);
324
int sqlite3OsFileExists(const char*);
325
char *sqlite3OsFullPathname(const char*);
326
int sqlite3OsIsDirWritable(char*);
327
int sqlite3OsSyncDirectory(const char*);
328
int sqlite3OsTempFileName(char*);
329
int sqlite3OsRandomSeed(char*);
330
int sqlite3OsSleep(int ms);
331
int sqlite3OsCurrentTime(double*);
332
void sqlite3OsEnterMutex(void);
333
void sqlite3OsLeaveMutex(void);
334
int sqlite3OsInMutex(int);
335
ThreadData *sqlite3OsThreadSpecificData(int);
336
void *sqlite3OsMalloc(int);
337
void *sqlite3OsRealloc(void *, int);
338
void sqlite3OsFree(void *);
339
int sqlite3OsAllocationSize(void *);
342
** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer
343
** interface routines are not called directly but are invoked using
344
** pointers to functions. This allows the implementation of various
345
** OS-layer interface routines to be modified at run-time. There are
346
** obscure but legitimate reasons for wanting to do this. But for
347
** most users, a direct call to the underlying interface is preferable
348
** so the the redefinable I/O interface is turned off by default.
350
#ifdef SQLITE_ENABLE_REDEF_IO
353
** When redefinable I/O is enabled, a single global instance of the
354
** following structure holds pointers to the routines that SQLite
355
** uses to talk with the underlying operating system. Modify this
356
** structure (before using any SQLite API!) to accomodate perculiar
357
** operating system interfaces or behaviors.
359
struct sqlite3OsVtbl {
360
int (*xOpenReadWrite)(const char*, OsFile**, int*);
361
int (*xOpenExclusive)(const char*, OsFile**, int);
362
int (*xOpenReadOnly)(const char*, OsFile**);
364
int (*xDelete)(const char*);
365
int (*xFileExists)(const char*);
366
char *(*xFullPathname)(const char*);
367
int (*xIsDirWritable)(char*);
368
int (*xSyncDirectory)(const char*);
369
int (*xTempFileName)(char*);
371
int (*xRandomSeed)(char*);
372
int (*xSleep)(int ms);
373
int (*xCurrentTime)(double*);
375
void (*xEnterMutex)(void);
376
void (*xLeaveMutex)(void);
377
int (*xInMutex)(int);
378
ThreadData *(*xThreadSpecificData)(int);
380
void *(*xMalloc)(int);
381
void *(*xRealloc)(void *, int);
382
void (*xFree)(void *);
383
int (*xAllocationSize)(void *);
386
/* Macro used to comment out routines that do not exists when there is
389
#ifdef SQLITE_OMIT_DISKIO
390
# define IF_DISKIO(X) 0
392
# define IF_DISKIO(X) X
397
** The os.c file implements the global virtual function table.
399
struct sqlite3OsVtbl sqlite3Os = {
400
IF_DISKIO( sqlite3OsOpenReadWrite ),
401
IF_DISKIO( sqlite3OsOpenExclusive ),
402
IF_DISKIO( sqlite3OsOpenReadOnly ),
403
IF_DISKIO( sqlite3OsDelete ),
404
IF_DISKIO( sqlite3OsFileExists ),
405
IF_DISKIO( sqlite3OsFullPathname ),
406
IF_DISKIO( sqlite3OsIsDirWritable ),
407
IF_DISKIO( sqlite3OsSyncDirectory ),
408
IF_DISKIO( sqlite3OsTempFileName ),
411
sqlite3OsCurrentTime,
415
sqlite3OsThreadSpecificData,
419
sqlite3OsAllocationSize
423
** Files other than os.c just reference the global virtual function table.
425
extern struct sqlite3OsVtbl sqlite3Os;
426
#endif /* _SQLITE_OS_C_ */
429
/* This additional API routine is available with redefinable I/O */
430
struct sqlite3OsVtbl *sqlite3_os_switch(void);
434
** Redefine the OS interface to go through the virtual function table
435
** rather than calling routines directly.
437
#undef sqlite3OsOpenReadWrite
438
#undef sqlite3OsOpenExclusive
439
#undef sqlite3OsOpenReadOnly
440
#undef sqlite3OsDelete
441
#undef sqlite3OsFileExists
442
#undef sqlite3OsFullPathname
443
#undef sqlite3OsIsDirWritable
444
#undef sqlite3OsSyncDirectory
445
#undef sqlite3OsTempFileName
446
#undef sqlite3OsRandomSeed
447
#undef sqlite3OsSleep
448
#undef sqlite3OsCurrentTime
449
#undef sqlite3OsEnterMutex
450
#undef sqlite3OsLeaveMutex
451
#undef sqlite3OsInMutex
452
#undef sqlite3OsThreadSpecificData
453
#undef sqlite3OsMalloc
454
#undef sqlite3OsRealloc
456
#undef sqlite3OsAllocationSize
457
#define sqlite3OsOpenReadWrite sqlite3Os.xOpenReadWrite
458
#define sqlite3OsOpenExclusive sqlite3Os.xOpenExclusive
459
#define sqlite3OsOpenReadOnly sqlite3Os.xOpenReadOnly
460
#define sqlite3OsDelete sqlite3Os.xDelete
461
#define sqlite3OsFileExists sqlite3Os.xFileExists
462
#define sqlite3OsFullPathname sqlite3Os.xFullPathname
463
#define sqlite3OsIsDirWritable sqlite3Os.xIsDirWritable
464
#define sqlite3OsSyncDirectory sqlite3Os.xSyncDirectory
465
#define sqlite3OsTempFileName sqlite3Os.xTempFileName
466
#define sqlite3OsRandomSeed sqlite3Os.xRandomSeed
467
#define sqlite3OsSleep sqlite3Os.xSleep
468
#define sqlite3OsCurrentTime sqlite3Os.xCurrentTime
469
#define sqlite3OsEnterMutex sqlite3Os.xEnterMutex
470
#define sqlite3OsLeaveMutex sqlite3Os.xLeaveMutex
471
#define sqlite3OsInMutex sqlite3Os.xInMutex
472
#define sqlite3OsThreadSpecificData sqlite3Os.xThreadSpecificData
473
#define sqlite3OsMalloc sqlite3Os.xMalloc
474
#define sqlite3OsRealloc sqlite3Os.xRealloc
475
#define sqlite3OsFree sqlite3Os.xFree
476
#define sqlite3OsAllocationSize sqlite3Os.xAllocationSize
478
#endif /* SQLITE_ENABLE_REDEF_IO */
224
** Functions for accessing sqlite3_file methods
226
int sqlite3OsClose(sqlite3_file*);
227
int sqlite3OsRead(sqlite3_file*, void*, int amt, i64 offset);
228
int sqlite3OsWrite(sqlite3_file*, const void*, int amt, i64 offset);
229
int sqlite3OsTruncate(sqlite3_file*, i64 size);
230
int sqlite3OsSync(sqlite3_file*, int);
231
int sqlite3OsFileSize(sqlite3_file*, i64 *pSize);
232
int sqlite3OsLock(sqlite3_file*, int);
233
int sqlite3OsUnlock(sqlite3_file*, int);
234
int sqlite3OsCheckReservedLock(sqlite3_file *id);
235
int sqlite3OsFileControl(sqlite3_file*,int,void*);
236
int sqlite3OsSectorSize(sqlite3_file *id);
237
int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
240
** Functions for accessing sqlite3_vfs methods
242
int sqlite3OsOpen(sqlite3_vfs *, const char *, sqlite3_file*, int, int *);
243
int sqlite3OsDelete(sqlite3_vfs *, const char *, int);
244
int sqlite3OsAccess(sqlite3_vfs *, const char *, int);
245
int sqlite3OsGetTempname(sqlite3_vfs *, int, char *);
246
int sqlite3OsFullPathname(sqlite3_vfs *, const char *, int, char *);
247
void *sqlite3OsDlOpen(sqlite3_vfs *, const char *);
248
void sqlite3OsDlError(sqlite3_vfs *, int, char *);
249
void *sqlite3OsDlSym(sqlite3_vfs *, void *, const char *);
250
void sqlite3OsDlClose(sqlite3_vfs *, void *);
251
int sqlite3OsRandomness(sqlite3_vfs *, int, char *);
252
int sqlite3OsSleep(sqlite3_vfs *, int);
253
int sqlite3OsCurrentTime(sqlite3_vfs *, double*);
256
** Convenience functions for opening and closing files using
257
** sqlite3_malloc() to obtain space for the file-handle structure.
259
int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int,int*);
260
int sqlite3OsCloseFree(sqlite3_file *);
263
** Each OS-specific backend defines an instance of the following
264
** structure for returning a pointer to its sqlite3_vfs. If OS_OTHER
265
** is defined (meaning that the application-defined OS interface layer
266
** is used) then there is no default VFS. The application must
267
** register one or more VFS structures using sqlite3_vfs_register()
268
** before attempting to use SQLite.
270
sqlite3_vfs *sqlite3OsDefaultVfs(void);
480
272
#endif /* _SQLITE_OS_H_ */