16 bit Assembly

Home   Feedback   Site Map   Instruction Index  


The Root Directory


Directory entries are 32 bytes in length.

The first entry is usually the disk label / name if it was set when the disk was formatted. Otherwise it can appear anywhere on the disk. It can be identified by the Label attribute 0x08h, there can only be one label per disk. So if any other entries have the same attribute they should be ignored, other instance are often paired with the sub folder attribute as well 0xA0h.

You can use these file records to display the Directory contents as shown below. The last values on the right of each entry are the start cluster as a decimal number. Deleted and Extended file names are not shown.

The image shows the file records in the sequence they appear in the Root Directory. Appart from the Start Cluster on the far right, which is shown here to assist with debugging any code.

File names and extensions are in capitals and they are padded with spaces with no dot.

The Date and Time indicate when the file was last modified. Extraction of the Time and Date, which are compressed into a 2 byte format and the 32 bit File Size are covered on a different page.

File Deletion and Recycling

Modern operation systems alow users to recover deleted files by temporarily saving them in a recyling bin.

This is acheived by moving the file to the bin and renaming it, by changing the first letter of the file name to byte E5h. Then storing the first letter in the first byte for the Reserve block for that ROOT file record. This preserves the file, preventing it from being over-written.

When the user empties the Recyle bin the first byte of the Reserve block is over-written with a NULL. This effectively makes recovery of the file difficult, as can now be overwritten by future file operations.

Loading a File from Floppy to Memory

Here is a summary of the tasks required.

  1. Enter the file name to be loaded.
  2. Convert the file name so it matches the required disk format (for floppies this is an 8.3 filename in UPPER case) as shown in the Directory file list image above.
  3. Load the Root Directory in to memory.
  4. Search the Root Directory in memory for the Filename.
  5. If found read the Start Cluster.
  6. Load one of the FAT's into memory.
  7. Convert the Start Cluster or Allocation Cluster into the Cylinder, Head and Sector numbers. (calculation shown above)
  8. Load the block in to memory.
  9. Read the FAT Allocation Table associated with the Data Block just read, to find the next Block to be read
  10. Repeat steps 7 to 9 until the "End of File" (0x0FFF) message has been reached.
  11. Display or use the loaded file.

Saving a File from Memory to Floppy

Here is a summary of the tasks required.

  1. Load both FAT's and Root Directory into memory.
  2. Check there is room in the Root Directory for the file record.
  3. Calculate the size of the data to be saved.
  4. Scan the FAT for empty spaces to see if there is enough space for the whole data file.
  5. Check both FAT's to ensure there are no bad sectors or errors.
  6. Write the Filename, Attributes, Date, Time, Start Cluster Address, File Size, in the File Directory.
  7. Write each sector block to the disk one sector at a time.
  8. Write the location of each block in Both FAT's as they must be kept identical.
  9. Repeat the step 7 and 8 above for each additonal 512 bytes of the data file.
  10. At the end of the data, write the "End of File" (0x0FFF) mark in both FAT's.
  11. Write both FAT's back to the disk.
  12. Write the File Directory back to the disk.
  13. To be sure one could verify the contents, before performing other tasks or clearing the data area.

If an error occurs stop further operations and display the appropriate error message. Then ask the user what they want to do next.




Last Update 15/01/2023