How can I read a directory on iso9660 from the path table when the table does not include size?

739 views Asked by At

According to the spec for the structure of an iso9660 / ecma119, the path table contains records for each path, including the location of the starting sector and its name, but not its size. I can find the directory entry, but don't know how many sectors (normally 2048 bytes) it contains. Is it one? Two? Six?

If I "walk the directory tree", each directory entry includes the referenced location and size, so I can know how many bytes (essentially, how many sectors, since a directory must use entire sectors) to read. However, the path table only includes the starting location, and not the size, leaving me not knowing how many bytes to read.

In an example iso I have (ubuntu-18.04.1-live-server-amd64.iso fwiw), the root directory entry in the primary volume descriptor shows:

         Root Directory:
      Directory Record Length: 34
    Extended Attribute Length: 0
           Location of Extent: 20  $00000014  00:00:20
                  Data Length: 2048  $00000800
      Recording Date and Time: 23:39:04 07/25/2018  GMT 0
                   File Flags: $02   visible regular dir non-record no-perms single-extent
               File Unit Size: 0
          Interleave Gap Size: 0
       Volume Sequence Number: 1
              File Identifier: .   (current directory)

Since it says the Data Length is 2048, I know to read just one sector.

However, the root directory entry in the path table shows:

       Path Record Length: 10  $0A
Extended Attribute Length: 0  $00
       Location of Extent: 20  $00000014  00:00:20
  Parent Directory Number: 1  $0001
          File Identifier: .   (current directory)

It also points to sector 20, but doesn't tell me how many sectors it uses, leaving me guessing.

Yes, unused bytes in a sector should be all 0x00, so if I read in a sector, read records, and then come to one whose first byte (length) is 0x00, then I know I have reached the end of records, but that has three issues:

  1. If that were the canonical way, why bother including size in the directory entry?
  2. If it includes 2 or 3 sectors, it is more efficient for me to read them all at once than one at a time.
  3. If I have a directory whose records precisely fill a sector, without some size attribute, I don't know if the next sector is supposed to be read as an entry, or if the directory ended here.

Basically, I know how to read the ordered path table to get the directory entry, but don't know how to use that to know how many sectors to read for the directory itself. I could, in theory, read the parent to get the entry for this directory to know the size, but that adds a seek and read and pretty much defeats the purpose of the path table.

1

There are 1 answers

0
deitch On BEST ANSWER

Ah, I figured it out. Because the directory entries always start with a directory entry for the directory itself, and the data length always is bytes 10-17 (10-13 for little-endian, 13-17 for big-endian), you can just read bytes 10-17 from the beginning of the sector and get the size. Still not as efficient as putting it in the path table itself - no idea why they did not - but it works.