From c1f24adfb671ca69b88d43693eac5cb81055995c Mon Sep 17 00:00:00 2001 From: Richard Acayan <11385160-flamingradian@users.noreply.gitlab.com> Date: Mon, 29 Aug 2022 17:50:57 -0400 Subject: [PATCH] properly remove the partition number and separator --- gpt-utils.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/gpt-utils.cpp b/gpt-utils.cpp index bb170be..20053f7 100644 --- a/gpt-utils.cpp +++ b/gpt-utils.cpp @@ -317,6 +317,7 @@ static int get_dev_path_from_partition_name(const char *partname, char *buf, { struct stat st; char path[PATH_MAX] = { 0 }; + int i; (void)st; @@ -334,7 +335,14 @@ static int get_dev_path_from_partition_name(const char *partname, char *buf, if (!buf) { return -1; } else { - buf[PATH_TRUNCATE_LOC] = '\0'; + for (i = strlen(buf); i > 0; i--) + if (!isdigit(buf[i - 1])) + break; + + if (i >= 2 && buf[i - 1] == 'p' && isdigit(buf[i - 2])) + i--; + + buf[i] = 0; } return 0; }