Repository navigation
Conversation
When a file gets its second link, apfs_prepare_dentry_for_link() deletes the dentry record and creates it again together with the sibling records. It uses dentry->d_name for both, but on case-insensitive volumes the lookup may have found the record under a different case, while the inode keeps its original name: echo abc > a.bin (remount, or anything else that drops the dentry) ln A.BIN c.lnk After this, the directory lists "A.BIN" instead of "a.bin", and apfsck reports "Inode record: wrong name for primary link." Copy the name from the record before deleting it, and use that instead. New links still get the name from their own dentry. Reported in linux-apfs#130. Signed-off-by: ozzycattt <ozzycattt@users.noreply.github.com>
|
Thanks again. Renaming files like this is definitely wrong, independently of the mismatch with the primary name. By the way, are these patches generated by an LLM? I ask because I'm not sure if I want to end up with this much LLM code in the driver, it might be better if I write a solution myself from your bug report. |
|
Yes, I wrote them with an LLM. It wasn't fire-and-forget, though. The bugs came out of my own stress tests on real hardware. Each fix was checked against a reproducer on your unpatched driver, with apfsck and fsck_apfs, and with the same stress round before and after. I only sent what held up. The patch is small, and I'm happy to change anything in it. That said, it's your driver, so if you'd rather write the fix yourself from the report, that's completely fine with me. The reproducer is in the PR description. |
|
I wasn't questioning the quality of the work, you've helped a lot so far. I'm just not confident about the copyright status of LLM code and I don't want to risk tainting the driver somehow. I'll come up with a patch myself. |
Fixes the apfsck warning from #130.
When a file gets its second link,
apfs_prepare_dentry_for_link()deletes the dentry record and creates it again with the sibling records, usingdentry->d_name. On a case-insensitive volume the lookup can find the record under a different case, so:renames the entry to
A.BIN(that's whatlsshows afterwards), while the inode keepsa.bin. apfsck then reportsInode record: wrong name for primary link.The patch copies the name from the record before deleting it, and uses it for both the sibling records and the new dentry record. New links still get the name from their own dentry.
Tested on a Raspberry Pi 4 (kernel 6.18). With apfsck after each case, all clean:
żaba.bin/ŻABA.BIN):lskeeps the original name, and both names read the same data,I also ran one 7-minute round of my stress test together with #131 (about 15k operations, same seed as the failing run): 0 mismatches out of 3179 files, apfsck clean,
fsck_apfs -n -Wclean.