diff mbox series

[5/5] diskformat handler: add support for fslabels

Message ID 20240826064006.41623-6-michael.adler@siemens.com
State Accepted
Headers show
Series Introduce FAT Filesystem Labeling | expand

Commit Message

Michael Adler Aug. 26, 2024, 6:40 a.m. UTC
Analoguous to diskpart_handler, diskformat_handler also sets FS labels.

Signed-off-by: Michael Adler <michael.adler@siemens.com>
Signed-off-by: Christian Storm <christian.storm@siemens.com>
---
 handlers/diskformat_handler.c | 26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)
diff mbox series

Patch

diff --git a/handlers/diskformat_handler.c b/handlers/diskformat_handler.c
index d968394b..07e0f2c5 100644
--- a/handlers/diskformat_handler.c
+++ b/handlers/diskformat_handler.c
@@ -35,19 +35,25 @@  static int diskformat(struct img_type *img,
 
 	char *force = dict_get_value(&img->properties, "force");
 
-	if (force != NULL && strtobool(force)) {
-		; /* Skip file system exists check */
+	/* create filesystem by default */
+	bool do_mkfs = true;
+	if (force == NULL || !strtobool(force)) {
+		/* only create fs if it does not exist */
+		do_mkfs = !diskformat_fs_exists(img->device, fstype);
+	}
+
+	if (do_mkfs) {
+		ret = diskformat_mkfs(img->device, fstype);
 	} else {
-		/* Check if file system exists */
-		if (diskformat_fs_exists(img->device, fstype)) {
-			TRACE("Found %s file system on %s, skip mkfs",
-			      fstype, img->device);
-			return 0;
-		}
+		TRACE("Skipping mkfs on %s", img->device);
 	}
 
-	/* File system does not exist, create new file system */
-	ret = diskformat_mkfs(img->device, fstype);
+	if (!ret) {
+		char *fslabel = dict_get_value(&img->properties, "fslabel");
+		if (fslabel) {
+			ret = diskformat_set_fslabel(img->device, fstype, fslabel);
+		}
+	}
 
 	/*
 	 * Declare that handler has finished