From d5a155dfa2dfbbf42059697007e304326ffd4331 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Thu, 16 Jun 2016 17:58:35 +0200 Subject: [PATCH] image-ext: make it possible to create the image with mke2fs Signed-off-by: Michael Olbrich --- config.c | 5 +++++ image-ext2.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/config.c b/config.c index 7ba515756252..052553578f84 100644 --- a/config.c +++ b/config.c @@ -307,6 +307,11 @@ static struct config opts[] = { .env = "GENIMAGE_MKDOSFS", .def = "mkdosfs", }, { + .name = "mke2fs", + .opt = CFG_STR("mke2fs", NULL, CFGF_NONE), + .env = "GENIMAGE_MKE2FS", + .def = "mke2fs", + }, { .name = "mkfsjffs2", .opt = CFG_STR("mkfsjffs2", NULL, CFGF_NONE), .env = "GENIMAGE_MKFJFFS2", diff --git a/image-ext2.c b/image-ext2.c index 1440e1cd6b10..8f7cff0364a3 100644 --- a/image-ext2.c +++ b/image-ext2.c @@ -22,7 +22,7 @@ #include "genimage.h" -static int ext2_generate(struct image *image) +static int ext2_generate_genext2fs(struct image *image) { int ret; char *extraargs = cfg_getstr(image->imagesec, "extraargs"); @@ -49,6 +49,44 @@ static int ext2_generate(struct image *image) if (ret) return ret; } + return 0; +} + +static int ext2_generate_mke2fs(struct image *image) +{ + char *extraargs = cfg_getstr(image->imagesec, "extraargs"); + char *label = cfg_getstr(image->imagesec, "label"); + char *conf = cfg_getstr(image->imagesec, "mke2fs_conf"); + + if (label &&label[0] == '\0') + label = NULL; + + return systemp(image, "%s%s%s%s -t %s -E root_owner=0:0 -E lazy_itable_init=0,lazy_journal_init=0 %s -d '%s' %s %s%s '%s' %lld", + conf ? "MKE2FS_CONFIG=" : "", conf ? conf : "", conf ? " " : "", + get_opt("mke2fs"), image->handler->type, + image->size < 0x20000000000 ? "-O ^huge_file" : "", + mountpath(image), extraargs, + label ? "-L " : "", label ? label : "", + imageoutfile(image), image->size / 1024); +} + +static int ext2_generate(struct image *image) +{ + int ret; + const char *tool = cfg_getstr(image->imagesec, "tool"); + + if (strcmp(tool, "mke2fs") == 0) + ret = ext2_generate_mke2fs(image); + else if (strcmp(tool, "genext2fs") == 0) + ret = ext2_generate_genext2fs(image); + else { + image_error(image, "unknown tool to create %s images: %s", + image->handler->type, tool); + ret = -EINVAL; + } + + if (ret) + return ret; ret = systemp(image, "%s -pvfD %s", get_opt("e2fsck"), imageoutfile(image)); @@ -61,6 +99,8 @@ static cfg_opt_t ext2_opts[] = { CFG_STR("extraargs", "", CFGF_NONE), CFG_STR("features", 0, CFGF_NONE), CFG_STR("label", 0, CFGF_NONE), + CFG_STR("tool", "genext2fs", CFGF_NONE), + CFG_STR("mke2fs_conf", 0, CFGF_NONE), CFG_END() }; @@ -74,6 +114,8 @@ static cfg_opt_t ext3_opts[] = { CFG_STR("extraargs", "", CFGF_NONE), CFG_STR("features", "has_journal", CFGF_NONE), CFG_STR("label", 0, CFGF_NONE), + CFG_STR("tool", "genext2fs", CFGF_NONE), + CFG_STR("mke2fs_conf", 0, CFGF_NONE), CFG_END() }; @@ -87,6 +129,8 @@ static cfg_opt_t ext4_opts[] = { CFG_STR("extraargs", "", CFGF_NONE), CFG_STR("features", "extents,uninit_bg,dir_index,has_journal", CFGF_NONE), CFG_STR("label", 0, CFGF_NONE), + CFG_STR("tool", "genext2fs", CFGF_NONE), + CFG_STR("mke2fs_conf", 0, CFGF_NONE), CFG_END() }; -- 2.11.0