0
votes

I have been searching for a utility/tool that can provide the md5sum(or any unique checksum) of a data block inside ext3 inode structure.

The requirement is to verify whether certain data blocks get zeroed, after a particular operation.

I am new to file systems and do not know if any existing tool can do the job, or I need to write this test utility myself.

Thanks...

1

1 Answers

0
votes

A colleague provided a very elegant solution. Here is the script. It needs the name of file as a parameter, and assumes the file system blocksize to be 4K

  • A further extension of this idea:

If you know the data blocks associated with the file (stat ), you can use 'skip' option of 'dd' command and build small files, each of 1 block size length. Further, you can get the md5sum of these blocks. So, this way you can get md5sum directly from the block device. Not something you would want to do everyday, but a nice analytical trick.

==================================================================================

#!/bin/bash

absname=$1
testdir="/root/test/"
mdfile="md5"
statfile="stat"
blksize=4096
fname=$(basename $absname)
fsize=$( ls -al $absname | cut -d " " -f 5 )
numblk=$(( fsize/blksize ))
x=1
#Create the test directory, if it does not exist already
if [[ ! -d $testdir ]]; 
then
        `mkdir -p $testdir`
fi
#Create multiple files from the test file, each 1 block sized
while [[ $x -le $numblk ]]
do
        (( s=x-1 ))
        `dd if=$absname of=$testdir$fname$x bs=4096 count=1 skip=$s`
        `md5sum $testdir$fname$x >> $testdir$mdfile`
        (( x=x+1 ))
done