Last active
August 10, 2022 02:17
-
-
Save itisravi/4440535 to your computer and use it in GitHub Desktop.
LFN checksum for a given short file name in FAT32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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