Skip to content

Commit 14d8554

Browse files
committed
zsnapshots: check if input is a valid ZFS filesystem
1 parent be37517 commit 14d8554

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

zfsbootmenu/bin/zsnapshots

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ fi
3131

3232
fs="${1}"
3333

34+
if ! is_zfs_filesystem "${fs}" ; then
35+
zerror "'${fs}' is not a ZFS filesystem"
36+
exit 1
37+
fi
38+
3439
COLUMNS="$( tput cols )"
3540

3641
while true; do

zfsbootmenu/lib/zfsbootmenu-core.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,6 @@ is_efi_system() {
20722072
return 1
20732073
}
20742074

2075-
20762075
# arg1: 'ro' or 'rw' to mount or remount efivarfs in that desired mode
20772076
# arg2: optional mountpoint
20782077
# prints: nothing
@@ -2096,3 +2095,21 @@ mount_efivarfs() {
20962095
mount -t efivarfs efivarfs "${efivar_location}" -o "${efivar_state}"
20972096
fi
20982097
}
2098+
2099+
# arg1: zfs dataset name
2100+
# returns: 0 if filesystem
2101+
2102+
is_zfs_filesystem() {
2103+
local dataset
2104+
2105+
dataset="${1}"
2106+
2107+
if [ -z "${dataset}" ]; then
2108+
zerror "dataset undefined"
2109+
return 1
2110+
fi
2111+
2112+
zfs list -H -o name -t filesystem "${dataset}" >/dev/null 2>&1 && return 0
2113+
2114+
return 1
2115+
}

0 commit comments

Comments
 (0)