From ed6d787bef94010fc444d0742f8362371a8c0529 Mon Sep 17 00:00:00 2001 From: kingofotaku Date: Sat, 30 May 2026 15:51:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(usb2jffs):=20=E4=BF=AE=E5=A4=8DRT-AX89X?= =?UTF-8?q?=E7=AD=89=E8=AE=BE=E5=A4=87=E7=9A=84ubifs=E6=8C=82=E8=BD=BD?= =?UTF-8?q?=E5=92=8Centware=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修复了4个影响RT-AX89X(内核4.4 + ubifs分区)和安装了entware(amtm)用户的Bug: 1. LINUX_VER判断缺少内核4.4的ubifs支持 RT-AX89X虽然内核版本为4.4,但JFFS分区实际使用ubifs格式而非jffs2。 原代码仅在LINUX_VER为419或54时使用ubifs挂载,导致4.4内核的设备 错误地使用jffs2方式挂载/cifs2,必然失败。 2. mounted_nu硬编码为2导致entware环境下检测失败 安装了entware(amtm)的设备会在USB分区上创建asusware.arm的bind mount, 导致同一个/dev/sdX设备在mount表中出现3次而非2次。 原代码中所有==2的精确匹配全部失效,表现为: - WebUI显示尚未挂载(实际已挂载) - 同步、备份、恢复功能全部不可用 - 卸载时无法检测到已挂载的USB设备 3. 手动挂载时/cifs2重复挂载失败 开机自动挂载M01已将/cifs2挂载成功后, 用户在WebUI手动点击挂载会再次执行start_usb2jffs, 此时mount /cifs2会因为已被占用而失败。 4. usb_path变量多行导致WebUI状态检测卡死 entware的asusware.arm bind mount使得grep匹配到多个挂载点, usb_path变量包含多行内容,导致http_response返回格式损坏, WebUI永远卡在检测状态中。 --- usb2jffs/usb2jffs/init.d/M01usb2jffs.sh | 4 ++-- usb2jffs/usb2jffs/scripts/usb2jffs_config.sh | 19 ++++++++++--------- .../usb2jffs/scripts/usb2jffs_mount_status.sh | 4 ++-- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/usb2jffs/usb2jffs/init.d/M01usb2jffs.sh b/usb2jffs/usb2jffs/init.d/M01usb2jffs.sh index 73c47686..a7e67c7a 100755 --- a/usb2jffs/usb2jffs/init.d/M01usb2jffs.sh +++ b/usb2jffs/usb2jffs/init.d/M01usb2jffs.sh @@ -135,7 +135,7 @@ JFFS2USB(){ # 防止用户在路由器开机状态,并且已经替换了JFFS为USB的情况下,再插入一个有.koolshare_jffs目录的USB储存设备导致重复挂载 get_current_jffs_device local mounted_nu=$(mount | /bin/grep "${jffs_device}" | grep -E "/tmp/mnt/|/jffs"|/bin/grep -c "/dev/s") - if [ "${mounted_nu}" == "2" ]; then + if [ "${mounted_nu}" -ge "2" ]; then # echo_date "USB2JFFS:检测到你的USB磁盘${jffs_device}已经挂载在/jffs上了,跳过!" return 1 fi @@ -290,7 +290,7 @@ JFFS2USB(){ nvram commit # 把原来的jffs分区挂载到cifs - if [ "${LINUX_VER}" == "419" -o "${LINUX_VER}" == "54" ];then + if [ "${LINUX_VER}" == "44" -o "${LINUX_VER}" == "419" -o "${LINUX_VER}" == "54" ];then mount -t ubifs ${mtd_disk} /cifs2 else mount -t jffs2 -o rw,noatime ${mtd_disk} /cifs2 diff --git a/usb2jffs/usb2jffs/scripts/usb2jffs_config.sh b/usb2jffs/usb2jffs/scripts/usb2jffs_config.sh index 410548e7..9ca7e4ad 100755 --- a/usb2jffs/usb2jffs/scripts/usb2jffs_config.sh +++ b/usb2jffs/usb2jffs/scripts/usb2jffs_config.sh @@ -303,7 +303,8 @@ start_usb2jffs(){ # 把原来的jffs分区挂载到cifs2 echo_date "将${mtd_disk}挂载在/cifs2" - if [ "${LINUX_VER}" == "419" -o "${LINUX_VER}" == "54" ];then + umount -l /cifs2 2>/dev/null + if [ "${LINUX_VER}" == "44" -o "${LINUX_VER}" == "419" -o "${LINUX_VER}" == "54" ];then mount -t ubifs ${mtd_disk} /cifs2 else mount -t jffs2 -o rw,noatime ${mtd_disk} /cifs2 @@ -320,7 +321,7 @@ start_usb2jffs(){ else echo_date "USB型JFFS挂载失败!!" echo_date "尝试恢复原始挂载方式!" - if [ "${LINUX_VER}" == "419" -o "${LINUX_VER}" == "54" ];then + if [ "${LINUX_VER}" == "44" -o "${LINUX_VER}" == "419" -o "${LINUX_VER}" == "54" ];then mount -t ubifs ${mtd_disk} /jffs else mount -t jffs2 -o rw,noatime ${mtd_disk} /jffs @@ -343,7 +344,7 @@ stop_usb2jffs(){ # 检测是否有USB磁盘挂载在/jffs上 get_current_jffs_device local mounted_nu=$(mount | /bin/grep "${jffs_device}" | grep -E "/tmp/mnt/|/jffs"|/bin/grep -c "/dev/s") - if [ "$mounted_nu" == "2" ]; then + if [ "$mounted_nu" -ge "2" ]; then local usb_path=$(mount | /bin/grep "${jffs_device}" | /bin/grep "/tmp/mnt/" | awk '{print $3}') echo_date "检测到USB磁盘的${usb_path}/.koolshare_jffs挂载在/jffs上" else @@ -401,7 +402,7 @@ stop_usb2jffs(){ if [ "$?" == "0" ]; then echo_date "/jffs卸载成功..." echo_date "将文件系统${mtd_disk}挂载到jffs分区..." - if [ "${LINUX_VER}" == "419" -o "${LINUX_VER}" == "54" ];then + if [ "${LINUX_VER}" == "44" -o "${LINUX_VER}" == "419" -o "${LINUX_VER}" == "54" ];then mount -t ubifs ${mtd_disk} /jffs else mount -t jffs2 -o rw,noatime ${mtd_disk} /jffs @@ -444,7 +445,7 @@ sync_usb_mtd(){ # 检测是否有USB磁盘挂载在/jffs上 get_current_jffs_device local mounted_nu=$(mount | /bin/grep "${jffs_device}" | grep -E "/tmp/mnt/|/jffs"|/bin/grep -c "/dev/s") - if [ "${mounted_nu}" == "2" ]; then + if [ "${mounted_nu}" -ge "2" ]; then local usb_path=$(mount | /bin/grep "${jffs_device}" | /bin/grep "/tmp/mnt/" | awk '{print $3}') #echo_date "检测到USB磁盘的${usb_path}/.koolshare_jffs挂载在/jffs上" else @@ -591,7 +592,7 @@ del_sync_job(){ set_sync_job(){ get_current_jffs_device local mounted_nu=$(mount | /bin/grep "${jffs_device}" | grep -E "/tmp/mnt/|/jffs"|/bin/grep -c "/dev/s") - if [ "${mounted_nu}" == "2" ]; then + if [ "${mounted_nu}" -ge "2" ]; then local usb_path=$(mount | /bin/grep "${jffs_device}" | /bin/grep "/tmp/mnt/" | awk '{print $3}') #echo_date "检测到USB磁盘的${usb_path}/.koolshare_jffs挂载在/jffs上" else @@ -634,7 +635,7 @@ set_sync_job(){ set_stop_sync(){ get_current_jffs_device local mounted_nu=$(mount | /bin/grep "${jffs_device}" | grep -E "/tmp/mnt/|/jffs"|/bin/grep -c "/dev/s") - if [ "${mounted_nu}" == "2" ]; then + if [ "${mounted_nu}" -ge "2" ]; then local usb_path=$(mount | /bin/grep "${jffs_device}" | /bin/grep "/tmp/mnt/" | awk '{print $3}') #echo_date "检测到USB磁盘的${usb_path}/.koolshare_jffs挂载在/jffs上" else @@ -664,7 +665,7 @@ make_backup(){ fi local mounted_nu=$(mount | /bin/grep "${jffs_device}" | grep -E "/tmp/mnt/|/jffs"|/bin/grep -c "/dev/s") - if [ "${mounted_nu}" != "2" ]; then + if [ "${mounted_nu}" -lt "2" ]; then echo_date "错误!没有检测到USB磁盘挂载在/jffs,无法备份!" echo_date "请先挂载USB磁盘到/jffs后再使用本功能!" return 1 @@ -744,7 +745,7 @@ restore_backup(){ fi local mounted_nu=$(mount | /bin/grep "${jffs_device}" | grep -E "/tmp/mnt/|/jffs"|/bin/grep -c "/dev/s") - if [ "${mounted_nu}" != "2" ]; then + if [ "${mounted_nu}" -lt "2" ]; then echo_date "错误!没有检测到USB磁盘挂载在/jffs,无法恢复!" echo_date "请先挂载USB磁盘到/jffs后再使用本功能!" return 1 diff --git a/usb2jffs/usb2jffs/scripts/usb2jffs_mount_status.sh b/usb2jffs/usb2jffs/scripts/usb2jffs_mount_status.sh index aab8c584..d820c572 100755 --- a/usb2jffs/usb2jffs/scripts/usb2jffs_mount_status.sh +++ b/usb2jffs/usb2jffs/scripts/usb2jffs_mount_status.sh @@ -29,8 +29,8 @@ get_current_jffs_device(){ start(){ get_current_jffs_device local mounted_nu=$(mount | /bin/grep "${jffs_device}" | grep -E "/tmp/mnt/|/jffs" | /bin/grep -v "DockRootData" | /bin/grep -c "/dev/s") - if [ "${mounted_nu}" -eq "2" ]; then - local usb_path=$(mount | /bin/grep "${jffs_device}" | /bin/grep "/tmp/mnt/" | /bin/grep -v "DockRootData" | awk '{print $3}') + if [ "${mounted_nu}" -ge "2" ]; then + local usb_path=$(mount | /bin/grep "${jffs_device}" | /bin/grep "/tmp/mnt/" | /bin/grep -v "DockRootData" | /bin/grep -v "asusware" | awk '{print $3}' | head -n1) http_response "$(get_current_jffs_status)@@jffs挂载路径:${usb_path}/.koolshare_jffs → /jffs@@1" else if [ -d "${usb2jffs_mount_path}/.koolshare_jffs" ];then