diff --git a/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.cpp b/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.cpp index 501ae8f8c5..2eb59db91c 100644 --- a/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.cpp +++ b/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.cpp @@ -73,10 +73,30 @@ BaseBlock::ValidateCheckSum() const // #pragma mark - -int32 -DirectoryBlock::HashIndexFor(const char *name) +char +DirectoryBlock::ToUpperChar(int32 type, char c) const { - return 0; + // Taken from Ralph Babel's "The Amiga Guru Book" (1993), section 15.3.4.3 + + if (type == DT_AMIGA_OFS || type == DT_AMIGA_FFS) + return c >= 'a' && c <= 'z' ? c + ('A' - 'a') : c; + + return (c >= '\340' && c <= '\376' && c != '\367') + || (c >= 'a' && c <= 'z') ? c + ('A' - 'a') : c; +} + + +int32 +DirectoryBlock::HashIndexFor(int32 type, const char *name) const +{ + int32 hash = strlen(name); + + while (name[0]) { + hash = (hash * 13 + ToUpperChar(type, name[0])) & 0x7ff; + name++; + } + + return hash % HashSize(); } @@ -131,6 +151,21 @@ HashIterator::~HashIterator() } +status_t +HashIterator::InitCheck() +{ + return fData != NULL ? B_OK : B_NO_MEMORY; +} + + +void +HashIterator::Goto(int32 index) +{ + fCurrent = index; + fBlock = fDirectory.HashValueAt(index); +} + + NodeBlock * HashIterator::GetNext(int32 &block) { diff --git a/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.h b/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.h index 44b447247c..8858fb4e4c 100644 --- a/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.h +++ b/src/kernel/boot/loader/file_systems/amiga_ffs/amiga_ffs.h @@ -87,7 +87,8 @@ class DirectoryBlock : public NodeBlock { DirectoryBlock(int32 blockSize) : NodeBlock(blockSize) {} DirectoryBlock(void *data, int32 blockSize) : NodeBlock(data, blockSize) {} - int32 HashIndexFor(const char *name); + char ToUpperChar(int32 type, char c) const; + int32 HashIndexFor(int32 type, const char *name) const; int32 HashValueAt(int32 index) const; int32 NextHashValue(int32 &index) const; @@ -143,6 +144,8 @@ class HashIterator { HashIterator(int32 device, DirectoryBlock &node); ~HashIterator(); + status_t InitCheck(); + void Goto(int32 index); NodeBlock *GetNext(int32 &block); void Rewind();