Is there a way I can see which sectors of the hard disk a given file occupies?

The filesystem is ext3 or ext4 on Linux.

link|improve this question

71% accept rate
Of course there is a way but it is not exactly what one would call "easy". What are you trying to accomplish? – msw Jun 22 '10 at 5:08
I'm performing an operation that requires reading a large amount of input data, and I want to pinpoint the cause of some anomalies in the performance of the reading. I want to know whether there is a correlation between the read performance and the physical layout of the input files on disk. This requires knowing what the physical layout of the input files is on the disk. – HighCommander4 Jun 22 '10 at 7:22
feedback

1 Answer

up vote 2 down vote accepted

If you are looking for blocks for file /tmp/squiggle/smurf.tgz, in the /tmp/ filesystem, mounted from /dev/sdg4, you would type:

# debugfs /dev/sdg4
> bmap /squiggle/smurf.tgz 0
> bmap /squiggle/smurf.tgz 1
> bmap /squiggle/smurf.tgz 2
> bmap /squiggle/smurf.tgz 3
....

Is that what you're looking for?

link|improve this answer
Yes, this seems to be what I'm looking for. I have a couple of follow-up questions: 1) Is there a way to do this without root privileges? 2) Can this be scripted, or can these numbers be queried programmatically? – HighCommander4 Jun 22 '10 at 7:23
It should be scriptable. I'd say piping your commands in on stdin would probably do the trick. Be very careful with that though, as you can do a LOT of damage to a filesystem with debugfs. As for doing this without root priv's, I don't know, but I suspect not. The filesystem is intended to be an abstraction that hides those details from the user. – Slartibartfast Jun 23 '10 at 2:44
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.