2014-12-10 14:36:44 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# $FreeBSD$
|
|
|
|
#
|
|
|
|
|
|
|
|
# Print newline-separated list of devices available for mounting.
|
|
|
|
# If there is a filesystem label - use it, otherwise use device name.
|
|
|
|
print_available() {
|
|
|
|
local _fstype _fstype_and_label _label _p
|
|
|
|
|
|
|
|
for _p in ${providers}; do
|
|
|
|
_fstype_and_label="$(fstyp -l "/dev/${_p}" 2> /dev/null)"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
# Ignore devices for which we were unable
|
|
|
|
# to determine filesystem type.
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
_fstype="${_fstype_and_label%% *}"
|
|
|
|
if [ "${_fstype}" != "${_fstype_and_label}" ]; then
|
|
|
|
_label="${_fstype_and_label#* }"
|
2016-03-14 17:45:39 +00:00
|
|
|
# Replace plus signs and slashes with minuses;
|
|
|
|
# leading plus signs have special meaning in maps,
|
2016-03-14 18:57:09 +00:00
|
|
|
# and multi-component keys are just not supported.
|
2016-03-14 17:45:39 +00:00
|
|
|
_label="$(echo ${_label} | sed 's,[+/],-,g')"
|
2014-12-10 14:36:44 +00:00
|
|
|
echo "${_label}"
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "${_p}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
# Print a single map entry.
|
2016-03-18 09:54:09 +00:00
|
|
|
print_map_entry() {
|
|
|
|
local _fstype _p
|
|
|
|
|
|
|
|
_fstype="$1"
|
|
|
|
_p="$2"
|
|
|
|
|
|
|
|
if [ "${_fstype}" = "ntfs" ]; then
|
|
|
|
if [ -f "/usr/local/bin/ntfs-3g" ]; then
|
|
|
|
echo "-mountprog=/usr/local/bin/ntfs-3g,fstype=${_fstype},nosuid :/dev/${_p}"
|
|
|
|
else
|
|
|
|
/usr/bin/logger -p info -t "special_media[$$]" \
|
|
|
|
"Cannot mount ${_fstype} formatted device /dev/${_p}: Install sysutils/fusefs-ntfs first"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "-fstype=${_fstype},nosuid :/dev/${_p}"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Determine map entry contents for the given key and print out the entry.
|
2014-12-10 14:36:44 +00:00
|
|
|
print_one() {
|
|
|
|
local _fstype _fstype_and_label _label _key _p
|
|
|
|
|
|
|
|
_key="$1"
|
|
|
|
|
|
|
|
_fstype="$(fstyp "/dev/${_key}" 2> /dev/null)"
|
|
|
|
if [ $? -eq 0 ]; then
|
2016-03-18 09:54:09 +00:00
|
|
|
print_map_entry "${_fstype}" "${_key}"
|
2014-12-10 14:36:44 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
for _p in ${providers}; do
|
|
|
|
_fstype_and_label="$(fstyp -l "/dev/${_p}" 2> /dev/null)"
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
# Ignore devices for which we were unable
|
|
|
|
# to determine filesystem type.
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
_fstype="${_fstype_and_label%% *}"
|
|
|
|
if [ "${_fstype}" = "${_fstype_and_label}" ]; then
|
|
|
|
# No label, try another device.
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
_label="${_fstype_and_label#* }"
|
2016-03-14 17:45:39 +00:00
|
|
|
# Replace plus signs and slashes with minuses;
|
|
|
|
# leading plus signs have special meaning in maps,
|
|
|
|
# and multi-component keys are just not supported.
|
|
|
|
_label="$(echo ${_label} | sed 's,[+/],-,g')"
|
2014-12-10 14:36:44 +00:00
|
|
|
if [ "${_label}" != "${_key}" ]; then
|
|
|
|
# Labels don't match, try another device.
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2016-03-18 09:54:09 +00:00
|
|
|
print_map_entry "${_fstype}" "${_p}"
|
2014-12-10 14:36:44 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# No matching device - don't print anything, autofs will handle it.
|
|
|
|
}
|
|
|
|
|
|
|
|
# Obtain a list of (geom-provider-name, access-count) pairs, turning this:
|
|
|
|
#
|
|
|
|
# z0xfffff80005085d00 [shape=hexagon,label="ada0\nr2w2e3\nerr#0\nsector=512\nstripe=0"];
|
|
|
|
#
|
|
|
|
# Into this:
|
|
|
|
#
|
|
|
|
# ada0 r2w2e3
|
|
|
|
#
|
|
|
|
# XXX: It would be easier to use kern.geom.conftxt instead, but it lacks
|
|
|
|
# access counts.
|
|
|
|
pairs=$(sysctl kern.geom.confdot | sed -n 's/^.*hexagon,label="\([^\]*\)\\n\([^\]*\).*/\1 \2/p')
|
|
|
|
|
|
|
|
# Obtain a list of GEOM providers that are not already open - not mounted,
|
|
|
|
# and without other GEOM class, such as gpart, attached. In other words,
|
|
|
|
# grep for "r0w0e0". Skip providers with names containing slashes; we're
|
|
|
|
# not interested in geom_label(4) creations.
|
|
|
|
providers=$(echo "$pairs" | awk '$2 == "r0w0e0" && $1 !~ /\// { print $1 }')
|
|
|
|
|
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
print_available
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
print_one "$1"
|
|
|
|
exit 0
|
|
|
|
|