I just got done reading this article on reading files on an ISO 9660 file system, and I am confused on how I would go about reading a file into memory. I understand that the root directory resides at offset 156, of the PVD, how would I use that to find a file that resides in the root directory, and once I find the file name, how would I find the address that file resides on, so that I could load it into memory (using int 0x13 AH=42)?
The BIOS may not make CD drives directly accessible via int 13h, only floppies and HDDs can be always accessed directly with int 13h. If you boot from a CD (if your BIOS supports that), you can use int 13h for accessing the CD, but then the only option that is guaranteed to work is the emulation mode, in which you'll be accessing not the entire CD, but the boot image as if it were FDD or HDD (in this case the BIOS typically assigns drive number 0 or 80h to the emulated disk AKA A:
and C:
). There's a discussion of this problem here.
You may need to write a CD driver to read data from it directly using I/O ports.
As for ISO9660, you need to read Directory entry for the root directory
from Primary Volume Descriptor
(which is at offset 156). Then you're interested in Location of extent (LBA)
(offset 2) and Data length (size of extent)
(offset 10) from Directory entry for the root directory
. These tell you where the directory data (list of files/dirs) resides and how big it is.
This list is basically a list of the same directory entries that are variable in length (due to variable file/dir name lengths and padding). When you read it you need to look at File flags
of every entry to determine if it's a file or a directory. If it's a directory and you want to access it, you repeat the whole procedure recursively. If it's a file, Location of extent (LBA)
(offset 2) and Data length (size of extent)
(offset 10) tell you where it is and how large it is.
Hopefully, I haven't messed this up as I don't have my old CD code handy.
Oh, and be warned, the above is a very simplified description of how you should read CDs, most CDs, but not all. The FS is unnecessarily general and complex and there many features and options that make it hard to read it correctly in all situations.
I suggest that you get a few .iso
files, a hex editor and a calculator and double check the logic and better familiarize yourself with the file system.