]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Use the pread()/pwrite() interface on Posix if compiled with -DUSE_PREAD=1.
authordrh <drh@noemail.net>
Thu, 23 Mar 2006 22:42:20 +0000 (22:42 +0000)
committerdrh <drh@noemail.net>
Thu, 23 Mar 2006 22:42:20 +0000 (22:42 +0000)
Note that on Linux this is slower and does not work for large files. (CVS 3147)

FossilOrigin-Name: 5a24f61981df4d8b696f03372eba2d37228906d9

manifest
manifest.uuid
src/os_unix.c

index 3f8a9fe1dee3d8d60df8a0ec3cf761ea90e2c583..156cd68e23a90cab0fbb23be7a1c742a4a88df5c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-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
@@ -55,7 +55,7 @@ F src/os.h 93035a0e3b9dd05cdd0aaef32ea28ca28e02fe78
 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
@@ -355,7 +355,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 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
index cd0f33486802c2dbb29cf764e989efa518e89e1b..c04336c7f6c1489b3f94d96fd672c9016b6be6c1 100644 (file)
@@ -1 +1 @@
-01e164da67fde3a89abeadd5973ead7a74e23a51
\ No newline at end of file
+5a24f61981df4d8b696f03372eba2d37228906d9
\ No newline at end of file
index c61efb81e6d4569e4a3a0a9187cf05aa6b207ce5..6dcc43ebe993000f5608c38181d1dcabde43e8fa 100644 (file)
@@ -80,6 +80,7 @@ struct unixFile {
   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
@@ -904,6 +905,24 @@ int sqlite3UnixIsDirWritable(char *zBuf){
   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
@@ -914,7 +933,7 @@ static int unixRead(OsFile *id, void *pBuf, int amt){
   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);
@@ -927,6 +946,25 @@ static int unixRead(OsFile *id, void *pBuf, int amt){
   }
 }
 
+/*
+** 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.
@@ -938,7 +976,7 @@ static int unixWrite(OsFile *id, const void *pBuf, int amt){
   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];
   }
@@ -961,7 +999,7 @@ static int unixSeek(OsFile *id, i64 offset){
 #ifdef SQLITE_TEST
   if( offset ) SimulateDiskfullError
 #endif
-  lseek(((unixFile*)id)->h, offset, SEEK_SET);
+  ((unixFile*)id)->offset = offset;
   return SQLITE_OK;
 }
 
@@ -1635,6 +1673,7 @@ static int allocateUnixFile(unixFile *pInit, OsFile **pId){
   pInit->dirfd = -1;
   pInit->fullSync = 0;
   pInit->locktype = 0;
+  pInit->offset = 0;
   SET_THREADID(pInit);
   pNew = sqlite3ThreadSafeMalloc( sizeof(unixFile) );
   if( pNew==0 ){