From 3af6d35b01343b9adbae51ef179fe9bc6817a7ec Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Tue, 7 May 2019 07:52:21 +0200 Subject: image-hd: add option to extend the image to the full size This can be useful when the image is used directly, e.g. with qemu. Signed-off-by: Michael Olbrich --- image-hd.c | 11 +++++++++++ test/basic-images.test | 2 +- test/hdimage.config | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/image-hd.c b/image-hd.c index 1f80ae7..2f32b8b 100644 --- a/image-hd.c +++ b/image-hd.c @@ -33,6 +33,7 @@ struct hdimage { uint32_t disksig; const char *disk_uuid; cfg_bool_t gpt; + cfg_bool_t fill; }; struct mbr_partition_entry { @@ -379,6 +380,14 @@ static int hdimage_generate(struct image *image) } } + if (hd->fill) { + ret = extend_file(image, image->size); + if (ret) { + image_error(image, "failed to fill the image.\n"); + return ret; + } + } + if (hd->partition_table) { if (hd->gpt) { ret = hdimage_insert_gpt(image, &image->partitions); @@ -414,6 +423,7 @@ static int hdimage_setup(struct image *image, cfg_t *cfg) hd->extended_partition = cfg_getint(cfg, "extended-partition"); hd->disksig = strtoul(cfg_getstr(cfg, "disk-signature"), NULL, 0); hd->gpt = cfg_getbool(cfg, "gpt"); + hd->fill = cfg_getbool(cfg, "fill"); hd->disk_uuid = cfg_getstr(cfg, "disk-uuid"); if (hd->extended_partition > 4) { @@ -564,6 +574,7 @@ cfg_opt_t hdimage_opts[] = { CFG_BOOL("partition-table", cfg_true, CFGF_NONE), CFG_INT("extended-partition", 0, CFGF_NONE), CFG_BOOL("gpt", cfg_false, CFGF_NONE), + CFG_BOOL("fill", cfg_false, CFGF_NONE), CFG_END() }; diff --git a/test/basic-images.test b/test/basic-images.test index 9b53b45..35f1bfb 100755 --- a/test/basic-images.test +++ b/test/basic-images.test @@ -193,7 +193,7 @@ exec_test_set_prereq sfdisk test_expect_success fdisk,sfdisk "hdimage" " setup_test_images && run_genimage hdimage.config test.hdimage && - check_size images/test.hdimage 9442816 && + check_size images/test.hdimage 10485760 && # check the this identifier fdisk -l images/test.hdimage | grep identifier: > hdimage.fdisk && # check partitions; filter output to handle different sfdisk versions diff --git a/test/hdimage.config b/test/hdimage.config index 7287b6d..3785432 100644 --- a/test/hdimage.config +++ b/test/hdimage.config @@ -1,6 +1,7 @@ image test.hdimage { hdimage { align = 1M + fill = true disk-signature = 0x12345678 } partition part1 { -- cgit v1.2.3