Sha256: cc6a9cf93bffc6793bc230180066cf73c4dbd1beea199682b207a18f2a227a4f

Contents?: true

Size: 1.92 KB

Versions: 66

Compression:

Stored size: 1.92 KB

Contents

require 'binary_struct'

module Ext3
  # ////////////////////////////////////////////////////////////////////////////
  # // Data definitions.

  DIR_ENTRY_ORIGINAL = BinaryStruct.new([
    'L',  'inode_val',  # Inode address of metadata.
    'S',  'entry_len',  # Length of entry.
    'S',  'name_len',   # Length of name.
  ])
  # Here follows the name in ASCII.
  SIZEOF_DIR_ENTRY_ORIGINAL = DIR_ENTRY_ORIGINAL.size

  DIR_ENTRY_NEW = BinaryStruct.new([
    'L',  'inode_val',  # Inode address of metadata.
    'S',  'entry_len',  # Length of entry.
    'C',  'name_len',   # Length of name.
    'C',  'file_type',  # Type of file (see FT_ below).
  ])
  # Here follows the name in ASCII.
  SIZEOF_DIR_ENTRY_NEW = DIR_ENTRY_NEW.size

  class DirectoryEntry
    FT_UNKNOWN    = 0
    FT_FILE       = 1
    FT_DIRECTORY  = 2
    FT_CHAR       = 3
    FT_BLOCK      = 4
    FT_FIFO       = 5
    FT_SOCKET     = 6
    FT_SYM_LNK    = 7

    attr_reader :inode, :len, :name
    attr_accessor :fileType

    def initialize(data, new_entry = true)
      raise "Ext3::DirectoryEntry.initialize: Nil directory entry data" if data.nil?
      @isNew = new_entry
      # Both entries are same size.
      siz = SIZEOF_DIR_ENTRY_NEW
      @de = @isNew ? DIR_ENTRY_NEW.decode(data[0..siz]) : DIR_ENTRY_ORIGINAL.decode(data[0..siz])
      # If there's a name get it.
      @name = data[siz, @de['name_len']] if @de['name_len'] != 0
      @inode = @de['inode_val']
      @len = @de['entry_len']
      @fileType = @de['file_type'] if @isNew
    end

    def isDir?
      @fileType == FT_DIRECTORY
    end

    def isSymLink?
      @fileType == FT_SYM_LNK
    end

    def dump
      out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
      out += "Inode   : #{inode}\n"
      out += "Len     : #{len}\n"
      out += "Name len: 0x#{'%04x' % @de['name_len']}\n"
      out += "Type    : #{fileType}\n" if @isNew
      out += "Name    : #{name}\n"
    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/directory_entry.rb
manageiq-smartstate-0.10.0 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.9.0 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.8.1 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.8.0 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.7.0 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.6.2 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.5.10 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.3.10 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.6.1 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.3.9 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.6.0 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.5.9 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.5.8 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.3.8 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.5.7 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.3.7 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.5.6 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.3.6 lib/fs/ext3/directory_entry.rb
manageiq-smartstate-0.5.5 lib/fs/ext3/directory_entry.rb