News: 11 March 2016 - Forum Rules

Author Topic: [Solved] Working with ISO 9660 (Tools for working with "UMD" ISOs)  (Read 1655 times)

flame

  • Full Member
  • ***
  • Posts: 120
    • View Profile
[Solved] Working with ISO 9660 (Tools for working with "UMD" ISOs)
« on: September 03, 2016, 06:39:21 pm »
I am trying to develop an application that will take a path or partial path you specify, look for that pathname and if found extract the file.

My question is related to parsing the directory record. The directory record specifies the attributes for each file and folder in a specific folder like LBA, size, filename, and file flags.
I need my program to know when the last directory record entry for a specific folder has been read.
Directory entries are per LBA, so mastering programs will, when they reach the end of a folder, write a lot of zeros until the end of the LBA is reached, then start writing directory entries for the next folder and so on.
I found out the longest possible directory record is 78 bytes long, because:
78 = 33 (mandatory minimum length) + 1 (padding) + 30 (maximum filename length, incl. extension) + 14 (14-byte field Sony uses, I don't understand what it means)
So if there are at least 78 bytes to go until the end of the LBA and byte "0" (directory entry length) is read, then I can be sure that the end of the directory entry for this folder has been reached.
But what if there are less than 78 bytes to go until the end of the LBA?
Well, my program will skip to the next LBA and read the first entry. If it is the first entry for the next folder (i.e., not an entry for an additional file or folder in the current folder), then its LBA field will equal the current LBA, because the first folder entry is always for ".", the current folder.

So really, problems will only happen in the edge case where there's less than 78 bytes to the next LBA for the last folder. Usually the first file will be the very next LBA after the end of the last directory entry. So how can I tell in this edge case whether the next LBA has additional directory entries or if it's the first file in the ISO? This is the PSP case: usually (always?) the first file is UMD_DATA.BIN and the first letters of this file are always UL or NP so I could check for that. How would you do this in the general case?
--------------------------------------------------
Found the answer. It's actually in the explanation above if you can believe that.

Quote
The directory record specifies the attributes for each file and folder in a specific folder like LBA, size, filename, and file flags.
Quote
If it is the first entry for the next folder (i.e., not an entry for an additional file or folder in the current folder), then its LBA field will equal the current LBA, because the first folder entry is always for ".", the current folder.
If you put those two together, then guess what? The directory entry for the current folder has its own size. So you can always know when you're done. The length entry for a folder is always 0x800 times the number of LBAs its directory record takes up.

A caltech grad explains that here: http://alumnus.caltech.edu/~pje/iso9660.html

I would never have figured that out.
« Last Edit: September 03, 2016, 06:59:02 pm by flame »