michallenc opened a new pull request, #18697: URL: https://github.com/apache/nuttx/pull/18697
## Summary Linux creates all files as long file name entries even if they fit short 8.3 format. This caused issues when deleting or renaming files as the long file name entry was not recognized and only deleted it's short file name entry. This basically kept breaking the file system as subsequent long file name files were not correctly stored. The typical representation of this issue was long file name being represented as it's short name alias. This commit adjusts the LFN/SFN logic a bit - the code now always fills in long file name and then checks if this could possibly be a short file entry (we still have to do that because Windows stores 8.3 files as short file entry). This ensures compatibility with files created both on Linux and Windows. The following log is a FAT entry on Linux. You can see short file name `config.ini` is still written as a long file entry. ``` touch config.ini on Linux 00042000: 4163 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff Ac.o.n.f.i....g...i.n.i......... 00042020: 434f 4e46 4947 2020 494e 4920 004a 8041 885c 885c 0000 8041 885c 0000 0000 0000 CONFIG INI .J.A.\.\...A.\...... first rename on Linux 00042000: e563 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff .c.o.n.f.i....g...i.n.i......... 00042020: e54f 4e46 4947 2020 494e 4920 004a 8041 885c 885c 0000 8041 885c 0000 0000 0000 .ONFIG INI .J.A.\.\...A.\...... 00042040: 4237 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff B7.8...i.n....i................. 00042060: 0163 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 00042080: 434f 4e46 4947 7e31 494e 4920 0080 8d41 885c 885c 0000 8d41 885c 0000 0000 0000 CONFIG~1INI ...A.\.\...A.\...... rename back on Linux 00042000: 4163 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff Ac.o.n.f.i....g...i.n.i......... 00042020: 434f 4e46 4947 2020 494e 4920 003c 9741 885c 885c 0000 9741 885c 0000 0000 0000 CONFIG INI .<.A.\.\...A.\...... 00042040: e537 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff .7.8...i.n....i................. 00042060: e563 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 00042080: e54f 4e46 4947 7e31 494e 4920 0080 8d41 885c 885c 0000 8d41 885c 0000 0000 0000 .ONFIG~1INI ...A.\.\...A.\...... second rename on Linux 00042000: e563 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff .c.o.n.f.i....g...i.n.i......... 00042020: e54f 4e46 4947 2020 494e 4920 004a 8041 885c 885c 0000 8041 885c 0000 0000 0000 .ONFIG INI .J.A.\.\...A.\...... 00042040: 4237 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff B7.8...i.n....i................. 00042060: 0163 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 00042080: 434f 4e46 4947 7e31 494e 4920 0049 a541 885c 885c 0000 a541 885c 0000 0000 0000 CONFIG~1INI .I.A.\.\...A.\...... ``` The issue on NuttX is easily reproducible by renaming `config.ini` file to long name `config_12345678.ini`. The first rename is ok (though the erase of the old entry already not correct), but subsequent rename back to `config.ini` on Linux and another rename to long name breaks the system - `ls` command now doesn't show `config_12345678.ini` as it should, but it's short file alias `CONFIG~1.INI` - and it's not just `ls`, calling `open` on `config_12345678.ini` doesn't work either. ``` touch config.ini on Linux 00042000: 4163 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff Ac.o.n.f.i....g...i.n.i......... 00042020: 434f 4e46 4947 2020 494e 4920 00c1 6f3e 885c 885c 0000 6f3e 885c 0000 0000 0000 CONFIG INI ..o>.\.\..o>.\...... first rename from config.ini to config_12345678.ini on NuttX - you can see the first line is not erased (first byte should be e5) 00042000: 4163 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff Ac.o.n.f.i....g...i.n.i......... 00042020: e54f 4e46 4947 2020 494e 4920 00c1 6f3e 885c 885c 0000 6f3e 885c 0000 0000 0000 .ONFIG INI ..o>.\.\..o>.\...... 00042040: 4237 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff B7.8...i.n....i................. 00042060: 0163 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 00042080: 434f 4e46 4947 7e31 494e 4920 00c1 6f3e 885c 885c 0000 6f3e 885c 0000 0000 0000 CONFIG~1INI ..o>.\.\..o>.\...... rename back to config.ini on Linux 00042000: 4163 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff Ac.o.n.f.i....g...i.n.i......... 00042020: e54f 4e46 4947 2020 494e 4920 00c1 6f3e 885c 885c 0000 6f3e 885c 0000 0000 0000 .ONFIG INI ..o>.\.\..o>.\...... 00042040: e537 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff .7.8...i.n....i................. 00042060: e563 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 00042080: e54f 4e46 4947 7e31 494e 4920 00c1 6f3e 885c 885c 0000 6f3e 885c 0000 0000 0000 .ONFIG~1INI ..o>.\.\..o>.\...... 000420a0: 4163 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff Ac.o.n.f.i....g...i.n.i......... 000420c0: 434f 4e46 4947 2020 494e 4920 0020 ac3e 885c 885c 0000 ac3e 885c 0000 0000 0000 CONFIG INI . .>.\.\...>.\...... second rename on NuttX -> ls shows CONFIG~1.INI 00042000: 4163 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff Ac.o.n.f.i....g...i.n.i......... 00042020: 4237 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff B7.8...i.n....i................. 00042040: 0163 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 00042060: 434f 4e46 4947 7e31 494e 4920 00c1 6f3e 885c 885c 0000 6f3e 885c 0000 0000 0000 CONFIG~1INI ..o>.\.\..o>.\...... 00042080: e54f 4e46 4947 7e31 494e 4920 00c1 6f3e 885c 885c 0000 6f3e 885c 0000 0000 0000 .ONFIG~1INI ..o>.\.\..o>.\...... 000420a0: 4163 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff Ac.o.n.f.i....g...i.n.i......... 000420c0: e54f 4e46 4947 2020 494e 4920 00c1 6f3e 885c 885c 0000 6f3e 885c 0000 0000 0000 .ONFIG INI ..o>.\.\..o>.\...... ``` ## Impact There should be none on existing code, it's just a bug fix. ## Testing Here are the logs after the fix - both Linux and Windows created files are correctly renamed now. ### Linux ``` touch config.ini 00042000: 4163 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff Ac.o.n.f.i....g...i.n.i......... 00042020: 434f 4e46 4947 2020 494e 4920 00a2 d67d 895c 895c 0000 d67d 895c 0000 0000 0000 CONFIG INI ...}.\.\...}.\...... first rename from config.ini to config_12345678.ini on NuttX - first entry is correctly erased 00042000: e563 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff .c.o.n.f.i....g...i.n.i......... 00042020: e54f 4e46 4947 2020 494e 4920 00a2 d67d 895c 895c 0000 d67d 895c 0000 0000 0000 .ONFIG INI ...}.\.\...}.\...... 00042040: 4237 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff B7.8...i.n....i................. 00042060: 0163 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 00042080: 434f 4e46 4947 7e31 494e 4920 00a2 d67d 895c 895c 0000 d67d 895c 0000 0000 0000 CONFIG~1INI ...}.\.\...}.\...... rename back to config.ini on Linux 00042000: 4163 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff Ac.o.n.f.i....g...i.n.i......... 00042020: 434f 4e46 4947 2020 494e 4920 00b3 f87d 895c 895c 0000 f87d 895c 0000 0000 0000 CONFIG INI ...}.\.\...}.\...... 00042040: e537 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff .7.8...i.n....i................. 00042060: e563 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 00042080: e54f 4e46 4947 7e31 494e 4920 00a2 d67d 895c 895c 0000 d67d 895c 0000 0000 0000 .ONFIG~1INI ...}.\.\...}.\...... second rename on NuttX -> ls shows correctly config_12345678.ini 00042000: e563 006f 006e 0066 0069 000f 00e6 6700 2e00 6900 6e00 6900 0000 0000 ffff ffff .c.o.n.f.i....g...i.n.i......... 00042020: e54f 4e46 4947 2020 494e 4920 00a2 d67d 895c 895c 0000 d67d 895c 0000 0000 0000 .ONFIG INI ...}.\.\...}.\...... 00042040: 4237 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff B7.8...i.n....i................. 00042060: 0163 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 00042080: 434f 4e46 4947 7e31 494e 4920 00a2 d67d 895c 895c 0000 d67d 895c 0000 0000 0000 CONFIG~1INI ...}.\.\...}.\...... echo "Hello" > /sdcard/test.txt - file with short name still takes only one entry 00042000: 5445 5354 2020 2020 5458 5420 1800 0000 0000 0000 0000 0000 0000 0200 0600 0000 TEST TXT .................... 00042020: e54f 4e46 4947 2020 494e 4920 00a2 d67d 895c 895c 0000 d67d 895c 0000 0000 0000 .ONFIG INI ...}.\.\...}.\...... 00042040: 4237 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff B7.8...i.n....i................. 00042060: 0163 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 00042080: 434f 4e46 4947 7e31 494e 4920 00a2 d67d 895c 895c 0000 d67d 895c 0000 0000 0000 CONFIG~1INI ...}.\.\...}.\...... ``` ### Windows ``` created config.ini -> short file name on Windows 10 00042000: 4220 0049 006e 0066 006f 000f 0072 7200 6d00 6100 7400 6900 6f00 0000 6e00 0000 B .I.n.f.o...rr.m.a.t.i.o...n... 00042020: 0153 0079 0073 0074 0065 000f 0072 6d00 2000 5600 6f00 6c00 7500 0000 6d00 6500 .S.y.s.t.e...rm. .V.o.l.u...m.e. 00042040: 5359 5354 454d 7e31 2020 2016 0088 ec8d 895c 895c 0000 ed8d 895c 0200 0000 0000 SYSTEM~1 ......\.\.....\...... 00042060: 434f 4e46 4947 2020 494e 4920 1807 f58d 895c 895c 0000 3582 885c 0000 0000 0000 CONFIG INI .....\.\..5..\...... first rename from config.ini to config_12345678.ini on NuttX 00042000: 4220 0049 006e 0066 006f 000f 0072 7200 6d00 6100 7400 6900 6f00 0000 6e00 0000 B .I.n.f.o...rr.m.a.t.i.o...n... 00042020: 0153 0079 0073 0074 0065 000f 0072 6d00 2000 5600 6f00 6c00 7500 0000 6d00 6500 .S.y.s.t.e...rm. .V.o.l.u...m.e. 00042040: 5359 5354 454d 7e31 2020 2016 0088 ec8d 895c 895c 0000 ed8d 895c 0200 0000 0000 SYSTEM~1 ......\.\.....\...... 00042060: e54f 4e46 4947 2020 494e 4920 1807 f58d 895c 895c 0000 3582 885c 0000 0000 0000 .ONFIG INI .....\.\..5..\...... 00042080: 4237 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff B7.8...i.n....i................. 000420a0: 0163 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 000420c0: 434f 4e46 4947 7e31 494e 4920 1807 f58d 895c 895c 0000 3582 885c 0000 0000 0000 CONFIG~1INI .....\.\..5..\...... rename back to config.ini on Windows 00042000: 4220 0049 006e 0066 006f 000f 0072 7200 6d00 6100 7400 6900 6f00 0000 6e00 0000 B .I.n.f.o...rr.m.a.t.i.o...n... 00042020: 0153 0079 0073 0074 0065 000f 0072 6d00 2000 5600 6f00 6c00 7500 0000 6d00 6500 .S.y.s.t.e...rm. .V.o.l.u...m.e. 00042040: 5359 5354 454d 7e31 2020 2016 0088 ec8d 895c 895c 0000 ed8d 895c 0200 0000 0000 SYSTEM~1 ......\.\.....\...... 00042060: e54f 4e46 4947 2020 494e 4920 1807 f58d 895c 895c 0000 3582 885c 0000 0000 0000 .ONFIG INI .....\.\..5..\...... 00042080: e537 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff .7.8...i.n....i................. 000420a0: e563 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 000420c0: e54f 4e46 4947 7e31 494e 4920 1807 f58d 895c 895c 0000 3582 885c 0000 0000 0000 .ONFIG~1INI .....\.\..5..\...... 000420e0: 434f 4e46 4947 2020 494e 4920 1807 f58d 895c 895c 0000 3582 885c 0000 0000 0000 CONFIG INI .....\.\..5..\...... second rename on NuttX -> ls shows correctly config_12345678.ini 00042000: 4220 0049 006e 0066 006f 000f 0072 7200 6d00 6100 7400 6900 6f00 0000 6e00 0000 B .I.n.f.o...rr.m.a.t.i.o...n... 00042020: 0153 0079 0073 0074 0065 000f 0072 6d00 2000 5600 6f00 6c00 7500 0000 6d00 6500 .S.y.s.t.e...rm. .V.o.l.u...m.e. 00042040: 5359 5354 454d 7e31 2020 2016 0088 ec8d 895c 895c 0000 ed8d 895c 0200 0000 0000 SYSTEM~1 ......\.\.....\...... 00042060: 4237 0038 002e 0069 006e 000f 00ee 6900 0000 ffff ffff ffff ffff 0000 ffff ffff B7.8...i.n....i................. 00042080: 0163 006f 006e 0066 0069 000f 00ee 6700 5f00 3100 3200 3300 3400 0000 3500 3600 .c.o.n.f.i....g._.1.2.3.4...5.6. 000420a0: 434f 4e46 4947 7e31 494e 4920 1807 f58d 895c 895c 0000 3582 885c 0000 0000 0000 CONFIG~1INI .....\.\..5..\...... 000420c0: e54f 4e46 4947 7e31 494e 4920 1807 f58d 895c 895c 0000 3582 885c 0000 0000 0000 .ONFIG~1INI .....\.\..5..\...... 000420e0: e54f 4e46 4947 2020 494e 4920 1807 f58d 895c 895c 0000 3582 885c 0000 0000 0000 .ONFIG INI .....\.\..5..\...... ``` I kept the original design that NuttX creates a file with short name as a short file entry - it seems like a better strategy for us since we are embedded and one would expect we wouldn't waste memory unless really have to. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
