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,105 @@
1
+ module LocalFS
2
+ def fs_init
3
+ self.fsType = "LocalFS"
4
+
5
+ if @dobj && @dobj.root
6
+ @root = @dobj.root
7
+ raise "LocalFS: root directory does not exist, #{@root}" unless File.directory?(@root)
8
+ else
9
+ @root = nil
10
+ end
11
+
12
+ @cwd = Dir.pwd
13
+ end
14
+
15
+ def freeBytes
16
+ (0)
17
+ end
18
+
19
+ def fs_dirEntries(p)
20
+ Dir.entries(internalPath(p))
21
+ end
22
+
23
+ def fs_dirMkdir(p)
24
+ Dir.mkdir(internalPath(p))
25
+ end
26
+
27
+ def dirRmdir(p)
28
+ Dir.rmdir(internalPath(p))
29
+ end
30
+
31
+ def fs_fileDelete(p)
32
+ File.delete(internalPath(p))
33
+ end
34
+
35
+ def fs_fileExists?(p)
36
+ File.exist?(internalPath(p))
37
+ end
38
+
39
+ def fs_fileFile?(p)
40
+ File.file?(internalPath(p))
41
+ end
42
+
43
+ def fs_fileDirectory?(p)
44
+ File.directory? internalPath((p))
45
+ end
46
+
47
+ def fs_fileSize(p)
48
+ File.size(internalPath(p))
49
+ end
50
+
51
+ def fs_fileSize_obj(fobj)
52
+ fobj.stat.size
53
+ end
54
+
55
+ def fs_fileAtime(p)
56
+ File.atime(internalPath(p))
57
+ end
58
+
59
+ def fs_fileCtime(p)
60
+ File.ctime(internalPath(p))
61
+ end
62
+
63
+ def fs_fileMtime(p)
64
+ File.mtime(internalPath(p))
65
+ end
66
+
67
+ def fs_fileAtime_obj(fobj)
68
+ fobj.atime
69
+ end
70
+
71
+ def fs_fileCtime_obj(fobj)
72
+ fobj.ctime
73
+ end
74
+
75
+ def fs_fileMtime_obj(fobj)
76
+ fobj.mtime
77
+ end
78
+
79
+ def fs_fileOpen(p, mode = "r")
80
+ File.new(internalPath(p), mode)
81
+ end
82
+
83
+ def fs_fileSeek(fobj, offset, whence)
84
+ fobj.seek(offset, whence)
85
+ end
86
+
87
+ def fs_fileRead(fobj, len)
88
+ fobj.read(len)
89
+ end
90
+
91
+ def fs_fileWrite(fobj, buf, len)
92
+ return(fobj.write(buf)) if buf.length == len
93
+ return(fobj.write(buf[0, len])) if buf.length > len
94
+ raise "LocalFS.fs_fileWrite: attempt to write passed the end of buffer"
95
+ end
96
+
97
+ def fs_fileClose(fobj)
98
+ fobj.close
99
+ end
100
+
101
+ def internalPath(p)
102
+ return(File.join(@root, p)) if @root
103
+ (p)
104
+ end
105
+ end
@@ -0,0 +1,287 @@
1
+ require 'rufus/lru'
2
+
3
+ # NTFS stuff.
4
+ require 'fs/ntfs/boot_sect'
5
+
6
+ # NTFS file system interface to MiqFS.
7
+ module NTFS
8
+ # Default index cache size
9
+ DEF_CACHE_SIZE = 50
10
+
11
+ # Members (these become members of an MiqFS instance).
12
+ attr_accessor :boot_sector, :drive_root, :index_cache, :cache_hits
13
+
14
+ # Top level file object.
15
+ class FileObject
16
+ include NTFS
17
+ attr_reader :path, :din, :data, :miqfs
18
+ # NOTE: miqfs will always be an MiqFS instance.
19
+
20
+ # fs_fileOpen passes 'self' into .. er, 'this'.
21
+ def initialize(path, miqfs)
22
+ @path = path
23
+ @miqfs = miqfs
24
+ end
25
+
26
+ def open(_mode = "rb")
27
+ # NTFS module methods use miqfs instance accessors to
28
+ # touch @boot_sector, @drive_root, @index_cache and @cache_hits
29
+ # (and any other NTFS members that may come later)
30
+ @din = ifs_getFile(@path, @miqfs)
31
+ raise "File not found: '#{@path}'" if @din.nil?
32
+ mft_entry = @din.resolve(@miqfs.boot_sector)
33
+ raise "File is directory: '#{@path}'" if @din.isDir?
34
+ @data = mft_entry.attributeData || AttribData.new("", 0)
35
+ end
36
+
37
+ def seek(offset, method = IO::SEEK_SET)
38
+ @data.seek(offset, method)
39
+ end
40
+ end
41
+
42
+ # File system interface.
43
+ def fs_init
44
+ self.fsType = "NTFS"
45
+
46
+ # Initialize Boot Sector
47
+ @dobj.seek(0, IO::SEEK_SET)
48
+ self.boot_sector = BootSect.new(@dobj)
49
+ boot_sector.setup
50
+ self.drive_root = boot_sector.rootDir
51
+
52
+ # Init cache.
53
+ self.index_cache = LruHash.new(DEF_CACHE_SIZE)
54
+ self.cache_hits = 0
55
+
56
+ # Expose fsId & volName.
57
+ @fsId, @volName = getVolumeInfo
58
+ end
59
+
60
+ def getVolumeInfo
61
+ vi = boot_sector.volumeInfo
62
+ volName = vi["name"]
63
+ fsId = vi["objectId"]
64
+ return fsId, volName
65
+ end
66
+
67
+ # Returns free space on file system in bytes.
68
+ def fs_freeBytes
69
+ boot_sector.freeBytes
70
+ end
71
+
72
+ # In these, p is a path.
73
+
74
+ # Returns String array of all names, sans path.
75
+ def fs_dirEntries(p)
76
+ # Get path index (directory).
77
+ index = ifs_getDir(p)
78
+ return nil if index.nil?
79
+ index.globNames
80
+ end
81
+
82
+ # Returns true if name exists, false if not.
83
+ def fs_fileExists?(p)
84
+ file = ifs_getFile(p)
85
+ return false if file.nil?
86
+ true
87
+ end
88
+
89
+ # Returns true if name is a regular file.
90
+ # NOTE: If a name isn't a directory, it's always a file - so far...
91
+ # (it could be a reparse point [a.k.a. hard link], but that's for later).
92
+ def fs_fileFile?(p)
93
+ file = ifs_getFile(p)
94
+ return false if file.nil?
95
+ file.resolve(boot_sector)
96
+ return false if file.isDir?
97
+ true
98
+ end
99
+
100
+ # Returns true if name is a directory.
101
+ def fs_fileDirectory?(p)
102
+ file = ifs_getFile(p)
103
+ return false if file.nil?
104
+ file.resolve(boot_sector)
105
+ return true if file.isDir?
106
+ false
107
+ end
108
+
109
+ # Returns true if name is a symbolic link.
110
+ def fs_isSymLink?(_p)
111
+ false
112
+ end
113
+
114
+ # Returns size in bytes.
115
+ def fs_fileSize(p)
116
+ file = ifs_getFile(p)
117
+ return nil if file.nil?
118
+ file.afn.length
119
+ end
120
+
121
+ # Returns Ruby Time object.
122
+ # NOTE: I *did* find files with 0 time, but they should never appear in this context.
123
+ def fs_fileAtime(p)
124
+ file = ifs_getFile(p)
125
+ return nil if file.nil?
126
+ file.afn.aTime
127
+ end
128
+
129
+ # Returns Ruby Time object.
130
+ def fs_fileCtime(p)
131
+ file = ifs_getFile(p)
132
+ return nil if file.nil?
133
+ file.afn.cTime
134
+ end
135
+
136
+ # Returns Ruby Time object.
137
+ def fs_fileMtime(p)
138
+ file = ifs_getFile(p)
139
+ return nil if file.nil?
140
+ file.afn.mTime
141
+ end
142
+
143
+ # In these, fobj is a FileObject, a DIN and AD.
144
+ # AD is not valid until opened. All afn members
145
+ # except permissions can be picked up from afn
146
+ # before resolving data (opening file).
147
+
148
+ # A FileObject is basically just :din, :data
149
+
150
+ # Returns a Ruby Time object.
151
+ def fs_fileAtime_obj(fobj)
152
+ fobj.din.afn.aTime
153
+ end
154
+
155
+ # Returns a Ruby Time object.
156
+ def fs_fileCtime_obj(fobj)
157
+ fobj.din.afn.cTime
158
+ end
159
+
160
+ # Returns a Ruby Time obect.
161
+ def fs_fileMtime_obj(fobj)
162
+ fobj.din.afn.mTime
163
+ end
164
+
165
+ # File size the faster way.
166
+ def fs_fileSize_obj(fobj)
167
+ fobj.din.afn.length
168
+ end
169
+
170
+ # New FileObject instance.
171
+ # NOTE: FileObject must have access to NTFS members.
172
+ # This is kind of like a 'skip this' thing. NTFS methods
173
+ # use stuff owned by MiqFS, so this is necessary.
174
+ def fs_fileOpen(p, _mode = "r")
175
+ fobj = FileObject.new(p, self)
176
+ fobj.open
177
+ fobj
178
+ end
179
+
180
+ # Seek to the requested position
181
+ def fs_fileSeek(fobj, offset, whence)
182
+ fobj.seek(offset, whence)
183
+ end
184
+
185
+ # Returns a Ruby String object.
186
+ def fs_fileRead(fobj, len)
187
+ return nil if fobj.data.nil?
188
+ fobj.data.read(len)
189
+ end
190
+
191
+ # Unless there's a way to explicitly destroy an object there's nothing to do here.
192
+ def fs_fileClose(_fobj)
193
+ fobj = nil
194
+ end
195
+
196
+ # IFS members: internal file system.
197
+
198
+ # Return DirectoryIndexNode for a given file or nil if not exist.
199
+ def ifs_getFile(p, miqfs = nil)
200
+ $log.debug "NTFS.ifs_getFile >> p=#{p}" if $log && $log.debug?
201
+
202
+ # If this is being called from a FileObject instance, then MiqFS owns contained instance members.
203
+ # If this is being called from an NTFS module method, then self owns contained instance members.
204
+ miqfs = self if miqfs.nil?
205
+
206
+ # Wack leading drive.
207
+ p = unnormalizePath(p).downcase
208
+
209
+ # Get directory & file as separate strings.
210
+ dir = p.split(/[\\\/]/)
211
+ fname = dir[dir.size - 1]
212
+ fname = "." if fname.nil? # Special case: if fname is nil then dir is root.
213
+ dir = dir.size > 2 ? dir[0...dir.size - 1].join('/') : '/'
214
+
215
+ # Check for this file in the cache.
216
+ cache_name = "#{dir == '/' ? '' : dir}/#{fname}"
217
+ if miqfs.index_cache.key?(cache_name)
218
+ miqfs.cache_hits += 1
219
+ file = miqfs.index_cache[cache_name]
220
+ $log.debug "NTFS.ifs_getFile << (cached) p=#{p} din=#{file}" if $log && $log.debug?
221
+ return file
222
+ end
223
+
224
+ # Look for file in dir, but don't error if it doesn't exist.
225
+ # NOTE: if p is a directory that's ok, find it.
226
+ file = nil
227
+ index = ifs_getDir(dir, miqfs)
228
+ unless index.nil?
229
+ $log.debug "NTFS.ifs_getFile -- getting din for #{fname} in <#{index.class.name}>" if $log && $log.debug?
230
+ file = index.find(fname)
231
+ end
232
+
233
+ $log.debug "NTFS.ifs_getFile << p=#{p} din=#{file}" if $log && $log.debug?
234
+ miqfs.index_cache[cache_name] = file
235
+ end
236
+
237
+ # Return an index of a path.
238
+ # Raise error if path doesn't exist.
239
+ def ifs_getDir(p, miqfs = nil)
240
+ $log.debug "NTFS.ifs_getDir >> p=#{p}" if $log && $log.debug?
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 NTFS module method, then self owns contained instance members.
244
+ miqfs = self if miqfs.nil?
245
+
246
+ # Wack leading drive.
247
+ p = unnormalizePath(p).downcase
248
+
249
+ # Get an array of directory names, kill off the first (it's always empty).
250
+ names = p.split(/[\\\/]/)
251
+ names.shift
252
+
253
+ # Get the index for this directory
254
+ index = ifs_getIndex(names, miqfs)
255
+ $log.debug "NTFS.ifs_getDir << #{index.nil? ? "Directory not found " : ""}p=#{p}" if $log && $log.debug?
256
+ index
257
+ end
258
+
259
+ # Return DirectoryIndexNode for given directory or nil if not exist.
260
+ def ifs_getIndex(names, miqfs)
261
+ return miqfs.drive_root if names.empty?
262
+
263
+ # Check for this path in the cache.
264
+ fname = names.join('/')
265
+ if miqfs.index_cache.key?(fname)
266
+ miqfs.cache_hits += 1
267
+ return miqfs.index_cache[fname]
268
+ end
269
+
270
+ name = names.pop
271
+ index = ifs_getIndex(names, miqfs)
272
+ return nil if index.nil?
273
+
274
+ din = index.find(name)
275
+ return nil if din.nil?
276
+
277
+ index = din.resolve(miqfs.boot_sector).indexRoot
278
+ return nil if index.nil?
279
+
280
+ miqfs.index_cache[fname] = index
281
+ end
282
+
283
+ # Wack leading drive leter & colon.
284
+ def unnormalizePath(p)
285
+ p[1] == 58 ? p[2, p.size] : p
286
+ end
287
+ end
@@ -0,0 +1,21 @@
1
+ module NTFSProbe
2
+ def self.probe(dobj)
3
+ $log.debug("NTFSProbe >> dobj=#{dobj}") if $log
4
+ unless dobj.kind_of?(MiqDisk)
5
+ $log.debug "NTFSProbe << FALSE because Disk Object class is not MiqDisk, but is '#{dobj.class}'" if $log
6
+ return false
7
+ end
8
+
9
+ # Check for oem name = NTFS.
10
+ dobj.seek(3)
11
+ oem = dobj.read(8).unpack('a8')[0].strip
12
+
13
+ ntfs = oem == 'NTFS'
14
+ if $log
15
+ $log.debug("NTFSProbe << TRUE") if ntfs
16
+ $log.debug("NTFSProbe << FALSE because OEM Name is not NTFS, but is '#{oem}'") unless ntfs
17
+ end
18
+
19
+ ntfs
20
+ end
21
+ end
@@ -0,0 +1,155 @@
1
+ module NativeFS
2
+ MOUNT_DIR = "/miq_mounts"
3
+ VOL_ID = "/KNOPPIX/lib/udev/vol_id"
4
+
5
+ def self.supported?(dobj)
6
+ devNode = dobj.devFile
7
+ fsType = `fstype #{devNode}`.chomp
8
+ $log.debug "NativeFS.supported?: devNode = #{devNode}, fsType = #{fsType}" if $log.debug?
9
+
10
+ return(false) if fsType.empty? || fsType == "auto" || fsType == "swap"
11
+ (true)
12
+ end
13
+
14
+ def fs_init
15
+ dInfo = @dobj.dInfo
16
+ raise "NativeFS: disk is not a local device" unless @dobj.devFile
17
+
18
+ @devNode = @dobj.devFile
19
+
20
+ self.fsType = `fstype #{@devNode}`.chomp
21
+ raise "NativeFS: cannot determine filesystem type for: #{@devNode}" if fsType.empty?
22
+
23
+ @volName = `#{VOL_ID} -l #{@devNode}`.chomp
24
+ @fsId = `#{VOL_ID} -u #{@devNode}`.chomp
25
+
26
+ if dInfo.lvObj
27
+ lv = "#{dInfo.lvObj.vgObj.vgName}-#{dInfo.lvObj.lvName}"
28
+ @mountPoint = File.join(MOUNT_DIR, lv)
29
+ @devNode = File.join("/dev/mapper", lv)
30
+ else
31
+ @mountPoint = File.join(MOUNT_DIR, File.basename(@devNode))
32
+ end
33
+
34
+ if $log.debug?
35
+ $log.debug "NativeFS.fs_init: devNode = #{@devNode}"
36
+ $log.debug "NativeFS.fs_init: fsType = #{fsType}"
37
+ $log.debug "NativeFS.fs_init: volName = #{@volName}"
38
+ $log.debug "NativeFS.fs_init: fsId = #{@fsId}"
39
+ end
40
+
41
+ return if isMounted?(@devNode)
42
+ system("mkdir", "-p", @mountPoint)
43
+ $log.debug "NativeFS.fs_init: mounting #{@devNode} on #{@mountPoint}" if $log.debug?
44
+ unless system("mount", @devNode, @mountPoint)
45
+ raise "NativeFS: Could not mount #{@devNode} on #{@mountPoint}, exit status: #{$?.exitstatus}"
46
+ end
47
+ end
48
+
49
+ def fs_umount
50
+ raise "NativeFS: #{@devNode} is not mounted" if @mountPoint.nil?
51
+ $log.debug "NativeFS.fs_umount: unmounting #{@mountPoint}" if $log.debug?
52
+ unless system("umount", @mountPoint)
53
+ raise "NativeFS: Could not unmount #{@devNode} from #{@mountPoint}, exit status: #{$?.exitstatus}"
54
+ end
55
+ @mountPoint = nil
56
+ end
57
+
58
+ def freeBytes
59
+ raise "NativeFS: #{@devNode} is not mounted" if @mountPoint.nil?
60
+ (`df -lPB1 | grep '#{@mountPoint}$' | awk '{ print $4 }'`.chomp.to_i)
61
+ end
62
+
63
+ def fs_dirEntries(p)
64
+ Dir.entries(internalPath(p))
65
+ end
66
+
67
+ def fs_dirMkdir(p)
68
+ Dir.mkdir(internalPath(p))
69
+ end
70
+
71
+ def dirRmdir(p)
72
+ Dir.rmdir(internalPath(p))
73
+ end
74
+
75
+ def fs_fileDelete(p)
76
+ File.delete(internalPath(p))
77
+ end
78
+
79
+ def fs_fileExists?(p)
80
+ File.exist?(internalPath(p))
81
+ end
82
+
83
+ def fs_fileFile?(p)
84
+ File.file?(internalPath(p))
85
+ end
86
+
87
+ def fs_fileDirectory?(p)
88
+ File.directory? internalPath((p))
89
+ end
90
+
91
+ def fs_fileSize(p)
92
+ File.size(internalPath(p))
93
+ end
94
+
95
+ def fs_fileSize_obj(fobj)
96
+ fobj.stat.size
97
+ end
98
+
99
+ def fs_fileAtime(p)
100
+ File.atime(internalPath(p))
101
+ end
102
+
103
+ def fs_fileCtime(p)
104
+ File.ctime(internalPath(p))
105
+ end
106
+
107
+ def fs_fileMtime(p)
108
+ File.mtime(internalPath(p))
109
+ end
110
+
111
+ def fs_fileAtime_obj(fobj)
112
+ fobj.atime
113
+ end
114
+
115
+ def fs_fileCtime_obj(fobj)
116
+ fobj.ctime
117
+ end
118
+
119
+ def fs_fileMtime_obj(fobj)
120
+ fobj.mtime
121
+ end
122
+
123
+ def fs_fileOpen(p, mode = "r")
124
+ File.new(internalPath(p), mode)
125
+ end
126
+
127
+ def fs_fileSeek(fobj, offset, whence)
128
+ fobj.seek(offset, whence)
129
+ end
130
+
131
+ def fs_fileRead(fobj, len)
132
+ fobj.read(len)
133
+ end
134
+
135
+ def fs_fileWrite(fobj, buf, len)
136
+ return(fobj.write(buf)) if buf.length == len
137
+ return(fobj.write(buf[0, len])) if buf.length > len
138
+ raise "NativeFS.fs_fileWrite: attempt to write passed the end of buffer"
139
+ end
140
+
141
+ def fs_fileClose(fobj)
142
+ fobj.close
143
+ end
144
+
145
+ def internalPath(p)
146
+ raise "NativeFS: #{@devNode} is not mounted" if @mountPoint.nil?
147
+ (File.join(@mountPoint, p))
148
+ end
149
+
150
+ def isMounted?(dev)
151
+ `mount`.each { |ml| return(true) if ml.split(" ", 2)[0] == dev }
152
+ (false)
153
+ end
154
+ private :isMounted?
155
+ end
@@ -0,0 +1,17 @@
1
+ module ReFSProbe
2
+ FS_SIGNATURE = [0x00, 0x00, 0x00, 0x52, 0x65, 0x46, 0x53, 0x00] # ...ReFS.
3
+
4
+ def self.probe(dobj)
5
+ $log.debug "ReFSProbe >> dobj=#{dobj}" if $log
6
+ return false unless dobj.kind_of?(MiqDisk)
7
+
8
+ dobj.seek(0, IO::SEEK_SET)
9
+ magic = dobj.read(FS_SIGNATURE.size).unpack('C*')
10
+
11
+ # Check for ReFS signature
12
+ raise "ReFS is Not Supported" if magic == FS_SIGNATURE
13
+
14
+ # No ReFS
15
+ false
16
+ end
17
+ end
@@ -0,0 +1,79 @@
1
+ module RealFS
2
+ attr_reader :guestOS
3
+
4
+ def fs_init
5
+ case Sys::Platform::IMPL
6
+ when :mswin, :mingw
7
+ self.fsType = "NTFS"
8
+ @guestOS = "Windows"
9
+ when :linux
10
+ self.fsType = `df -lT / | tail -1 | awk '{ print $2 }'`
11
+ @guestOS = "Linux"
12
+ when :macosx
13
+ end
14
+ end
15
+
16
+ def fs_dirEntries(p)
17
+ Dir.entries(p)
18
+ end
19
+
20
+ def fs_fileExists?(p)
21
+ File.exist?(p)
22
+ end
23
+
24
+ def fs_fileFile?(p)
25
+ File.file?(p)
26
+ end
27
+
28
+ def fs_fileDirectory?(p)
29
+ File.directory?(p)
30
+ end
31
+
32
+ def fs_fileSize(p)
33
+ File.size(p)
34
+ end
35
+
36
+ def fs_fileSize_obj(fobj)
37
+ fobj.stat.size
38
+ end
39
+
40
+ def fs_fileAtime(p)
41
+ File.atime(p)
42
+ end
43
+
44
+ def fs_fileCtime(p)
45
+ File.ctime(p)
46
+ end
47
+
48
+ def fs_fileMtime(p)
49
+ File.mtime(p)
50
+ end
51
+
52
+ def fs_fileAtime_obj(fobj)
53
+ fobj.atime
54
+ end
55
+
56
+ def fs_fileCtime_obj(fobj)
57
+ fobj.ctime
58
+ end
59
+
60
+ def fs_fileMtime_obj(fobj)
61
+ fobj.mtime
62
+ end
63
+
64
+ def fs_fileOpen(p, mode = "r")
65
+ File.new(p, mode)
66
+ end
67
+
68
+ def fs_fileSeek(fobj, offset, whence)
69
+ fobj.seek(offset, whence)
70
+ end
71
+
72
+ def fs_fileRead(fobj, len)
73
+ fobj.read(len)
74
+ end
75
+
76
+ def fs_fileClose(fobj)
77
+ fobj.close
78
+ end
79
+ end
@@ -0,0 +1,6 @@
1
+ module RealFSProbe
2
+ def self.probe(dobj)
3
+ return(true) if dobj.to_s == "test_disk"
4
+ (false)
5
+ end
6
+ end
@@ -0,0 +1,18 @@
1
+ module Reiser4Probe
2
+ REISER4_MASTER_OFFSET = 65536
3
+ REISER4_MAGIC_OFFSET = REISER4_MASTER_OFFSET
4
+ REISER4_MAGIC_SIZE = 10
5
+ REISER4_MAGIC = "ReIsEr4"
6
+
7
+ def self.probe(dobj)
8
+ return(false) unless dobj.kind_of?(MiqDisk)
9
+
10
+ # Assume Reiser4 - read magic at offset.
11
+ dobj.seek(REISER4_MAGIC_OFFSET)
12
+ magic = dobj.read(REISER4_MAGIC_SIZE).strip
13
+ raise "Reiser4 is Not Supported" if magic == REISER4_MAGIC
14
+
15
+ # No Reiser4.
16
+ false
17
+ end
18
+ end