Page 1 of 1
ext2fs and hash tables
Posted: Mon May 26, 2003 12:14 pm
by stonedzealot
Im trying to search an ext2 filesystem for a specific file. Since this particular ext2fs is using the indexed directory structure (for faster searching), to find this file, I need to be able to figure out its hash, correct? Well, this beautiful ext2 specification faq (
http://www.nongnu.org/ext2-doc/ext2.html) includes pretty much everything but how to calculate that. Anyone have any ideas on how to do such a thing?
Alternatively, anyone know a better way to search ext2?
Re:ext2fs and hash tables
Posted: Mon May 26, 2003 6:44 pm
by stonedzealot
well...upon looking through the linux ext2 source code, I found this in /usr/src/linux/include/linux/dcache.h...
static __inline__ unsigned long partial_name_hash(unsigned long c, unsigned long prevhash)
{
return (prevhash + (c << 4) + (c >> 4)) * 11;
}
/* Finally: cut down the number of bits to a int value (and try to avoid losing bits) */
static __inline__ unsigned long end_name_hash(unsigned long hash)
{
return (unsigned int) hash;
}
/* Compute the hash for a name string. */
static __inline__ unsigned int full_name_hash(const unsigned char * name, unsigned int len)
{
unsigned long hash = init_name_hash();
while (len--)
hash = partial_name_hash(*name++, hash);
return end_name_hash(hash);
}
I guess that's how you do it....just thought it'd be more difficult...