Repository navigation
fix: add codepage 936 for non-ASCII FAT volume labels - #234
wangrong1069 wants to merge 1 commit into
Conversation
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
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: wangrong1069 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideUpdates FAT16 formatting to pass Sequence diagram for FAT formatting with non-ASCII volume labelssequenceDiagram
participant PartedCore
participant FAT16
participant mkfs_fat
participant writeLabel
PartedCore->>FAT16: create(new_partition)
alt label contains non-ASCII characters
FAT16->>mkfs_fat: format with --codepage=936 -n label
mkfs_fat-->>FAT16: success
else label is ASCII or empty
FAT16->>mkfs_fat: format with existing arguments
mkfs_fat-->>FAT16: success or existing result
end
FAT16->>writeLabel: writeLabel()
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="service/diskoperation/filesystems/fat16.cpp" line_range="297" />
<code_context>
+ }
+ 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")
</code_context>
<issue_to_address>
**Labels with spaces fail formatting**
When a non-ASCII volume label contains whitespace, `FAT16::create()` inserts the label unquoted into the combined command, so command parsing splits it into separate arguments and `mkfs.fat` receives the wrong `-n` value and an extra operand; formatting fails.
Pass the label as a single argument instead of interpolating it unquoted into the combined command.
</issue_to_address>| } | ||
| if (hasNonAscii) { | ||
| cmd = QString("mkfs.fat -F %1 -v -I --codepage=936 -n %2 %3") | ||
| .arg(fat_size).arg(label).arg(new_partition.getPath()); |
There was a problem hiding this comment.
🟡 Medium · Labels with spaces fail formatting
When a non-ASCII volume label contains whitespace, FAT16::create() inserts the label unquoted into the combined command, so command parsing splits it into separate arguments and mkfs.fat receives the wrong -n value and an extra operand; formatting fails.
Pass the label as a single argument instead of interpolating it unquoted into the combined command.
Prompt for AI agents
In `service/diskoperation/filesystems/fat16.cpp` at line 297:
**Labels with spaces fail formatting**
When a non-ASCII volume label contains whitespace, `FAT16::create()` inserts the label unquoted into the combined command, so command parsing splits it into separate arguments and `mkfs.fat` receives the wrong `-n` value and an extra operand; formatting fails.
Pass the label as a single argument instead of interpolating it unquoted into the combined command.
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 语法正确,逻辑清晰 ✅ 通过 潜在问题: 建议: ['无语法逻辑问题,代码逻辑清晰正确。'] 2. 代码质量 ✅评价: 代码结构清晰,注释完整 ✅ 通过 潜在问题: 建议: ['建议将 codepage 参数提取为条件变量,合并两条分支,例如:QString codepage = hasNonAscii ? "--codepage=936 " : ""; 然后统一构造命令字符串,减少重复代码。'] 3. 代码性能 ✅评价: 性能良好,资源使用合理 ✅ 通过 潜在问题: 建议: ['无性能问题,break 提前退出循环的优化合理。'] 4. 代码安全 🔒评价: 存在0个安全漏洞 ✅ 通过
安全漏洞详情: 建议: ['无安全漏洞。建议后续考虑对 label 中的 shell 元字符进行转义校验,作为防御性编程的改进方向(非本次 PR 引入的问题)。'] 💡 改进建议代码示例// 建议重构:消除 if/else 分支的代码重复
QString label = new_partition.getFileSystemLabel();
bool hasNonAscii = false;
for (const QChar &ch : label) {
if (ch.unicode() > 127) {
hasNonAscii = true;
break;
}
}
// 将 codepage 参数提取为条件变量,合并命令构造
QString codepage = hasNonAscii ? "--codepage=936 " : "";
cmd = QString("mkfs.fat -F %1 -v -I %2-n %3 %4")
.arg(fat_size)
.arg(codepage)
.arg(label)
.arg(new_partition.getPath());本报告由 AI 代码审查工具自动生成 |
|
TAG Bot New tag: 6.0.28 |
|
TAG Bot New tag: 6.0.29 |
|
TAG Bot New tag: 6.0.30 |
Root Cause Analysis
FAT16::create()(service/diskoperation/filesystems/fat16.cpp:287) passes UTF-8 encoded Chinese volume labels directly tomkfs.fat -n. Themkfs.fattool defaults to the CP850 codepage, which cannot convert UTF-8 multibyte characters (e.g., Chinese), causing the format operation to fail with exit code 1. The downstreamwriteLabel()(which usesmlabeland handles UTF-8) is never reached becausecreate()returns failure.Fix Approach
In
FAT16::create(), detect whether the label contains non-ASCII characters. If it does, add--codepage=936to themkfs.fatcommand, enabling proper GBK codepage conversion for Chinese labels. ASCII-only labels and empty labels follow the original code path with no change.Change Safety Assessment
Code Safety
b4fc9c63fixed a missing.arg()call, which is preserved)PartedCore::createFileSystem()(partedcore.cpp:3992) sees no change increate()return value semanticsBusiness Impact Scope
Verification Suggestion
根因分析
FAT16::create()(service/diskoperation/filesystems/fat16.cpp:287)将 UTF-8 编码的中文卷标直接通过mkfs.fat -n参数传递。mkfs.fat默认使用 CP850 代码页,无法转换 UTF-8 多字节字符(如中文),导致格式化操作失败(退出码 1)。下游的writeLabel()(使用 mlabel,支持 UTF-8)因create()返回失败而永远不会被执行。修复方案
在
FAT16::create()中检测卷标是否包含非 ASCII 字符。如果包含,则为mkfs.fat命令添加--codepage=936参数,使 GBK 代码页正确转换中文卷标。纯 ASCII 卷标和空卷标走原有代码路径,无变化。改动安全评估
代码安全评估
b4fc9c63的.arg()修复PartedCore::createFileSystem()(partedcore.cpp:3992)所见create()返回值语义不变业务影响范围
验证建议
Summary by Sourcery
Bug Fixes: