Class: XFS::DirectoryEntry
- Inherits:
-
Object
- Object
- XFS::DirectoryEntry
- Defined in:
- lib/fs/xfs/directory_entry.rb
Constant Summary collapse
- XFS_DIR2_DATA_FREE_TAG =
0xffff
- XFS_DIR2_DATA_ALIGN_LOG =
3
- XFS_DIR2_DATA_ALIGN =
1 << XFS_DIR2_DATA_ALIGN_LOG
- XFS_DIR2_SPACE_SIZE =
1 << (32 + XFS_DIR2_DATA_ALIGN_LOG)
- XFS_DIR2_LEAF_SPACE =
1
- XFS_DIR2_LEAF_OFFSET =
XFS_DIR2_LEAF_SPACE * XFS_DIR2_SPACE_SIZE
- SIZEOF_SMALLEST_DIRECTORY_ENTRY =
16 is the smallest directory entry size but hard-coding is not nice
16
Instance Attribute Summary collapse
-
#file_type ⇒ Object
Returns the value of attribute file_type.
-
#inode ⇒ Object
readonly
Returns the value of attribute inode.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#name_length ⇒ Object
readonly
Returns the value of attribute name_length.
-
#tag ⇒ Object
readonly
Returns the value of attribute tag.
Instance Method Summary collapse
- #device? ⇒ Boolean
- #dir_data_entsize(n, version_3_header) ⇒ Object
- #directory? ⇒ Boolean
- #dump ⇒ Object
- #file? ⇒ Boolean
-
#initialize(data, version_3_header) ⇒ DirectoryEntry
constructor
A new instance of DirectoryEntry.
- #round_up(num, base) ⇒ Object
- #symlink? ⇒ Boolean
Constructor Details
#initialize(data, version_3_header) ⇒ DirectoryEntry
Returns a new instance of DirectoryEntry.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fs/xfs/directory_entry.rb', line 73 def initialize(data, version_3_header) raise "XFS::DirectoryEntry.initialize: Nil directory entry data" if data.nil? size = SIZEOF_DIRECTORY2_UNUSED_ENTRY start = @length = @name_length = 0 unused_entry = DIRECTORY2_UNUSED_ENTRY.decode(data[start..size]) if unused_entry['freetag'] == XFS_DIR2_DATA_FREE_TAG @length = unused_entry['length'] @name = "" return end free_size = start size = SIZEOF_DIRECTORY2_DATA_ENTRY @de = DIRECTORY2_DATA_ENTRY.decode(data[start..(start + size)]) @inode = @de['inumber'] @name_length = @de['name_len'] start += size # If there's a name get it. unless @name_length == 0 @name = data[start, @name_length] @tag = DIRECTORY2_DATA_TAG.decode(data[start]) @length = free_size + dir_data_entsize(@name_length, version_3_header) end raise "XFS::Directory: DirectoryEntry length cannot be 0" if @length == 0 end |
Instance Attribute Details
#file_type ⇒ Object
Returns the value of attribute file_type.
71 72 73 |
# File 'lib/fs/xfs/directory_entry.rb', line 71 def file_type @file_type end |
#inode ⇒ Object (readonly)
Returns the value of attribute inode.
70 71 72 |
# File 'lib/fs/xfs/directory_entry.rb', line 70 def inode @inode end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
70 71 72 |
# File 'lib/fs/xfs/directory_entry.rb', line 70 def length @length end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
70 71 72 |
# File 'lib/fs/xfs/directory_entry.rb', line 70 def name @name end |
#name_length ⇒ Object (readonly)
Returns the value of attribute name_length.
70 71 72 |
# File 'lib/fs/xfs/directory_entry.rb', line 70 def name_length @name_length end |
#tag ⇒ Object (readonly)
Returns the value of attribute tag.
70 71 72 |
# File 'lib/fs/xfs/directory_entry.rb', line 70 def tag @tag end |
Instance Method Details
#device? ⇒ Boolean
53 54 55 56 |
# File 'lib/fs/xfs/directory_entry.rb', line 53 def device? @file_type == Inode::FT_CHAR || @file_type == Inode::FT_BLOCK || @file_type == Inode::FT_FIFO || @file_type == Inode::FT_SOCKET end |
#dir_data_entsize(n, version_3_header) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/fs/xfs/directory_entry.rb', line 63 def dir_data_entsize(n, version_3_header) if version_3_header return round_up(SIZEOF_DIRECTORY2_DATA_ENTRY + n + SIZEOF_DIRECTORY2_DATA_TAG + 1, XFS_DIR2_DATA_ALIGN) end round_up(SIZEOF_DIRECTORY2_DATA_ENTRY + n + SIZEOF_DIRECTORY2_DATA_TAG, XFS_DIR2_DATA_ALIGN) end |
#directory? ⇒ Boolean
45 46 47 |
# File 'lib/fs/xfs/directory_entry.rb', line 45 def directory? @file_type == Inode::FT_DIRECTORY end |
#dump ⇒ Object
98 99 100 101 102 103 104 |
# File 'lib/fs/xfs/directory_entry.rb', line 98 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
49 50 51 |
# File 'lib/fs/xfs/directory_entry.rb', line 49 def file? @file_type == Inode::FT_FILE end |
#round_up(num, base) ⇒ Object
58 59 60 61 |
# File 'lib/fs/xfs/directory_entry.rb', line 58 def round_up(num, base) return num if num % base == 0 num + base - (num % base) end |
#symlink? ⇒ Boolean
41 42 43 |
# File 'lib/fs/xfs/directory_entry.rb', line 41 def symlink? @file_type == Inode::FT_SYM_LNK end |