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

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


BenHanokh Gabriel writes:
> Malcolm Beattie wrote:
>
> > 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.
[...]
> > if (ioctl(fd, FIBMAP, &block) == 0) {
> > /* block now holds "physical" block number */
> > }
> >
>
> sound good, is this ioctl simply calling bmap for me ?
> where can i find documantion about this ioctl( e.g. sparse-files

The source, of course. fs/ioctl.c says:

static int file_ioctl(struct file *filp,unsigned int cmd,unsigned long arg)
{
...
                        /* do we support this mess? */
                        if (!mapping->a_ops->bmap)
                                return -EINVAL;
                        if (!capable(CAP_SYS_RAWIO))
                                return -EPERM;
                        if ((error = get_user(block, (int *) arg)) != 0)
                                return error;

                        res = mapping->a_ops->bmap(mapping, block);
                        return put_user(res, (int *) arg);

which tells you all you need to know (including somebody's
opinion--and I think I know whose--about FIBMAP :-)

> > You need CAP_SYS_RAWIO to do this. Note the
>
> sorry, i don't understand what you mean with CAP_SYS_RAWIO

The capability. "Root", if no explicit action has been taken to
reduce root's privileges by default.

> > #include <linux/fs.h>
> > which shouts "I'm not portable" to the entire world.
>
> i'm aware to this, but something like this can never be done in a portable way.

If you explained *why* you thought you wanted the number that bmap
gives you, maybe others would be able to think of a better way of
achieving your goal.

> > or it may be a real disk but the block has been transparently remapped
> > elsewhere by the firmware or probably various other gotchas.
> >
>
> do you mean that a special-purpose hardware is being used as a proxy to the disk, or
> that this is a feature available in a "normal" hard drives?

All SCSI and other high-end disks do this and I think some fancy
ATA ones do too (or soon will or something).

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