]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add a checksum to the master journal name stored at the end of a journal
authordanielk1977 <danielk1977@noemail.net>
Fri, 25 Jun 2004 11:11:54 +0000 (11:11 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Fri, 25 Jun 2004 11:11:54 +0000 (11:11 +0000)
file. (CVS 1692)

FossilOrigin-Name: 4905e74925a4e9d467c51dc174f265b9395ae9fa

manifest
manifest.uuid
src/pager.c

index 28d24d112a3370c295c32e52f2a6705a3dd5d35a..1d36047bb6c59f723df02a9ffc46b548d4b75a1f 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\scrash.test\sfrom\smemleak.test.\s(CVS\s1691)
-D 2004-06-25T10:26:13
+C Add\sa\schecksum\sto\sthe\smaster\sjournal\sname\sstored\sat\sthe\send\sof\sa\sjournal\nfile.\s(CVS\s1692)
+D 2004-06-25T11:11:54
 F Makefile.in cb7a9889c38723f72b2506c4236ff30a05ff172b
 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -50,7 +50,7 @@ F src/os_unix.c bd62e20d3abfb96c41fe737715b328d1dbb52bf7
 F src/os_unix.h 00c1f82b526ab2fb7ee5ddd555ea4ed68363c93a
 F src/os_win.c 84549f6cc815237533c5d0eb3697352b03478d96
 F src/os_win.h babd4e912967c6b09088cfe38a45e8005a07ba44
-F src/pager.c 65e1b2ed257567016cbc1777378322d9975dd9fd
+F src/pager.c e4c7e844d8ce52bf23d53d25bd5fc506abdcf441
 F src/pager.h bc58d32a9dee464f7268fb68652c130a4216e438
 F src/parse.y 097438674976355a10cf177bd97326c548820b86
 F src/pragma.c 0750e1c360647dbe0a991f16133b0fe5e42e5039
@@ -229,7 +229,7 @@ F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075
 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
 F www/version3.tcl 563ba3ac02f64da27ab17f3edbe8e56bfd0293fb
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P 0322c83776f0c17286e9accb3ed3c72b5be6cdab
-R 1c47d184a887eda9e881c1b4a1d940e7
+P 2a9cea61f90be4881b01f8a7c1ca4dab77706d2f
+R bd27578118e1d5c93a1e7eca81aa4432
 U danielk1977
-Z 0b333313f7015cf5a584993469883429
+Z 3291e0dae2ad58b9c1c0c10b19637fd1
index a8c6290ee47783f4c9d714d5aa7a0a5f2df9742b..f84eef84b998fe6a36d7149a264a75e487c6f4ec 100644 (file)
@@ -1 +1 @@
-2a9cea61f90be4881b01f8a7c1ca4dab77706d2f
\ No newline at end of file
+4905e74925a4e9d467c51dc174f265b9395ae9fa
\ No newline at end of file
index 45eafbb3ca19f773d97b3ea42dbb900a8ee04616..fa63926a75b1ea30e46561f944a3595ffeb39eb3 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.141 2004/06/25 08:32:26 danielk1977 Exp $
+** @(#) $Id: pager.c,v 1.142 2004/06/25 11:11:54 danielk1977 Exp $
 */
 #include "os.h"         /* Must be first to enable large file support */
 #include "sqliteInt.h"
@@ -402,19 +402,24 @@ static int readMasterJournal(OsFile *pJrnl, char **pzMaster){
   int rc;
   u32 len;
   off_t szJ;
+  int cksum;
+  int i;
   unsigned char aMagic[8]; /* A buffer to hold the magic header */
 
   *pzMaster = 0;
 
   rc = sqlite3OsFileSize(pJrnl, &szJ);
-  if( rc!=SQLITE_OK || szJ<12 ) return rc;
+  if( rc!=SQLITE_OK || szJ<16 ) return rc;
 
-  rc = sqlite3OsSeek(pJrnl, szJ-12);
+  rc = sqlite3OsSeek(pJrnl, szJ-16);
   if( rc!=SQLITE_OK ) return rc;
  
   rc = read32bits(pJrnl, &len);
   if( rc!=SQLITE_OK ) return rc;
 
+  rc = read32bits(pJrnl, &cksum);
+  if( rc!=SQLITE_OK ) return rc;
+
   rc = sqlite3OsRead(pJrnl, aMagic, 8);
   if( rc!=SQLITE_OK || memcmp(aMagic, aJournalMagic, 8) ) return rc;
 
@@ -431,6 +436,15 @@ static int readMasterJournal(OsFile *pJrnl, char **pzMaster){
     *pzMaster = 0;
     return rc;
   }
+
+  /* See if the checksum matches the master journal name */
+  for(i=0; i<len; i++){
+    cksum -= *pzMaster[i];
+  }
+  if( !cksum ){
+    sqliteFree(*pzMaster);
+    *pzMaster = 0;
+  }
    
   return SQLITE_OK;
 }
@@ -591,16 +605,33 @@ static int readJournalHdr(
 
 /*
 ** Write the supplied master journal name into the journal file for pager
-** pPager at the current location.
+** pPager at the current location. The master journal name must be the last
+** thing written to a journal file. If the pager is in full-sync mode, the
+** journal file descriptor is advanced to the next sector boundary before
+** anything is written. The format is:
+**
+** + 4 bytes: PAGER_MJ_PGNO.
+** + N bytes: length of master journal name.
+** + 4 bytes: N
+** + 4 bytes: Master journal name checksum.
+** + 8 bytes: aJournalMagic[].
+**
+** The master journal page checksum is the sum of the bytes in the master
+** journal name.
 */
 static int writeMasterJournal(Pager *pPager, const char *zMaster){
   int rc;
   int len; 
+  int i; 
+  int cksum = 0; 
 
   if( !zMaster || pPager->setMaster) return SQLITE_OK;
   pPager->setMaster = 1;
 
   len = strlen(zMaster);
+  for(i=0; i<len; i++){
+    cksum += zMaster[i];
+  }
 
   /* If in full-sync mode, advance to the next disk sector before writing
   ** the master journal name. This is in case the previous page written to
@@ -610,8 +641,7 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
     rc = seekJournalHdr(pPager);
     if( rc!=SQLITE_OK ) return rc;
   }
-
-  pPager->journalOff += (len+16);
+  pPager->journalOff += (len+20);
 
   rc = write32bits(&pPager->jfd, PAGER_MJ_PGNO(pPager));
   if( rc!=SQLITE_OK ) return rc;
@@ -622,6 +652,9 @@ static int writeMasterJournal(Pager *pPager, const char *zMaster){
   rc = write32bits(&pPager->jfd, len);
   if( rc!=SQLITE_OK ) return rc;
 
+  rc = write32bits(&pPager->jfd, cksum);
+  if( rc!=SQLITE_OK ) return rc;
+
   rc = sqlite3OsWrite(&pPager->jfd, aJournalMagic, sizeof(aJournalMagic));
   return rc;
 }