ShortPathFilename in memory disk.

Feb 22, 2006 9 Replies

Hi All,



I want to create a file index on EEPROM for memory disk.



In order to recude cost, I have to save shortPathFilename ( 8.3 file format) instead of full name, but I can't sure, is that OK ( all function correct ) to save 8.3 filename only?



Is it possbile to happen any error on 8.3 format file name instead of full filename.



BR/ Boki.



The 8.3 version of the full name uses the first 6 (if all DOS "legal") characters of the full name and then a ~ with a sequential number; so if there are some file names that start the same, the first one created would have an 8.3 flename ending ~1, the next one would end ~2 etc. So they are unique. But say the earliest one gets deleted after you did the transfer, and then another file of "like" name gets created, i think it would be ~1 and the index would be pointing to the "wrong" file. That is probably worse than if that new file was created; a non-existant file is a lot easier to determine than the fact of a replacement IF only the 8.3 name was saved.

You can do that, the VFAT file system takes care of the 8.3 names remaining unique.

If you're really strapped for space you could save some hash of the long file name as 32 or 64 bits, that would be more compact and would work with other file systems, like NTFS, that don't make short names.

One good hash algorithm is to add up all the characters, multiplying the total by some prime (like 13) each time. Simple and you only risk a 1 in 2^32 or 2^64 chance of collision.

Why add that extra step of multiplying? It takes time and onlymakes for a larger result to store...

If you don't multiply, then your hash function is nearly worthless. It will get the same hash for abcdefghijkl as for defabchgilkj.

If number A is worthless, then number A*B will be worthless since B is some arbitrary un-related number (odd, even, integer, rational, irrational, whatever). There would seem to be at least one step that is missing...

You multiply by a prime number at each step:

Tot = 0;

for i = 1 to length( FileName ) do Tot = (Tot * 13) + FileName[ i ];

Tot = Tot mod 4999; // another prime

AhHa!!!!!!!!! The missing step! Modulo!!!

Hi,

I can't understand,

it seems that

"abc.abc"

is the same result as

"cba.cba"

could you please advice more?

thank you very much!

BR/ Boki.

Ancient_Hacker =E5=AF=AB=E9=81=93=EF=BC=9A

$ cat hasher.c /* hasher.c */ #include #include

char mystring[256];

int main(int argc, char **argv) { unsigned int tot; int i, j; tot = 0; for (;;) { printf("-> "); gets (mystring); if ((j = strlen(mystring)) < 1) exit(0); for (i = 0; i < j; i++) { tot = (tot * 13) + (unsigned int) mystring[i]; tot %= 4999; } printf("%s hashes to %d\\n", mystring, tot); } }

$ gcc hasher.c -o hasher /tmp/cc0qtaZC.o(.text+0x30): In function `main': : warning: the `gets' function is dangerous and should not be used. richgrise@thunderbird:~/Programming/C/hash $ hasher

-> abc.abc abc.abc hashes to 81

-> cba.cba cba.cba hashes to 439

Cheers! Rich

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required