diff --git a/headers/private/vmdk/vmdk.h b/headers/private/vmdk/vmdk.h new file mode 100644 index 0000000000..9cb287cb62 --- /dev/null +++ b/headers/private/vmdk/vmdk.h @@ -0,0 +1,38 @@ +/* + * Copyright 2007, Marcus Overhagen. All Rights Reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef _VMDK_H +#define _VMDK_H + + +#include + + +typedef uint64_t SectorType; + + +struct SparseExtentHeader { + uint32_t magicNumber; + uint32_t version; + uint32_t flags; + SectorType capacity; + SectorType grainSize; + SectorType descriptorOffset; + SectorType descriptorSize; + uint32_t numGTEsPerGT; + SectorType rgdOffset; + SectorType gdOffset; + SectorType overHead; + uint8_t uncleanShutdown; + char singleEndLineChar; + char nonEndLineChar; + char doubleEndLineChar1; + char doubleEndLineChar2; + uint8_t pad[435]; +} __attribute__((__packed__)) ; + +#define VMDK_SPARSE_MAGICNUMBER 0x564d444b /* 'V' 'M' 'D' 'K' */ +#define VMDK_SPARSE_VERSION 1 + +#endif // _VMDK_H diff --git a/src/tools/vmdkimage/Jamfile b/src/tools/vmdkimage/Jamfile index 20ef2f1523..7d3ed3d8bb 100644 --- a/src/tools/vmdkimage/Jamfile +++ b/src/tools/vmdkimage/Jamfile @@ -1,6 +1,7 @@ SubDir HAIKU_TOP src tools vmdkimage ; UsePrivateHeaders kernel ; +UsePrivateHeaders vmdk ; BuildPlatformMain vmdkimage : vmdkimage.cpp diff --git a/src/tools/vmdkimage/vmdkimage.cpp b/src/tools/vmdkimage/vmdkimage.cpp index 0ed179fe02..0865aadf76 100644 --- a/src/tools/vmdkimage/vmdkimage.cpp +++ b/src/tools/vmdkimage/vmdkimage.cpp @@ -3,6 +3,7 @@ * Distributed under the terms of the MIT License. */ + #include #include #include @@ -15,13 +16,15 @@ #include #include -#include "vmdkimage.h" +#include + #if defined(__BEOS__) && !defined(__HAIKU__) #define pread(_fd, _buf, _count, _pos) read_pos(_fd, _pos, _buf, _count) #define realpath(x, y) NULL #endif + static void print_usage() { @@ -59,7 +62,7 @@ dump_image_info(const char *filename) exit(EXIT_FAILURE); } - if (header.magicNumber != SPARSE_MAGICNUMBER) { + if (header.magicNumber != VMDK_SPARSE_MAGICNUMBER) { fprintf(stderr, "Error: invalid header magic.\n"); exit(EXIT_FAILURE); } @@ -108,10 +111,10 @@ dump_image_info(const char *filename) } -static uint64 +static uint64_t hash_string(const char *string) { - uint64 hash = 0; + uint64_t hash = 0; char c; while ((c = *string++) != 0) { @@ -145,8 +148,8 @@ is_valid_uuid(const char *uuid) int main(int argc, char *argv[]) { - uint64 headerSize = 0; - uint64 imageSize = 0; + uint64_t headerSize = 0; + uint64_t imageSize = 0; const char *file = NULL; const char *uuid = NULL; bool headerOnly = false; @@ -277,9 +280,9 @@ main(int argc, char *argv[]) // printf("imageSize %llu\n", imageSize); // printf("file %s\n", file); - uint64 sectors; - uint64 heads; - uint64 cylinders; + uint64_t sectors; + uint64_t heads; + uint64_t cylinders; // TODO: fixme! sectors = 63; @@ -294,8 +297,8 @@ main(int argc, char *argv[]) memset(desc, 0, sizeof(desc)); memset(&header, 0, sizeof(header)); - header.magicNumber = SPARSE_MAGICNUMBER; - header.version = 1; + header.magicNumber = VMDK_SPARSE_MAGICNUMBER; + header.version = VMDK_SPARSE_VERSION; header.flags = 1; header.capacity = 0; header.grainSize = 16; @@ -312,7 +315,7 @@ main(int argc, char *argv[]) header.doubleEndLineChar2 = '\n'; // Generate UUID for the image by hashing its full path - uint64 uuid1 = 0, uuid2 = 0, uuid3 = 0, uuid4 = 0, uuid5 = 0; + uint64_t uuid1 = 0, uuid2 = 0, uuid3 = 0, uuid4 = 0, uuid5 = 0; if (uuid == NULL) { char fullPath[PATH_MAX + 6]; strcpy(fullPath, "Haiku"); @@ -376,7 +379,7 @@ main(int argc, char *argv[]) if (write(fd, desc, sizeof(desc)) != sizeof(desc)) goto write_err; - if ((uint64)lseek(fd, headerSize - 1, SEEK_SET) != headerSize - 1) + if ((uint64_t)lseek(fd, headerSize - 1, SEEK_SET) != headerSize - 1) goto write_err; if (1 != write(fd, "", 1)) diff --git a/src/tools/vmdkimage/vmdkimage.h b/src/tools/vmdkimage/vmdkimage.h deleted file mode 100644 index eefef60fb5..0000000000 --- a/src/tools/vmdkimage/vmdkimage.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2007, Marcus Overhagen. All Rights Reserved. - * Distributed under the terms of the MIT License. - */ -#ifndef _VMDKIMAGE_H -#define _VMDKIMAGE_H - -typedef unsigned char uint8; -typedef unsigned int uint32; -typedef unsigned long long uint64; - - -typedef uint64 SectorType; -typedef uint8 Bool; - -struct SparseExtentHeader { - uint32 magicNumber; - uint32 version; - uint32 flags; - SectorType capacity; - SectorType grainSize; - SectorType descriptorOffset; - SectorType descriptorSize; - uint32 numGTEsPerGT; - SectorType rgdOffset; - SectorType gdOffset; - SectorType overHead; - Bool uncleanShutdown; - char singleEndLineChar; - char nonEndLineChar; - char doubleEndLineChar1; - char doubleEndLineChar2; - uint8 pad[435]; -} __attribute__((__packed__)) ; - -#define SPARSE_MAGICNUMBER 0x564d444b /* 'V' 'M' 'D' 'K' */ - -#endif // _VMDKIMAGE_H