xfs
[Top] [All Lists]

Re: Get file using a specific sector number

To: olivier@xxxxxxxxx
Subject: Re: Get file using a specific sector number
From: Dave Chinner <david@xxxxxxxxxxxxx>
Date: Tue, 10 Jan 2012 08:46:30 +1100
Cc: xfs@xxxxxxxxxxx
In-reply-to: <CAPPqfY1DOesJGfpZfnukr6PGo-KsGQ3u3tnF8UdVTZgWn2=HKA@xxxxxxxxxxxxxx>
References: <CAPPqfY1DOesJGfpZfnukr6PGo-KsGQ3u3tnF8UdVTZgWn2=HKA@xxxxxxxxxxxxxx>
User-agent: Mutt/1.5.21 (2010-09-15)
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
david@xxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>