From 4565174733c43a765fadafdc12b5c2e882e96789 Mon Sep 17 00:00:00 2001 From: Hyy2001X <1804430051@qq.com> Date: Tue, 29 Mar 2022 01:32:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20ntfs3=20=E5=BC=BA=E5=88=B6?= =?UTF-8?q?=E6=8C=82=E8=BD=BD;=20=E4=BC=98=E5=8C=96=E6=8C=82=E8=BD=BD?= =?UTF-8?q?=E7=82=B9=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CustomFiles/fake-automount | 53 +++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/CustomFiles/fake-automount b/CustomFiles/fake-automount index 154368a..cefeda2 100755 --- a/CustomFiles/fake-automount +++ b/CustomFiles/fake-automount @@ -5,37 +5,55 @@ LOGGER() { logger -t "automount[$$]" "$*" } +get_mnt() { + [ -z "$*" ] && return + mnt_count=$(uci show | egrep 'fstab.@mount.*uuid' | wc -l) + [ "$mnt_count" = 0 ] && return + local i=1;for i in $(seq 0 $mnt_count) + do + if_enabled=$(uci get fstab.@mount[$i].enabled 2> /dev/null) + [ "$if_enabled" != 1 ] && continue + uuid=$(uci get fstab.@mount[$i].uuid 2> /dev/null) + [ "$uuid" != "$1" ] && continue + mnt=$(uci get fstab.@mount[$i].target 2> /dev/null) + echo $mnt + done +} + if [ "$(uci get fstab.@global[0].auto_mount)" != 1 ] then block mount + rm -f /tmp/automount.pid exit fi +# [ -f /tmp/automount.pid ] && exit echo "$$" > /tmp/automount.pid touch -f /tmp/automount.log case "$HOTPLUG_TYPE,$DEVTYPE" in block,partition) - LOGGER "Attached mode: $ACTION" - sleep 3 + sleep 1 if [ "$ACTION" = remove -o "$ACTION" = add ] then for disk in $(mount | awk '{print $1}' | grep /dev | egrep -v "rom|mtdblock|loop|overlay");do - part=$(mount | grep $disk | awk '{print $3}') + part=$(mount | grep $disk | egrep -v "rom|mtdblock|loop|overlay" | awk '{print $3}') [ ! "$part" ] && continue skip_umount=$(lsblk --list $disk > /dev/null 2>&1; echo $?) if [ "$skip_umount" != 0 ] then umount $part 2> /dev/null || umount -l $part 2> /dev/null - LOGGER "Successfully umounted invisible part [$part]" + LOGGER "Successfully umounted [$part]" [ ! "$(ls -A $part)" ] && rm -rf $part fi done fi + sleep 1 if [ "$ACTION" = add ] then block mount for part in $(lsblk --list | egrep -v "mtdblock|loop|overlay" | grep part | awk '{print $1}');do + blk_id="$(block info /dev/$part | egrep -o 'UUID="[0-9a-zA-Z].+' | awk -F '["]' '/UUID/{print $2}')" skip_mount=$(mount | awk '{print $1}' | grep -q $part ; echo $?) fstype=$(block info /dev/$part 2> /dev/null | egrep -o 'TYPE="[0-9a-zA-Z].+' | awk -F '["]' '/TYPE/{print $2}') if [ "$skip_mount" = 0 ] @@ -43,31 +61,30 @@ block,partition) LOGGER "Already mounted [/dev/$part] on this device" continue fi - if [ -z "$fstype" ] - then - LOGGER "Unknown filesystem of [/dev/$part]" - continue - fi case "$fstype" in - ntfs) + *ntfs*) extra="-o nls=utf8" + [ -n "$(opkg list | grep ntfs3-oot 2> /dev/null)" ] && extra="$extra -o force" + [ -n "$(opkg list | grep antfs 2> /dev/null)" ] && fstype="antfs" ;; vfat) extra="-o iocharset=utf8" ;; esac - LOGGER "Try to mount disk [/dev/$part]($fstype) on [/mnt/$part] ..." - mkdir -p /mnt/$part - chmod 777 /mnt/$part - mount -t $fstype /dev/$part /mnt/$part -o rw,defaults,discard $extra + mnt_point="$(get_mnt $blk_id)" + [ -z "$mnt_point" ] && mnt_point="/mnt/$part" + LOGGER "Mounting disk [/dev/$part]($fstype:$blk_id) on [$mnt_point] ..." + mkdir -p $mnt_point || LOGGER "Failed to create mount point [$mnt_point]" + chmod 777 $mnt_point + mount -t $fstype /dev/$part $mnt_point -o rw,defaults,discard $extra if [ "$?" != 0 ] then - mount /dev/$part /mnt/$part -o rw,defaults && failed=0 || failed=1 + mount /dev/$part $mnt_point -o rw,defaults && failed=0 || failed=1 else failed=0 fi - [ "$failed" = 0 ] && LOGGER "Successfully mounted disk [/dev/$part] on [/mnt/$part]" || { - LOGGER "Failed to mount disk [/dev/$part] on [/mnt/$part]" + [ "$failed" = 0 ] && LOGGER "Successfully mounted disk [/dev/$part]" || { + LOGGER "Failed to mount disk [/dev/$part]" } sleep 1 & unset failed done @@ -76,5 +93,5 @@ block,partition) esac rm -f /tmp/automount.pid -LOGGER "automount: Finished" +LOGGER "automount: Done" exit 0