1

I wanted to know if there is a command to view the details/contents of the file at the sector/block level? Meaning ,I want the following details: I have 2 files.I needed to know whether the contents stored at the block/sector level are same for the two files?Is there a command or tool to check it?If so,can you please direct me in the right way? I know both the files I am comparing are running linux operating systems

Extra Info: Here is my situation.I have two image files.I want to see if the contents of the two image files at block/sector level are the same (first few mb's where the kernel code would reside).Assuming both the image files contain linux os,I know that first few MB of both should be the same.So, I did the following:

  1. ls -i web-test.img -- got the inode as 13

  2. debugfs /dev/sdb1

  3. stat <13> -- (ETB0): 33409

  4. dd if=/dev/sdb1 of=success.txt ibs=4096 count=1 skip =33409.the contents of o/p are not in clear txt.I needed to see if its contents are the same.

In simple words,Read the first few mb of data from the images files(kernel portion) in both files at block/sector level

Looking forward to your reply.

SRK
  • 49
  • 8
  • Possible duplicate of [Read a single sector from a disk](https://stackoverflow.com/q/1753067/608639) – jww Dec 09 '18 at 09:58

1 Answers1

1

Edit: You are getting the inode of the image file from the filesystem it resides on. Then, you use that inode number inside debugfs? So whatever file happens to reside at inode 13 in the image is what you are using. That seems odd to me.

However, maybe you are just confused about the contents not being human readable. I assume you are using some sort of text editor which will show the ASCII representation of the file. Instead of visually inspecting the data you could make a checksum of the data with md5sum or use a binary diff tool like cmp.

If you had two hard links to the same inode, you could use a series of ioctl FIBMAP requests. This will return the logical block address given a block number. For example:

int block_count;
struct stat statBuf;
int block;

fstat(fd, &statBuf);

block_count = (statBuf.st_size + statBuf.st_blksize - 1) / statBuf.st_blksize;

int i;
for(i = 0; i < block_count; i++) {
    block = i;
    ioctl(fd, FIBMAP, &block) < 0)
    printf("%3d %10d\n", i, block);
}

So if I create an 8K file on a filesystem with a 4K block size it will contain 2 blocks. I then create a second hard link to the same file and use the FIBMAP request on both hard links to the same inode. You will find that the logical block addresses will match:

hardlink1:
  0   51404606
  1   51404607

hardlink2:
  0   51404606
  1   51404607
pughar
  • 148
  • 1
  • 6
  • I believe your comment was truncated. You might want to update the question itself with the extra info. – pughar Apr 08 '14 at 00:30