Class: Ext3::Inode

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

Overview

//////////////////////////////////////////////////////////////////////////// // Class.

Constant Summary collapse

PF_O_EXECUTE =

Bits 0 to 8 of file mode.

0x0001
PF_O_WRITE =

owner execute

0x0002
PF_O_READ =

owner write

0x0004
PF_G_EXECUTE =

owner read

0x0008
PF_G_WRITE =

group execute

0x0010
PF_G_READ =

group write

0x0020
PF_U_EXECUTE =

group read

0x0040
PF_U_WRITE =

user execute

0x0080
PF_U_READ =

user write

0x0100
MSK_PERM_OWNER =

For accessor convenience.

(PF_O_EXECUTE | PF_O_WRITE | PF_O_READ)
MSK_PERM_GROUP =
(PF_G_EXECUTE | PF_G_WRITE | PF_G_READ)
MSK_PERM_USER =
(PF_U_EXECUTE | PF_U_WRITE | PF_U_READ)
DF_STICKY =

Bits 9 to 11 of file mode.

0x0200
DF_SET_GID =
0x0400
DF_SET_UID =
0x0800
FM_FIFO =

Bits 12 to 15 of file mode.

0x1000
FM_CHAR =

fifo device (pipe)

0x2000
FM_DIRECTORY =

char device

0x4000
FM_BLOCK_DEV =

directory

0x6000
FM_FILE =

block device

0x8000
FM_SYM_LNK =

regular file

0xa000
FM_SOCKET =

symbolic link

0xc000
MSK_FILE_MODE =

For accessor convenience.

0xf000
MSK_IS_DEV =
(FM_FIFO | FM_CHAR | FM_BLOCK_DEV | FM_SOCKET)
IF_SECURE_DEL =

Inode flags.

0x00000001
IF_KEEP_COPY =

wipe when deleting

0x00000002
IF_COMPRESS =

never delete

0x00000004
IF_SYNCHRO =

compress content

0x00000008
IF_IMMUTABLE =

don’t cache

0x00000010
IF_APPEND =

file cannot change

0x00000020
IF_NO_DUMP =

always append

0x00000040
IF_NO_ATIME =

don’t cat

0x00000080
IF_HASH_INDEX =

don’t update atime

0x00001000
IF_JOURNAL =

if dir, has hash index

0x00002000
@@FM2FT =

Lookup table for File Mode to File Type.

{
  Inode::FM_FIFO      => DirectoryEntry::FT_FIFO,
  Inode::FM_CHAR      => DirectoryEntry::FT_CHAR,
  Inode::FM_DIRECTORY => DirectoryEntry::FT_DIRECTORY,
  Inode::FM_BLOCK_DEV => DirectoryEntry::FT_BLOCK,
  Inode::FM_FILE      => DirectoryEntry::FT_FILE,
  Inode::FM_SYM_LNK   => DirectoryEntry::FT_SYM_LNK,
  Inode::FM_SOCKET    => DirectoryEntry::FT_SOCKET
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buf) ⇒ Inode

Returns a new instance of Inode.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/fs/ext3/inode.rb', line 106

def initialize(buf)
  raise "Ext3::Inode.initialize: Nil buffer" if buf.nil?
  @in = INODE.decode(buf)

  @mode    = @in['file_mode']
  @flags   = @in['flags']
  @length  = @in['size_lo']
  @length += (@in['size_hi'] << 32) unless self.isDir?

  # NOTE: Unpack the direct block pointers separately.
  @blockPointers      = @in['blk_ptrs'].unpack('L12')
  @sngIndBlockPointer = @in['ind_ptr']
  @dblIndBlockPointer = @in['dbl_ind_ptr']
  @tplIndBlockPointer = @in['tpl_ind_ptr']

  # If this is a symlnk < 60 bytes, grab the link metadata.
  if self.isSymLink? && length < SYM_LNK_SIZE
    @symlnk = buf[SYM_LNK_OFFSET, SYM_LNK_SIZE]
    # rPath is a wildcard. Sometimes they allocate when length < SYM_LNK_SIZE.
    # Analyze each byte of the first block pointer & see if it makes sense as ASCII.
    @symlnk[0, 4].each_byte do |c|
      if !(c > 45 && c < 48) && !((c > 64 && c < 91) || (c > 96 && c < 123))
        # This seems to be a block pointer, so nix @symlnk & pretend it's a regular file.
        @symlnk = nil
        break
      end
    end
  end
end

Instance Attribute Details

#blockPointersObject (readonly)

Returns the value of attribute blockPointers.



103
104
105
# File 'lib/fs/ext3/inode.rb', line 103

def blockPointers
  @blockPointers
end

#dblIndBlockPointerObject (readonly)

Returns the value of attribute dblIndBlockPointer.



104
105
106
# File 'lib/fs/ext3/inode.rb', line 104

def dblIndBlockPointer
  @dblIndBlockPointer
end

#flagsObject (readonly)

Returns the value of attribute flags.



103
104
105
# File 'lib/fs/ext3/inode.rb', line 103

def flags
  @flags
end

#lengthObject (readonly)

Returns the value of attribute length.



103
104
105
# File 'lib/fs/ext3/inode.rb', line 103

def length
  @length
end

#modeObject (readonly)

Returns the value of attribute mode.



103
104
105
# File 'lib/fs/ext3/inode.rb', line 103

def mode
  @mode
end

#sngIndBlockPointerObject (readonly)

Returns the value of attribute sngIndBlockPointer.



104
105
106
# File 'lib/fs/ext3/inode.rb', line 104

def sngIndBlockPointer
  @sngIndBlockPointer
end

#symlnkObject (readonly)

Returns the value of attribute symlnk.



103
104
105
# File 'lib/fs/ext3/inode.rb', line 103

def symlnk
  @symlnk
end

#tplIndBlockPointerObject (readonly)

Returns the value of attribute tplIndBlockPointer.



104
105
106
# File 'lib/fs/ext3/inode.rb', line 104

def tplIndBlockPointer
  @tplIndBlockPointer
end

Instance Method Details

#aTimeObject



159
160
161
# File 'lib/fs/ext3/inode.rb', line 159

def aTime
  Time.at(@in['atime'])
end

#cTimeObject



163
164
165
# File 'lib/fs/ext3/inode.rb', line 163

def cTime
  Time.at(@in['ctime'])
end

#dTimeObject



171
172
173
# File 'lib/fs/ext3/inode.rb', line 171

def dTime
  Time.at(@in['dtime'])
end

#dumpObject



202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/fs/ext3/inode.rb', line 202

def dump
  out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
  out += "File mode    : 0x#{'%04x' % @in['file_mode']}\n"
  out += "UID          : #{uid}\n"
  out += "Size         : #{length}\n"
  out += "ATime        : #{aTime}\n"
  out += "CTime        : #{cTime}\n"
  out += "MTime        : #{mTime}\n"
  out += "DTime        : #{dTime}\n"
  out += "GID          : #{gid}\n"
  out += "Link count   : #{@in['link_count']}\n"
  out += "Sector count : #{@in['sector_count']}\n"
  out += "Flags        : 0x#{'%08x' % @in['flags']}\n"
  out += "Direct block pointers:\n"
  12.times { |i| p = @blockPointers[i]; out += "  #{i} = 0x#{'%08x' % p}\n" }
  out += "Sng Indirect : 0x#{'%08x' % @in['ind_ptr']}\n"
  out += "Dbl Indirect : 0x#{'%08x' % @in['dbl_ind_ptr']}\n"
  out += "Tpl Indirect : 0x#{'%08x' % @in['tpl_ind_ptr']}\n"
  out += "Generation   : 0x#{'%08x' % @in['gen_num']}\n"
  out += "Ext attrib   : 0x#{'%08x' % @in['ext_attrib']}\n"
  out += "Frag blk adrs: 0x#{'%08x' % @in['frag_blk']}\n"
  out += "Frag index   : 0x#{'%02x' % @in['frag_idx']}\n"
  out += "Frag size    : 0x#{'%02x' % @in['frag_siz']}\n"
  out
end

#fileModeToFileTypeObject

//////////////////////////////////////////////////////////////////////////// // Utility functions.



198
199
200
# File 'lib/fs/ext3/inode.rb', line 198

def fileModeToFileType
  @@FM2FT[@mode & MSK_FILE_MODE]
end

#gidObject



175
176
177
# File 'lib/fs/ext3/inode.rb', line 175

def gid
  (@in['gid_hi'] << 16) | @in['gid_lo']
end

#groupPermissionsObject



187
188
189
# File 'lib/fs/ext3/inode.rb', line 187

def groupPermissions
  @in['file_mode'] & MSK_PERM_GROUP
end

#isDev?Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/fs/ext3/inode.rb', line 151

def isDev?
  @mode & MSK_IS_DEV > 0
end

#isDir?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'lib/fs/ext3/inode.rb', line 143

def isDir?
  @mode & FM_DIRECTORY == FM_DIRECTORY
end

#isFile?Boolean

Returns:

  • (Boolean)


147
148
149
# File 'lib/fs/ext3/inode.rb', line 147

def isFile?
  @mode & FM_FILE == FM_FILE
end

#isSymLink?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'lib/fs/ext3/inode.rb', line 155

def isSymLink?
  @mode & FM_SYM_LNK == FM_SYM_LNK
end

#mTimeObject



167
168
169
# File 'lib/fs/ext3/inode.rb', line 167

def mTime
  Time.at(@in['mtime'])
end

#ownerPermissionsObject



183
184
185
# File 'lib/fs/ext3/inode.rb', line 183

def ownerPermissions
  @in['file_mode'] & MSK_PERM_OWNER
end

#permissionsObject



179
180
181
# File 'lib/fs/ext3/inode.rb', line 179

def permissions
  @in['file_mode'] & (MSK_PERM_OWNER | MSK_PERM_GROUP | MSK_PERM_USER)
end

#uidObject

//////////////////////////////////////////////////////////////////////////// // Class helpers & accessors.



139
140
141
# File 'lib/fs/ext3/inode.rb', line 139

def uid
  (@in['uid_hi'] << 16) | @in['uid_lo']
end

#userPermissionsObject



191
192
193
# File 'lib/fs/ext3/inode.rb', line 191

def userPermissions
  @in['file_mode'] & MSK_PERM_USER
end