commit d8c21c3650f2570a395cbda87872649966066557 Author: Michael Krayer Date: Tue Feb 16 15:48:19 2021 +0100 initial commit diff --git a/README.md b/README.md new file mode 100644 index 0000000..4b93a89 --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +nullblocks +--- +Scan a file for contiguous blocks of 'null' bytes. + +Usage: +```bash +nullblocks +``` +The default minimum block size to be reported is 8192 bytes. Maybe this will +be adjustable as a command line argument in the future... diff --git a/build b/build new file mode 100755 index 0000000..98f002c --- /dev/null +++ b/build @@ -0,0 +1,2 @@ +#!/bin/bash +g++ -o nullblocks src/nullblocks.cc diff --git a/src/nullblocks.cc b/src/nullblocks.cc new file mode 100644 index 0000000..aa4a849 --- /dev/null +++ b/src/nullblocks.cc @@ -0,0 +1,66 @@ +#include +#include +#include +#include +using namespace std; + +const long IO_BUFFSIZE=(long)1024*1024; // read 1 KiB at a time +const long MIN_NULL_BLOCK_SIZE=(long)8*1024; // minimum number of consecutive NULL bytes + +int main(int argc,char *argv[]){ + int ifile, iblock; + char* buffer = new char[IO_BUFFSIZE]; + long filesize, iosize, nullblock_len, nullblock_beg; + + cout << "Checking files for NULL blocks (threshold: " + << MIN_NULL_BLOCK_SIZE << " bytes)" << endl; + string filename; + + for(ifile=1;ifile=MIN_NULL_BLOCK_SIZE){ + cout << "NULL block: position = " << setw(16) << nullblock_beg + << ", size = " << setw(16) << nullblock_len << endl; + } + nullblock_len = 0; + nullblock_beg = 0; + } + } + iblock++; + } + file.close(); + } + delete[] buffer; + + return 0; +}