[comp.sys.amiga] The AmigaDos Hash function, how???

RCST12@HEITHE5.BITNET (01/18/88)

Subject: AmigaDos hash function, how???


A friend of mine is writing a disk-editor, and he ran into a problem
when he wanted to put some amigados knowledge into it.
The question is : How does the hashfunction work??
After some time trying to reverse-engineer it out of disked and a
searn trough the RKM's and the amigados manual we're kind of desperate.
Any Help is Welcome!
Please reply with mail since the news-feed is very irregular lately.
Thanks,

Martien Kuunders,
RCST12 @ HEITHE5.BITNET or
rcst12@eutrc3.uucp (try routing it via mcvax)

"You name it, I'll disclaim it."

carolyn@cbmvax.UUCP (Carolyn Scheppner CATS) (01/19/88)

In article <8801182112.AA24295@jade.berkeley.edu> RCST12@HEITHE5.BITNET writes:
>Subject: AmigaDos hash function, how???
>
>
>A friend of mine is writing a disk-editor, and he ran into a problem
>when he wanted to put some amigados knowledge into it.
>The question is : How does the hashfunction work??


   HASH FUNCTION

   The hash function is applied to the name of a file or directory, and the
resulting value provides an offset into the HashTable which contains either
zero or a key to the first block on a chain linking blocks with the same
hash value.  Each block contains a name field which identifies it.  The
directory and file header block fields are described in the AmigaDOS manual.
 

int HashName(str,hlen)
 
char    *str;           /* The string to find the hash number for       */
int     hlen;           /* The length of the hash table                 */
 
{
  char  xchar;
  int   i, result;

  result = strlen(str);
  for (i=0; i<strlen(str); i++) {
    if (isalpha(str[i])) xchar = toupper(str[i]);
    else xchar = str[i];
    result = ((result * 13) + xchar) & 0x7ff;
  }
  result = result % hlen;
  return(result);
}

-- 
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Carolyn Scheppner -- CATS   >>Commodore Amiga Technical Support<<
                     UUCP  ...{allegra,ihnp4,rutgers}!cbmvax!carolyn 
                     PHONE 215-431-9180
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

page@swan.ulowell.edu (Bob Page) (01/20/88)

[ another topic for comp.sys.amiga.tech :-) ]

RCST12@HEITHE5.BITNET wrote:
>After some time trying to reverse-engineer it out of disked and a

Yeah, DiskEd.  The program that can work on floppies, and the disk
doesn't have to be inserted to be examined by DiskEd.  Now that's what
I call true Guru Meditation.	;-)

>How does the hashfunction work??

From: amiga!neil (Neil Katin)
Subject: Dos hash function
Date: 12 Apr 86 08:56:54 GMT

Recently several people have asked for the dos directory hash function.
Here is a small program that computes it.  The hash value is the longword
offset into the directory block, NOT into the hash table (I just love that
BCPL...).

Anyway, hope it helps.

	Neil Katin
	Commodore-Amiga Inc.
	pyramid!amiga!neil

---- cut here --------------------
main( argc, argv )
int argc;
char **argv;
{
    if( argc != 2 ) {
        printf( "Usage: %s <name>\n", argv[0] );
        exit( 1 );
    }

    printf( "hash is %ld\n", (hash( argv[1] ) % 72) + 6 );

}
 
hash( s )
unsigned char *s;
{
    int i;
    int res;
    unsigned char *sp;
    unsigned c;

    res = strlen( s );

    for( i = 1, sp = s; *sp; i++, sp++ ) {
        c = *sp;
        if( c >= 'a' && c <= 'z' ) {
            c = c - 'a' + 'A';
        }
        res = ((res * 13 + c ) & 0x7ff);
    }
    return( res );
}

>searn trough the RKM's and the amigados manual we're kind of desperate.
>Any Help is Welcome!
>Please reply with mail since the news-feed is very irregular lately.
>Thanks,
>
>Martien Kuunders,
>RCST12 @ HEITHE5.BITNET or
>rcst12@eutrc3.uucp (try routing it via mcvax)
>
>"You name it, I'll disclaim it."


-- 
Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
"I don't know such stuff.  I just do eyes."  -- from 'Blade Runner'