Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
changeset 207:a19acddb4662
Implement a "-N" flag for mounting: mount at "natural" configured ZFS mountpoints.
NOTE: Note that the semantics of the "-O" flag is left as-is.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Sun, 21 Aug 2022 15:10:09 +0200 |
| parents | 92e5db34eb2b |
| children | 0136dce2db22 |
| files | sbin/fjail |
| diffstat | 1 files changed, 26 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/sbin/fjail Sun Aug 21 14:38:05 2022 +0200 +++ b/sbin/fjail Sun Aug 21 15:10:09 2022 +0200 @@ -40,13 +40,14 @@ -T Create only an extra tiny set of datasets -u Do not automatically mount newly created datasets - mount [-O] [-u] [-n] DATASET MOUNTPOINT + mount [-O] [-u] [-n] DATASET [MOUNTPOINT] Mount the ZFS dataset DATASET and all its children to mountpoint MOUNTPOINT - -O Also mount datasets at mountpoints outside of their natural + -O Also mount datasets at mountpoints outside of their "natural" and inherited mountpoints + -N Mount at their "natural" configured ZFS mountpoints (MOUNTPOINT is not required) -n Do not really mount but show what would be mounted where -u Alias of -n @@ -366,15 +367,19 @@ local _dsname _mountpoint local _name _mp _canmount _mounted local _rootds_mountpoint _relative_mp _real_mp - local _dry_run _mount_outside + local _dry_run _mount_outside _mount_natural _dry_run="" _mount_outside="" - while getopts "Onu" _opt ; do + _mount_natural="" + while getopts "ONnu" _opt ; do case ${_opt} in O) _mount_outside="yes" ;; + N) + _mount_natural="yes" + ;; n|u) _dry_run="yes" ;; @@ -393,20 +398,31 @@ echo "ERROR: no dataset given" >&2 return 2 fi + + _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \ + { echo "ERROR: root dataset does not exist" >&2; return 1; } + if [ -z "${_mountpoint}" ]; then - echo "ERROR: no mountpoint given" >&2 - return 2 + if [ "${_mount_natural}" = "yes" ]; then + _mountpoint="${_rootds_mountpoint}" + else + echo "ERROR: no mountpoint given" >&2 + return 2 + fi + else + if [ "${_mount_natural}" = "yes" ]; then + echo "ERROR: Cannot have a custom mountpoint when \"-O\" is given" >&2 + return 2 + fi fi - # Remove a trailing slash + + # Eventually remove a trailing slash _mountpoint="${_mountpoint%/}" if [ -z "${_mountpoint}" ]; then echo "ERROR: would mount over the root filesystem" >&2 return 1 fi - _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \ - { echo "ERROR: root dataset does not exist" >&2; return 1; } - zfs list -H -o name,mountpoint,canmount,mounted -s mountpoint -t filesystem -r "${_dsname}" \ | { while IFS=$'\t' read -r _name _mp _canmount _mounted ; do
