Chapter
4
I
MS-DOS
Disk
Albcation
How
to Use the File Allocation Table
To find the starting cluster
of
the file, use the directory entry.
Next,
to
locate each subsequent cluster
of
the file:
1.
2.
3.
4.
5.
Multiply the cluster number just used by 1.5 (each FAT en-
try
is
1.5
bytes
long).
The whole part of the product is an offset into the FAT,
pointing to the entry that maps the cluster just used. That
entry contains the cluster number
of
the next cluster
of
the
file.
Use
a
MOV
instruction
to
move the word at the calculated
FAT offset into a register.
If the last cluster used was an even number, keep the low-
order 12 bits
of
the register by ANDing it with FFF; other-
wise, keep the high-order 12 bits by shifting the register
right
4
bits with
a
SHR
instruction.
If the resultant 12 bits are FF8H-FFFH, the file contains
no more clusters. Otherwise, the 12 bits contain the cluster
number
of
the next cluster in the file.
To convert the cluster number
to
a logical sector number (rela-
tive sector, such as that used by Interrupts 25H and 26H and by
DEBUG):
1.
2.
3.
Subtract 2 from the cluster number.
Multiply the result by the number
of
sectors per cluster.
Add to this result the logical sector number
of
the begin-
ning
of
the data area.
170