filefrag shows how many physical extents (contiguous runs) a file uses. It works on any filesystem. It uses the FIEMAP ioctl, falling back to FIBMAP if the filesystem does not support it.
filefrag file.iso
file.iso: 3 extents found
filefrag -v file.iso # list every extent: logical and physical offsets and lengths
sudo filefrag -v /var/lib/mysql/ibdata1
Fragmentation matters much less than it used to. On SSD/NVMe it is largely irrelevant, and ext4/XFS allocate well. It is worth checking for big, slowly growing files (databases, logs, VM images) on spinning disks. e4defrag defragments ext4 files: sudo e4defrag file.img, or sudo e4defrag -c file.img for a fragmentation score.