/ Check-in [6191c5e4]
Login

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

Overview
Comment:Change the name ZERO_DAMAGE to the more descriptive POWERSAFE_OVERWRITE. The query parameter used to control this device characteristic is now "psow".
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | statvfs
Files: files | file ages | folders
SHA1: 6191c5e45175f5c6040e891843b0725a929d6dd7
User & Date: drh 2011-12-23 01:04:17
Context
2011-12-23
02:07
Merge the POWERSAFE_OVERWRITE features and the use of statvfs() from the statvfs branch into trunk. check-in: 2370d70e user: drh tags: trunk
01:04
Change the name ZERO_DAMAGE to the more descriptive POWERSAFE_OVERWRITE. The query parameter used to control this device characteristic is now "psow". Closed-Leaf check-in: 6191c5e4 user: drh tags: statvfs
00:25
Merge the latest trunk changes into the statvfs branch. check-in: d5e36327 user: drh tags: statvfs
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/os_unix.c.

   259    259   #define UNIXFILE_RDONLY      0x02     /* Connection is read only */
   260    260   #define UNIXFILE_PERSIST_WAL 0x04     /* Persistent WAL mode */
   261    261   #ifndef SQLITE_DISABLE_DIRSYNC
   262    262   # define UNIXFILE_DIRSYNC    0x08     /* Directory sync needed */
   263    263   #else
   264    264   # define UNIXFILE_DIRSYNC    0x00
   265    265   #endif
   266         -#define UNIXFILE_ZERO_DAMAGE 0x10     /* True if SQLITE_IOCAP_ZERO_DAMAGE */
          266  +#define UNIXFILE_PSOW        0x10     /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
   267    267   
   268    268   /*
   269    269   ** Include code that is common to all os_*.c files
   270    270   */
   271    271   #include "os_common.h"
   272    272   
   273    273   /*
................................................................................
  3553   3553         SimulateIOErrorBenign(0);
  3554   3554         return rc;
  3555   3555       }
  3556   3556       case SQLITE_FCNTL_PERSIST_WAL: {
  3557   3557         unixModeBit(pFile, UNIXFILE_PERSIST_WAL, (int*)pArg);
  3558   3558         return SQLITE_OK;
  3559   3559       }
  3560         -    case SQLITE_FCNTL_ZERO_DAMAGE: {
  3561         -      unixModeBit(pFile, UNIXFILE_ZERO_DAMAGE, (int*)pArg);
         3560  +    case SQLITE_FCNTL_POWERSAFE_OVERWRITE: {
         3561  +      unixModeBit(pFile, UNIXFILE_PSOW, (int*)pArg);
  3562   3562         return SQLITE_OK;
  3563   3563       }
  3564   3564       case SQLITE_FCNTL_VFSNAME: {
  3565   3565         *(char**)pArg = sqlite3_mprintf("%s", pFile->pVfs->zName);
  3566   3566         return SQLITE_OK;
  3567   3567       }
  3568   3568   #ifndef NDEBUG
................................................................................
  3618   3618     }
  3619   3619     return p->szSector*512;
  3620   3620   }
  3621   3621   
  3622   3622   /*
  3623   3623   ** Return the device characteristics for the file.
  3624   3624   **
  3625         -** This VFS is set up to return SQLITE_IOCAP_ZERO_DAMAGE by default.
  3626         -** However, that choice is contraversial sicne technically the underlying
  3627         -** file system does not always provide ZERO_DAMAGE.  (In other words, after
  3628         -** a power-loss event, parts of the file that were never written might end
  3629         -** up being altered.)  However, non-ZERO-DAMAGE behavior is very, very rare.
  3630         -** And asserting ZERO_DAMAGE makes a large reduction in the amount of required
  3631         -** I/O.  Hence, while ZERO_DAMAGE is on by default, there is a file-control
  3632         -** available to turn it off.
         3625  +** This VFS is set up to return SQLITE_IOCAP_POWERSAFE_OVERWRITE by default.
         3626  +** However, that choice is contraversial since technically the underlying
         3627  +** file system does not always provide powersafe overwrites.  (In other
         3628  +** words, after a power-loss event, parts of the file that were never
         3629  +** written might end up being altered.)  However, non-PSOW behavior is very,
         3630  +** very rare.  And asserting PSOW makes a large reduction in the amount
         3631  +** of required I/O for journaling, since a lot of padding is eliminated.
         3632  +**  Hence, while POWERSAFE_OVERWRITE is on by default, there is a file-control
         3633  +** available to turn it off and URI query parameter available to turn it off.
  3633   3634   */
  3634   3635   static int unixDeviceCharacteristics(sqlite3_file *id){
  3635   3636     unixFile *p = (unixFile*)id;
  3636         -  return (p->ctrlFlags & UNIXFILE_ZERO_DAMAGE) ? SQLITE_IOCAP_ZERO_DAMAGE : 0;
         3637  +  if( p->ctrlFlags & UNIXFILE_PSOW ){
         3638  +    return SQLITE_IOCAP_POWERSAFE_OVERWRITE;
         3639  +  }else{
         3640  +    return 0;
         3641  +  }
  3637   3642   }
  3638   3643   
  3639   3644   #ifndef SQLITE_OMIT_WAL
  3640   3645   
  3641   3646   
  3642   3647   /*
  3643   3648   ** Object used to represent an shared memory buffer.  
................................................................................
  4613   4618     assert( zFilename!=0 || noLock );
  4614   4619   
  4615   4620     OSTRACE(("OPEN    %-3d %s\n", h, zFilename));
  4616   4621     pNew->h = h;
  4617   4622     pNew->pVfs = pVfs;
  4618   4623     pNew->zPath = zFilename;
  4619   4624     pNew->ctrlFlags = 0;
  4620         -  if( sqlite3_uri_boolean(zFilename, "zero_damage", 1) ){
  4621         -    pNew->ctrlFlags |= UNIXFILE_ZERO_DAMAGE;
         4625  +  if( sqlite3_uri_boolean(zFilename, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
         4626  +    pNew->ctrlFlags |= UNIXFILE_PSOW;
  4622   4627     }
  4623   4628     if( memcmp(pVfs->zName,"unix-excl",10)==0 ){
  4624   4629       pNew->ctrlFlags |= UNIXFILE_EXCL;
  4625   4630     }
  4626   4631     if( isReadOnly ){
  4627   4632       pNew->ctrlFlags |= UNIXFILE_RDONLY;
  4628   4633     }

Changes to src/os_win.c.

    74     74   #endif
    75     75   };
    76     76   
    77     77   /*
    78     78   ** Allowed values for winFile.ctrlFlags
    79     79   */
    80     80   #define WINFILE_PERSIST_WAL     0x04   /* Persistent WAL mode */
    81         -#define WINFILE_ZERO_DAMAGE     0x10   /* True if SQLITE_IOCAP_ZERO_DAMAGE */
           81  +#define WINFILE_PSOW            0x10   /* SQLITE_IOCAP_POWERSAFE_OVERWRITE */
    82     82   
    83     83   /*
    84     84    * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the
    85     85    * various Win32 API heap functions instead of our own.
    86     86    */
    87     87   #ifdef SQLITE_WIN32_MALLOC
    88     88   /*
................................................................................
  2181   2181         }
  2182   2182         return SQLITE_OK;
  2183   2183       }
  2184   2184       case SQLITE_FCNTL_PERSIST_WAL: {
  2185   2185         winModeBit(pFile, WINFILE_PERSIST_WAL, (int*)pArg);
  2186   2186         return SQLITE_OK;
  2187   2187       }
  2188         -    case SQLITE_FCNTL_ZERO_DAMAGE: {
  2189         -      winModeBit(pFile, WINFILE_ZERO_DAMAGE, (int*)pArg);
         2188  +    case SQLITE_FCNTL_POWERSAFE_OVERWRITE: {
         2189  +      winModeBit(pFile, WINFILE_PSOW, (int*)pArg);
  2190   2190         return SQLITE_OK;
  2191   2191       }
  2192   2192       case SQLITE_FCNTL_VFSNAME: {
  2193   2193         *(char**)pArg = sqlite3_mprintf("win32");
  2194   2194         return SQLITE_OK;
  2195   2195       }
  2196   2196       case SQLITE_FCNTL_SYNC_OMITTED: {
................................................................................
  2231   2231   
  2232   2232   /*
  2233   2233   ** Return a vector of device characteristics.
  2234   2234   */
  2235   2235   static int winDeviceCharacteristics(sqlite3_file *id){
  2236   2236     winFile *p = (winFile*)id;
  2237   2237     return SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN |
  2238         -         ((p->ctrlFlags & WINFILE_ZERO_DAMAGE)?SQLITE_IOCAP_ZERO_DAMAGE:0);
         2238  +         ((p->ctrlFlags & WINFILE_PSOW)?SQLITE_IOCAP_POWERSAFE_OVERWRITE:0);
  2239   2239   }
  2240   2240   
  2241   2241   #ifndef SQLITE_OMIT_WAL
  2242   2242   
  2243   2243   /* 
  2244   2244   ** Windows will only let you create file view mappings
  2245   2245   ** on allocation size granularity boundaries.
................................................................................
  3196   3196     memset(pFile, 0, sizeof(*pFile));
  3197   3197     pFile->pMethod = &winIoMethod;
  3198   3198     pFile->h = h;
  3199   3199     pFile->lastErrno = NO_ERROR;
  3200   3200     pFile->pVfs = pVfs;
  3201   3201     pFile->pShm = 0;
  3202   3202     pFile->zPath = zName;
  3203         -  if( sqlite3_uri_boolean(zName, "zero_damage", 1) ){
  3204         -    pFile->ctrlFlags |= WINFILE_ZERO_DAMAGE;
         3203  +  if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){
         3204  +    pFile->ctrlFlags |= WINFILE_PSOW;
  3205   3205     }
  3206   3206     pFile->sectorSize = getSectorSize(pVfs, zUtf8Name);
  3207   3207   
  3208   3208   #if SQLITE_OS_WINCE
  3209   3209     if( isReadWrite && eType==SQLITE_OPEN_MAIN_DB
  3210   3210          && !winceCreateLock(zName, pFile)
  3211   3211     ){

Changes to src/pager.c.

  2512   2512   ** For temporary files the effective sector size is always 512 bytes.
  2513   2513   **
  2514   2514   ** Otherwise, for non-temporary files, the effective sector size is
  2515   2515   ** the value returned by the xSectorSize() method rounded up to 32 if
  2516   2516   ** it is less than 32, or rounded down to MAX_SECTOR_SIZE if it
  2517   2517   ** is greater than MAX_SECTOR_SIZE.
  2518   2518   **
  2519         -** If the file has the SQLITE_IOCAP_ZERO_DAMAGE property, then set the
  2520         -** effective sector size to its minimum value (512).  The purpose of
         2519  +** If the file has the SQLITE_IOCAP_POWERSAFE_OVERWRITE property, then set
         2520  +** the effective sector size to its minimum value (512).  The purpose of
  2521   2521   ** pPager->sectorSize is to define the "blast radius" of bytes that
  2522   2522   ** might change if a crash occurs while writing to a single byte in
  2523         -** that range.  But with ZERO_DAMAGE, the blast radius is zero, so
  2524         -** we minimize the sector size.  For backwards compatibility of the
  2525         -** rollback journal file format, we cannot reduce the effective sector
  2526         -** size below 512.
         2523  +** that range.  But with POWERSAFE_OVERWRITE, the blast radius is zero
         2524  +** (that is what POWERSAFE_OVERWRITE means), so we minimize the sector
         2525  +** size.  For backwards compatibility of the rollback journal file format,
         2526  +** we cannot reduce the effective sector size below 512.
  2527   2527   */
  2528   2528   static void setSectorSize(Pager *pPager){
  2529   2529     assert( isOpen(pPager->fd) || pPager->tempFile );
  2530   2530   
  2531   2531     if( pPager->tempFile
  2532         -   || (sqlite3OsDeviceCharacteristics(pPager->fd)&SQLITE_IOCAP_ZERO_DAMAGE)!=0
         2532  +   || (sqlite3OsDeviceCharacteristics(pPager->fd) & 
         2533  +              SQLITE_IOCAP_POWERSAFE_OVERWRITE)!=0
  2533   2534     ){
  2534   2535       /* Sector size doesn't matter for temporary files. Also, the file
  2535   2536       ** may not have been opened yet, in which case the OsSectorSize()
  2536   2537       ** call will segfault. */
  2537   2538       pPager->sectorSize = 512;
  2538   2539     }else{
  2539   2540       pPager->sectorSize = sqlite3OsSectorSize(pPager->fd);

Changes to src/sqlite.h.in.

   500    500   ** mean that writes of blocks that are nnn bytes in size and
   501    501   ** are aligned to an address which is an integer multiple of
   502    502   ** nnn are atomic.  The SQLITE_IOCAP_SAFE_APPEND value means
   503    503   ** that when data is appended to a file, the data is appended
   504    504   ** first then the size of the file is extended, never the other
   505    505   ** way around.  The SQLITE_IOCAP_SEQUENTIAL property means that
   506    506   ** information is written to disk in the same order as calls
   507         -** to xWrite().  The SQLITE_IOCAP_ZERO_DAMAGE property means that
          507  +** to xWrite().  The SQLITE_IOCAP_POWERSAFE_OVERWRITE property means that
   508    508   ** after reboot following a crash or power loss, the value of
   509    509   ** each byte in a file is a value that was actually written
   510    510   ** into that byte at some point.  In other words, a crash will
   511         -** not introduce garbage or randomness into a file, and byte of
          511  +** not cause unwritten bytes of the file to change nor introduce 
          512  +** randomness into a file nor zero out parts of the file, and any byte of
   512    513   ** a file that are never written will not change values due to
   513    514   ** writes to nearby bytes.
   514    515   */
   515    516   #define SQLITE_IOCAP_ATOMIC                 0x00000001
   516    517   #define SQLITE_IOCAP_ATOMIC512              0x00000002
   517    518   #define SQLITE_IOCAP_ATOMIC1K               0x00000004
   518    519   #define SQLITE_IOCAP_ATOMIC2K               0x00000008
................................................................................
   520    521   #define SQLITE_IOCAP_ATOMIC8K               0x00000020
   521    522   #define SQLITE_IOCAP_ATOMIC16K              0x00000040
   522    523   #define SQLITE_IOCAP_ATOMIC32K              0x00000080
   523    524   #define SQLITE_IOCAP_ATOMIC64K              0x00000100
   524    525   #define SQLITE_IOCAP_SAFE_APPEND            0x00000200
   525    526   #define SQLITE_IOCAP_SEQUENTIAL             0x00000400
   526    527   #define SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN  0x00000800
   527         -#define SQLITE_IOCAP_ZERO_DAMAGE            0x00001000
          528  +#define SQLITE_IOCAP_POWERSAFE_OVERWRITE    0x00001000
   528    529   
   529    530   /*
   530    531   ** CAPI3REF: File Locking Levels
   531    532   **
   532    533   ** SQLite uses one of these integer values as the second
   533    534   ** argument to calls it makes to the xLock() and xUnlock() methods
   534    535   ** of an [sqlite3_io_methods] object.
................................................................................
   770    771   ** to read the database file, as the WAL and shared memory files must exist
   771    772   ** in order for the database to be readable.  The fourth parameter to
   772    773   ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
   773    774   ** That integer is 0 to disable persistent WAL mode or 1 to enable persistent
   774    775   ** WAL mode.  If the integer is -1, then it is overwritten with the current
   775    776   ** WAL persistence setting.
   776    777   **
   777         -** ^The [SQLITE_FCNTL_ZERO_DAMAGE] opcode is used to set or query the
   778         -** persistent zero-damage setting.  The zero-damage setting determines
   779         -** the [SQLITE_IOCAP_ZERO_DAMAGE] bit of the xDeviceCharacteristics methods.
   780         -** The fourth parameter to
          778  +** ^The [SQLITE_FCNTL_POWERSAFE_OVERWRITE] opcode is used to set or query the
          779  +** persistent "powersafe-overwrite" or "PSOW" setting.  The PSOW setting
          780  +** determines the [SQLITE_IOCAP_POWERSAFE_OVERWRITE] bit of the
          781  +** xDeviceCharacteristics methods. The fourth parameter to
   781    782   ** [sqlite3_file_control()] for this opcode should be a pointer to an integer.
   782    783   ** That integer is 0 to disable zero-damage mode or 1 to enable zero-damage
   783    784   ** mode.  If the integer is -1, then it is overwritten with the current
   784    785   ** zero-damage mode setting.
   785    786   **
   786    787   ** ^The [SQLITE_FCNTL_OVERWRITE] opcode is invoked by SQLite after opening
   787    788   ** a write transaction to indicate that, unless it is rolled back for some
................................................................................
   795    796   ** that the fourth parameter of [sqlite3_file_control()] points to.
   796    797   ** The caller is responsible for freeing the memory when done.  As with
   797    798   ** all file-control actions, there is no guarantee that this will actually
   798    799   ** do anything.  Callers should initialize the char* variable to a NULL
   799    800   ** pointer in case this file-control is not implemented.  This file-control
   800    801   ** is intended for diagnostic use only.
   801    802   */
   802         -#define SQLITE_FCNTL_LOCKSTATE        1
   803         -#define SQLITE_GET_LOCKPROXYFILE      2
   804         -#define SQLITE_SET_LOCKPROXYFILE      3
   805         -#define SQLITE_LAST_ERRNO             4
   806         -#define SQLITE_FCNTL_SIZE_HINT        5
   807         -#define SQLITE_FCNTL_CHUNK_SIZE       6
   808         -#define SQLITE_FCNTL_FILE_POINTER     7
   809         -#define SQLITE_FCNTL_SYNC_OMITTED     8
   810         -#define SQLITE_FCNTL_WIN32_AV_RETRY   9
   811         -#define SQLITE_FCNTL_PERSIST_WAL     10
   812         -#define SQLITE_FCNTL_OVERWRITE       11
   813         -#define SQLITE_FCNTL_VFSNAME         12
   814         -#define SQLITE_FCNTL_ZERO_DAMAGE     13
          803  +#define SQLITE_FCNTL_LOCKSTATE               1
          804  +#define SQLITE_GET_LOCKPROXYFILE             2
          805  +#define SQLITE_SET_LOCKPROXYFILE             3
          806  +#define SQLITE_LAST_ERRNO                    4
          807  +#define SQLITE_FCNTL_SIZE_HINT               5
          808  +#define SQLITE_FCNTL_CHUNK_SIZE              6
          809  +#define SQLITE_FCNTL_FILE_POINTER            7
          810  +#define SQLITE_FCNTL_SYNC_OMITTED            8
          811  +#define SQLITE_FCNTL_WIN32_AV_RETRY          9
          812  +#define SQLITE_FCNTL_PERSIST_WAL            10
          813  +#define SQLITE_FCNTL_OVERWRITE              11
          814  +#define SQLITE_FCNTL_VFSNAME                12
          815  +#define SQLITE_FCNTL_POWERSAFE_OVERWRITE    13
   815    816   
   816    817   /*
   817    818   ** CAPI3REF: Mutex Handle
   818    819   **
   819    820   ** The mutex module within SQLite defines [sqlite3_mutex] to be an
   820    821   ** abstract type for a mutex object.  The SQLite core never looks
   821    822   ** at the internal representation of an [sqlite3_mutex].  It only

Changes to src/sqliteInt.h.

   121    121   #if defined(THREADSAFE)
   122    122   # define SQLITE_THREADSAFE THREADSAFE
   123    123   #else
   124    124   # define SQLITE_THREADSAFE 1 /* IMP: R-07272-22309 */
   125    125   #endif
   126    126   #endif
   127    127   
          128  +/*
          129  +** Powersafe overwrite is on by default.  But can be turned off using
          130  +** the -DSQLITE_POWERSAFE_OVERWRITE=0 command-line option.
          131  +*/
          132  +#ifndef SQLITE_POWERSAFE_OVERWRITE
          133  +# define SQLITE_POWERSAFE_OVERWRITE 1
          134  +#endif
          135  +
   128    136   /*
   129    137   ** The SQLITE_DEFAULT_MEMSTATUS macro must be defined as either 0 or 1.
   130    138   ** It determines whether or not the features related to 
   131    139   ** SQLITE_CONFIG_MEMSTATUS are available by default or not. This value can
   132    140   ** be overridden at runtime using the sqlite3_config() API.
   133    141   */
   134    142   #if !defined(SQLITE_DEFAULT_MEMSTATUS)

Changes to src/test1.c.

  5232   5232     rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_PERSIST_WAL, (void*)&bPersist);
  5233   5233     sqlite3_snprintf(sizeof(z), z, "%d %d", rc, bPersist);
  5234   5234     Tcl_AppendResult(interp, z, (char*)0);
  5235   5235     return TCL_OK;  
  5236   5236   }
  5237   5237   
  5238   5238   /*
  5239         -** tclcmd:   file_control_zero_damage DB ZERO-DAMAGE-FLAG
         5239  +** tclcmd:   file_control_powersafe_overwrite DB PSOW-FLAG
  5240   5240   **
  5241   5241   ** This TCL command runs the sqlite3_file_control interface with
  5242         -** the SQLITE_FCNTL_ZERO_DAMAGE opcode.
         5242  +** the SQLITE_FCNTL_POWERSAFE_OVERWRITE opcode.
  5243   5243   */
  5244         -static int file_control_zero_damage(
         5244  +static int file_control_powersafe_overwrite(
  5245   5245     ClientData clientData, /* Pointer to sqlite3_enable_XXX function */
  5246   5246     Tcl_Interp *interp,    /* The TCL interpreter that invoked this command */
  5247   5247     int objc,              /* Number of arguments */
  5248   5248     Tcl_Obj *CONST objv[]  /* Command arguments */
  5249   5249   ){
  5250   5250     sqlite3 *db;
  5251   5251     int rc;
  5252         -  int bDamage;
         5252  +  int b;
  5253   5253     char z[100];
  5254   5254   
  5255   5255     if( objc!=3 ){
  5256   5256       Tcl_AppendResult(interp, "wrong # args: should be \"",
  5257   5257           Tcl_GetStringFromObj(objv[0], 0), " DB FLAG", 0);
  5258   5258       return TCL_ERROR;
  5259   5259     }
  5260   5260     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ){
  5261   5261       return TCL_ERROR;
  5262   5262     }
  5263         -  if( Tcl_GetIntFromObj(interp, objv[2], &bDamage) ) return TCL_ERROR;
  5264         -  rc = sqlite3_file_control(db, NULL, SQLITE_FCNTL_ZERO_DAMAGE,(void*)&bDamage);
  5265         -  sqlite3_snprintf(sizeof(z), z, "%d %d", rc, bDamage);
         5263  +  if( Tcl_GetIntFromObj(interp, objv[2], &b) ) return TCL_ERROR;
         5264  +  rc = sqlite3_file_control(db,NULL,SQLITE_FCNTL_POWERSAFE_OVERWRITE,(void*)&b);
         5265  +  sqlite3_snprintf(sizeof(z), z, "%d %d", rc, b);
  5266   5266     Tcl_AppendResult(interp, z, (char*)0);
  5267   5267     return TCL_OK;  
  5268   5268   }
  5269   5269   
  5270   5270   
  5271   5271   /*
  5272   5272   ** tclcmd:   file_control_vfsname DB ?AUXDB?
................................................................................
  6121   6121        { "file_control_test",          file_control_test,   0   },
  6122   6122        { "file_control_lasterrno_test", file_control_lasterrno_test,  0   },
  6123   6123        { "file_control_lockproxy_test", file_control_lockproxy_test,  0   },
  6124   6124        { "file_control_chunksize_test", file_control_chunksize_test,  0   },
  6125   6125        { "file_control_sizehint_test",  file_control_sizehint_test,   0   },
  6126   6126        { "file_control_win32_av_retry", file_control_win32_av_retry,  0   },
  6127   6127        { "file_control_persist_wal",    file_control_persist_wal,     0   },
  6128         -     { "file_control_zero_damage",    file_control_zero_damage,     0   },
         6128  +     { "file_control_powersafe_overwrite",file_control_powersafe_overwrite,0},
  6129   6129        { "file_control_vfsname",        file_control_vfsname,         0   },
  6130   6130        { "sqlite3_vfs_list",           vfs_list,     0   },
  6131   6131        { "sqlite3_create_function_v2", test_create_function_v2, 0 },
  6132   6132   
  6133   6133        /* Functions from os.h */
  6134   6134   #ifndef SQLITE_OMIT_UTF16
  6135   6135        { "add_test_collate",        test_collate, 0            },

Changes to src/test6.c.

   701    701     int *piDeviceChar,
   702    702     int *piSectorSize
   703    703   ){
   704    704     struct DeviceFlag {
   705    705       char *zName;
   706    706       int iValue;
   707    707     } aFlag[] = {
   708         -    { "atomic",      SQLITE_IOCAP_ATOMIC      },
   709         -    { "atomic512",   SQLITE_IOCAP_ATOMIC512   },
   710         -    { "atomic1k",    SQLITE_IOCAP_ATOMIC1K    },
   711         -    { "atomic2k",    SQLITE_IOCAP_ATOMIC2K    },
   712         -    { "atomic4k",    SQLITE_IOCAP_ATOMIC4K    },
   713         -    { "atomic8k",    SQLITE_IOCAP_ATOMIC8K    },
   714         -    { "atomic16k",   SQLITE_IOCAP_ATOMIC16K   },
   715         -    { "atomic32k",   SQLITE_IOCAP_ATOMIC32K   },
   716         -    { "atomic64k",   SQLITE_IOCAP_ATOMIC64K   },
   717         -    { "sequential",  SQLITE_IOCAP_SEQUENTIAL  },
   718         -    { "safe_append", SQLITE_IOCAP_SAFE_APPEND },
   719         -    { "zero_damage", SQLITE_IOCAP_ZERO_DAMAGE },
          708  +    { "atomic",              SQLITE_IOCAP_ATOMIC                },
          709  +    { "atomic512",           SQLITE_IOCAP_ATOMIC512             },
          710  +    { "atomic1k",            SQLITE_IOCAP_ATOMIC1K              },
          711  +    { "atomic2k",            SQLITE_IOCAP_ATOMIC2K              },
          712  +    { "atomic4k",            SQLITE_IOCAP_ATOMIC4K              },
          713  +    { "atomic8k",            SQLITE_IOCAP_ATOMIC8K              },
          714  +    { "atomic16k",           SQLITE_IOCAP_ATOMIC16K             },
          715  +    { "atomic32k",           SQLITE_IOCAP_ATOMIC32K             },
          716  +    { "atomic64k",           SQLITE_IOCAP_ATOMIC64K             },
          717  +    { "sequential",          SQLITE_IOCAP_SEQUENTIAL            },
          718  +    { "safe_append",         SQLITE_IOCAP_SAFE_APPEND           },
          719  +    { "powersafe_overwrite", SQLITE_IOCAP_POWERSAFE_OVERWRITE   },
   720    720       { 0, 0 }
   721    721     };
   722    722   
   723    723     int i;
   724    724     int iDc = 0;
   725    725     int iSectorSize = 0;
   726    726     int setSectorsize = 0;

Changes to src/test_vfs.c.

  1158   1158   
  1159   1159       case CMD_DEVCHAR: {
  1160   1160         struct DeviceFlag {
  1161   1161           char *zName;
  1162   1162           int iValue;
  1163   1163         } aFlag[] = {
  1164   1164           { "default",               -1 },
  1165         -        { "atomic",                SQLITE_IOCAP_ATOMIC      },
  1166         -        { "atomic512",             SQLITE_IOCAP_ATOMIC512   },
  1167         -        { "atomic1k",              SQLITE_IOCAP_ATOMIC1K    },
  1168         -        { "atomic2k",              SQLITE_IOCAP_ATOMIC2K    },
  1169         -        { "atomic4k",              SQLITE_IOCAP_ATOMIC4K    },
  1170         -        { "atomic8k",              SQLITE_IOCAP_ATOMIC8K    },
  1171         -        { "atomic16k",             SQLITE_IOCAP_ATOMIC16K   },
  1172         -        { "atomic32k",             SQLITE_IOCAP_ATOMIC32K   },
  1173         -        { "atomic64k",             SQLITE_IOCAP_ATOMIC64K   },
  1174         -        { "sequential",            SQLITE_IOCAP_SEQUENTIAL  },
  1175         -        { "safe_append",           SQLITE_IOCAP_SAFE_APPEND },
         1165  +        { "atomic",                SQLITE_IOCAP_ATOMIC                },
         1166  +        { "atomic512",             SQLITE_IOCAP_ATOMIC512             },
         1167  +        { "atomic1k",              SQLITE_IOCAP_ATOMIC1K              },
         1168  +        { "atomic2k",              SQLITE_IOCAP_ATOMIC2K              },
         1169  +        { "atomic4k",              SQLITE_IOCAP_ATOMIC4K              },
         1170  +        { "atomic8k",              SQLITE_IOCAP_ATOMIC8K              },
         1171  +        { "atomic16k",             SQLITE_IOCAP_ATOMIC16K             },
         1172  +        { "atomic32k",             SQLITE_IOCAP_ATOMIC32K             },
         1173  +        { "atomic64k",             SQLITE_IOCAP_ATOMIC64K             },
         1174  +        { "sequential",            SQLITE_IOCAP_SEQUENTIAL            },
         1175  +        { "safe_append",           SQLITE_IOCAP_SAFE_APPEND           },
  1176   1176           { "undeletable_when_open", SQLITE_IOCAP_UNDELETABLE_WHEN_OPEN },
  1177         -        { "zero_damage",           SQLITE_IOCAP_ZERO_DAMAGE },
         1177  +        { "powersafe_overwrite",   SQLITE_IOCAP_POWERSAFE_OVERWRITE   },
  1178   1178           { 0, 0 }
  1179   1179         };
  1180   1180         Tcl_Obj *pRet;
  1181   1181         int iFlag;
  1182   1182   
  1183   1183         if( objc>3 ){
  1184   1184           Tcl_WrongNumArgs(interp, 2, objv, "?ATTR-LIST?");

Changes to src/wal.c.

  1301   1301     if( rc!=SQLITE_OK ){
  1302   1302       walIndexClose(pRet, 0);
  1303   1303       sqlite3OsClose(pRet->pWalFd);
  1304   1304       sqlite3_free(pRet);
  1305   1305     }else{
  1306   1306       int iDC = sqlite3OsDeviceCharacteristics(pRet->pWalFd);
  1307   1307       if( iDC & SQLITE_IOCAP_SEQUENTIAL ){ pRet->syncHeader = 0; }
  1308         -    if( iDC & SQLITE_IOCAP_ZERO_DAMAGE ){ pRet->padToSectorBoundary = 0; }
         1308  +    if( iDC & SQLITE_IOCAP_POWERSAFE_OVERWRITE ){
         1309  +      pRet->padToSectorBoundary = 0;
         1310  +    }
  1309   1311       *ppWal = pRet;
  1310   1312       WALTRACE(("WAL%d: opened\n", pRet));
  1311   1313     }
  1312   1314     return rc;
  1313   1315   }
  1314   1316   
  1315   1317   /*
................................................................................
  2806   2808     /* If this is the end of a transaction, then we might need to pad
  2807   2809     ** the transaction and/or sync the WAL file.
  2808   2810     **
  2809   2811     ** Padding and syncing only occur if this set of frames complete a
  2810   2812     ** transaction and if PRAGMA synchronous=FULL.  If synchronous==NORMAL
  2811   2813     ** or synchonous==OFF, then no padding or syncing are needed.
  2812   2814     **
  2813         -  ** If SQLITE_IOCAP_ZERO_DAMAGE is defined, then padding is not needed
  2814         -  ** and only the sync is done.  If padding is needed, then the final
  2815         -  ** frame is repeated (with its commit mark) until the next sector
         2815  +  ** If SQLITE_IOCAP_POWERSAFE_OVERWRITE is defined, then padding is not
         2816  +  ** needed and only the sync is done.  If padding is needed, then the
         2817  +  ** final frame is repeated (with its commit mark) until the next sector
  2816   2818     ** boundary is crossed.  Only the part of the WAL prior to the last
  2817   2819     ** sector boundary is synced; the part of the last frame that extends
  2818   2820     ** past the sector boundary is written after the sync.
  2819   2821     */
  2820   2822     if( isCommit && (sync_flags & WAL_SYNC_TRANSACTIONS)!=0 ){
  2821   2823       if( pWal->padToSectorBoundary ){
  2822   2824         int sectorSize = sqlite3OsSectorSize(pWal->pWalFd);

Changes to test/journal2.test.

    30     30     string range [string repeat "${a_string_counter}." $n] 1 $n
    31     31   }
    32     32   
    33     33   # Create a [testvfs] and install it as the default VFS. Set the device
    34     34   # characteristics flags to "SAFE_DELETE".
    35     35   #
    36     36   testvfs tvfs -default 1
    37         -tvfs devchar {undeletable_when_open zero_damage}
           37  +tvfs devchar {undeletable_when_open powersafe_overwrite}
    38     38   
    39     39   # Set up a hook so that each time a journal file is opened, closed or
    40     40   # deleted, the method name ("xOpen", "xClose" or "xDelete") and the final
    41     41   # segment of the journal file-name (i.e. "test.db-journal") are appended to
    42     42   # global list variable $::oplog.
    43     43   #
    44     44   tvfs filter {xOpen xClose xDelete}

Changes to test/zerodamage.test.

     5      5   #
     6      6   #    May you do good and not evil.
     7      7   #    May you find forgiveness for yourself and forgive others.
     8      8   #    May you share freely, never taking more than you give.
     9      9   #
    10     10   #***********************************************************************
    11     11   # 
    12         -# This file implements tests of the SQLITE_IOCAP_ZERO_DAMAGE property
    13         -# and the SQLITE_FCNTL_ZERO_DAMAGE file-control for manipulating it.
           12  +# This file implements tests of the SQLITE_IOCAP_POWERSAFE_OVERWRITE property
           13  +# and the SQLITE_FCNTL_POWERSAFE_OVERWRITE file-control for manipulating it.
           14  +#
           15  +# The name of this file comes from the fact that we used to call the
           16  +# POWERSAFE_OVERWRITE property ZERO_DAMAGE.
    14     17   #
    15     18   
    16     19   set testdir [file dirname $argv0]
    17     20   source $testdir/tester.tcl
    18     21   set testprefix wal5
    19     22   
    20         -# ZERO_DAMAGE defaults to true
           23  +# POWERSAFE_OVERWRITE defaults to true
    21     24   #
    22     25   do_test zerodamage-1.0 {
    23         -  file_control_zero_damage db -1
           26  +  file_control_powersafe_overwrite db -1
    24     27   } {0 1}
    25     28   
    26     29   # Check the ability to turn zero-damage on and off.
    27     30   #
    28     31   do_test zerodamage-1.1 {
    29         -  file_control_zero_damage db 0
    30         -  file_control_zero_damage db -1
           32  +  file_control_powersafe_overwrite db 0
           33  +  file_control_powersafe_overwrite db -1
    31     34   } {0 0}
    32     35   do_test zerodamage-1.2 {
    33         -  file_control_zero_damage db 1
    34         -  file_control_zero_damage db -1
           36  +  file_control_powersafe_overwrite db 1
           37  +  file_control_powersafe_overwrite db -1
    35     38   } {0 1}
    36     39   
    37     40   # Run a transaction with zero-damage on, a small page size and a much larger
    38     41   # sectorsize.  Verify that the maximum journal size is small - that the
    39     42   # rollback journal is not being padded.
    40     43   #
    41     44   do_test zerodamage-2.0 {
    42     45     db close
    43     46     testvfs tv -default 1
    44     47     tv sectorsize 8192
    45         -  sqlite3 db file:test.db?zero_damage=1 -uri 1
           48  +  sqlite3 db file:test.db?psow=TRUE -uri 1
    46     49     unset -nocomplain ::max_journal_size
    47     50     set ::max_journal_size 0
    48     51     proc xDeleteCallback {method file args} {
    49     52       set sz [file size $file]
    50     53       if {$sz>$::max_journal_size} {set ::max_journal_size $sz}
    51     54     }
    52     55     tv filter xDelete
................................................................................
    61     64       INSERT INTO t1 SELECT value, randomblob(100) FROM nums
    62     65                       WHERE value BETWEEN 1 AND 400;
    63     66     }
    64     67     set ::max_journal_size 0
    65     68     db eval {
    66     69       UPDATE t1 SET y=randomblob(50) WHERE x=123;
    67     70     }
    68         -  concat [file_control_zero_damage db -1] [set ::max_journal_size]
           71  +  concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
    69     72   } {0 1 2576}
    70     73   
    71     74   # Repeat the previous step with zero-damage turned off.  This time the
    72     75   # maximum rollback journal size should be much larger.
    73     76   #
    74     77   do_test zerodamage-2.1 {
    75     78     set ::max_journal_size 0
    76     79     db close
    77         -  sqlite3 db file:test.db?zero_damage=0 -uri 1
           80  +  sqlite3 db file:test.db?psow=FALSE -uri 1
    78     81     db eval {
    79     82       UPDATE t1 SET y=randomblob(50) WHERE x=124;
    80     83     }
    81         -  concat [file_control_zero_damage db -1] [set ::max_journal_size]
           84  +  concat [file_control_powersafe_overwrite db -1] [set ::max_journal_size]
    82     85   } {0 0 24704}
    83     86   
    84         -# Run a WAL-mode transaction with ZERO_DAMAGE on to verify that the
           87  +# Run a WAL-mode transaction with POWERSAFE_OVERWRITE on to verify that the
    85     88   # WAL file does not get too big.
    86     89   #
    87     90   do_test zerodamage-3.0 {
    88     91     db eval {
    89     92        PRAGMA journal_mode=WAL;
    90     93     }
    91     94     db close
    92         -  sqlite3 db file:test.db?zero_damage=1 -uri 1
           95  +  sqlite3 db file:test.db?psow=TRUE -uri 1
    93     96     db eval {
    94     97        UPDATE t1 SET y=randomblob(50) WHERE x=124;
    95     98     }
    96     99     file size test.db-wal
    97    100   } {1080}
    98    101   
    99         -# Repeat the previous with ZERO_DAMAGE off.  Verify that the WAL file
          102  +# Repeat the previous with POWERSAFE_OVERWRITE off.  Verify that the WAL file
   100    103   # is padded.
   101    104   #
   102    105   do_test zerodamage-3.1 {
   103    106     db close
   104         -  sqlite3 db file:test.db?zero_damage=0 -uri 1
          107  +  sqlite3 db file:test.db?psow=FALSE -uri 1
   105    108     db eval {
   106    109        UPDATE t1 SET y=randomblob(50) WHERE x=124;
   107    110     }
   108    111     file size test.db-wal
   109    112   } {8416}