Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 14 May 2014 15:46:07 +0000 (UTC)
From:      Marcel Moolenaar <marcel@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-user@freebsd.org
Subject:   svn commit: r266039 - user/marcel/mkimg
Message-ID:  <201405141546.s4EFk7oT001992@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: marcel
Date: Wed May 14 15:46:07 2014
New Revision: 266039
URL: http://svnweb.freebsd.org/changeset/base/266039

Log:
  Give output formats a chance to (re-)size the image before the
  scheme adds the partitioning metadata. This is needed by VMDK
  to round the image size to the grain size.

Modified:
  user/marcel/mkimg/format.c
  user/marcel/mkimg/format.h
  user/marcel/mkimg/mkimg.c
  user/marcel/mkimg/raw.c
  user/marcel/mkimg/scheme.c
  user/marcel/mkimg/vmdk.c

Modified: user/marcel/mkimg/format.c
==============================================================================
--- user/marcel/mkimg/format.c	Wed May 14 15:36:23 2014	(r266038)
+++ user/marcel/mkimg/format.c	Wed May 14 15:46:07 2014	(r266039)
@@ -38,13 +38,22 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
-#include "format.h"
 #include "image.h"
+#include "format.h"
 #include "mkimg.h"
 
 static struct mkimg_format *format;
 
 int
+format_resize(lba_t end)
+{
+
+	if (format == NULL || format->resize == NULL)
+		return (ENOSYS);
+	return (format->resize(end));
+}
+
+int
 format_select(const char *spec)
 {
 	struct mkimg_format *f, **iter;
@@ -70,8 +79,7 @@ int
 format_write(int fd)
 {
 
-	if (format == NULL)
+	if (format == NULL || format->write == NULL)
 		return (ENOSYS);
-
 	return (format->write(fd));
 }

Modified: user/marcel/mkimg/format.h
==============================================================================
--- user/marcel/mkimg/format.h	Wed May 14 15:36:23 2014	(r266038)
+++ user/marcel/mkimg/format.h	Wed May 14 15:46:07 2014	(r266039)
@@ -34,12 +34,14 @@
 struct mkimg_format {
 	const char	*name;
 	const char	*description;
+	int		(*resize)(lba_t);
 	int		(*write)(int);
 };
 
 SET_DECLARE(formats, struct mkimg_format);
 #define	FORMAT_DEFINE(nm)	DATA_SET(formats, nm)
 
+int	format_resize(lba_t);
 int	format_select(const char *);
 struct mkimg_format *format_selected(void);
 int	format_write(int);

Modified: user/marcel/mkimg/mkimg.c
==============================================================================
--- user/marcel/mkimg/mkimg.c	Wed May 14 15:36:23 2014	(r266038)
+++ user/marcel/mkimg/mkimg.c	Wed May 14 15:46:07 2014	(r266039)
@@ -42,8 +42,8 @@ __FBSDID("$FreeBSD$");
 #include <sysexits.h>
 #include <unistd.h>
 
-#include "format.h"
 #include "image.h"
+#include "format.h"
 #include "mkimg.h"
 #include "scheme.h"
 
@@ -316,7 +316,16 @@ mkimg(void)
 	}
 
 	block = scheme_metadata(SCHEME_META_IMG_END, block);
+	error = image_set_size(block);
+	if (!error)
+		error = format_resize(block);
+	if (error)
+		errc(EX_IOERR, error, "image sizing");
+	block = image_get_size();
+	ncyls = block / (nsecs * nheads);
 	error = (scheme_write(block));
+	if (error)
+		errc(EX_IOERR, error, "writing metadata");
 }
 
 int

Modified: user/marcel/mkimg/raw.c
==============================================================================
--- user/marcel/mkimg/raw.c	Wed May 14 15:36:23 2014	(r266038)
+++ user/marcel/mkimg/raw.c	Wed May 14 15:46:07 2014	(r266039)
@@ -35,11 +35,18 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
-#include "format.h"
 #include "image.h"
+#include "format.h"
 #include "mkimg.h"
 
 static int
+raw_resize(lba_t imgsz __unused)
+{
+
+	return (0);
+}
+
+static int
 raw_write(int fd)
 {
 
@@ -49,6 +56,7 @@ raw_write(int fd)
 static struct mkimg_format raw_format = {
 	.name = "raw",
 	.description = "Raw Disk",
+	.resize = raw_resize,
 	.write = raw_write,
 };
 

Modified: user/marcel/mkimg/scheme.c
==============================================================================
--- user/marcel/mkimg/scheme.c	Wed May 14 15:36:23 2014	(r266038)
+++ user/marcel/mkimg/scheme.c	Wed May 14 15:46:07 2014	(r266039)
@@ -182,14 +182,9 @@ scheme_metadata(u_int where, lba_t start
 int
 scheme_write(lba_t end)
 {
-	u_int cylsz;
 	int error;
 
-	cylsz = nsecs * nheads;
-	ncyls = (end + cylsz - 1) / cylsz;
-
-	error = image_set_size(end);
-	if (!error)
-		error = scheme->write(end, bootcode);
+	end = image_get_size();
+	error = scheme->write(end, bootcode);
 	return (error);
 }

Modified: user/marcel/mkimg/vmdk.c
==============================================================================
--- user/marcel/mkimg/vmdk.c	Wed May 14 15:36:23 2014	(r266038)
+++ user/marcel/mkimg/vmdk.c	Wed May 14 15:46:07 2014	(r266039)
@@ -37,8 +37,8 @@ __FBSDID("$FreeBSD$");
 #include <string.h>
 #include <unistd.h>
 
-#include "format.h"
 #include "image.h"
+#include "format.h"
 #include "mkimg.h"
 
 struct vmdk_header {
@@ -85,6 +85,17 @@ static const char desc_fmt[] =
     "ddb.geometry.sectors = \"%u\"\n";
 
 static int
+vmdk_resize(lba_t imgsz __unused)
+{
+
+	/*
+	 * Caulculate optimal grain size and round image size to
+	 * a multiple of the grain size.
+	 */
+	return (ENOSYS);
+}
+
+static int
 vmdk_write(int fd __unused)
 {
 	char *desc;
@@ -132,6 +143,7 @@ vmdk_write(int fd __unused)
 static struct mkimg_format vmdk_format = {
 	.name = "vmdk",
 	.description = "Virtual Machine Disk",
+	.resize = vmdk_resize,
 	.write = vmdk_write,
 };
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405141546.s4EFk7oT001992>