Sha256: 25a192bfbd1488b70e7538fb98a1657fc029007450278c6d5c1fb3ca1eda84c2

Contents?: true

Size: 1.41 KB

Versions: 66

Compression:

Stored size: 1.41 KB

Contents

require 'fs/ext3/group_descriptor_entry'
require 'fs/ext3/alloc_bitmap'
require 'binary_struct'

module Ext3
  class GroupDescriptorTable
    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

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

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

    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

    private

    def getAllocBitmap(sb, block, size)
      sb.stream.seek(sb.blockToAddress(block))
      AllocBitmap.new(sb.stream.read(size))
    end
  end # class
end # module

Version data entries

66 entries across 66 versions & 1 rubygems

Version Path
manageiq-smartstate-0.10.1 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.10.0 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.9.0 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.8.1 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.8.0 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.7.0 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.6.2 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.5.10 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.3.10 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.6.1 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.3.9 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.6.0 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.5.9 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.5.8 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.3.8 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.5.7 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.3.7 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.5.6 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.3.6 lib/fs/ext3/group_descriptor_table.rb
manageiq-smartstate-0.5.5 lib/fs/ext3/group_descriptor_table.rb