Chapter Nineteen

GET AND
FREE
SECTOR
ROUTINES


The get sector routine, GETSECTOR, is called when a new sector is needed. The routine searches the bit map in the VTOC for a free sector. The sector found is deallocated from the bit map and the sector number is returned to the caller. The free sector routine, FRESECT, is given a sector number to be freed. FRESECT locates the required bit map bit in the VTOC and turns it on (sets it to one). The sector is now eligible for reuse.

GETSECTOR
Address $1106 
Entry Registers  
A = Don't Care.
X = IOCB and FCB number times 16.
Y = Don't Care.
Exit Registers    
A = Unknown.
X = IOCB and FCB number times 16.
Y = Unknown.

Functions:

1) The Y register is used as an index into the bit map bytes.
2) The bit bytes are examined sequentially from the first bit map byte to the last bit map byte until a non-zero byte is found. The displacement to this byte is saved in TEMP 1.
3) If no bits are found in the bit map, then the ERRNSA exit (no sectors available) is taken.
4) The number-of-sectors-available-field, in the VTOC, is decremented by one.
5) The VTOC write required byte in the VTOC is set to a non-zero value to indicate that the VTOC has been changed and must be written back to the disk.
6) The non-zero bit map byte that was found in the bit map search is retrieved. The bits in this byte are shifted left until a bit moves into the carry flag. The carry is then set clear and the bits shifted back to their original position. The byte with the newly allocated sector bit turned off is placed back into the bit map.
7) The number of bits shifted and the index to the bit map byte are used to develop the sector number represented by the bit.
8) The sector number is stored in the FCB link sector field, FCBLSN.
9) The user then returned to via the RTS instruction.
FRESECT
Address $10C5
Entry Registers   
A = Don't Care.
X = IOCB and FCB number times 16.
Y = Don't Care.
Exit Registers     
A = Unknown.
X = IOCB and FCB number times 16.
Y = Unknown.

Functions:

1) The sector to be freed is in the FCB current sector field, FCBCSN. If the sector number is zero, then FRESECT exits back to the user via the RTS instruction.
2) The sector number is divided by eight to determine the bit map byte which represents the sector. The remainder from this division represents the bit within the byte.
3) The byte is retrieved from the bit map, the bit is turned on, and the byte placed hack into the bit map.
4) The number of available sectors field in the VTOC is incremented by one.
5) The VTOC write required byte is set to non-zero to indicate that the VTOC has been changed and needs to be written back to the disk.
6) The caller is returned to via the RTS instruction.

Return to Table of Contents | Previous Chapter | Next Chapter