hdparm, including latest version 9.43 when using --fibmap and falling back to FIBMAP ioctl does the wrong thing and returns wildly inaccurate LBAs for some file systems.
In the source code in fibmap.c::do_filemap(), ioctl(FIGETBSZ) is used to get the blocksize for the file system and then sectors_per_block is worked out from that. This is correct.
The problem happens when walk_fibmap() is called. Instead of using the obtained blocksize from ioctl(FIGETBSZ), the st->st_blksize returned from stat() is used. But st_blksize is both according to stat(2) man page and to POSIX standard: "A file system-specific preferred I/O block size for this object. In some file system types, this may vary from file to file.".
The code should use the FIGETBSZ blocksize instead of st_blksize to work out how many times to call FIBMAP ioctl (i.e. the num_blocks calculation). Same for the ext.byte_offset calculation.
(In older versions the code was even worse using st_blksize everywhere but that seems to have improved in the 9.43 version but not sufficiently.)
Can this please be fixed?
PS. Let me know if you want a patch fixing it...
Log in to post a comment.