Messages in this thread | | | Subject | Re: Physical Sectors for a File | Date | Wed, 28 Apr 1999 15:14:12 +0100 (BST) | From | Malcolm Beattie <> |
| |
Brian Gerst writes: > Yash Shitoot wrote: > > > > For a driver I am writing, I need to find the physical sectors > > for a given file. I know the inode number for that file. Any help/ > > pointers would be appreciated. > > Try looking at the source to lilo, that also needs to make a block map > of where the kernel image sits on the disk.
I haven't looked at how lilo does it from userland but if he's writing a kernel driver I'd have thought the easiest way would be int bmap(struct inode *inode, int block); which takes an inode and the relative block number within the file and returns the absolute block number of the block on the underlying block device. It only works for "ordinary" filesystems that support the VFS bmap method but that certainly covers things like ext2.
If you can assume that the block number of the block device is the "physical" block you're after then you are home free. Otherwise (if you're worried about bad block remapping, md, nbd or any other weird block device) then you've got more to do.
--Malcolm
-- Malcolm Beattie <mbeattie@sable.ox.ac.uk> Unix Systems Programmer Oxford University Computing Services
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |