mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Updates to the showjournal.c utility in order to bring it up to version 3.
FossilOrigin-Name: fa97d895463be6fd963c29b4525c2664193e36ec
This commit is contained in:
18
manifest
18
manifest
@ -1,8 +1,8 @@
|
||||
-----BEGIN PGP SIGNED MESSAGE-----
|
||||
Hash: SHA1
|
||||
|
||||
C Merge\sexperimental\sinto\strunk:\s\sRefactor\sthe\stext-to-numeric\sconversion\nroutines\sto\swork\swithout\szero-terminators\sand\sin\sUTF16\sas\swell\sas\sUTF8.\nAvoid\sinvalidating\sstrings\swith\sdoing\saffinity\sconversions.
|
||||
D 2010-09-30T20:33:40
|
||||
C Updates\sto\sthe\sshowjournal.c\sutility\sin\sorder\sto\sbring\sit\sup\sto\sversion\s3.
|
||||
D 2010-10-01T13:28:43
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in c599a15d268b1db2aeadea19df2adc3bf2eb6bee
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -864,7 +864,7 @@ F tool/shell3.test 4fad469e8003938426355afdf34155f08c587836
|
||||
F tool/shell4.test 35f9c3d452b4e76d5013c63e1fd07478a62f14ce
|
||||
F tool/shell5.test 62bfaf9267296da1b91e4b1c03e44e7b393f6a94
|
||||
F tool/showdb.c c7a978cf525ef0f8bc2fd29cd52108dd1dfa605a
|
||||
F tool/showjournal.c ec3b171be148656827c4949fbfb8ab4370822f87
|
||||
F tool/showjournal.c b62cecaab86a4053d944c276bb5232e4d17ece02
|
||||
F tool/showwal.c f09e5a80a293919290ec85a6a37c85a5ddcf37d9
|
||||
F tool/soak1.tcl 8d407956e1a45b485a8e072470a3e629a27037fe
|
||||
F tool/space_used.tcl f714c41a59e326b8b9042f415b628b561bafa06b
|
||||
@ -875,14 +875,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P 0a4528d629018eae0b0f3e173ebda666c2e2d502 dd6d61a967e3c0d98b78987f6f7bb9bdf090174e
|
||||
R ad1d113ec850200341f8d4b0b4290fb2
|
||||
P 07ee080ec4527fd2191f41231208da66b3f6b955
|
||||
R 9f2a4041fba267d551d8b2ff622f8fd7
|
||||
U drh
|
||||
Z db01694f0e5febfb397c97bb3dc289ab
|
||||
Z f01f039ec8bab3da1a3e09c88186de66
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
Version: GnuPG v1.4.6 (GNU/Linux)
|
||||
|
||||
iD8DBQFMpPQooxKgR168RlERAuYFAJ48UfDVvwv5OeiELuVh1cra3a7+lACeP6IT
|
||||
GYp3aSgYDm2W/VlxdCCZfbs=
|
||||
=i1hI
|
||||
iD8DBQFMpeIPoxKgR168RlERAoriAJ9XVMPUnrT7ry8RAodedHBJKebqlgCfZklw
|
||||
+EI4nS9fr/f+845hG1I3k0k=
|
||||
=lgHj
|
||||
-----END PGP SIGNATURE-----
|
||||
|
@ -1 +1 @@
|
||||
07ee080ec4527fd2191f41231208da66b3f6b955
|
||||
fa97d895463be6fd963c29b4525c2664193e36ec
|
@ -3,74 +3,137 @@
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
** state information
|
||||
*/
|
||||
static int pageSize = 1024;
|
||||
static int sectorSize = 512;
|
||||
static FILE *db = 0;
|
||||
static int showPageContent = 0;
|
||||
static int fileSize = 0;
|
||||
static unsigned cksumNonce = 0;
|
||||
|
||||
static int pagesize = 1024;
|
||||
static int db = -1;
|
||||
static int mxPage = 0;
|
||||
|
||||
/* Report a memory allocation error */
|
||||
static void out_of_memory(void){
|
||||
fprintf(stderr,"Out of memory...\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static print_page(int iPg){
|
||||
unsigned char *aData;
|
||||
/*
|
||||
** Read N bytes of memory starting at iOfst into space obtained
|
||||
** from malloc().
|
||||
*/
|
||||
static char *read_content(int N, int iOfst){
|
||||
int got;
|
||||
char *pBuf = malloc(N);
|
||||
if( pBuf==0 ) out_of_memory();
|
||||
fseek(db, iOfst, SEEK_SET);
|
||||
got = fread(pBuf, 1, N, db);
|
||||
if( got<0 ){
|
||||
fprintf(stderr, "I/O error reading %d bytes from %d\n", N, iOfst);
|
||||
memset(pBuf, 0, N);
|
||||
}else if( got<N ){
|
||||
fprintf(stderr, "Short read: got only %d of %d bytes from %d\n",
|
||||
got, N, iOfst);
|
||||
memset(&pBuf[got], 0, N-got);
|
||||
}
|
||||
return pBuf;
|
||||
}
|
||||
|
||||
/* Print a line of decode output showing a 4-byte integer.
|
||||
*/
|
||||
static unsigned print_decode_line(
|
||||
unsigned char *aData, /* Content being decoded */
|
||||
int ofst, int nByte, /* Start and size of decode */
|
||||
const char *zMsg /* Message to append */
|
||||
){
|
||||
int i, j;
|
||||
aData = malloc(pagesize);
|
||||
if( aData==0 ) out_of_memory();
|
||||
read(db, aData, pagesize);
|
||||
fprintf(stdout, "Page %d:\n", iPg);
|
||||
for(i=0; i<pagesize; i += 16){
|
||||
fprintf(stdout, " %03x: ",i);
|
||||
for(j=0; j<16; j++){
|
||||
fprintf(stdout,"%02x ", aData[i+j]);
|
||||
unsigned val = aData[ofst];
|
||||
char zBuf[100];
|
||||
sprintf(zBuf, " %03x: %02x", ofst, aData[ofst]);
|
||||
i = strlen(zBuf);
|
||||
for(j=1; j<4; j++){
|
||||
if( j>=nByte ){
|
||||
sprintf(&zBuf[i], " ");
|
||||
}else{
|
||||
sprintf(&zBuf[i], " %02x", aData[ofst+j]);
|
||||
val = val*256 + aData[ofst+j];
|
||||
}
|
||||
for(j=0; j<16; j++){
|
||||
fprintf(stdout,"%c", isprint(aData[i+j]) ? aData[i+j] : '.');
|
||||
}
|
||||
fprintf(stdout,"\n");
|
||||
i += strlen(&zBuf[i]);
|
||||
}
|
||||
sprintf(&zBuf[i], " %10u", val);
|
||||
printf("%s %s\n", zBuf, zMsg);
|
||||
return val;
|
||||
}
|
||||
|
||||
/*
|
||||
** Read and print a journal header. Store key information (page size, etc)
|
||||
** in global variables.
|
||||
*/
|
||||
static unsigned decode_journal_header(int iOfst){
|
||||
char *pHdr = read_content(64, iOfst);
|
||||
unsigned nPage;
|
||||
printf("Header at offset %d:\n", iOfst);
|
||||
print_decode_line(pHdr, 0, 4, "Header part 1 (3654616569)");
|
||||
print_decode_line(pHdr, 4, 4, "Header part 2 (547447767)");
|
||||
nPage =
|
||||
print_decode_line(pHdr, 8, 4, "page count");
|
||||
cksumNonce =
|
||||
print_decode_line(pHdr, 12, 4, "chksum nonce");
|
||||
print_decode_line(pHdr, 16, 4, "initial database size in pages");
|
||||
sectorSize =
|
||||
print_decode_line(pHdr, 20, 4, "sector size");
|
||||
pageSize =
|
||||
print_decode_line(pHdr, 24, 4, "page size");
|
||||
print_decode_line(pHdr, 28, 4, "zero");
|
||||
print_decode_line(pHdr, 32, 4, "zero");
|
||||
print_decode_line(pHdr, 36, 4, "zero");
|
||||
print_decode_line(pHdr, 40, 4, "zero");
|
||||
free(pHdr);
|
||||
return nPage;
|
||||
}
|
||||
|
||||
static void print_page(int iOfst){
|
||||
unsigned char *aData;
|
||||
char zTitle[50];
|
||||
aData = read_content(pageSize+8, iOfst);
|
||||
sprintf(zTitle, "page number for page at offset %d", iOfst);
|
||||
print_decode_line(aData, 0, 4, zTitle);
|
||||
free(aData);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
struct stat sbuf;
|
||||
unsigned int u;
|
||||
int rc;
|
||||
unsigned char zBuf[10];
|
||||
unsigned char zBuf2[sizeof(u)];
|
||||
int nPage, cnt;
|
||||
int iOfst;
|
||||
if( argc!=2 ){
|
||||
fprintf(stderr,"Usage: %s FILENAME\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
db = open(argv[1], O_RDONLY);
|
||||
if( db<0 ){
|
||||
db = fopen(argv[1], "rb");
|
||||
if( db==0 ){
|
||||
fprintf(stderr,"%s: can't open %s\n", argv[0], argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
read(db, zBuf, 8);
|
||||
if( zBuf[7]==0xd6 ){
|
||||
read(db, &u, sizeof(u));
|
||||
printf("Records in Journal: %u\n", u);
|
||||
read(db, &u, sizeof(u));
|
||||
printf("Magic Number: 0x%08x\n", u);
|
||||
fseek(db, 0, SEEK_END);
|
||||
fileSize = ftell(db);
|
||||
printf("journal file size: %d bytes\n", fileSize);
|
||||
fseek(db, 0, SEEK_SET);
|
||||
iOfst = 0;
|
||||
while( iOfst<fileSize ){
|
||||
cnt = nPage = (int)decode_journal_header(iOfst);
|
||||
if( cnt==0 ){
|
||||
cnt = (fileSize - sectorSize)/(pageSize+8);
|
||||
}
|
||||
read(db, zBuf2, sizeof(zBuf2));
|
||||
u = zBuf2[0]<<24 | zBuf2[1]<<16 | zBuf2[2]<<8 | zBuf2[3];
|
||||
printf("Database Size: %u\n", u);
|
||||
while( read(db, zBuf2, sizeof(zBuf2))==sizeof(zBuf2) ){
|
||||
u = zBuf2[0]<<24 | zBuf2[1]<<16 | zBuf2[2]<<8 | zBuf2[3];
|
||||
print_page(u);
|
||||
if( zBuf[7]==0xd6 ){
|
||||
read(db, &u, sizeof(u));
|
||||
printf("Checksum: 0x%08x\n", u);
|
||||
iOfst += sectorSize;
|
||||
while( cnt && iOfst<fileSize ){
|
||||
print_page(iOfst);
|
||||
iOfst += pageSize+8;
|
||||
}
|
||||
iOfst = (iOfst/sectorSize + 1)*sectorSize;
|
||||
}
|
||||
close(db);
|
||||
fclose(db);
|
||||
}
|
||||
|
Reference in New Issue
Block a user