问题
I need to construct a SDHC card (FAT32) with a directory where I have chosen the short and long filenames independently. E.g. short filename MYDIR
but long name i am a cool name. yeah. check out the awesomeness.
Based on Wikipedia, there is no mandatory correlation between the two names, so my goal should be possible:
there is no compulsory algorithm for creating the 8.3 name from an LFN
-- http://en.wikipedia.org/wiki/8.3_filename#Overview
I can use any necessary system to do this (windows, mac, linux, hex editor) but the easier the better. Thanks!
回答1:
The short file name is automatically and compulsorily constructed from the LFN using the algorithm you mentioned. (Also detailed in the FAT32 specifications). This is done by the file-system driver (at least on Windows and Linux).You really can't change that, unless you modify the driver which is not advisable. If you want to do this only for one directory, then you could achieve this by modifying the disk image in a hex editor being wary of not creating duplicate entries with the same name.
Here is what I tried on Linux:
#dd if=/dev/zero of=fatImage bs=1048576 count=256
#mkfs.vfat -F 32 fatImage
#mount -o loop fatImage /mnt
#cd /mnt
#mkdir ThisIsALongDirectoryName
The fat driver generates a short name for the directory:THISIS~1. You can use both names to access it.
#cd /mnt/ThisIsALongDirectoryName
#cd /mnt/THISIS~1
Then after unmounting the partition, I opened the image in a hex editor(Okteta on KDE), searched for the SFN entry THISIS~1, and replaced it with MYNEWDIR. Also,each 32 byte LFN sub-entry stores a checksum of the SFN at offset 13. So I had to calculate and replace the checksum of THISIS~1(which is 0xA6) with the checksum for MYNEWDIR(which is 0x6A) in all the LFN sub-entries.After saving the modifications,I remounted the image and was able to access the directory using the old LFN and the new SFN.
#cd /mnt/ThisIsALongDirectoryName
#cd /mnt/MYNEWDIR
回答2:
I wouldn't rely in Wikipedia as a technical reference. It's better to consult Microsoft's documentation. Reading up on this, I think there may be a relationship between the two files, so I would not recommend fiddling with these. You are probably better off using a short name.
来源:https://stackoverflow.com/questions/14123302/fat32-set-long-filename-and-8-3-filename-separately