diff options
author | Victor Mocanu | 2018-03-30 13:42:02 +0200 |
---|---|---|
committer | Victor Mocanu | 2018-03-30 13:42:02 +0200 |
commit | 8b8c584bb51e03f18f7d4161493dccbc0c108696 (patch) | |
tree | a76e9796a9d4cd58102c837bc5688db66637fbbc /src/main | |
parent | [VBox] added new, more elegant way to add placeholders (diff) | |
download | master-sync-shared-8b8c584bb51e03f18f7d4161493dccbc0c108696.tar.gz master-sync-shared-8b8c584bb51e03f18f7d4161493dccbc0c108696.tar.xz master-sync-shared-8b8c584bb51e03f18f7d4161493dccbc0c108696.zip |
[VBox] changed the way the new UUID is patched into the vdi file at download
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/openslx/util/vm/VboxMetaData.java | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/src/main/java/org/openslx/util/vm/VboxMetaData.java b/src/main/java/org/openslx/util/vm/VboxMetaData.java index 3aa7491..1d857b0 100644 --- a/src/main/java/org/openslx/util/vm/VboxMetaData.java +++ b/src/main/java/org/openslx/util/vm/VboxMetaData.java @@ -3,7 +3,9 @@ package org.openslx.util.vm; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; +import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; +import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -149,34 +151,30 @@ public class VboxMetaData extends VmMetaData<VBoxSoundCardMeta, VBoxDDAccelMeta, config.changeAttribute( "HardDisk", "location", diskImagePath ); UUID newhdduuid = UUID.randomUUID(); - + // patching the new uuid in the vbox config file here String vboxUUid = "{" + newhdduuid.toString() + "}"; config.changeAttribute( "HardDisk", "uuid", vboxUUid ); config.changeAttribute( "Image", "uuid", vboxUUid ); - // write the new hdd uuid in the vdi file - byte[] bytesToWrite = new byte[ 16 ]; - - int[] bytesOffset = { 32, 40, 48, 56, 16, 24, 0, 8, 56, 48, 40, 32, 24, 16, 8, 0 }; - - int offset = 0; - for ( int i = 0; i < 2; i++ ) { - Long uuidlong = null; - if ( i == 0 ) { - uuidlong = newhdduuid.getMostSignificantBits(); - } else { - uuidlong = newhdduuid.getLeastSignificantBits(); - } - - for ( int j = 0; j < 8; j++ ) { - int index = j + offset; - bytesToWrite[index] = (byte) ( uuidlong >>> bytesOffset[index] ); - } - offset = 8; + // the order of the UUID is BIG_ENDIAN but we need to change the order of the first 8 Bytes + // to be able to write them to the vdi file... the PROBLEM here is that the first 8 + // are in LITTLE_ENDIAN order in pairs of 4-2-2 not the whole 8 so just changing the + // order when we are adding them to the bytebuffer won't help + // + // the following is a workaround that works + ByteBuffer buffer = ByteBuffer.wrap( new byte[16] ); + buffer.putLong( newhdduuid.getMostSignificantBits() ); + buffer.putLong( newhdduuid.getLeastSignificantBits() ); + byte[] oldOrder = buffer.array(); + // make a coppy here because the last 8 Bytes don't need to change position + byte[] bytesToWrite = Arrays.copyOf( oldOrder, oldOrder.length ); + // use an offset int[] to help with the shuffle + int[] offsets = { 3, 2, 1, 0, 5, 4, 7, 6}; + for ( int index = 0; index < 8; index++) { + bytesToWrite[index] = oldOrder[offsets[index]]; } try ( RandomAccessFile file = new RandomAccessFile( diskImage, "rw" ) ) { - file.seek( 392 ); file.write( bytesToWrite, 0, 16 ); } catch ( Exception e ) { |