linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: How to find the inodes in XFS
       [not found]     ` <535AE19D.8@sandeen.net>
@ 2014-04-26  2:21       ` Felipe Monteiro de Carvalho
  2014-04-27 15:53         ` Felipe Monteiro de Carvalho
  0 siblings, 1 reply; 3+ messages in thread
From: Felipe Monteiro de Carvalho @ 2014-04-26  2:21 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: xfs

Hello,

Thanks a lot! Based on your tips I found the issue and now it is
working =) My failure was trying to convert sb_inopblog and other log2
values from big endian to native endian .... it utilized a 16-bit
routine swapping routine, and when assigning back the value it would
cut the higher bits ... leaving zero =o

Of course 8-bit values don't need endian conversion, so just removing
that fixed the issue =)

thanks,

Felipe Monteiro de Carvalho


On Fri, Apr 25, 2014 at 7:28 PM, Eric Sandeen <sandeen@sandeen.net> wrote:
> On 4/25/14, 4:51 PM, Felipe Monteiro de Carvalho wrote:
>> 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.
>
> Then perhaps you have mp set up wrong?  Or maybe it's an endian isue?
>
> If I stuff:
>
> printf("%lld\n", XFS_INO_TO_FSB(mp, 128));
>
> into, say, xfs_repair where we have a valid mp, I get "8"
>
> And xfs_db agrees:
>
> xfs_db> inode 128
> xfs_db> fsblock
> current fsblock is 8
> xfs_db>
>
>
>> 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
>> zero.
>
> 0, really?
>
>         __uint16_t      sb_inopblock;   /* inodes per block */
>         __uint8_t       sb_inopblog;    /* log2 of sb_inopblock */
>
> Even with maximally-sized inodes at 2k, sb_inopblog would be 1.
>
>
>> 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_TO_AGBNO = (i shr XFS_INO_OFFSET_BITS(m_sb)) and
>> XFS_INO_MASK(XFS_INO_AGBNO_BITS(m_sb));
>>
>> XFS_INO_OFFSET_BITS = sb_inopblog which is 0 in my partition
>>
>> XFS_INO_AGBNO_BITS = sb_agblklog which is 0 in my partition
>
> That doesn't sound right:
>
> xfs_db> sb 0
> xfs_db> p inopblog
> inopblog = 4
> xfs_db> p agblklog
> agblklog = 20
> xfs_db>
>
> -Eric
>
>
>> 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)) & \
>> XFS_INO_MASK(XFS_INO_AGBNO_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@sandeen.net> 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

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to find the inodes in XFS
  2014-04-26  2:21       ` How to find the inodes in XFS Felipe Monteiro de Carvalho
@ 2014-04-27 15:53         ` Felipe Monteiro de Carvalho
  2014-04-27 16:07           ` Eric Sandeen
  0 siblings, 1 reply; 3+ messages in thread
From: Felipe Monteiro de Carvalho @ 2014-04-27 15:53 UTC (permalink / raw)
  To: Eric Sandeen; +Cc: xfs

Oh, well, ...now my code works great for low inode numbers, but it
doesn't work at all for high inode numbers. =)

If inode is the root one 0x80 or similar small numbers which as 0x83
it will map correctly to the block 8, which means position 0x8000 +
internal offset inside the block

But in high inodes, for example 0x204B87 and 0x204B80 it will split
the inode number like this:
AG=2
Block inside AG Nr=0x4B8

And since XFS_INO_TO_FSB just recombines back together the parts:

#define XFS_INO_TO_FSB(mp,i) \
XFS_AGB_TO_FSB(mp, XFS_INO_TO_AGNO(mp,i), XFS_INO_TO_AGBNO(mp,i))

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

I get as the result from XFS_INO_TO_FSB 0x204B8, which would mean
position 0x204B8000, but this is a wrong position =(

I opened the partition with a hex viewer and the correct position is
block 0x1521A which means position 0x1521A000 + offset inside block

My superblock has these values:

XFS_INO_AGINO_BITS = mp^.m_agino_log = 20
XFS_INO_OFFSET_BITS= m_sb^.sb_inopblog = 4
XFS_INO_AGBNO_BITS = m_sb^.sb_agblklog = 16
XFS_INO_MASK = FFFF
sb_agcount = 4

Any ideas?

Maybe my flaw is that to get the disk position I simply multiply the
block number by the size of a block ... I tryed to use
XFS_FSB_TO_DADDR instead but it gives 64 for block nr 8, which doesn't
make much sense, I'd expect 0x8000

thanks!
-- 
Felipe Monteiro de Carvalho

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to find the inodes in XFS
  2014-04-27 15:53         ` Felipe Monteiro de Carvalho
@ 2014-04-27 16:07           ` Eric Sandeen
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Sandeen @ 2014-04-27 16:07 UTC (permalink / raw)
  To: Felipe Monteiro de Carvalho; +Cc: xfs

On 4/27/14, 10:53 AM, Felipe Monteiro de Carvalho wrote:
> Maybe my flaw is that to get the disk position I simply multiply the
> block number by the size of a block ... I tryed to use
> XFS_FSB_TO_DADDR instead but it gives 64 for block nr 8, which doesn't
> make much sense, I'd expect 0x8000

if you have 4k blocks, filesystem block #8 is at 32k, or 64 512-byte
"daddrs" so that is correct.  A "DADDR" is in 512-byte units.

-Eric

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-04-27 16:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CACyNnZMtP87y6VHum+J4xKEZqaYp2YERVnt3YuaCmeiZBmMTzQ@mail.gmail.com>
     [not found] ` <5359912A.70603@sandeen.net>
     [not found]   ` <CACyNnZPV89C87DggE4fiJX+_r3zh1hKhcX3ExmXRzpLLhWJ6CQ@mail.gmail.com>
     [not found]     ` <535AE19D.8@sandeen.net>
2014-04-26  2:21       ` How to find the inodes in XFS Felipe Monteiro de Carvalho
2014-04-27 15:53         ` Felipe Monteiro de Carvalho
2014-04-27 16:07           ` Eric Sandeen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).