diff mbox series

[1/1] diskpart: resolve symlinks for fdisk_assign_device

Message ID 20210830113458.5655-1-james.hilliard1@gmail.com
State Changes Requested
Headers show
Series [1/1] diskpart: resolve symlinks for fdisk_assign_device | expand

Commit Message

James Hilliard Aug. 30, 2021, 11:34 a.m. UTC
This should help ensure diskpart behaves consistently when using
device paths that are symlinks.

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
 handlers/diskpart_handler.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Stefano Babic Aug. 30, 2021, 5:59 p.m. UTC | #1
Hi James,

On 30.08.21 13:34, James Hilliard wrote:
> This should help ensure diskpart behaves consistently when using
> device paths that are symlinks.
> 
> Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
> ---
>   handlers/diskpart_handler.c | 11 ++++++++++-
>   1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
> index 45ee97c..d079c8f 100644
> --- a/handlers/diskpart_handler.c
> +++ b/handlers/diskpart_handler.c
> @@ -147,6 +147,7 @@ static int diskpart_assign_context(struct fdisk_context **cxt,struct img_type *i
>   		struct hnd_priv priv, unsigned long hybrid, struct create_table *createtable)
>   {
>   	struct fdisk_context *parent;
> +	char *path = NULL;
>   	int ret = 0;
>   
>   	/*
> @@ -169,10 +170,18 @@ static int diskpart_assign_context(struct fdisk_context **cxt,struct img_type *i
>   		return ret;
>   	}
>   
> +	/*
> +	 * Resolve device path symlink.
> +	 */
> +	path = realpath(img->device, NULL);
> +	if (!path)
> +		path = strdup(img->device);
> +
>   	/*
>   	 * fdisk_new_nested_context requires the device to be assigned.
>   	 */
> -	ret = fdisk_assign_device(parent, img->device, 0);
> +	ret = fdisk_assign_device(parent, path, 0);
> +	free(path);
>   	if (ret == -EACCES) {
>   		ERROR("no access to %s", img->device);
>   		return ret;
> 

Acked-by : Stefano Babic <sbabic@denx.de>

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/handlers/diskpart_handler.c b/handlers/diskpart_handler.c
index 45ee97c..d079c8f 100644
--- a/handlers/diskpart_handler.c
+++ b/handlers/diskpart_handler.c
@@ -147,6 +147,7 @@  static int diskpart_assign_context(struct fdisk_context **cxt,struct img_type *i
 		struct hnd_priv priv, unsigned long hybrid, struct create_table *createtable)
 {
 	struct fdisk_context *parent;
+	char *path = NULL;
 	int ret = 0;
 
 	/*
@@ -169,10 +170,18 @@  static int diskpart_assign_context(struct fdisk_context **cxt,struct img_type *i
 		return ret;
 	}
 
+	/*
+	 * Resolve device path symlink.
+	 */
+	path = realpath(img->device, NULL);
+	if (!path)
+		path = strdup(img->device);
+
 	/*
 	 * fdisk_new_nested_context requires the device to be assigned.
 	 */
-	ret = fdisk_assign_device(parent, img->device, 0);
+	ret = fdisk_assign_device(parent, path, 0);
+	free(path);
 	if (ret == -EACCES) {
 		ERROR("no access to %s", img->device);
 		return ret;