@@ -7,7 +7,6 @@ CONFIG_PATH="/data/adb/csc_config"
77ARCH=$( getprop ro.product.cpu.abi)
88CSC=$( getprop ro.boot.sales_code)
99TOOL=" $MODDIR /libs/$ARCH /csc_tool"
10- HASH_DIR=" $MODDIR /hashes"
1110
1211# ===== Debug 开关 =====
1312DEBUG=0 # 0=关闭 1=开启
@@ -26,7 +25,6 @@ debug() {
2625
2726prepare_log () {
2827 : > " $LOG_FILE "
29- mkdir -p " $HASH_DIR "
3028 log " === 模块启动: CSC=$CSC , ARCH=$ARCH , DEBUG=$DEBUG ==="
3129}
3230
@@ -47,41 +45,41 @@ find_file() {
4745 return 1
4846}
4947
50- # 计算文件联合 Hash
51- # 参数: 传入需要纳入校验的多个文件路径
52- calc_hash () {
53- # 将存在的文件内容合并后计算 md5
54- cat " $@ " 2> /dev/null | md5sum | awk ' {print $1}'
55- }
56-
57- # 部署文件以供 Magisk/KSU OverlayFS/Magic Mount 挂载
58- deploy_for_mount () {
48+ # 使用 mount --bind 显式挂载文件
49+ # 参数: $1=源文件路径(模块内处理后的文件) $2=目标文件路径(系统原始文件)
50+ mount_bind_file () {
5951 local src_file=$1
60- local origin_path =$2
61-
62- # 路径标准化: 如果是 /etc 开头,转为 /system/etc,确保 Magisk/KSU 正确识别挂载点
63- local target_path =" $origin_path "
64- case " $target_path " in
65- /etc/* ) target_path =" /system$target_path " ;;
52+ local target_path =$2
53+
54+ # 路径标准化: 如果是 /etc 开头,转为 /system/etc
55+ local normalized_target =" $target_path "
56+ case " $normalized_target " in
57+ /etc/* ) normalized_target =" /system$target_path " ;;
6658 esac
6759
68- local module_target_path=" $MODDIR$target_path "
69-
70- debug " 准备部署挂载点: $module_target_path "
71-
72- # 创建对应的目录树
73- mkdir -p " $( dirname " $module_target_path " ) "
74-
75- # 复制文件到模块对应目录,KSU/Magisk 会在稍后自动 OverlayFS 挂载它
76- cp -f " $src_file " " $module_target_path "
77-
78- # 同步 SELinux 上下文
79- if [ -f " $origin_path " ]; then
80- local ctx=$( ls -Z " $origin_path " 2> /dev/null | awk ' {print $1}' )
81- [ -n " $ctx " ] && chcon " $ctx " " $module_target_path " 2> /dev/null
60+ # 确保目标文件存在
61+ if [ ! -f " $normalized_target " ]; then
62+ log " 错误: 目标文件不存在 $normalized_target "
63+ return 1
8264 fi
8365
84- log " 成功部署: $target_path "
66+ # 先卸载可能存在的旧挂载
67+ if mount | grep -q " $normalized_target " ; then
68+ debug " 检测到旧挂载,正在卸载: $normalized_target "
69+ umount -l " $normalized_target " 2> /dev/null
70+ fi
71+
72+ # 执行 mount --bind
73+ mount --bind " $src_file " " $normalized_target " >> " $LOG_FILE " 2>&1
74+
75+ # 检查挂载是否成功
76+ if mount | grep -q " $normalized_target " ; then
77+ log " ✓ 成功挂载: $normalized_target "
78+ return 0
79+ else
80+ log " ✗ 挂载失败: $normalized_target "
81+ return 1
82+ fi
8583}
8684
8785# 通用特性文件处理函数
@@ -119,24 +117,14 @@ process_feature_file() {
119117 local final_file=" $MODDIR /final_$label "
120118 local user_config=" $CONFIG_PATH /$config_name "
121119
122- # 3. Hash 校验 (支持增量更新)
123- local hash_file=" $HASH_DIR /$label .md5"
124- local current_hash=$( calc_hash " $origin_path " " $user_config " " $TOOL " )
125- local old_hash=" "
126- [ -f " $hash_file " ] && old_hash=$( cat " $hash_file " )
127-
128- # 检查已部署文件路径
129- local check_path=" $origin_path "
130- case " $check_path " in
131- /etc/* ) check_path=" /system$check_path " ;;
132- esac
133-
134- if [ " $current_hash " = " $old_hash " ] && [ -f " $MODDIR$check_path " ]; then
135- log " 增量校验通过: $label 无变动,跳过。"
120+ # 3. 检查已处理文件是否存在(重启后直接使用缓存的处理后文件)
121+ if [ -f " $final_file " ]; then
122+ log " $label 已存在缓存,直接使用..."
123+ mount_bind_file " $final_file " " $origin_path "
136124 return
137125 fi
138126
139- log " 检测到 $label 变动,开始处理 ..."
127+ log " 开始处理 $label ..."
140128
141129 # 4. 解码/复制 (根据文件类型)
142130 if [ " $is_plain " = " 1" ]; then
@@ -172,11 +160,10 @@ process_feature_file() {
172160 fi
173161 fi
174162
175- # 7. 部署挂载
163+ # 7. 使用 mount --bind 显式挂载
176164 if [ -f " $final_file " ]; then
177- deploy_for_mount " $final_file " " $origin_path "
178- echo " $current_hash " > " $hash_file "
179- log " ✓ $label 处理完成"
165+ mount_bind_file " $final_file " " $origin_path "
166+ log " ✓ $label 处理完成并已挂载"
180167 else
181168 log " ✗ 错误: patch 失败 ($label )"
182169 fi
@@ -203,4 +190,4 @@ process_feature_file "carrier" "customer_carrier_feature.json" "carrier.json"
203190process_feature_file " ff" " floating_feature.xml" " ff.json" 1
204191process_feature_file " camera" " camera-feature.xml" " camera-feature.json" 1 " /system/cameradata/camera-feature.xml"
205192
206- log " === 脚本执行完毕,等待系统 OverlayFS 挂载 ==="
193+ log " === 脚本执行完毕,mount --bind 挂载完成 ==="
0 commit comments