# define TEMP_FILE_PREFIX "etilqs_"
#endif
-#if 0
-
-/*
-** Define the interfaces for Unix, Windows, and OS/2.
-*/
-#if OS_UNIX
-#define sqlite3OsOpenReadWrite sqlite3UnixOpenReadWrite
-#define sqlite3OsOpenExclusive sqlite3UnixOpenExclusive
-#define sqlite3OsOpenReadOnly sqlite3UnixOpenReadOnly
-#define sqlite3OsDelete sqlite3UnixDelete
-#define sqlite3OsFileExists sqlite3UnixFileExists
-#define sqlite3OsFullPathname sqlite3UnixFullPathname
-#define sqlite3OsIsDirWritable sqlite3UnixIsDirWritable
-#define sqlite3OsSyncDirectory sqlite3UnixSyncDirectory
-#define sqlite3OsTempFileName sqlite3UnixTempFileName
-#define sqlite3OsRandomSeed sqlite3UnixRandomSeed
-#define sqlite3OsSleep sqlite3UnixSleep
-#define sqlite3OsCurrentTime sqlite3UnixCurrentTime
-#define sqlite3OsEnterMutex sqlite3UnixEnterMutex
-#define sqlite3OsLeaveMutex sqlite3UnixLeaveMutex
-#define sqlite3OsInMutex sqlite3UnixInMutex
-#define sqlite3OsThreadSpecificData sqlite3UnixThreadSpecificData
-#define sqlite3OsMalloc sqlite3GenericMalloc
-#define sqlite3OsRealloc sqlite3GenericRealloc
-#define sqlite3OsFree sqlite3GenericFree
-#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
-#define sqlite3OsDlopen sqlite3UnixDlopen
-#define sqlite3OsDlsym sqlite3UnixDlsym
-#define sqlite3OsDlclose sqlite3UnixDlclose
-#endif
-#if OS_WIN
-#define sqlite3OsOpenReadWrite sqlite3WinOpenReadWrite
-#define sqlite3OsOpenExclusive sqlite3WinOpenExclusive
-#define sqlite3OsOpenReadOnly sqlite3WinOpenReadOnly
-#define sqlite3OsDelete sqlite3WinDelete
-#define sqlite3OsFileExists sqlite3WinFileExists
-#define sqlite3OsFullPathname sqlite3WinFullPathname
-#define sqlite3OsIsDirWritable sqlite3WinIsDirWritable
-#define sqlite3OsSyncDirectory sqlite3WinSyncDirectory
-#define sqlite3OsTempFileName sqlite3WinTempFileName
-#define sqlite3OsRandomSeed sqlite3WinRandomSeed
-#define sqlite3OsSleep sqlite3WinSleep
-#define sqlite3OsCurrentTime sqlite3WinCurrentTime
-#define sqlite3OsEnterMutex sqlite3WinEnterMutex
-#define sqlite3OsLeaveMutex sqlite3WinLeaveMutex
-#define sqlite3OsInMutex sqlite3WinInMutex
-#define sqlite3OsThreadSpecificData sqlite3WinThreadSpecificData
-#define sqlite3OsMalloc sqlite3GenericMalloc
-#define sqlite3OsRealloc sqlite3GenericRealloc
-#define sqlite3OsFree sqlite3GenericFree
-#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
-#define sqlite3OsDlopen sqlite3WinDlopen
-#define sqlite3OsDlsym sqlite3WinDlsym
-#define sqlite3OsDlclose sqlite3WinDlclose
-#endif
-#if OS_OS2
-#define sqlite3OsOpenReadWrite sqlite3Os2OpenReadWrite
-#define sqlite3OsOpenExclusive sqlite3Os2OpenExclusive
-#define sqlite3OsOpenReadOnly sqlite3Os2OpenReadOnly
-#define sqlite3OsDelete sqlite3Os2Delete
-#define sqlite3OsFileExists sqlite3Os2FileExists
-#define sqlite3OsFullPathname sqlite3Os2FullPathname
-#define sqlite3OsIsDirWritable sqlite3Os2IsDirWritable
-#define sqlite3OsSyncDirectory sqlite3Os2SyncDirectory
-#define sqlite3OsTempFileName sqlite3Os2TempFileName
-#define sqlite3OsRandomSeed sqlite3Os2RandomSeed
-#define sqlite3OsSleep sqlite3Os2Sleep
-#define sqlite3OsCurrentTime sqlite3Os2CurrentTime
-#define sqlite3OsEnterMutex sqlite3Os2EnterMutex
-#define sqlite3OsLeaveMutex sqlite3Os2LeaveMutex
-#define sqlite3OsInMutex sqlite3Os2InMutex
-#define sqlite3OsThreadSpecificData sqlite3Os2ThreadSpecificData
-#define sqlite3OsMalloc sqlite3GenericMalloc
-#define sqlite3OsRealloc sqlite3GenericRealloc
-#define sqlite3OsFree sqlite3GenericFree
-#define sqlite3OsAllocationSize sqlite3GenericAllocationSize
-#define sqlite3OsDlopen sqlite3Os2Dlopen
-#define sqlite3OsDlsym sqlite3Os2Dlsym
-#define sqlite3OsDlclose sqlite3Os2Dlclose
-#endif
-
-#endif
-
-
-
/*
** If using an alternative OS interface, then we must have an "os_other.h"
** header file available for that interface. Presumably the "os_other.h"
#endif
-
-/*
-** Forward declarations
-*/
-typedef struct OsFile OsFile;
-typedef struct IoMethod IoMethod;
-
-/*
-** An instance of the following structure contains pointers to all
-** methods on an OsFile object.
-*/
-struct IoMethod {
- int (*xClose)(OsFile**);
- int (*xOpenDirectory)(OsFile*, const char*);
- int (*xRead)(OsFile*, void*, int amt);
- int (*xWrite)(OsFile*, const void*, int amt);
- int (*xSeek)(OsFile*, i64 offset);
- int (*xTruncate)(OsFile*, i64 size);
- int (*xSync)(OsFile*, int);
- void (*xSetFullSync)(OsFile *id, int setting);
- int (*xFileHandle)(OsFile *id);
- int (*xFileSize)(OsFile*, i64 *pSize);
- int (*xLock)(OsFile*, int);
- int (*xUnlock)(OsFile*, int);
- int (*xLockState)(OsFile *id);
- int (*xCheckReservedLock)(OsFile *id);
- int (*xSectorSize)(OsFile *id);
-};
-
-/*
-** The OsFile object describes an open disk file in an OS-dependent way.
-** The version of OsFile defined here is a generic version. Each OS
-** implementation defines its own subclass of this structure that contains
-** additional information needed to handle file I/O. But the pMethod
-** entry (pointing to the virtual function table) always occurs first
-** so that we can always find the appropriate methods.
-*/
-struct OsFile {
- IoMethod const *pMethod;
-};
-
/*
** The following values may be passed as the second argument to
** sqlite3OsLock(). The various locks exhibit the following semantics:
int sqlite3OsUnlock(sqlite3_file*, int);
int sqlite3OsBreakLock(sqlite3_file*);
int sqlite3OsCheckReservedLock(sqlite3_file *id);
+int sqlite3OsLockState(sqlite3_file *id);
int sqlite3OsSectorSize(sqlite3_file *id);
int sqlite3OsDeviceCharacteristics(sqlite3_file *id);
int sqlite3OsOpenMalloc(sqlite3_vfs *, const char *, sqlite3_file **, int);
int sqlite3OsCloseFree(sqlite3_file *);
-#if 0
-int sqlite3OsOpenReadWrite(const char*, sqlite3_file**, int*);
-int sqlite3OsOpenExclusive(const char*, sqlite3_file**, int);
-int sqlite3OsOpenReadOnly(const char*, sqlite3_file**);
-int sqlite3OsDelete(const char*);
-int sqlite3OsFileExists(const char*);
-char *sqlite3OsFullPathname(const char*);
-int sqlite3OsIsDirWritable(char*);
-int sqlite3OsSyncDirectory(const char*);
-int sqlite3OsTempFileName(char*);
-int sqlite3OsRandomSeed(char*);
-int sqlite3OsSleep(int ms);
-int sqlite3OsCurrentTime(double*);
-void sqlite3OsEnterMutex(void);
-void sqlite3OsLeaveMutex(void);
-int sqlite3OsInMutex(int);
-ThreadData *sqlite3OsThreadSpecificData(int);
-void *sqlite3OsMalloc(int);
-void *sqlite3OsRealloc(void *, int);
-void sqlite3OsFree(void *);
-int sqlite3OsAllocationSize(void *);
-void *sqlite3OsDlopen(const char*);
-void *sqlite3OsDlsym(void*, const char*);
-int sqlite3OsDlclose(void*);
-#endif
-
#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
int sqlite3OsFileHandle(sqlite3_file *id);
int sqlite3OsLockState(sqlite3_file *id);
#endif
-/*
-** If the SQLITE_ENABLE_REDEF_IO macro is defined, then the OS-layer
-** interface routines are not called directly but are invoked using
-** pointers to functions. This allows the implementation of various
-** OS-layer interface routines to be modified at run-time. There are
-** obscure but legitimate reasons for wanting to do this. But for
-** most users, a direct call to the underlying interface is preferable
-** so the the redefinable I/O interface is turned off by default.
-*/
-#ifdef SQLITE_ENABLE_REDEF_IO
-
-/*
-** When redefinable I/O is enabled, a single global instance of the
-** following structure holds pointers to the routines that SQLite
-** uses to talk with the underlying operating system. Modify this
-** structure (before using any SQLite API!) to accomodate perculiar
-** operating system interfaces or behaviors.
-*/
-struct sqlite3OsVtbl {
- int (*xOpenReadWrite)(const char*, sqlite3_file**, int*);
- int (*xOpenExclusive)(const char*, sqlite3_file**, int);
- int (*xOpenReadOnly)(const char*, sqlite3_file**);
-
- int (*xDelete)(const char*);
- int (*xFileExists)(const char*);
- char *(*xFullPathname)(const char*);
- int (*xIsDirWritable)(char*);
- int (*xSyncDirectory)(const char*);
- int (*xTempFileName)(char*);
-
- int (*xRandomSeed)(char*);
- int (*xSleep)(int ms);
- int (*xCurrentTime)(double*);
-
- void (*xEnterMutex)(void);
- void (*xLeaveMutex)(void);
- int (*xInMutex)(int);
- ThreadData *(*xThreadSpecificData)(int);
-
- void *(*xMalloc)(int);
- void *(*xRealloc)(void *, int);
- void (*xFree)(void *);
- int (*xAllocationSize)(void *);
-
- void *(*xDlopen)(const char*);
- void *(*xDlsym)(void*, const char*);
- int (*xDlclose)(void*);
-};
-
-/* Macro used to comment out routines that do not exists when there is
-** no disk I/O or extension loading
-*/
-#ifdef SQLITE_OMIT_DISKIO
-# define IF_DISKIO(X) 0
-#else
-# define IF_DISKIO(X) X
-#endif
-#ifdef SQLITE_OMIT_LOAD_EXTENSION
-# define IF_DLOPEN(X) 0
-#else
-# define IF_DLOPEN(X) X
-#endif
-
-
-#if defined(_SQLITE_OS_C_) || defined(SQLITE_AMALGAMATION)
- /*
- ** The os.c file implements the global virtual function table.
- ** We have to put this file here because the initializers
- ** (ex: sqlite3OsRandomSeed) are macros that are about to be
- ** redefined.
- */
- struct sqlite3OsVtbl sqlite3Os = {
- IF_DISKIO( sqlite3OsOpenReadWrite ),
- IF_DISKIO( sqlite3OsOpenExclusive ),
- IF_DISKIO( sqlite3OsOpenReadOnly ),
- IF_DISKIO( sqlite3OsDelete ),
- IF_DISKIO( sqlite3OsFileExists ),
- IF_DISKIO( sqlite3OsFullPathname ),
- IF_DISKIO( sqlite3OsIsDirWritable ),
- IF_DISKIO( sqlite3OsSyncDirectory ),
- IF_DISKIO( sqlite3OsTempFileName ),
- sqlite3OsRandomSeed,
- sqlite3OsSleep,
- sqlite3OsCurrentTime,
- sqlite3OsEnterMutex,
- sqlite3OsLeaveMutex,
- sqlite3OsInMutex,
- 0,
- sqlite3OsMalloc,
- sqlite3OsRealloc,
- sqlite3OsFree,
- sqlite3OsAllocationSize,
- IF_DLOPEN( sqlite3OsDlopen ),
- IF_DLOPEN( sqlite3OsDlsym ),
- IF_DLOPEN( sqlite3OsDlclose ),
- };
-#else
- /*
- ** Files other than os.c just reference the global virtual function table.
- */
- extern struct sqlite3OsVtbl sqlite3Os;
-#endif /* _SQLITE_OS_C_ */
-
-
-/* This additional API routine is available with redefinable I/O */
-struct sqlite3OsVtbl *sqlite3_os_switch(void);
-
-
-/*
-** Redefine the OS interface to go through the virtual function table
-** rather than calling routines directly.
-*/
-#undef sqlite3OsOpenReadWrite
-#undef sqlite3OsOpenExclusive
-#undef sqlite3OsOpenReadOnly
-#undef sqlite3OsDelete
-#undef sqlite3OsFileExists
-#undef sqlite3OsFullPathname
-#undef sqlite3OsIsDirWritable
-#undef sqlite3OsSyncDirectory
-#undef sqlite3OsTempFileName
-#undef sqlite3OsRandomSeed
-#undef sqlite3OsSleep
-#undef sqlite3OsCurrentTime
-#undef sqlite3OsEnterMutex
-#undef sqlite3OsLeaveMutex
-#undef sqlite3OsInMutex
-#undef sqlite3OsThreadSpecificData
-#undef sqlite3OsMalloc
-#undef sqlite3OsRealloc
-#undef sqlite3OsFree
-#undef sqlite3OsAllocationSize
-#define sqlite3OsOpenReadWrite sqlite3Os.xOpenReadWrite
-#define sqlite3OsOpenExclusive sqlite3Os.xOpenExclusive
-#define sqlite3OsOpenReadOnly sqlite3Os.xOpenReadOnly
-#define sqlite3OsDelete sqlite3Os.xDelete
-#define sqlite3OsFileExists sqlite3Os.xFileExists
-#define sqlite3OsFullPathname sqlite3Os.xFullPathname
-#define sqlite3OsIsDirWritable sqlite3Os.xIsDirWritable
-#define sqlite3OsSyncDirectory sqlite3Os.xSyncDirectory
-#define sqlite3OsTempFileName sqlite3Os.xTempFileName
-#define sqlite3OsRandomSeed sqlite3Os.xRandomSeed
-#define sqlite3OsSleep sqlite3Os.xSleep
-#define sqlite3OsCurrentTime sqlite3Os.xCurrentTime
-#define sqlite3OsEnterMutex sqlite3Os.xEnterMutex
-#define sqlite3OsLeaveMutex sqlite3Os.xLeaveMutex
-#define sqlite3OsInMutex sqlite3Os.xInMutex
-#define sqlite3OsThreadSpecificData sqlite3Os.xThreadSpecificData
-#define sqlite3OsMalloc sqlite3Os.xMalloc
-#define sqlite3OsRealloc sqlite3Os.xRealloc
-#define sqlite3OsFree sqlite3Os.xFree
-#define sqlite3OsAllocationSize sqlite3Os.xAllocationSize
-
-#endif /* SQLITE_ENABLE_REDEF_IO */
-
#endif /* _SQLITE_OS_H_ */
int h; /* The file descriptor */
unsigned char locktype; /* The type of lock held on this fd */
unsigned char isOpen; /* True if needs to be closed */
- unsigned char fullSync; /* Use F_FULLSYNC if available */
int dirfd; /* File descriptor for the directory */
i64 offset; /* Seek offset */
#ifdef SQLITE_UNIX_THREADS
return access(zFilename, 0)==0;
}
-/* Forward declaration */
-static int allocateUnixFile(
- int h, /* File descriptor of the open file */
- sqlite3_file **pId, /* Write the real file descriptor here */
- const char *zFilename, /* Name of the file being opened */
- int delFlag /* If true, make sure the file deletes on close */
-);
-
/*
** Attempt to open a file for both reading and writing. If that
** fails, try opening it read-only. If the file does not exist,
** On failure, the function returns SQLITE_CANTOPEN and leaves
** *id unchanged.
*/
+#if 0
static int unixOpenDirectory(
OsFile *id,
const char *zDirname
OSTRACE3("OPENDIR %-3d %s\n", h, zDirname);
return SQLITE_OK;
}
+#endif
/*
** Check that a given pathname is a directory and is writable
return SQLITE_OK;
}
-/*
-** Move the read/write pointer in a file.
-*/
-static int unixSeek(OsFile *id, i64 offset){
- assert( id );
-#ifdef SQLITE_TEST
- if( offset ) SimulateDiskfullError(return SQLITE_FULL);
-#endif
- ((unixFile*)id)->offset = offset;
- return SQLITE_OK;
-}
-
#ifdef SQLITE_TEST
/*
** Count the number of fullsyncs and normal syncs. This is used to test
** the directory entry for the journal was never created) and the transaction
** will not roll back - possibly leading to database corruption.
*/
-static int unixSync(sqlite3_file *id, int dataOnly){
+static int unixSync(sqlite3_file *id, int flags){
int rc;
unixFile *pFile = (unixFile*)id;
+
+ int isDataOnly = (flags & SQLITE_SYNC_DATAONLY);
+ int isFullsync = (flags & SQLITE_SYNC_FULL);
+
assert( pFile );
OSTRACE2("SYNC %-3d\n", pFile->h);
- rc = full_fsync(pFile->h, pFile->fullSync, dataOnly);
+ rc = full_fsync(pFile->h, isFullsync, isDataOnly);
SimulateIOError( rc=1 );
if( rc ){
return SQLITE_IOERR_FSYNC;
}
if( pFile->dirfd>=0 ){
OSTRACE4("DIRSYNC %-3d (have_fullfsync=%d fullsync=%d)\n", pFile->dirfd,
- HAVE_FULLFSYNC, pFile->fullSync);
+ HAVE_FULLFSYNC, isFullsync);
#ifndef SQLITE_DISABLE_DIRSYNC
/* The directory sync is only attempted if full_fsync is
** turned off or unavailable. If a full_fsync occurred above,
** then the directory sync is superfluous.
*/
- if( (!HAVE_FULLFSYNC || !pFile->fullSync) && full_fsync(pFile->dirfd,0,0) ){
+ if( (!HAVE_FULLFSYNC || !isFullsync) && full_fsync(pFile->dirfd,0,0) ){
/*
** We have received multiple reports of fsync() returning
** errors when applied to directories on certain file systems.
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
+#if 0
/*
** Change the value of the fullsync flag in the given file descriptor.
*/
return ((unixFile*)id)->h;
}
-/*
-** Return an integer that indices the type of lock currently held
-** by this handle. (Used for testing and analysis only.)
-*/
-static int unixLockState(OsFile *id){
- return ((unixFile*)id)->locktype;
-}
+#endif
/*
** Return the sector size in bytes of the underlying block device for
return SQLITE_DEFAULT_SECTOR_SIZE;
}
+/*
+** Return the device characteristics for the file. This is always 0.
+*/
static int unixDeviceCharacteristics(sqlite3_file *id){
return 0;
}
return 0;
}
+/*
+** Return an integer that indices the type of lock currently held
+** by this handle. (Used for testing and analysis only.)
+*/
+static int unixLockState(sqlite3_file *id){
+ return ((unixFile*)id)->locktype;
+}
+
/*
** This vector defines all the methods that can operate on an OsFile
** for unix.
unixUnlock,
unixCheckReservedLock,
unixBreakLock,
+ unixLockState,
unixSectorSize,
unixDeviceCharacteristics
};
return SQLITE_OK;
}
+/*
+** Test the existance of or access permissions of file zPath. The
+** test performed depends on the value of flags:
+**
+** SQLITE_ACCESS_EXISTS: Return 1 if the file exists
+** SQLITE_ACCESS_READWRITE: Return 1 if the file is read and writable.
+** SQLITE_ACCESS_READONLY: Return 1 if the file is readable.
+**
+** Otherwise return 0.
+*/
static int unixAccess(void *pNotUsed, const char *zPath, int flags){
int amode;
switch( flags ){
#endif
/*
-** Both arguments are integers. This macro returns the lowest of the
-** two arguments.
-*/
-#define MIN(x,y) ((x)>(y)?(y):(x))
-
-/*
-** Get information to seed the random number generator. The seed
-** is written into the buffer zBuf[256]. The calling function must
-** supply a sufficiently large buffer.
+** Write nBuf bytes of random data to the supplied buffer zBuf.
*/
static int unixRandomness(void *pNotUsed, int nBuf, char *zBuf){
+
+ assert(nBuf>=(sizeof(time_t)+sizeof(int)));
+
/* We have to initialize zBuf to prevent valgrind from reporting
** errors. The reports issued by valgrind are incorrect - we would
** prefer that the randomness be increased by making use of the
if( fd<0 ){
time_t t;
time(&t);
- memcpy(zBuf, &t, MIN(nBuf, sizeof(t)));
- if( (nBuf-sizeof(t))>0 ){
- pid = getpid();
- memcpy(&zBuf[sizeof(t)], &pid, MIN(nBuf-sizeof(t), sizeof(pid)));
- }
+ memcpy(zBuf, &t, sizeof(t));
+ pid = getpid();
+ memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
}else{
read(fd, zBuf, nBuf);
close(fd);