From 9b711f20ecefc55d42f587ca408de59140ae50a0 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Mon, 2 Dec 2019 17:13:00 +0100 Subject: [PATCH] Reassured success of unmount --- xorriso-dd-target/xorriso-dd-target | 42 ++++++++++++++------- xorriso-dd-target/xorriso-dd-target.1 | 10 ++--- xorriso-dd-target/xorriso-dd-target.info | 48 ++++++++++++------------ xorriso-dd-target/xorriso-dd-target.texi | 12 +++--- 4 files changed, 64 insertions(+), 48 deletions(-) diff --git a/xorriso-dd-target/xorriso-dd-target b/xorriso-dd-target/xorriso-dd-target index 210174b0..a6a37dfc 100755 --- a/xorriso-dd-target/xorriso-dd-target +++ b/xorriso-dd-target/xorriso-dd-target @@ -512,19 +512,12 @@ list_devices() { return 0; } -write_image() { - - if test -z "$umount_cmd" - then - echo "No executable program umount found in: $sudo_x_dir_list" >&2 - return 6 - fi - - echo "Looking for mount points of $2:" - partitions=$($lsblk_cmd -n -p -o NAME /dev/"$2" | grep -v '^'/dev/"$2"'$' \ +## Puts list of mounted (sub-)devices of $1 into $mounted_devs +list_mounted_of() { + partitions=$($lsblk_cmd -n -p -o NAME /dev/"$1" | grep -v '^'/dev/"$1"'$' \ | sed -e 's/[^a-zA-Z0-9_+@:.,/-]//g' | tr '\n\r' ' ') mounted_devs= - for i in /dev/"$2" $partitions + for i in /dev/"$1" $partitions do # Show the found mount lines and add their device paths to list mount_line=$(mount | grep '^'"$i"' ') @@ -534,6 +527,20 @@ write_image() { mounted_devs="$mounted_devs $i" fi done +} + +## Does the work of unmounting and dd-ing +write_image() { + + if test -z "$umount_cmd" + then + echo "No executable program umount found in: $sudo_x_dir_list" >&2 + return 6 + fi + echo "Looking for mount points of $2:" + mounted_devs= + list_mounted_of "$2" + if test -n "$dummy_force" then echo "AGAINST THE ADVICE BY THIS PROGRAM, a daring user could do:" @@ -554,13 +561,20 @@ write_image() { then echo "Unmounted: $i" else - echo "FAILURE: Non-zero exit value with: sudo_cmd $umount_cmd $i" >&2 + echo "FAILURE: Non-zero exit value with: $sudo_cmd $umount_cmd $i" >&2 return 7 fi fi done - fi + # Check again if any mount points still exist + list_mounted_of "$2" + if test -n "$mounted_devs" -a -z "$dummy_run" + then + echo "FAILURE: $sudo_cmd $umount_cmd could not remove all mounts: $mounted_devs" >&2 + return 7 + fi + fi if test -z "$dd_cmd" then @@ -585,6 +599,8 @@ write_image() { return 0 } +# main() + reset_job arg_interpreter "$@" diff --git a/xorriso-dd-target/xorriso-dd-target.1 b/xorriso-dd-target/xorriso-dd-target.1 index abe5cf5d..40932850 100644 --- a/xorriso-dd-target/xorriso-dd-target.1 +++ b/xorriso-dd-target/xorriso-dd-target.1 @@ -2,7 +2,7 @@ .\" .\" IMPORTANT NOTE: .\" -.\" The original of this file is kept in xorriso/xorriso-tcltk.texi +.\" The original of this file is kept in xorriso/xorriso-dd-target.texi .\" This here was generated by program xorriso/make_xorriso_1 .\" .\" @@ -53,7 +53,7 @@ possible unmounting, and for possible image writing. Option \fB\-with_sudo\fR offers a way to gain this power only for those tasks and to run the program elsewise with a normal user's power. .br -If a particular disk image file is intended as eventual copy source, then +If a particular disk image file is intended as copy source, then its path should be given by option \-image_file, so that its size can be used as decision criterion. .PP @@ -223,7 +223,7 @@ Example: .br $ xorriso\-dd\-target \-with_sudo \-plug_test \-DO_WRITE \\ .br -> \-image_file debian\-live\-10.0.0\-amd64\-xfce.iso + \-image_file debian\-live\-10.0.0\-amd64\-xfce.iso .br ... sudo messages and above plug test steps 1 and 2 ... .br @@ -269,7 +269,7 @@ Example: .br $ xorriso\-dd\-target \-with_sudo \-dummy_force sdd \\ .br -> \-image_file debian\-live\-10.0.0\-amd64\-xfce.iso + \-image_file debian\-live\-10.0.0\-amd64\-xfce.iso .br ... .br @@ -484,7 +484,7 @@ Copyright (c) 2019 Thomas Schmitt .br Permission is granted to distribute this text freely. It shall only be modified in sync with the technical properties of xorriso\-dd\-target. -If you make use of the license to derive modified versions of xorriso\-idd\-target +If you make use of the license to derive modified versions of xorriso\-dd\-target then you are entitled to modify this text under that same license. .SH CREDITS \fBxorriso\-dd\-target\fR is developed in cooperation with Nio Wiklund alias diff --git a/xorriso-dd-target/xorriso-dd-target.info b/xorriso-dd-target/xorriso-dd-target.info index f3147408..67035c58 100644 --- a/xorriso-dd-target/xorriso-dd-target.info +++ b/xorriso-dd-target/xorriso-dd-target.info @@ -1,7 +1,7 @@ This is xorriso-dd-target.info, produced by makeinfo version 5.2 from xorriso-dd-target.texi. -xorriso-tcltk - Device evaluator and disk image copier for GNU/Linux +xorriso-dd-target - Device evaluator and disk image copier for GNU/Linux Copyright (C) 2019 Thomas Schmitt @@ -54,9 +54,9 @@ of the target device. possible unmounting, and for possible image writing. Option *-with_sudo* offers a way to gain this power only for those tasks and to run the program elsewise with a normal user's power. -If a particular disk image file is intended as eventual copy source, -then its path should be given by option -image_file, so that its size -can be used as decision criterion. +If a particular disk image file is intended as copy source, then its +path should be given by option -image_file, so that its size can be used +as decision criterion. Following are use case descriptions with examples: * Menu: @@ -197,7 +197,7 @@ Option *-dummy* prevents this kind of real action and rather shows the planned umount and dd commands on stdout. Example: $ xorriso-dd-target -with_sudo -plug_test -DO_WRITE \ -> -image_file debian-live-10.0.0-amd64-xfce.iso +-image_file debian-live-10.0.0-amd64-xfce.iso ... sudo messages and above plug test steps 1 and 2 ... @@ -232,7 +232,7 @@ device, even if it looks not advisable. I.e. it will show the shell commands which the program does not dare to perform. Example: $ xorriso-dd-target -with_sudo -dummy_force sdd \ -> -image_file debian-live-10.0.0-amd64-xfce.iso +-image_file debian-live-10.0.0-amd64-xfce.iso ... sdd : NO : usb+ has_iso9660+ has_vfat+ has_ext2- @@ -430,7 +430,7 @@ Copyright (c) 2019 Thomas Schmitt Permission is granted to distribute this text freely. It shall only be modified in sync with the technical properties of xorriso-dd-target. If you make use of the license to derive modified versions of -xorriso-idd-target then you are entitled to modify this text under that +xorriso-dd-target then you are entitled to modify this text under that same license. 14.3 Credits @@ -497,22 +497,22 @@ File: xorriso-dd-target.info, Node: ConceptIdx, Next: Top, Prev: CommandIdx,  Tag Table: -Node: Top425 -Node: Overview992 -Node: Simplenames2784 -Node: Listall3395 -Node: Givendevices4805 -Node: Plugtest5607 -Node: Dowrite7355 -Node: Unwise8464 -Node: Reasons9822 -Node: Options12120 -Node: Examples14722 -Node: Files14895 -Node: Seealso15053 -Node: Bugreport15219 -Node: Legal15805 -Node: CommandIdx16510 -Node: ConceptIdx17557 +Node: Top429 +Node: Overview996 +Node: Simplenames2779 +Node: Listall3390 +Node: Givendevices4800 +Node: Plugtest5602 +Node: Dowrite7350 +Node: Unwise8457 +Node: Reasons9813 +Node: Options12111 +Node: Examples14713 +Node: Files14886 +Node: Seealso15044 +Node: Bugreport15210 +Node: Legal15796 +Node: CommandIdx16500 +Node: ConceptIdx17547  End Tag Table diff --git a/xorriso-dd-target/xorriso-dd-target.texi b/xorriso-dd-target/xorriso-dd-target.texi index 3dcc683c..c2f30585 100644 --- a/xorriso-dd-target/xorriso-dd-target.texi +++ b/xorriso-dd-target/xorriso-dd-target.texi @@ -43,7 +43,7 @@ @c man .\" @c man .\" IMPORTANT NOTE: @c man .\" -@c man .\" The original of this file is kept in xorriso/xorriso-tcltk.texi +@c man .\" The original of this file is kept in xorriso/xorriso-dd-target.texi @c man .\" This here was generated by program xorriso/make_xorriso_1 @c man .\" @c man .\" @@ -66,7 +66,7 @@ @c man .nh @c man-ignore-lines begin @copying -xorriso-tcltk - Device evaluator and disk image copier for GNU/Linux +xorriso-dd-target - Device evaluator and disk image copier for GNU/Linux Copyright @copyright{} 2019 Thomas Schmitt @@ -133,7 +133,7 @@ possible unmounting, and for possible image writing. Option @strong{-with_sudo} offers a way to gain this power only for those tasks and to run the program elsewise with a normal user's power. @* -If a particular disk image file is intended as eventual copy source, then +If a particular disk image file is intended as copy source, then its path should be given by option -image_file, so that its size can be used as decision criterion. @sp 1 @@ -328,7 +328,7 @@ Example: @* $ xorriso-dd-target -with_sudo -plug_test -DO_WRITE \ @* -> -image_file debian-live-10.0.0-amd64-xfce.iso + -image_file debian-live-10.0.0-amd64-xfce.iso @* ... sudo messages and above plug test steps 1 and 2 ... @* @@ -377,7 +377,7 @@ Example: @* $ xorriso-dd-target -with_sudo -dummy_force sdd \ @* -> -image_file debian-live-10.0.0-amd64-xfce.iso + -image_file debian-live-10.0.0-amd64-xfce.iso @* ... @* @@ -644,7 +644,7 @@ Copyright (c) 2019 Thomas Schmitt @* Permission is granted to distribute this text freely. It shall only be modified in sync with the technical properties of xorriso-dd-target. -If you make use of the license to derive modified versions of xorriso-idd-target +If you make use of the license to derive modified versions of xorriso-dd-target then you are entitled to modify this text under that same license. @c man .SH CREDITS @section Credits