Class: XFS::BmapBTreeRootNode
- Inherits:
-
Object
- Object
- XFS::BmapBTreeRootNode
- Defined in:
- lib/fs/xfs/bmap_btree_root_node.rb
Overview
Handle the BTree Root Node in the Disk Inode
Instance Attribute Summary collapse
-
#blocks ⇒ Object
Returns the value of attribute blocks.
-
#entry_count ⇒ Object
Returns the value of attribute entry_count.
-
#level ⇒ Object
Returns the value of attribute level.
Instance Method Summary collapse
-
#initialize(data, inode) ⇒ BmapBTreeRootNode
constructor
A new instance of BmapBTreeRootNode.
Constructor Details
#initialize(data, inode) ⇒ BmapBTreeRootNode
Returns a new instance of BmapBTreeRootNode.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fs/xfs/bmap_btree_root_node.rb', line 37 def initialize(data, inode) raise "XFS::BmapBTreeRootNode: Nil buffer" if data.nil? @inode = inode @header = BMAP_BTREE_ROOT_NODE_HEADER.decode(data[0..inode.length]) @level = @header['level'] @entry_count = @header['entry_count'] raise "XFS::BmapBTreeRootNode: Invalid Root Node Level" if @level.nil? || @level == 0 header_size = SIZEOF_BMAP_BTREE_ROOT_NODE_HEADER return if @entry_count == 0 # # The Root Node contains an array of starting offsets followed by # an array of block numbers. While only the required number of entries # are initialized, there is space left for the maximum number of entries # that may fit in the disk inode data fork (eliminating any space taken # up by extended attributes). # We only care about the block numbers. The offsets of individual data blocks are # also kept in the BmapBTreeRecord # fork_size = @inode.dfork_size(Inode::XFS_DATA_FORK) maximum_records = (fork_size - header_size) / SIZEOF_BMAP_BTREE_ROOT_NODE_ENTRIES return if maximum_records == 0 @blocks = [] offset_size = SIZEOF_BMAP_BTREE_ROOT_NODE_OFFSET block_size = SIZEOF_BMAP_BTREE_ROOT_NODE_BLOCK size = SIZEOF_BMAP_BTREE_ROOT_NODE_HEADER 1.upto(@entry_count) do |i| start = size + maximum_records * offset_size + (i - 1) * block_size block = (data[start..start + block_size]).unpack('Q>').shift agbno = inode.sb.fsb_to_agbno(block) agno = inode.sb.fsb_to_agno(block) real_block = inode.sb.agbno_to_real_block(agno, agbno) @blocks.concat([real_block]) end end |
Instance Attribute Details
#blocks ⇒ Object
Returns the value of attribute blocks.
35 36 37 |
# File 'lib/fs/xfs/bmap_btree_root_node.rb', line 35 def blocks @blocks end |
#entry_count ⇒ Object
Returns the value of attribute entry_count.
35 36 37 |
# File 'lib/fs/xfs/bmap_btree_root_node.rb', line 35 def entry_count @entry_count end |
#level ⇒ Object
Returns the value of attribute level.
35 36 37 |
# File 'lib/fs/xfs/bmap_btree_root_node.rb', line 35 def level @level end |