]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - FatPkg/EnhancedFatDxe/Hash.c
FatPkg/EnhancedFatDxe: Add comments for functions
[mirror_edk2.git] / FatPkg / EnhancedFatDxe / Hash.c
... / ...
CommitLineData
1/** @file\r
2 Hash table operations.\r
3\r
4Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials are licensed and made available\r
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
13**/\r
14\r
15#include "Fat.h"\r
16\r
17/**\r
18\r
19 Get hash value for long name.\r
20\r
21 @param LongNameString - The long name string to be hashed.\r
22\r
23 @return HashValue.\r
24\r
25**/\r
26STATIC\r
27UINT32\r
28FatHashLongName (\r
29 IN CHAR16 *LongNameString\r
30 )\r
31{\r
32 UINT32 HashValue;\r
33 CHAR16 UpCasedLongFileName[EFI_PATH_STRING_LENGTH];\r
34 StrnCpyS (\r
35 UpCasedLongFileName,\r
36 ARRAY_SIZE (UpCasedLongFileName),\r
37 LongNameString,\r
38 ARRAY_SIZE (UpCasedLongFileName) - 1\r
39 );\r
40 FatStrUpr (UpCasedLongFileName);\r
41 gBS->CalculateCrc32 (UpCasedLongFileName, StrSize (UpCasedLongFileName), &HashValue);\r
42 return (HashValue & HASH_TABLE_MASK);\r
43}\r
44\r
45/**\r
46\r
47 Get hash value for short name.\r
48\r
49 @param ShortNameString - The short name string to be hashed.\r
50\r
51 @return HashValue\r
52\r
53**/\r
54STATIC\r
55UINT32\r
56FatHashShortName (\r
57 IN CHAR8 *ShortNameString\r
58 )\r
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
65/**\r
66\r
67 Search the long name hash table for the directory entry.\r
68\r
69 @param ODir - The directory to be searched.\r
70 @param LongNameString - The long name string to search.\r
71\r
72 @return The previous long name hash node of the directory entry.\r
73\r
74**/\r
75FAT_DIRENT **\r
76FatLongNameHashSearch (\r
77 IN FAT_ODIR *ODir,\r
78 IN CHAR16 *LongNameString\r
79 )\r
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
94/**\r
95\r
96 Search the short name hash table for the directory entry.\r
97\r
98 @param ODir - The directory to be searched.\r
99 @param ShortNameString - The short name string to search.\r
100\r
101 @return The previous short name hash node of the directory entry.\r
102\r
103**/\r
104FAT_DIRENT **\r
105FatShortNameHashSearch (\r
106 IN FAT_ODIR *ODir,\r
107 IN CHAR8 *ShortNameString\r
108 )\r
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
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
131VOID\r
132FatInsertToHashTable (\r
133 IN FAT_ODIR *ODir,\r
134 IN FAT_DIRENT *DirEnt\r
135 )\r
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
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
164VOID\r
165FatDeleteFromHashTable (\r
166 IN FAT_ODIR *ODir,\r
167 IN FAT_DIRENT *DirEnt\r
168 )\r
169{\r
170 *FatShortNameHashSearch (ODir, DirEnt->Entry.FileName) = DirEnt->ShortNameForwardLink;\r
171 *FatLongNameHashSearch (ODir, DirEnt->FileString) = DirEnt->LongNameForwardLink;\r
172}\r