forked from cbsd/cbsd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzfs.subr
70 lines (60 loc) · 1.49 KB
/
zfs.subr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#v10.0.0
# return 0 if $1 is not valid ZFS mountpoint
# return 1 if $1 is valid ZFS mountpoint and mounted
# return 2 if $1 is valid ZFS mountpoint and not mounted
# if zfsmnt /mnt; then
# echo " not zfs (mounted or not) mountpoint"
# fi
# export ZPOOL for name ZFS for $1 mountpoint
zfsmnt() {
local _A
ZPOOL=$(zfs list -Ho name,mountpoint | while read _name _mnt; do
[ "${_mnt}" = "${1}" ] && echo ${_name} && exit 2
done)
if [ $? -eq 2 ]; then
# Check for mounted
_A=`zfs get -Ho value mounted ${ZPOOL}`
[ "${_A}" = "yes" ] && return 1
return 2
else
return 0
fi
}
# return 0 if $1 is not valid ZFS filesystem
# return 1 if $1 is valid ZFS mountpoint and mounted
# return 2 if $1 is valid ZFS mountpoint and not mounted
# if zfsfs /mnt; then
# echo " not zfs (mounted or not) mounted"
# fi
zfsfs() {
local _A
_A=$(zfs list -Ho name | while read _name; do
[ "${_name}" = "${1}" ] && exit 2
done)
if [ $? -eq 2 ]; then
# Check for mounted
_A=`zfs get -Ho value mounted ${1}`
[ "${_A}" = "yes" ] && return 1
return 2
else
return 0
fi
}
# export zmnt if $zroot exist, return 1
getmnt() {
local _res
[ -z "$1" ] && return 1
zmnt=`zfs get -Ho value mountpoint ${1}`
return $?
}
# return 0 if ${ZPOOL}/$1 zfs source exist
# if zfsroot jail1; then
# echo "zroot/$jail1 exist
# fi
zfsroot() {
[ -z "$1" ] && return 0
zfs list -H -o name | while read _mnt; do
[ "$_mnt" = "${ZPOOL}/${1}" ] && exit 0
done
return $?
}