Re: how can i get hold of a file inode ?

From: Malcolm Beattie (mbeattie@sable.ox.ac.uk)
Date: Tue Jul 25 2000 - 08:35:54 EST


BenHanokh Gabriel writes:
> i need to find what physical blocks a file occuiped on disk.
> so i have to find the file's inode and pass it as an argument to the vfs method
> - bmap.

No you don't, you can persuade the kernel to do it for you.

    #include <linux/fs.h>
    ...
    int block;
    ...
    fd = open(.....);

    block = get_logical_blocknum();
    if (ioctl(fd, FIBMAP, &block) == 0) {
        /* block now holds "physical" block number */
    }

You need CAP_SYS_RAWIO to do this. Note the
    #include <linux/fs.h>
which shouts "I'm not portable" to the entire world. Note also that
knowing the "physical" block number is often not what you want (even
if you think you do) and that I've been putting scare quotes around
"physical" because the device might actually be a logical device (e.g.
LVM or RAID md) where the physical block number isn't really physical
or it may be a real disk but the block has been transparently remapped
elsewhere by the firmware or probably various other gotchas.

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



This archive was generated by hypermail 2b29 : Mon Jul 31 2000 - 21:00:19 EST