#58 hdparm --fibmap uses incorrect block size

v1.0 (example)


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...

Best regards,



  • Anton Altaparmakov

    Patch to fix --fibmap so it reports correct LBA runs when it has to fall back to FIBMAP ioctl. Now all information displayed is correct.

  • Mark Lord

    Mark Lord - 2014-09-27

    Fixed in hdparm-9.45 (pending release).
    Thanks for the patch, but next time please just email it to me.

  • Mark Lord

    Mark Lord - 2014-09-27
    • status: open --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks