Enhance the "showwal" utility program to show checksum failures on frames.
FossilOrigin-Name: a7f6d19816cbfc50060a9d1c0c402cdd23bd16de
This commit is contained in:
parent
bc46f02c5d
commit
d63ce044d1
12
manifest
12
manifest
@ -1,5 +1,5 @@
|
||||
C Improved\sparsing\sof\sthe\sarguments\sto\sthe\s".backup"\scommand\sin\sthe\s\ncommand-line\sshell.
|
||||
D 2013-01-23T18:53:23.246
|
||||
C Enhance\sthe\s"showwal"\sutility\sprogram\sto\sshow\schecksum\sfailures\son\sframes.
|
||||
D 2013-01-25T15:09:41.890
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in a48faa9e7dd7d556d84f5456eabe5825dd8a6282
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -1016,7 +1016,7 @@ F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a
|
||||
F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5
|
||||
F tool/showdb.c aca2644aa4de7c0cad5821e50bbd55397e0974b8
|
||||
F tool/showjournal.c b62cecaab86a4053d944c276bb5232e4d17ece02
|
||||
F tool/showwal.c f09e5a80a293919290ec85a6a37c85a5ddcf37d9
|
||||
F tool/showwal.c 2ef22ea67806f0e9fdba8083989c30e4bf4002e3
|
||||
F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe
|
||||
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
|
||||
F tool/spaceanal.tcl 76f583a246a0b027f423252339e711f13198932e
|
||||
@ -1034,7 +1034,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381
|
||||
F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac
|
||||
P 5bfb5967d70433bf41d39b57506b7ec167a1b6a0
|
||||
R 08c8109626ac00561b249e6640d8f589
|
||||
P f1127e87b90c7ba049404ec68cb4e99009c22185
|
||||
R 20e35b503c10c06065f1e1625b37816e
|
||||
U drh
|
||||
Z c715715f0fc3823fbef7e95ac29cf308
|
||||
Z fa08d05e69180548469496ecb5ae134e
|
||||
|
@ -1 +1 @@
|
||||
f1127e87b90c7ba049404ec68cb4e99009c22185
|
||||
a7f6d19816cbfc50060a9d1c0c402cdd23bd16de
|
106
tool/showwal.c
106
tool/showwal.c
@ -18,6 +18,65 @@ static int perLine = 16; /* HEX elements to print per line */
|
||||
|
||||
typedef long long int i64; /* Datatype for 64-bit integers */
|
||||
|
||||
/* Information for computing the checksum */
|
||||
typedef struct Cksum Cksum;
|
||||
struct Cksum {
|
||||
int bSwap; /* True to do byte swapping on 32-bit words */
|
||||
unsigned s0, s1; /* Current checksum value */
|
||||
};
|
||||
|
||||
/*
|
||||
** extract a 32-bit big-endian integer
|
||||
*/
|
||||
static unsigned int getInt32(const unsigned char *a){
|
||||
unsigned int x = (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
|
||||
return x;
|
||||
}
|
||||
|
||||
/*
|
||||
** Swap bytes on a 32-bit unsigned integer
|
||||
*/
|
||||
static unsigned int swab32(unsigned int x){
|
||||
return (((x)&0x000000FF)<<24) + (((x)&0x0000FF00)<<8)
|
||||
+ (((x)&0x00FF0000)>>8) + (((x)&0xFF000000)>>24);
|
||||
}
|
||||
|
||||
/* Extend the checksum. Reinitialize the checksum if bInit is true.
|
||||
*/
|
||||
static void extendCksum(
|
||||
Cksum *pCksum,
|
||||
unsigned char *aData,
|
||||
unsigned int nByte,
|
||||
int bInit
|
||||
){
|
||||
unsigned int *a32;
|
||||
if( bInit ){
|
||||
int a = 0;
|
||||
*((char*)&a) = 1;
|
||||
if( a==1 ){
|
||||
/* Host is little-endian */
|
||||
pCksum->bSwap = getInt32(aData)!=0x377f0682;
|
||||
}else{
|
||||
/* Host is big-endian */
|
||||
pCksum->bSwap = getInt32(aData)!=0x377f0683;
|
||||
}
|
||||
pCksum->s0 = 0;
|
||||
pCksum->s1 = 0;
|
||||
}
|
||||
a32 = (unsigned int*)aData;
|
||||
while( nByte>0 ){
|
||||
unsigned int x0 = a32[0];
|
||||
unsigned int x1 = a32[1];
|
||||
if( pCksum->bSwap ){
|
||||
x0 = swab32(x0);
|
||||
x1 = swab32(x1);
|
||||
}
|
||||
pCksum->s0 += x0 + pCksum->s1;
|
||||
pCksum->s1 += x1 + pCksum->s0;
|
||||
nByte -= 8;
|
||||
a32 += 2;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Convert the var-int format into i64. Return the number of bytes
|
||||
@ -152,29 +211,27 @@ static void print_frame(int iFrame){
|
||||
}
|
||||
|
||||
/*
|
||||
** extract a 32-bit big-endian integer
|
||||
** Summarize a single frame on a single line.
|
||||
*/
|
||||
static unsigned int getInt32(const unsigned char *a){
|
||||
unsigned int x = (a[0]<<24) + (a[1]<<16) + (a[2]<<8) + a[3];
|
||||
return x;
|
||||
}
|
||||
|
||||
/*
|
||||
** Print an entire page of content as hex
|
||||
*/
|
||||
static void print_oneline_frame(int iFrame){
|
||||
static void print_oneline_frame(int iFrame, Cksum *pCksum){
|
||||
int iStart;
|
||||
unsigned char *aData;
|
||||
unsigned int s0, s1;
|
||||
iStart = 32 + (iFrame-1)*(pagesize+24);
|
||||
aData = getContent(iStart, 24);
|
||||
fprintf(stdout, "Frame %4d: %6d %6d 0x%08x 0x%08x 0x%08x 0x%08x\n",
|
||||
extendCksum(pCksum, aData, 8, 0);
|
||||
extendCksum(pCksum, getContent(iStart+24, pagesize), pagesize, 0);
|
||||
s0 = getInt32(aData+16);
|
||||
s1 = getInt32(aData+20);
|
||||
fprintf(stdout, "Frame %4d: %6d %6d 0x%08x,%08x 0x%08x,%08x %s\n",
|
||||
iFrame,
|
||||
getInt32(aData),
|
||||
getInt32(aData+4),
|
||||
getInt32(aData+8),
|
||||
getInt32(aData+12),
|
||||
getInt32(aData+16),
|
||||
getInt32(aData+20)
|
||||
s0,
|
||||
s1,
|
||||
(s0==pCksum->s0 && s1==pCksum->s1) ? "cksum-ok" : "cksum-fail"
|
||||
);
|
||||
free(aData);
|
||||
}
|
||||
@ -182,9 +239,13 @@ static void print_oneline_frame(int iFrame){
|
||||
/*
|
||||
** Decode the WAL header.
|
||||
*/
|
||||
static void print_wal_header(void){
|
||||
static void print_wal_header(Cksum *pCksum){
|
||||
unsigned char *aData;
|
||||
aData = getContent(0, 32);
|
||||
if( pCksum ){
|
||||
extendCksum(pCksum, aData, 24, 1);
|
||||
printf("Checksum byte order: %s\n", pCksum->bSwap ? "swapped" : "native");
|
||||
}
|
||||
printf("WAL Header:\n");
|
||||
print_decode_line(aData, 0, 4,1,"Magic. 0x377f0682 (le) or 0x377f0683 (be)");
|
||||
print_decode_line(aData, 4, 4, 0, "File format");
|
||||
@ -194,6 +255,14 @@ static void print_wal_header(void){
|
||||
print_decode_line(aData, 20,4, 1, "Salt-2");
|
||||
print_decode_line(aData, 24,4, 1, "Checksum-1");
|
||||
print_decode_line(aData, 28,4, 1, "Checksum-2");
|
||||
if( pCksum ){
|
||||
if( pCksum->s0!=getInt32(aData+24) ){
|
||||
printf("**** cksum-1 mismatch: 0x%08x\n", pCksum->s0);
|
||||
}
|
||||
if( pCksum->s1!=getInt32(aData+28) ){
|
||||
printf("**** cksum-2 mismatch: 0x%08x\n", pCksum->s1);
|
||||
}
|
||||
}
|
||||
free(aData);
|
||||
}
|
||||
|
||||
@ -298,15 +367,18 @@ int main(int argc, char **argv){
|
||||
printf("Available pages: 1..%d\n", mxFrame);
|
||||
if( argc==2 ){
|
||||
int i;
|
||||
print_wal_header();
|
||||
for(i=1; i<=mxFrame; i++) print_oneline_frame(i);
|
||||
Cksum x;
|
||||
print_wal_header(&x);
|
||||
for(i=1; i<=mxFrame; i++){
|
||||
print_oneline_frame(i, &x);
|
||||
}
|
||||
}else{
|
||||
int i;
|
||||
for(i=2; i<argc; i++){
|
||||
int iStart, iEnd;
|
||||
char *zLeft;
|
||||
if( strcmp(argv[i], "header")==0 ){
|
||||
print_wal_header();
|
||||
print_wal_header(0);
|
||||
continue;
|
||||
}
|
||||
if( !isdigit(argv[i][0]) ){
|
||||
|
Loading…
x
Reference in New Issue
Block a user