From 8fee0fce40f1ba754db1e12804d1192b9b3736b2 Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Sat, 14 Dec 2019 17:13:01 +0100 Subject: [PATCH] Created function xdt_unmount from xdt_write_image --- xorriso-dd-target/xorriso-dd-target.xdt | 63 ++++++++++++++----------- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/xorriso-dd-target/xorriso-dd-target.xdt b/xorriso-dd-target/xorriso-dd-target.xdt index c8ed57e6..983dc5e6 100755 --- a/xorriso-dd-target/xorriso-dd-target.xdt +++ b/xorriso-dd-target/xorriso-dd-target.xdt @@ -650,6 +650,40 @@ xdt_list_mounted_of() { return 0 } +## Unmount xdt_mounted_devs (maybe filled by xdt_list_mounted_of) +xdt_unmount() { + if test -z "$xdt_mounted_devs" + then + return 0 + fi + + for xdt_i in $xdt_mounted_devs + do + if test -n "$xdt_dummy_run" + then + echo " $xdt_sudo_cmd $xdt_umount_cmd $xdt_i" + elif $xdt_sudo_cmd "$xdt_umount_cmd" "$xdt_i" + then + echo "Unmounted: $xdt_i" + else + echo "FAILURE: Non-zero exit value with: $xdt_sudo_cmd $xdt_umount_cmd $xdt_i" >&2 + return 7 + fi + done + + # Check again if any mount points still exist + if test -z "$xdt_dummy_run" + then + xdt_list_mounted_of "$2" + if test -n "$xdt_mounted_devs" + then + echo "FAILURE: $xdt_sudo_cmd $xdt_umount_cmd could not remove all mounts: $xdt_mounted_devs" >&2 + return 7 + fi + fi + return 0 +} + ## Does the work of unmounting and dd-ing xdt_write_image() { @@ -670,35 +704,8 @@ xdt_write_image() { then echo "Would do if not -dummy:" fi - if test -n "$xdt_mounted_devs" - then - for xdt_i in $xdt_mounted_devs - do - if test -n "$xdt_dummy_run" - then - echo " $xdt_sudo_cmd $xdt_umount_cmd $xdt_i" - else - if $xdt_sudo_cmd "$xdt_umount_cmd" "$xdt_i" - then - echo "Unmounted: $xdt_i" - else - echo "FAILURE: Non-zero exit value with: $xdt_sudo_cmd $xdt_umount_cmd $xdt_i" >&2 - return 7 - fi - fi - done - # Check again if any mount points still exist - if test -z "$xdt_dummy_run" - then - xdt_list_mounted_of "$2" - if test -n "$xdt_mounted_devs" - then - echo "FAILURE: $xdt_sudo_cmd $xdt_umount_cmd could not remove all mounts: $xdt_mounted_devs" >&2 - return 7 - fi - fi - fi + xdt_unmount || return "$?" if test -z "$xdt_dd_cmd" then