Remove some old OsFile and IoMethod related code. Add the sqlite3OsLockState function. (CVS 4241)

FossilOrigin-Name: 08a0f48028794abbeae1b4852652062b38d37d88
This commit is contained in:
danielk1977 2007-08-17 16:50:38 +00:00
parent b4b47411ab
commit 90949c2003
7 changed files with 61 additions and 371 deletions

View File

@ -1,5 +1,5 @@
C Begin\smigration\sto\susing\ssqlite3_vfs\sinterface.\s(CVS\s4240)
D 2007-08-17T15:53:36
C Remove\ssome\sold\sOsFile\sand\sIoMethod\srelated\scode.\sAdd\sthe\ssqlite3OsLockState\sfunction.\s(CVS\s4241)
D 2007-08-17T16:50:38
F Makefile.in 0c0e53720f658c7a551046442dd7afba0b72bfbe
F Makefile.linux-gcc 65241babba6faf1152bf86574477baab19190499
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@ -68,7 +68,7 @@ F src/alter.c f0aac0060ae8102e58f210b44d35b53438d53173
F src/analyze.c a14237d869c6bea0846493b59317e4097e81a0b6
F src/attach.c a52225c75b107be8c5bc144a2b6d20201be3f8f8
F src/auth.c 5ea90bc93dfea46e9fe4bf531e14c7cd98219ecb
F src/btree.c c4e563b8a8301413984156909461dea882eabed8
F src/btree.c f00ed30c442b4934d042af84e065498c542d21aa
F src/btree.h 91ee529d581c1473d8e6e15299acc3b8de1d0674
F src/btreeInt.h 6329e955a7dadd8628d5866e2465721b5fd25ef2
F src/build.c add67be992307b4b11849a6611bfd3352aacde92
@ -91,14 +91,14 @@ F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217
F src/mem1.c 30bf8be3846f92fdf88c490c5e5378512383bcbe
F src/mem2.c 661ca7ebf6e4b964fecc95d24e8c89dbcfc9dfea
F src/mutex.c 67b2efd36a1e67a7dc7b7fa852fd69953462c943
F src/os.c c8034df18a06cd1e9dde7d6e096b6709345ee72e
F src/os.h e54a81bc851724ad17206bfcb4a474f9481f9fc0
F src/os.c dce5a35b7ef4e8087b682376adf835d132ccf850
F src/os.h d33920f6b3e0dc300a2de3d765820cb0e8176cbc
F src/os_common.h a5c446d3b93f09f369d13bf217de4bed3437dd1c
F src/os_os2.c cba4e96fadb949076c717108fe0599d1a3c2e446
F src/os_os2.h e5f17dd69333632bbc3112881ea407c37d245eb3
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
F src/os_unix.c bf86c474a5febb67684b967a8d2816b1d7f26891
F src/os_unix.c 4b27202b4bfc1548c2ff3ae9a40b2e4530e57c7b
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c d868d5f9e95ec9c1b9e2a30c54c996053db6dddd
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
@ -112,7 +112,7 @@ F src/random.c 00b30565f018f3a256c157432935de070231c73b
F src/select.c 98c367bce3f38c5adfcc97de9ab5c79b0e5dc2b2
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c ac29402b538515fa4697282387be9c1205e6e9eb
F src/sqlite.h.in f29eb4bc8dc8f4dc61690f339ebb82fec010d4c1
F src/sqlite.h.in 366645a566cb674c1e26d10451e784cbe2a7b58c
F src/sqlite3ext.h 647a6b8a8f76ff6c9611e4a071531d8e63ff2d6b
F src/sqliteInt.h 442a6861cf3f535f410acad19a55b2fbca2564a7
F src/sqliteLimit.h f14609c27636ebc217c9603ade26dbdd7d0f6afa
@ -529,7 +529,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 4c1e9ffebe7c611a8b6a89153ae97ab9bca19ea3
R 473ba7528424cad7a8d671117a18b080
P af3e3c7acdc67013dd733effebe981620d922dd1
R 0b450cd00a75691c9505bbff03bfb4a5
U danielk1977
Z ac059cef33a845a67fcbf5f572a89687
Z 31339accc484dfc95959c68759a89caa

View File

@ -1 +1 @@
af3e3c7acdc67013dd733effebe981620d922dd1
08a0f48028794abbeae1b4852652062b38d37d88

View File

@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.400 2007/08/17 15:53:36 danielk1977 Exp $
** $Id: btree.c,v 1.401 2007/08/17 16:50:38 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information.
@ -1100,13 +1100,14 @@ int sqlite3BtreeOpen(
&& zFilename && zFilename[0]
&& sqlite3SharedCacheEnabled
){
char *zFullPathname = sqlite3OsFullPathname(zFilename);
char *zFullPathname = (char *)sqlite3_malloc(pVfs->mxPathname);
sqlite3_mutex *mutexShared;
p->sharable = 1;
if( !zFullPathname ){
sqlite3_free(p);
return SQLITE_NOMEM;
}
sqlite3OsFullPathname(pVfs, zFilename, zFullPathname);
mutexShared = sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER);
sqlite3_mutex_enter(mutexShared);
for(pBt=sqlite3SharedCacheList; pBt; pBt=pBt->pNext){

View File

@ -37,8 +37,8 @@ int sqlite3OsWrite(sqlite3_file *id, const void *pBuf, int amt, i64 offset){
int sqlite3OsTruncate(sqlite3_file *id, i64 size){
return id->pMethods->xTruncate(id, size);
}
int sqlite3OsSync(sqlite3_file *id, int fullsync){
return id->pMethods->xSync(id, fullsync);
int sqlite3OsSync(sqlite3_file *id, int flags){
return id->pMethods->xSync(id, flags);
}
int sqlite3OsFileSize(sqlite3_file *id, i64 *pSize){
return id->pMethods->xFileSize(id, pSize);
@ -70,8 +70,7 @@ int sqlite3OsDeviceCharacteristics(sqlite3_file *id){
return 0;
}
int sqlite3OsLockState(sqlite3_file *id){
/* return id->pMethods->xLockState(id); */
return 0;
return id->pMethods->xLockState(id);
}
#endif

308
src/os.h
View File

@ -121,91 +121,6 @@
# 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"
@ -216,47 +131,6 @@
#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:
@ -361,6 +235,7 @@ int sqlite3OsLock(sqlite3_file*, int);
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);
@ -387,190 +262,9 @@ int sqlite3OsCurrentTime(sqlite3_vfs *, double*);
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_ */

View File

@ -95,7 +95,6 @@ struct unixFile {
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
@ -807,14 +806,6 @@ int sqlite3UnixFileExists(const char *zFilename){
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,
@ -933,6 +924,7 @@ int sqlite3UnixOpenReadOnly(const char *zFilename, sqlite3_file **pId){
** On failure, the function returns SQLITE_CANTOPEN and leaves
** *id unchanged.
*/
#if 0
static int unixOpenDirectory(
OsFile *id,
const char *zDirname
@ -952,6 +944,7 @@ static int unixOpenDirectory(
OSTRACE3("OPENDIR %-3d %s\n", h, zDirname);
return SQLITE_OK;
}
#endif
/*
** Check that a given pathname is a directory and is writable
@ -1075,18 +1068,6 @@ static int unixWrite(
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
@ -1189,25 +1170,29 @@ static int full_fsync(int fd, int fullSync, int dataOnly){
** 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.
@ -2248,6 +2233,7 @@ static int nolockUnixClose(OsFile **pId) {
#endif /* SQLITE_ENABLE_LOCKING_STYLE */
#if 0
/*
** Change the value of the fullsync flag in the given file descriptor.
*/
@ -2262,13 +2248,7 @@ static int unixFileHandle(OsFile *id){
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
@ -2284,6 +2264,9 @@ static int unixSectorSize(sqlite3_file *id){
return SQLITE_DEFAULT_SECTOR_SIZE;
}
/*
** Return the device characteristics for the file. This is always 0.
*/
static int unixDeviceCharacteristics(sqlite3_file *id){
return 0;
}
@ -2293,6 +2276,14 @@ static int unixBreakLock(sqlite3_file *id){
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.
@ -2309,6 +2300,7 @@ static const sqlite3_io_methods sqlite3UnixIoMethod = {
unixUnlock,
unixCheckReservedLock,
unixBreakLock,
unixLockState,
unixSectorSize,
unixDeviceCharacteristics
};
@ -2629,6 +2621,16 @@ static int unixDelete(void *pNotUsed, const char *zPath){
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 ){
@ -2776,17 +2778,12 @@ void unixDlClose(void *pHandle){
#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
@ -2807,11 +2804,9 @@ static int unixRandomness(void *pNotUsed, int nBuf, char *zBuf){
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);

View File

@ -30,7 +30,7 @@
** the version number) and changes its name to "sqlite3.h" as
** part of the build process.
**
** @(#) $Id: sqlite.h.in,v 1.228 2007/08/17 15:53:37 danielk1977 Exp $
** @(#) $Id: sqlite.h.in,v 1.229 2007/08/17 16:50:38 danielk1977 Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@ -496,6 +496,7 @@ struct sqlite3_io_methods {
int (*xUnlock)(sqlite3_file*, int);
int (*xCheckReservedLock)(sqlite3_file*);
int (*xBreakLock)(sqlite3_file*);
int (*xLockState)(sqlite3_file *);
int (*xSectorSize)(sqlite3_file*);
int (*xDeviceCharacteristics)(sqlite3_file*);
/* Additional methods may be added in future releases */