1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-27 20:41:58 +03:00

Add a version number to the wal-index header. If SQLite encounters a version number in either the wal or wal-index files that it does not understand, the operation is abandoned and SQLITE_CANTOPEN returned.

FossilOrigin-Name: 8d0f8a7f70d6fb42369411a934b30f8c8ca8322f
This commit is contained in:
dan
2010-06-23 15:55:43 +00:00
parent b316cb22de
commit 10f5a50e57
13 changed files with 324 additions and 152 deletions

View File

@ -14,13 +14,77 @@
#
proc wal_file_size {nFrame pgsz} {
expr {24 + ($pgsz+24)*$nFrame}
expr {32 + ($pgsz+24)*$nFrame}
}
proc wal_frame_count {zFile pgsz} {
set f [file size $zFile]
expr {($f - 24) / ($pgsz+24)}
expr {($f - 32) / ($pgsz+24)}
}
proc wal_cksum_intlist {ckv1 ckv2 intlist} {
upvar $ckv1 c1
upvar $ckv2 c2
foreach {v1 v2} $intlist {
set c1 [expr {($c1 + $v1 + $c2)&0xFFFFFFFF}]
set c2 [expr {($c2 + $v2 + $c1)&0xFFFFFFFF}]
}
}
# This proc calculates checksums in the same way as those used by SQLite
# in WAL files. If the $endian argument is "big", then checksums are
# calculated by interpreting data as an array of big-endian integers. If
# it is "little", data is interpreted as an array of little-endian integers.
#
proc wal_cksum {endian ckv1 ckv2 blob} {
upvar $ckv1 c1
upvar $ckv2 c2
if {$endian!="big" && $endian!="little"} {
return -error "Bad value \"$endian\" - must be \"big\" or \"little\""
}
set scanpattern I*
if {$endian == "little"} { set scanpattern i* }
binary scan $blob $scanpattern values
wal_cksum_intlist c1 c2 $values
}
proc wal_set_walhdr {filename {intlist {}}} {
if {[llength $intlist]==6} {
set blob [binary format I6 $intlist]
set endian little
if {[lindex $intlist 0] & 0x00000001} { set endian big }
set c1 0
set c2 0
wal_cksum $endian c1 c2 $blob
append blob [binary format II $c1 $c2]
set fd [open $filename r+]
fconfigure $fd -translation binary
fconfigure $fd -encoding binary
seek $fd 0
puts -nonewline $fd $blob
close $fd
}
set fd [open $filename]
fconfigure $fd -translation binary
fconfigure $fd -encoding binary
set blob [read $fd 24]
binary scan $blob I6 ints
set ints
}
proc wal_fix_walindex_cksum {hdrvar} {
upvar $hdrvar hdr
set c1 0
set c2 0
wal_cksum_intlist c1 c2 [lrange $hdr 0 9]
lset hdr 10 $c1
lset hdr 11 $c2
}