Class: NTFS::FileName

Inherits:
Object
  • Object
show all
Defined in:
lib/fs/ntfs/attrib_file_name.rb

Constant Summary collapse

NS_POSIX =
0
NS_WIN32 =
1
NS_DOS =
2
NS_DOSWIN =
3
UNNAMED =
'[unnamed]'.AsciiToUtf8.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(buf) ⇒ FileName

Returns a new instance of FileName.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/fs/ntfs/attrib_file_name.rb', line 55

def initialize(buf)
  raise "MIQ(NTFS::FileName.initialize) Nil buffer" if buf.nil?
  buf          = buf.read(buf.length) if buf.kind_of?(DataRun)
  @afn         = ATTRIB_FILE_NAME.decode(buf)
  buf          = buf[SIZEOF_ATTRIB_FILE_NAME, buf.size]

  # Set accessor data.
  @permissions = @afn['flags']
  @length      = @afn['data_size']
  @namespace   = @afn['namespace']
  @refParent   = NTFS::Utils.MkRef(@afn['ref_to_parent_dir'])

  # If there's a name get it.
  len          = @afn['name_length'] * 2
  @name        = buf[0, len].UnicodeToUtf8 if len > 0

  # If name is nil use NT standard unnamed.
  @name ||= UNNAMED.dup
end

Instance Attribute Details

#lengthObject (readonly)

Returns the value of attribute length.



46
47
48
# File 'lib/fs/ntfs/attrib_file_name.rb', line 46

def length
  @length
end

#nameObject (readonly)

Returns the value of attribute name.



46
47
48
# File 'lib/fs/ntfs/attrib_file_name.rb', line 46

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



46
47
48
# File 'lib/fs/ntfs/attrib_file_name.rb', line 46

def namespace
  @namespace
end

#permissionsObject (readonly)

Returns the value of attribute permissions.



46
47
48
# File 'lib/fs/ntfs/attrib_file_name.rb', line 46

def permissions
  @permissions
end

#refParentObject (readonly)

Returns the value of attribute refParent.



46
47
48
# File 'lib/fs/ntfs/attrib_file_name.rb', line 46

def refParent
  @refParent
end

Instance Method Details

#aTimeObject



83
84
85
# File 'lib/fs/ntfs/attrib_file_name.rb', line 83

def aTime
  @aTime ||= NtUtil.nt_filetime_to_ruby_time(@afn['time_read'])
end

#cTimeObject



87
88
89
# File 'lib/fs/ntfs/attrib_file_name.rb', line 87

def cTime
  @cTime ||= NtUtil.nt_filetime_to_ruby_time(@afn['time_created'])
end

#dumpObject



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fs/ntfs/attrib_file_name.rb', line 96

def dump
  out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
  out << "  Parent dir : seq #{@refParent[0]}, entry #{@refParent[1]}\n"
  out << "  Created    : #{@cTime}\n"
  out << "  Modified   : #{@mTime}\n"
  out << "  MFT changed: #{NtUtil.nt_filetime_to_ruby_time(@afn['time_mft_changed'])}\n"
  out << "  Accessed   : #{@aTime}\n"
  out << "  Allocated  : #{@afn['allocated_size']}\n"
  out << "  Real size  : #{@length}\n"
  out << "  Flags      : 0x#{'%08x' % @flags}\n"
  out << "  Reparse    : #{@afn['reparse_point_tag']}\n"
  out << "  Name length: #{@afn['name_length']}\n"
  out << "  Namespace  : #{@namespace}\n"
  out << "  Name       : #{@name}\n"
  out << "---\n"
end

#isDir?Boolean

Returns nil if not directory.

Returns:

  • (Boolean)


92
93
94
# File 'lib/fs/ntfs/attrib_file_name.rb', line 92

def isDir?
  NTFS::Utils.gotBit?(@permissions, StandardInformation.FP_DIRECTORY)
end

#mTimeObject



79
80
81
# File 'lib/fs/ntfs/attrib_file_name.rb', line 79

def mTime
  @mTime ||= NtUtil.nt_filetime_to_ruby_time(@afn['time_altered'])
end

#to_sObject



75
76
77
# File 'lib/fs/ntfs/attrib_file_name.rb', line 75

def to_s
  @name
end