Locating the FAT
Since LFNDir will be going directly to the disk's FAT and directory areas, it must determine which sectors are inhabited by these DOS file system structures. This is readily accomplished by issuing the INT 21h Get Device Parameters function. This call returns a structure that describes the layout of the disk, including the number of FATs, number of sectors per FAT, and number of root-directory entries.

It's easy to find the location of the first root-directory sector. Just multiply the number of FATs by the sectors per FAT, and add the result to the location of the first FAT sector. The first FAT sector immediately follows the boot record, which is the first logical sector of the disk. Finding where subdirectories start isn't as straightforward, since these are not stored in a fixed location. I'll discuss this a little later.

Later in the search process, we'll need to read the contents of subdirectories from the disk. To do so, we'll have to translate the FAT entries for the starting and subsequent clusters into actual sector locations on-disk. Each FAT entry is an index into the disk's file area, the area of the disk that can be mapped by the FAT. So to prepare for this task, we calculate and save the sector number where the file area begins. This location immediately follows the root-directory sectors, and it is calculated by adding the number of root-directory sectors to the location of the first root-directory sector.

Armed with the location of the root-directory sectors, the number of FAT sectors, and the first sector of the file area, we're now prepared to start searching for the desired files.