29.12.2012 Views

The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...

The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...

The Programmer's Guide to TRSDOS Version 6 - Tim Mann's Home ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

5.3 THE HASH INDEX TABLE (HIT)<br />

<strong>The</strong> Hash Index Table is the key <strong>to</strong> addressing any file in the direc<strong>to</strong>ry. It is designed<br />

so as <strong>to</strong> pinpoint the location of a file's primary direc<strong>to</strong>ry entry with a minimum of disk<br />

accesses. A minimum quantity of disk accesses is useful <strong>to</strong> keep system overhead low while<br />

at the same time providing for rapid file access.<br />

===================================================<br />

| ___________________________________________ |<br />

| | 10| 9 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | |<br />

| | F | I | L | E | N | A | M | E | E | X | T | |<br />

| | E X A M P L E D A T | |<br />

| |___________________________________________| |<br />

| |<br />

===================================================<br />

Figure 5-4: File NAME/EXT buffer<br />

When an application requests the system <strong>to</strong> open a file, the system must locate that<br />

File's Primary Direc<strong>to</strong>ry Entry (FPDE) record which contains the disk s<strong>to</strong>rage data needed<br />

<strong>to</strong> address the file. <strong>The</strong> procedure that the system uses <strong>to</strong> locate a file's FPDE is <strong>to</strong><br />

first take the file name and extension and construct an 11-byte field with the file name<br />

left justified and padded with blanks so as <strong>to</strong> fill out eight positions. <strong>The</strong> file<br />

extension is then inserted, padded with blanks, and will occupy the three least<br />

significant bytes of the 11-byte field. <strong>The</strong> resulting string is illustrated in figure 5-<br />

4. This field is then processed through a hashing algorithm which produces a single byte<br />

value in the range X'01' through X'FF' (a hash value of X'00' is reserved <strong>to</strong> indicate a<br />

spare HIT position). <strong>The</strong> following code may be used <strong>to</strong> obtain the one-byte hash code for<br />

an 11-character NAME/EXT buffer.<br />

HASHSPEC LD HL,SPECPTR ;Point <strong>to</strong> the 8-char buffer<br />

LD A,0D4H ;Specify filename hash function<br />

RST 40 ;Issue the RST instruction<br />

<strong>The</strong> one-byte hash code is returned in the accumula<strong>to</strong>r. Registers AF, B and HL are<br />

altered. <strong>The</strong> operating system will not return <strong>to</strong> the address following the RST 40<br />

instruction when the SVC function code is an internal system request code (i.e. has bit-7<br />

set) but will return <strong>to</strong> the previous caller. Thus, it is necessary <strong>to</strong> CALL this routine.<br />

Each file's hash code is s<strong>to</strong>red in the Hash Index Table (HIT) at a position which is<br />

associated with the FPDE record containing the file's access information. After the OPEN<br />

routine obtains the hash code for the file identified in the file specification, it<br />

searches the HIT for a matching hash code. Since more than one 11-byte string can hash <strong>to</strong><br />

identical codes, the opportunity for a "collision" exists (a collision is where two or<br />

more file names result in the same hash code). For this reason, the search algorithm will<br />

sequentially scan the HIT for a matching code entry and when found, will then read the<br />

FPDE record corresponding <strong>to</strong> the matching HIT position. OPEN will then compare the file<br />

name/ext s<strong>to</strong>red in the FPDE record with that provided in the file specification. If both<br />

match, the file's FPDE direc<strong>to</strong>ry record has been found. If the two fields do not match,<br />

the HIT entry was a collision and the algorithm continues its search from where it left<br />

off. If a match <strong>to</strong> the hash code is not found in the HIT, the file does not exist on that<br />

disk drive. If the user passed a drive specification (drivespec) as part of the file<br />

specification, a "File not found" error will be returned. If no drivespec was passed, the<br />

system will search all drives in logical number order starting with drive 0. If the @INIT<br />

SuperVisor Call was used <strong>to</strong> open the file, the system will first use @OPEN <strong>to</strong> determine<br />

the possible existence of the file. If @OPEN advises that the file has not been found,<br />

then @INIT will create the file by obtaining a spare HIT position then constructing the<br />

corresponding FPDE.<br />

5-6

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!