[Top] [All Lists]

Re: How to find the inodes in XFS

To: Eric Sandeen <sandeen@xxxxxxxxxxx>
Subject: Re: How to find the inodes in XFS
From: Felipe Monteiro de Carvalho <felipemonteiro.carvalho@xxxxxxxxx>
Date: Fri, 25 Apr 2014 18:51:38 -0300
Cc: xfs@xxxxxxxxxxx
Delivered-to: xfs@xxxxxxxxxxx
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=9dTbIDVvP3FFdQMSIV8aqdc7IC6QBVJ9sbt8oM6jztY=; b=VNUG07Oey4dFgucCbYRRO8H/fkrkfiHDPafi8knSRkSleMALZzaNq7cruoNTBOUz+P 41q3+XIbGgzGplCgfaSMZYUybRB6LwX09fsKglgllYlPyI5jjU2ROS6xCgs/bhuXtJiT PqMD3ybwqdwi+cIrrsY+dToeCPVUbV5ZAUFku8LLNyk176j+tgt5/5wZalYTDRRPTbPg Pe5b082NwX4b3bCrjt8aq6wRRgwkJc9BWXPYRA1vAWxeE9wCS3bTNeX3cR8kLSr2Ljrg d2sKFqbJD59hl1+4zsOQ1N7UtjydRz8+UjUKq1IFeUMGP5WTP5N9vWnOyS7Tk3jjagZ5 j2yA==
In-reply-to: <5359912A.70603@xxxxxxxxxxx>
References: <CACyNnZMtP87y6VHum+J4xKEZqaYp2YERVnt3YuaCmeiZBmMTzQ@xxxxxxxxxxxxxx> <5359912A.70603@xxxxxxxxxxx>
Thanks a lot! That's really helpful =)

Unfortunately something is going wrong here, and the implementation of
XFS_INO_TO_FSB is quite intrincated, enough that it is hard to be sure
what is wrong here ... I am trying to resolve the location of the root
inode, which has number 128, but my XFS_INO_TO_FSB call is resolving
to $80000 which is not an inode.

XFS_INO_AGINO_BITS returns m_agino_log which is defined as sb_inopblog
+ sb_agblklog. Both are zero here, so this whole part resolves to

About sb_agcount I read and reread the code and it is really hard to
figure what number it should have in this part of the code, but in my
superblock it comes with value 4, so I am using this.

XFS_INO_TO_AGNO = (i) shr XFS_INO_AGINO_BITS, with i (inode nr) =128
shr 0 = so this part resolves to 128


XFS_INO_OFFSET_BITS = sb_inopblog which is 0 in my partition

XFS_INO_AGBNO_BITS = sb_agblklog which is 0 in my partition

XFS_INO_MASK = (1 shl k) - 1; with k=0 it resolves to 0

#define XFS_INO_TO_AGBNO(mp,i) \
(((xfs_agblock_t)(i) >> XFS_INO_OFFSET_BITS(mp)) & \

With i=128 >> 0 we get 0, but then we have & 0, so this whole part
resolves to zero

So now we are left with         XFS_AGB_TO_FSB(mp, 128, 0)

#define XFS_AGB_TO_FSB(mp,agno,agbno) \
(((xfs_fsblock_t)(agno) << (mp)->m_sb.sb_agblklog) | (agbno))

Which resolves to 128 because 128 << 0 | 0 = 128

So I calculate 128 * block_size, I have a blocksize of $1000 in my
supernode, so that's how I arrived at $80000

But looking inside my partition I'm pretty sure that $80000 is not an inode....

Any ideas where I got things wrong?? =( I've been trying for hours to
figure where I got things wrong but no ideas yet =/

I can post my superblock content here if it would be helpful.

thanks again =)

Felipe Monteiro de Carvalho

On Thu, Apr 24, 2014 at 7:33 PM, Eric Sandeen <sandeen@xxxxxxxxxxx> wrote:
> On 4/24/14, 5:09 PM, Felipe Monteiro de Carvalho wrote:
>> Hello,
>> I am writing an application which reads XFS partitions, so I am trying
>> to understand the internal working of XFS. I read the documentation
>> here: 
>> http://www.dubeyko.com/development/FileSystems/XFS/xfs_filesystem_structure.pdf
>> But I am stuck at a particular point. To get to the inodes I see that
>> I should first read xfs_agi_t, no problem here, then its root field
>> points to a block which contains xfs_inobt_block_t + a sequence of
>> xfs_inobt_rec_t records and those records are supposed to show me
>> where the inodes are, but there is no field in xfs_inobt_rec_t such as
>> a block number =( Any idea how to get then the physical position in
>> the disk where the inodes are from xfs_inobt_block_t + a sequence of
>> xfs_inobt_rec_t?
> The inode's location is encoded in its inode number.
> See for example:
> /*
>  * Inode number format:
>  * low inopblog bits - offset in block
>  * next agblklog bits - block number in ag
>  * next agno_log bits - ag number
>  * high agno_log-agblklog-inopblog bits - 0
>  */
> #define XFS_INO_TO_FSB(mp,i)            \
>         XFS_AGB_TO_FSB(mp, XFS_INO_TO_AGNO(mp,i), XFS_INO_TO_AGBNO(mp,i))
> -Eric
>> thanks,

Felipe Monteiro de Carvalho

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