* Renamed vmdkheader to vmdkimage and changed it to create a full image

by default (new option "-H" will create the header only). Option "-c"
  will clear the image.
* Adjusted build_haiku_image accordingly. vmdkimage is way faster and
  more portable than the former vmdkheader+dd combo.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@24784 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-04-03 21:18:18 +00:00
parent 2608583e58
commit 7c529c2415
7 changed files with 56 additions and 29 deletions
+1 -1
View File
@@ -531,7 +531,7 @@ AddTargetVariableToScript $(script) : <build>makebootable ;
AddTargetVariableToScript $(script) : <build>rc ;
AddTargetVariableToScript $(script) : <build>resattr ;
AddTargetVariableToScript $(script) : <build>unzip ;
AddTargetVariableToScript $(script) : <build>vmdkheader ;
AddTargetVariableToScript $(script) : <build>vmdkimage ;
if $(HOST_RM_ATTRS_TARGET) {
AddTargetVariableToScript $(script) : $(HOST_RM_ATTRS_TARGET) : rmAttrs ;
} else {
+11 -9
View File
@@ -21,7 +21,7 @@
# rc
# rmAttrs
# unzip
# vmdkheader
# vmdkimage
#
if [ $# -gt 0 ]; then
. $1
@@ -93,17 +93,19 @@ if [ $isImage ]; then
if [ ! $updateOnly ]; then
echo "Creating image ..."
ddFlags=
ddFlags=
if [ $isVMwareImage ]; then
rm -f "$imagePath"
$vmdkheader -h 64k -i${imageSize}M "$imagePath" || exit 1
ddFlags="conv=notrunc oflag=append"
dontClearImage=
vmdkImageFlags=
if [ ! "$dontClearImage" ]; then
vmdkImageFlags="-c"
fi
$vmdkimage -h 64k -i${imageSize}M $vmdkImageFlags "$imagePath" \
|| exit 1
elif [ ! -e "$imagePath" -o ! "$dontClearImage" ]; then
dd if=/dev/zero of="$imagePath" bs=1048576 count=$imageSize \
|| exit 1
fi
if [ ! -e "$imagePath" -o ! "$dontClearImage" ]; then
dd if=/dev/zero of="$imagePath" bs=1048576 count=$imageSize $ddFlags
fi
$bfsShell --initialize $imageOffsetFlags "$imagePath" Haiku \
"block_size 2048" || exit 1
$makebootable $imageOffsetFlags "$imagePath"
+1 -1
View File
@@ -104,6 +104,6 @@ SubInclude HAIKU_TOP src tools resattr ;
SubInclude HAIKU_TOP src tools rman ;
SubInclude HAIKU_TOP src tools translation ;
SubInclude HAIKU_TOP src tools unzip ;
SubInclude HAIKU_TOP src tools vmdkheader ;
SubInclude HAIKU_TOP src tools vmdkimage ;
SubInclude HAIKU_TOP src tools unflatten ;
-8
View File
@@ -1,8 +0,0 @@
SubDir HAIKU_TOP src tools vmdkheader ;
UsePrivateHeaders kernel ;
BuildPlatformMain <build>vmdkheader
: vmdkheader.cpp
: $(HOST_LIBSUPC++)
;
+8
View File
@@ -0,0 +1,8 @@
SubDir HAIKU_TOP src tools vmdkimage ;
UsePrivateHeaders kernel ;
BuildPlatformMain <build>vmdkimage
: vmdkimage.cpp
: $(HOST_LIBSUPC++)
;
@@ -13,19 +13,22 @@
#include <stdlib.h>
#include <string.h>
#include "vmdkheader.h"
#include "vmdkimage.h"
static void
print_usage()
{
printf("\n");
printf("vmdkheader\n");
printf("vmdkimage\n");
printf("\n");
printf("usage: vmdkheader -i <imagesize> -h <headersize> [-f] <file>\n");
printf("usage: vmdkimage -i <imagesize> -h <headersize> [-c] [-H] [-f] "
"<file>\n");
printf(" -i, --imagesize size of raw partition image file\n");
printf(" -h, --headersize size of the vmdk header to write\n");
printf(" -f, --file the raw partition image file\n");
printf(" -c, --clear-image set the image content to zero\n");
printf(" -H, --header-only write only the header\n");
exit(EXIT_FAILURE);
}
@@ -36,10 +39,12 @@ main(int argc, char *argv[])
uint64 headersize = 0;
uint64 imagesize = 0;
const char *file = NULL;
bool headerOnly = false;
bool clearImage = false;
if (sizeof(SparseExtentHeader) != 512) {
fprintf(stderr, "compilation error: struct size is %lu byte\n",
sizeof(SparseExtentHeader));
fprintf(stderr, "compilation error: struct size is %u byte\n",
(unsigned)sizeof(SparseExtentHeader));
exit(EXIT_FAILURE);
}
@@ -50,11 +55,13 @@ main(int argc, char *argv[])
{"headersize", required_argument, 0, 'h'},
{"imagesize", required_argument, 0, 'i'},
{"file", required_argument, 0, 'f'},
{"clear-image", no_argument, 0, 'c'},
{"header-only", no_argument, 0, 'H'},
{0, 0, 0, 0}
};
opterr = 0; /* don't print errors */
c = getopt_long(argc, argv, "h:i:f:", long_options, NULL);
c = getopt_long(argc, argv, "h:i:c:H:f:", long_options, NULL);
if (c == -1)
break;
@@ -83,6 +90,14 @@ main(int argc, char *argv[])
file = optarg;
break;
case 'c':
clearImage = true;
break;
case 'H':
headerOnly = true;
break;
default:
print_usage();
}
@@ -98,8 +113,8 @@ main(int argc, char *argv[])
SparseExtentHeader header;
if (headersize < sizeof(desc) + sizeof(header)) {
fprintf(stderr, "Error: header size must be at least %lu byte\n",
sizeof(desc) + sizeof(header));
fprintf(stderr, "Error: header size must be at least %u byte\n",
(unsigned)(sizeof(desc) + sizeof(header)));
exit(EXIT_FAILURE);
}
@@ -144,6 +159,7 @@ main(int argc, char *argv[])
cylinders /= 2;
heads *= 2;
}
off_t actualImageSize = (off_t)cylinders * sectors * heads * 512;
memset(desc, 0, sizeof(desc));
memset(&header, 0, sizeof(header));
@@ -204,6 +220,15 @@ main(int argc, char *argv[])
if (1 != write(fd, "", 1))
goto write_err;
if (!headerOnly) {
if (clearImage && ftruncate(fd, headersize) != 0
|| ftruncate(fd, actualImageSize) != 0) {
fprintf(stderr, "Error: resizing file %s failed (%s)\n", file,
strerror(errno));
exit(EXIT_FAILURE);
}
}
close(fd);
return 0;
@@ -2,8 +2,8 @@
* Copyright 2007, Marcus Overhagen. All Rights Reserved.
* Distributed under the terms of the MIT License.
*/
#ifndef _VMDKHEADER_H
#define _VMDKHEADER_H
#ifndef _VMDKIMAGE_H
#define _VMDKIMAGE_H
typedef unsigned char uint8;
typedef unsigned int uint32;