changeset 528:93b98803219b

fzfs umount: implemented option "-k" (dry-run)
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 04 Sep 2024 18:48:10 +0200
parents b7d60802b25f
children 703e9f357339
files docs/man/man8/fzfs-umount.rst sbin/fzfs
diffstat 2 files changed, 36 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/docs/man/man8/fzfs-umount.rst	Wed Sep 04 18:29:42 2024 +0200
+++ b/docs/man/man8/fzfs-umount.rst	Wed Sep 04 18:48:10 2024 +0200
@@ -6,9 +6,9 @@
 Synopsis
 --------
 
-**fzfs umount** `dataset`
+**fzfs umount** [**-k**] `dataset`
 
-**fzfs unmount** `dataset`
+**fzfs unmount** [**-k**] `dataset`
 
 
 Description
@@ -17,6 +17,16 @@
 Unmount the mounted `dataset` and all its children.
 
 
+Options
+-------
+
+.. program:: fzfs umount
+
+.. option:: -k
+
+   Do not really unmount anything but show what would be unmounted.
+
+
 See Also
 --------
 
--- a/sbin/fzfs	Wed Sep 04 18:29:42 2024 +0200
+++ b/sbin/fzfs	Wed Sep 04 18:48:10 2024 +0200
@@ -36,7 +36,7 @@
 
   mount [-O] [-N] [-P] [-k] [-u] [-n] DATASET [MOUNTPOINT]
 
-  umount DATASET
+  umount [-k] DATASET
 
   unmount
 
@@ -282,8 +282,24 @@
 #:
 command_umount() {
     local _dsname
+    local _opt_dry_run
 
-    local _name _mp _rest _rootds_mountpoint
+    local _opt _name _mp _rest _rootds_mountpoint
+
+    _opt_dry_run=""
+
+    while getopts "k" _opt ; do
+        case ${_opt} in
+            k)
+                _opt_dry_run="yes"
+                ;;
+            \?)
+                return 2;
+                ;;
+        esac
+    done
+    shift $((OPTIND-1))
+    OPTIND=1
 
     _dsname="${1-}"
     [ -z "${_dsname}" ] && { echo "ERROR: no dataset given" 1>&2; return 2; }
@@ -296,8 +312,12 @@
     | /usr/bin/sort -n -r \
     | {
         while IFS=' '$'\t' read -r _name _mp _rest ; do
-            echo "Umounting ${_name} on ${_mp}"
-            /sbin/umount "${_mp}" || return 1
+            if checkyes _opt_dry_run ; then
+                echo "Would umount ${_name} from ${_mp}"
+            else
+                echo "Umounting ${_name} on ${_mp}"
+                /sbin/umount "${_mp}" || return 1
+            fi
         done
     }
     return 0