[SOLVED] FAT32 filesystem short entry of LFN

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

[SOLVED] FAT32 filesystem short entry of LFN

Post by HugeCode »

Hi all. I've read this document. I was looking for how to use long file names and I found a part that is not covered there. There's an example which shows translation of "The quick brown.fox" to LFN entries. After all LFN entries there's also one 'short entry'. I found that in it's name there's only the part which fits there. So from the string above there's only "T H E Q U I ~ F O X". And creation of these names is the point of my question:
Is there any standard way how to build name of short entry following LFNs?
What about usage of unicode charcters only (char>255)? There's written that unreadable unicode char should be replaced with '_', but I don't know if it also applies on SFNs.

Thanks.
Last edited by HugeCode on Sun May 12, 2013 6:02 am, edited 2 times in total.
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: FAT32 filesystem short entgry of LFN

Post by thepowersgang »

The algorithm is standardised (from my memory), and I think it is provided in the official documentation (intended for UEFI implementers). A quick descripton of the method used is
  • All invalid characters are replaced by '_'
  • Lowercase characters are converted to uppercase
  • The name is truncated to 6 characters if the non-extension part is longer than 8 (or not unique) and '~' plus a number is appended (such that the 8.3 name is unique)
[edit: Fixed list
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

Re: FAT32 filesystem short entgry of LFN

Post by HugeCode »

Isn't the document I put here official (it's from microsoft)?
BTW what from extension is put to 3 chars in short entry? Start or end?
Also I saw numbers after ~. Does it something to do with number of LFN entries following?
I'm fed up a bit from my FAT code, because Windows doesn't accept it (invalid short entry -> invalid checksum -> invalid long file name -> "There's a problem with this drive. Scan the drive now and fix it.").

Thanks.
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

Re: FAT32 filesystem short entgry of LFN

Post by HugeCode »

Found it. The older one contains it:
http://msdn.microsoft.com/en-us/library ... 63080.aspx
Just an optional question: can number tail rewrite the extension?

EDIT:
What the hack is this? No tails, only mess of characters. Why?
Image
Last edited by HugeCode on Thu Apr 25, 2013 11:08 am, edited 1 time in total.
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: FAT32 filesystem short entgry of LFN

Post by dozniak »

HugeCode wrote:Found it. The older one contains it:
http://msdn.microsoft.com/en-us/library ... 63080.aspx
Just an optional question: can number tail rewrite the extension?

EDIT:
What the hack is this? No tails, only mess of characters. Why?
Image
All ~1 are tails. No they can not overwrite the extension.
Learn to read.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: FAT32 filesystem short entgry of LFN

Post by Combuster »

dozniak wrote:A.ll ~1 are tails. No they can not overwrite the extension.
So if you force a single-digit tail to be insufficient, it'll need to find space elsewhere to create unique filenames, and that has to be earlier in the 8.3 string.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
dozniak
Member
Member
Posts: 723
Joined: Thu Jul 12, 2012 7:29 am
Location: Tallinn, Estonia

Re: FAT32 filesystem short entgry of LFN

Post by dozniak »

Combuster wrote:
dozniak wrote:A.ll ~1 are tails. No they can not overwrite the extension.
So if you force a single-digit tail to be insufficient, it'll need to find space elsewhere to create unique filenames, and that has to be earlier in the 8.3 string.
And if you look carefully at your dump, you'll see that it takes only 2 first characters of the long filename and then generates a 4-character random identifier, then finishes it with a tail.
Learn to read.
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: FAT32 filesystem short entgry of LFN

Post by Owen »

Note that you can omit the short name. Linux, for example, does this because the "FAT LFN" patent only covers cases where you create a file with both the long and short names.
HugeCode
Member
Member
Posts: 112
Joined: Mon Dec 17, 2012 9:12 am

Re: FAT32 filesystem short entgry of LFN

Post by HugeCode »

So if I understand it correctly, faster way for LFN SFN entry generation is to create random numbers (based on actual time) so they won't mess and there's no need to perform check in directory to generate correct tail number.
Thank you all.
Post Reply