diff options
author | Florent Viard <fviard@cxignited.com> | 2019-10-27 23:48:16 +0100 |
---|---|---|
committer | Florent Viard <fviard@cxignited.com> | 2019-10-30 15:09:45 +0100 |
commit | 516f37144fc43eb40c051af1482a81399bbdd24d (patch) | |
tree | 38185326fd3b88921c3d5a101374bcc797d197aa | |
parent | 27f903039d164c6ee47f16b2a56d59bb8bf57a50 (diff) | |
download | genimage-516f37144fc43eb40c051af1482a81399bbdd24d.tar.gz genimage-516f37144fc43eb40c051af1482a81399bbdd24d.tar.xz |
image-vfat: Add label option to set volume name.
Signed-off-by: Florent Viard <fviard@cxignited.com>
-rw-r--r-- | README.rst | 1 | ||||
-rw-r--r-- | image-vfat.c | 18 |
2 files changed, 17 insertions, 2 deletions
@@ -303,6 +303,7 @@ Generates a VFAT image. Options: :extraargs: Extra arguments passed to mkdosfs +:label: Specify the volume-label. Passed to the ``-n`` option of mkdosfs :file: Specify a file to be added into the filesystem image. Usage is: ``file foo { image = "bar" }`` which adds a file "foo" in the filesystem image from the input file "bar" diff --git a/image-vfat.c b/image-vfat.c index d3f7bdb..026e1a2 100644 --- a/image-vfat.c +++ b/image-vfat.c @@ -27,14 +27,20 @@ static int vfat_generate(struct image *image) int ret; struct partition *part; char *extraargs = cfg_getstr(image->imagesec, "extraargs"); + char *label = cfg_getstr(image->imagesec, "label"); + + if (label && label[0] != '\0') + xasprintf(&label, "-n '%s'", label); + else + label = ""; ret = systemp(image, "%s if=/dev/zero of=\"%s\" seek=%lld count=0 bs=1 2>/dev/null", get_opt("dd"), imageoutfile(image), image->size); if (ret) return ret; - ret = systemp(image, "%s %s '%s'", get_opt("mkdosfs"), - extraargs, imageoutfile(image)); + ret = systemp(image, "%s %s %s '%s'", get_opt("mkdosfs"), + extraargs, label, imageoutfile(image)); if (ret) return ret; @@ -73,11 +79,18 @@ static int vfat_generate(struct image *image) static int vfat_setup(struct image *image, cfg_t *cfg) { + char *label = cfg_getstr(image->imagesec, "label"); + if (!image->size) { image_error(image, "no size given or must not be zero\n"); return -EINVAL; } + if (label && strlen(label) > 11) { + image_error(image, "vfat volume name cannot be longer than 11 characters\n"); + return -EINVAL; + } + return 0; } @@ -113,6 +126,7 @@ static cfg_opt_t file_opts[] = { static cfg_opt_t vfat_opts[] = { CFG_STR("extraargs", "", CFGF_NONE), + CFG_STR("label", "", CFGF_NONE), CFG_STR_LIST("files", 0, CFGF_NONE), CFG_SEC("file", file_opts, CFGF_MULTI | CFGF_TITLE), CFG_END() |