Moved vmdkimage.h to a shareable place, cleaned it up a bit, and renamed it to

vmdk.h.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33387 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold 2009-10-01 03:08:46 +00:00
parent d6778355ee
commit 7f16b78c41
4 changed files with 55 additions and 51 deletions

View File

@ -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 <stdint.h>
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

View File

@ -1,6 +1,7 @@
SubDir HAIKU_TOP src tools vmdkimage ;
UsePrivateHeaders kernel ;
UsePrivateHeaders vmdk ;
BuildPlatformMain <build>vmdkimage
: vmdkimage.cpp

View File

@ -3,6 +3,7 @@
* Distributed under the terms of the MIT License.
*/
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
@ -15,13 +16,15 @@
#include <sys/stat.h>
#include <unistd.h>
#include "vmdkimage.h"
#include <vmdk.h>
#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))

View File

@ -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