]> git.proxmox.com Git - mirror_edk2.git/blame - FatPkg/EnhancedFatDxe/Hash.c
FatPkg/EnhancedFatDxe: Make the comments align with EDKIIcoding style
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Hash.c
CommitLineData
cae7420b
DB
1/** @file\r
2 Hash table operations.\r
b9ec9330 3\r
e76bc43e 4Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
6163cc98 5This program and the accompanying materials are licensed and made available\r
b9ec9330
QH
6under the terms and conditions of the BSD License which accompanies this\r
7distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
cae7420b 13**/\r
b9ec9330 14\r
cae7420b 15#include "Fat.h"\r
b9ec9330 16\r
cae7420b 17/**\r
b9ec9330 18\r
cae7420b 19 Get hash value for long name.\r
b9ec9330 20\r
cae7420b 21 @param LongNameString - The long name string to be hashed.\r
b9ec9330 22\r
cae7420b 23 @return HashValue.\r
b9ec9330 24\r
cae7420b 25**/\r
b9ec9330
QH
26STATIC\r
27UINT32\r
28FatHashLongName (\r
29 IN CHAR16 *LongNameString\r
30 )\r
b9ec9330
QH
31{\r
32 UINT32 HashValue;\r
33 CHAR16 UpCasedLongFileName[EFI_PATH_STRING_LENGTH];\r
e76bc43e
HW
34 StrnCpyS (\r
35 UpCasedLongFileName,\r
0cdc10bd 36 ARRAY_SIZE (UpCasedLongFileName),\r
e76bc43e 37 LongNameString,\r
0cdc10bd 38 ARRAY_SIZE (UpCasedLongFileName) - 1\r
e76bc43e 39 );\r
b9ec9330
QH
40 FatStrUpr (UpCasedLongFileName);\r
41 gBS->CalculateCrc32 (UpCasedLongFileName, StrSize (UpCasedLongFileName), &HashValue);\r
42 return (HashValue & HASH_TABLE_MASK);\r
43}\r
44\r
cae7420b 45/**\r
b9ec9330
QH
46\r
47 Get hash value for short name.\r
48\r
cae7420b 49 @param ShortNameString - The short name string to be hashed.\r
b9ec9330 50\r
cae7420b 51 @return HashValue\r
b9ec9330 52\r
cae7420b
DB
53**/\r
54STATIC\r
55UINT32\r
56FatHashShortName (\r
57 IN CHAR8 *ShortNameString\r
58 )\r
b9ec9330
QH
59{\r
60 UINT32 HashValue;\r
61 gBS->CalculateCrc32 (ShortNameString, FAT_NAME_LEN, &HashValue);\r
62 return (HashValue & HASH_TABLE_MASK);\r
63}\r
64\r
cae7420b 65/**\r
b9ec9330
QH
66\r
67 Search the long name hash table for the directory entry.\r
68\r
cae7420b
DB
69 @param ODir - The directory to be searched.\r
70 @param LongNameString - The long name string to search.\r
b9ec9330 71\r
cae7420b 72 @return The previous long name hash node of the directory entry.\r
b9ec9330 73\r
cae7420b
DB
74**/\r
75FAT_DIRENT **\r
76FatLongNameHashSearch (\r
77 IN FAT_ODIR *ODir,\r
78 IN CHAR16 *LongNameString\r
79 )\r
b9ec9330
QH
80{\r
81 FAT_DIRENT **PreviousHashNode;\r
82 for (PreviousHashNode = &ODir->LongNameHashTable[FatHashLongName (LongNameString)];\r
83 *PreviousHashNode != NULL;\r
84 PreviousHashNode = &(*PreviousHashNode)->LongNameForwardLink\r
85 ) {\r
86 if (FatStriCmp (LongNameString, (*PreviousHashNode)->FileString) == 0) {\r
87 break;\r
88 }\r
89 }\r
90\r
91 return PreviousHashNode;\r
92}\r
93\r
cae7420b 94/**\r
b9ec9330
QH
95\r
96 Search the short name hash table for the directory entry.\r
97\r
cae7420b
DB
98 @param ODir - The directory to be searched.\r
99 @param ShortNameString - The short name string to search.\r
b9ec9330 100\r
cae7420b 101 @return The previous short name hash node of the directory entry.\r
b9ec9330 102\r
cae7420b
DB
103**/\r
104FAT_DIRENT **\r
105FatShortNameHashSearch (\r
106 IN FAT_ODIR *ODir,\r
107 IN CHAR8 *ShortNameString\r
108 )\r
b9ec9330
QH
109{\r
110 FAT_DIRENT **PreviousHashNode;\r
111 for (PreviousHashNode = &ODir->ShortNameHashTable[FatHashShortName (ShortNameString)];\r
112 *PreviousHashNode != NULL;\r
113 PreviousHashNode = &(*PreviousHashNode)->ShortNameForwardLink\r
114 ) {\r
115 if (CompareMem (ShortNameString, (*PreviousHashNode)->Entry.FileName, FAT_NAME_LEN) == 0) {\r
116 break;\r
117 }\r
118 }\r
119\r
120 return PreviousHashNode;\r
121}\r
122\r
cae7420b
DB
123/**\r
124\r
125 Insert directory entry to hash table.\r
126\r
127 @param ODir - The parent directory.\r
128 @param DirEnt - The directory entry node.\r
129\r
130**/\r
b9ec9330
QH
131VOID\r
132FatInsertToHashTable (\r
133 IN FAT_ODIR *ODir,\r
134 IN FAT_DIRENT *DirEnt\r
135 )\r
b9ec9330
QH
136{\r
137 FAT_DIRENT **HashTable;\r
138 UINT32 HashTableIndex;\r
139\r
140 //\r
141 // Insert hash table index for short name\r
142 //\r
143 HashTableIndex = FatHashShortName (DirEnt->Entry.FileName);\r
144 HashTable = ODir->ShortNameHashTable;\r
145 DirEnt->ShortNameForwardLink = HashTable[HashTableIndex];\r
146 HashTable[HashTableIndex] = DirEnt;\r
147 //\r
148 // Insert hash table index for long name\r
149 //\r
150 HashTableIndex = FatHashLongName (DirEnt->FileString);\r
151 HashTable = ODir->LongNameHashTable;\r
152 DirEnt->LongNameForwardLink = HashTable[HashTableIndex];\r
153 HashTable[HashTableIndex] = DirEnt;\r
154}\r
155\r
cae7420b
DB
156/**\r
157\r
158 Delete directory entry from hash table.\r
159\r
160 @param ODir - The parent directory.\r
161 @param DirEnt - The directory entry node.\r
162\r
163**/\r
b9ec9330
QH
164VOID\r
165FatDeleteFromHashTable (\r
166 IN FAT_ODIR *ODir,\r
167 IN FAT_DIRENT *DirEnt\r
168 )\r
b9ec9330
QH
169{\r
170 *FatShortNameHashSearch (ODir, DirEnt->Entry.FileName) = DirEnt->ShortNameForwardLink;\r
171 *FatLongNameHashSearch (ODir, DirEnt->FileString) = DirEnt->LongNameForwardLink;\r
172}\r