Class: Ext3::GroupDescriptorTable

Inherits:
Object
  • Object
show all
Defined in:
lib/fs/ext3/group_descriptor_table.rb

Instance Method Summary collapse

Constructor Details

#initialize(sb) ⇒ GroupDescriptorTable

Returns a new instance of GroupDescriptorTable.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/fs/ext3/group_descriptor_table.rb', line 7

def initialize(sb)
  raise "Ext3::GroupDescriptorTable.initialize: Nil Superblock" if sb.nil?

  # Read all the group descriptor entries.
  @gdt = []
  sb.stream.seek(sb.blockToAddress(sb.blockSize == 1024 ? 2 : 1))
  buf = sb.stream.read(SIZEOF_GDE * sb.numGroups)
  offset = 0
  sb.numGroups.times do
    gde = GroupDescriptorEntry.new(buf[offset, SIZEOF_GDE])

    # Construct allocation bitmaps for blocks & inodes.
    gde.blockAllocBmp = getAllocBitmap(sb, gde.blockBmp, sb.blockSize)
    gde.inodeAllocBmp = getAllocBitmap(sb, gde.inodeBmp, sb.inodesPerGroup / 8)

    @gdt << gde
    offset += SIZEOF_GDE
  end
end

Instance Method Details

#[](group) ⇒ Object



31
32
33
# File 'lib/fs/ext3/group_descriptor_table.rb', line 31

def [](group)
  @gdt[group]
end

#dump(dump_bitmaps = false) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/fs/ext3/group_descriptor_table.rb', line 35

def dump(dump_bitmaps = false)
  out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
  @gdt.each do|gde|
    out += gde.dump
    if dump_bitmaps
      out += "Block allocation\n#{gde.blockAllocBmp.dump}"
      out += "Inode allocation\n#{gde.inodeAllocBmp.dump}"
    end
  end
  out
end

#eachObject



27
28
29
# File 'lib/fs/ext3/group_descriptor_table.rb', line 27

def each
  @gdt.each { |gde| yield(gde) }
end