Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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

1 Answer 1

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?

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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