Class: ReiserFS::Superblock
- Inherits:
-
Object
- Object
- ReiserFS::Superblock
- Defined in:
- lib/fs/ReiserFS/superblock.rb
Constant Summary collapse
- DEF_LEAF_NODE_CACHE_SIZE =
Default cache sizes.
50
Instance Attribute Summary collapse
-
#bitmapNumber ⇒ Object
readonly
Returns the value of attribute bitmapNumber.
-
#blockSize ⇒ Object
readonly
Returns the value of attribute blockSize.
-
#nblocksInBitmap ⇒ Object
readonly
Returns the value of attribute nblocksInBitmap.
-
#rootBlock ⇒ Object
readonly
Returns the value of attribute rootBlock.
-
#treeHeight ⇒ Object
readonly
Returns the value of attribute treeHeight.
Instance Method Summary collapse
- #blockUsed?(blockNum) ⇒ Boolean
-
#freeBytes ⇒ Object
Returns free space on file system in bytes.
- #getBitmapBlock(bitmapNum) ⇒ Object
- #getLeafNodes(key) ⇒ Object
-
#initialize(stream) ⇒ Superblock
constructor
A new instance of Superblock.
- #readBlock(blockNum) ⇒ Object
- #readBlockRaw(blockNum) ⇒ Object
Constructor Details
#initialize(stream) ⇒ Superblock
Returns a new instance of Superblock.
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 |
# File 'lib/fs/ReiserFS/superblock.rb', line 43 def initialize(stream) raise "Nil stream" if stream.nil? @stream = stream # Seek, read & decode the superblock structure @stream.seek(SUPERBLOCK_OFFSET) @sb = SUPERBLOCK.decode(@stream.read(SUPERBLOCK_SIZE)) # Grab some quick facts & make sure there's nothing wrong. Tight qualification. raise "Invalid Magic String: #{@sb['magic']}" unless isMagic?(@sb['magic']) @totalBlocks = @sb['num_blocks'] @freeBlocks = @sb['num_free_blocks'] @rootBlock = @sb['root_block'] @treeHeight = @sb['tree_height'] @bitmapNumber = @sb['bitmap_number'] @version = @sb['version'] @state = @sb['state'] @blockSize = @sb['block_size'] @nblocksInBitmap = 8 * @blockSize @oidMaxSize = @sb['oid_max_size'] @oidCurrentSize = @sb['oid_current_size'] @superBlock = SUPERBLOCK_OFFSET / @blockSize @leaf_nodes = LruHash.new(DEF_LEAF_NODE_CACHE_SIZE) end |
Instance Attribute Details
#bitmapNumber ⇒ Object (readonly)
Returns the value of attribute bitmapNumber.
41 42 43 |
# File 'lib/fs/ReiserFS/superblock.rb', line 41 def bitmapNumber @bitmapNumber end |
#blockSize ⇒ Object (readonly)
Returns the value of attribute blockSize.
41 42 43 |
# File 'lib/fs/ReiserFS/superblock.rb', line 41 def blockSize @blockSize end |
#nblocksInBitmap ⇒ Object (readonly)
Returns the value of attribute nblocksInBitmap.
41 42 43 |
# File 'lib/fs/ReiserFS/superblock.rb', line 41 def nblocksInBitmap @nblocksInBitmap end |
#rootBlock ⇒ Object (readonly)
Returns the value of attribute rootBlock.
41 42 43 |
# File 'lib/fs/ReiserFS/superblock.rb', line 41 def rootBlock @rootBlock end |
#treeHeight ⇒ Object (readonly)
Returns the value of attribute treeHeight.
41 42 43 |
# File 'lib/fs/ReiserFS/superblock.rb', line 41 def treeHeight @treeHeight end |
Instance Method Details
#blockUsed?(blockNum) ⇒ Boolean
80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fs/ReiserFS/superblock.rb', line 80 def blockUsed?(blockNum) bitmapNum = blockNum / @nblocksInBitmap raise "Block out of Range" if bitmapNum >= @bitmapNumber bitmapBlock = getBitmapBlock(bitmapNum) bitmapOffset = blockNum % @nblocksInBitmap bitmapByte = bitmapOffset / 8 bitmapByteOffset = bitmapOffset % 8 bits = bitmapBlock[bitmapByte, 1].unpack('B8')[0] (bits[bitmapByteOffset, 1] == "1") end |
#freeBytes ⇒ Object
Returns free space on file system in bytes.
130 131 132 |
# File 'lib/fs/ReiserFS/superblock.rb', line 130 def freeBytes @freeBlocks * @blockSize end |
#getBitmapBlock(bitmapNum) ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/fs/ReiserFS/superblock.rb', line 70 def getBitmapBlock(bitmapNum) if bitmapNum == 0 blockNum = @superBlock + 1 else blockNum = bitmapNum * @nblocksInBitmap end readBlockRaw(blockNum) end |
#getLeafNodes(key) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/fs/ReiserFS/superblock.rb', line 106 def getLeafNodes(key) key_s = Utils.dumpKey(key) return @leaf_nodes[key_s] if @leaf_nodes.key?(key_s) blocks = [] leaves = [] blocks << readBlock(@rootBlock) blocks.each do |block| next if block.nil? if block.isLeaf? leaves << block next end block.findPointers(key).each do |pointer| blocks << readBlock(pointer['block_number']) end end @leaf_nodes[key_s] = leaves end |
#readBlock(blockNum) ⇒ Object
100 101 102 103 104 |
# File 'lib/fs/ReiserFS/superblock.rb', line 100 def readBlock(blockNum) # return nil if !blockUsed?(blockNum) data = readBlockRaw(blockNum) Block.new(data, blockNum) end |
#readBlockRaw(blockNum) ⇒ Object
93 94 95 96 97 98 |
# File 'lib/fs/ReiserFS/superblock.rb', line 93 def readBlockRaw(blockNum) raise "ReiserFS::SuperBlock >> blockNum is nil" if blockNum.nil? @stream.seek(blockNum * @blockSize) @stream.read(@blockSize) end |