【问题标题】:Utility/Tool to get hash value of a data block in ext3在 ext3 中获取数据块哈希值的实用程序/工具
【发布时间】:2014-04-30 15:22:17
【问题描述】:

我一直在寻找可以在 ext3 inode 结构中提供数据块的 md5sum(或任何唯一校验和)的实用程序/工具。

要求是在特定操作之后验证某些数据块是否归零。

我是文件系统的新手,不知道是否有任何现有工具可以完成这项工作,或者我需要自己编写这个测试实用程序。

谢谢...

【问题讨论】:

    标签: hash md5sum ext3


    【解决方案1】:

    一位同事提供了一个非常优雅的解决方案。这是脚本。 它需要文件名作为参数,并假设文件系统块大小为4K

    • 这个想法的进一步延伸:

    如果您知道与文件关联的数据块 (stat),您可以使用 'dd' 命令的 'skip' 选项并构建小文件,每个 1 个块大小长度。此外,您可以获得这些块的 md5sum。因此,通过这种方式,您可以直接从块设备中获取 md5sum。这不是您每天都想做的事情,而是一个不错的分析技巧。

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

    #!/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
    

    【讨论】:

      猜你喜欢
      • 2012-08-17
      • 2021-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多