manageiq-smartstate 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +4 -0
- data/.rspec_ci +4 -0
- data/.travis.yml +15 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +202 -0
- data/README.md +45 -0
- data/Rakefile +23 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/MiqContainerGroup/MiqContainerGroup.rb +31 -0
- data/lib/MiqVm/MiqLocalVm.rb +50 -0
- data/lib/MiqVm/MiqRhevmVm.rb +179 -0
- data/lib/MiqVm/MiqVm.rb +355 -0
- data/lib/MiqVm/miq_azure_vm.rb +96 -0
- data/lib/MiqVm/miq_scvmm_vm.rb +38 -0
- data/lib/MiqVm/test/camcorder_fleece_test.rb +60 -0
- data/lib/MiqVm/test/localVm.rb +45 -0
- data/lib/MiqVm/test/partitionAlignmentCheck.rb +76 -0
- data/lib/MiqVm/test/remoteVm.rb +65 -0
- data/lib/MiqVm/test/rhevmNfsTest.rb +62 -0
- data/lib/MiqVm/test/rhevmNfsTest2.rb +66 -0
- data/lib/MiqVm/test/rhevmTest.rb +70 -0
- data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackCommon.rb +107 -0
- data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackImage.rb +67 -0
- data/lib/OpenStackExtract/MiqOpenStackVm/MiqOpenStackInstance.rb +182 -0
- data/lib/Scvmm/miq_hyperv_disk.rb +273 -0
- data/lib/Scvmm/miq_scvmm_parse_powershell.rb +75 -0
- data/lib/Scvmm/miq_scvmm_vm_ssa_info.rb +135 -0
- data/lib/Scvmm/test/miq_hyperv_disk_test.rb +33 -0
- data/lib/Scvmm/test/miq_scvmm_vm_ssa_info_test.rb +41 -0
- data/lib/VmLocalDiskAccess/test/localCfg.rb +97 -0
- data/lib/VolumeManager/LVM/logical_volume.rb +75 -0
- data/lib/VolumeManager/LVM/lv_segment.rb +43 -0
- data/lib/VolumeManager/LVM/lvm2disk.rb +158 -0
- data/lib/VolumeManager/LVM/parser.rb +138 -0
- data/lib/VolumeManager/LVM/physical_volume.rb +19 -0
- data/lib/VolumeManager/LVM/scanner.rb +156 -0
- data/lib/VolumeManager/LVM/thin/btree.rb +83 -0
- data/lib/VolumeManager/LVM/thin/constants.rb +86 -0
- data/lib/VolumeManager/LVM/thin/data_map.rb +44 -0
- data/lib/VolumeManager/LVM/thin/mapping_tree.rb +19 -0
- data/lib/VolumeManager/LVM/thin/space_maps.rb +58 -0
- data/lib/VolumeManager/LVM/thin/superblock.rb +136 -0
- data/lib/VolumeManager/LVM/thin.rb +6 -0
- data/lib/VolumeManager/LVM/volume_group.rb +97 -0
- data/lib/VolumeManager/LVM.rb +8 -0
- data/lib/VolumeManager/MiqLdm.rb +546 -0
- data/lib/VolumeManager/MiqLvm.rb +17 -0
- data/lib/VolumeManager/MiqNativeVolumeManager.rb +150 -0
- data/lib/VolumeManager/MiqVolumeManager.rb +277 -0
- data/lib/VolumeManager/VolMgrPlatformSupport.rb +18 -0
- data/lib/VolumeManager/VolMgrPlatformSupportLinux.rb +77 -0
- data/lib/VolumeManager/VolMgrPlatformSupportWin.rb +17 -0
- data/lib/VolumeManager/test/blockDevTest.rb +40 -0
- data/lib/VolumeManager/test/ldm.rb +97 -0
- data/lib/blackbox/VmBlackBox.rb +103 -0
- data/lib/blackbox/xmlStorage.rb +180 -0
- data/lib/db/MiqBdb/MiqBdb.rb +309 -0
- data/lib/db/MiqBdb/MiqBdbBtree.rb +219 -0
- data/lib/db/MiqBdb/MiqBdbHash.rb +199 -0
- data/lib/db/MiqBdb/MiqBdbPage.rb +159 -0
- data/lib/db/MiqBdb/MiqBdbUtil.rb +18 -0
- data/lib/db/MiqSqlite/MiqSqlite3.rb +330 -0
- data/lib/db/MiqSqlite/MiqSqlite3Cell.rb +167 -0
- data/lib/db/MiqSqlite/MiqSqlite3Page.rb +151 -0
- data/lib/db/MiqSqlite/MiqSqlite3Table.rb +124 -0
- data/lib/db/MiqSqlite/MiqSqlite3Util.rb +32 -0
- data/lib/disk/DiskProbe.rb +68 -0
- data/lib/disk/MiqDisk.rb +317 -0
- data/lib/disk/camcorder_test.rb +90 -0
- data/lib/disk/dos_mbr.img +0 -0
- data/lib/disk/modules/AzureBlobDisk.rb +101 -0
- data/lib/disk/modules/LocalDevMod.rb +47 -0
- data/lib/disk/modules/LocalDevProbe.rb +6 -0
- data/lib/disk/modules/MSCommon.rb +352 -0
- data/lib/disk/modules/MSVSDiffDisk.rb +91 -0
- data/lib/disk/modules/MSVSDiskProbe.rb +61 -0
- data/lib/disk/modules/MSVSDynamicDisk.rb +42 -0
- data/lib/disk/modules/MSVSFixedDisk.rb +45 -0
- data/lib/disk/modules/MiqLargeFile.rb +63 -0
- data/lib/disk/modules/MiqLargeFileWin32.rb +107 -0
- data/lib/disk/modules/QcowDisk.rb +692 -0
- data/lib/disk/modules/QcowDiskProbe.rb +34 -0
- data/lib/disk/modules/RawBlockIO.rb +116 -0
- data/lib/disk/modules/RawDisk.rb +45 -0
- data/lib/disk/modules/RawDiskProbe.rb +7 -0
- data/lib/disk/modules/RhevmDescriptor.rb +167 -0
- data/lib/disk/modules/RhevmDiskProbe.rb +52 -0
- data/lib/disk/modules/VMWareCowdDisk.rb +207 -0
- data/lib/disk/modules/VMWareDescriptor.rb +214 -0
- data/lib/disk/modules/VMWareDiskProbe.rb +74 -0
- data/lib/disk/modules/VMWareSparseDisk.rb +189 -0
- data/lib/disk/modules/VhdxDisk.rb +625 -0
- data/lib/disk/modules/VhdxDiskProbe.rb +46 -0
- data/lib/disk/modules/VixDiskMod.rb +54 -0
- data/lib/disk/modules/VixDiskProbe.rb +6 -0
- data/lib/disk/modules/miq_disk_cache.rb +135 -0
- data/lib/disk/modules/miq_dummy_disk.rb +41 -0
- data/lib/disk/modules/vhdx_bat_entry.rb +10 -0
- data/lib/disk/test.rb +66 -0
- data/lib/fs/MetakitFS/MetakitFS.rb +530 -0
- data/lib/fs/MetakitFS/test/Makefile +14 -0
- data/lib/fs/MetakitFS/test/MkCollectFiles.rb +165 -0
- data/lib/fs/MetakitFS/test/MkSelectFiles.rb +30 -0
- data/lib/fs/MetakitFS/test/collect_files.yaml +70 -0
- data/lib/fs/MetakitFS/test/init.rb +3 -0
- data/lib/fs/MetakitFS/test/mk2vmdk.rb +64 -0
- data/lib/fs/MetakitFS/test/mk4test.c +92 -0
- data/lib/fs/MetakitFS/test/mkFsTest.rb +113 -0
- data/lib/fs/MetakitFS/test/proto.rb +97 -0
- data/lib/fs/MiqFS/FsProbe.rb +39 -0
- data/lib/fs/MiqFS/MiqFS.rb +515 -0
- data/lib/fs/MiqFS/modules/AUFSProbe.rb +26 -0
- data/lib/fs/MiqFS/modules/Ext3.rb +305 -0
- data/lib/fs/MiqFS/modules/Ext3Probe.rb +25 -0
- data/lib/fs/MiqFS/modules/Ext4.rb +304 -0
- data/lib/fs/MiqFS/modules/Ext4Probe.rb +25 -0
- data/lib/fs/MiqFS/modules/Fat32.rb +318 -0
- data/lib/fs/MiqFS/modules/Fat32Probe.rb +30 -0
- data/lib/fs/MiqFS/modules/HFSProbe.rb +18 -0
- data/lib/fs/MiqFS/modules/Iso9660.rb +293 -0
- data/lib/fs/MiqFS/modules/Iso9660Probe.rb +18 -0
- data/lib/fs/MiqFS/modules/LocalFS.rb +105 -0
- data/lib/fs/MiqFS/modules/NTFS.rb +287 -0
- data/lib/fs/MiqFS/modules/NTFSProbe.rb +21 -0
- data/lib/fs/MiqFS/modules/NativeFS.rb +155 -0
- data/lib/fs/MiqFS/modules/ReFSProbe.rb +17 -0
- data/lib/fs/MiqFS/modules/RealFS.rb +79 -0
- data/lib/fs/MiqFS/modules/RealFSProbe.rb +6 -0
- data/lib/fs/MiqFS/modules/Reiser4Probe.rb +18 -0
- data/lib/fs/MiqFS/modules/ReiserFS.rb +315 -0
- data/lib/fs/MiqFS/modules/ReiserFSProbe.rb +42 -0
- data/lib/fs/MiqFS/modules/UnionFSProbe.rb +18 -0
- data/lib/fs/MiqFS/modules/WebDAV.rb +127 -0
- data/lib/fs/MiqFS/modules/WebDAVFile.rb +68 -0
- data/lib/fs/MiqFS/modules/XFS.rb +300 -0
- data/lib/fs/MiqFS/modules/XFSProbe.rb +26 -0
- data/lib/fs/MiqFS/modules/ZFSProbe.rb +18 -0
- data/lib/fs/MiqFS/test.rb +59 -0
- data/lib/fs/MiqFsUtil.rb +383 -0
- data/lib/fs/MiqMountManager.rb +209 -0
- data/lib/fs/MiqNativeMountManager.rb +101 -0
- data/lib/fs/MountManagerProbe.rb +29 -0
- data/lib/fs/ReiserFS/block.rb +209 -0
- data/lib/fs/ReiserFS/directory.rb +136 -0
- data/lib/fs/ReiserFS/directory_entry.rb +140 -0
- data/lib/fs/ReiserFS/file_data.rb +111 -0
- data/lib/fs/ReiserFS/superblock.rb +140 -0
- data/lib/fs/ReiserFS/utils.rb +95 -0
- data/lib/fs/VimDatastoreFS/VimDatastoreFS.rb +192 -0
- data/lib/fs/ext3/alloc_bitmap.rb +38 -0
- data/lib/fs/ext3/block_pointers_path.rb +130 -0
- data/lib/fs/ext3/directory.rb +51 -0
- data/lib/fs/ext3/directory_entry.rb +67 -0
- data/lib/fs/ext3/ex_attrib_header.rb +14 -0
- data/lib/fs/ext3/ex_attrib_name.rb +23 -0
- data/lib/fs/ext3/file_data.rb +130 -0
- data/lib/fs/ext3/group_descriptor_entry.rb +65 -0
- data/lib/fs/ext3/group_descriptor_table.rb +54 -0
- data/lib/fs/ext3/hash_tree_entry.rb +18 -0
- data/lib/fs/ext3/hash_tree_header.rb +15 -0
- data/lib/fs/ext3/inode.rb +228 -0
- data/lib/fs/ext3/posix_acl_entry.rb +29 -0
- data/lib/fs/ext3/posix_acl_header.rb +11 -0
- data/lib/fs/ext3/superblock.rb +406 -0
- data/lib/fs/ext3/test/tc_Ext3BlockPointersPath.rb +74 -0
- data/lib/fs/ext4/alloc_bitmap.rb +38 -0
- data/lib/fs/ext4/directory.rb +87 -0
- data/lib/fs/ext4/directory_entry.rb +77 -0
- data/lib/fs/ext4/ex_attrib_header.rb +14 -0
- data/lib/fs/ext4/ex_attrib_name.rb +23 -0
- data/lib/fs/ext4/extent.rb +35 -0
- data/lib/fs/ext4/extent_header.rb +40 -0
- data/lib/fs/ext4/extent_index.rb +33 -0
- data/lib/fs/ext4/group_descriptor_entry.rb +69 -0
- data/lib/fs/ext4/group_descriptor_table.rb +54 -0
- data/lib/fs/ext4/hash_tree_entry.rb +58 -0
- data/lib/fs/ext4/hash_tree_header.rb +35 -0
- data/lib/fs/ext4/inode.rb +465 -0
- data/lib/fs/ext4/posix_acl_entry.rb +29 -0
- data/lib/fs/ext4/posix_acl_header.rb +11 -0
- data/lib/fs/ext4/superblock.rb +412 -0
- data/lib/fs/fat32/boot_sect.rb +379 -0
- data/lib/fs/fat32/directory.rb +222 -0
- data/lib/fs/fat32/directory_entry.rb +540 -0
- data/lib/fs/fat32/file_data.rb +128 -0
- data/lib/fs/iso9660/boot_sector.rb +170 -0
- data/lib/fs/iso9660/directory.rb +90 -0
- data/lib/fs/iso9660/directory_entry.rb +147 -0
- data/lib/fs/iso9660/file_data.rb +78 -0
- data/lib/fs/iso9660/rock_ridge.rb +329 -0
- data/lib/fs/iso9660/util.rb +57 -0
- data/lib/fs/modules/LinuxMount.rb +300 -0
- data/lib/fs/modules/LinuxMountProbe.rb +29 -0
- data/lib/fs/modules/WinMount.rb +97 -0
- data/lib/fs/modules/WinMountProbe.rb +24 -0
- data/lib/fs/ntfs/attrib_attribute_list.rb +131 -0
- data/lib/fs/ntfs/attrib_bitmap.rb +26 -0
- data/lib/fs/ntfs/attrib_data.rb +74 -0
- data/lib/fs/ntfs/attrib_file_name.rb +110 -0
- data/lib/fs/ntfs/attrib_header.rb +194 -0
- data/lib/fs/ntfs/attrib_index_allocation.rb +19 -0
- data/lib/fs/ntfs/attrib_index_root.rb +247 -0
- data/lib/fs/ntfs/attrib_object_id.rb +40 -0
- data/lib/fs/ntfs/attrib_standard_information.rb +107 -0
- data/lib/fs/ntfs/attrib_type.rb +49 -0
- data/lib/fs/ntfs/attrib_volume_information.rb +53 -0
- data/lib/fs/ntfs/attrib_volume_name.rb +31 -0
- data/lib/fs/ntfs/boot_sect.rb +253 -0
- data/lib/fs/ntfs/data_run.rb +358 -0
- data/lib/fs/ntfs/directory_index_node.rb +114 -0
- data/lib/fs/ntfs/index_node_header.rb +69 -0
- data/lib/fs/ntfs/index_record_header.rb +85 -0
- data/lib/fs/ntfs/mft_entry.rb +288 -0
- data/lib/fs/ntfs/utils.rb +43 -0
- data/lib/fs/test/camcorder_fs_test.rb +108 -0
- data/lib/fs/test/collect_files_direct.yaml +22 -0
- data/lib/fs/test/collect_files_in.yaml +24 -0
- data/lib/fs/test/collect_files_in_nc.yaml +22 -0
- data/lib/fs/test/collect_files_out.yaml +6 -0
- data/lib/fs/test/collect_files_rm.yaml +6 -0
- data/lib/fs/test/copyTest.rb +126 -0
- data/lib/fs/test/fsTest.rb +87 -0
- data/lib/fs/test/updateTest.rb +184 -0
- data/lib/fs/xfs/allocation_group.rb +160 -0
- data/lib/fs/xfs/bmap_btree_block.rb +125 -0
- data/lib/fs/xfs/bmap_btree_record.rb +80 -0
- data/lib/fs/xfs/bmap_btree_root_node.rb +72 -0
- data/lib/fs/xfs/directory.rb +133 -0
- data/lib/fs/xfs/directory2_data_header.rb +27 -0
- data/lib/fs/xfs/directory3_data_header.rb +34 -0
- data/lib/fs/xfs/directory_block_tail.rb +22 -0
- data/lib/fs/xfs/directory_data_header.rb +46 -0
- data/lib/fs/xfs/directory_entry.rb +106 -0
- data/lib/fs/xfs/inode.rb +532 -0
- data/lib/fs/xfs/inode_map.rb +100 -0
- data/lib/fs/xfs/short_form_directory_entry.rb +91 -0
- data/lib/fs/xfs/short_form_header.rb +44 -0
- data/lib/fs/xfs/superblock.rb +556 -0
- data/lib/lib/tasks/azure.rake +52 -0
- data/lib/manageiq/smartstate/version.rb +5 -0
- data/lib/manageiq/smartstate.rb +7 -0
- data/lib/manageiq-smartstate.rb +1 -0
- data/lib/metadata/MIQExtract/MIQExtract.rb +297 -0
- data/lib/metadata/MIQExtract/test/extractTest.rb +41 -0
- data/lib/metadata/MIQExtract/test/full_extract_test.rb +68 -0
- data/lib/metadata/ScanProfile/HostScanItem.rb +4 -0
- data/lib/metadata/ScanProfile/HostScanProfile.rb +4 -0
- data/lib/metadata/ScanProfile/HostScanProfiles.rb +41 -0
- data/lib/metadata/ScanProfile/ScanItemBase.rb +63 -0
- data/lib/metadata/ScanProfile/ScanProfileBase.rb +51 -0
- data/lib/metadata/ScanProfile/ScanProfilesBase.rb +60 -0
- data/lib/metadata/ScanProfile/VmScanItem.rb +4 -0
- data/lib/metadata/ScanProfile/VmScanProfile.rb +4 -0
- data/lib/metadata/ScanProfile/VmScanProfiles.rb +38 -0
- data/lib/metadata/ScanProfile/modules/HostScanItemFile.rb +51 -0
- data/lib/metadata/ScanProfile/modules/HostScanItemNteventlog.rb +84 -0
- data/lib/metadata/ScanProfile/modules/VmScanItemFile.rb +39 -0
- data/lib/metadata/ScanProfile/modules/VmScanItemNteventlog.rb +34 -0
- data/lib/metadata/ScanProfile/modules/VmScanItemRegistry.rb +64 -0
- data/lib/metadata/VMMount/VMMount.rb +81 -0
- data/lib/metadata/VMMount/VMPlatformMount.rb +18 -0
- data/lib/metadata/VMMount/VMPlatformMountLinux.rb +75 -0
- data/lib/metadata/VMMount/VMPlatformMountWin.rb +13 -0
- data/lib/metadata/VmConfig/GetNativeCfg.rb +45 -0
- data/lib/metadata/VmConfig/VmConfig.rb +947 -0
- data/lib/metadata/VmConfig/cfgConfig.rb +45 -0
- data/lib/metadata/VmConfig/ovfConfig.rb +99 -0
- data/lib/metadata/VmConfig/test/GetVMwareCfgTest.rb +40 -0
- data/lib/metadata/VmConfig/vmcConfig.rb +116 -0
- data/lib/metadata/VmConfig/vmtxConfig.rb +4 -0
- data/lib/metadata/VmConfig/vmxConfig.rb +162 -0
- data/lib/metadata/VmConfig/xmlConfig.rb +79 -0
- data/lib/metadata/VmConfig/xmlMsHyperVConfig.rb +41 -0
- data/lib/metadata/linux/InitProcHash.rb +632 -0
- data/lib/metadata/linux/LinuxInitProcs.rb +142 -0
- data/lib/metadata/linux/LinuxOSInfo.rb +237 -0
- data/lib/metadata/linux/LinuxPackages.rb +209 -0
- data/lib/metadata/linux/LinuxSystemd.rb +130 -0
- data/lib/metadata/linux/LinuxUsers.rb +289 -0
- data/lib/metadata/linux/LinuxUtils.rb +197 -0
- data/lib/metadata/linux/MiqConaryPackages.rb +41 -0
- data/lib/metadata/linux/MiqRpmPackages.rb +160 -0
- data/lib/metadata/linux/test/Name +0 -0
- data/lib/metadata/linux/test/Packages +0 -0
- data/lib/metadata/linux/test/rpoTest.rb +5 -0
- data/lib/metadata/linux/test/tc_LinuxUtils.rb +4157 -0
- data/lib/metadata/util/event_log_filter.rb +61 -0
- data/lib/metadata/util/md5deep.rb +280 -0
- data/lib/metadata/util/win32/Win32Accounts.rb +764 -0
- data/lib/metadata/util/win32/Win32EventLog.rb +743 -0
- data/lib/metadata/util/win32/Win32Services.rb +86 -0
- data/lib/metadata/util/win32/Win32Software.rb +326 -0
- data/lib/metadata/util/win32/Win32System.rb +333 -0
- data/lib/metadata/util/win32/boot_info_win.rb +59 -0
- data/lib/metadata/util/win32/fleece_hives.rb +220 -0
- data/lib/metadata/util/win32/ms-registry.rb +650 -0
- data/lib/metadata/util/win32/peheader.rb +868 -0
- data/lib/metadata/util/win32/remote-registry.rb +142 -0
- data/lib/metadata/util/win32/system_path_win.rb +103 -0
- data/lib/metadata/util/win32/versioninfo.rb +17 -0
- data/manageiq-smartstate.gemspec +35 -0
- metadata +486 -0
@@ -0,0 +1,329 @@
|
|
1
|
+
require 'sys-uname'
|
2
|
+
|
3
|
+
require 'binary_struct'
|
4
|
+
require 'util/miq-unicode'
|
5
|
+
|
6
|
+
module Iso9660
|
7
|
+
# SUSP extensions are present if the first two characters of the SUA of
|
8
|
+
# the first directory entry are "SP". After SUSP is identified, if the
|
9
|
+
# first two characters of any directory entry's SUA are "RR" a Rock Ridge
|
10
|
+
# extension is active for that entry. The particular extension is
|
11
|
+
# identified by the two characters after the next two bytes following "RR".
|
12
|
+
|
13
|
+
# NOTE: This implementation is sufficient for Rock Ridge extensions. It will
|
14
|
+
# not identify or process any other System Use Sharing Protocol extensions.
|
15
|
+
# In particular, SUSP CE (continuation area) records are not processed. This
|
16
|
+
# is where the "RR" extension is defined. This implementation uses the
|
17
|
+
# assumed definition RR_HEADER.
|
18
|
+
|
19
|
+
RR_SIGNATURE = "RR"
|
20
|
+
RR_HEADER = BinaryStruct.new([
|
21
|
+
'a2', 'signature', # RR if Rock Ridge.
|
22
|
+
'C', 'unused1', # ? always seems to be 5.
|
23
|
+
'C', 'unused2', # ? always seems to be 1 (version?).
|
24
|
+
'C', 'unused3' # ? 0x81
|
25
|
+
])
|
26
|
+
RR_HEADER_SIZE = 5
|
27
|
+
|
28
|
+
# These types are not used, but we want to know if they pop up.
|
29
|
+
RR_PN_SIGNATURE = "PN"
|
30
|
+
RR_CL_SIGNATURE = "CL"
|
31
|
+
RR_PL_SIGNATURE = "PL"
|
32
|
+
RR_RE_SIGNATURE = "RE"
|
33
|
+
RR_TF_SIGNATURE = "TF"
|
34
|
+
|
35
|
+
# POSIX file attributes. See POSIX 5.6.1.
|
36
|
+
RR_PX_SIGNATURE = "PX"
|
37
|
+
RR_PX = BinaryStruct.new([
|
38
|
+
'L', 'modeLE', # file mode (used to identify a link).
|
39
|
+
'L', 'modeBE',
|
40
|
+
'L', 'linksLE', # Num links (st_nlink).
|
41
|
+
'L', 'linksBE',
|
42
|
+
'L', 'userLE', # User ID.
|
43
|
+
'L', 'userBE',
|
44
|
+
'L', 'groupLE', # Group ID.
|
45
|
+
'L', 'groupBE'
|
46
|
+
# 'L', 'serialLE', # File serial number.
|
47
|
+
# 'L', 'serialBE'
|
48
|
+
])
|
49
|
+
# NOTE: IEEE P1282 specifies that file serial number is included, but
|
50
|
+
# real data shows this number is absent. Likewise, the spec says the
|
51
|
+
# struct length is 44 bytes, where real data shows a length of 36 bytes.
|
52
|
+
# It's also worth noting that the real data shows a structure version
|
53
|
+
# of 1, so there is definitely disagreement betweeen theory (IEEE P1282)
|
54
|
+
# and reality (the Open Solaris developer edition distro iso).
|
55
|
+
|
56
|
+
# File mode bits.
|
57
|
+
RR_EXT_SL_FM_SOCK = 0xc000
|
58
|
+
RR_EXT_SL_FM_LINK = 0xa000
|
59
|
+
RR_EXT_SL_FM_FILE = 0x8000
|
60
|
+
RR_EXT_SL_FM_BLOK = 0x6000
|
61
|
+
RR_EXT_SL_FM_CHAR = 0x2000
|
62
|
+
RR_EXT_SL_FM_DIR = 0x4000
|
63
|
+
RR_EXT_SL_FM_FIFO = 0x1000
|
64
|
+
|
65
|
+
class PosixAttributes
|
66
|
+
attr_reader :flags
|
67
|
+
|
68
|
+
def initialize(data, suff)
|
69
|
+
@flags = 0
|
70
|
+
@suff = suff
|
71
|
+
@px = RR_PX.decode(data)
|
72
|
+
end
|
73
|
+
|
74
|
+
def mode
|
75
|
+
@px["mode#{@suff}"]
|
76
|
+
end
|
77
|
+
|
78
|
+
def nlinks
|
79
|
+
@px["links#{@suff}"]
|
80
|
+
end
|
81
|
+
|
82
|
+
def user
|
83
|
+
@px["user#{@suff}"]
|
84
|
+
end
|
85
|
+
|
86
|
+
def group
|
87
|
+
@px["group#{@suff}"]
|
88
|
+
end
|
89
|
+
|
90
|
+
def isFile?
|
91
|
+
mode & RR_EXT_SL_FM_FILE != 0
|
92
|
+
end
|
93
|
+
|
94
|
+
def isDir?
|
95
|
+
mode & RR_EXT_SL_FM_DIR != 0
|
96
|
+
end
|
97
|
+
|
98
|
+
def isSymLink?
|
99
|
+
mode & RR_EXT_SL_FM_LINK != 0
|
100
|
+
end
|
101
|
+
end # class PosixAttributes
|
102
|
+
|
103
|
+
# Symbolic link.
|
104
|
+
RR_SL_SIGNATURE = "SL"
|
105
|
+
RR_SL = BinaryStruct.new([
|
106
|
+
'C', 'flags', # See RR_EXT_SLF_ below.
|
107
|
+
'a*', 'components'
|
108
|
+
])
|
109
|
+
|
110
|
+
# Symbolic link flags.
|
111
|
+
RR_EXT_SLF_CONTINUE = 0x01 # Link continues in the next SL entry.
|
112
|
+
|
113
|
+
# A symbolic link component record.
|
114
|
+
RR_SL_COMPONENT = BinaryStruct.new([
|
115
|
+
'C', 'flags', # See RR_EXT_SLCOMPF_ below.
|
116
|
+
'C', 'length', # Length of content in bytes.
|
117
|
+
'a*', 'content'
|
118
|
+
])
|
119
|
+
|
120
|
+
RR_EXT_SLCOMPF_CONTINUE = 0x01 # Component continues in the next component record.
|
121
|
+
RR_EXT_SLCOMPF_CURRENT = 0x02 # Component refers to the current directory.
|
122
|
+
RR_EXT_SLCOMPF_PARENT = 0x04 # Component refers to the parent directory.
|
123
|
+
RR_EXT_SLCOMPF_ROOT = 0x08 # Component refers to the root directory.
|
124
|
+
RR_EXT_SLCOMPF_RESERVED1 = 0x10 # See below.
|
125
|
+
RR_EXT_CLCOMPF_RESERVED2 = 0x20 # See below.
|
126
|
+
# RESERVED1: Historically, this component has referred to the directory on
|
127
|
+
# which the current CD-ROM is mounted.
|
128
|
+
# Reserved2: Historically, this component has contained the network node
|
129
|
+
# name of the current system as defined in the uname structure of POSIX 4.4.1.2
|
130
|
+
|
131
|
+
class SymbolicLink
|
132
|
+
attr_reader :flags
|
133
|
+
attr_accessor :linkData
|
134
|
+
|
135
|
+
def initialize(data, _suff)
|
136
|
+
sl = RR_SL.decode(data)
|
137
|
+
|
138
|
+
# Reader data.
|
139
|
+
@flags = sl['flags']
|
140
|
+
@linkData = assembleComponents(sl['components'])
|
141
|
+
end
|
142
|
+
|
143
|
+
def assembleComponents(data)
|
144
|
+
out = ""; offset = 0
|
145
|
+
loop do
|
146
|
+
comp = RR_SL_COMPONENT.decode(data[offset..-1])
|
147
|
+
|
148
|
+
# Check for referential flags.
|
149
|
+
out += "./" if comp['flags'] & RR_EXT_SLCOMPF_CURRENT != 0
|
150
|
+
out += "../" if comp['flags'] & RR_EXT_SLCOMPF_PARENT != 0
|
151
|
+
out += "/" if comp['flags'] & RR_EXT_SLCOMPF_ROOT != 0
|
152
|
+
|
153
|
+
# Advance offset, append content (if any) & check for done.
|
154
|
+
# puts "Component content:"
|
155
|
+
# comp['content'][0, comp['length']].hex_dump(:obj => STDOUT, :meth => :puts, :newline => false)
|
156
|
+
# puts "\n\n"
|
157
|
+
offset += comp['length'] + 2 # compensate for first two bytes of component.
|
158
|
+
next if comp['length'] == 0
|
159
|
+
out = File.join(out, comp['content'][0, comp['length']])
|
160
|
+
# break if comp['flags'] & RR_EXT_SLCOMPF_CONTINUE == 0
|
161
|
+
# Analysis of real data shows the condition is offset >= data len.
|
162
|
+
break if offset >= data.length
|
163
|
+
end
|
164
|
+
# puts "Total content:"
|
165
|
+
# out.hex_dump(:obj => STDOUT, :meth => :puts, :newline => false)
|
166
|
+
# puts "\n\n"
|
167
|
+
out
|
168
|
+
end
|
169
|
+
end # class SymbolicLink
|
170
|
+
|
171
|
+
# Alternate name.
|
172
|
+
RR_NM_SIGNATURE = "NM"
|
173
|
+
RR_NM = BinaryStruct.new([
|
174
|
+
'C', 'flags', # See RR_EXT_NMF_ below.
|
175
|
+
'a*', 'content'
|
176
|
+
])
|
177
|
+
|
178
|
+
# NOTE: These flag bits are mutually exclusive.
|
179
|
+
RR_EXT_NMF_CONTINUE = 0x01 # Name continues in the next NM entry.
|
180
|
+
RR_EXT_NMF_CURRENT = 0x02 # Name refers to the current directory.
|
181
|
+
RR_EXT_NMF_PARENT = 0x04 # Name refers to the parent directory.
|
182
|
+
RR_EXT_NMF_RESERVED1 = 0x08 # Reserved - 0.
|
183
|
+
RR_EXT_NMF_RESERVED2 = 0x10 # Reserved - 0.
|
184
|
+
RR_EXT_NMF_RESERVED3 = 0x20 # Implementation specific.
|
185
|
+
# NOTE: IEEE-P1282 lists the following note about RESERVED3:
|
186
|
+
# Historically, this component has contained the network node name of
|
187
|
+
# the current system as defined in the uname structure of POSIX 4.4.1.2
|
188
|
+
|
189
|
+
class AlternateName
|
190
|
+
attr_reader :flags
|
191
|
+
attr_accessor :name
|
192
|
+
|
193
|
+
def initialize(data, _suff)
|
194
|
+
an = RR_NM.decode(data)
|
195
|
+
|
196
|
+
# Check for referential flags.
|
197
|
+
@name = ""
|
198
|
+
@name += "./" if an['flags'] & RR_EXT_NMF_CURRENT != 0
|
199
|
+
@name += "../" if an['flags'] & RR_EXT_NMF_PARENT != 0
|
200
|
+
raise "RR extension NM: RESERVED3 flag is set." if an['flags'] & RR_EXT_NMF_RESERVED3 != 0
|
201
|
+
|
202
|
+
# Reader data.
|
203
|
+
@flags = an['flags']
|
204
|
+
@name += an['content']
|
205
|
+
end
|
206
|
+
end # class AlternateName
|
207
|
+
|
208
|
+
# Sparse File.
|
209
|
+
RR_SF_SIGNATURE = "SF"
|
210
|
+
RR_SF = BinaryStruct.new([
|
211
|
+
'L', 'size_hiLE',
|
212
|
+
'L', 'size_hiBE',
|
213
|
+
'L', 'size_loLE',
|
214
|
+
'L', 'size_loBE',
|
215
|
+
'C', 'table_depth',
|
216
|
+
])
|
217
|
+
|
218
|
+
# Um, sparse file is pretty complicated so I'm just going to get the
|
219
|
+
# first three going and then worry about this.
|
220
|
+
|
221
|
+
class SparseFile
|
222
|
+
attr_reader :length, :fileData, :flags
|
223
|
+
|
224
|
+
def initialize(data, suff)
|
225
|
+
@sf = RR_SF.decode(data)
|
226
|
+
@flags = 0
|
227
|
+
@suff = suff
|
228
|
+
raise "Sparse file."
|
229
|
+
end
|
230
|
+
|
231
|
+
def length
|
232
|
+
(@sf["size_hi#{@suff}"] << 32) + @sf["size_lo#{@suff}"]
|
233
|
+
end
|
234
|
+
end # class SparseFile
|
235
|
+
|
236
|
+
# Common to all RR extensions.
|
237
|
+
RR_EXT_HEADER = BinaryStruct.new([
|
238
|
+
'a2', 'signature', # Extension type.
|
239
|
+
'C', 'length', # length in bytes.
|
240
|
+
'C', 'version' # Entry version, always 1.
|
241
|
+
])
|
242
|
+
RR_EXT_HEADER_SIZE = 4
|
243
|
+
|
244
|
+
class Extension
|
245
|
+
attr_reader :length, :ext
|
246
|
+
|
247
|
+
def initialize(data, suff)
|
248
|
+
# Get extension header, length & data.
|
249
|
+
@header = RR_EXT_HEADER.decode(data)
|
250
|
+
@length = @header['length']
|
251
|
+
data = data[RR_EXT_HEADER_SIZE, @length - RR_EXT_HEADER_SIZE]
|
252
|
+
# puts "Extension data (from Extension):"
|
253
|
+
# data.hex_dump(:obj => STDOUT, :meth => :puts, :newline => false)
|
254
|
+
# puts "\n\n"
|
255
|
+
|
256
|
+
# Delegate to extension.
|
257
|
+
@ext = case @header['signature']
|
258
|
+
when RR_PX_SIGNATURE then PosixAttributes.new(data, suff)
|
259
|
+
when RR_PN_SIGNATURE then warnAbout(RR_PN_SIGNATURE, data)
|
260
|
+
when RR_SL_SIGNATURE then SymbolicLink.new(data, suff)
|
261
|
+
when RR_NM_SIGNATURE then AlternateName.new(data, suff)
|
262
|
+
when RR_CL_SIGNATURE then warnAbout(RR_CL_SIGNATURE, data)
|
263
|
+
when RR_PL_SIGNATURE then warnAbout(RR_PL_SIGNATURE, data)
|
264
|
+
when RR_RE_SIGNATURE then warnAbout(RR_RE_SIGNATURE, data)
|
265
|
+
when RR_TF_SIGNATURE then warnAbout(RR_TF_SIGNATURE, data)
|
266
|
+
when RR_SF_SIGNATURE then SparseFile.new(data, suff)
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
def warnAbout(ext, data)
|
271
|
+
if $log
|
272
|
+
$log.debug("RR extension #{ext} found, not processed. Data is:")
|
273
|
+
data.hex_dump(:obj => $log, :meth => :debug, :newline => false)
|
274
|
+
end
|
275
|
+
nil
|
276
|
+
end
|
277
|
+
end # class Extension
|
278
|
+
|
279
|
+
class RockRidge
|
280
|
+
SUSP_SIZE = 7
|
281
|
+
CONTINUE = 1
|
282
|
+
|
283
|
+
attr_reader :extensions
|
284
|
+
|
285
|
+
def initialize(de, suff)
|
286
|
+
raise "No DirectoryEntry specified." if de.nil?
|
287
|
+
raise "The specified DirectoryEntry has no System Use Area." if de.sua.nil?
|
288
|
+
|
289
|
+
# Root directories need to skip SUSP header.
|
290
|
+
offset = de.name == "." ? SUSP_SIZE : 0
|
291
|
+
|
292
|
+
# Get the RR header from the DirectoryEntry & verify.
|
293
|
+
@header = RR_HEADER.decode(de.sua[offset..-1])
|
294
|
+
raise "This is not a Rock Ridge extension record" if @header['signature'] != RR_SIGNATURE
|
295
|
+
|
296
|
+
# Loop through extensions.
|
297
|
+
offset += RR_HEADER_SIZE
|
298
|
+
@extensions = []
|
299
|
+
loop do
|
300
|
+
# puts "Extension data:
|
301
|
+
# de.sua[offset..-1].hex_dump(:obj => STDOUT, :meth => :puts, :newline => false)
|
302
|
+
# puts "\n\n"
|
303
|
+
ext = Extension.new(de.sua[offset..-1], suff)
|
304
|
+
@extensions << ext
|
305
|
+
offset += ext.length
|
306
|
+
break if offset >= de.sua.length
|
307
|
+
end
|
308
|
+
|
309
|
+
# Handle continuations.
|
310
|
+
0.upto(@extensions.size - 1) do |idx|
|
311
|
+
obj = @extensions[idx]
|
312
|
+
next if obj.nil?
|
313
|
+
|
314
|
+
# TODO: Simplify this - the meat of all extensions is .data
|
315
|
+
if obj.flags & CONTINUE
|
316
|
+
if obj.kind_of?(AlternateName)
|
317
|
+
obj.name += @extensions[idx + 1].name
|
318
|
+
@extensions[idx + 1] = nil
|
319
|
+
end
|
320
|
+
if obj.kind_of?(SymbolicLink)
|
321
|
+
obj.linkData += @extensions[idx + 1].linkData
|
322
|
+
@extensions[idx + 1] = nil
|
323
|
+
end
|
324
|
+
end
|
325
|
+
end
|
326
|
+
@extensions.delete(nil)
|
327
|
+
end
|
328
|
+
end # class RockRidge
|
329
|
+
end # module
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# encoding: US-ASCII
|
2
|
+
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
require 'binary_struct'
|
6
|
+
|
7
|
+
module Iso9660
|
8
|
+
module Util
|
9
|
+
ISO_DATE = BinaryStruct.new([
|
10
|
+
'a4', 'year', # Absolute year.
|
11
|
+
'a2', 'month',
|
12
|
+
'a2', 'day',
|
13
|
+
'a2', 'hour',
|
14
|
+
'a2', 'min',
|
15
|
+
'a2', 'sec',
|
16
|
+
'a2', 'hun',
|
17
|
+
'c', 'offset' # 15-min intervals (iow 4 per time zone).
|
18
|
+
])
|
19
|
+
|
20
|
+
ISO_DATE_SHORT = BinaryStruct.new([
|
21
|
+
'C', 'year', # Since 1900.
|
22
|
+
'C', 'month',
|
23
|
+
'C', 'day',
|
24
|
+
'C', 'hour',
|
25
|
+
'C', 'min',
|
26
|
+
'C', 'sec',
|
27
|
+
'c', 'offset' # 15-min intervals.
|
28
|
+
])
|
29
|
+
|
30
|
+
def self.IsoToRubyDate(isodate)
|
31
|
+
begin
|
32
|
+
tv = OpenStruct.new(ISO_DATE.decode(isodate))
|
33
|
+
rescue
|
34
|
+
return Time.at(0).gmtime
|
35
|
+
end
|
36
|
+
Time.gm(tv.sec, tv.min, tv.hour, tv.day, tv.month, tv.year, nil, nil, nil, tv.offset / 4)
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.GetTimezone(isodate)
|
40
|
+
isodate[16, 1].unpack('c')[0] / 4
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.IsoShortToRubyDate(isoShort)
|
44
|
+
return Time.at(0).gmtime if isoShort == "\0" * 7
|
45
|
+
begin
|
46
|
+
tv = OpenStruct.new(ISO_DATE_SHORT.decode(isoShort))
|
47
|
+
rescue
|
48
|
+
return Time.at(0).gmtime
|
49
|
+
end
|
50
|
+
Time.gm(tv.sec, tv.min, tv.hour, tv.day, tv.month, tv.year + 1900, nil, nil, nil, tv.offset / 4)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.GetShortTimezone(isoShort)
|
54
|
+
isoShort[7] / 4
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,300 @@
|
|
1
|
+
require 'fs/MiqFS/MiqFS'
|
2
|
+
|
3
|
+
module LinuxMount
|
4
|
+
FSTAB_FILE_NAME = "/etc/fstab"
|
5
|
+
|
6
|
+
def fs_init
|
7
|
+
@guestOS = "Linux"
|
8
|
+
|
9
|
+
@rootFS = MiqFS.getFS(@rootVolume)
|
10
|
+
raise "LinuxMount: could not mount root volume" unless @rootFS
|
11
|
+
|
12
|
+
#
|
13
|
+
# Assign device letters to all ide and scsi devices,
|
14
|
+
# even if they're not visible volumes. We need to do
|
15
|
+
# this to assign the proper device names to visible
|
16
|
+
# devices.
|
17
|
+
#
|
18
|
+
sdLetter = 'a'
|
19
|
+
ideMap = {"ide0:0" => "a", "ide0:1" => "b", "ide1:0" => "c", "ide1:1" => "d"}
|
20
|
+
@devHash = {}
|
21
|
+
@vmConfig.getAllDiskKeys.each do |dk|
|
22
|
+
if dk =~ /^ide.*$/
|
23
|
+
@devHash[dk] = "/dev/hd" + ideMap[dk]
|
24
|
+
$log.debug "LinuxMount: devHash[#{dk}] = /dev/hd#{ideMap[dk]}" if $log.debug?
|
25
|
+
elsif dk =~ /^scsi.*$/
|
26
|
+
@devHash[dk] = "/dev/sd" + sdLetter
|
27
|
+
$log.debug "LinuxMount: devHash[#{dk}] = /dev/sd#{sdLetter}" if $log.debug?
|
28
|
+
sdLetter.succ!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
#
|
33
|
+
# Build hash for fstab fs_spec look up.
|
34
|
+
#
|
35
|
+
fsSpecHash = {}
|
36
|
+
@volumes.each do |v|
|
37
|
+
$log.debug "LinuxMount: Volume = #{v.dInfo.localDev} (#{v.dInfo.hardwareId}, partition = #{v.partNum})" if $log.debug?
|
38
|
+
if v == @rootVolume
|
39
|
+
fs = @rootFS
|
40
|
+
else
|
41
|
+
unless (fs = MiqFS.getFS(v))
|
42
|
+
$log.debug "LinuxMount: No filesystem on Volume: #{v.dInfo.localDev}, partition = #{v.partNum}" if $log.debug?
|
43
|
+
next
|
44
|
+
end
|
45
|
+
end
|
46
|
+
@allFileSystems << fs
|
47
|
+
|
48
|
+
#
|
49
|
+
# Specific file systems can be identified by fs UUID
|
50
|
+
# or file system volume label.
|
51
|
+
#
|
52
|
+
unless fs.volName.empty?
|
53
|
+
$log.debug "LinuxMount: adding \"LABEL=#{fs.volName}\" to fsSpecHash" if $log.debug?
|
54
|
+
fsSpecHash["LABEL=#{fs.volName}"] = fs
|
55
|
+
$log.debug "LinuxMount: adding \"LABEL=/#{fs.volName}\" to fsSpecHash" if $log.debug?
|
56
|
+
fsSpecHash["LABEL=/#{fs.volName}"] = fs
|
57
|
+
end
|
58
|
+
unless fs.fsId.empty?
|
59
|
+
$log.debug "LinuxMount: adding \"UUID=#{fs.fsId}\" to fsSpecHash" if $log.debug?
|
60
|
+
fsSpecHash["UUID=#{fs.fsId}"] = fs
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# Logical volumes can be identified by their lv specific
|
65
|
+
# entries under /dev.
|
66
|
+
#
|
67
|
+
if v.dInfo.lvObj
|
68
|
+
lvName = v.dInfo.lvObj.lvName
|
69
|
+
vgName = v.dInfo.lvObj.vgObj.vgName
|
70
|
+
fsSpecHash["/dev/#{vgName}/#{lvName}"] = fs
|
71
|
+
fsSpecHash["/dev/mapper/#{vgName.gsub('-','--')}-#{lvName.gsub('-','--')}"] = fs
|
72
|
+
fsSpecHash["UUID=#{v.dInfo.lvObj.lvId}"] = fs
|
73
|
+
$log.debug "LinuxMount: Volume = #{v.dInfo.localDev}, partition = #{v.partNum} is a logical volume" if $log.debug?
|
74
|
+
next
|
75
|
+
end
|
76
|
+
|
77
|
+
#
|
78
|
+
# Physical volumes are identified by entries under
|
79
|
+
# /dev based on OS hardware scan.
|
80
|
+
# TODO: support physical volume UUIDs
|
81
|
+
#
|
82
|
+
$log.debug "LinuxMount: v.dInfo.hardwareId = #{v.dInfo.hardwareId}" if $log.debug?
|
83
|
+
if v.partNum == 0
|
84
|
+
fsSpecHash[@devHash[v.dInfo.hardwareId]] = fs
|
85
|
+
else
|
86
|
+
fsSpecHash[@devHash[v.dInfo.hardwareId] + v.partNum.to_s] = fs
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
#
|
91
|
+
# Assign OS-specific names to all physical volumes.
|
92
|
+
#
|
93
|
+
@osNames = {}
|
94
|
+
@volMgr.allPhysicalVolumes.each do |v|
|
95
|
+
if $log.debug?
|
96
|
+
$log.debug "LinuxMount: v.dInfo.hardwareId = #{v.dInfo.hardwareId}"
|
97
|
+
$log.debug "LinuxMount: v.partNum.to_s = #{v.partNum}"
|
98
|
+
$log.debug "LinuxMount: @devHash[v.dInfo.hardwareId] = #{@devHash[v.dInfo.hardwareId]}"
|
99
|
+
end
|
100
|
+
@osNames[v.dInfo.hardwareId + ':' + v.partNum.to_s] = @devHash[v.dInfo.hardwareId] + v.partNum.to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Build a tree of file systems and their associated mont points.
|
105
|
+
#
|
106
|
+
root_added = false
|
107
|
+
@mountPoints = {}
|
108
|
+
$log.debug "LinuxMount: processing #{FSTAB_FILE_NAME}" if $log.debug?
|
109
|
+
@rootFS.fileOpen(FSTAB_FILE_NAME, &:read).each_line do |fstl|
|
110
|
+
$log.debug "LinuxMount: fstab line: #{fstl}" if $log.debug?
|
111
|
+
next if fstl =~ /^#.*$/ || fstl =~ /^\s*$/
|
112
|
+
fsSpec, mtPoint = fstl.split(/\s+/)
|
113
|
+
$log.debug "LinuxMount: fsSpec: #{fsSpec}, mtPoint: #{mtPoint}" if $log.debug?
|
114
|
+
next if fsSpec == "none" || mtPoint == "swap"
|
115
|
+
next unless (fs = fsSpecHash[fsSpec])
|
116
|
+
$log.debug "LinuxMount: Adding fsSpec: #{fsSpec}, mtPoint: #{mtPoint}" if $log.debug?
|
117
|
+
addMountPoint(mtPoint, fs, fsSpec)
|
118
|
+
root_added = true if mtPoint == '/'
|
119
|
+
end
|
120
|
+
saveFs(@rootFS, "/", "ROOT") unless root_added
|
121
|
+
end # def fs_init
|
122
|
+
|
123
|
+
#
|
124
|
+
# Given a path to a file, return true if it's a symbolic link.
|
125
|
+
# Otherwise, return false.
|
126
|
+
#
|
127
|
+
def fileSymLink?(p)
|
128
|
+
#
|
129
|
+
# We can't just expand the links in the whole path,
|
130
|
+
# because then, the target file will no longer be a link.
|
131
|
+
# So, we expand the path to the target file, then open
|
132
|
+
# the target file through that path to obtain the link data.
|
133
|
+
#
|
134
|
+
np = normalizePath(p)
|
135
|
+
d = File.dirname(np)
|
136
|
+
f = File.basename(np)
|
137
|
+
|
138
|
+
# Expand the path to the target file.
|
139
|
+
exp_dir = expandLinks(d)
|
140
|
+
|
141
|
+
# Get the file system where the target file resides, and it's local path.
|
142
|
+
fs, lp = getFsPathBase(File.join(exp_dir, f))
|
143
|
+
(fs.fileSymLink?(lp))
|
144
|
+
end
|
145
|
+
|
146
|
+
#
|
147
|
+
# Given a path to a symbolic link, return the full
|
148
|
+
# path to where the link points.
|
149
|
+
#
|
150
|
+
def getLinkPath(p)
|
151
|
+
#
|
152
|
+
# We can't just expand the links in the whole path,
|
153
|
+
# because then, the target file will no longer be a link.
|
154
|
+
# So, we expand the path to the target file, then open
|
155
|
+
# the target file through that path to obtain the link data.
|
156
|
+
#
|
157
|
+
np = normalizePath(p)
|
158
|
+
d = File.dirname(np)
|
159
|
+
f = File.basename(np)
|
160
|
+
|
161
|
+
# Expand the path to the target file.
|
162
|
+
exp_dir = expandLinks(d)
|
163
|
+
|
164
|
+
# Get the file system where the target file resides, and it's local path.
|
165
|
+
fs, lp = getFsPathBase(File.join(exp_dir, f))
|
166
|
+
# Read the link data from the file, through its file system.
|
167
|
+
sp = getSymLink(fs, lp)
|
168
|
+
# Construct and return the full path to the link target.
|
169
|
+
return(sp) if sp[0, 1] == '/'
|
170
|
+
(normalizePath(File.join(exp_dir, sp)))
|
171
|
+
end
|
172
|
+
|
173
|
+
private
|
174
|
+
|
175
|
+
def normalizePath(p)
|
176
|
+
# When running on windows, File.expand_path will add a drive letter.
|
177
|
+
# Remove it if it's there.
|
178
|
+
np = File.expand_path(p, @cwd).gsub(/^[a-zA-Z]:/, "")
|
179
|
+
# puts "LinuxMount::normalizePath: p = #{p}, np = #{np}"
|
180
|
+
(np)
|
181
|
+
end
|
182
|
+
|
183
|
+
class PathNode
|
184
|
+
attr_accessor :children, :fs
|
185
|
+
|
186
|
+
def initialize
|
187
|
+
@children = {}
|
188
|
+
@fs = nil
|
189
|
+
end
|
190
|
+
end # def PathNode
|
191
|
+
|
192
|
+
#
|
193
|
+
# Add the file system to the mount point tree.
|
194
|
+
#
|
195
|
+
def addMountPoint(mp, fs, fsSpec)
|
196
|
+
saveFs(fs, mp, fsSpec)
|
197
|
+
return if mp == '/'
|
198
|
+
path = mp.split('/')
|
199
|
+
path.delete("")
|
200
|
+
h = @mountPoints
|
201
|
+
tn = nil
|
202
|
+
path.each do |d|
|
203
|
+
h[d] = PathNode.new unless h[d]
|
204
|
+
tn = h[d]
|
205
|
+
h = h[d].children
|
206
|
+
end
|
207
|
+
tn.fs = fs if tn
|
208
|
+
end
|
209
|
+
|
210
|
+
#
|
211
|
+
# Expand symbolic links and perform mount indirection look up.
|
212
|
+
#
|
213
|
+
def getFsPath(path)
|
214
|
+
if path.kind_of? Array
|
215
|
+
if path.length == 0
|
216
|
+
localPath = @cwd
|
217
|
+
else
|
218
|
+
localPath = normalizePath(path[0])
|
219
|
+
end
|
220
|
+
else
|
221
|
+
localPath = normalizePath(path)
|
222
|
+
end
|
223
|
+
|
224
|
+
p = getFsPathBase(expandLinks(localPath))
|
225
|
+
# getFsPathBase(path)
|
226
|
+
end
|
227
|
+
|
228
|
+
#
|
229
|
+
# Mount indirection look up.
|
230
|
+
# Given a path, return its corresponding file system
|
231
|
+
# and the part of the path relative to that file system.
|
232
|
+
# It assumes symbolic links have already been expanded.
|
233
|
+
#
|
234
|
+
def getFsPathBase(path)
|
235
|
+
if path.kind_of? Array
|
236
|
+
if path.length == 0
|
237
|
+
localPath = @cwd
|
238
|
+
else
|
239
|
+
localPath = normalizePath(path[0])
|
240
|
+
end
|
241
|
+
else
|
242
|
+
localPath = normalizePath(path)
|
243
|
+
end
|
244
|
+
|
245
|
+
fs = @rootFS
|
246
|
+
p = localPath.split('/')
|
247
|
+
p.delete("")
|
248
|
+
|
249
|
+
h = @mountPoints
|
250
|
+
while d = p.shift
|
251
|
+
return fs, localPath unless h[d]
|
252
|
+
if tfs = h[d].fs
|
253
|
+
fs = tfs
|
254
|
+
localPath = '/' + p.join('/')
|
255
|
+
end
|
256
|
+
h = h[d].children
|
257
|
+
end
|
258
|
+
return fs, localPath
|
259
|
+
end
|
260
|
+
|
261
|
+
#
|
262
|
+
# Expand symbolic links in the path.
|
263
|
+
# This must be done here, because a symlink in one file system
|
264
|
+
# can point to a file in another filesystem.
|
265
|
+
#
|
266
|
+
def expandLinks(p)
|
267
|
+
cp = '/'
|
268
|
+
components = p.split('/')
|
269
|
+
components.shift if components[0] == "" # root
|
270
|
+
|
271
|
+
#
|
272
|
+
# For each component of the path, check to see
|
273
|
+
# if it's a symbolic link. If so, expand it
|
274
|
+
# relative to its base directory.
|
275
|
+
#
|
276
|
+
components.each do |c|
|
277
|
+
ncp = File.join(cp, c)
|
278
|
+
#
|
279
|
+
# Each file system know how to check for,
|
280
|
+
# and read its own links.
|
281
|
+
#
|
282
|
+
fs, lp = getFsPathBase(ncp)
|
283
|
+
if fs.fileSymLink?(lp)
|
284
|
+
sl = getSymLink(fs, lp)
|
285
|
+
if sl[0, 1] == '/'
|
286
|
+
cp = sl
|
287
|
+
else
|
288
|
+
cp = File.join(cp, sl)
|
289
|
+
end
|
290
|
+
else
|
291
|
+
cp = ncp
|
292
|
+
end
|
293
|
+
end
|
294
|
+
(cp)
|
295
|
+
end
|
296
|
+
|
297
|
+
def getSymLink(fs, p)
|
298
|
+
fs.fileOpen(p, &:read)
|
299
|
+
end
|
300
|
+
end # module LinuxMount
|