TianoCore EDK2 master
Loading...
Searching...
No Matches
Hash.c
Go to the documentation of this file.
1
9#include "Fat.h"
10
21UINT32
23 IN CHAR16 *LongNameString
24 )
25{
26 UINT32 HashValue;
27 CHAR16 UpCasedLongFileName[EFI_PATH_STRING_LENGTH];
28
29 StrnCpyS (
30 UpCasedLongFileName,
31 ARRAY_SIZE (UpCasedLongFileName),
32 LongNameString,
33 ARRAY_SIZE (UpCasedLongFileName) - 1
34 );
35 FatStrUpr (UpCasedLongFileName);
36 gBS->CalculateCrc32 (UpCasedLongFileName, StrSize (UpCasedLongFileName), &HashValue);
37 return (HashValue & HASH_TABLE_MASK);
38}
39
50UINT32
52 IN CHAR8 *ShortNameString
53 )
54{
55 UINT32 HashValue;
56
57 gBS->CalculateCrc32 (ShortNameString, FAT_NAME_LEN, &HashValue);
58 return (HashValue & HASH_TABLE_MASK);
59}
60
73 IN FAT_ODIR *ODir,
74 IN CHAR16 *LongNameString
75 )
76{
77 FAT_DIRENT **PreviousHashNode;
78
79 for (PreviousHashNode = &ODir->LongNameHashTable[FatHashLongName (LongNameString)];
80 *PreviousHashNode != NULL;
81 PreviousHashNode = &(*PreviousHashNode)->LongNameForwardLink
82 )
83 {
84 if (FatStriCmp (LongNameString, (*PreviousHashNode)->FileString) == 0) {
85 break;
86 }
87 }
88
89 return PreviousHashNode;
90}
91
102FAT_DIRENT **
104 IN FAT_ODIR *ODir,
105 IN CHAR8 *ShortNameString
106 )
107{
108 FAT_DIRENT **PreviousHashNode;
109
110 for (PreviousHashNode = &ODir->ShortNameHashTable[FatHashShortName (ShortNameString)];
111 *PreviousHashNode != NULL;
112 PreviousHashNode = &(*PreviousHashNode)->ShortNameForwardLink
113 )
114 {
115 if (CompareMem (ShortNameString, (*PreviousHashNode)->Entry.FileName, FAT_NAME_LEN) == 0) {
116 break;
117 }
118 }
119
120 return PreviousHashNode;
121}
122
131VOID
133 IN FAT_ODIR *ODir,
134 IN FAT_DIRENT *DirEnt
135 )
136{
137 FAT_DIRENT **HashTable;
138 UINT32 HashTableIndex;
139
140 //
141 // Insert hash table index for short name
142 //
143 HashTableIndex = FatHashShortName (DirEnt->Entry.FileName);
144 HashTable = ODir->ShortNameHashTable;
145 DirEnt->ShortNameForwardLink = HashTable[HashTableIndex];
146 HashTable[HashTableIndex] = DirEnt;
147 //
148 // Insert hash table index for long name
149 //
150 HashTableIndex = FatHashLongName (DirEnt->FileString);
151 HashTable = ODir->LongNameHashTable;
152 DirEnt->LongNameForwardLink = HashTable[HashTableIndex];
153 HashTable[HashTableIndex] = DirEnt;
154}
155
164VOID
166 IN FAT_ODIR *ODir,
167 IN FAT_DIRENT *DirEnt
168 )
169{
170 *FatShortNameHashSearch (ODir, DirEnt->Entry.FileName) = DirEnt->ShortNameForwardLink;
171 *FatLongNameHashSearch (ODir, DirEnt->FileString) = DirEnt->LongNameForwardLink;
172}
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
Definition: String.c:72
RETURN_STATUS EFIAPI StrnCpyS(OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source, IN UINTN Length)
Definition: SafeString.c:310
INTN EFIAPI CompareMem(IN CONST VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
INTN FatStriCmp(IN CHAR16 *Str1, IN CHAR16 *Str2)
VOID FatStrUpr(IN CHAR16 *Str)
FAT_DIRENT ** FatShortNameHashSearch(IN FAT_ODIR *ODir, IN CHAR8 *ShortNameString)
Definition: Hash.c:103
VOID FatInsertToHashTable(IN FAT_ODIR *ODir, IN FAT_DIRENT *DirEnt)
Definition: Hash.c:132
STATIC UINT32 FatHashShortName(IN CHAR8 *ShortNameString)
Definition: Hash.c:51
STATIC UINT32 FatHashLongName(IN CHAR16 *LongNameString)
Definition: Hash.c:22
VOID FatDeleteFromHashTable(IN FAT_ODIR *ODir, IN FAT_DIRENT *DirEnt)
Definition: Hash.c:165
FAT_DIRENT ** FatLongNameHashSearch(IN FAT_ODIR *ODir, IN CHAR16 *LongNameString)
Definition: Hash.c:72
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define ARRAY_SIZE(Array)
Definition: Base.h:1393
#define IN
Definition: Base.h:279
EFI_BOOT_SERVICES * gBS
Definition: Fat.h:204