summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2018-12-12 11:09:19 +0100
committerSimon Rettberg2018-12-12 11:17:59 +0100
commit9e8553a71645e225c6d702e6e1c1ee865f824af7 (patch)
tree6010b46dd96963bb87ff4e52aba5f8b4db05f118
parentRPC Version 5, MIN_VERSION 4 (diff)
downloadmaster-sync-shared-9e8553a71645e225c6d702e6e1c1ee865f824af7.tar.gz
master-sync-shared-9e8553a71645e225c6d702e6e1c1ee865f824af7.tar.xz
master-sync-shared-9e8553a71645e225c6d702e6e1c1ee865f824af7.zip
DiskImage: Support split vmdk files with plain text header
Closes #3505
-rw-r--r--src/main/java/org/openslx/util/vm/DiskImage.java38
1 files changed, 23 insertions, 15 deletions
diff --git a/src/main/java/org/openslx/util/vm/DiskImage.java b/src/main/java/org/openslx/util/vm/DiskImage.java
index fc57e79..ed8f5db 100644
--- a/src/main/java/org/openslx/util/vm/DiskImage.java
+++ b/src/main/java/org/openslx/util/vm/DiskImage.java
@@ -71,9 +71,14 @@ public class DiskImage
LOGGER.debug( "Validating disk file: " + disk.getAbsolutePath() );
try ( RandomAccessFile file = new RandomAccessFile( disk, "r" ) ) {
// vmdk
- if ( file.readInt() == VMDK_MAGIC ) {
- file.seek( 512 );
- byte[] buffer = new byte[ 2048 ];
+ boolean isVmdkMagic = ( file.readInt() == VMDK_MAGIC );
+ if ( isVmdkMagic || file.length() < 4096 ) {
+ if ( isVmdkMagic ) {
+ file.seek( 512 );
+ } else {
+ file.seek( 0 );
+ }
+ byte[] buffer = new byte[ (int)Math.min( 2048, file.length() ) ];
file.readFully( buffer );
VmwareConfig config;
try {
@@ -82,20 +87,23 @@ public class DiskImage
config = null;
}
if ( config != null ) {
- subFormat = config.get( "createType" );
+ String sf = config.get( "createType" );
String parent = config.get( "parentCID" );
- this.isStandalone = isStandaloneCreateType( subFormat, parent );
- this.isCompressed = subFormat != null && subFormat.equalsIgnoreCase( "streamOptimized" );
- this.isSnapshot = parent != null && !parent.equalsIgnoreCase( "ffffffff" );
- this.format = ImageFormat.VMDK;
- String hwv = config.get( "ddb.virtualHWVersion" );
- if ( hwv == null ) {
- this.hwVersion = 10;
- } else {
- this.hwVersion = Util.parseInt( hwv, 10 );
+ if ( sf != null || parent != null ) {
+ subFormat = sf;
+ this.isStandalone = isStandaloneCreateType( subFormat, parent );
+ this.isCompressed = subFormat != null && subFormat.equalsIgnoreCase( "streamOptimized" );
+ this.isSnapshot = parent != null && !parent.equalsIgnoreCase( "ffffffff" );
+ this.format = ImageFormat.VMDK;
+ String hwv = config.get( "ddb.virtualHWVersion" );
+ if ( hwv == null ) {
+ this.hwVersion = 10;
+ } else {
+ this.hwVersion = Util.parseInt( hwv, 10 );
+ }
+ this.diskDescription = null;
+ return;
}
- this.diskDescription = null;
- return;
}
}
// Format spec from: https://forums.virtualbox.org/viewtopic.php?t=8046