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,305 @@
1
+ require 'rufus/lru'
2
+
3
+ # Ext3 stuff.
4
+ require 'fs/ext3/superblock'
5
+ require 'fs/ext3/directory_entry'
6
+ require 'fs/ext3/directory'
7
+ require 'fs/ext3/file_data'
8
+
9
+ # Ext3 file system interface to MiqFS.
10
+ module Ext3
11
+ # Default directory cache size.
12
+ DEF_CACHE_SIZE = 50
13
+
14
+ # Members (these become members of an MiqFS instance).
15
+ attr_accessor :superblock, :rootDir, :entry_cache, :dir_cache, :cache_hits
16
+
17
+ # Top level file object.
18
+ class FileObject
19
+ include Ext3
20
+ attr_reader :path, :de, :inode, :data, :miqfs
21
+ # NOTE: miqfs will always be an MiqFS instance.
22
+
23
+ # fs_fileOpen passes 'self' into .. er, 'this'.
24
+ def initialize(path, miqfs)
25
+ @path = path
26
+ @miqfs = miqfs
27
+ end
28
+
29
+ def open(mode = "r")
30
+ # Ext3 module methods use miqfs instance accessors to touch @boot_sector.
31
+ @mode = mode.downcase
32
+ @de = ifs_getFile(@path, @miqfs)
33
+ unless @de.nil?
34
+ raise "File is directory: '#{@path}'" if @de.isDir?
35
+ end
36
+ if mode.include?("r")
37
+ raise "File not found: '#{@path}'" if @de.nil?
38
+ @inode = @miqfs.superblock.getInode(@de.inode)
39
+ @data = FileData.new(@inode, @miqfs.superblock)
40
+ end
41
+ end
42
+ end
43
+
44
+ # File system interface.
45
+ def fs_init
46
+ # puts "Ext3::fs_init(#{@dobj.dInfo.fileName})"
47
+ self.fsType = "Ext3"
48
+
49
+ # Initialize bs & read root dir.
50
+ @dobj.seek(0, IO::SEEK_SET)
51
+ self.superblock = Superblock.new(@dobj)
52
+ @fsId = superblock.fsId.to_s
53
+ @volName = superblock.volName
54
+ self.rootDir = Directory.new(superblock)
55
+ self.entry_cache = LruHash.new(DEF_CACHE_SIZE)
56
+ self.dir_cache = LruHash.new(DEF_CACHE_SIZE)
57
+ self.cache_hits = 0
58
+ end
59
+
60
+ # Returns free space on file system in bytes.
61
+ def fs_freeBytes
62
+ @superblock.freeBytes
63
+ end
64
+
65
+ #
66
+ # Directory instance methods.
67
+ #
68
+
69
+ # Returns String array of all names, sans path.
70
+ def fs_dirEntries(p)
71
+ # Get path directory.
72
+ dir = ifs_getDir(p)
73
+ return nil if dir.nil?
74
+ dir.globNames
75
+ end
76
+
77
+ # Make a directory. Parent must exist.
78
+ def fs_dirMkdir(_p)
79
+ raise "Write functionality is not yet supported on Ext3."
80
+ end
81
+
82
+ # Remove a directory.
83
+ def fs_dirRmdir(_p)
84
+ raise "Write functionality is not yet supported on Ext3."
85
+ end
86
+
87
+ #
88
+ # File instance methods.
89
+ #
90
+
91
+ # Returns true if name exists, false if not.
92
+ def fs_fileExists?(p)
93
+ de = ifs_getFile(p)
94
+ return false if de.nil?
95
+ true
96
+ end
97
+
98
+ # Returns true if name is a regular file.
99
+ def fs_fileFile?(p)
100
+ de = ifs_getFile(p)
101
+ return false if de.nil?
102
+ de.fileType == DirectoryEntry::FT_FILE
103
+ end
104
+
105
+ # Returns true if name is a directory.
106
+ def fs_fileDirectory?(p)
107
+ de = ifs_getFile(p)
108
+ return false if de.nil?
109
+ de.fileType == DirectoryEntry::FT_DIRECTORY
110
+ end
111
+
112
+ # Returns size in bytes.
113
+ def fs_fileSize(p)
114
+ de = ifs_getFile(p)
115
+ return nil if de.nil?
116
+ @superblock.getInode(de.inode).length
117
+ end
118
+
119
+ # Delete file.
120
+ def fs_fileDelete(_p)
121
+ raise "Write functionality is not yet supported on Ext3."
122
+ end
123
+
124
+ # Returns Ruby Time object.
125
+ def fs_fileAtime(p)
126
+ de = ifs_getFile(p)
127
+ return nil if de.nil?
128
+ @superblock.getInode(de.inode).aTime
129
+ end
130
+
131
+ # Returns Ruby Time object.
132
+ def fs_fileCtime(p)
133
+ de = ifs_getFile(p)
134
+ return nil if de.nil?
135
+ @superblock.getInode(de.inode).cTime
136
+ end
137
+
138
+ # Returns Ruby Time object.
139
+ def fs_fileMtime(p)
140
+ de = ifs_getFile(p)
141
+ return nil if de.nil?
142
+ @superblock.getInode(de.inode).mTime
143
+ end
144
+
145
+ # Return true if p is a path to a symbolic link.
146
+ def fs_isSymLink?(p)
147
+ de = ifs_getFile(p)
148
+ return false if de.nil?
149
+ de.isSymLink?
150
+ end
151
+ # In these, fobj is a FileObject.
152
+
153
+ def fs_fileSize_obj(fobj)
154
+ fobj.inode.length
155
+ end
156
+
157
+ # Returns a Ruby Time object.
158
+ def fs_fileAtime_obj(fobj)
159
+ fobj.inode.aTime
160
+ end
161
+
162
+ # Returns a Ruby Time object.
163
+ def fs_fileCtime_obj(fobj)
164
+ fobj.inode.cTime
165
+ end
166
+
167
+ # Returns a Ruby Time obect.
168
+ def fs_fileMtime_obj(fobj)
169
+ fobj.inode.mTime
170
+ end
171
+
172
+ # New FileObject instance.
173
+ # NOTE: FileObject must have access to Ext3 members.
174
+ # This is kind of like a 'skip this' thing. Ext3 methods
175
+ # use stuff owned by MiqFS, so this is necessary.
176
+ def fs_fileOpen(p, mode = "r")
177
+ fobj = FileObject.new(p, self)
178
+ fobj.open(mode)
179
+ fobj
180
+ end
181
+
182
+ # Returns current file position.
183
+ def fs_fileSeek(fobj, offset, whence)
184
+ fobj.data.seek(offset, whence)
185
+ end
186
+
187
+ # Returns a Ruby String object.
188
+ def fs_fileRead(fobj, len)
189
+ fobj.data.read(len)
190
+ end
191
+
192
+ def fs_fileWrite(_fobj, _buf, _len)
193
+ raise "Write functionality is not yet supported on Ext3."
194
+ # fobj.data.write(buf, len)
195
+ end
196
+
197
+ # Write changes & destroy.
198
+ def fs_fileClose(_fobj)
199
+ # TODO: unrem when write is supported.
200
+ # fobj.data.close
201
+ fobj = nil
202
+ end
203
+
204
+ # IFS members: internal file system.
205
+
206
+ # Return a DirectoryEntry for a given file or nil if not exist.
207
+ def ifs_getFile(p, miqfs = nil)
208
+ # If this is being called from a FileObject instance, then MiqFS owns contained instance members.
209
+ # If this is being called from an Ext3 module method, then self owns contained instance members.
210
+ miqfs = self if miqfs.nil?
211
+
212
+ # Preprocess path.
213
+ p = unnormalizePath(p)
214
+ dir, fname = File.split(p)
215
+ # Fix for FB#835: if fil == root then fil needs to be "."
216
+ fname = "." if fname == "/" || fname == "\\"
217
+
218
+ # Check for this file in the cache.
219
+ cache_name = "#{dir == '/' ? '' : dir}/#{fname}"
220
+ if miqfs.entry_cache.key?(cache_name)
221
+ miqfs.cache_hits += 1
222
+ return miqfs.entry_cache[cache_name]
223
+ end
224
+
225
+ # Look for file in dir, but don't error if it doesn't exist.
226
+ # NOTE: if p is a directory that's ok, find it.
227
+ begin
228
+ dirObj = ifs_getDir(dir, miqfs)
229
+ dirEnt = dirObj.nil? ? nil : dirObj.findEntry(fname)
230
+ rescue RuntimeError
231
+ dirEnt = nil
232
+ end
233
+
234
+ miqfs.entry_cache[cache_name] = dirEnt
235
+ end
236
+
237
+ # Create a directory entry.
238
+ def ifs_putFile(p, miqfs = nil)
239
+ raise "Write functionality is not yet supported on Ext3."
240
+
241
+ # Commented out for now to avoid unreachable code
242
+ #
243
+ # # If this is being called from a FileObject instance, then MiqFS owns contained instance members.
244
+ # # If this is being called from an Ext3 module method, then self owns contained instance members.
245
+ # miqfs = self if miqfs.nil?
246
+
247
+ # # Preprocess path.
248
+ # p = unnormalizePath(p)
249
+ # dir, fil = File.split(p)
250
+
251
+ # # Parent directory must exist.
252
+ # dirObj = ifs_getDir(dir, miqfs)
253
+ # return nil if dir.nil?
254
+ # dirObj.createFile(fil)
255
+ end
256
+
257
+ # Return a Directory object for a path.
258
+ # Raise error if path doesn't exist.
259
+ def ifs_getDir(p, miqfs = nil)
260
+ # If this is being called from a FileObject instance, then MiqFS owns contained instance members.
261
+ # If this is being called from an Ext3 module method, then self owns contained instance members.
262
+ miqfs = self if miqfs.nil?
263
+
264
+ # Wack leading drive.
265
+ p = unnormalizePath(p)
266
+
267
+ # Get an array of directory names, kill off the first (it's always empty).
268
+ names = p.split(/[\\\/]/)
269
+ names.shift
270
+
271
+ dir = ifs_getDirR(names, miqfs)
272
+ raise "Directory '#{p}' not found" if dir.nil?
273
+ dir
274
+ end
275
+
276
+ # Return Directory recursively for given directory or nil if not exist.
277
+ def ifs_getDirR(names, miqfs)
278
+ return miqfs.rootDir if names.empty?
279
+
280
+ # Check for this path in the cache.
281
+ fname = names.join('/')
282
+ if miqfs.dir_cache.key?(fname)
283
+ miqfs.cache_hits += 1
284
+ return miqfs.dir_cache[fname]
285
+ end
286
+
287
+ name = names.pop
288
+ pdir = ifs_getDirR(names, miqfs)
289
+ return nil if pdir.nil?
290
+
291
+ de = pdir.findEntry(name, DirectoryEntry::FT_DIRECTORY)
292
+ return nil if de.nil?
293
+ miqfs.entry_cache[fname] = de
294
+
295
+ dir = Directory.new(miqfs.superblock, de.inode)
296
+ return nil if dir.nil?
297
+
298
+ miqfs.dir_cache[fname] = dir
299
+ end
300
+
301
+ # Wack leading drive leter & colon.
302
+ def unnormalizePath(p)
303
+ p[1] == 58 ? p[2, p.size] : p
304
+ end
305
+ end
@@ -0,0 +1,25 @@
1
+ require 'fs/ext3/superblock'
2
+
3
+ module Ext3Probe
4
+ def self.probe(dobj)
5
+ $log.debug("Ext3Probe >> dobj=#{dobj}") if $log
6
+ unless dobj.kind_of?(MiqDisk)
7
+ $log.debug "Ext3Probe << FALSE because Disk Object class is not MiqDisk, but is '#{dobj.class}'" if $log
8
+ return false
9
+ end
10
+
11
+ begin
12
+ dobj.seek(0, IO::SEEK_SET)
13
+ sb = Ext3::Superblock.new(dobj)
14
+
15
+ # If initializing the superblock does not throw any errors, then this is ext3
16
+ $log.debug("Ext3Probe << TRUE")
17
+ return true
18
+ rescue => err
19
+ $log.debug "Ext3Probe << FALSE because #{err.message}" if $log
20
+ return false
21
+ ensure
22
+ dobj.seek(0, IO::SEEK_SET)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,304 @@
1
+ require 'rufus/lru'
2
+
3
+ # Ext4 stuff.
4
+ require 'fs/ext4/superblock'
5
+ require 'fs/ext4/directory_entry'
6
+ require 'fs/ext4/directory'
7
+
8
+ # Ext4 file system interface to MiqFS.
9
+ module Ext4
10
+ # Default directory cache size.
11
+ DEF_CACHE_SIZE = 50
12
+
13
+ # Members (these become members of an MiqFS instance).
14
+ attr_accessor :superblock, :rootDir, :entry_cache, :dir_cache, :cache_hits
15
+
16
+ # Top level file object.
17
+ class FileObject
18
+ include Ext4
19
+ attr_reader :path, :de, :inode, :miqfs
20
+ # NOTE: miqfs will always be an MiqFS instance.
21
+
22
+ # fs_fileOpen passes 'self' into .. er, 'this'.
23
+ def initialize(path, miqfs)
24
+ @path = path
25
+ @miqfs = miqfs
26
+ end
27
+
28
+ def open(mode = "r")
29
+ # Ext4 module methods use miqfs instance accessors to touch @boot_sector.
30
+ @mode = mode.downcase
31
+ @de = ifs_getFile(@path, @miqfs)
32
+ raise "File is directory: '#{@path}'" if @de && @de.isDir?
33
+
34
+ if mode.include?("r")
35
+ raise "File not found: '#{@path}'" if @de.nil?
36
+ @inode = @miqfs.superblock.getInode(@de.inode)
37
+ end
38
+ end
39
+ end
40
+
41
+ # File system interface.
42
+ def fs_init
43
+ # puts "Ext4::fs_init(#{@dobj.dInfo.fileName})"
44
+ self.fsType = "Ext4"
45
+
46
+ # Initialize bs & read root dir.
47
+ @dobj.seek(0, IO::SEEK_SET)
48
+ self.superblock = Superblock.new(@dobj)
49
+ @fsId = superblock.fsId.to_s
50
+ @volName = superblock.volName
51
+ self.rootDir = Directory.new(superblock)
52
+ self.entry_cache = LruHash.new(DEF_CACHE_SIZE)
53
+ self.dir_cache = LruHash.new(DEF_CACHE_SIZE)
54
+ self.cache_hits = 0
55
+ end
56
+
57
+ # Returns free space on file system in bytes.
58
+ def fs_freeBytes
59
+ @superblock.freeBytes
60
+ end
61
+
62
+ #
63
+ # Directory instance methods.
64
+ #
65
+
66
+ # Returns String array of all names, sans path.
67
+ def fs_dirEntries(p)
68
+ # Get path directory.
69
+ dir = ifs_getDir(p)
70
+ return nil if dir.nil?
71
+ dir.globNames
72
+ end
73
+
74
+ # Make a directory. Parent must exist.
75
+ def fs_dirMkdir(_p)
76
+ raise "Write functionality is not yet supported on Ext4."
77
+ end
78
+
79
+ # Remove a directory.
80
+ def fs_dirRmdir(_p)
81
+ raise "Write functionality is not yet supported on Ext4."
82
+ end
83
+
84
+ #
85
+ # File instance methods.
86
+ #
87
+
88
+ # Returns true if name exists, false if not.
89
+ def fs_fileExists?(p)
90
+ de = ifs_getFile(p)
91
+ return false if de.nil?
92
+ true
93
+ end
94
+
95
+ # Returns true if name is a regular file.
96
+ def fs_fileFile?(p)
97
+ de = ifs_getFile(p)
98
+ return false if de.nil?
99
+ de.fileType == DirectoryEntry::FT_FILE
100
+ end
101
+
102
+ # Returns true if name is a directory.
103
+ def fs_fileDirectory?(p)
104
+ de = ifs_getFile(p)
105
+ return false if de.nil?
106
+ de.fileType == DirectoryEntry::FT_DIRECTORY
107
+ end
108
+
109
+ # Returns size in bytes.
110
+ def fs_fileSize(p)
111
+ de = ifs_getFile(p)
112
+ return nil if de.nil?
113
+ @superblock.getInode(de.inode).length
114
+ end
115
+
116
+ # Delete file.
117
+ def fs_fileDelete(_p)
118
+ raise "Write functionality is not yet supported on Ext4."
119
+ end
120
+
121
+ # Returns Ruby Time object.
122
+ def fs_fileAtime(p)
123
+ de = ifs_getFile(p)
124
+ return nil if de.nil?
125
+ @superblock.getInode(de.inode).aTime
126
+ end
127
+
128
+ # Returns Ruby Time object.
129
+ def fs_fileCtime(p)
130
+ de = ifs_getFile(p)
131
+ return nil if de.nil?
132
+ @superblock.getInode(de.inode).cTime
133
+ end
134
+
135
+ # Returns Ruby Time object.
136
+ def fs_fileMtime(p)
137
+ de = ifs_getFile(p)
138
+ return nil if de.nil?
139
+ @superblock.getInode(de.inode).mTime
140
+ end
141
+
142
+ # Return true if p is a path to a symbolic link.
143
+ def fs_isSymLink?(p)
144
+ de = ifs_getFile(p)
145
+ return false if de.nil?
146
+ de.isSymLink?
147
+ end
148
+ # In these, fobj is a FileObject.
149
+
150
+ def fs_fileSize_obj(fobj)
151
+ fobj.inode.length
152
+ end
153
+
154
+ # Returns a Ruby Time object.
155
+ def fs_fileAtime_obj(fobj)
156
+ fobj.inode.aTime
157
+ end
158
+
159
+ # Returns a Ruby Time object.
160
+ def fs_fileCtime_obj(fobj)
161
+ fobj.inode.cTime
162
+ end
163
+
164
+ # Returns a Ruby Time obect.
165
+ def fs_fileMtime_obj(fobj)
166
+ fobj.inode.mTime
167
+ end
168
+
169
+ # New FileObject instance.
170
+ # NOTE: FileObject must have access to Ext4 members.
171
+ # This is kind of like a 'skip this' thing. Ext4 methods
172
+ # use stuff owned by MiqFS, so this is necessary.
173
+ def fs_fileOpen(p, mode = "r")
174
+ fobj = FileObject.new(p, self)
175
+ fobj.open(mode)
176
+ fobj
177
+ end
178
+
179
+ # Returns current file position.
180
+ def fs_fileSeek(fobj, offset, whence)
181
+ fobj.inode.seek(offset, whence)
182
+ end
183
+
184
+ # Returns a Ruby String object.
185
+ def fs_fileRead(fobj, len)
186
+ fobj.inode.read(len)
187
+ end
188
+
189
+ def fs_fileWrite(_fobj, _buf, _len)
190
+ raise "Write functionality is not yet supported on Ext4."
191
+ # fobj.inode.write(buf, len)
192
+ end
193
+
194
+ # Write changes & destroy.
195
+ def fs_fileClose(fobj)
196
+ # TODO: unrem when write is supported.
197
+ # fobj.inode.close
198
+ fobj.inode.rewind
199
+ fobj = nil
200
+ end
201
+
202
+ # IFS members: internal file system.
203
+
204
+ # Return a DirectoryEntry for a given file or nil if not exist.
205
+ def ifs_getFile(p, miqfs = nil)
206
+ # If this is being called from a FileObject instance, then MiqFS owns contained instance members.
207
+ # If this is being called from an Ext4 module method, then self owns contained instance members.
208
+ miqfs = self if miqfs.nil?
209
+
210
+ # Preprocess path.
211
+ p = unnormalizePath(p)
212
+ dir, fname = File.split(p)
213
+ # Fix for FB#835: if fil == root then fil needs to be "."
214
+ fname = "." if fname == "/" || fname == "\\"
215
+
216
+ # Check for this file in the cache.
217
+ cache_name = "#{dir == '/' ? '' : dir}/#{fname}"
218
+ if miqfs.entry_cache.key?(cache_name)
219
+ miqfs.cache_hits += 1
220
+ return miqfs.entry_cache[cache_name]
221
+ end
222
+
223
+ # Look for file in dir, but don't error if it doesn't exist.
224
+ # NOTE: if p is a directory that's ok, find it.
225
+ begin
226
+ dirObj = ifs_getDir(dir, miqfs)
227
+ dirEnt = dirObj.nil? ? nil : dirObj.findEntry(fname)
228
+ rescue RuntimeError => err
229
+ $log.error err.message.to_s if $log
230
+ dirEnt = nil
231
+ end
232
+
233
+ miqfs.entry_cache[cache_name] = dirEnt
234
+ end
235
+
236
+ # Create a directory entry.
237
+ def ifs_putFile(p, miqfs = nil)
238
+ raise "Write functionality is not yet supported on Ext4."
239
+
240
+ # Commented out for now to avoid unreachable code
241
+ #
242
+ # # If this is being called from a FileObject instance, then MiqFS owns contained instance members.
243
+ # # If this is being called from an Ext4 module method, then self owns contained instance members.
244
+ # miqfs = self if miqfs.nil?
245
+
246
+ # # Preprocess path.
247
+ # p = unnormalizePath(p)
248
+ # dir, fil = File.split(p)
249
+
250
+ # # Parent directory must exist.
251
+ # dirObj = ifs_getDir(dir, miqfs)
252
+ # return nil if dir.nil?
253
+ # dirObj.createFile(fil)
254
+ end
255
+
256
+ # Return a Directory object for a path.
257
+ # Raise error if path doesn't exist.
258
+ def ifs_getDir(p, miqfs = nil)
259
+ # If this is being called from a FileObject instance, then MiqFS owns contained instance members.
260
+ # If this is being called from an Ext4 module method, then self owns contained instance members.
261
+ miqfs = self if miqfs.nil?
262
+
263
+ # Wack leading drive.
264
+ p = unnormalizePath(p)
265
+
266
+ # Get an array of directory names, kill off the first (it's always empty).
267
+ names = p.split(/[\\\/]/)
268
+ names.shift
269
+
270
+ dir = ifs_getDirR(names, miqfs)
271
+ raise "Directory '#{p}' not found" if dir.nil?
272
+ dir
273
+ end
274
+
275
+ # Return Directory recursively for given directory or nil if not exist.
276
+ def ifs_getDirR(names, miqfs)
277
+ return miqfs.rootDir if names.empty?
278
+
279
+ # Check for this path in the cache.
280
+ fname = names.join('/')
281
+ if miqfs.dir_cache.key?(fname)
282
+ miqfs.cache_hits += 1
283
+ return miqfs.dir_cache[fname]
284
+ end
285
+
286
+ name = names.pop
287
+ pdir = ifs_getDirR(names, miqfs)
288
+ return nil if pdir.nil?
289
+
290
+ de = pdir.findEntry(name, DirectoryEntry::FT_DIRECTORY)
291
+ return nil if de.nil?
292
+ miqfs.entry_cache[fname] = de
293
+
294
+ dir = Directory.new(miqfs.superblock, de.inode)
295
+ return nil if dir.nil?
296
+
297
+ miqfs.dir_cache[fname] = dir
298
+ end
299
+
300
+ # Wack leading drive letter & colon.
301
+ def unnormalizePath(p)
302
+ p[1] == 58 ? p[2, p.size] : p
303
+ end
304
+ end
@@ -0,0 +1,25 @@
1
+ require 'fs/ext4/superblock'
2
+
3
+ module Ext4Probe
4
+ def self.probe(dobj)
5
+ $log.debug("Ext4Probe >> dobj=#{dobj}") if $log
6
+ unless dobj.kind_of?(MiqDisk)
7
+ $log.debug "Ext4Probe << FALSE because Disk Object class is not MiqDisk, but is '#{dobj.class}'" if $log
8
+ return false
9
+ end
10
+
11
+ begin
12
+ dobj.seek(0, IO::SEEK_SET)
13
+ sb = Ext4::Superblock.new(dobj)
14
+
15
+ # If initializing the superblock does not throw any errors, then this is Ext4
16
+ $log.debug("Ext4Probe << TRUE")
17
+ return true
18
+ rescue => err
19
+ $log.debug "Ext4Probe << FALSE because #{err.message}" if $log
20
+ return false
21
+ ensure
22
+ dobj.seek(0, IO::SEEK_SET)
23
+ end
24
+ end
25
+ end