/ Check-in [5752d84d]
Login

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

Overview
Comment:Add new OS file method to return the sector-size of the underlying storage: sqlite3OsSectorSize() (CVS 3700)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5752d84d374205e011d49b0221d6237967fe0743
User & Date: danielk1977 2007-03-19 05:54:49
Context
2007-03-19
11:25
Changes to support medium sector sizes larger than the database page size. (CVS 3701) check-in: 3a3e8eb2 user: danielk1977 tags: trunk
05:54
Add new OS file method to return the sector-size of the underlying storage: sqlite3OsSectorSize() (CVS 3700) check-in: 5752d84d user: danielk1977 tags: trunk
2007-03-17
18:22
Add documentation of the REPLACE, TRIM, LTRIM, and RTRIM functions. (CVS 3699) check-in: d42c9636 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os.c.

    71     71   }
    72     72   int sqlite3OsLockState(OsFile *id){
    73     73     return id->pMethod->xLockState(id);
    74     74   }
    75     75   int sqlite3OsCheckReservedLock(OsFile *id){
    76     76     return id->pMethod->xCheckReservedLock(id);
    77     77   }
           78  +int sqlite3OsSectorSize(OsFile *id){
           79  +  return id->pMethod->xSectorSize(id);
           80  +}
    78     81   
    79     82   #ifdef SQLITE_ENABLE_REDEF_IO
    80     83   /*
    81     84   ** A function to return a pointer to the virtual function table.
    82     85   ** This routine really does not accomplish very much since the
    83     86   ** virtual function table is a global variable and anybody who
    84     87   ** can call this function can just as easily access the variable

Changes to src/os.h.

   212    212     void (*xSetFullSync)(OsFile *id, int setting);
   213    213     int (*xFileHandle)(OsFile *id);
   214    214     int (*xFileSize)(OsFile*, i64 *pSize);
   215    215     int (*xLock)(OsFile*, int);
   216    216     int (*xUnlock)(OsFile*, int);
   217    217     int (*xLockState)(OsFile *id);
   218    218     int (*xCheckReservedLock)(OsFile *id);
          219  +  int (*xSectorSize)(OsFile *id);
   219    220   };
   220    221   
   221    222   /*
   222    223   ** The OsFile object describes an open disk file in an OS-dependent way.
   223    224   ** The version of OsFile defined here is a generic version.  Each OS
   224    225   ** implementation defines its own subclass of this structure that contains
   225    226   ** additional information needed to handle file I/O.  But the pMethod
................................................................................
   342    343   int sqlite3OsOpenExclusive(const char*, OsFile**, int);
   343    344   int sqlite3OsOpenReadOnly(const char*, OsFile**);
   344    345   int sqlite3OsDelete(const char*);
   345    346   int sqlite3OsFileExists(const char*);
   346    347   char *sqlite3OsFullPathname(const char*);
   347    348   int sqlite3OsIsDirWritable(char*);
   348    349   int sqlite3OsSyncDirectory(const char*);
          350  +int sqlite3OsSectorSize(OsFile *id);
   349    351   int sqlite3OsTempFileName(char*);
   350    352   int sqlite3OsRandomSeed(char*);
   351    353   int sqlite3OsSleep(int ms);
   352    354   int sqlite3OsCurrentTime(double*);
   353    355   void sqlite3OsEnterMutex(void);
   354    356   void sqlite3OsLeaveMutex(void);
   355    357   int sqlite3OsInMutex(int);

Changes to src/os_common.h.

   186    186   void sqlite3GenericFree(void *p){
   187    187     assert(p);
   188    188     free(p);
   189    189   }
   190    190   /* Never actually used, but needed for the linker */
   191    191   int sqlite3GenericAllocationSize(void *p){ return 0; }
   192    192   #endif
          193  +
          194  +/*
          195  +** The default size of a disk sector
          196  +*/
          197  +#ifndef PAGER_SECTOR_SIZE
          198  +# define PAGER_SECTOR_SIZE 512
          199  +#endif
          200  +static int osGenericSectorSize(OsFile *id){
          201  +  return PAGER_SECTOR_SIZE;
          202  +}
          203  +

Changes to src/os_os2.c.

   747    747     os2SetFullSync,
   748    748     os2FileHandle,
   749    749     os2FileSize,
   750    750     os2Lock,
   751    751     os2Unlock,
   752    752     os2LockState,
   753    753     os2CheckReservedLock,
          754  +  osGenericSectorSize,
   754    755   };
   755    756   
   756    757   /*
   757    758   ** Allocate memory for an OsFile.  Initialize the new OsFile
   758    759   ** to the value given in pInit and return a pointer to the new
   759    760   ** OsFile.  If we run out of memory, close the file and return NULL.
   760    761   */

Changes to src/os_unix.c.

  2351   2351     unixSetFullSync,
  2352   2352     unixFileHandle,
  2353   2353     unixFileSize,
  2354   2354     unixLock,
  2355   2355     unixUnlock,
  2356   2356     unixLockState,
  2357   2357     unixCheckReservedLock,
         2358  +  osGenericSectorSize,
  2358   2359   };
  2359   2360   
  2360   2361   #ifdef SQLITE_ENABLE_LOCKING_STYLE
  2361   2362   /*
  2362   2363    ** This vector defines all the methods that can operate on an OsFile
  2363   2364    ** for unix with AFP style file locking.
  2364   2365    */
................................................................................
  2373   2374       unixSetFullSync,
  2374   2375       unixFileHandle,
  2375   2376       unixFileSize,
  2376   2377       afpUnixLock,
  2377   2378       afpUnixUnlock,
  2378   2379       unixLockState,
  2379   2380       afpUnixCheckReservedLock,
         2381  +    osGenericSectorSize,
  2380   2382   };
  2381   2383   
  2382   2384   /*
  2383   2385    ** This vector defines all the methods that can operate on an OsFile
  2384   2386    ** for unix with flock() style file locking.
  2385   2387    */
  2386   2388   static const IoMethod sqlite3FlockLockingUnixIoMethod = {
................................................................................
  2394   2396       unixSetFullSync,
  2395   2397       unixFileHandle,
  2396   2398       unixFileSize,
  2397   2399       flockUnixLock,
  2398   2400       flockUnixUnlock,
  2399   2401       unixLockState,
  2400   2402       flockUnixCheckReservedLock,
         2403  +    osGenericSectorSize,
  2401   2404   };
  2402   2405   
  2403   2406   /*
  2404   2407    ** This vector defines all the methods that can operate on an OsFile
  2405   2408    ** for unix with dotlock style file locking.
  2406   2409    */
  2407   2410   static const IoMethod sqlite3DotlockLockingUnixIoMethod = {
................................................................................
  2415   2418       unixSetFullSync,
  2416   2419       unixFileHandle,
  2417   2420       unixFileSize,
  2418   2421       dotlockUnixLock,
  2419   2422       dotlockUnixUnlock,
  2420   2423       unixLockState,
  2421   2424       dotlockUnixCheckReservedLock,
         2425  +    osGenericSectorSize,
  2422   2426   };
  2423   2427   
  2424   2428   /*
  2425   2429    ** This vector defines all the methods that can operate on an OsFile
  2426   2430    ** for unix with dotlock style file locking.
  2427   2431    */
  2428   2432   static const IoMethod sqlite3NolockLockingUnixIoMethod = {
................................................................................
  2436   2440     unixSetFullSync,
  2437   2441     unixFileHandle,
  2438   2442     unixFileSize,
  2439   2443     nolockUnixLock,
  2440   2444     nolockUnixUnlock,
  2441   2445     unixLockState,
  2442   2446     nolockUnixCheckReservedLock,
         2447  +  osGenericSectorSize,
  2443   2448   };
  2444   2449   
  2445   2450   #endif /* SQLITE_ENABLE_LOCKING_STYLE */
  2446   2451   
  2447   2452   /*
  2448   2453   ** Allocate memory for a new unixFile and initialize that unixFile.
  2449   2454   ** Write a pointer to the new unixFile into *pId.

Changes to src/os_win.c.

  1469   1469     winSetFullSync,
  1470   1470     winFileHandle,
  1471   1471     winFileSize,
  1472   1472     winLock,
  1473   1473     winUnlock,
  1474   1474     winLockState,
  1475   1475     winCheckReservedLock,
         1476  +  osGenericSectorSize,
  1476   1477   };
  1477   1478   
  1478   1479   /*
  1479   1480   ** Allocate memory for an OsFile.  Initialize the new OsFile
  1480   1481   ** to the value given in pInit and return a pointer to the new
  1481   1482   ** OsFile.  If we run out of memory, close the file and return NULL.
  1482   1483   */

Changes to src/pager.c.

    14     14   ** The pager is used to access a database disk file.  It implements
    15     15   ** atomic commit and rollback through the use of a journal file that
    16     16   ** is separate from the database file.  The pager also implements file
    17     17   ** locking to prevent two processes from writing the same database
    18     18   ** file simultaneously, or one process from reading the database while
    19     19   ** another is writing.
    20     20   **
    21         -** @(#) $Id: pager.c,v 1.288 2007/03/15 12:51:16 drh Exp $
           21  +** @(#) $Id: pager.c,v 1.289 2007/03/19 05:54:49 danielk1977 Exp $
    22     22   */
    23     23   #ifndef SQLITE_OMIT_DISKIO
    24     24   #include "sqliteInt.h"
    25     25   #include "os.h"
    26     26   #include "pager.h"
    27     27   #include <assert.h>
    28     28   #include <string.h>
................................................................................
   345    345   */
   346    346   #ifdef SQLITE_OMIT_MEMORYDB
   347    347   # define MEMDB 0
   348    348   #else
   349    349   # define MEMDB pPager->memDb
   350    350   #endif
   351    351   
   352         -/*
   353         -** The default size of a disk sector
   354         -*/
   355         -#ifndef PAGER_SECTOR_SIZE
   356         -# define PAGER_SECTOR_SIZE 512
   357         -#endif
   358         -
   359    352   /*
   360    353   ** Page number PAGER_MJ_PGNO is never used in an SQLite database (it is
   361    354   ** reserved for working around a windows/posix incompatibility). It is
   362    355   ** used in the journal to signify that the remainder of the journal file 
   363    356   ** is devoted to storing a master journal name - there are no more pages to
   364    357   ** roll back. See comments for function writeMasterJournal() for details.
   365    358   */
................................................................................
  1390   1383       sqliteFree(zMaster);
  1391   1384     }
  1392   1385   
  1393   1386     /* The Pager.sectorSize variable may have been updated while rolling
  1394   1387     ** back a journal created by a process with a different PAGER_SECTOR_SIZE
  1395   1388     ** value. Reset it to the correct value for this process.
  1396   1389     */
  1397         -  pPager->sectorSize = PAGER_SECTOR_SIZE;
         1390  +  pPager->sectorSize = sqlite3OsSectorSize(pPager->fd);
  1398   1391     return rc;
  1399   1392   }
  1400   1393   
  1401   1394   /*
  1402   1395   ** Playback the statement journal.
  1403   1396   **
  1404   1397   ** This is similar to playing back the transaction journal but with
................................................................................
  1734   1727     /* pPager->needSync = 0; */
  1735   1728     pPager->noSync = pPager->tempFile || !useJournal;
  1736   1729     pPager->fullSync = (pPager->noSync?0:1);
  1737   1730     /* pPager->pFirst = 0; */
  1738   1731     /* pPager->pFirstSynced = 0; */
  1739   1732     /* pPager->pLast = 0; */
  1740   1733     pPager->nExtra = FORCE_ALIGNMENT(nExtra);
  1741         -  pPager->sectorSize = PAGER_SECTOR_SIZE;
         1734  +  assert(fd||memDb);
         1735  +  if( !memDb ){
         1736  +    pPager->sectorSize = sqlite3OsSectorSize(fd);
         1737  +  }
  1742   1738     /* pPager->pBusyHandler = 0; */
  1743   1739     /* memset(pPager->aHash, 0, sizeof(pPager->aHash)); */
  1744   1740     *ppPager = pPager;
  1745   1741   #ifdef SQLITE_ENABLE_MEMORY_MANAGEMENT
  1746   1742     pPager->pNext = pTsd->pPager;
  1747   1743     pTsd->pPager = pPager;
  1748   1744   #endif

Changes to src/test6.c.

   473    473   */
   474    474   int crashFileHandle(OsFile *id){
   475    475   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
   476    476     return sqlite3OsFileHandle(((crashFile*)id)->pBase);
   477    477   #endif
   478    478     return 0;
   479    479   }
          480  +
          481  +/*
          482  +** Return the simulated file-system sector size.
          483  +*/
          484  +int crashSectorSize(OsFile *id){
          485  +  return BLOCKSIZE;
          486  +}
   480    487   
   481    488   /*
   482    489   ** This vector defines all the methods that can operate on an OsFile
   483    490   ** for the crash tester.
   484    491   */
   485    492   static const IoMethod crashIoMethod = {
   486    493     crashClose,
................................................................................
   493    500     crashSetFullSync,
   494    501     crashFileHandle,
   495    502     crashFileSize,
   496    503     crashLock,
   497    504     crashUnlock,
   498    505     crashLockState,
   499    506     crashCheckReservedLock,
          507  +  crashSectorSize,
   500    508   };
   501    509   
   502    510   
   503    511   /*
   504    512   ** Initialise the os_test.c specific fields of pFile.
   505    513   */
   506    514   static void initFile(OsFile **pId, char const *zName, OsFile *pBase){

Changes to src/test_async.c.

   645    645     int rc;
   646    646     pthread_mutex_lock(&async.lockMutex);
   647    647     rc = (int)sqlite3HashFind(&async.aLock, pFile->zName, pFile->nName);
   648    648     pthread_mutex_unlock(&async.lockMutex);
   649    649     TRACE(("CHECK-LOCK %d (%s)\n", rc, pFile->zName));
   650    650     return rc>SHARED_LOCK;
   651    651   }
          652  +
          653  +static int asyncSectorSize(OsFile *id){
          654  +  /* TODO: This is tricky to implement, as this backend might not have
          655  +  ** an open file handle at this point.
          656  +  */
          657  +  return 512;
          658  +}
   652    659   
   653    660   /* 
   654    661   ** This is broken. But sqlite3OsLockState() is only used for testing anyway.
   655    662   */
   656    663   static int asyncLockState(OsFile *id){
   657    664     return SQLITE_OK;
   658    665   }
................................................................................
   693    700       asyncSync,
   694    701       asyncSetFullSync,
   695    702       asyncFileHandle,
   696    703       asyncFileSize,
   697    704       asyncLock,
   698    705       asyncUnlock,
   699    706       asyncLockState,
   700         -    asyncCheckReservedLock
          707  +    asyncCheckReservedLock,
          708  +    asyncSectorSize,
   701    709     };
   702    710   
   703    711     if( openForWriting && SQLITE_ASYNC_TWO_FILEHANDLES ){
   704    712       int dummy;
   705    713       rc = xOrigOpenReadWrite(zName, &pBaseWrite, &dummy);
   706    714       if( rc!=SQLITE_OK ){
   707    715         goto error_out;

Changes to test/crash2.test.

    12     12   #
    13     13   # The focus of this file is testing the ability of the database to
    14     14   # uses its rollback journal to recover intact (no database corruption)
    15     15   # from a power failure during the middle of a COMMIT. Even more
    16     16   # specifically, the tests in this file verify this functionality
    17     17   # for storage mediums with various sector sizes.
    18     18   #
    19         -# $Id: crash2.test,v 1.1 2007/03/17 10:28:05 danielk1977 Exp $
           19  +# $Id: crash2.test,v 1.2 2007/03/19 05:54:50 danielk1977 Exp $
    20     20   
    21     21   set testdir [file dirname $argv0]
    22     22   source $testdir/tester.tcl
    23     23   
    24     24   ifcapable !crashtest {
    25     25     finish_test
    26     26     return