2016-12-09 03:07:49 +01:00
|
|
|
/** @file
|
|
|
|
Hash table operations.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2015-07-06 03:41:45 +02:00
|
|
|
Copyright (c) 2005 - 2015, Intel Corporation. All rights reserved.<BR>
|
2019-04-04 01:03:46 +02:00
|
|
|
SPDX-License-Identifier: BSD-2-Clause-Patent
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
**/
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
#include "Fat.h"
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
/**
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
Get hash value for long name.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@param LongNameString - The long name string to be hashed.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@return HashValue.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
**/
|
2007-12-20 10:16:45 +01:00
|
|
|
STATIC
|
|
|
|
UINT32
|
|
|
|
FatHashLongName (
|
|
|
|
IN CHAR16 *LongNameString
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UINT32 HashValue;
|
|
|
|
CHAR16 UpCasedLongFileName[EFI_PATH_STRING_LENGTH];
|
2015-07-06 03:41:45 +02:00
|
|
|
StrnCpyS (
|
|
|
|
UpCasedLongFileName,
|
2016-10-26 18:33:08 +02:00
|
|
|
ARRAY_SIZE (UpCasedLongFileName),
|
2015-07-06 03:41:45 +02:00
|
|
|
LongNameString,
|
2016-10-26 18:33:08 +02:00
|
|
|
ARRAY_SIZE (UpCasedLongFileName) - 1
|
2015-07-06 03:41:45 +02:00
|
|
|
);
|
2007-12-20 10:16:45 +01:00
|
|
|
FatStrUpr (UpCasedLongFileName);
|
|
|
|
gBS->CalculateCrc32 (UpCasedLongFileName, StrSize (UpCasedLongFileName), &HashValue);
|
|
|
|
return (HashValue & HASH_TABLE_MASK);
|
|
|
|
}
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
/**
|
2007-12-20 10:16:45 +01:00
|
|
|
|
|
|
|
Get hash value for short name.
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@param ShortNameString - The short name string to be hashed.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@return HashValue
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
**/
|
|
|
|
STATIC
|
|
|
|
UINT32
|
|
|
|
FatHashShortName (
|
|
|
|
IN CHAR8 *ShortNameString
|
|
|
|
)
|
2007-12-20 10:16:45 +01:00
|
|
|
{
|
|
|
|
UINT32 HashValue;
|
|
|
|
gBS->CalculateCrc32 (ShortNameString, FAT_NAME_LEN, &HashValue);
|
|
|
|
return (HashValue & HASH_TABLE_MASK);
|
|
|
|
}
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
/**
|
2007-12-20 10:16:45 +01:00
|
|
|
|
|
|
|
Search the long name hash table for the directory entry.
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@param ODir - The directory to be searched.
|
|
|
|
@param LongNameString - The long name string to search.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@return The previous long name hash node of the directory entry.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
**/
|
|
|
|
FAT_DIRENT **
|
|
|
|
FatLongNameHashSearch (
|
|
|
|
IN FAT_ODIR *ODir,
|
|
|
|
IN CHAR16 *LongNameString
|
|
|
|
)
|
2007-12-20 10:16:45 +01:00
|
|
|
{
|
|
|
|
FAT_DIRENT **PreviousHashNode;
|
|
|
|
for (PreviousHashNode = &ODir->LongNameHashTable[FatHashLongName (LongNameString)];
|
|
|
|
*PreviousHashNode != NULL;
|
|
|
|
PreviousHashNode = &(*PreviousHashNode)->LongNameForwardLink
|
|
|
|
) {
|
|
|
|
if (FatStriCmp (LongNameString, (*PreviousHashNode)->FileString) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PreviousHashNode;
|
|
|
|
}
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
/**
|
2007-12-20 10:16:45 +01:00
|
|
|
|
|
|
|
Search the short name hash table for the directory entry.
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@param ODir - The directory to be searched.
|
|
|
|
@param ShortNameString - The short name string to search.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
@return The previous short name hash node of the directory entry.
|
2007-12-20 10:16:45 +01:00
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
**/
|
|
|
|
FAT_DIRENT **
|
|
|
|
FatShortNameHashSearch (
|
|
|
|
IN FAT_ODIR *ODir,
|
|
|
|
IN CHAR8 *ShortNameString
|
|
|
|
)
|
2007-12-20 10:16:45 +01:00
|
|
|
{
|
|
|
|
FAT_DIRENT **PreviousHashNode;
|
|
|
|
for (PreviousHashNode = &ODir->ShortNameHashTable[FatHashShortName (ShortNameString)];
|
|
|
|
*PreviousHashNode != NULL;
|
|
|
|
PreviousHashNode = &(*PreviousHashNode)->ShortNameForwardLink
|
|
|
|
) {
|
|
|
|
if (CompareMem (ShortNameString, (*PreviousHashNode)->Entry.FileName, FAT_NAME_LEN) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PreviousHashNode;
|
|
|
|
}
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
Insert directory entry to hash table.
|
|
|
|
|
|
|
|
@param ODir - The parent directory.
|
|
|
|
@param DirEnt - The directory entry node.
|
|
|
|
|
|
|
|
**/
|
2007-12-20 10:16:45 +01:00
|
|
|
VOID
|
|
|
|
FatInsertToHashTable (
|
|
|
|
IN FAT_ODIR *ODir,
|
|
|
|
IN FAT_DIRENT *DirEnt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
FAT_DIRENT **HashTable;
|
|
|
|
UINT32 HashTableIndex;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Insert hash table index for short name
|
|
|
|
//
|
|
|
|
HashTableIndex = FatHashShortName (DirEnt->Entry.FileName);
|
|
|
|
HashTable = ODir->ShortNameHashTable;
|
|
|
|
DirEnt->ShortNameForwardLink = HashTable[HashTableIndex];
|
|
|
|
HashTable[HashTableIndex] = DirEnt;
|
|
|
|
//
|
|
|
|
// Insert hash table index for long name
|
|
|
|
//
|
|
|
|
HashTableIndex = FatHashLongName (DirEnt->FileString);
|
|
|
|
HashTable = ODir->LongNameHashTable;
|
|
|
|
DirEnt->LongNameForwardLink = HashTable[HashTableIndex];
|
|
|
|
HashTable[HashTableIndex] = DirEnt;
|
|
|
|
}
|
|
|
|
|
2016-12-09 03:07:49 +01:00
|
|
|
/**
|
|
|
|
|
|
|
|
Delete directory entry from hash table.
|
|
|
|
|
|
|
|
@param ODir - The parent directory.
|
|
|
|
@param DirEnt - The directory entry node.
|
|
|
|
|
|
|
|
**/
|
2007-12-20 10:16:45 +01:00
|
|
|
VOID
|
|
|
|
FatDeleteFromHashTable (
|
|
|
|
IN FAT_ODIR *ODir,
|
|
|
|
IN FAT_DIRENT *DirEnt
|
|
|
|
)
|
|
|
|
{
|
|
|
|
*FatShortNameHashSearch (ODir, DirEnt->Entry.FileName) = DirEnt->ShortNameForwardLink;
|
|
|
|
*FatLongNameHashSearch (ODir, DirEnt->FileString) = DirEnt->LongNameForwardLink;
|
|
|
|
}
|