Class: Ext3::DirectoryEntry

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, new_entry = true) ⇒ DirectoryEntry

Returns a new instance of DirectoryEntry.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fs/ext3/directory_entry.rb', line 37

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

Instance Attribute Details

#fileTypeObject

Returns the value of attribute fileType.



35
36
37
# File 'lib/fs/ext3/directory_entry.rb', line 35

def fileType
  @fileType
end

#inodeObject (readonly)

Returns the value of attribute inode.



34
35
36
# File 'lib/fs/ext3/directory_entry.rb', line 34

def inode
  @inode
end

#lenObject (readonly)

Returns the value of attribute len.



34
35
36
# File 'lib/fs/ext3/directory_entry.rb', line 34

def len
  @len
end

#nameObject (readonly)

Returns the value of attribute name.



34
35
36
# File 'lib/fs/ext3/directory_entry.rb', line 34

def name
  @name
end

Instance Method Details

#dumpObject



58
59
60
61
62
63
64
65
# File 'lib/fs/ext3/directory_entry.rb', line 58

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

#isDir?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/fs/ext3/directory_entry.rb', line 50

def isDir?
  @fileType == FT_DIRECTORY
end

#isSymLink?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/fs/ext3/directory_entry.rb', line 54

def isSymLink?
  @fileType == FT_SYM_LNK
end