]>
Commit | Line | Data |
---|---|---|
b9ec9330 QH |
1 | /*++\r |
2 | \r | |
6163cc98 HT |
3 | Copyright (c) 2005 - 2007, Intel Corporation. All rights reserved.<BR>\r |
4 | This program and the accompanying materials are licensed and made available\r | |
b9ec9330 QH |
5 | under the terms and conditions of the BSD License which accompanies this\r |
6 | distribution. The full text of the license may be found at\r | |
7 | http://opensource.org/licenses/bsd-license.php\r | |
8 | \r | |
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
11 | \r | |
12 | \r | |
13 | Module Name:\r | |
14 | \r | |
15 | Hash.c\r | |
16 | \r | |
17 | Abstract:\r | |
18 | \r | |
19 | Hash table operations\r | |
20 | \r | |
21 | Revision History\r | |
22 | \r | |
23 | --*/\r | |
24 | \r | |
25 | #include "Fat.h"\r | |
26 | \r | |
27 | STATIC\r | |
28 | UINT32\r | |
29 | FatHashLongName (\r | |
30 | IN CHAR16 *LongNameString\r | |
31 | )\r | |
32 | /*++\r | |
33 | \r | |
34 | Routine Description:\r | |
35 | \r | |
36 | Get hash value for long name.\r | |
37 | \r | |
38 | Arguments:\r | |
39 | \r | |
40 | LongNameString - The long name string to be hashed.\r | |
41 | \r | |
42 | Returns:\r | |
43 | \r | |
44 | HashValue.\r | |
45 | \r | |
46 | --*/\r | |
47 | {\r | |
48 | UINT32 HashValue;\r | |
49 | CHAR16 UpCasedLongFileName[EFI_PATH_STRING_LENGTH];\r | |
50 | StrCpy (UpCasedLongFileName, LongNameString);\r | |
51 | FatStrUpr (UpCasedLongFileName);\r | |
52 | gBS->CalculateCrc32 (UpCasedLongFileName, StrSize (UpCasedLongFileName), &HashValue);\r | |
53 | return (HashValue & HASH_TABLE_MASK);\r | |
54 | }\r | |
55 | \r | |
56 | STATIC\r | |
57 | UINT32\r | |
58 | FatHashShortName (\r | |
59 | IN CHAR8 *ShortNameString\r | |
60 | )\r | |
61 | /*++\r | |
62 | \r | |
63 | Routine Description:\r | |
64 | \r | |
65 | Get hash value for short name.\r | |
66 | \r | |
67 | Arguments:\r | |
68 | \r | |
69 | ShortNameString - The short name string to be hashed.\r | |
70 | \r | |
71 | Returns:\r | |
72 | \r | |
73 | HashValue\r | |
74 | \r | |
75 | --*/\r | |
76 | {\r | |
77 | UINT32 HashValue;\r | |
78 | gBS->CalculateCrc32 (ShortNameString, FAT_NAME_LEN, &HashValue);\r | |
79 | return (HashValue & HASH_TABLE_MASK);\r | |
80 | }\r | |
81 | \r | |
82 | FAT_DIRENT **\r | |
83 | FatLongNameHashSearch (\r | |
84 | IN FAT_ODIR *ODir,\r | |
85 | IN CHAR16 *LongNameString\r | |
86 | )\r | |
87 | /*++\r | |
88 | \r | |
89 | Routine Description:\r | |
90 | \r | |
91 | Search the long name hash table for the directory entry.\r | |
92 | \r | |
93 | Arguments:\r | |
94 | \r | |
95 | ODir - The directory to be searched.\r | |
96 | LongNameString - The long name string to search.\r | |
97 | \r | |
98 | Returns:\r | |
99 | \r | |
100 | The previous long name hash node of the directory entry.\r | |
101 | \r | |
102 | --*/\r | |
103 | {\r | |
104 | FAT_DIRENT **PreviousHashNode;\r | |
105 | for (PreviousHashNode = &ODir->LongNameHashTable[FatHashLongName (LongNameString)];\r | |
106 | *PreviousHashNode != NULL;\r | |
107 | PreviousHashNode = &(*PreviousHashNode)->LongNameForwardLink\r | |
108 | ) {\r | |
109 | if (FatStriCmp (LongNameString, (*PreviousHashNode)->FileString) == 0) {\r | |
110 | break;\r | |
111 | }\r | |
112 | }\r | |
113 | \r | |
114 | return PreviousHashNode;\r | |
115 | }\r | |
116 | \r | |
117 | FAT_DIRENT **\r | |
118 | FatShortNameHashSearch (\r | |
119 | IN FAT_ODIR *ODir,\r | |
120 | IN CHAR8 *ShortNameString\r | |
121 | )\r | |
122 | /*++\r | |
123 | \r | |
124 | Routine Description:\r | |
125 | \r | |
126 | Search the short name hash table for the directory entry.\r | |
127 | \r | |
128 | Arguments:\r | |
129 | \r | |
130 | ODir - The directory to be searched.\r | |
131 | ShortNameString - The short name string to search.\r | |
132 | \r | |
133 | Returns:\r | |
134 | \r | |
135 | The previous short name hash node of the directory entry.\r | |
136 | \r | |
137 | --*/\r | |
138 | {\r | |
139 | FAT_DIRENT **PreviousHashNode;\r | |
140 | for (PreviousHashNode = &ODir->ShortNameHashTable[FatHashShortName (ShortNameString)];\r | |
141 | *PreviousHashNode != NULL;\r | |
142 | PreviousHashNode = &(*PreviousHashNode)->ShortNameForwardLink\r | |
143 | ) {\r | |
144 | if (CompareMem (ShortNameString, (*PreviousHashNode)->Entry.FileName, FAT_NAME_LEN) == 0) {\r | |
145 | break;\r | |
146 | }\r | |
147 | }\r | |
148 | \r | |
149 | return PreviousHashNode;\r | |
150 | }\r | |
151 | \r | |
152 | VOID\r | |
153 | FatInsertToHashTable (\r | |
154 | IN FAT_ODIR *ODir,\r | |
155 | IN FAT_DIRENT *DirEnt\r | |
156 | )\r | |
157 | /*++\r | |
158 | \r | |
159 | Routine Description:\r | |
160 | \r | |
161 | Insert directory entry to hash table.\r | |
162 | \r | |
163 | Arguments:\r | |
164 | \r | |
165 | ODir - The parent directory.\r | |
166 | DirEnt - The directory entry node.\r | |
167 | \r | |
168 | Returns:\r | |
169 | \r | |
170 | None.\r | |
171 | \r | |
172 | --*/\r | |
173 | {\r | |
174 | FAT_DIRENT **HashTable;\r | |
175 | UINT32 HashTableIndex;\r | |
176 | \r | |
177 | //\r | |
178 | // Insert hash table index for short name\r | |
179 | //\r | |
180 | HashTableIndex = FatHashShortName (DirEnt->Entry.FileName);\r | |
181 | HashTable = ODir->ShortNameHashTable;\r | |
182 | DirEnt->ShortNameForwardLink = HashTable[HashTableIndex];\r | |
183 | HashTable[HashTableIndex] = DirEnt;\r | |
184 | //\r | |
185 | // Insert hash table index for long name\r | |
186 | //\r | |
187 | HashTableIndex = FatHashLongName (DirEnt->FileString);\r | |
188 | HashTable = ODir->LongNameHashTable;\r | |
189 | DirEnt->LongNameForwardLink = HashTable[HashTableIndex];\r | |
190 | HashTable[HashTableIndex] = DirEnt;\r | |
191 | }\r | |
192 | \r | |
193 | VOID\r | |
194 | FatDeleteFromHashTable (\r | |
195 | IN FAT_ODIR *ODir,\r | |
196 | IN FAT_DIRENT *DirEnt\r | |
197 | )\r | |
198 | /*++\r | |
199 | \r | |
200 | Routine Description:\r | |
201 | \r | |
202 | Delete directory entry from hash table.\r | |
203 | \r | |
204 | Arguments:\r | |
205 | \r | |
206 | ODir - The parent directory.\r | |
207 | DirEnt - The directory entry node.\r | |
208 | \r | |
209 | Returns:\r | |
210 | \r | |
211 | None.\r | |
212 | \r | |
213 | --*/\r | |
214 | {\r | |
215 | *FatShortNameHashSearch (ODir, DirEnt->Entry.FileName) = DirEnt->ShortNameForwardLink;\r | |
216 | *FatLongNameHashSearch (ODir, DirEnt->FileString) = DirEnt->LongNameForwardLink;\r | |
217 | }\r |