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,412 @@
1
+ # encoding: US-ASCII
2
+
3
+ require 'fs/ext4/group_descriptor_table'
4
+ require 'fs/ext4/inode'
5
+
6
+ require 'binary_struct'
7
+ require 'util/miq-uuid'
8
+ require 'stringio'
9
+ require 'memory_buffer'
10
+
11
+ require 'rufus/lru'
12
+
13
+ module Ext4
14
+ # ////////////////////////////////////////////////////////////////////////////
15
+ # // Data definitions. Linux 2.6.2 from Fedora Core 6.
16
+
17
+ SUPERBLOCK = BinaryStruct.new([
18
+ 'L', 'num_inodes', # Number of inodes in file system.
19
+ 'L', 'num_blocks', # Number of blocks in file system.
20
+ 'L', 'reserved_blocks', # Number of reserved blocks to prevent file system from filling up.
21
+ 'L', 'unallocated_blocks', # Number of unallocated blocks.
22
+ 'L', 'unallocated_inodes', # Number of unallocated inodes.
23
+ 'L', 'block_group_zero', # Block where block group 0 starts.
24
+ 'L', 'block_size', # Block size (saved as num bits to shift 1024 left).
25
+ 'L', 'fragment_size', # Fragment size (saved as num bits to shift 1024 left).
26
+ 'L', 'blocks_in_group', # Number of blocks in each block group.
27
+ 'L', 'fragments_in_group', # Number of fragments in each block group.
28
+ 'L', 'inodes_in_group', # Number of inodes in each block group.
29
+ 'L', 'last_mount_time', # Time FS was last mounted.
30
+ 'L', 'last_write_time', # Time FS was last written to.
31
+ 'S', 'mount_count', # Current mount count.
32
+ 'S', 'max_mount_count', # Maximum mount count.
33
+ 'S', 'signature', # Always 0xef53
34
+ 'S', 'fs_state', # File System State: see FSS_ below.
35
+ 'S', 'err_method', # Error Handling Method: see EHM_ below.
36
+ 'S', 'ver_minor', # Minor version number.
37
+ 'L', 'last_check_time', # Last consistency check time.
38
+ 'L', 'forced_check_int', # Forced check interval.
39
+ 'L', 'creator_os', # Creator OS: see CO_ below.
40
+ 'L', 'ver_major', # Major version: see MV_ below.
41
+ 'S', 'uid_res_blocks', # UID that can use reserved blocks.
42
+ 'S', 'gid_res_blocks', # GID that can uss reserved blocks.
43
+ # Begin dynamic version fields
44
+ 'L', 'first_inode', # First non-reserved inode in file system.
45
+ 'S', 'inode_size', # Size of each inode.
46
+ 'S', 'block_group', # Block group that this superblock is part of (if backup copy).
47
+ 'L', 'compat_flags', # Compatible feature flags (see CFF_ below).
48
+ 'L', 'incompat_flags', # Incompatible feature flags (see ICF_ below).
49
+ 'L', 'ro_flags', # Read Only feature flags (see ROF_ below).
50
+ 'a16', 'fs_id', # File system ID (UUID or GUID).
51
+ 'a16', 'vol_name', # Volume name.
52
+ 'a64', 'last_mnt_path', # Path where last mounted.
53
+ 'L', 'algo_use_bmp', # Algorithm usage bitmap.
54
+ # Performance hints
55
+ 'C', 'file_prealloc_blks', # Blocks to preallocate for files.
56
+ 'C', 'dir_prealloc_blks', # Blocks to preallocate for directories.
57
+ 'S', 'unused1', # Unused.
58
+ # Journal support
59
+ 'a16', 'jrnl_id', # Joural ID (UUID or GUID).
60
+ 'L', 'jrnl_inode', # Journal inode.
61
+ 'L', 'jrnl_device', # Journal device.
62
+ 'L', 'orphan_head', # Head of orphan inode list.
63
+ 'a16', 'hash_seed', # HTREE hash seed. This is actually L4 (__u32 s_hash_seed[4])
64
+ 'C', 'hash_ver', # Default hash version.
65
+ 'C', 'unused2',
66
+ 'S', 'group_desc_size', # Group descriptor size.
67
+ 'L', 'mount_opts', # Default mount options.
68
+ 'L', 'first_meta_blk_grp', # First metablock block group.
69
+ 'a360', 'reserved' # Unused.
70
+ ])
71
+
72
+ SUPERBLOCK_SIG = 0xef53
73
+ SUPERBLOCK_OFFSET = 1024
74
+ SUPERBLOCK_SIZE = 1024
75
+ GDE_SIZE = 32 # default group descriptor size.
76
+ INODE_SIZE = 128 # Default inode size.
77
+
78
+ # ////////////////////////////////////////////////////////////////////////////
79
+ # // Class.
80
+
81
+ class Superblock
82
+ # Default cache sizes.
83
+ DEF_BLOCK_CACHE_SIZE = 50
84
+ DEF_INODE_CACHE_SIZE = 50
85
+
86
+ # File System State.
87
+ FSS_CLEAN = 0x0001 # File system is clean.
88
+ FSS_ERR = 0x0002 # File system has errors.
89
+ FSS_ORPHAN_REC = 0x0004 # Orphan inodes are being recovered.
90
+ # NOTE: Recovered NOT by this software but by the 'NIX kernel.
91
+ # IOW start the VM to repair it.
92
+ FSS_END = FSS_CLEAN | FSS_ERR | FSS_ORPHAN_REC
93
+
94
+ # Error Handling Method.
95
+ EHM_CONTINUE = 1 # No action.
96
+ EHM_RO_REMOUNT = 2 # Remount file system as read only.
97
+ EHM_PANIC = 3 # Don't mount? halt? - don't know what this means.
98
+
99
+ # Creator OS.
100
+ CO_LINUX = 0 # NOTE: FS creation tools allow setting this value.
101
+ CO_GNU_HURD = 1 # These values are supposedly defined.
102
+ CO_MASIX = 2
103
+ CO_FREE_BSD = 3
104
+ CO_LITES = 4
105
+
106
+ # Major Version.
107
+ MV_ORIGINAL = 0 # NOTE: If version is not dynamic, then values from
108
+ MV_DYNAMIC = 1 # first_inode on may not be accurate.
109
+
110
+ # Compatible Feature Flags.
111
+ CFF_PREALLOC_DIR_BLKS = 0x0001 # Preallocate directory blocks to reduce fragmentation.
112
+ CFF_AFS_SERVER_INODES = 0x0002 # AFS server inodes exist in system.
113
+ CFF_JOURNAL = 0x0004 # File system has journal (Ext3).
114
+ CFF_EXTENDED_ATTRIBS = 0x0008 # Inodes have extended attributes.
115
+ CFF_BIG_PART = 0x0010 # File system can resize itself for larger partitions.
116
+ CFF_HASH_INDEX = 0x0020 # Directories use hash index (another modified b-tree).
117
+ CFF_FLAGS = (CFF_PREALLOC_DIR_BLKS | CFF_AFS_SERVER_INODES | CFF_JOURNAL | CFF_EXTENDED_ATTRIBS | CFF_BIG_PART | CFF_HASH_INDEX)
118
+
119
+ # Incompatible Feature flags.
120
+ ICF_COMPRESSION = 0x0001 # Not supported on Linux?
121
+ ICF_FILE_TYPE = 0x0002 # Directory entries contain file type field.
122
+ ICF_RECOVER_FS = 0x0004 # File system needs recovery.
123
+ ICF_JOURNAL = 0x0008 # File system uses journal device.
124
+ ICF_META_BG = 0x0010 #
125
+ ICF_EXTENTS = 0x0040 # File system uses extents (ext4)
126
+ ICF_64BIT = 0x0080 # File system uses 64-bit
127
+ ICF_MMP = 0x0100 #
128
+ ICF_FLEX_BG = 0x0200 #
129
+ ICF_EA_INODE = 0x0400 # EA in inode
130
+ ICF_DIRDATA = 0x1000 # data in dirent
131
+ ICF_FLAGS = (ICF_COMPRESSION | ICF_FILE_TYPE | ICF_RECOVER_FS | ICF_JOURNAL | ICF_META_BG | ICF_EXTENTS | ICF_64BIT | ICF_MMP | ICF_FLEX_BG | ICF_EA_INODE | ICF_DIRDATA)
132
+
133
+ # ReadOnly Feature flags.
134
+ ROF_SPARSE = 0x0001 # Sparse superblocks & group descriptor tables.
135
+ ROF_LARGE_FILES = 0x0002 # File system contains large files (over 4G).
136
+ ROF_BTREES = 0x0004 # Directories use B-Trees (not implemented?).
137
+ ROF_HUGE_FILE = 0x0008 #
138
+ ROF_GDT_CSUM = 0x0010 #
139
+ ROF_DIR_NLINK = 0x0020 #
140
+ ROF_EXTRA_ISIZE = 0x0040 #
141
+ ROF_FLAGS = (ROF_SPARSE | ROF_LARGE_FILES | ROF_BTREES | ROF_HUGE_FILE | ROF_GDT_CSUM | ROF_DIR_NLINK | ROF_EXTRA_ISIZE)
142
+
143
+ # /////////////////////////////////////////////////////////////////////////
144
+ # // initialize
145
+ attr_reader :numGroups, :fsId, :stream, :numBlocks, :numInodes, :fsId, :volName
146
+ attr_reader :sectorSize, :blockSize, :groupDescriptorSize
147
+
148
+ @@track_inodes = false
149
+
150
+ def initialize(stream)
151
+ raise "Ext4::Superblock.initialize: Nil stream" if stream.nil?
152
+ @stream = stream
153
+
154
+ # Seek, read & decode the superblock structure
155
+ @stream.seek(SUPERBLOCK_OFFSET)
156
+ @sb = SUPERBLOCK.decode(@stream.read(SUPERBLOCK_SIZE))
157
+
158
+ # Grab some quick facts & make sure there's nothing wrong. Tight qualification.
159
+ raise "Ext4::Superblock.initialize: Invalid signature=[#{@sb['signature']}]" if @sb['signature'] != SUPERBLOCK_SIG
160
+ state = @sb['fs_state']
161
+ raise "Ext4::Superblock.initialize: Invalid file system state" if state > FSS_END
162
+ if state != FSS_CLEAN
163
+ $log.warn("Ext4 file system has errors") if $log && gotBit?(state, FSS_ERR)
164
+ $log.warn("Ext4 orphan inodes being recovered") if $log && gotBit?(state, FSS_ORPHAN_REC)
165
+ end
166
+ raise "Ext4::Superblock.initialize: Invalid error handling method=[#{@sb['err_method']}]" if @sb['err_method'] > EHM_PANIC
167
+
168
+ @blockSize = 1024 << @sb['block_size']
169
+
170
+ @block_cache = LruHash.new(DEF_BLOCK_CACHE_SIZE)
171
+ @inode_cache = LruHash.new(DEF_INODE_CACHE_SIZE)
172
+
173
+ # expose for testing.
174
+ @numBlocks = @sb['num_blocks']
175
+ @numInodes = @sb['num_inodes']
176
+
177
+ # Inode file size members can't be trusted, so use sector count instead.
178
+ # MiqDisk exposes blockSize, which for our purposes is sectorSize.
179
+ @sectorSize = @stream.blockSize
180
+
181
+ # Preprocess some members.
182
+ @sb['vol_name'].delete!("\000")
183
+ @sb['last_mnt_path'].delete!("\000")
184
+ @numGroups, @lastGroupBlocks = @sb['num_blocks'].divmod(@sb['blocks_in_group'])
185
+ @numGroups += 1 if @lastGroupBlocks > 0
186
+ @fsId = UUIDTools::UUID.parse_raw(@sb['fs_id'])
187
+ @volName = @sb['vol_name']
188
+ @jrnlId = UUIDTools::UUID.parse_raw(@sb['jrnl_id'])
189
+ end
190
+
191
+ # ////////////////////////////////////////////////////////////////////////////
192
+ # // Class helpers & accessors.
193
+
194
+ def gdt
195
+ @gdt ||= GroupDescriptorTable.new(self)
196
+ end
197
+
198
+ def isDynamic?
199
+ @sb['ver_major'] == MV_DYNAMIC
200
+ end
201
+
202
+ def isNewDirEnt?
203
+ gotBit?(@sb['incompat_flags'], ICF_FILE_TYPE)
204
+ end
205
+
206
+ def fragmentSize
207
+ 1024 << @sb['fragment_size']
208
+ end
209
+
210
+ def blocksPerGroup
211
+ @sb['blocks_in_group']
212
+ end
213
+
214
+ def fragmentsPerGroup
215
+ @sb['fragments_in_group']
216
+ end
217
+
218
+ def inodesPerGroup
219
+ @sb['inodes_in_group']
220
+ end
221
+
222
+ def inodeSize
223
+ isDynamic? ? @sb['inode_size'] : INODE_SIZE
224
+ end
225
+
226
+ def is_enabled_64_bit?
227
+ @is_enabled_64_bit ||= gotBit?(@sb['incompat_flags'], ICF_64BIT)
228
+ end
229
+
230
+ def groupDescriptorSize
231
+ @groupDescriptorSize ||= is_enabled_64_bit? ? @sb['group_desc_size'] : GDE_SIZE
232
+ end
233
+
234
+ def freeBytes
235
+ @sb['unallocated_blocks'] * @blockSize
236
+ end
237
+
238
+ def blockNumToGroupNum(block)
239
+ unless block.kind_of?(Numeric)
240
+ $log.error("Ext4::Superblock.blockNumToGroupNum called from: #{caller.join('\n')}")
241
+ raise "Ext4::Superblock.blockNumToGroupNum: block is expected to be numeric, but is <#{block.class.name}>"
242
+ end
243
+ group = (block - @sb['block_group_zero']) / @sb['blocks_in_group']
244
+ offset = block.modulo(@sb['blocks_in_group'])
245
+ return group, offset
246
+ end
247
+
248
+ def firstGroupBlockNum(group)
249
+ group * @sb['blocks_in_group'] + @sb['block_group_zero']
250
+ end
251
+
252
+ def inodeNumToGroupNum(inode)
253
+ (inode - 1).divmod(inodesPerGroup)
254
+ end
255
+
256
+ def blockToAddress(block)
257
+ address = block * @blockSize
258
+ address += (SUPERBLOCK_SIZE + groupDescriptorSize * @numGroups) if address == SUPERBLOCK_OFFSET
259
+ address
260
+ end
261
+
262
+ def isValidInode?(inode)
263
+ group, offset = inodeNumToGroupNum(inode)
264
+ gde = gdt[group]
265
+ gde.inodeAllocBmp[offset]
266
+ end
267
+
268
+ def isValidBlock?(block)
269
+ group, offset = blockNumToGroupNum(block)
270
+ gde = gdt[group]
271
+ gde.blockAllocBmp[offset]
272
+ end
273
+
274
+ # Ignore allocation is for testing only.
275
+ def getInode(inode, _ignore_alloc = false)
276
+ unless @inode_cache.key?(inode)
277
+ group, offset = inodeNumToGroupNum(inode)
278
+ gde = gdt[group]
279
+ # raise "Inode #{inode} is not allocated" if (not gde.inodeAllocBmp[offset] and not ignore_alloc)
280
+ @stream.seek(blockToAddress(gde.inodeTable) + offset * inodeSize)
281
+ @inode_cache[inode] = Inode.new(@stream.read(inodeSize), self, inode)
282
+ $log.info "Inode num: #{inode}\n#{@inode_cache[inode].dump}\n\n" if $log && @@track_inodes
283
+ end
284
+
285
+ @inode_cache[inode]
286
+ end
287
+
288
+ # Ignore allocation is for testing only.
289
+ def getBlock(block, _ignore_alloc = false)
290
+ raise "Ext4::Superblock.getBlock: block is nil" if block.nil?
291
+
292
+ unless @block_cache.key?(block)
293
+ if block == 0
294
+ @block_cache[block] = MemoryBuffer.create(@blockSize)
295
+ else
296
+ group, offset = blockNumToGroupNum(block)
297
+ gde = gdt[group]
298
+ # raise "Block #{block} is not allocated" if (not gde.blockAllocBmp[offset] and not ignore_alloc)
299
+
300
+ address = blockToAddress(block) # This function will read the block into our cache
301
+
302
+ @stream.seek(address)
303
+ @block_cache[block] = @stream.read(@blockSize)
304
+ end
305
+ end
306
+ @block_cache[block]
307
+ end
308
+
309
+ def getFeatureStrings
310
+ out = "Compatible Feature Flags:\n"
311
+ cff = @sb['compat_flags']
312
+ out << " CFF_PREALLOC_DIR_BLKS\n" if gotBit?(cff, CFF_PREALLOC_DIR_BLKS)
313
+ out << " CFF_AFS_SERVER_INODE\n" if gotBit?(cff, CFF_AFS_SERVER_INODES)
314
+ out << " CFF_JOURNAL\n" if gotBit?(cff, CFF_JOURNAL)
315
+ out << " CFF_EXTENDED_ATTRIBS\n" if gotBit?(cff, CFF_EXTENDED_ATTRIBS)
316
+ out << " CFF_BIG_PART\n" if gotBit?(cff, CFF_BIG_PART)
317
+ out << " CFF_HASH_INDEX\n" if gotBit?(cff, CFF_HASH_INDEX)
318
+ extra = cff - (cff & CFF_FLAGS)
319
+ out << " Extra Flags: 0x%08X\n" % extra if extra != 0
320
+
321
+ out << "Incompatible Feature Flags:\n"
322
+ icf = @sb['incompat_flags']
323
+ out << " ICF_COMPRESSION\n" if gotBit?(icf, ICF_COMPRESSION)
324
+ out << " ICF_FILE_TYPE\n" if gotBit?(icf, ICF_FILE_TYPE)
325
+ out << " ICF_RECOVER_FS\n" if gotBit?(icf, ICF_RECOVER_FS)
326
+ out << " ICF_JOURNAL\n" if gotBit?(icf, ICF_JOURNAL)
327
+ out << " ICF_META_BG\n" if gotBit?(icf, ICF_META_BG)
328
+ out << " ICF_EXTENTS\n" if gotBit?(icf, ICF_EXTENTS)
329
+ out << " ICF_64BIT\n" if gotBit?(icf, ICF_64BIT)
330
+ out << " ICF_MMP\n" if gotBit?(icf, ICF_MMP)
331
+ out << " ICF_FLEX_BG\n" if gotBit?(icf, ICF_FLEX_BG)
332
+ out << " ICF_EA_INODE\n" if gotBit?(icf, ICF_EA_INODE)
333
+ out << " ICF_DIRDATA\n" if gotBit?(icf, ICF_DIRDATA)
334
+ extra = icf - (icf & ICF_FLAGS)
335
+ out << " Extra Flags: 0x%08X\n" % extra if extra != 0
336
+
337
+ out << "Read Only Feature Flags:\n"
338
+ rof = @sb['ro_flags']
339
+ out << " ROF_SPARSE\n" if gotBit?(rof, ROF_SPARSE)
340
+ out << " ROF_LARGE_FILES\n" if gotBit?(rof, ROF_LARGE_FILES)
341
+ out << " ROF_BTREES\n" if gotBit?(rof, ROF_BTREES)
342
+ out << " ROF_HUGE_FILE\n" if gotBit?(rof, ROF_HUGE_FILE)
343
+ out << " ROF_GDT_CSUM\n" if gotBit?(rof, ROF_GDT_CSUM)
344
+ out << " ROF_DIR_NLINK\n" if gotBit?(rof, ROF_DIR_NLINK)
345
+ out << " ROF_EXTRA_ISIZE\n" if gotBit?(rof, ROF_EXTRA_ISIZE)
346
+ extra = rof - (rof & ROF_FLAGS)
347
+ out << " Extra Flags: 0x%08X\n" % extra if extra != 0
348
+
349
+ out
350
+ end
351
+
352
+ # ////////////////////////////////////////////////////////////////////////////
353
+ # // Utility functions.
354
+
355
+ def gotBit?(field, bit)
356
+ field & bit == bit
357
+ end
358
+
359
+ # Dump object.
360
+ def dump
361
+ out = "\#<#{self.class}:0x#{'%08x' % object_id}>\n"
362
+ out << "Number of inodes : #{@sb['num_inodes']}\n"
363
+ out << "Number of blocks : #{@sb['num_blocks']}\n"
364
+ out << "Reserved blocks : #{@sb['reserved_blocks']}\n"
365
+ out << "Unallocated blocks : #{@sb['unallocated_blocks']}\n"
366
+ out << "Unallocated inodes : #{@sb['unallocated_inodes']}\n"
367
+ out << "Block group 0 : #{@sb['block_group_zero']}\n"
368
+ out << "Block size : #{@sb['block_size']} (#{@blockSize} bytes)\n"
369
+ out << "Fragment size : #{@sb['fragment_size']} (#{fragmentSize} bytes)\n"
370
+ out << "Blocks per group : #{@sb['blocks_in_group']} (#{blocksPerGroup} blocks per group)\n"
371
+ out << "Fragments per group : #{@sb['fragments_in_group']} (#{fragmentsPerGroup} fragments per group)\n"
372
+ out << "Inodes per group : #{@sb['inodes_in_group']} (#{inodesPerGroup} inodes per group)\n"
373
+ out << "Last mount time : #{Time.at(@sb['last_mount_time'])}\n"
374
+ out << "Last write time : #{Time.at(@sb['last_write_time'])}\n"
375
+ out << "Current mount count : #{@sb['mount_count']}\n"
376
+ out << "Maximum mount count : #{@sb['max_mount_count']}\n"
377
+ out << "Signature : #{@sb['signature']}\n"
378
+ out << "File system state : #{@sb['fs_state']}\n"
379
+ out << "Error hndling methd : #{@sb['err_method']}\n"
380
+ out << "Minor version : #{@sb['ver_minor']}\n"
381
+ out << "Last consistency check: #{Time.at(@sb['last_check_time'])}\n"
382
+ out << "Forced check interval : #{@sb['forced_check_int']} sec\n"
383
+ out << "Creator OS : #{@sb['creator_os']}\n"
384
+ out << "Major version : #{@sb['ver_major']}\n"
385
+ out << "UID can use res blocks: #{@sb['uid_res_blocks']}\n"
386
+ out << "GID can use res blocks: #{@sb['gid_res_blocks']}\n"
387
+ out << "Group descriptor size : #{@sb['group_desc_size']}\n"
388
+ if isDynamic?
389
+ out << "First non-res inode : #{@sb['first_inode']}\n"
390
+ out << "Size of inode : #{@sb['inode_size']}\n"
391
+ out << "Block group of this SB: #{@sb['block_group']}\n"
392
+ out << "Compatible features : 0x#{'%08x' % @sb['compat_flags']}\n"
393
+ out << "Incompatible features : 0x#{'%08x' % @sb['incompat_flags']}\n"
394
+ out << "Read Only features : 0x#{'%08x' % @sb['ro_flags']}\n"
395
+ out << "File system id : #{@fsId}\n"
396
+ out << "Volume name : #{@sb['vol_name']}\n"
397
+ out << "Last mount path : #{@sb['last_mnt_path']}\n"
398
+ out << "Algorithm usage bitmap: 0x#{'%08x' % @sb['algo_use_bmp']}\n"
399
+ out << "Blocks prealloc files : #{@sb['file_prealloc_blks']}\n"
400
+ out << "Blocks prealloc dirs : #{@sb['dir_prealloc_blks']}\n"
401
+ out << "Journal id : #{@jrnlId}\n"
402
+ out << "Journal inode : #{@sb['jrnl_inode']}\n"
403
+ out << "Journal device : #{@sb['jrnl_device']}\n"
404
+ out << "Orphan inode head : #{@sb['orphan_head']}\n"
405
+ end
406
+ out << "Number of groups : #{numGroups}\n"
407
+ out << "Free bytes : #{freeBytes}\n"
408
+ out << getFeatureStrings
409
+ out
410
+ end
411
+ end
412
+ end # moule Ext4