/ Check-in [80fac2a6]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add more system calls to the set that can be overridden in os_unix.c. Also merge in recent fixes from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | syscall-override
Files: files | file ages | folders
SHA1: 80fac2a6e07221bb67613af84ab9dda3e18b5ceb
User & Date: drh 2011-03-02 18:01:10
Context
2011-03-02
19:06
Add additional VFS methods to retrieve system call pointers and to get a list of all changeable system calls. check-in: 38558363 user: drh tags: syscall-override
18:01
Add more system calls to the set that can be overridden in os_unix.c. Also merge in recent fixes from trunk. check-in: 80fac2a6 user: drh tags: syscall-override
17:54
Fix bugs in [7b6e30e6a7] that only show up on Mac. check-in: ec55e8c6 user: drh tags: trunk
15:09
Proof-of-concept prototype for the proposed xSetSystemCall extension method on the VFS. check-in: 92b5a76a user: drh tags: syscall-override
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rtree/rtree.c.

  3129   3129     for(ii=0; ii<NCELL(&node); ii++){
  3130   3130       char zCell[512];
  3131   3131       int nCell = 0;
  3132   3132       RtreeCell cell;
  3133   3133       int jj;
  3134   3134   
  3135   3135       nodeGetCell(&tree, &node, ii, &cell);
  3136         -    sqlite3_snprintf(512-nCell,&zCell[nCell],"%d", cell.iRowid);
         3136  +    sqlite3_snprintf(512-nCell,&zCell[nCell],"%lld", cell.iRowid);
  3137   3137       nCell = strlen(zCell);
  3138   3138       for(jj=0; jj<tree.nDim*2; jj++){
  3139   3139         sqlite3_snprintf(512-nCell,&zCell[nCell]," %f",(double)cell.aCoord[jj].f);
  3140   3140         nCell = strlen(zCell);
  3141   3141       }
  3142   3142   
  3143   3143       if( zText ){

Added ext/rtree/rtreeB.test.

            1  +# 2011 March 2
            2  +#
            3  +# The author disclaims copyright to this source code.  In place of
            4  +# a legal notice, here is a blessing:
            5  +#
            6  +#    May you do good and not evil.
            7  +#    May you find forgiveness for yourself and forgive others.
            8  +#    May you share freely, never taking more than you give.
            9  +#
           10  +#***********************************************************************
           11  +# Make sure the rtreenode() testing function can handle entries with
           12  +# 64-bit rowids.
           13  +# 
           14  +
           15  +if {![info exists testdir]} {
           16  +  set testdir [file join [file dirname [info script]] .. .. test]
           17  +} 
           18  +source $testdir/tester.tcl
           19  +ifcapable !rtree { finish_test ; return }
           20  +
           21  +do_test rtreeB-1.1 {
           22  +  db eval {
           23  +    CREATE VIRTUAL TABLE t1 USING rtree(ii, x0, y0, x1, y1);
           24  +    INSERT INTO t1 VALUES(1073741824, 0.0, 0.0, 100.0, 100.0);
           25  +    INSERT INTO t1 VALUES(2147483646, 0.0, 0.0, 200.0, 200.0);
           26  +    INSERT INTO t1 VALUES(4294967296, 0.0, 0.0, 300.0, 300.0);
           27  +    INSERT INTO t1 VALUES(8589934592, 20.0, 20.0, 150.0, 150.0);
           28  +    INSERT INTO t1 VALUES(9223372036854775807, 150, 150, 400, 400);
           29  +    SELECT rtreenode(2, data) FROM t1_node;
           30  +  }
           31  +} {{1073741824 0.000000 0.000000 100.000000 100.000000} {2147483646 0.000000 0.000000 200.000000 200.000000} {4294967296 0.000000 0.000000 300.000000 300.000000} {8589934592 20.000000 20.000000 150.000000 150.000000} {9223372036854775807 150.000000 150.000000 400.000000 400.000000}}
           32  +
           33  +
           34  +finish_test

Changes to src/os_unix.c.

   319    319     { "fstat",        (void*)fstat,      0  },
   320    320   #define osFstat     ((int(*)(int,struct stat*))aSyscall[5].pCurrent)
   321    321   #endif
   322    322   
   323    323     { "ftruncate",    (void*)ftruncate,  0  },
   324    324   #define osFtruncate ((int(*)(int,off_t))aSyscall[6].pCurrent)
   325    325   
   326         -  { "fcntl",        (void*)fcntl,    0  },
          326  +  { "fcntl",        (void*)fcntl,      0  },
   327    327   #define osFcntl     ((int(*)(int,int,...))aSyscall[7].pCurrent)
   328         -};
          328  +
          329  +  { "read",         (void*)read,       0  },
          330  +#define osRead      ((ssize_t(*)(int,void*,size_t))aSyscall[8].pCurrent)
          331  +
          332  +#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
          333  +  { "pread",        (void*)pread,      0  },
          334  +#else
          335  +  { "pread",        (void*)0,          0  },
          336  +#endif
          337  +#define osPread     ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[9].pCurrent)
          338  +
          339  +#if defined(USE_PREAD64)
          340  +  { "pread64",      (void*)pread64,    0  },
          341  +#else
          342  +  { "pread64",      (void*)0,          0  },
          343  +#endif
          344  +#define osPread64   ((ssize_t(*)(int,void*,size_t,off_t))aSyscall[10].pCurrent)
          345  +
          346  +  { "write",        (void*)write,      0  },
          347  +#define osWrite     ((ssize_t(*)(int,const void*,size_t))aSyscall[11].pCurrent)
          348  +
          349  +#if defined(USE_PREAD) || defined(SQLITE_ENABLE_LOCKING_STYLE)
          350  +  { "pwrite",       (void*)pwrite,     0  },
          351  +#else
          352  +  { "pwrite",       (void*)0,          0  },
          353  +#endif
          354  +#define osPwrite    ((ssize_t(*)(int,const void*,size_t,off_t))\
          355  +                    aSyscall[12].pCurrent)
          356  +
          357  +#if defined(USE_PREAD64)
          358  +  { "pwrite64",     (void*)pwrite64,   0  },
          359  +#else
          360  +  { "pwrite64",     (void*)0,          0  },
          361  +#endif
          362  +#define osPwrite64  ((ssize_t(*)(int,const void*,size_t,off_t))\
          363  +                    aSyscall[13].pCurrent)
          364  +
          365  +  { "fchmod",       (void*)fchmod,     0  },
          366  +#define osFchmod    ((int(*)(int,mode_t))aSyscall[14].pCurrent)
          367  +
          368  +#if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
          369  +  { "fallocate",    (void*)posix_fallocate,  0 },
          370  +#else
          371  +  { "fallocate",    (void*)0,                0 },
          372  +#endif
          373  +#define osFallocate ((int(*)(int,off_t,off_t)aSyscall[15].pCurrent)
          374  +
          375  +}; /* End of the overrideable system calls */
   329    376   
   330    377   /*
   331    378   ** This is the xSetSystemCall() method of sqlite3_vfs for all of the
   332    379   ** "unix" VFSes.
   333    380   */
   334    381   static int unixSetSystemCall(
   335    382     sqlite3_vfs *pNotUsed,     /* The VFS pointer.  Not used */
................................................................................
  1007   1054     ** prior to accessing the inode number.  The one byte written is
  1008   1055     ** an ASCII 'S' character which also happens to be the first byte
  1009   1056     ** in the header of every SQLite database.  In this way, if there
  1010   1057     ** is a race condition such that another thread has already populated
  1011   1058     ** the first page of the database, no damage is done.
  1012   1059     */
  1013   1060     if( statbuf.st_size==0 && (pFile->fsFlags & SQLITE_FSFLAGS_IS_MSDOS)!=0 ){
  1014         -    do{ rc = write(fd, "S", 1); }while( rc<0 && errno==EINTR );
         1061  +    do{ rc = osWrite(fd, "S", 1); }while( rc<0 && errno==EINTR );
  1015   1062       if( rc!=1 ){
  1016   1063         pFile->lastErrno = errno;
  1017   1064         return SQLITE_IOERR;
  1018   1065       }
  1019   1066       rc = osFstat(fd, &statbuf);
  1020   1067       if( rc!=0 ){
  1021   1068         pFile->lastErrno = errno;
................................................................................
  2779   2826   static int seekAndRead(unixFile *id, sqlite3_int64 offset, void *pBuf, int cnt){
  2780   2827     int got;
  2781   2828   #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
  2782   2829     i64 newOffset;
  2783   2830   #endif
  2784   2831     TIMER_START;
  2785   2832   #if defined(USE_PREAD)
  2786         -  do{ got = pread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
         2833  +  do{ got = osPread(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
  2787   2834     SimulateIOError( got = -1 );
  2788   2835   #elif defined(USE_PREAD64)
  2789         -  do{ got = pread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
         2836  +  do{ got = osPread64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR);
  2790   2837     SimulateIOError( got = -1 );
  2791   2838   #else
  2792   2839     newOffset = lseek(id->h, offset, SEEK_SET);
  2793   2840     SimulateIOError( newOffset-- );
  2794   2841     if( newOffset!=offset ){
  2795   2842       if( newOffset == -1 ){
  2796   2843         ((unixFile*)id)->lastErrno = errno;
  2797   2844       }else{
  2798   2845         ((unixFile*)id)->lastErrno = 0;			
  2799   2846       }
  2800   2847       return -1;
  2801   2848     }
  2802         -  do{ got = read(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
         2849  +  do{ got = osRead(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
  2803   2850   #endif
  2804   2851     TIMER_END;
  2805   2852     if( got<0 ){
  2806   2853       ((unixFile*)id)->lastErrno = errno;
  2807   2854     }
  2808   2855     OSTRACE(("READ    %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED));
  2809   2856     return got;
................................................................................
  2857   2904   static int seekAndWrite(unixFile *id, i64 offset, const void *pBuf, int cnt){
  2858   2905     int got;
  2859   2906   #if (!defined(USE_PREAD) && !defined(USE_PREAD64))
  2860   2907     i64 newOffset;
  2861   2908   #endif
  2862   2909     TIMER_START;
  2863   2910   #if defined(USE_PREAD)
  2864         -  do{ got = pwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
         2911  +  do{ got = osPwrite(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
  2865   2912   #elif defined(USE_PREAD64)
  2866         -  do{ got = pwrite64(id->h, pBuf, cnt, offset); }while( got<0 && errno==EINTR );
         2913  +  do{ got = osPwrite64(id->h, pBuf, cnt, offset);}while( got<0 && errno==EINTR);
  2867   2914   #else
  2868   2915     newOffset = lseek(id->h, offset, SEEK_SET);
  2869   2916     if( newOffset!=offset ){
  2870   2917       if( newOffset == -1 ){
  2871   2918         ((unixFile*)id)->lastErrno = errno;
  2872   2919       }else{
  2873   2920         ((unixFile*)id)->lastErrno = 0;			
  2874   2921       }
  2875   2922       return -1;
  2876   2923     }
  2877         -  do{ got = write(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
         2924  +  do{ got = osWrite(id->h, pBuf, cnt); }while( got<0 && errno==EINTR );
  2878   2925   #endif
  2879   2926     TIMER_END;
  2880   2927     if( got<0 ){
  2881   2928       ((unixFile*)id)->lastErrno = errno;
  2882   2929     }
  2883   2930   
  2884   2931     OSTRACE(("WRITE   %-3d %5d %7lld %llu\n", id->h, got, offset, TIMER_ELAPSED));
................................................................................
  3233   3280       if( osFstat(pFile->h, &buf) ) return SQLITE_IOERR_FSTAT;
  3234   3281   
  3235   3282       nSize = ((nByte+pFile->szChunk-1) / pFile->szChunk) * pFile->szChunk;
  3236   3283       if( nSize>(i64)buf.st_size ){
  3237   3284   #if defined(HAVE_POSIX_FALLOCATE) && HAVE_POSIX_FALLOCATE
  3238   3285         int rc;
  3239   3286         do{
  3240         -        rc = posix_fallocate(pFile-.h, buf.st_size, nSize-buf.st_size;
         3287  +        rc = osFallocate(pFile->.h, buf.st_size, nSize-buf.st_size;
  3241   3288         }while( rc<0 && errno=EINTR );
  3242   3289         if( rc ) return SQLITE_IOERR_WRITE;
  3243   3290   #else
  3244   3291         /* If the OS does not have posix_fallocate(), fake it. First use
  3245   3292         ** ftruncate() to set the file size, then write a single byte to
  3246   3293         ** the last byte in each block within the extended region. This
  3247   3294         ** is the same technique used by glibc to implement posix_fallocate()
................................................................................
  5111   5158         time(&t);
  5112   5159         memcpy(zBuf, &t, sizeof(t));
  5113   5160         pid = getpid();
  5114   5161         memcpy(&zBuf[sizeof(t)], &pid, sizeof(pid));
  5115   5162         assert( sizeof(t)+sizeof(pid)<=(size_t)nBuf );
  5116   5163         nBuf = sizeof(t) + sizeof(pid);
  5117   5164       }else{
  5118         -      do{ nBuf = read(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
         5165  +      do{ nBuf = osRead(fd, zBuf, nBuf); }while( nBuf<0 && errno==EINTR );
  5119   5166         robust_close(0, fd, __LINE__);
  5120   5167       }
  5121   5168     }
  5122   5169   #endif
  5123   5170     return nBuf;
  5124   5171   }
  5125   5172   
................................................................................
  5634   5681     pathLen = strlcpy(tPath, cPath, MAXPATHLEN);
  5635   5682     if( pathLen>MAXPATHLEN || pathLen<6 || 
  5636   5683        (strlcpy(&tPath[pathLen-5], "break", 6) != 5) ){
  5637   5684       sqlite3_snprintf(sizeof(errmsg),errmsg,"path error (len %d)",(int)pathLen);
  5638   5685       goto end_breaklock;
  5639   5686     }
  5640   5687     /* read the conch content */
  5641         -  readLen = pread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0);
         5688  +  readLen = osPread(conchFile->h, buf, PROXY_MAXCONCHLEN, 0);
  5642   5689     if( readLen<PROXY_PATHINDEX ){
  5643   5690       sqlite3_snprintf(sizeof(errmsg),errmsg,"read error (len %d)",(int)readLen);
  5644   5691       goto end_breaklock;
  5645   5692     }
  5646   5693     /* write it out to the temporary break file */
  5647   5694     fd = osOpen(tPath, (O_RDWR|O_CREAT|O_EXCL), SQLITE_DEFAULT_FILE_PERMISSIONS);
  5648   5695     if( fd<0 ){
  5649   5696       sqlite3_snprintf(sizeof(errmsg), errmsg, "create failed (%d)", errno);
  5650   5697       goto end_breaklock;
  5651   5698     }
  5652         -  if( pwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
         5699  +  if( osPwrite(fd, buf, readLen, 0) != (ssize_t)readLen ){
  5653   5700       sqlite3_snprintf(sizeof(errmsg), errmsg, "write failed (%d)", errno);
  5654   5701       goto end_breaklock;
  5655   5702     }
  5656   5703     if( rename(tPath, cPath) ){
  5657   5704       sqlite3_snprintf(sizeof(errmsg), errmsg, "rename failed (%d)", errno);
  5658   5705       goto end_breaklock;
  5659   5706     }
................................................................................
  5710   5757         if( conchModTime.tv_sec != buf.st_mtimespec.tv_sec || 
  5711   5758            conchModTime.tv_nsec != buf.st_mtimespec.tv_nsec ){
  5712   5759           return SQLITE_BUSY;
  5713   5760         }
  5714   5761         
  5715   5762         if( nTries==2 ){  
  5716   5763           char tBuf[PROXY_MAXCONCHLEN];
  5717         -        int len = pread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
         5764  +        int len = osPread(conchFile->h, tBuf, PROXY_MAXCONCHLEN, 0);
  5718   5765           if( len<0 ){
  5719   5766             pFile->lastErrno = errno;
  5720   5767             return SQLITE_IOERR_LOCK;
  5721   5768           }
  5722   5769           if( len>PROXY_PATHINDEX && tBuf[0]==(char)PROXY_CONCHVERSION){
  5723   5770             /* don't break the lock if the host id doesn't match */
  5724   5771             if( 0!=memcmp(&tBuf[PROXY_HEADERLEN], myHostID, PROXY_HOSTIDLEN) ){
................................................................................
  5880   5927           rc = unixWrite((sqlite3_file *)conchFile, writeBuffer, writeSize, 0);
  5881   5928           fsync(conchFile->h);
  5882   5929           /* If we created a new conch file (not just updated the contents of a 
  5883   5930            ** valid conch file), try to match the permissions of the database 
  5884   5931            */
  5885   5932           if( rc==SQLITE_OK && createConch ){
  5886   5933             struct stat buf;
  5887         -          int rc;
  5888   5934             int err = osFstat(pFile->h, &buf);
  5889   5935             if( err==0 ){
  5890   5936               mode_t cmode = buf.st_mode&(S_IRUSR|S_IWUSR | S_IRGRP|S_IWGRP |
  5891   5937                                           S_IROTH|S_IWOTH);
  5892   5938               /* try to match the database file R/W permissions, ignore failure */
  5893   5939   #ifndef SQLITE_PROXY_DEBUG
  5894         -            fchmod(conchFile->h, cmode);
         5940  +            osFchmod(conchFile->h, cmode);
  5895   5941   #else
  5896   5942               do{
  5897         -              rc = fchmod(conchFile->h, cmode);
         5943  +              rc = osFchmod(conchFile->h, cmode);
  5898   5944               }while( rc==(-1) && errno==EINTR );
  5899   5945               if( rc!=0 ){
  5900   5946                 int code = errno;
  5901   5947                 fprintf(stderr, "fchmod %o FAILED with %d %s\n",
  5902   5948                         cmode, code, strerror(code));
  5903   5949               } else {
  5904   5950                 fprintf(stderr, "fchmod %o SUCCEDED\n",cmode);
................................................................................
  5913   5959         }
  5914   5960         conchFile->pMethod->xUnlock((sqlite3_file*)conchFile, SHARED_LOCK);
  5915   5961         
  5916   5962       end_takeconch:
  5917   5963         OSTRACE(("TRANSPROXY: CLOSE  %d\n", pFile->h));
  5918   5964         if( rc==SQLITE_OK && pFile->openFlags ){
  5919   5965           if( pFile->h>=0 ){
  5920         -          robust_close(pFile, pFile->h, __LINE__) ){
         5966  +          robust_close(pFile, pFile->h, __LINE__);
  5921   5967           }
  5922   5968           pFile->h = -1;
  5923   5969           int fd = osOpen(pCtx->dbPath, pFile->openFlags,
  5924   5970                         SQLITE_DEFAULT_FILE_PERMISSIONS);
  5925   5971           OSTRACE(("TRANSPROXY: OPEN  %d\n", fd));
  5926   5972           if( fd>=0 ){
  5927   5973             pFile->h = fd;