我刚刚读完这篇关于在 ISO 9660 文件系统上读取文件的文章,我对如何将文件读入内存感到困惑。我知道根目录位于 PVD 的偏移量 156,我将如何使用它来查找位于根目录中的文件,一旦找到文件名,我将如何找到该文件所在的地址,这样我就可以将它加载到内存中(使用 int 0x13 AH=42)?
1 回答
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.