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,209 @@
1
+ require 'fs/ReiserFS/utils'
2
+
3
+ module ReiserFS
4
+ class Block
5
+ BLOCK_HEADER = BinaryStruct.new([
6
+ 'v', 'level', # Level of the block in the tree
7
+ 'v', 'nitems', # The number of items in the block
8
+ 'x20', nil # Ignoring the following, as they are not presently used
9
+ # 'v', 'free_space', # Free space left in the block
10
+ # 'a2', 'reserved',
11
+ # 'a16','right_key', # right delimiting key for the block
12
+ ])
13
+ SIZEOF_BLOCK_HEADER = BLOCK_HEADER.size
14
+
15
+ attr_reader :blockNum, :data
16
+
17
+ def initialize(data, bnum)
18
+ @blockNum = bnum
19
+ @data = data
20
+ @bh = BLOCK_HEADER.decode(@data)
21
+ @nitems = @bh['nitems']
22
+ @level = @bh['level']
23
+ @iHeaders = {}
24
+ end
25
+
26
+ def nkeys
27
+ @nitems
28
+ end
29
+
30
+ def npointers
31
+ return 0 if isLeaf?
32
+ @nitems + 1
33
+ end
34
+
35
+ KEY = BinaryStruct.new([
36
+ 'V', 'directory_id',
37
+ 'V', 'object_id',
38
+ 'V', 'offset',
39
+ 'V', 'type'
40
+ ])
41
+ SIZEOF_KEY = KEY.size
42
+
43
+ def data2key(keydata)
44
+ key = KEY.decode(keydata)
45
+ key['type'] = Utils.type2integer(key['type'])
46
+ key
47
+ end
48
+
49
+ # Keys are 1-based
50
+ def getKey(k)
51
+ return nil if k > @nitems || k <= 0
52
+ pos = SIZEOF_BLOCK_HEADER + (SIZEOF_KEY * (k - 1))
53
+ keydata = @data[pos, SIZEOF_KEY]
54
+ data2key(keydata)
55
+ end
56
+
57
+ POINTER = BinaryStruct.new([
58
+ 'V', 'block_number',
59
+ 'v', 'size',
60
+ 'a2', 'reserved',
61
+ ])
62
+ SIZEOF_POINTER = POINTER.size
63
+
64
+ # Pointers are 0-based
65
+ def getPointer(p)
66
+ # puts "getPointer >> p=#{p}"
67
+ return nil if p > @nitems || p < 0
68
+ pos = SIZEOF_BLOCK_HEADER + (SIZEOF_KEY * @nitems) + (SIZEOF_POINTER * p)
69
+ ptrdata = @data[pos, SIZEOF_POINTER]
70
+ POINTER.decode(ptrdata)
71
+ end
72
+
73
+ def findPointer(searchKey)
74
+ # puts "findPointer >> #{dumpKey(searchKey, "searchKey")}"
75
+ (1..@nitems).each do |i|
76
+ currentKey = getKey(i)
77
+ compare = Utils.compareKeys(searchKey, currentKey)
78
+ # puts dumpKey(currentKey, "currentKey(#{i})")
79
+ next if compare > 0
80
+ return getPointer(i - 1) if compare <= 0
81
+ end
82
+ getPointer(@nitems)
83
+ end
84
+
85
+ def findPointers(searchKey)
86
+ pointers = []
87
+ compare = nil
88
+
89
+ (1..@nitems).each do |i|
90
+ currentKey = getKey(i)
91
+ compare = Utils.compareKeys(searchKey, currentKey)
92
+ # puts dumpKey(currentKey, "currentKey(#{i})")
93
+ next if compare > 0
94
+ pointers << getPointer(i - 1)
95
+ break if compare < 0
96
+ end
97
+ pointers << getPointer(@nitems) if pointers.size == 0 || compare == 0
98
+
99
+ pointers
100
+ end
101
+
102
+ ITEM_HEADER = BinaryStruct.new([
103
+ 'a16', 'key',
104
+ 'v', 'count',
105
+ 'v', 'length',
106
+ 'v', 'location',
107
+ 'v', 'version'
108
+ ])
109
+ SIZEOF_ITEM_HEADER = ITEM_HEADER.size
110
+
111
+ def getItemHeaders(key = nil)
112
+ return @iHeadersAll if key.nil? && !@iHeadersAll.nil?
113
+
114
+ did = Utils.getKeyDirectoryID(key) if key
115
+ oid = Utils.getKeyObjectID(key) if key
116
+
117
+ iHeaders = []
118
+ (1..nkeys).each do |i|
119
+ iheader = getItemHeader(i)
120
+ if key
121
+ curKey = iheader['key']
122
+ next if did != Utils.getKeyDirectoryID(curKey)
123
+ next if oid != Utils.getKeyObjectID(curKey)
124
+ end
125
+
126
+ iHeaders << iheader
127
+ end
128
+
129
+ @iHeadersAll = iHeaders if key.nil?
130
+
131
+ iHeaders
132
+ end
133
+
134
+ def getItemHeader(i)
135
+ return @iHeaders[i] if @iHeaders.key?(i)
136
+ return nil if i > @nitems || i <= 0
137
+
138
+ pos = SIZEOF_BLOCK_HEADER + (SIZEOF_ITEM_HEADER * (i - 1))
139
+ iheaddata = @data[pos, SIZEOF_ITEM_HEADER]
140
+ keydata = iheaddata[0, SIZEOF_KEY]
141
+ key = data2key(keydata)
142
+ iheader = ITEM_HEADER.decode(iheaddata)
143
+ iheader['key'] = key
144
+ @iHeaders[i] = iheader
145
+ end
146
+
147
+ def getItemVersion(iheader)
148
+ iheader['version']
149
+ end
150
+
151
+ def getItemCount(iheader)
152
+ iheader['count']
153
+ end
154
+
155
+ def getItemType(iheader)
156
+ iheader['key']['type']
157
+ end
158
+
159
+ def getItem(iheader)
160
+ offset = iheader['location']
161
+ length = iheader['length']
162
+ @data[offset, length]
163
+ end
164
+
165
+ def isLeaf?
166
+ @level == 1
167
+ end
168
+
169
+ def dump
170
+ out = dumpHeader
171
+
172
+ if isLeaf?
173
+ (1..@nitems).each do |i|
174
+ ihead = getItemHeader(i)
175
+ out += dumpItemHeader(ihead, "Item Header #{i}")
176
+ end
177
+ else
178
+ (1..@nitems).each do |i|
179
+ key = getKey(i)
180
+ out += dumpKey(key, "Key #{i}")
181
+ end
182
+ out += "\n"
183
+ (0..@nitems).each do |i|
184
+ ptr = getPointer(i)
185
+ out += dumpPointer(ptr, "Ptr #{i}")
186
+ end
187
+ end
188
+ out
189
+ end
190
+
191
+ def dumpHeader
192
+ "Block Header: blockNum=#{@blockNum} nitems=#{@bh['nitems']} level=#{@bh['level']}\n"
193
+ end
194
+
195
+ def dumpKey(key, label = nil)
196
+ "#{Utils.dumpKey(key, label)}\n"
197
+ end
198
+
199
+ def dumpPointer(ptr, label = nil)
200
+ "#{label}:\t\{#{ptr['block_number']},#{ptr['size']}\}\n"
201
+ end
202
+
203
+ def dumpItemHeader(ihead, label = nil)
204
+ key = ihead['key']
205
+ keystring = "\{#{key['directory_id']},#{key['object_id']},#{key['offset']},#{key['type']}\}"
206
+ "#{label}:\t\{#{keystring},#{ihead['count']},#{ihead['length']},#{ihead['location']},#{ihead['version']}\}\n"
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,136 @@
1
+ # encoding: US-ASCII
2
+
3
+ require 'fs/ReiserFS/utils'
4
+ require 'fs/ReiserFS/directory_entry'
5
+
6
+ module ReiserFS
7
+ class Directory
8
+ ROOT_DIR = {'directory_id' => 1, 'object_id' => 2, 'offset' => 0, 'type' => 0}
9
+
10
+ attr_accessor :key, :sb
11
+
12
+ ###################################################################
13
+ # A directory is composed of 2 things: Key and BlockNum
14
+ # Key is in the form of {doid,oid,offset,type}
15
+ # BlockNum is what is used to actually instantiate the Block object
16
+ #
17
+ # Note: BlockNum can always be computed from Key and the ROOT_DIR
18
+ ###################################################################
19
+ def initialize(sb, key = nil)
20
+ raise "Nil superblock" if sb.nil?
21
+ @sb = sb
22
+ @key = key.nil? ? ROOT_DIR : key
23
+ @leaves = @sb.getLeafNodes(@key)
24
+ @dirEntry = nil
25
+ @dirItems = nil
26
+
27
+ raise "Key #{Utils.dumpKey(@key)} NOT found" if @leaves.nil?
28
+
29
+ @leaves.each do |leaf|
30
+ leaf.getItemHeaders.each do |iheader|
31
+ @dirEntry = DirectoryEntry.new(leaf, iheader, @key) if Utils.typeIsStat?(leaf.getItemType(iheader))
32
+ end
33
+ end
34
+ end
35
+
36
+ def findKey(name)
37
+ initDirItems
38
+ if @dirItems.key?(name)
39
+ hash = @dirItems[name]
40
+ return hash['key']
41
+ end
42
+
43
+ nil
44
+ end
45
+
46
+ def findEntry(name)
47
+ initDirItems
48
+ if @dirItems.key?(name)
49
+ hash = @dirItems[name]
50
+ unless hash.key?('dirEntry')
51
+ hash['dirEntry'] = createDirectoryEntry(hash['key'])
52
+ @dirItems[name] = hash
53
+ end
54
+ return hash['dirEntry']
55
+ end
56
+
57
+ nil
58
+ end
59
+
60
+ def globNames
61
+ if @names.nil?
62
+ initDirItems
63
+ @names = @dirItems.keys
64
+ @names.sort!
65
+ end
66
+
67
+ @names
68
+ end
69
+
70
+ #################
71
+
72
+ private
73
+
74
+ def createDirectoryEntry(key)
75
+ @sb.getLeafNodes(key).each do |leaf|
76
+ leaf.getItemHeaders(key).each do |iheader|
77
+ return DirectoryEntry.new(leaf, iheader, key) if Utils.typeIsStat?(leaf.getItemType(iheader))
78
+ end
79
+ end
80
+ nil
81
+ end
82
+
83
+ def initDirItems
84
+ return @dirItems unless @dirItems.nil?
85
+
86
+ @dirItems = {}
87
+ @leaves.each do |leaf|
88
+ leaf.getItemHeaders(@key).each do |ih|
89
+ if Utils.typeIsDirectory?(leaf.getItemType(ih))
90
+ getDirItems(leaf, ih).each do |item|
91
+ name = item['name']
92
+ @dirItems[name] = item
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
98
+
99
+ ITEM_DIRECTORY = BinaryStruct.new([
100
+ 'V', 'offset',
101
+ 'V', 'directory_id',
102
+ 'V', 'object_id',
103
+ 'v', 'location',
104
+ 'v', 'state',
105
+ ])
106
+ SIZEOF_ITEM_DIRECTORY = ITEM_DIRECTORY.size
107
+
108
+ def getDirItems(b, i)
109
+ item = b.getItem(i)
110
+ count = b.getItemCount(i)
111
+ last = 0
112
+
113
+ dirItems = []
114
+ (1..count).each do |d|
115
+ offset = SIZEOF_ITEM_DIRECTORY * (d - 1)
116
+ length = SIZEOF_ITEM_DIRECTORY
117
+ dir = ITEM_DIRECTORY.decode(item[offset, length])
118
+ gen, hash = item[offset, 4].unpack('B7B24')
119
+ dir['gen'] = gen.to_i(2)
120
+ dir['hash'] = hash.to_i(2)
121
+ dir['key'] = {'directory_id' => dir['directory_id'], 'object_id' => dir['object_id'], 'offset' => 0, 'type' => 0}
122
+ dir['name'] = getASCIIZ(item[dir['location']..(last - 1)])
123
+ last = dir['location']
124
+
125
+ dirItems << dir
126
+ end
127
+ dirItems
128
+ end
129
+
130
+ def getASCIIZ(data)
131
+ i = data.index("\0")
132
+ return data if i.nil?
133
+ data[0..i - 1]
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,140 @@
1
+ require 'fs/ReiserFS/utils'
2
+
3
+ module ReiserFS
4
+ class DirectoryEntry
5
+ ITEM_STAT_V1 = BinaryStruct.new([
6
+ 'v', 'mode',
7
+ 'v', 'nlinks',
8
+ 'v', 'uid',
9
+ 'v', 'gid',
10
+ 'V', 'size',
11
+ 'V', 'atime',
12
+ 'V', 'mtime',
13
+ 'V', 'ctime',
14
+ 'V', 'nblocks',
15
+ 'V', 'first'
16
+ ])
17
+ SIZEOF_ITEM_STAT_V1 = ITEM_STAT_V1.size
18
+
19
+ ITEM_STAT_V2 = BinaryStruct.new([
20
+ 'v', 'mode',
21
+ 'a2', 'reserved',
22
+ 'V', 'nlinks',
23
+ 'Q', 'size',
24
+ 'V', 'uid',
25
+ 'V', 'gid',
26
+ 'V', 'atime',
27
+ 'V', 'mtime',
28
+ 'V', 'ctime',
29
+ 'V', 'nblocks',
30
+ 'V', 'first'
31
+ ])
32
+ SIZEOF_ITEM_STAT_V2 = ITEM_STAT_V2.size
33
+
34
+ # Bits 0 to 8 of file mode.
35
+ PF_O_EXECUTE = 0x0001 # owner execute
36
+ PF_O_WRITE = 0x0002 # owner write
37
+ PF_O_READ = 0x0004 # owner read
38
+ PF_G_EXECUTE = 0x0008 # group execute
39
+ PF_G_WRITE = 0x0010 # group write
40
+ PF_G_READ = 0x0020 # group read
41
+ PF_U_EXECUTE = 0x0040 # user execute
42
+ PF_U_WRITE = 0x0080 # user write
43
+ PF_U_READ = 0x0100 # user read
44
+
45
+ # For accessor convenience.
46
+ MSK_PERM_OWNER = (PF_O_EXECUTE | PF_O_WRITE | PF_O_READ)
47
+ MSK_PERM_GROUP = (PF_G_EXECUTE | PF_G_WRITE | PF_G_READ)
48
+ MSK_PERM_USER = (PF_U_EXECUTE | PF_U_WRITE | PF_U_READ)
49
+
50
+ # Bits 9 to 11 of file mode.
51
+ DF_STICKY = 0x0200
52
+ DF_SET_GID = 0x0400
53
+ DF_SET_UID = 0x0800
54
+
55
+ # Bits 12 to 15 of file mode.
56
+ FM_FIFO = 0x1000 # fifo device (pipe)
57
+ FM_CHAR = 0x2000 # char device
58
+ FM_DIRECTORY = 0x4000 # directory
59
+ FM_BLOCK_DEV = 0x6000 # block device
60
+ FM_FILE = 0x8000 # regular file
61
+ FM_SYM_LNK = 0xa000 # symbolic link
62
+ FM_SOCKET = 0xc000 # socket device
63
+
64
+ # For accessor convenience.
65
+ MSK_FILE_MODE = 0xf000
66
+ MSK_IS_DEV = (FM_FIFO | FM_CHAR | FM_BLOCK_DEV | FM_SOCKET)
67
+
68
+ attr_reader :key, :blockObj
69
+
70
+ def initialize(blockObj, itemHeader, key)
71
+ @itemHeader = itemHeader
72
+ @blockObj = blockObj
73
+ @key = key
74
+ @data = @blockObj.getItem(itemHeader)
75
+ @version = @blockObj.getItemVersion(itemHeader)
76
+
77
+ statStruct = @version == 0 ? ITEM_STAT_V1 : ITEM_STAT_V2
78
+ statSize = @version == 0 ? SIZEOF_ITEM_STAT_V1 : SIZEOF_ITEM_STAT_V2
79
+ raise "Stat Structure Length Inconsistency" if statSize != @data.length
80
+ @stat = statStruct.decode(@data)
81
+ @mode = @stat['mode']
82
+ end
83
+
84
+ def isDir?
85
+ @mode & FM_DIRECTORY == FM_DIRECTORY
86
+ end
87
+
88
+ def isFile?
89
+ @mode & FM_FILE == FM_FILE
90
+ end
91
+
92
+ def isDev?
93
+ @mode & MSK_IS_DEV > 0
94
+ end
95
+
96
+ def isSymLink?
97
+ @mode & FM_SYM_LNK == FM_SYM_LNK
98
+ end
99
+
100
+ def permissions
101
+ @mode & (MSK_PERM_OWNER | MSK_PERM_GROUP | MSK_PERM_USER)
102
+ end
103
+
104
+ def ownerPermissions
105
+ @mode & MSK_PERM_OWNER
106
+ end
107
+
108
+ def groupPermissions
109
+ @mode & MSK_PERM_GROUP
110
+ end
111
+
112
+ def userPermissions
113
+ @mode & MSK_PERM_USER
114
+ end
115
+
116
+ def uid
117
+ @stat['uid']
118
+ end
119
+
120
+ def gid
121
+ @stat['gid']
122
+ end
123
+
124
+ def aTime
125
+ Time.at(@stat['atime'])
126
+ end
127
+
128
+ def cTime
129
+ Time.at(@stat['ctime'])
130
+ end
131
+
132
+ def mTime
133
+ Time.at(@stat['mtime'])
134
+ end
135
+
136
+ def length
137
+ @stat['size']
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,111 @@
1
+ require 'fs/ReiserFS/utils'
2
+
3
+ module ReiserFS
4
+ class FileData
5
+ attr_reader :pos
6
+
7
+ # Initialization
8
+ def initialize(dirEntry, superblock)
9
+ raise "Nil dirEntry object" if dirEntry.nil?
10
+ raise "Nil superblock" if superblock.nil?
11
+
12
+ @sb = superblock
13
+ @de = dirEntry
14
+ @key = @de.key
15
+ @len = @de.length
16
+ @blocks = []
17
+
18
+ # puts "Key=#{Utils.dumpKey(@key)} datalen=#{@len}"
19
+
20
+ @sb.getLeafNodes(@key).each do |leaf|
21
+ leaf.getItemHeaders(@key).each do |ih|
22
+ next if Utils.typeIsStat?(leaf.getItemType(ih))
23
+ raise "Directory Node when FileData expected" if Utils.typeIsDirectory?(leaf.getItemType(ih))
24
+
25
+ if Utils.typeIsDirect?(leaf.getItemType(ih))
26
+ @blocks << {:blockNum => leaf.blockNum, :offset => ih['location'], :length => ih['length'], :blockObj => leaf}
27
+ end
28
+
29
+ if Utils.typeIsIndirect?(leaf.getItemType(ih))
30
+ leaf.getItem(ih).unpack("V*").each do |blockNum|
31
+ @blocks << {:blockNum => blockNum, :offset => 0, :length => @sb.blockSize}
32
+ end
33
+ end
34
+ end
35
+ end
36
+
37
+ @bpos = []
38
+ pos = 0
39
+ @blocks.each do |b|
40
+ @bpos << pos
41
+ pos += b[:length]
42
+ end
43
+
44
+ @blen = @blocks[0][:length]
45
+
46
+ # @blocks.each { |b| puts "Block(#{b['blockNum']}): len=#{b['length']} offset=#{b['offset']}" }
47
+
48
+ rewind
49
+ end
50
+
51
+ def findIndex(pos)
52
+ index = pos / @blen
53
+ index -= 1 while @bpos[index] > pos
54
+ index += 1 while @bpos[index + 1] && (@bpos[index + 1] < pos)
55
+ index
56
+ end
57
+
58
+ def rewind
59
+ @pos = 0
60
+ end
61
+
62
+ def seek(offset, method = IO::SEEK_SET)
63
+ @pos = case method
64
+ when IO::SEEK_SET then offset
65
+ when IO::SEEK_CUR then @pos + offset
66
+ when IO::SEEK_END then @len - offset
67
+ end
68
+ @pos = 0 if @pos < 0
69
+ @pos = @len if @pos > @len
70
+ @pos
71
+ end
72
+
73
+ def read(bytes = @len)
74
+ return nil if @pos >= @len
75
+
76
+ index = findIndex(@pos)
77
+ out = ""
78
+
79
+ while out.length < bytes
80
+ b = @blocks[index]
81
+ pos = @bpos[index]
82
+ index += 1
83
+
84
+ blockLength = b[:length]
85
+ blockLength = (@len - pos) if (pos + blockLength) > @len
86
+
87
+ # Do we have to start reading from an offset?
88
+ byteOffset = (pos < @pos) ? (@pos - pos) : 0
89
+
90
+ # Get the block with data
91
+ b[:blockObj] = @sb.readBlock(b[:blockNum]) unless b.key?(:blockObj)
92
+ blockObj = b[:blockObj]
93
+
94
+ # Extract the data we need out of it
95
+ blockOffset = b[:offset]
96
+ out << blockObj.data[blockOffset + byteOffset, blockLength - byteOffset]
97
+ end
98
+
99
+ bytes = out.length if bytes > out.length
100
+ @pos += bytes
101
+
102
+ out[0, bytes]
103
+ end
104
+
105
+ def write(buf, _len = buf.length)
106
+ raise "Write functionality is not yet supported on ReiserFS."
107
+ end
108
+
109
+ private
110
+ end # class
111
+ end # module