From fc3d2ac098ea635d5ded1424bd815817d1c70256 Mon Sep 17 00:00:00 2001 From: wangrong Date: Wed, 28 Oct 2026 13:43:21 +0800 Subject: [PATCH] fix: add codepage 936 for non-ASCII FAT volume labels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: FAT16::create() passes UTF-8 encoded Chinese labels directly to mkfs.fat -n, which defaults to CP850 codepage and cannot convert UTF-8 multibyte characters, causing format failure (exit 1) 2. Fix: detect non-ASCII characters in the label and add --codepage=936 to the mkfs.fat command, enabling proper GBK codepage conversion 3. Impact: ASCII label and empty label paths unchanged, only non-ASCII label path adds the --codepage=936 parameter Log: Fix FAT format failure when setting Chinese volume label Influence: 1. Test FAT32 partition creation with Chinese volume label 2. Test FAT32 partition creation with ASCII volume label (regression) 3. Test FAT16 partition creation with Chinese volume label 4. Test FAT32 partition creation without label (regression) fix: 修复非ASCII卷标导致FAT格式化失败的问题 1. 根因:FAT16::create() 将UTF-8编码的中文卷标直接传给mkfs.fat -n, mkfs.fat默认使用CP850代码页,无法转换UTF-8多字节字符,导致格式化失败 2. 方案:检测卷标中的非ASCII字符,为mkfs.fat命令添加--codepage=936 参数,使GBK代码页正确转换中文卷标 3. 影响:ASCII卷标和空卷标路径不变,仅非ASCII卷标路径新增参数 Log: 修复设置中文卷标时FAT格式化失败的问题 Influence: 1. 测试FAT32分区创建时设置中文卷标 2. 测试FAT32分区创建时设置ASCII卷标(回归) 3. 测试FAT16分区创建时设置中文卷标 4. 测试FAT32分区创建时不设置卷标(回归) PMS: BUG-362663 --- service/diskoperation/filesystems/fat16.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/service/diskoperation/filesystems/fat16.cpp b/service/diskoperation/filesystems/fat16.cpp index 68dc20fb..e9ba751e 100644 --- a/service/diskoperation/filesystems/fat16.cpp +++ b/service/diskoperation/filesystems/fat16.cpp @@ -284,7 +284,21 @@ bool FAT16::create(const Partition & new_partition) cmd = QString("mkfs.fat -F %1 -v -I %2").arg(fat_size).arg(new_partition.getPath()); } else { qDebug() << "Label is not empty, creating with label"; - cmd = QString("mkfs.fat -F %1 -v -I -n %2 %3").arg(fat_size).arg(new_partition.getFileSystemLabel()).arg(new_partition.getPath()); + QString label = new_partition.getFileSystemLabel(); + bool hasNonAscii = false; + for (const QChar &ch : label) { + if (ch.unicode() > 127) { + hasNonAscii = true; + break; + } + } + if (hasNonAscii) { + cmd = QString("mkfs.fat -F %1 -v -I --codepage=936 -n %2 %3") + .arg(fat_size).arg(label).arg(new_partition.getPath()); + } else { + cmd = QString("mkfs.fat -F %1 -v -I -n %2 %3") + .arg(fat_size).arg(label).arg(new_partition.getPath()); + } } qDebug() << "FAT16::create***** " << cmd;