Get file using a specific sector number

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Get file using a specific sector number

Olivier Doucet-4
Hello everyone,

I'm actually using xfsprogs quite heavily and I'm stuck with one problem : 

I have a sector number and I want to know which file is using it. xfs_bmap does exactly the opposite (give sector number for a specific file), but I cannot find how to do it the other way.
I made several attempts with xfs_db but cannot find how to do it properly. Moreover, I need to do it on a mounted filesystem (RW), and xfs_db does not seem very friendly about that ...

Any help would be much appreciated.

Thank you,

Olivier


_______________________________________________
xfs mailing list
[hidden email]
http://oss.sgi.com/mailman/listinfo/xfs
Reply | Threaded
Open this post in threaded view
|

Re: Get file using a specific sector number

Dave Chinner
On Mon, Jan 09, 2012 at 07:14:23PM +0100, Olivier Doucet wrote:

> Hello everyone,
>
> I'm actually using xfsprogs quite heavily and I'm stuck with one problem :
>
> I have a sector number and I want to know which file is using it. xfs_bmap
> does exactly the opposite (give sector number for a specific file), but I
> cannot find how to do it the other way.
> I made several attempts with xfs_db but cannot find how to do it properly.
> Moreover, I need to do it on a mounted filesystem (RW), and xfs_db does not
> seem very friendly about that ...
>
> Any help would be much appreciated.

There is no easy way to do it, because XFS does not have a reverse
map btree to tell you the owner of any given block. The only way to
find this is to walk the entire metadata tree to find the owner of
the block.

You can't do that reliably just by walking the directory heirarchy
and running xfs_bmap and xfs_bmap -a on every file and directory,
because the sector you are after may be in metadata that you can't
expose via this method. e.g. it might be a block in the extent tree
that xfs_bmap walks, in the free space or inode btrees, etc.

xfs_db is really the only way you can do this right now, using the
blockget command. You can run xfs_db on a RW filesystem (run it in
read-only mode), but xfs_db is not coherent with active filesystem
changes and hence is likely to crash randomly as the filesytem
changes under it. Also, blockget takes blocks in FSB format, so you
need to convert your sector (daddr) to FSB units using the convert
command first.

FWIW, you could always freeze the filesystem while you run the xfs_db
command, but that may cause other problems for your applications...

Cheers,

Dave.
--
Dave Chinner
[hidden email]

_______________________________________________
xfs mailing list
[hidden email]
http://oss.sgi.com/mailman/listinfo/xfs