From 4e6861d23da2e05fdeff2fc913e87c1b7b1976c8 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 20 Jul 2020 14:54:36 +0000 Subject: [PATCH] Add the "enlargedb" utility program used to construct very large database files for testing. FossilOrigin-Name: 66858d87507bfdd17bb76c0afb1108ad5dec752438a79bf57f0f51690232e943 --- manifest | 14 +++++----- manifest.uuid | 2 +- tool/enlargedb.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 tool/enlargedb.c diff --git a/manifest b/manifest index fb324fa973..3a2e4bcd08 100644 --- a/manifest +++ b/manifest @@ -1,6 +1,6 @@ B 7a876209a678a34c198b54ceef9e3c041f128a14dc73357f6a57cadadaa6cf7b -C Initial\schanges\sto\sallow\sdatabase\sup\sto\s281TB\sin\ssize. -D 2020-07-20T12:47:32.233 +C Add\sthe\s"enlargedb"\sutility\sprogram\sused\sto\sconstruct\svery\slarge\sdatabase\nfiles\sfor\stesting. +D 2020-07-20T14:54:36.782 F Makefile.in 19374a5db06c3199ec1bab71ab74a103d8abf21053c05e9389255dc58083f806 F Makefile.msc 48f5a3fc32672c09ad73795749f6253e406a31526935fbbffd8f021108d54574 F autoconf/Makefile.am a8d1d24affe52ebf8d7ddcf91aa973fa0316618ab95bb68c87cabf8faf527dc8 @@ -66,6 +66,7 @@ F test/upfrom3.test 7dab379d128e8dd7beb2055b295fb113c7ba93e8c2038f5ddb7a4a10f0eb F test/upfromfault.test 70ecf8eb85559727a487283f69374e3ae39879e994d8a2437c49d7c05ecb70c9 F test/wherelimit2.test 657a3f24aadee62d058c5091ea682dc4af4b95ffe32f137155be49799a58e721 F test/window1.test e52b81fff0c3cb122a1240f336688eb81bea2967a99c4ddb78969adec7aadc2a +F tool/enlargedb.c 3e8b2612b985cfa7e3e8800031ee191b43ae80de96abb5abbd5eada62651ee21 F tool/lemon.c 600a58b9d1b8ec5419373982428e927ca208826edacb91ca42ab94514d006039 F tool/mkautoconfamal.sh f62353eb6c06ab264da027fd4507d09914433dbdcab9cb011cdc18016f1ab3b8 F tool/mkpragmatab.tcl ae5585ae76ca26e4d6ccd5ea9cdebaf5efefb318bf989497a0e846cd711d9ab1 @@ -73,10 +74,7 @@ F tool/mksqlite3c.tcl f4ef476510eca4124c874a72029f1e01bc54a896b1724e8f9eef0d8bfa F tool/mksqlite3h.tcl 1f5e4a1dbbbc43c83cc6e74fe32c6c620502240b66c7c0f33a51378e78fc4edf F tool/showlocks.c 9cc5e66d4ebbf2d194f39db2527ece92077e86ae627ddd233ee48e16e8142564 F tool/speed-check.sh 615cbdf50f1409ef3bbf9f682e396df80f49d97ed93ed3e61c8e91fae6afde58 -P 020dbfa2aef20e5872cc3e785d99f45903843401292114b5092b9c8aa829b9c3 -R ab2ebf91e53f6501695c6ee9adc86286 -T *branch * larger-databases -T *sym-larger-databases * -T -sym-trunk * +P 9cb7da9bdb666ea40771513b89591dca275f1e92092b39190df747e3797178a3 +R 9067d26895bc3a2e17574c32eefe8d76 U drh -Z 75b6d7d462ec8aff5320b5004ad4c7b9 +Z a6e9581b3af88e284f742d70fddd747a diff --git a/manifest.uuid b/manifest.uuid index 47fb46cd08..e30ffe29d8 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -9cb7da9bdb666ea40771513b89591dca275f1e92092b39190df747e3797178a3 \ No newline at end of file +66858d87507bfdd17bb76c0afb1108ad5dec752438a79bf57f0f51690232e943 \ No newline at end of file diff --git a/tool/enlargedb.c b/tool/enlargedb.c new file mode 100644 index 0000000000..dab5ef1f1c --- /dev/null +++ b/tool/enlargedb.c @@ -0,0 +1,68 @@ +/* +** Try to enlarge an SQLite database by appending many unused pages. +** The resulting database will fail PRAGMA integrity_check due to the +** appended unused pages, but it should work otherwise. +** +** Usage: +** +** enlargedb DATABASE N +** +** Adds N blank pages onto the end of DATABASE. N can be decimal +** or hex. The total number of pages after adding must be no greater +** than 4294967297 +*/ +#include +#include +#include + +int main(int argc, char **argv){ + char *zEnd; + long long int toAppend; + long long int currentSz; + long long int newSz; + FILE *f; + size_t got; + int pgsz; + char zero = 0; + unsigned char buf[100]; + + if( argc!=3 ) goto usage_error; + toAppend = strtoll(argv[2], &zEnd, 0); + if( zEnd==argv[2] || zEnd[0] ) goto usage_error; + if( toAppend<1 ){ + fprintf(stderr, "N must be at least 1\n"); + exit(1); + } + f = fopen(argv[1], "r+b"); + if( f==0 ){ + fprintf(stderr, "cannot open \"%s\" for reading and writing\n", argv[1]); + exit(1); + } + got = fread(buf, 1, sizeof(buf), f); + if( got!=sizeof(buf) ) goto not_valid_db; + if( strcmp((char*)buf,"SQLite format 3")!=0 ) goto not_valid_db; + pgsz = (buf[16]<<8) + buf[17]; + if( pgsz==1 ) pgsz = 65536; + if( pgsz<512 || pgsz>65536 || (pgsz&(pgsz-1))!=0 ) goto not_valid_db; + currentSz = (buf[28]<<24) + (buf[29]<<16) + (buf[30]<<8) + buf[31]; + newSz = currentSz + toAppend; + if( newSz > 0xffffffff ) newSz = 0xffffffff; + buf[28] = (newSz>>24) & 0xff; + buf[29] = (newSz>>16) & 0xff; + buf[30] = (newSz>>8) & 0xff; + buf[31] = newSz & 0xff; + fseek(f, 28, SEEK_SET); + fwrite(&buf[28],4,1,f); + fseek(f, (long)(newSz*pgsz - 1), SEEK_SET); + fwrite(&zero,1,1,f); + fclose(f); + return 0; + +not_valid_db: + fprintf(stderr,"not a valid database: %s\n", argv[1]); + exit(1); + +usage_error: + fprintf(stderr,"Usage: %s DATABASE N\n", argv[0]); + exit(1); +}