Add the "PRAGMA secure_delete=FAST" option, which overwrites most deleted
content without increasing the amount of I/O. Deleted content might persist on the free page list, however. And extra CPU cycles are used for zeroing, of course. FossilOrigin-Name: 38978ce65b280bb7cba3fc08ba91485fb1b84cd9fbba2e950ecf41c021ff452a
This commit is contained in:
+28
-11
@@ -1640,7 +1640,7 @@ static int freeSpace(MemPage *pPage, u16 iStart, u16 iSize){
|
||||
|
||||
/* Overwrite deleted information with zeros when the secure_delete
|
||||
** option is enabled */
|
||||
if( pPage->pBt->btsFlags & BTS_SECURE_DELETE ){
|
||||
if( pPage->pBt->btsFlags & BTS_FAST_SECURE ){
|
||||
memset(&data[iStart], 0, iSize);
|
||||
}
|
||||
|
||||
@@ -1931,7 +1931,7 @@ static void zeroPage(MemPage *pPage, int flags){
|
||||
assert( sqlite3PagerGetData(pPage->pDbPage) == data );
|
||||
assert( sqlite3PagerIswriteable(pPage->pDbPage) );
|
||||
assert( sqlite3_mutex_held(pBt->mutex) );
|
||||
if( pBt->btsFlags & BTS_SECURE_DELETE ){
|
||||
if( pBt->btsFlags & BTS_FAST_SECURE ){
|
||||
memset(&data[hdr], 0, pBt->usableSize - hdr);
|
||||
}
|
||||
data[hdr] = (char)flags;
|
||||
@@ -2354,8 +2354,10 @@ int sqlite3BtreeOpen(
|
||||
pBt->pCursor = 0;
|
||||
pBt->pPage1 = 0;
|
||||
if( sqlite3PagerIsreadonly(pBt->pPager) ) pBt->btsFlags |= BTS_READ_ONLY;
|
||||
#ifdef SQLITE_SECURE_DELETE
|
||||
#if defined(SQLITE_SECURE_DELETE)
|
||||
pBt->btsFlags |= BTS_SECURE_DELETE;
|
||||
#elif defined(SQLITE_FAST_SECURE_DELETE)
|
||||
pBt->btsFlags |= BTS_OVERWRITE;
|
||||
#endif
|
||||
/* EVIDENCE-OF: R-51873-39618 The page size for a database file is
|
||||
** determined by the 2-byte integer located at an offset of 16 bytes from
|
||||
@@ -2803,19 +2805,34 @@ int sqlite3BtreeMaxPageCount(Btree *p, int mxPage){
|
||||
}
|
||||
|
||||
/*
|
||||
** Set the BTS_SECURE_DELETE flag if newFlag is 0 or 1. If newFlag is -1,
|
||||
** then make no changes. Always return the value of the BTS_SECURE_DELETE
|
||||
** setting after the change.
|
||||
** Change the values for the BTS_SECURE_DELETE and BTS_OVERWRITE flags:
|
||||
**
|
||||
** newFlag==0 Both BTS_SECURE_DELETE and BTS_OVERWRITE are cleared
|
||||
** newFlag==1 BTS_SECURE_DELETE set and BTS_OVERWRITE is cleared
|
||||
** newFlag==2 BTS_SECURE_DELETE cleared and BTS_OVERWRITE is set
|
||||
** newFlag==(-1) No changes
|
||||
**
|
||||
** This routine acts as a query if newFlag is less than zero
|
||||
**
|
||||
** With BTS_OVERWRITE set, deleted content is overwritten by zeros, but
|
||||
** freelist leaf pages are not written back to the database. Thus in-page
|
||||
** deleted content is cleared, but freelist deleted content is not.
|
||||
**
|
||||
** With BTS_SECURE_DELETE, operation is like BTS_OVERWRITE with the addition
|
||||
** that freelist leaf pages are written back into the database, increasing
|
||||
** the amount of disk I/O.
|
||||
*/
|
||||
int sqlite3BtreeSecureDelete(Btree *p, int newFlag){
|
||||
int b;
|
||||
if( p==0 ) return 0;
|
||||
sqlite3BtreeEnter(p);
|
||||
assert( BTS_OVERWRITE==BTS_SECURE_DELETE*2 );
|
||||
assert( BTS_FAST_SECURE==(BTS_OVERWRITE|BTS_SECURE_DELETE) );
|
||||
if( newFlag>=0 ){
|
||||
p->pBt->btsFlags &= ~BTS_SECURE_DELETE;
|
||||
if( newFlag ) p->pBt->btsFlags |= BTS_SECURE_DELETE;
|
||||
}
|
||||
b = (p->pBt->btsFlags & BTS_SECURE_DELETE)!=0;
|
||||
p->pBt->btsFlags &= ~BTS_FAST_SECURE;
|
||||
p->pBt->btsFlags |= BTS_SECURE_DELETE*newFlag;
|
||||
}
|
||||
b = (p->pBt->btsFlags & BTS_FAST_SECURE)/BTS_SECURE_DELETE;
|
||||
sqlite3BtreeLeave(p);
|
||||
return b;
|
||||
}
|
||||
@@ -7210,7 +7227,7 @@ static int balance_nonroot(
|
||||
** In this case, temporarily copy the cell into the aOvflSpace[]
|
||||
** buffer. It will be copied out again as soon as the aSpace[] buffer
|
||||
** is allocated. */
|
||||
if( pBt->btsFlags & BTS_SECURE_DELETE ){
|
||||
if( pBt->btsFlags & BTS_FAST_SECURE ){
|
||||
int iOff;
|
||||
|
||||
iOff = SQLITE_PTR_TO_INT(apDiv[i]) - SQLITE_PTR_TO_INT(pParent->aData);
|
||||
|
||||
+6
-4
@@ -448,10 +448,12 @@ struct BtShared {
|
||||
#define BTS_READ_ONLY 0x0001 /* Underlying file is readonly */
|
||||
#define BTS_PAGESIZE_FIXED 0x0002 /* Page size can no longer be changed */
|
||||
#define BTS_SECURE_DELETE 0x0004 /* PRAGMA secure_delete is enabled */
|
||||
#define BTS_INITIALLY_EMPTY 0x0008 /* Database was empty at trans start */
|
||||
#define BTS_NO_WAL 0x0010 /* Do not open write-ahead-log files */
|
||||
#define BTS_EXCLUSIVE 0x0020 /* pWriter has an exclusive lock */
|
||||
#define BTS_PENDING 0x0040 /* Waiting for read-locks to clear */
|
||||
#define BTS_OVERWRITE 0x0008 /* Overwrite deleted content with zeros */
|
||||
#define BTS_FAST_SECURE 0x000c /* Combination of the previous two */
|
||||
#define BTS_INITIALLY_EMPTY 0x0010 /* Database was empty at trans start */
|
||||
#define BTS_NO_WAL 0x0020 /* Do not open write-ahead-log files */
|
||||
#define BTS_EXCLUSIVE 0x0040 /* pWriter has an exclusive lock */
|
||||
#define BTS_PENDING 0x0080 /* Waiting for read-locks to clear */
|
||||
|
||||
/*
|
||||
** An instance of the following structure is used to hold information
|
||||
|
||||
+7
-3
@@ -515,18 +515,22 @@ void sqlite3Pragma(
|
||||
|
||||
/*
|
||||
** PRAGMA [schema.]secure_delete
|
||||
** PRAGMA [schema.]secure_delete=ON/OFF
|
||||
** PRAGMA [schema.]secure_delete=ON/OFF/FAST
|
||||
**
|
||||
** The first form reports the current setting for the
|
||||
** secure_delete flag. The second form changes the secure_delete
|
||||
** flag setting and reports thenew value.
|
||||
** flag setting and reports the new value.
|
||||
*/
|
||||
case PragTyp_SECURE_DELETE: {
|
||||
Btree *pBt = pDb->pBt;
|
||||
int b = -1;
|
||||
assert( pBt!=0 );
|
||||
if( zRight ){
|
||||
b = sqlite3GetBoolean(zRight, 0);
|
||||
if( sqlite3_stricmp(zRight, "fast")==0 ){
|
||||
b = 2;
|
||||
}else{
|
||||
b = sqlite3GetBoolean(zRight, 0);
|
||||
}
|
||||
}
|
||||
if( pId2->n==0 && b>=0 ){
|
||||
int ii;
|
||||
|
||||
Reference in New Issue
Block a user