Class: XFS::ShortFormDirectoryEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/fs/xfs/short_form_directory_entry.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data, short_inode, sb, dots = nil, inode_number = nil) ⇒ ShortFormDirectoryEntry

Returns a new instance of ShortFormDirectoryEntry.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 57

def initialize(data, short_inode, sb, dots = nil, inode_number = nil)
  #
  # If dots is 1 or 2 we need to construct the
  # "." and ".." directory entries.
  #
  return dot_entry(dots, inode_number) if dots
  raise "XFS::ShortFormDirectoryEntry.initialize: Nil directory entry data" if data.nil?
  siz              = SIZEOF_SHORT_FORM_DIRECTORY_ENTRY
  @directory_entry = SHORT_FORM_DIRECTORY_ENTRY.decode(data[0..siz])
  @name_length     = @directory_entry['name_length']
  unless @name_length == 0
    @name = data[siz, @name_length]
    @name_length += 1 if sb.version_has_crc?
    start = siz + @name_length
    if short_inode
      ino_size = SIZEOF_SHORT_FORM_SHORT_INO
      inode    = SHORT_FORM_SHORT_INO.decode(data[start..(start + ino_size)])
    else
      ino_size = SIZEOF_SHORT_FORM_LONG_INO
      inode    = SHORT_FORM_LONG_INO.decode(data[start..(start + ino_size)])
    end
    @length    = start + ino_size
    @inode     = inode['inode_num']
  end
end

Instance Attribute Details

#file_typeObject

Returns the value of attribute file_type.



29
30
31
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 29

def file_type
  @file_type
end

#inodeObject

Returns the value of attribute inode.



29
30
31
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 29

def inode
  @inode
end

#lengthObject (readonly)

Returns the value of attribute length.



28
29
30
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 28

def length
  @length
end

#nameObject (readonly)

Returns the value of attribute name.



28
29
30
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 28

def name
  @name
end

#name_lengthObject (readonly)

Returns the value of attribute name_length.



28
29
30
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 28

def name_length
  @name_length
end

#short_inodeObject (readonly)

Returns the value of attribute short_inode.



28
29
30
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 28

def short_inode
  @short_inode
end

Instance Method Details

#device?Boolean

Returns:

  • (Boolean)


43
44
45
46
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 43

def device?
  @file_type == Inode::FT_CHAR || @file_type == Inode::FT_BLOCK ||
    @file_type == Inode::FT_FIFO || @file_type == Inode::FT_SOCKET
end

#directory?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 35

def directory?
  @file_type == Inode::FT_DIRECTORY
end

#dot_entry(dots, inode_number) ⇒ Object



48
49
50
51
52
53
54
55
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 48

def dot_entry(dots, inode_number)
  @length      = 0
  @name_length = dots
  @name        = "."
  @name        = ".." if dots == 2
  @inode       = inode_number
  # Inode Numbers will be filled in by the caller
end

#dumpObject



83
84
85
86
87
88
89
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 83

def dump
  out = "\#<#{self.class}:0x#{format('%08x', object_id)}>\n"
  out += "Inode   : #{inode}\n"
  out += "Len     : #{length}\n"
  out += "Name    : #{name}\n"
  out
end

#file?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 39

def file?
  @file_type == Inode::FT_FILE
end

#symlink?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/fs/xfs/short_form_directory_entry.rb', line 31

def symlink?
  @file_type == Inode::FT_SYM_LNK
end