svn commit: r265725 - user/marcel/mkimg
Marcel Moolenaar
marcel at FreeBSD.org
Fri May 9 01:13:16 UTC 2014
Author: marcel
Date: Fri May 9 01:13:14 2014
New Revision: 265725
URL: http://svnweb.freebsd.org/changeset/base/265725
Log:
Add image_get_size() so formats can query about the image size.
Create the VMDK (embedded) descriptor file and round its size
to a multiple of 512.
TODO: We need the name of the output file -- it's in the extent
description. For now, just use "mkimg.vmdk".
Modified:
user/marcel/mkimg/image.c
user/marcel/mkimg/image.h
user/marcel/mkimg/vmdk.c
Modified: user/marcel/mkimg/image.c
==============================================================================
--- user/marcel/mkimg/image.c Fri May 9 00:34:29 2014 (r265724)
+++ user/marcel/mkimg/image.c Fri May 9 01:13:14 2014 (r265725)
@@ -40,6 +40,7 @@ __FBSDID("$FreeBSD$");
static char image_tmpfile[] = "/tmp/mkimg-XXXXXX";
static int image_fd = -1;
+static lba_t image_size;
static void
cleanup(void)
@@ -123,10 +124,18 @@ image_copyout(int fd)
return (error);
}
+lba_t
+image_get_size(void)
+{
+
+ return (image_size);
+}
+
int
image_set_size(lba_t blk)
{
+ image_size = blk;
if (ftruncate(image_fd, blk * secsz) == -1)
return (errno);
return (0);
Modified: user/marcel/mkimg/image.h
==============================================================================
--- user/marcel/mkimg/image.h Fri May 9 00:34:29 2014 (r265724)
+++ user/marcel/mkimg/image.h Fri May 9 01:13:14 2014 (r265725)
@@ -33,6 +33,7 @@ typedef int64_t lba_t;
int image_copyin(lba_t blk, int fd, uint64_t *sizep);
int image_copyout(int fd);
+lba_t image_get_size(void);
int image_init(void);
int image_set_size(lba_t blk);
int image_write(lba_t blk, void *buf, ssize_t len);
Modified: user/marcel/mkimg/vmdk.c
==============================================================================
--- user/marcel/mkimg/vmdk.c Fri May 9 00:34:29 2014 (r265724)
+++ user/marcel/mkimg/vmdk.c Fri May 9 01:13:14 2014 (r265725)
@@ -31,6 +31,8 @@ __FBSDID("$FreeBSD$");
#include <sys/apm.h>
#include <sys/endian.h>
#include <sys/errno.h>
+#include <stdint.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@@ -67,9 +69,34 @@ struct vmdk_header {
char padding[433];
} __attribute__((__packed__));
+static const char desc_fmt[] =
+ "# Disk DescriptorFile\n"
+ "version=%d\n"
+ "CID=%08x\n"
+ "parentCID=ffffffff\n"
+ "createType=\"monolithicSparse\"\n"
+ "# Extent description\n"
+ "RW %ju SPARSE \"%s\"\n"
+ "# The Disk Data Base\n"
+ "#DDB\n"
+ "ddb.adapterType = \"ide\"\n"
+ "ddb.geometry.cylinders = \"%u\"\n"
+ "ddb.geometry.heads = \"%u\"\n"
+ "ddb.geometry.sectors = \"%u\"\n";
+
static int
vmdk_write(int fd __unused)
{
+ char *desc;
+ lba_t imgsz;
+ int desc_len;
+
+ imgsz = image_get_size();
+ desc_len = asprintf(&desc, desc_fmt, 1 /*version*/, 0 /*CID*/,
+ (uintmax_t)imgsz /*size*/, "mkimg.vmdk" /*name*/,
+ ncyls /*cylinders*/, nheads /*heads*/, nsecs /*sectors*/);
+ desc_len = (desc_len + 512 - 1) & ~(512 - 1);
+ desc = realloc(desc, desc_len);
/*
* Steps:
More information about the svn-src-user
mailing list