From: drh <> Date: Thu, 8 Jan 2026 01:37:13 +0000 (+0000) Subject: Improve showdb so that it does a better job of handling reserve-bytes. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e46b51e23479ee43e2e3ab454787dba543c8f91e;p=thirdparty%2Fsqlite.git Improve showdb so that it does a better job of handling reserve-bytes. Add the --tmstmp option that causes pgidx to interpret tmstmpvfs tags if they are available. FossilOrigin-Name: d7e6e9a5781f467a5b5f02f46134099cf01607a0cf55510155533d57d4a4618a --- diff --git a/manifest b/manifest index 9426f06170..543e9c293d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\stmstmpvfs.c\sextension\sto\strunk.\s\sIt\sis\snot\sa\spart\sof\sany\sdeliverable\nand\scan\seasily\sbe\sremoved\slater,\sif\sfound\sto\snot\sbe\sdesirable. -D 2026-01-08T00:41:12.638 +C Improve\sshowdb\sso\sthat\sit\sdoes\sa\sbetter\sjob\sof\shandling\sreserve-bytes.\nAdd\sthe\s--tmstmp\soption\sthat\scauses\spgidx\sto\sinterpret\stmstmpvfs\stags\nif\sthey\sare\savailable. +D 2026-01-08T01:37:13.895 F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea @@ -2159,7 +2159,7 @@ F tool/pagesig.c f98909b4168d9cac11a2de7f031adea0e2f3131faa7515a72807c03ec58eafe F tool/replace.tcl 511c61acfe563dfb58675efb4628bb158a13d48ff8322123ac447e9d25a82d9a F tool/restore_jrnl.tcl 1079ecba47cc82fa82115b81c1f68097ab1f956f357ee8da5fc4b2589af6bd98 F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 -F tool/showdb.c 3071a801f2a630bf9f615f9cbc018d20c7b6dcbc01baf639274de3c693f243cc +F tool/showdb.c 9c2c783a64b4d3b1f5fa9fe8e64add8c620c21b1831e10a2cec51ab59768da71 F tool/showjournal.c 5bad7ae8784a43d2b270d953060423b8bd480818 F tool/showlocks.c 9cc5e66d4ebbf2d194f39db2527ece92077e86ae627ddd233ee48e16e8142564 F tool/showshm.c a0ab6ec32dd1f11218ca2a4018f8fb875b59414801ab8ceed8b2e69b7b45a809 @@ -2190,9 +2190,8 @@ F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/winmain.c 00c8fb88e365c9017db14c73d3c78af62194d9644feaf60e220ab0f411f3604c -P b6ad93f62eb883ee8f4c43dd90c69b31398be6b13186866a7b05d85fe588d967 4e1a1b6aeffaa5b8c11e165803c6d33becabd1f646f39e4309dfba6892fd4bd6 -R c62a88b6743ccf33134c23eac604ca1b -T +closed 4e1a1b6aeffaa5b8c11e165803c6d33becabd1f646f39e4309dfba6892fd4bd6 +P 869f306592a86d2a78f00266c615f033cd2318a7bff0a97b3dcdd3348d99fc66 +R 84dfc7b9c377c2c122ebbcbfef876fb5 U drh -Z 16554405872f41bd820dd07a6083967e +Z da6fd7cd7ce3a4452ba602eb99ca3b3b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index c1a69e9924..ae055627fe 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -869f306592a86d2a78f00266c615f033cd2318a7bff0a97b3dcdd3348d99fc66 +d7e6e9a5781f467a5b5f02f46134099cf01607a0cf55510155533d57d4a4618a diff --git a/tool/showdb.c b/tool/showdb.c index 399d785342..045956e186 100644 --- a/tool/showdb.c +++ b/tool/showdb.c @@ -28,14 +28,21 @@ typedef sqlite3_uint64 u64; /* unsigned 64-bit */ static struct GlobalData { i64 pagesize; /* Size of a database page */ + i64 usablesize; /* pagesize-nRes */ int dbfd; /* File descriptor for reading the DB */ u32 mxPage; /* Last page number */ + u32 nRes; /* Amount of reserve space */ int perLine; /* HEX elements to print per line */ int bRaw; /* True to access db file via OS APIs */ int bCSV; /* CSV output for "pgidx" */ + int bTmstmp; /* Interpret tmstmpvfs tags on "pgidx" */ sqlite3_file *pFd; /* File descriptor for non-raw mode */ sqlite3 *pDb; /* Database handle that owns pFd */ -} g = {1024, -1, 0, 16, 0, 0, 0}; + char **zPageUse; /* Use for each page */ + struct TmstmpTag { + unsigned char a[16]; /* tmstmpvfs tag for each page */ + } *aPageTag; +} g = {4096, 4096, -1, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0}; /* ** Convert the var-int format into i64. Return the number of bytes @@ -143,11 +150,12 @@ static void fileClose(){ static unsigned char *fileRead(sqlite3_int64 ofst, int nByte){ unsigned char *aData; int got; + int rc; aData = sqlite3_malloc64(32+(i64)nByte); if( aData==0 ) out_of_memory(); memset(aData, 0, nByte+32); if( g.bRaw==0 ){ - int rc = g.pFd->pMethods->xRead(g.pFd, (void*)aData, nByte, ofst); + rc = g.pFd->pMethods->xRead(g.pFd, (void*)aData, nByte, ofst); if( rc!=SQLITE_OK && rc!=SQLITE_IOERR_SHORT_READ ){ fprintf(stderr, "error in xRead() - %d\n", rc); exit(1); @@ -155,7 +163,21 @@ static unsigned char *fileRead(sqlite3_int64 ofst, int nByte){ }else{ lseek(g.dbfd, (long)ofst, SEEK_SET); got = read(g.dbfd, aData, nByte); - if( got>0 && got0 && got=0 && pgno<=g.mxPage ){ + memcpy(g.aPageTag[pgno].a, &aData[nByte-16], 16); + } } return aData; } @@ -383,14 +405,14 @@ static i64 localPayload(i64 nPayload, char cType){ i64 nLocal; if( cType==13 ){ /* Table leaf */ - maxLocal = g.pagesize-35; - minLocal = (g.pagesize-12)*32/255-23; + maxLocal = g.usablesize-35; + minLocal = (g.usablesize-12)*32/255-23; }else{ - maxLocal = (g.pagesize-12)*64/255-23; - minLocal = (g.pagesize-12)*32/255-23; + maxLocal = (g.usablesize-12)*64/255-23; + minLocal = (g.usablesize-12)*32/255-23; } if( nPayload>maxLocal ){ - surplus = minLocal + (nPayload-minLocal)%(g.pagesize-4); + surplus = minLocal + (nPayload-minLocal)%(g.usablesize-4); if( surplus<=maxLocal ){ nLocal = surplus; }else{ @@ -752,7 +774,7 @@ static void decode_trunk_page( print_decode_line(a, 4, 4, "Number of entries on this page"); if( detail ){ n = decodeInt32(&a[4]); - for(i=0; i= g.pagesize ){ + if( cellidx+1 >= g.usablesize ){ printf("ERROR: page %d too many cells (%d)\n", pgno, nCell); break; } ofst = a[cellidx]*256 + a[cellidx+1]; - if( ofst=g.pagesize ){ + if( ofst=g.usablesize ){ printf("ERROR: page %d cell %d out of bounds\n", pgno, i); continue; } @@ -960,9 +977,9 @@ static void page_usage_freelist(u32 pgno){ a = fileRead((pgno-1)*g.pagesize, g.pagesize); iNext = decodeInt32(a); n = decodeInt32(a+4); - if( n>(g.pagesize - 8)/4 ){ + if( n>(g.usablesize - 8)/4 ){ printf("ERROR: page %d too many freelist entries (%d)\n", pgno, n); - n = (g.pagesize - 8)/4; + n = (g.usablesize - 8)/4; } for(i=0; i