Skip to content

Instantly share code, notes, and snippets.

@itisravi
Last active August 10, 2022 02:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itisravi/4440535 to your computer and use it in GitHub Desktop.
Save itisravi/4440535 to your computer and use it in GitHub Desktop.
LFN checksum for a given short file name in FAT32
#include <stdio.h>
#include <stdlib.h>
unsigned char
ChkSum (unsigned char *pFcbName)
{
short FcbNameLen;
unsigned char Sum;
Sum = 0;
for (FcbNameLen = 11; FcbNameLen != 0; FcbNameLen--)
{
// NOTE: The operation is an unsigned char rotate right
Sum = ((Sum & 1) ? 0x80 : 0) + (Sum >> 1) + *pFcbName++;
}
return (Sum);
}
int
main (void)
{
unsigned char SFN_old[11] =
{ 'T', 'H', 'I', 'S', 'I', 'S', '~', '1', ' ', ' ', ' ' };
unsigned char SFN_new[11] =
{ 'M', 'Y', 'N', 'E', 'W', 'D', 'I', 'R', ' ', ' ', ' ' };
unsigned char ck = ChkSum (SFN_old);
printf ("Old Checksum=%X\n", ck);
ck = ChkSum (SFN_new);
printf ("New Checksum=%X\n", ck);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment