-C Changes\sto\scleanup\sand\simprove\sthe\sconsistency\sof\stests\sfor\slarge\sfile\ssupport\sin\sbigfile.test.\s(CVS\s6338)
-D 2009-03-05T04:27:08
+C Implemented\swinSectorSize();\sOther\schanges\sfor\sconsistency.\s\sos_win.c.\s\sTicket\s#2931.\s(CVS\s6339)
+D 2009-03-05T05:54:55
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in d64baddbf55cdf33ff030e14da837324711a4ef7
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
F src/os_common.h 8c61457df58f1a4bd5f5adc3e90e01b37bf7afbc
F src/os_os2.c bed77dc26e3a95ce4a204936b9a1ca6fe612fcc5
F src/os_unix.c 52352674c19688026a72cd0e8620e6a29bacba4a
-F src/os_win.c 4a91fbbeed9ec318de833b252931ea8464d371cf
+F src/os_win.c 40636702058ed4dcd35d68151bfab56d4997cdc1
F src/pager.c 01e3facb2f7c5f307e36a0f4ed9343cf3761711a
F src/pager.h 0c9f3520c00d8a3b8e792ca56c9a11b6b02b4b0f
F src/parse.y c315b6f9bf6c7e7ec985481f81b6a45dba6c26d0
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 6b0cabd017ed25530b2d918d2c069fcbdd60a3f6
-R fee3d718417bd5cb78c4e8b1c7f65105
+P 3dbdf68030855a5da24de0ae2f10a26da2531d33
+R 93580061acc7426f99498a97ca6f1c0d
U shane
-Z 736b679812172868a9aa6eb0fad79522
+Z fe989efe3b3e3aab1842ad05067b7cd6
**
** This file contains code that is specific to windows.
**
-** $Id: os_win.c,v 1.149 2009/03/05 04:20:32 shane Exp $
+** $Id: os_win.c,v 1.150 2009/03/05 05:54:55 shane Exp $
*/
#include "sqliteInt.h"
#if SQLITE_OS_WIN /* This file is used for windows only */
*/
#if SQLITE_OS_WINCE
# define AreFileApisANSI() 1
+# define GetDiskFreeSpaceW() 0
#endif
/*
unsigned char locktype; /* Type of lock currently held on this file */
short sharedLockByte; /* Randomly chosen byte used as a shared lock */
DWORD lastErrno; /* The Windows errno from the last I/O error */
+ DWORD sectorSize; /* Sector size of the device file is on */
#if SQLITE_OS_WINCE
WCHAR *zDeleteOnClose; /* Name of file to delete when closing */
HANDLE hMutex; /* Mutex used to control access to shared lock */
#endif
};
+/*
+** Forward prototypes.
+*/
+static int getSectorSize(
+ sqlite3_vfs *pVfs,
+ const char *zRelative /* UTF-8 file name */
+);
/*
** The following variable is (normally) set once and never changes
**
** Here is an interesting observation: Win95, Win98, and WinME lack
** the LockFileEx() API. But we can still statically link against that
-** API as long as we don't call it win running Win95/98/ME. A call to
+** API as long as we don't call it when running Win95/98/ME. A call to
** this routine is used to determine if the host is Win95/98/ME or
** WinNT/2K/XP so that we will know whether or not we can safely call
** the LockFileEx() API.
static int winClose(sqlite3_file *id){
int rc, cnt = 0;
winFile *pFile = (winFile*)id;
+
+ assert( id!=0 );
OSTRACE2("CLOSE %d\n", pFile->h);
do{
rc = CloseHandle(pFile->h);
LONG upperBits = (LONG)((offset>>32) & 0x7fffffff);
LONG lowerBits = (LONG)(offset & 0xffffffff);
DWORD rc;
- DWORD got;
winFile *pFile = (winFile*)id;
DWORD error;
+ DWORD got;
+
assert( id!=0 );
SimulateIOError(return SQLITE_IOERR_READ);
OSTRACE3("READ %d lock=%d\n", pFile->h, pFile->locktype);
LONG upperBits = (LONG)((offset>>32) & 0x7fffffff);
LONG lowerBits = (LONG)(offset & 0xffffffff);
DWORD rc;
- DWORD wrote = 0;
winFile *pFile = (winFile*)id;
DWORD error;
+ DWORD wrote = 0;
+
assert( id!=0 );
SimulateIOError(return SQLITE_IOERR_WRITE);
SimulateDiskfullError(return SQLITE_FULL);
** Truncate an open file to a specified size
*/
static int winTruncate(sqlite3_file *id, sqlite3_int64 nByte){
- DWORD rc;
LONG upperBits = (LONG)((nByte>>32) & 0x7fffffff);
LONG lowerBits = (LONG)(nByte & 0xffffffff);
+ DWORD rc;
winFile *pFile = (winFile*)id;
- DWORD error = NO_ERROR;
+ DWORD error;
+
+ assert( id!=0 );
OSTRACE3("TRUNCATE %d %lld\n", pFile->h, nByte);
SimulateIOError(return SQLITE_IOERR_TRUNCATE);
rc = SetFilePointer(pFile->h, lowerBits, &upperBits, FILE_BEGIN);
- if( INVALID_SET_FILE_POINTER == rc ){
- error = GetLastError();
+ if( rc==INVALID_SET_FILE_POINTER && (error=GetLastError())!=NO_ERROR ){
+ pFile->lastErrno = error;
+ return SQLITE_IOERR_TRUNCATE;
}
- if( error == NO_ERROR ){
- /* SetEndOfFile will fail if nByte is negative */
- if( SetEndOfFile(pFile->h) ){
- return SQLITE_OK;
- }
- error = GetLastError();
+ /* SetEndOfFile will fail if nByte is negative */
+ if( !SetEndOfFile(pFile->h) ){
+ pFile->lastErrno = GetLastError();
+ return SQLITE_IOERR_TRUNCATE;
}
- pFile->lastErrno = error;
- return SQLITE_IOERR_TRUNCATE;
+ return SQLITE_OK;
}
#ifdef SQLITE_TEST
static int winSync(sqlite3_file *id, int flags){
#ifndef SQLITE_NO_SYNC
winFile *pFile = (winFile*)id;
+
+ assert( id!=0 );
OSTRACE3("SYNC %d lock=%d\n", pFile->h, pFile->locktype);
#else
UNUSED_PARAMETER(id);
** Determine the current size of a file in bytes
*/
static int winFileSize(sqlite3_file *id, sqlite3_int64 *pSize){
+ DWORD upperBits;
+ DWORD lowerBits;
winFile *pFile = (winFile*)id;
- DWORD upperBits, lowerBits;
DWORD error;
+
+ assert( id!=0 );
SimulateIOError(return SQLITE_IOERR_FSTAT);
lowerBits = GetFileSize(pFile->h, &upperBits);
if( (lowerBits == INVALID_FILE_SIZE)
winFile *pFile = (winFile*)id;
DWORD error = NO_ERROR;
- assert( pFile!=0 );
+ assert( id!=0 );
OSTRACE5("LOCK %d %d was %d(%d)\n",
pFile->h, locktype, pFile->locktype, pFile->sharedLockByte);
static int winCheckReservedLock(sqlite3_file *id, int *pResOut){
int rc;
winFile *pFile = (winFile*)id;
- assert( pFile!=0 );
+
+ assert( id!=0 );
if( pFile->locktype>=RESERVED_LOCK ){
rc = 1;
OSTRACE3("TEST WR-LOCK %d %d (local)\n", pFile->h, rc);
** same for both.
*/
static int winSectorSize(sqlite3_file *id){
- UNUSED_PARAMETER(id);
- return SQLITE_DEFAULT_SECTOR_SIZE;
+ assert( id!=0 );
+ return (int)(((winFile*)id)->sectorSize);
}
/*
return 0;
}
-
/*
** Open a file.
*/
const char *zUtf8Name = zName; /* Filename in UTF-8 encoding */
char zTmpname[MAX_PATH+1]; /* Buffer used to create temp filename */
+ assert( id!=0 );
UNUSED_PARAMETER(pVfs);
/* If the second argument to this function is NULL, generate a
pFile->pMethod = &winIoMethod;
pFile->h = h;
pFile->lastErrno = NO_ERROR;
+ pFile->sectorSize = getSectorSize(pVfs, zUtf8Name);
#if SQLITE_OS_WINCE
if( (flags & (SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)) ==
(SQLITE_OPEN_READWRITE|SQLITE_OPEN_MAIN_DB)
#endif
}
+/*
+** Get the sector size of the device used to store
+** file.
+*/
+static int getSectorSize(
+ sqlite3_vfs *pVfs,
+ const char *zRelative /* UTF-8 file name */
+){
+ DWORD bytesPerSector = SQLITE_DEFAULT_SECTOR_SIZE;
+ char zFullpath[MAX_PATH+1];
+ int rc;
+ DWORD dwRet = 0;
+
+ /*
+ ** We need to get the full path name of the file
+ ** to get the drive letter to look up the sector
+ ** size.
+ */
+ rc = winFullPathname(pVfs, zRelative, MAX_PATH, zFullpath);
+ if( rc == SQLITE_OK )
+ {
+ void *zConverted = convertUtf8Filename(zFullpath);
+ if( zConverted ){
+ if( isNT() ){
+ int i;
+ /* trim path to just drive reference */
+ WCHAR *p = zConverted;
+ for(i=0;i<MAX_PATH;i++){
+ if( p[i] == '\\' ){
+ i++;
+ p[i] = '\0';
+ break;
+ }
+ }
+ dwRet = GetDiskFreeSpaceW((WCHAR*)zConverted,
+ NULL,
+ &bytesPerSector,
+ NULL,
+ NULL);
+#if SQLITE_OS_WINCE==0
+ }else{
+ int i;
+ /* trim path to just drive reference */
+ CHAR *p = (CHAR *)zConverted;
+ for(i=0;i<MAX_PATH;i++){
+ if( p[i] == '\\' ){
+ i++;
+ p[i] = '\0';
+ break;
+ }
+ }
+ dwRet = GetDiskFreeSpaceA((CHAR*)zConverted,
+ NULL,
+ &bytesPerSector,
+ NULL,
+ NULL);
+#endif
+ }
+ free(zConverted);
+ }
+ if( !dwRet ){
+ bytesPerSector = SQLITE_DEFAULT_SECTOR_SIZE;
+ }
+ }
+ return (int) bytesPerSector;
+}
+
#ifndef SQLITE_OMIT_LOAD_EXTENSION
/*
** Interfaces for opening a shared library, finding entry points