From 0c236a76cb4110d250f9efab9815a0c14c891daf Mon Sep 17 00:00:00 2001 From: Greg Whiteley Date: Thu, 23 Mar 2023 16:55:03 +1100 Subject: [PATCH 1/2] Honour partition number from originally supplied device Use the command-line parameter to determine the partition number, not the stripped device Issue #31 --- fatresize.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fatresize.c b/fatresize.c index 414f9e7..09bdc74 100644 --- a/fatresize.c +++ b/fatresize.c @@ -208,7 +208,7 @@ static int get_device(char *dev) { return 0; } } else { - opts.pnum = get_partnum(devname); + opts.pnum = get_partnum(dev); } ped_device_destroy(peddev); opts.device = devname; From f6fa613ef3cacbcdfea922c0ea9fe6936e4b61df Mon Sep 17 00:00:00 2001 From: Greg Whiteley Date: Thu, 23 Mar 2023 16:56:57 +1100 Subject: [PATCH 2/2] Try multiple ways to retrieve the correct partition number Assuming the original code had a reason for using devname prefer to use devname unless no partition can be deduced. Issue #31 --- fatresize.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/fatresize.c b/fatresize.c index 09bdc74..b8cce37 100644 --- a/fatresize.c +++ b/fatresize.c @@ -157,7 +157,7 @@ static int get_partnum(char *dev) { } pnum = atoi(p + 1); - return pnum ? pnum : 1; + return pnum ? pnum : -1; } static int get_device(char *dev) { @@ -208,7 +208,12 @@ static int get_device(char *dev) { return 0; } } else { - opts.pnum = get_partnum(dev); + int pnum = get_partnum(devname); + if (pnum < 0) + pnum = get_partnum(dev); + if (pnum < 0) + pnum = 1; /* Original code returned 1 in this case */ + opts.pnum = pnum; } ped_device_destroy(peddev); opts.device = devname;