0

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!

Community
  • 1
  • 1
AlcubierreDrive
  • 3,654
  • 2
  • 29
  • 45
  • Are you using an API to do this? If so, which one? If not, then StackOverflow probably isn't the right place to ask this. – Paul Turner Jan 02 '13 at 15:04
  • You can do this on NTFS with fsutil setshortname: http://technet.microsoft.com/en-us/library/bb490642.aspx – AlcubierreDrive Jan 02 '13 at 20:56
  • unfortunately [`SetFileShortName()`](https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-setfileshortnamew) says that *The file must be on an NTFS file system volume* so you can't do that on FAT32 automatically. And there's a duplicate of this: [How to set FAT32 short names in Powershell or Windows Command Shell](https://stackoverflow.com/q/4115519/995714) – phuclv Dec 31 '20 at 03:31

2 Answers2

2

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
itisravi
  • 3,406
  • 3
  • 23
  • 30
  • You say you tried this. What tools did you use? Do you have instructions? Even if it ultimately failed, I want to try for myself. Thanks! :) – AlcubierreDrive Jan 02 '13 at 20:47
  • 1
    @JonRodriguez Actually, it is possible to do what I described after all.Please see the updated answer. – itisravi Jan 03 '13 at 03:48
0

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.

Rob
  • 781
  • 5
  • 19