diff mbox series

Add "force" flag to diskpart handler in order to be consistent with diskformat handler

Message ID PAWP192MB21288B8B3D9A836920AC40F0C3499@PAWP192MB2128.EURP192.PROD.OUTLOOK.COM
State Accepted
Headers show
Series Add "force" flag to diskpart handler in order to be consistent with diskformat handler | expand

Commit Message

Sava Jakovljev June 1, 2023, 12:57 p.m. UTC
From: Sava Jakovljev <savaj@meyersound.com>

Signed-off-by: Sava Jakovljev <savaj@meyersound.com>
---
 doc/source/handlers.rst     | 16 ++++++++++------
 handlers/diskpart_handler.c | 10 +++++++++-
 2 files changed, 19 insertions(+), 7 deletions(-)

Comments

Stefano Babic June 14, 2023, 1:14 p.m. UTC | #1
On 01.06.23 14:57, Sava Jakovljev wrote:
> From: Sava Jakovljev <savaj@meyersound.com>
> 
> Signed-off-by: Sava Jakovljev <savaj@meyersound.com>
> ---
>   doc/source/handlers.rst     | 16 ++++++++++------
>   handlers/diskpart_handler.c | 10 +++++++++-
>   2 files changed, 19 insertions(+), 7 deletions(-)
> 
> diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst
> index 06999e6..e8e2e43 100644
> --- a/doc/source/handlers.rst
> +++ b/doc/source/handlers.rst
> @@ -323,7 +323,7 @@ For a script handler written in Lua, the prototype is
>           --- Lua Handler.
>           --
>           --- @param  image     img_type  Lua equivalent of `struct img_type`
> -        --- @param  scriptfn  string    Type, one of `preinst` or `postinst`
> +        --- @param  scriptfn  string    Type, one of `preinst` or `postinst`
>           --- @return number              # 0 on success, 1 on error
>           function lua_handler(image, scriptfn)
>               ...
> @@ -811,7 +811,7 @@ Copy handler
>   
>   The copy handler copies one source to a destination. It is a script handler, and no artifact in the SWU is associated
>   with the handler.  It can be used to copy configuration data, or parts that should be taken by the current installation.
> -It requires the mandatory  property (`copyfrom`), while device contains the destination path.
> +It requires the mandatory  property (`copyfrom`), while device contains the destination path.
>   The handler performs a byte copy, and it does not matter which is the source - it can be a file or a partition.
>   An optional `type` field can set if the handler is active as pre or postinstall script. If not set, the handler
>   is called twice.
> @@ -985,14 +985,18 @@ supported:
>      | fstype      | string   | Optional filesystem type to be created on the      |
>      |             |          | partition. If no fstype key is given, no file      |
>      |             |          | will be created on the corresponding partition.    |
> -   |             |          | vfat / ext2 / ext3 /ext4 / btrfs                   |
> -   |             |          | file system is supported                           |
> +   |             |          | vfat / ext2 / ext3 /ext4 / btrfs                   |
> +   |             |          | file system is supported                           |
>      +-------------+----------+----------------------------------------------------+
>      | partuuid    | string   | The partition UUID (GPT only). If omitted, a UUID  |
> -   |             |          | will be generated automatically.			 |
> +   |             |          | will be generated automatically.                   |
>      +-------------+----------+----------------------------------------------------+
>      | flag        | string   | The following flags are supported:                 |
> -   |             |          | Dos Partition : "boot" set bootflag		 |
> +   |             |          | Dos Partition : "boot" set bootflag                |
> +   +-------------+----------+----------------------------------------------------+
> +   | force       | string   | If set to "true", existing file-system shall be    |
> +   |             |          | overwritten uncoditionally.                        |
> +   |             |          | Default value is "false".                          |
>      +-------------+----------+----------------------------------------------------+
>   
>   
> diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
> index e1056ef..67bf9a0 100644
> --- a/handlers/diskpart_handler.c
> +++ b/handlers/diskpart_handler.c
> @@ -62,6 +62,7 @@ enum partfield {
>   	PART_DOSTYPE,
>   	PART_UUID,
>   	PART_FLAG,
> +	PART_FORCE
>   };
>   
>   const char *fields[] = {
> @@ -73,6 +74,7 @@ const char *fields[] = {
>   	[PART_DOSTYPE] = "dostype",
>   	[PART_UUID] = "partuuid",
>   	[PART_FLAG] = "flag",
> +	[PART_FORCE] = "force",
>   };
>   
>   struct partition_data {
> @@ -86,6 +88,7 @@ struct partition_data {
>   	char partuuid[UUID_STR_LEN];
>   	int explicit_size;
>   	unsigned long flags;
> +	int force;
>   	LIST_ENTRY(partition_data) next;
>   };
>   LIST_HEAD(listparts, partition_data);
> @@ -1215,6 +1218,7 @@ static int diskpart(struct img_type *img,
>   		part->partno = LIBFDISK_INIT_UNDEF(part->partno);
>   		part->start = LIBFDISK_INIT_UNDEF(part->start);
>   		part->size = LIBFDISK_INIT_UNDEF(part->size);
> +		part->force = 0;
>   
>   		part->partno = strtoul(entry->key  + strlen("partition-"), NULL, 10);
>   		while (elem) {
> @@ -1270,6 +1274,10 @@ static int diskpart(struct img_type *img,
>   						}
>   						part->flags |= DOS_FLAG_ACTIVE;
>   						break;
> +					case PART_FORCE:
> +						part->force = strcmp(equal, "true") == 0;
> +						TRACE("Force flag explicitly mentioned, value %d", part->force);
> +						break;
>   					}
>   				}
>   			}
> @@ -1417,7 +1425,7 @@ handler_release:
>   			device = fdisk_partname(path, partno);
>   			free(path);
>   
> -			if (!createtable->parent) {
> +			if (!createtable->parent && !part->force) {
>   				/* Check if file system exists */
>   				ret = diskformat_fs_exists(device, part->fstype);
>   

Applied to -master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/doc/source/handlers.rst b/doc/source/handlers.rst
index 06999e6..e8e2e43 100644
--- a/doc/source/handlers.rst
+++ b/doc/source/handlers.rst
@@ -323,7 +323,7 @@  For a script handler written in Lua, the prototype is
         --- Lua Handler.
         --
         --- @param  image     img_type  Lua equivalent of `struct img_type`
-        --- @param  scriptfn  string    Type, one of `preinst` or `postinst` 
+        --- @param  scriptfn  string    Type, one of `preinst` or `postinst`
         --- @return number              # 0 on success, 1 on error
         function lua_handler(image, scriptfn)
             ...
@@ -811,7 +811,7 @@  Copy handler
 
 The copy handler copies one source to a destination. It is a script handler, and no artifact in the SWU is associated
 with the handler.  It can be used to copy configuration data, or parts that should be taken by the current installation.
-It requires the mandatory  property (`copyfrom`), while device contains the destination path. 
+It requires the mandatory  property (`copyfrom`), while device contains the destination path.
 The handler performs a byte copy, and it does not matter which is the source - it can be a file or a partition.
 An optional `type` field can set if the handler is active as pre or postinstall script. If not set, the handler
 is called twice.
@@ -985,14 +985,18 @@  supported:
    | fstype      | string   | Optional filesystem type to be created on the      |
    |             |          | partition. If no fstype key is given, no file      |
    |             |          | will be created on the corresponding partition.    |
-   |             |          | vfat / ext2 / ext3 /ext4 / btrfs                   | 
-   |             |          | file system is supported                           | 
+   |             |          | vfat / ext2 / ext3 /ext4 / btrfs                   |
+   |             |          | file system is supported                           |
    +-------------+----------+----------------------------------------------------+
    | partuuid    | string   | The partition UUID (GPT only). If omitted, a UUID  |
-   |             |          | will be generated automatically.			 |
+   |             |          | will be generated automatically.                   |
    +-------------+----------+----------------------------------------------------+
    | flag        | string   | The following flags are supported:                 |
-   |             |          | Dos Partition : "boot" set bootflag		 |
+   |             |          | Dos Partition : "boot" set bootflag                |
+   +-------------+----------+----------------------------------------------------+
+   | force       | string   | If set to "true", existing file-system shall be    |
+   |             |          | overwritten uncoditionally.                        |
+   |             |          | Default value is "false".                          |
    +-------------+----------+----------------------------------------------------+
 
 
diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
index e1056ef..67bf9a0 100644
--- a/handlers/diskpart_handler.c
+++ b/handlers/diskpart_handler.c
@@ -62,6 +62,7 @@  enum partfield {
 	PART_DOSTYPE,
 	PART_UUID,
 	PART_FLAG,
+	PART_FORCE
 };
 
 const char *fields[] = {
@@ -73,6 +74,7 @@  const char *fields[] = {
 	[PART_DOSTYPE] = "dostype",
 	[PART_UUID] = "partuuid",
 	[PART_FLAG] = "flag",
+	[PART_FORCE] = "force",
 };
 
 struct partition_data {
@@ -86,6 +88,7 @@  struct partition_data {
 	char partuuid[UUID_STR_LEN];
 	int explicit_size;
 	unsigned long flags;
+	int force;
 	LIST_ENTRY(partition_data) next;
 };
 LIST_HEAD(listparts, partition_data);
@@ -1215,6 +1218,7 @@  static int diskpart(struct img_type *img,
 		part->partno = LIBFDISK_INIT_UNDEF(part->partno);
 		part->start = LIBFDISK_INIT_UNDEF(part->start);
 		part->size = LIBFDISK_INIT_UNDEF(part->size);
+		part->force = 0;
 
 		part->partno = strtoul(entry->key  + strlen("partition-"), NULL, 10);
 		while (elem) {
@@ -1270,6 +1274,10 @@  static int diskpart(struct img_type *img,
 						}
 						part->flags |= DOS_FLAG_ACTIVE;
 						break;
+					case PART_FORCE:
+						part->force = strcmp(equal, "true") == 0;
+						TRACE("Force flag explicitly mentioned, value %d", part->force);
+						break;
 					}
 				}
 			}
@@ -1417,7 +1425,7 @@  handler_release:
 			device = fdisk_partname(path, partno);
 			free(path);
 
-			if (!createtable->parent) {
+			if (!createtable->parent && !part->force) {
 				/* Check if file system exists */
 				ret = diskformat_fs_exists(device, part->fstype);