I'm not sure if this is the right place to propose a change to the mount script in the block-mount package. Admin, please feel free to move the thread if this is the wrong subforum.
The idea is to support auto mount attached storage devices using the labels of the partition as names of the mountpoints. The idea similar to modern linux desktops, e.g. mount /dev/sda1 /mnt/MyBackup. This is especially useful when sharing storage on the network, labels are much simpler to identify than sda1, sda2, sdb1... etc.
I also think support utf8 is a safer default (please correct me if I'm wrong), considering this is the default encoding being used by most linux desktops nowadays.
Here's a quick dirty patch I've come up with to implement these features. But I hope a developer would consider accepting this change.
Patch file for /etc/hotplug.d/block/40-mount:
--- 40-mount.orig 2013-02-16 01:28:19.000000000 +1300
+++ 40-mount 2013-02-16 22:22:52.680067821 +1300
@@ -11,7 +11,6 @@
if [ `basename $blkdev` != "block" ]; then
device=`basename $DEVPATH`
- mountpoint=`sed -ne "s|^[^ ]*/$device ||; T; s/ .*//p" /proc/self/mounts`
case "$ACTION" in
add)
@@ -74,16 +73,41 @@
case "$device" in
mtdblock*) ;;
*)
- ( mkdir -p /mnt/$device && mount /dev/$device /mnt/$device ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
+ export $(blkid -o export /dev/$device)
+ case "$TYPE" in
+ vfat)
+ mount_opts="-o iocharset=utf8"
+ ;;
+ ntfs)
+ mount_opts="-o nls=utf8"
+ ;;
+ esac
+ if [ -n "$LABEL" ]; then
+ mountpoint=/mnt/$LABEL
+ else
+ mountpoint=/mnt/$device
+ fi
+ let i=0
+ while [ -d "$mountpoint" ]; do
+ i=$(( i + 1 ))
+ done
+ [ "$i" -gt 0 ] && mountpoint=${mountpoint}-$i
+ ( mkdir -p $mountpoint && mount /dev/$device $mountpoint $mount_opts ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
;;
esac
}
}
+ mountpoint=`sed -ne "s|^[^ ]*/$device ||; T; s/ .*//p" /proc/self/mounts`
+ echo "$mountpoint" > /tmp/$device
reset_dev_section_cb
;;
remove)
umount /dev/$device
+ mountpoint=`cat /tmp/$device`
umount $mountpoint
+ rmdir $mountpoint
+ rm /tmp/$device
+ logger -t 'fstab' "Umounted /dev/$device at $mountpoint"
;;
esac
Complete file:
#!/bin/sh
# Copyright (C) 2009-2012 OpenWrt.org
# Copyright (C) 2010 Vertical Communications
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
. /lib/functions/block.sh
blkdev=`dirname $DEVPATH`
if [ `basename $blkdev` != "block" ]; then
device=`basename $DEVPATH`
case "$ACTION" in
add)
local from_fstab
local anon_mount
local anon_swap
local anon_fsck
local mds_mount_target
local mds_mount_device
local mds_mount_fstype
local sds_swap_device
local use_device
local do_fsck=0
local fsck_type
local autoswap_from_fstab
local automount_from_fstab
mount_dev_section_cb() {
mds_mount_target="$2"
mds_mount_device="$3"
mds_mount_fstype="$4"
mds_mount_enabled="$6"
}
swap_dev_section_cb() {
sds_swap_device="$2"
return 0
}
config_get_automount
automount_from_fstab="$from_fstab"
[ "$automount_from_fstab" -eq 1 ] && {
config_get_mount_section_by_device "/dev/$device"
use_device="$mds_mount_device"
[ "$mds_mount_enabled" -eq 1 ] && {
if [ -n "$mds_mount_target" ]; then
grep -q "/dev/$device" /proc/swaps || grep -q "/dev/$device" /proc/mounts || {
( mkdir -p "$mds_mount_target" && mount "$mds_mount_target" ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
}
else
logger -t 'fstab' "Mount enabled for $mds_mount_device but it doesn't have a defined mountpoint (target)"
fi
}
}
[ -z "$use_device" ] && {
config_get_autoswap
autoswap_from_fstab="$from_fstab"
[ "$autoswap_from_fstab" -eq 1 ] && {
config_get_swap_section_by_device "/dev/$device"
use_device="$sds_swap_device"
}
}
grep -q "/dev/$device" /proc/swaps || grep -q "/dev/$device" /proc/mounts || {
[ "$anon_mount" -eq 1 -a -z "$use_device" ] && {
case "$device" in
mtdblock*) ;;
*)
export $(blkid -o export /dev/$device)
#[ "$TYPE" = "vfat" -o "$TYPE" = "ntfs" ] && mount_opts="-o iocharset=utf8"
case "$TYPE" in
vfat)
mount_opts="-o iocharset=utf8"
;;
ntfs)
mount_opts="-o nls=utf8"
;;
esac
if [ -n "$LABEL" ]; then
mountpoint=/mnt/$LABEL
else
mountpoint=/mnt/$device
fi
let i=0
while [ -d "$mountpoint" ]; do
i=$(( i + 1 ))
done
[ "$i" -gt 0 ] && mountpoint=${mountpoint}-$i
( mkdir -p $mountpoint && mount /dev/$device $mountpoint $mount_opts ) 2>&1 | tee /proc/self/fd/2 | logger -t 'fstab'
;;
esac
}
}
mountpoint=`sed -ne "s|^[^ ]*/$device ||; T; s/ .*//p" /proc/self/mounts`
echo "$mountpoint" > /tmp/$device
reset_dev_section_cb
;;
remove)
umount /dev/$device
mountpoint=`cat /tmp/$device`
umount $mountpoint
rmdir $mountpoint
rm /tmp/$device
logger -t 'fstab' "Umounted /dev/$device at $mountpoint"
;;
esac
fi