Mercurial > hgrepos > FreeBSD > ports > sysutils > local-bsdtools
comparison sbin/fjail @ 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 |
comparison
equal
deleted
inserted
replaced
| 206:92e5db34eb2b | 207:a19acddb4662 |
|---|---|
| 38 -s Also create a dataset for freebsd-update data files | 38 -s Also create a dataset for freebsd-update data files |
| 39 -t Create a more tiny set of datasets | 39 -t Create a more tiny set of datasets |
| 40 -T Create only an extra tiny set of datasets | 40 -T Create only an extra tiny set of datasets |
| 41 -u Do not automatically mount newly created datasets | 41 -u Do not automatically mount newly created datasets |
| 42 | 42 |
| 43 mount [-O] [-u] [-n] DATASET MOUNTPOINT | 43 mount [-O] [-u] [-n] DATASET [MOUNTPOINT] |
| 44 | 44 |
| 45 Mount the ZFS dataset DATASET and all its children to mountpoint | 45 Mount the ZFS dataset DATASET and all its children to mountpoint |
| 46 MOUNTPOINT | 46 MOUNTPOINT |
| 47 | 47 |
| 48 -O Also mount datasets at mountpoints outside of their natural | 48 -O Also mount datasets at mountpoints outside of their "natural" |
| 49 and inherited mountpoints | 49 and inherited mountpoints |
| 50 -N Mount at their "natural" configured ZFS mountpoints (MOUNTPOINT is not required) | |
| 50 -n Do not really mount but show what would be mounted where | 51 -n Do not really mount but show what would be mounted where |
| 51 -u Alias of -n | 52 -u Alias of -n |
| 52 | 53 |
| 53 umount DATASET | 54 umount DATASET |
| 54 | 55 |
| 364 # | 365 # |
| 365 command_mount() { | 366 command_mount() { |
| 366 local _dsname _mountpoint | 367 local _dsname _mountpoint |
| 367 local _name _mp _canmount _mounted | 368 local _name _mp _canmount _mounted |
| 368 local _rootds_mountpoint _relative_mp _real_mp | 369 local _rootds_mountpoint _relative_mp _real_mp |
| 369 local _dry_run _mount_outside | 370 local _dry_run _mount_outside _mount_natural |
| 370 | 371 |
| 371 _dry_run="" | 372 _dry_run="" |
| 372 _mount_outside="" | 373 _mount_outside="" |
| 373 while getopts "Onu" _opt ; do | 374 _mount_natural="" |
| 375 while getopts "ONnu" _opt ; do | |
| 374 case ${_opt} in | 376 case ${_opt} in |
| 375 O) | 377 O) |
| 376 _mount_outside="yes" | 378 _mount_outside="yes" |
| 379 ;; | |
| 380 N) | |
| 381 _mount_natural="yes" | |
| 377 ;; | 382 ;; |
| 378 n|u) | 383 n|u) |
| 379 _dry_run="yes" | 384 _dry_run="yes" |
| 380 ;; | 385 ;; |
| 381 \?|:) | 386 \?|:) |
| 391 | 396 |
| 392 if [ -z "${_dsname}" ]; then | 397 if [ -z "${_dsname}" ]; then |
| 393 echo "ERROR: no dataset given" >&2 | 398 echo "ERROR: no dataset given" >&2 |
| 394 return 2 | 399 return 2 |
| 395 fi | 400 fi |
| 401 | |
| 402 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \ | |
| 403 { echo "ERROR: root dataset does not exist" >&2; return 1; } | |
| 404 | |
| 396 if [ -z "${_mountpoint}" ]; then | 405 if [ -z "${_mountpoint}" ]; then |
| 397 echo "ERROR: no mountpoint given" >&2 | 406 if [ "${_mount_natural}" = "yes" ]; then |
| 398 return 2 | 407 _mountpoint="${_rootds_mountpoint}" |
| 399 fi | 408 else |
| 400 # Remove a trailing slash | 409 echo "ERROR: no mountpoint given" >&2 |
| 410 return 2 | |
| 411 fi | |
| 412 else | |
| 413 if [ "${_mount_natural}" = "yes" ]; then | |
| 414 echo "ERROR: Cannot have a custom mountpoint when \"-O\" is given" >&2 | |
| 415 return 2 | |
| 416 fi | |
| 417 fi | |
| 418 | |
| 419 # Eventually remove a trailing slash | |
| 401 _mountpoint="${_mountpoint%/}" | 420 _mountpoint="${_mountpoint%/}" |
| 402 if [ -z "${_mountpoint}" ]; then | 421 if [ -z "${_mountpoint}" ]; then |
| 403 echo "ERROR: would mount over the root filesystem" >&2 | 422 echo "ERROR: would mount over the root filesystem" >&2 |
| 404 return 1 | 423 return 1 |
| 405 fi | 424 fi |
| 406 | |
| 407 _rootds_mountpoint="$(zfs list -H -o mountpoint -t filesystem "${_dsname}")" || \ | |
| 408 { echo "ERROR: root dataset does not exist" >&2; return 1; } | |
| 409 | 425 |
| 410 zfs list -H -o name,mountpoint,canmount,mounted -s mountpoint -t filesystem -r "${_dsname}" \ | 426 zfs list -H -o name,mountpoint,canmount,mounted -s mountpoint -t filesystem -r "${_dsname}" \ |
| 411 | { | 427 | { |
| 412 while IFS=$'\t' read -r _name _mp _canmount _mounted ; do | 428 while IFS=$'\t' read -r _name _mp _canmount _mounted ; do |
| 413 # Skip filesystems that are already mounted | 429 # Skip filesystems that are already mounted |
