From 3c3dbf367eeb049b29b2255919f79d2b20fa46ccddc44f204f4da2d0c52b633c Mon Sep 17 00:00:00 2001 From: Sebastian Parschauer Date: Tue, 19 Dec 2017 18:02:05 +0000 Subject: [PATCH] Accepting request 558622 from home:sparschauer:branches:Base:System fatresize: Fix getting the device name from partition name (boo#959181) OBS-URL: https://build.opensuse.org/request/show/558622 OBS-URL: https://build.opensuse.org/package/show/Base:System/parted?expand=0&rev=136 --- fatresize-fix-getting-dev-name.patch | 73 ++++++++++++++++++++++++++++ parted.changes | 7 +++ parted.spec | 2 + 3 files changed, 82 insertions(+) create mode 100644 fatresize-fix-getting-dev-name.patch diff --git a/fatresize-fix-getting-dev-name.patch b/fatresize-fix-getting-dev-name.patch new file mode 100644 index 0000000..5f8f5a1 --- /dev/null +++ b/fatresize-fix-getting-dev-name.patch @@ -0,0 +1,73 @@ +From: Sebastian Parschauer +Date: Sun, 3 Dec 2017 12:09:44 +0100 +Subject: Fix getting the device name from partition name +References: boo#959181 +Patch-mainline: submitted, https://github.com/ya-mouse/fatresize/pull/4 + +There are many partition device names like e.g. /dev/mmcblk0p1 where +it is not enough to trim the trailing digits to get the disk device +name. Using open() here would depend on a POSIX platform. So do it +like _ped_device_probe() and silence libparted exceptions and try +to get the device with ped_device_get(). Trim further trailing +characters until libparted finds it. Print an error and exit if +the partition name is invalid. + +Fixes #2 + +Signed-off-by: Sebastian Parschauer +--- + fatresize/fatresize.c | 29 +++++++++++++++++++++++++++++ + 1 file changed, 29 insertions(+) + +--- a/fatresize/fatresize.c ++++ b/fatresize/fatresize.c +@@ -9,6 +9,7 @@ + #include + #include + ++#include + #include + #include + +@@ -79,6 +80,18 @@ resize(const char* disk_device, int part + } + + ++/* Code parts have been taken from _ped_device_probe(). */ ++static void ++probe_device(PedDevice **dev, const char *path) ++{ ++ ped_exception_fetch_all(); ++ *dev = ped_device_get(path); ++ if (!*dev) ++ ped_exception_catch(); ++ ped_exception_leave_all(); ++} ++ ++ + int + main(int argc, char** argv) + { +@@ -126,6 +139,22 @@ main(int argc, char** argv) + disk_device = strndup(argv[1], pos - argv[1] + 1); + partition_number = strtol(pos + 1, NULL, 10); + ++ PedDevice *peddev = NULL; ++ /* check if the device really exists */ ++ while (pos != argv[1] && *pos != '/' && !peddev) ++ { ++ disk_device[pos - argv[1] + 1] = '\0'; ++ probe_device(&peddev, disk_device); ++ --pos; ++ } ++ if (!peddev) ++ { ++ free(disk_device); ++ fprintf(stderr, "invalid device\n"); ++ exit(EXIT_FAILURE); ++ } ++ ped_device_destroy(peddev); ++ + if (argc == 3) + { + char* endptr = NULL; diff --git a/parted.changes b/parted.changes index 591fc15..468b7ab 100644 --- a/parted.changes +++ b/parted.changes @@ -1,3 +1,10 @@ +------------------------------------------------------------------- +Tue Dec 19 17:23:10 UTC 2017 - sparschauer@suse.de + +- fatresize: Fix getting the device name from partition name + (boo#959181) + - add: fatresize-fix-getting-dev-name.patch + ------------------------------------------------------------------- Tue Nov 21 09:26:23 UTC 2017 - sebastian.parschauer@suse.com diff --git a/parted.spec b/parted.spec index 7b2620e..40eb174 100644 --- a/parted.spec +++ b/parted.spec @@ -87,6 +87,7 @@ Patch58: parted-add-ignore-busy-option.patch Patch59: parted-fix-resizepart-and-rm-command.patch # Fatresize Patch100: parted-fatresize-autoconf.patch +Patch101: fatresize-fix-getting-dev-name.patch # Upstream tests patches Patch150: tests-set-optimal-blocks-for-scsi_debug.patch Patch151: tests-increase-scsi_debug-tmo.patch @@ -194,6 +195,7 @@ to develop applications that require these. %patch58 -p1 %patch59 -p1 %patch100 -p1 +%patch101 -p1 %patch150 -p1 %patch151 -p1 %patch152 -p1