summaryrefslogtreecommitdiffstats
path: root/etc/autofs
diff options
context:
space:
mode:
authortrasz <trasz@FreeBSD.org>2014-12-10 14:36:44 +0000
committertrasz <trasz@FreeBSD.org>2014-12-10 14:36:44 +0000
commit5a2f0c0e007e0c887b40dd74adf4feb0b5703c29 (patch)
tree7510c012671cf60372e8a75bbee1eff547c1177a /etc/autofs
parent3e3c248f832f796881ac2ce0d45049552e8d9a9b (diff)
downloadFreeBSD-src-5a2f0c0e007e0c887b40dd74adf4feb0b5703c29.zip
FreeBSD-src-5a2f0c0e007e0c887b40dd74adf4feb0b5703c29.tar.gz
Add "-media" autofs map, to access data on removable media, such as CD
drives or flash keys. It can be enabled by uncommenting a single entry in default /etc/auto_master. It can also be easily modified to use fuse-based filesystems instead of in-kernel ones. There is still one deficiency - the mountpoints are permanent, they don't disappear when user removes the media. Fixing it needs some autofs changes. Differential Revision: https://reviews.freebsd.org/D1210 MFC after: 1 month Sponsored by: The FreeBSD Foundation
Diffstat (limited to 'etc/autofs')
-rw-r--r--etc/autofs/Makefile2
-rwxr-xr-xetc/autofs/special_media93
2 files changed, 94 insertions, 1 deletions
diff --git a/etc/autofs/Makefile b/etc/autofs/Makefile
index c9eda50..3aa7e03 100644
--- a/etc/autofs/Makefile
+++ b/etc/autofs/Makefile
@@ -1,6 +1,6 @@
# $FreeBSD$
-FILES= include_ldap special_hosts special_null
+FILES= include_ldap special_hosts special_media special_null
NO_OBJ=
FILESDIR= /etc/autofs
diff --git a/etc/autofs/special_media b/etc/autofs/special_media
new file mode 100755
index 0000000..2a654b1
--- /dev/null
+++ b/etc/autofs/special_media
@@ -0,0 +1,93 @@
+#!/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#* }"
+ echo "${_label}"
+ continue
+ fi
+
+ echo "${_p}"
+ done
+}
+
+# Print a single map entry.
+print_one() {
+ local _fstype _fstype_and_label _label _key _p
+
+ _key="$1"
+
+ _fstype="$(fstyp "/dev/${_key}" 2> /dev/null)"
+ if [ $? -eq 0 ]; then
+ echo "-fstype=${_fstype},nosuid :/dev/${_key}"
+ 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#* }"
+ if [ "${_label}" != "${_key}" ]; then
+ # Labels don't match, try another device.
+ continue
+ fi
+
+ echo "-fstype=${_fstype},nosuid :/dev/${_p}"
+ 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
+
OpenPOWER on IntegriCloud