ShortPathFilename in memory disk.

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.

Reply to
Boki
Loading thread data ...

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.

Reply to
Robert Baer

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.

Reply to
Ancient_Hacker

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

Reply to
Robert Baer

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

Reply to
Ancient_Hacker

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...

Reply to
Robert Baer

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

Reply to
Ancient_Hacker

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

Reply to
Robert Baer

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

Reply to
Boki

On Sat, 04 Mar 2006 19:29:01 -0800, Boki top-posted:

$ 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

Reply to
Rich Grise

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.