-C Improvements\sto\scomments.\s\s\sNo\schanges\sto\scode.\s(CVS\s3146)
-D 2006-03-23T14:03:00
+C Use\sthe\spread()/pwrite()\sinterface\son\sPosix\sif\scompiled\swith\s-DUSE_PREAD=1.\nNote\sthat\son\sLinux\sthis\sis\sslower\sand\sdoes\snot\swork\sfor\slarge\sfiles.\s(CVS\s3147)
+D 2006-03-23T22:42:20
F Makefile.in 5d8dff443383918b700e495de42ec65bc1c8865b
F Makefile.linux-gcc 74ba0eadf88748a9ce3fd03d2a3ede2e6715baec
F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
F src/os_common.h 108cd719c96a2b714b64e02aeabbd40684274e6a
F src/os_test.c 49833426101f99aee4bb5f6a44b7c4b2029fda1c
F src/os_test.h 903c93554c23d88f34f667f1979e4a1cee792af3
-F src/os_unix.c 757a7b726764367f7b0595c4302969582c04413d
+F src/os_unix.c 35ad4d81c90800f509d28580742b67906d289223
F src/os_unix.h 5768d56d28240d3fe4537fac08cc85e4fb52279e
F src/os_win.c 8ced9ac82670bbf77492961a2f7ff80a87f1404f
F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 15e3b183bc554f729ce99c7daa5e36cdbcfa93fa
-R 956e5a1109502a7f2f2504ca4dc2dd35
+P 01e164da67fde3a89abeadd5973ead7a74e23a51
+R 5cbb3e3897611b57c9aea56a412ade76
U drh
-Z ca8cb6253cf8ae9ed004fb8973574663
+Z 617ee67652f0c5592bd9cf08ec1103f6
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
pthread_t tid; /* The thread that "owns" this OsFile */
#endif
return 1;
}
+/*
+** Seek to the offset in id->offset then read cnt bytes into pBuf.
+** Return the number of bytes actually read. Update the offset.
+*/
+static int seekAndRead(unixFile *id, void *pBuf, int cnt){
+ int got;
+#ifdef USE_PREAD
+ got = pread(id->h, pBuf, cnt, id->offset);
+#else
+ lseek(id->h, id->offset, SEEK_SET);
+ got = read(id->h, pBuf, cnt);
+#endif
+ if( got>0 ){
+ id->offset += got;
+ }
+ return got;
+}
+
/*
** Read data from a file into a buffer. Return SQLITE_OK if all
** bytes were read successfully and SQLITE_IOERR if anything goes
assert( id );
SimulateIOError(SQLITE_IOERR);
TIMER_START;
- got = read(((unixFile*)id)->h, pBuf, amt);
+ got = seekAndRead((unixFile*)id, pBuf, amt);
TIMER_END;
TRACE5("READ %-3d %5d %7d %d\n", ((unixFile*)id)->h, got,
last_page, TIMER_ELAPSED);
}
}
+/*
+** Seek to the offset in id->offset then read cnt bytes into pBuf.
+** Return the number of bytes actually read. Update the offset.
+*/
+static int seekAndWrite(unixFile *id, const void *pBuf, int cnt){
+ int got;
+#ifdef USE_PREAD
+ got = pwrite(id->h, pBuf, cnt, id->offset);
+#else
+ lseek(id->h, id->offset, SEEK_SET);
+ got = write(id->h, pBuf, cnt);
+#endif
+ if( got>0 ){
+ id->offset += got;
+ }
+ return got;
+}
+
+
/*
** Write data from a buffer into a file. Return SQLITE_OK on success
** or some other error code on failure.
SimulateIOError(SQLITE_IOERR);
SimulateDiskfullError;
TIMER_START;
- while( amt>0 && (wrote = write(((unixFile*)id)->h, pBuf, amt))>0 ){
+ while( amt>0 && (wrote = seekAndWrite((unixFile*)id, pBuf, amt))>0 ){
amt -= wrote;
pBuf = &((char*)pBuf)[wrote];
}
#ifdef SQLITE_TEST
if( offset ) SimulateDiskfullError
#endif
- lseek(((unixFile*)id)->h, offset, SEEK_SET);
+ ((unixFile*)id)->offset = offset;
return SQLITE_OK;
}
pInit->dirfd = -1;
pInit->fullSync = 0;
pInit->locktype = 0;
+ pInit->offset = 0;
SET_THREADID(pInit);
pNew = sqlite3ThreadSafeMalloc( sizeof(unixFile) );
if( pNew==0 ){