mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-05 15:55:57 +03:00
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:
39
src/btree.c
39
src/btree.c
@@ -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);
|
||||
|
Reference in New Issue
Block a user