manageiq-smartstate 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (305) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +15 -0
  3. data/.rspec +4 -0
  4. data/.rspec_ci +4 -0
  5. data/.travis.yml +15 -0
  6. data/Gemfile +9 -0
  7. data/LICENSE.txt +202 -0
  8. data/README.md +45 -0
  9. data/Rakefile +23 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +8 -0
  12. data/lib/MiqContainerGroup/MiqContainerGroup.rb +31 -0
  13. data/lib/MiqVm/MiqLocalVm.rb +50 -0
  14. data/lib/MiqVm/MiqRhevmVm.rb +179 -0
  15. data/lib/MiqVm/MiqVm.rb +355 -0
  16. data/lib/MiqVm/miq_azure_vm.rb +96 -0
  17. data/lib/MiqVm/miq_scvmm_vm.rb +38 -0
  18. data/lib/MiqVm/test/camcorder_fleece_test.rb +60 -0
  19. data/lib/MiqVm/test/localVm.rb +45 -0
  20. data/lib/MiqVm/test/partitionAlignmentCheck.rb +76 -0
  21. data/lib/MiqVm/test/remoteVm.rb +65 -0
  22. data/lib/MiqVm/test/rhevmNfsTest.rb +62 -0
  23. data/lib/MiqVm/test/rhevmNfsTest2.rb +66 -0
  24. data/lib/MiqVm/test/rhevmTest.rb +70 -0
  25. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackCommon.rb +107 -0
  26. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackImage.rb +67 -0
  27. data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackInstance.rb +182 -0
  28. data/lib/Scvmm/miq_hyperv_disk.rb +273 -0
  29. data/lib/Scvmm/miq_scvmm_parse_powershell.rb +75 -0
  30. data/lib/Scvmm/miq_scvmm_vm_ssa_info.rb +135 -0
  31. data/lib/Scvmm/test/miq_hyperv_disk_test.rb +33 -0
  32. data/lib/Scvmm/test/miq_scvmm_vm_ssa_info_test.rb +41 -0
  33. data/lib/VmLocalDiskAccess/test/localCfg.rb +97 -0
  34. data/lib/VolumeManager/LVM/logical_volume.rb +75 -0
  35. data/lib/VolumeManager/LVM/lv_segment.rb +43 -0
  36. data/lib/VolumeManager/LVM/lvm2disk.rb +158 -0
  37. data/lib/VolumeManager/LVM/parser.rb +138 -0
  38. data/lib/VolumeManager/LVM/physical_volume.rb +19 -0
  39. data/lib/VolumeManager/LVM/scanner.rb +156 -0
  40. data/lib/VolumeManager/LVM/thin/btree.rb +83 -0
  41. data/lib/VolumeManager/LVM/thin/constants.rb +86 -0
  42. data/lib/VolumeManager/LVM/thin/data_map.rb +44 -0
  43. data/lib/VolumeManager/LVM/thin/mapping_tree.rb +19 -0
  44. data/lib/VolumeManager/LVM/thin/space_maps.rb +58 -0
  45. data/lib/VolumeManager/LVM/thin/superblock.rb +136 -0
  46. data/lib/VolumeManager/LVM/thin.rb +6 -0
  47. data/lib/VolumeManager/LVM/volume_group.rb +97 -0
  48. data/lib/VolumeManager/LVM.rb +8 -0
  49. data/lib/VolumeManager/MiqLdm.rb +546 -0
  50. data/lib/VolumeManager/MiqLvm.rb +17 -0
  51. data/lib/VolumeManager/MiqNativeVolumeManager.rb +150 -0
  52. data/lib/VolumeManager/MiqVolumeManager.rb +277 -0
  53. data/lib/VolumeManager/VolMgrPlatformSupport.rb +18 -0
  54. data/lib/VolumeManager/VolMgrPlatformSupportLinux.rb +77 -0
  55. data/lib/VolumeManager/VolMgrPlatformSupportWin.rb +17 -0
  56. data/lib/VolumeManager/test/blockDevTest.rb +40 -0
  57. data/lib/VolumeManager/test/ldm.rb +97 -0
  58. data/lib/blackbox/VmBlackBox.rb +103 -0
  59. data/lib/blackbox/xmlStorage.rb +180 -0
  60. data/lib/db/MiqBdb/MiqBdb.rb +309 -0
  61. data/lib/db/MiqBdb/MiqBdbBtree.rb +219 -0
  62. data/lib/db/MiqBdb/MiqBdbHash.rb +199 -0
  63. data/lib/db/MiqBdb/MiqBdbPage.rb +159 -0
  64. data/lib/db/MiqBdb/MiqBdbUtil.rb +18 -0
  65. data/lib/db/MiqSqlite/MiqSqlite3.rb +330 -0
  66. data/lib/db/MiqSqlite/MiqSqlite3Cell.rb +167 -0
  67. data/lib/db/MiqSqlite/MiqSqlite3Page.rb +151 -0
  68. data/lib/db/MiqSqlite/MiqSqlite3Table.rb +124 -0
  69. data/lib/db/MiqSqlite/MiqSqlite3Util.rb +32 -0
  70. data/lib/disk/DiskProbe.rb +68 -0
  71. data/lib/disk/MiqDisk.rb +317 -0
  72. data/lib/disk/camcorder_test.rb +90 -0
  73. data/lib/disk/dos_mbr.img +0 -0
  74. data/lib/disk/modules/AzureBlobDisk.rb +101 -0
  75. data/lib/disk/modules/LocalDevMod.rb +47 -0
  76. data/lib/disk/modules/LocalDevProbe.rb +6 -0
  77. data/lib/disk/modules/MSCommon.rb +352 -0
  78. data/lib/disk/modules/MSVSDiffDisk.rb +91 -0
  79. data/lib/disk/modules/MSVSDiskProbe.rb +61 -0
  80. data/lib/disk/modules/MSVSDynamicDisk.rb +42 -0
  81. data/lib/disk/modules/MSVSFixedDisk.rb +45 -0
  82. data/lib/disk/modules/MiqLargeFile.rb +63 -0
  83. data/lib/disk/modules/MiqLargeFileWin32.rb +107 -0
  84. data/lib/disk/modules/QcowDisk.rb +692 -0
  85. data/lib/disk/modules/QcowDiskProbe.rb +34 -0
  86. data/lib/disk/modules/RawBlockIO.rb +116 -0
  87. data/lib/disk/modules/RawDisk.rb +45 -0
  88. data/lib/disk/modules/RawDiskProbe.rb +7 -0
  89. data/lib/disk/modules/RhevmDescriptor.rb +167 -0
  90. data/lib/disk/modules/RhevmDiskProbe.rb +52 -0
  91. data/lib/disk/modules/VMWareCowdDisk.rb +207 -0
  92. data/lib/disk/modules/VMWareDescriptor.rb +214 -0
  93. data/lib/disk/modules/VMWareDiskProbe.rb +74 -0
  94. data/lib/disk/modules/VMWareSparseDisk.rb +189 -0
  95. data/lib/disk/modules/VhdxDisk.rb +625 -0
  96. data/lib/disk/modules/VhdxDiskProbe.rb +46 -0
  97. data/lib/disk/modules/VixDiskMod.rb +54 -0
  98. data/lib/disk/modules/VixDiskProbe.rb +6 -0
  99. data/lib/disk/modules/miq_disk_cache.rb +135 -0
  100. data/lib/disk/modules/miq_dummy_disk.rb +41 -0
  101. data/lib/disk/modules/vhdx_bat_entry.rb +10 -0
  102. data/lib/disk/test.rb +66 -0
  103. data/lib/fs/MetakitFS/MetakitFS.rb +530 -0
  104. data/lib/fs/MetakitFS/test/Makefile +14 -0
  105. data/lib/fs/MetakitFS/test/MkCollectFiles.rb +165 -0
  106. data/lib/fs/MetakitFS/test/MkSelectFiles.rb +30 -0
  107. data/lib/fs/MetakitFS/test/collect_files.yaml +70 -0
  108. data/lib/fs/MetakitFS/test/init.rb +3 -0
  109. data/lib/fs/MetakitFS/test/mk2vmdk.rb +64 -0
  110. data/lib/fs/MetakitFS/test/mk4test.c +92 -0
  111. data/lib/fs/MetakitFS/test/mkFsTest.rb +113 -0
  112. data/lib/fs/MetakitFS/test/proto.rb +97 -0
  113. data/lib/fs/MiqFS/FsProbe.rb +39 -0
  114. data/lib/fs/MiqFS/MiqFS.rb +515 -0
  115. data/lib/fs/MiqFS/modules/AUFSProbe.rb +26 -0
  116. data/lib/fs/MiqFS/modules/Ext3.rb +305 -0
  117. data/lib/fs/MiqFS/modules/Ext3Probe.rb +25 -0
  118. data/lib/fs/MiqFS/modules/Ext4.rb +304 -0
  119. data/lib/fs/MiqFS/modules/Ext4Probe.rb +25 -0
  120. data/lib/fs/MiqFS/modules/Fat32.rb +318 -0
  121. data/lib/fs/MiqFS/modules/Fat32Probe.rb +30 -0
  122. data/lib/fs/MiqFS/modules/HFSProbe.rb +18 -0
  123. data/lib/fs/MiqFS/modules/Iso9660.rb +293 -0
  124. data/lib/fs/MiqFS/modules/Iso9660Probe.rb +18 -0
  125. data/lib/fs/MiqFS/modules/LocalFS.rb +105 -0
  126. data/lib/fs/MiqFS/modules/NTFS.rb +287 -0
  127. data/lib/fs/MiqFS/modules/NTFSProbe.rb +21 -0
  128. data/lib/fs/MiqFS/modules/NativeFS.rb +155 -0
  129. data/lib/fs/MiqFS/modules/ReFSProbe.rb +17 -0
  130. data/lib/fs/MiqFS/modules/RealFS.rb +79 -0
  131. data/lib/fs/MiqFS/modules/RealFSProbe.rb +6 -0
  132. data/lib/fs/MiqFS/modules/Reiser4Probe.rb +18 -0
  133. data/lib/fs/MiqFS/modules/ReiserFS.rb +315 -0
  134. data/lib/fs/MiqFS/modules/ReiserFSProbe.rb +42 -0
  135. data/lib/fs/MiqFS/modules/UnionFSProbe.rb +18 -0
  136. data/lib/fs/MiqFS/modules/WebDAV.rb +127 -0
  137. data/lib/fs/MiqFS/modules/WebDAVFile.rb +68 -0
  138. data/lib/fs/MiqFS/modules/XFS.rb +300 -0
  139. data/lib/fs/MiqFS/modules/XFSProbe.rb +26 -0
  140. data/lib/fs/MiqFS/modules/ZFSProbe.rb +18 -0
  141. data/lib/fs/MiqFS/test.rb +59 -0
  142. data/lib/fs/MiqFsUtil.rb +383 -0
  143. data/lib/fs/MiqMountManager.rb +209 -0
  144. data/lib/fs/MiqNativeMountManager.rb +101 -0
  145. data/lib/fs/MountManagerProbe.rb +29 -0
  146. data/lib/fs/ReiserFS/block.rb +209 -0
  147. data/lib/fs/ReiserFS/directory.rb +136 -0
  148. data/lib/fs/ReiserFS/directory_entry.rb +140 -0
  149. data/lib/fs/ReiserFS/file_data.rb +111 -0
  150. data/lib/fs/ReiserFS/superblock.rb +140 -0
  151. data/lib/fs/ReiserFS/utils.rb +95 -0
  152. data/lib/fs/VimDatastoreFS/VimDatastoreFS.rb +192 -0
  153. data/lib/fs/ext3/alloc_bitmap.rb +38 -0
  154. data/lib/fs/ext3/block_pointers_path.rb +130 -0
  155. data/lib/fs/ext3/directory.rb +51 -0
  156. data/lib/fs/ext3/directory_entry.rb +67 -0
  157. data/lib/fs/ext3/ex_attrib_header.rb +14 -0
  158. data/lib/fs/ext3/ex_attrib_name.rb +23 -0
  159. data/lib/fs/ext3/file_data.rb +130 -0
  160. data/lib/fs/ext3/group_descriptor_entry.rb +65 -0
  161. data/lib/fs/ext3/group_descriptor_table.rb +54 -0
  162. data/lib/fs/ext3/hash_tree_entry.rb +18 -0
  163. data/lib/fs/ext3/hash_tree_header.rb +15 -0
  164. data/lib/fs/ext3/inode.rb +228 -0
  165. data/lib/fs/ext3/posix_acl_entry.rb +29 -0
  166. data/lib/fs/ext3/posix_acl_header.rb +11 -0
  167. data/lib/fs/ext3/superblock.rb +406 -0
  168. data/lib/fs/ext3/test/tc_Ext3BlockPointersPath.rb +74 -0
  169. data/lib/fs/ext4/alloc_bitmap.rb +38 -0
  170. data/lib/fs/ext4/directory.rb +87 -0
  171. data/lib/fs/ext4/directory_entry.rb +77 -0
  172. data/lib/fs/ext4/ex_attrib_header.rb +14 -0
  173. data/lib/fs/ext4/ex_attrib_name.rb +23 -0
  174. data/lib/fs/ext4/extent.rb +35 -0
  175. data/lib/fs/ext4/extent_header.rb +40 -0
  176. data/lib/fs/ext4/extent_index.rb +33 -0
  177. data/lib/fs/ext4/group_descriptor_entry.rb +69 -0
  178. data/lib/fs/ext4/group_descriptor_table.rb +54 -0
  179. data/lib/fs/ext4/hash_tree_entry.rb +58 -0
  180. data/lib/fs/ext4/hash_tree_header.rb +35 -0
  181. data/lib/fs/ext4/inode.rb +465 -0
  182. data/lib/fs/ext4/posix_acl_entry.rb +29 -0
  183. data/lib/fs/ext4/posix_acl_header.rb +11 -0
  184. data/lib/fs/ext4/superblock.rb +412 -0
  185. data/lib/fs/fat32/boot_sect.rb +379 -0
  186. data/lib/fs/fat32/directory.rb +222 -0
  187. data/lib/fs/fat32/directory_entry.rb +540 -0
  188. data/lib/fs/fat32/file_data.rb +128 -0
  189. data/lib/fs/iso9660/boot_sector.rb +170 -0
  190. data/lib/fs/iso9660/directory.rb +90 -0
  191. data/lib/fs/iso9660/directory_entry.rb +147 -0
  192. data/lib/fs/iso9660/file_data.rb +78 -0
  193. data/lib/fs/iso9660/rock_ridge.rb +329 -0
  194. data/lib/fs/iso9660/util.rb +57 -0
  195. data/lib/fs/modules/LinuxMount.rb +300 -0
  196. data/lib/fs/modules/LinuxMountProbe.rb +29 -0
  197. data/lib/fs/modules/WinMount.rb +97 -0
  198. data/lib/fs/modules/WinMountProbe.rb +24 -0
  199. data/lib/fs/ntfs/attrib_attribute_list.rb +131 -0
  200. data/lib/fs/ntfs/attrib_bitmap.rb +26 -0
  201. data/lib/fs/ntfs/attrib_data.rb +74 -0
  202. data/lib/fs/ntfs/attrib_file_name.rb +110 -0
  203. data/lib/fs/ntfs/attrib_header.rb +194 -0
  204. data/lib/fs/ntfs/attrib_index_allocation.rb +19 -0
  205. data/lib/fs/ntfs/attrib_index_root.rb +247 -0
  206. data/lib/fs/ntfs/attrib_object_id.rb +40 -0
  207. data/lib/fs/ntfs/attrib_standard_information.rb +107 -0
  208. data/lib/fs/ntfs/attrib_type.rb +49 -0
  209. data/lib/fs/ntfs/attrib_volume_information.rb +53 -0
  210. data/lib/fs/ntfs/attrib_volume_name.rb +31 -0
  211. data/lib/fs/ntfs/boot_sect.rb +253 -0
  212. data/lib/fs/ntfs/data_run.rb +358 -0
  213. data/lib/fs/ntfs/directory_index_node.rb +114 -0
  214. data/lib/fs/ntfs/index_node_header.rb +69 -0
  215. data/lib/fs/ntfs/index_record_header.rb +85 -0
  216. data/lib/fs/ntfs/mft_entry.rb +288 -0
  217. data/lib/fs/ntfs/utils.rb +43 -0
  218. data/lib/fs/test/camcorder_fs_test.rb +108 -0
  219. data/lib/fs/test/collect_files_direct.yaml +22 -0
  220. data/lib/fs/test/collect_files_in.yaml +24 -0
  221. data/lib/fs/test/collect_files_in_nc.yaml +22 -0
  222. data/lib/fs/test/collect_files_out.yaml +6 -0
  223. data/lib/fs/test/collect_files_rm.yaml +6 -0
  224. data/lib/fs/test/copyTest.rb +126 -0
  225. data/lib/fs/test/fsTest.rb +87 -0
  226. data/lib/fs/test/updateTest.rb +184 -0
  227. data/lib/fs/xfs/allocation_group.rb +160 -0
  228. data/lib/fs/xfs/bmap_btree_block.rb +125 -0
  229. data/lib/fs/xfs/bmap_btree_record.rb +80 -0
  230. data/lib/fs/xfs/bmap_btree_root_node.rb +72 -0
  231. data/lib/fs/xfs/directory.rb +133 -0
  232. data/lib/fs/xfs/directory2_data_header.rb +27 -0
  233. data/lib/fs/xfs/directory3_data_header.rb +34 -0
  234. data/lib/fs/xfs/directory_block_tail.rb +22 -0
  235. data/lib/fs/xfs/directory_data_header.rb +46 -0
  236. data/lib/fs/xfs/directory_entry.rb +106 -0
  237. data/lib/fs/xfs/inode.rb +532 -0
  238. data/lib/fs/xfs/inode_map.rb +100 -0
  239. data/lib/fs/xfs/short_form_directory_entry.rb +91 -0
  240. data/lib/fs/xfs/short_form_header.rb +44 -0
  241. data/lib/fs/xfs/superblock.rb +556 -0
  242. data/lib/lib/tasks/azure.rake +52 -0
  243. data/lib/manageiq/smartstate/version.rb +5 -0
  244. data/lib/manageiq/smartstate.rb +7 -0
  245. data/lib/manageiq-smartstate.rb +1 -0
  246. data/lib/metadata/MIQExtract/MIQExtract.rb +297 -0
  247. data/lib/metadata/MIQExtract/test/extractTest.rb +41 -0
  248. data/lib/metadata/MIQExtract/test/full_extract_test.rb +68 -0
  249. data/lib/metadata/ScanProfile/HostScanItem.rb +4 -0
  250. data/lib/metadata/ScanProfile/HostScanProfile.rb +4 -0
  251. data/lib/metadata/ScanProfile/HostScanProfiles.rb +41 -0
  252. data/lib/metadata/ScanProfile/ScanItemBase.rb +63 -0
  253. data/lib/metadata/ScanProfile/ScanProfileBase.rb +51 -0
  254. data/lib/metadata/ScanProfile/ScanProfilesBase.rb +60 -0
  255. data/lib/metadata/ScanProfile/VmScanItem.rb +4 -0
  256. data/lib/metadata/ScanProfile/VmScanProfile.rb +4 -0
  257. data/lib/metadata/ScanProfile/VmScanProfiles.rb +38 -0
  258. data/lib/metadata/ScanProfile/modules/HostScanItemFile.rb +51 -0
  259. data/lib/metadata/ScanProfile/modules/HostScanItemNteventlog.rb +84 -0
  260. data/lib/metadata/ScanProfile/modules/VmScanItemFile.rb +39 -0
  261. data/lib/metadata/ScanProfile/modules/VmScanItemNteventlog.rb +34 -0
  262. data/lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb +64 -0
  263. data/lib/metadata/VMMount/VMMount.rb +81 -0
  264. data/lib/metadata/VMMount/VMPlatformMount.rb +18 -0
  265. data/lib/metadata/VMMount/VMPlatformMountLinux.rb +75 -0
  266. data/lib/metadata/VMMount/VMPlatformMountWin.rb +13 -0
  267. data/lib/metadata/VmConfig/GetNativeCfg.rb +45 -0
  268. data/lib/metadata/VmConfig/VmConfig.rb +947 -0
  269. data/lib/metadata/VmConfig/cfgConfig.rb +45 -0
  270. data/lib/metadata/VmConfig/ovfConfig.rb +99 -0
  271. data/lib/metadata/VmConfig/test/GetVMwareCfgTest.rb +40 -0
  272. data/lib/metadata/VmConfig/vmcConfig.rb +116 -0
  273. data/lib/metadata/VmConfig/vmtxConfig.rb +4 -0
  274. data/lib/metadata/VmConfig/vmxConfig.rb +162 -0
  275. data/lib/metadata/VmConfig/xmlConfig.rb +79 -0
  276. data/lib/metadata/VmConfig/xmlMsHyperVConfig.rb +41 -0
  277. data/lib/metadata/linux/InitProcHash.rb +632 -0
  278. data/lib/metadata/linux/LinuxInitProcs.rb +142 -0
  279. data/lib/metadata/linux/LinuxOSInfo.rb +237 -0
  280. data/lib/metadata/linux/LinuxPackages.rb +209 -0
  281. data/lib/metadata/linux/LinuxSystemd.rb +130 -0
  282. data/lib/metadata/linux/LinuxUsers.rb +289 -0
  283. data/lib/metadata/linux/LinuxUtils.rb +197 -0
  284. data/lib/metadata/linux/MiqConaryPackages.rb +41 -0
  285. data/lib/metadata/linux/MiqRpmPackages.rb +160 -0
  286. data/lib/metadata/linux/test/Name +0 -0
  287. data/lib/metadata/linux/test/Packages +0 -0
  288. data/lib/metadata/linux/test/rpoTest.rb +5 -0
  289. data/lib/metadata/linux/test/tc_LinuxUtils.rb +4157 -0
  290. data/lib/metadata/util/event_log_filter.rb +61 -0
  291. data/lib/metadata/util/md5deep.rb +280 -0
  292. data/lib/metadata/util/win32/Win32Accounts.rb +764 -0
  293. data/lib/metadata/util/win32/Win32EventLog.rb +743 -0
  294. data/lib/metadata/util/win32/Win32Services.rb +86 -0
  295. data/lib/metadata/util/win32/Win32Software.rb +326 -0
  296. data/lib/metadata/util/win32/Win32System.rb +333 -0
  297. data/lib/metadata/util/win32/boot_info_win.rb +59 -0
  298. data/lib/metadata/util/win32/fleece_hives.rb +220 -0
  299. data/lib/metadata/util/win32/ms-registry.rb +650 -0
  300. data/lib/metadata/util/win32/peheader.rb +868 -0
  301. data/lib/metadata/util/win32/remote-registry.rb +142 -0
  302. data/lib/metadata/util/win32/system_path_win.rb +103 -0
  303. data/lib/metadata/util/win32/versioninfo.rb +17 -0
  304. data/manageiq-smartstate.gemspec +35 -0
  305. metadata +486 -0
@@ -0,0 +1,194 @@
1
+ require 'binary_struct'
2
+ require 'util/miq-unicode'
3
+ require 'fs/ntfs/utils'
4
+ require 'fs/ntfs/attrib_type'
5
+
6
+ module NTFS
7
+ # Standard attribute header.
8
+ # Each attribute begins with one of these.
9
+ STANDARD_ATTRIBUTE_HEADER = BinaryStruct.new([
10
+ 'L', 'attrib_type', # The (32-bit) type of the attribute
11
+ 'L', 'length', # Byte size of the resident part of the attribute
12
+ # (aligned to 8-byte boundary). Used to get to the next attribute
13
+ 'C', 'non_resident', # If 0, attribute is resident.
14
+ # If 1, attribute is non-resident
15
+ 'C', 'name_length', # Unicode character size of name of attribute.
16
+ # 0 if unnamed
17
+ 'S', 'name_offset', # If name_length != 0, the byte offset to the beginning of the name
18
+ # from the attribute record. Note that the name is stored as a
19
+ # Unicode string.
20
+ 'S', 'flags', # Attribute flags (see AF_ below)
21
+ 'S', 'attrib_id', # The instance of this attribute record. This number is unique within this mft record
22
+ ])
23
+ SIZEOF_STANDARD_ATTRIBUTE_HEADER = STANDARD_ATTRIBUTE_HEADER.size
24
+
25
+ # The standard attribute header continues with one of the following two
26
+ # structs depending on whether the attribute is resident or non-resident.
27
+
28
+ # The resident struct.
29
+ SAH_RESIDENT = BinaryStruct.new([
30
+ 'L', 'value_length', # Byte size of attribute value
31
+ 'S', 'value_offset', # Byte offset of the attribute value from the start of the attribute record
32
+ 'C', 'resident_flags', # Flags of resident attributes (8-bit)
33
+ 'C', nil, # Reserved/alignment to 8-byte boundary
34
+ ])
35
+ SIZEOF_SAH_RESIDENT = SAH_RESIDENT.size
36
+
37
+ # The non-resident struct.
38
+ SAH_NONRESIDENT = BinaryStruct.new([
39
+ 'Q', 'first_vcn', # Lowest valid virtual cluster number for this portion of the attribute value
40
+ # or 0 if this is the only extent (usually the case). - Only when an attribute
41
+ # list is used does lowest_vcn != 0 ever occur
42
+ 'Q', 'last_vcn', # Highest valid vcn of this extent of the attribute value. - Usually there is
43
+ # only one portion, so this usually equals the attribute value size in clusters
44
+ # minus 1. Can be -1 for zero length files. Can be 0 for "single extent" attributes
45
+ 'S', 'mapping_pairs_offset', # Byte offset from the beginning of the structure to the mapping pairs array
46
+ # which contains the mappings between the vcns and the logical cluster numbers (lcns).
47
+ # When creating, place this at the end of this record header aligned to 8-byte boundary.
48
+ 'S', 'compression_unit', # The compression unit expressed as the log to the base 2 of the number of
49
+ # clusters in a compression unit. 0 means not compressed. (This effectively limits the
50
+ # compression unit size to be a power of two clusters.) WinNT4 only uses a value of 4.
51
+ 'L', nil, # Align to 8-byte boundary
52
+
53
+ # The sizes below are only used when lowest_vcn is zero, as otherwise it would
54
+ # be difficult to keep them up-to-date.
55
+
56
+ 'Q', 'allocated_size', # Byte size of disk space allocated to hold the attribute value. Always is a
57
+ # multiple of the cluster size. When a file is compressed, this field is a
58
+ # multiple of the compression block size (2^compression_unit) and it
59
+ # represents the logically allocated space rather than the actual on disk usage.
60
+ 'Q', 'data_size', # Byte size of the attribute value.
61
+ # Can be larger than allocated_size if attribute value is compressed or sparse
62
+ 'Q', 'initialized_size', # Byte size of initialized portion of the attribute value. Usually equals data_size
63
+ ])
64
+ # If the attribute is named (name_length is not 0), then the name (in UNICODE) follows here.
65
+ # Here follows the attribute data (if resident) or the data runs (if non-resident).
66
+ SIZEOF_SAH_NONRESIDENT = SAH_NONRESIDENT.size
67
+
68
+ # One Attribute Header.
69
+ class AttribHeader
70
+ attr_reader :name, :type, :typeName, :flags, :id, :length, :specific, :namelen
71
+
72
+ AF_COMPRESSED = 0x0001
73
+ AF_ENCRPYTED = 0x4000
74
+ AF_SPARSE = 0x8000
75
+
76
+ RESIDENT_ATTR_IS_INDEXED = 0x01 # Attribute is referenced in an index
77
+ # (has implications for deleting and modifying the attribute).
78
+
79
+ # NOTE: All the subordinate objects (attrib header & attributes) take
80
+ # a buffer (a packed string) starting at the start of the sub object.
81
+ def initialize(buf)
82
+ raise "MIQ(NTFS::AttribHeader.initialize) Nil buffer" if buf.nil?
83
+
84
+ # Decode standard attribute header.
85
+ @header = STANDARD_ATTRIBUTE_HEADER.decode(buf)
86
+ offset = SIZEOF_STANDARD_ATTRIBUTE_HEADER
87
+
88
+ # If type is AT_END we're done.
89
+ return nil if @header['attrib_type'] == AT_END
90
+
91
+ # Get accessor values.
92
+ @length = @header['length']
93
+ @id = @header['attrib_id']
94
+ @flags = @header['flags']
95
+ @type = @header['attrib_type']
96
+ @namelen = @header['name_length']
97
+
98
+ # Get the rest of the data (a resident or non-resident struct).
99
+ which = isResident? ? SAH_RESIDENT : SAH_NONRESIDENT
100
+ len = isResident? ? SIZEOF_SAH_RESIDENT : SIZEOF_SAH_NONRESIDENT
101
+ @specific = which.decode(buf[offset..-1])
102
+ offset += len
103
+
104
+ # If there's a name get it.
105
+ @name = buf[offset, (@namelen * 2)].UnicodeToUtf8 if @namelen != 0
106
+ end
107
+
108
+ def get_value(buf, boot_sector)
109
+ # Prep a buffer to pass to subobjects.
110
+ if isResident?
111
+ # Resident attributes are after header res struct & name.
112
+ abuf = buf[@specific['value_offset'], @specific['value_length']]
113
+ else
114
+ # Nonresident attributes are defined by data runs.
115
+ alen = @specific['data_size']
116
+ alen = buf.size if alen == 0
117
+ abuf = DataRun.new(boot_sector, buf[@specific['mapping_pairs_offset'], alen], self)
118
+ end
119
+
120
+ abuf
121
+ end
122
+
123
+ # Name will always be something, either name or N/A
124
+ def to_s
125
+ @name.nil? ? 'N/A' : @name
126
+ end
127
+
128
+ def isResident?
129
+ @header['non_resident'] == 0
130
+ end
131
+
132
+ def typeName
133
+ TypeName[@header['attrib_type']]
134
+ end
135
+
136
+ def isCompressed?
137
+ NTFS::Utils.gotBit?(@flags, AF_COMPRESSED)
138
+ end
139
+
140
+ def isEncrypted?
141
+ NTFS::Utils.gotBit?(@flags, AF_ENCRYPTED)
142
+ end
143
+
144
+ def isSparse?
145
+ NTFS::Utils.gotBit?(@flags, AF_SPARSE)
146
+ end
147
+
148
+ ######################################################################################################
149
+ # The $I30 is the a "file" name given to NTFS MFT attributes containing file
150
+ # name indexes for directories. NTFS stores the file name contents of the
151
+ # directory in several places, depending on the number of files in the directory:
152
+ #
153
+ # - For directories with just a few files, all are stored resident in the MFT entry $INDEX_ROOT
154
+ # - For directories with many files, the indexes are stored non-resident in the MFT entry $INDEX_ALLOCATION
155
+ # - The allocation status of these entries are managed by the $BITMAP MFT entry
156
+ #
157
+ # NTFS uses B-tree structures to store and quickly access the data. So, the $INDEX_ROOT attribute
158
+ # (with a name of $I30) was not large enough to store the B-tree index of file names. Instead, it
159
+ # points to index records stored in the non-resident $INDEX_ALLOCATION. Viewing the contents of that
160
+ # file, the B-tree index of file names in the directory.
161
+ ######################################################################################################
162
+ def containsFileNameIndexes?
163
+ name == "$I30"
164
+ end
165
+
166
+ def dump
167
+ out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
168
+ out << " Type : 0x#{'%08x' % @header['attrib_type']} (#{typeName})\n"
169
+ out << " Length : 0x#{'%08x' % @header['length']}\n"
170
+ out << " Non resident : 0x#{'%02x' % @header['non_resident']}\n"
171
+ out << " Name length : 0x#{'%02x' % @header['name_length']}\n"
172
+ out << " Offset to name : 0x#{'%04x' % @header['name_offset']}\n"
173
+ out << " Flags : 0x#{'%04x' % @header['flags']}\n"
174
+ out << " Attrib id : 0x#{'%04x' % @header['attrib_id']}\n"
175
+
176
+ # Further depends on type.
177
+ if self.isResident?
178
+ out << " Value length : 0x#{'%08x' % @specific['value_length']}\n"
179
+ out << " Value offset : 0x#{'%04x' % @specific['value_offset']}\n"
180
+ out << " Resident Flags : 0x#{'%02x' % @specific['resident_flags']}\n"
181
+ else
182
+ out << " First VCN : 0x#{'%016x' % @specific['first_vcn']}\n"
183
+ out << " Last VCN : 0x#{'%016x' % @specific['last_vcn']}\n"
184
+ out << " Mapping Pairs Offset: 0x#{'%04x' % @specific['mapping_pairs_offset']}\n"
185
+ out << " Compression : 0x#{'%04x' % @specific['compression_unit']}\n"
186
+ out << " Allocated size : 0x#{'%016x' % @specific['allocated_size']}\n"
187
+ out << " Data size : 0x#{'%016x' % @specific['data_size']}\n"
188
+ out << " Initialized size : 0x#{'%016x' % @specific['initialized_size']}\n"
189
+ end
190
+ out << " Name : #{@name}\n" if @header['name_length'] > 0
191
+ out << "---\n"
192
+ end
193
+ end
194
+ end # module NTFS
@@ -0,0 +1,19 @@
1
+ module NTFS
2
+ class IndexAllocation
3
+ def self.create_from_header(header, buf)
4
+ return IndexAllocation.new(buf, header) if header.containsFileNameIndexes?
5
+ $log.debug("Skipping #{header.typeName} for name <#{header.name}>") if $log
6
+ nil
7
+ end
8
+
9
+ attr_reader :data_run, :header
10
+
11
+ def initialize(buf, header)
12
+ raise "MIQ(NTFS::IndexAllocation.initialize) Buffer must be DataRun (passed #{buf.class.name})" unless buf.kind_of?(DataRun)
13
+ raise "MIQ(NTFS::IndexAllocation.initialize) Header must be AttribHeader (passed #{header.class.name})" unless header.kind_of?(NTFS::AttribHeader)
14
+
15
+ @data_run = buf
16
+ @header = header
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,247 @@
1
+ require 'binary_struct'
2
+ require 'util/miq-unicode'
3
+ require 'fs/ntfs/index_node_header'
4
+ require 'fs/ntfs/directory_index_node'
5
+ require 'fs/ntfs/index_record_header'
6
+
7
+ module NTFS
8
+ #
9
+ # INDEX_ROOT - Attribute: Index root (0x90).
10
+ #
11
+ # NOTE: Always resident.
12
+ #
13
+ # This is followed by a sequence of index entries (INDEX_ENTRY structures)
14
+ # as described by the index header.
15
+ #
16
+ # When a directory is small enough to fit inside the index root then this
17
+ # is the only attribute describing the directory. When the directory is too
18
+ # large to fit in the index root, on the other hand, two additional attributes
19
+ # are present: an index allocation attribute, containing sub-nodes of the B+
20
+ # directory tree (see below), and a bitmap attribute, describing which virtual
21
+ # cluster numbers (vcns) in the index allocation attribute are in use by an
22
+ # index block.
23
+ #
24
+ # NOTE: The root directory (FILE_root) contains an entry for itself. Other
25
+ # directories do not contain entries for themselves, though.
26
+ #
27
+
28
+ ATTRIB_INDEX_ROOT = BinaryStruct.new([
29
+ 'L', 'type', # Type of the indexed attribute. Is FILE_NAME for directories, zero
30
+ # for view indexes. No other values allowed.
31
+ 'L', 'collation_rule', # Collation rule used to sort the index entries. If type is $FILE_NAME,
32
+ # this must be COLLATION_FILE_NAME
33
+ 'L', 'index_block_size', # Size of index block in bytes (in the index allocation attribute)
34
+ 'C', 'clusters_per_index_block', # Size of index block in clusters (in the index allocation attribute),
35
+ # when an index block is >= than a cluster, otherwise sectors per index block
36
+ 'a3', nil, # Reserved/align to 8-byte boundary
37
+ ])
38
+ # Here follows a node header.
39
+ SIZEOF_ATTRIB_INDEX_ROOT = ATTRIB_INDEX_ROOT.size
40
+
41
+ class IndexRoot
42
+ DEBUG_TRACE_FIND = false && $log
43
+
44
+ CT_BINARY = 0x00000000 # Binary compare, MSB is first (does that mean big endian?)
45
+ CT_FILENAME = 0x00000001 # UNICODE strings.
46
+ CT_UNICODE = 0x00000002 # UNICODE, upper case first.
47
+ CT_ULONG = 0x00000010 # Standard ULONG, 32-bits little endian.
48
+ CT_SID = 0x00000011 # Security identifier.
49
+ CT_SECHASH = 0x00000012 # First security hash, then security identifier.
50
+ CT_ULONGS = 0x00000013 # Set of ULONGS? (doc is unclear - indicates GUID).
51
+
52
+ def self.create_from_header(header, buf, bs)
53
+ return IndexRoot.new(buf, bs) if header.containsFileNameIndexes?
54
+ $log.debug("Skipping #{header.typeName} for name <#{header.name}>") if $log
55
+ nil
56
+ end
57
+
58
+ attr_reader :type, :nodeHeader, :index, :indexAlloc
59
+
60
+ def initialize(buf, boot_sector)
61
+ log_prefix = "MIQ(NTFS::IndexRoot.initialize)"
62
+
63
+ raise "#{log_prefix} Nil buffer" if buf.nil?
64
+ raise "#{log_prefix} Nil boot sector" if boot_sector.nil?
65
+
66
+ buf = buf.read(buf.length) if buf.kind_of?(DataRun)
67
+ @air = ATTRIB_INDEX_ROOT.decode(buf)
68
+ buf = buf[SIZEOF_ATTRIB_INDEX_ROOT..-1]
69
+
70
+ # Get accessor data.
71
+ @type = @air['type']
72
+ @collation_rule = @air['collation_rule']
73
+ @byteSize = @air['index_block_size']
74
+ @clusterSize = @air['size_of_index_clus']
75
+
76
+ @boot_sector = boot_sector
77
+
78
+ # Get node header & index.
79
+ @foundEntries = {}
80
+ @indexNodeHeader = IndexNodeHeader.new(buf)
81
+ @indexEntries = cleanAllocEntries(DirectoryIndexNode.nodeFactory(buf[@indexNodeHeader.startEntries..-1]))
82
+ @indexAlloc = {}
83
+ end
84
+
85
+ def to_s
86
+ @type.to_s
87
+ end
88
+
89
+ def allocations=(indexAllocations)
90
+ @indexAllocRuns = []
91
+ if @indexNodeHeader.hasChildren? && indexAllocations
92
+ indexAllocations.each { |alloc| @indexAllocRuns << [alloc.header, alloc.data_run] }
93
+ end
94
+ @indexAllocRuns
95
+ end
96
+
97
+ def bitmap=(bmp)
98
+ if @indexNodeHeader.hasChildren?
99
+ @bitmap = bmp.data.unpack("b#{bmp.length * 8}") unless bmp.nil?
100
+ end
101
+
102
+ @bitmap
103
+ end
104
+
105
+ # Find a name in this index.
106
+ def find(name)
107
+ log_prefix = "MIQ(NTFS::IndexRoot.find)"
108
+
109
+ name = name.downcase
110
+ $log.debug "#{log_prefix} Searching for [#{name}]" if DEBUG_TRACE_FIND
111
+ if @foundEntries.key?(name)
112
+ $log.debug "#{log_prefix} Found [#{name}] (cached)" if DEBUG_TRACE_FIND
113
+ return @foundEntries[name]
114
+ end
115
+
116
+ found = findInEntries(name, @indexEntries)
117
+ if found.nil?
118
+ # Fallback to full directory search if not found
119
+ $log.debug "#{log_prefix} [#{name}] not found. Performing full directory scan." if $log
120
+ found = findBackup(name)
121
+ $log.send(found.nil? ? :debug : :warn, "#{log_prefix} [#{name}] #{found.nil? ? "not " : ""}found in full directory scan.") if $log
122
+ end
123
+ found
124
+ end
125
+
126
+ # Return all names in this index as a sorted string array.
127
+ def globNames
128
+ @globNames = globEntries.collect { |e| e.namespace == NTFS::FileName::NS_DOS ? nil : e.name.downcase }.compact if @globNames.nil?
129
+ @globNames
130
+ end
131
+
132
+ def findInEntries(name, entries)
133
+ log_prefix = "MIQ(NTFS::IndexRoot.findInEntries)"
134
+
135
+ if @foundEntries.key?(name)
136
+ $log.debug "#{log_prefix} Found [#{name}] in #{entries.collect { |e| e.isLast? ? "**last**" : e.name.downcase }.inspect}" if DEBUG_TRACE_FIND
137
+ return @foundEntries[name]
138
+ end
139
+
140
+ $log.debug "#{log_prefix} Searching for [#{name}] in #{entries.collect { |e| e.isLast? ? "**last**" : e.name.downcase }.inspect}" if DEBUG_TRACE_FIND
141
+ # TODO: Uses linear search within an index entry; switch to more performant search eventually
142
+ entries.each do |e|
143
+ $log.debug "#{log_prefix} before [#{e.isLast? ? "**last**" : e.name.downcase}]" if DEBUG_TRACE_FIND
144
+ if e.isLast? || name < e.name.downcase
145
+ $log.debug "#{log_prefix} #{e.hasChild? ? "Sub-search in child vcn [#{e.child}]" : "No sub-search"}" if DEBUG_TRACE_FIND
146
+ return e.hasChild? ? findInEntries(name, getIndexAllocEntries(e.child)) : nil
147
+ end
148
+ end
149
+ $log.debug "#{log_prefix} Did not find [#{name}]" if DEBUG_TRACE_FIND
150
+ nil
151
+ end
152
+
153
+ def findBackup(name)
154
+ globEntriesByName[name]
155
+ end
156
+
157
+ def getIndexAllocEntries(vcn)
158
+ unless @indexAlloc.key?(vcn)
159
+ log_prefix = "MIQ(NTFS::IndexRoot.getIndexAllocEntries)"
160
+
161
+ begin
162
+ raise "not allocated" if @bitmap[vcn, 1] == "0"
163
+ header, run = @indexAllocRuns.detect { |h, _r| vcn >= h.specific['first_vcn'] && vcn <= h.specific['last_vcn'] }
164
+ raise "header not found" if header.nil?
165
+ raise "run not found" if run.nil?
166
+
167
+ run.seekToVcn(vcn - header.specific['first_vcn'])
168
+ buf = run.read(@byteSize)
169
+
170
+ raise "buffer not found" if buf.nil?
171
+ raise "buffer signature is expected to be INDX, but is [#{buf[0, 4].inspect}]" if buf[0, 4] != "INDX"
172
+ irh = IndexRecordHeader.new(buf, @boot_sector.bytesPerSector)
173
+ buf = irh.data[IndexRecordHeader.size..-1]
174
+ inh = IndexNodeHeader.new(buf)
175
+ @indexAlloc[vcn] = cleanAllocEntries(DirectoryIndexNode.nodeFactory(buf[inh.startEntries..-1]))
176
+ rescue => err
177
+ $log.warn "#{log_prefix} Unable to read data from index allocation at vcn [#{vcn}] because <#{err.message}>\n#{dump}" if $log
178
+ @indexAlloc[vcn] = []
179
+ end
180
+ end
181
+
182
+ @indexAlloc[vcn]
183
+ end
184
+
185
+ def cleanAllocEntries(entries)
186
+ cleanEntries = []
187
+ entries.each do |e|
188
+ if e.isLast? || !(e.contentLen == 0 || (e.refMft[1] < 12 && e.name[0, 1] == "$"))
189
+ cleanEntries << e
190
+ # Since we are already looping through all entries to clean
191
+ # them we can store them in a lookup for optimization
192
+ @foundEntries[e.name.downcase] = e unless e.isLast?
193
+ end
194
+ end
195
+ cleanEntries
196
+ end
197
+
198
+ def globEntries
199
+ return @globEntries unless @globEntries.nil?
200
+
201
+ # Since we are reading all entries, retrieve all of the data in one call
202
+ @indexAllocRuns.each do |_h, r|
203
+ r.rewind
204
+ r.read(r.length)
205
+ end
206
+
207
+ @globEntries = globAllEntries(@indexEntries)
208
+ end
209
+
210
+ def globEntriesByName
211
+ log_prefix = "MIQ(NTFS::IndexRoot.globEntriesByName)"
212
+
213
+ if @globbedEntriesByName
214
+ $log.debug "#{log_prefix} Using cached globEntries." if DEBUG_TRACE_FIND
215
+ return @foundEntries
216
+ end
217
+
218
+ $log.debug "#{log_prefix} Initializing globEntries:" if DEBUG_TRACE_FIND
219
+ globEntries.each do |e|
220
+ $log.debug "#{log_prefix} #{e.isLast? ? "**last**" : e.name.downcase}" if DEBUG_TRACE_FIND
221
+ @foundEntries[e.name.downcase] = e
222
+ end
223
+ @globbedEntriesByName = true
224
+ @foundEntries
225
+ end
226
+
227
+ def globAllEntries(entries)
228
+ ret = []
229
+ entries.each do |e|
230
+ ret += globAllEntries(getIndexAllocEntries(e.child)) if e.hasChild?
231
+ ret << e unless e.isLast?
232
+ end
233
+ ret
234
+ end
235
+
236
+ def dump
237
+ out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
238
+ out << " Type : 0x#{'%08x' % @type}\n"
239
+ out << " Collation Rule : #{@collation_rule}\n"
240
+ out << " Index size (bytes) : #{@byteSize}\n"
241
+ out << " Index size (clusters): #{@clusterSize}\n"
242
+ @indexEntries.each { |din| out << din.dump }
243
+ out << "---\n"
244
+ out
245
+ end
246
+ end
247
+ end # module NTFS
@@ -0,0 +1,40 @@
1
+ require 'util/miq-uuid'
2
+
3
+ module NTFS
4
+ # There is no real data definition for this class - it consists entirely of GUIDs.
5
+ #
6
+ # struct GUID - GUID structures store globally unique identifiers (GUID).
7
+ #
8
+ # A GUID is a 128-bit value consisting of one group of eight hexadecimal
9
+ # digits, followed by three groups of four hexadecimal digits each, followed
10
+ # by one group of twelve hexadecimal digits. GUIDs are Microsoft's
11
+ # implementation of the distributed computing environment (DCE) universally
12
+ # unique identifier (UUID).
13
+ #
14
+ # Example of a GUID:
15
+ # 1F010768-5A73-BC91-0010-A52216A7227B
16
+ #
17
+
18
+ class ObjectId
19
+ attr_reader :objectId, :birthVolumeId, :birthObjectId, :domainId
20
+
21
+ def initialize(buf)
22
+ raise "MIQ(NTFS::ObjectId.initialize) Nil buffer" if buf.nil?
23
+ buf = buf.read(buf.length) if buf.kind_of?(DataRun)
24
+ len = 16
25
+ @objectId = UUIDTools::UUID.parse_raw(buf[len * 0, len])
26
+ @birthVolumeId = UUIDTools::UUID.parse_raw(buf[len * 1, len]) if buf.length > 16
27
+ @birthObjectId = UUIDTools::UUID.parse_raw(buf[len * 2, len]) if buf.length > 16
28
+ @domainId = UUIDTools::UUID.parse_raw(buf[len * 3, len]) if buf.length > 16
29
+ end
30
+
31
+ def dump
32
+ out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
33
+ out << " Object id : #{@objectId}\n"
34
+ out << " Birth volume id: #{@birthVolumeId}\n"
35
+ out << " Birth object id: #{@birthObjectId}\n"
36
+ out << " Domain id : #{@domainId}\n"
37
+ out << "---\n"
38
+ end
39
+ end
40
+ end # module NTFS
@@ -0,0 +1,107 @@
1
+ require 'util/win32/nt_util'
2
+ require 'binary_struct'
3
+
4
+ module NTFS
5
+ #
6
+ # STANDARD_INFORMATION - Attribute: Standard information (0x10).
7
+ #
8
+ # NOTE: Always resident.
9
+ # NOTE: Present in all base file records on a volume.
10
+ # NOTE: There is conflicting information about the meaning of each of the time
11
+ # fields but the meaning as defined below has been verified to be
12
+ # correct by practical experimentation on Windows NT4 SP6a and is hence
13
+ # assumed to be the one and only correct interpretation.
14
+ #
15
+
16
+ ATTRIB_STANDARD_INFORMATION = BinaryStruct.new([
17
+ 'Q', 'time_created', # Time file was created. Updated when a filename is changed(?)
18
+ 'Q', 'time_altered', # Time the data attribute was last modified
19
+ 'Q', 'time_mft_changed', # Time this mft record was last modified
20
+ 'Q', 'time_read', # Approximate time when the file was last accessed (obviously
21
+ # this is not updated on read-only volumes). In Windows this
22
+ # is only updated when accessed if some time delta has passed
23
+ # since the last update. Also, last access times updates can be
24
+ # disabled altogether for speed
25
+ 'L', 'dos_permissions', # These are the flags we know as 'attributes' (see FP_ below)
26
+
27
+ #
28
+ # If a volume has been upgraded from a previous NTFS version, then thes following
29
+ # fields are present only if the file has been accessed since the upgrade.
30
+ # Recognize the difference by comparing the length of the resident attribute
31
+ # value. If it is 48, then the following fields are missing. If it is 72 then
32
+ # the fields are present. Maybe just check like this:
33
+ # if (resident.ValueLength < sizeof(STANDARD_INFORMATION)) {
34
+ # Assume NTFS 1.2- format.
35
+ # If (volume version is 3.0+)
36
+ # Upgrade attribute to NTFS 3.0 format.
37
+ # else
38
+ # Use NTFS 1.2- format for access.
39
+ # } else
40
+ # Use NTFS 3.0 format for access.
41
+ # Only problem is that it might be legal to set the length of the value to
42
+ # arbitrarily large values thus spoiling this check. - But chkdsk probably
43
+ # views that as a corruption, assuming that it behaves like this for all
44
+ # attributes.
45
+ #
46
+
47
+ 'L', 'max_versions', # Maximum allowed versions for file. Zero if version numbering is disabled.
48
+ 'L', 'ver_num', # This file's version (if any). Set to zero if maximum_versions is zero
49
+ 'L', 'class_id', # Class id from bidirectional class id index (?)
50
+ 'L', 'owner_id', # Owner_id of the user owning the file. Translate via $Q index
51
+ # in FILE_Extend /$Quota to the quota control entry for the user
52
+ # owning the file. Zero if quotas are disabled.
53
+ 'L', 'security_id', # This is a key in the $SII index and the $SDS data stream in the file $Secure
54
+ 'Q', 'quota_charged', # Number of bytes this file uses from the user's quota - total size of all streams - if zero then quotas are disabled
55
+ 'Q', 'update_seq_num', # This is a direct index into the file $UsnJrnl - if zero then the USN journal is disabled
56
+ ])
57
+
58
+ # One $STANDARD_INFORMATION attribute.
59
+ class StandardInformation
60
+ attr_reader :mTime, :aTime, :cTime, :permissions
61
+
62
+ # 'DOS' File permissions.
63
+ FP_READONLY = 0x00000001
64
+ FP_HIDDEN = 0x00000002
65
+ FP_SYSTEM = 0x00000004
66
+ FP_ARCHIVE = 0x00000020
67
+ FP_DEVICE = 0x00000040
68
+ FP_NORMAL = 0x00000080
69
+ FP_TEMPORARY = 0x00000100
70
+ FP_SPARSE = 0x00000200
71
+ FP_REPARSE = 0x00000400
72
+ FP_COMPRESSED = 0x00000800
73
+ FP_OFFLINE = 0x00001000
74
+ FP_NOTINDEXED = 0x00002000
75
+ FP_ENCRYPTED = 0x00004000
76
+ FP_DIRECTORY = 0x10000000
77
+ FP_INDEXVIEW = 0x20000000
78
+
79
+ def initialize(buf)
80
+ raise "MIQ(NTFS::StandardInformation.initialize) Nil buffer" if buf.nil?
81
+
82
+ buf = buf.read(buf.length) if buf.kind_of?(DataRun)
83
+ @asi = ATTRIB_STANDARD_INFORMATION.decode(buf)
84
+ @mTime = NtUtil.nt_filetime_to_ruby_time(@asi['time_altered'])
85
+ @aTime = NtUtil.nt_filetime_to_ruby_time(@asi['time_read'])
86
+ @cTime = NtUtil.nt_filetime_to_ruby_time(@asi['time_created'])
87
+ @permissions = @asi['dos_permissions']
88
+ end
89
+
90
+ def dump
91
+ out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
92
+ out << " Time created : #{@cTime}\n"
93
+ out << " Time altered : #{@mTime}\n"
94
+ out << " Time mft changed: #{NtUtil.nt_filetime_to_ruby_time(@asi['time_mft_changed'])}\n"
95
+ out << " Time read : #{@aTime}\n"
96
+ out << " Permissions : 0x#{'%08x' % @permissions}\n"
97
+ out << " Max versions : #{@asi['max_versions']}\n"
98
+ out << " Version number : #{@asi['ver_num']}\n"
99
+ out << " Class id : #{@asi['class_id']}\n"
100
+ out << " Owner id : #{@asi['owner_id']}\n"
101
+ out << " Security id : #{@asi['security_id']}\n"
102
+ out << " Quota charged : #{@asi['quota_charged']}\n"
103
+ out << " Update seq num : #{@asi['update_seq_num']}\n"
104
+ out << "---\n"
105
+ end
106
+ end
107
+ end # module NTFS
@@ -0,0 +1,49 @@
1
+ module NTFS
2
+ # The _ATTRIB_TYPE enumeration.
3
+ # Every entry in the MFT is made of a list of attributes. These are the attrib types.
4
+ AT_STANDARD_INFORMATION = 0x00000010 # Base data: MAC times, version, owner, security, quota, permissions
5
+ AT_ATTRIBUTE_LIST = 0x00000020 # Used for a list of attributes that spans one MFT file record
6
+ AT_FILE_NAME = 0x00000030 # MAC times, size, flags, (and of course) file name
7
+ AT_VOLUME_VERSION = 0x00000040 # No information
8
+ AT_OBJECT_ID = 0x00000040 # Object GUID, birth GUIDs & domain GUID
9
+ AT_SECURITY_DESCRIPTOR = 0x00000050 # User & Group SIDs, system and descr ACLs
10
+ AT_VOLUME_NAME = 0x00000060 # Vol name (label)
11
+ AT_VOLUME_INFORMATION = 0x00000070 # Major, minor & flags (chkdsk & others)
12
+ AT_DATA = 0x00000080 # File data, aux stream data
13
+ AT_INDEX_ROOT = 0x00000090 # Root of an index - usually root of directory
14
+ AT_INDEX_ALLOCATION = 0x000000a0 # Larger index structures use index allocation for overflow
15
+ AT_BITMAP = 0x000000b0 # Cluster allocation bitmap
16
+ AT_SYMBOLIC_LINK = 0x000000c0 # Haven't seen it yet
17
+ AT_REPARSE_POINT = 0x000000c0 # Reparse data
18
+ AT_EA_INFORMATION = 0x000000d0 # Extended attribute information
19
+ AT_EA = 0x000000e0 # Extended attribute data
20
+ AT_PROPERTY_SET = 0x000000f0 # Haven't seen it
21
+ AT_LOGGED_UTILITY_STREAM = 0x00000100 # Encrypted File System data
22
+ AT_END = 0xffffffff # End of attributes
23
+
24
+ # OBSOLETE TYPES
25
+ # AT_VOLUME_VERSION and AT_SYMBOLIC_LINK have been depreciated, but remain in the type constants for
26
+ # backward compatibility. The name hash can't contain them since the type is used as a key.
27
+
28
+ # NT names for the attributes.
29
+ TypeName = {
30
+ AT_STANDARD_INFORMATION => '$STANDARD_INFORMATION',
31
+ AT_ATTRIBUTE_LIST => '$ATTRIBUTE_LIST',
32
+ AT_FILE_NAME => '$FILE_NAME',
33
+ # AT_VOLUME_VERSION => '$VOLUME_VERSION', # This type is depreciated.
34
+ AT_OBJECT_ID => '$OBJECT_ID',
35
+ AT_SECURITY_DESCRIPTOR => '$SECURITY_DESCRIPTOR',
36
+ AT_VOLUME_NAME => '$VOLUME_NAME',
37
+ AT_VOLUME_INFORMATION => '$VOLUME_INFORMATION',
38
+ AT_DATA => '$DATA',
39
+ AT_INDEX_ROOT => '$INDEX_ROOT',
40
+ AT_INDEX_ALLOCATION => '$INDEX_ALLOCATION',
41
+ AT_BITMAP => '$BITMAP',
42
+ # AT_SYMBOLIC_LINK => '$SYMBOLIC_LINK', # This type is depreciated.
43
+ AT_REPARSE_POINT => '$REPARSE_POINT',
44
+ AT_EA_INFORMATION => '$EA_INFORMATION',
45
+ AT_EA => '$EA',
46
+ AT_PROPERTY_SET => '$PROPERTY_SET',
47
+ AT_LOGGED_UTILITY_STREAM => '$LOGGED_UTILITY_STREAM'
48
+ }
49
+ end # module NTFS