Skip to content

cdrdao: fix DATAFILE lengths, data file paths and sub-channel images - #108

Open
nicosp wants to merge 5 commits into
libcdio:mainfrom
nicosp:cdrdao-fixes
Open

nicosp wants to merge 5 commits into
libcdio:mainfrom
nicosp:cdrdao-fixes

Conversation

@nicosp

@nicosp nicosp commented Oct 22, 2026

Copy link
Copy Markdown

Problem

The cdrdao driver misreads common TOCs:

  • The DATAFILE length is read as a start position. The test suite's cdda.toc and vcd2.toc open with negative track LSNs and a wrong lead-out.
  • Data files are opened relative to the current directory instead of the TOC.
  • Every audio read uses the first data file at lsn * 2352, ignoring each track's file, byte offset and block size.
  • The RW and RW_RAW sub-channel modes are ignored, so images read with cdrdao read-cd --read-subchan return misaligned audio.

Changes

  • Read the DATAFILE MSF as the track length.
  • Open data files relative to the TOC, as bincue does.
  • Read each track's audio from its own file, offset and block size.
  • Add 96 bytes per sector for RW/RW_RAW, and reject unknown sub-channel modes.
  • Add a test with a small synthetic RW_RAW image, opened from outside its directory, that checks track positions and audio. Also add cdda.toc to check_DATA, since a test already reads it.

Testing

  • make check passes at each commit.
  • On a 55-track enhanced CD read with cdrdao read-cd --read-raw --read-subchan rw_raw, the image now opens with the correct track positions and audio.

Returning the stored sub-channel data is a separate draft, #106, since it needs MMC commands on images.

🤖 Generated with Claude Code

nicosp and others added 5 commits October 22, 2026 21:52
FILE, AUDIOFILE and DATAFILE names were opened relative to the
current directory, although the path relative to the TOC file's
directory was already computed and stored as the track's filename.
TOC files only opened when the program ran from the TOC file's
directory, which is how the cdrdao driver test runs.

Open the computed path, as the bincue driver does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cdrdao's TOC format is DATAFILE "<filename>" [#byte-offset] [<length>]
(see cdrdao(1)), and cdrdao read-cd and read-toc write the length of
each track there. The parser took it as the track's start instead, so
every track started at its own length; test/data/cdda.toc and vcd2.toc
opened with negative LSNs:

  cdda.toc   before: track 1 LSN -125, lead-out 177
             after:  track 1 LSN 0, lead-out 25
  vcd2.toc   before: tracks at LSN -150, -147, -125, lead-out 177
             after:  tracks at LSN 0, 302, 305, lead-out 330

Store the length as the track's sector count and start each track
where the previous one ends: after its length, or after the rest of
its data file when no length is given. That fallback used to add the
150 sector lead-in pregap on every track, and dropped any byte offset.

Keep the LBA of the sector at the track's byte offset in data_lba, as
START moves start_lba past the pregap, and leave unknown lengths at 0
on START instead of making them negative.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Audio sectors were read from the first track's data file at
lsn * 2352, ignoring each track's file, byte offset and block size.
That only works for a single file that starts at the first sector.

For DATAFILE tracks, find the track holding each sector and read it
from that track's file, at its byte offset plus the sector's position
times the block size. FILE and AUDIOFILE tracks are read as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
TRACK <track-mode> [<sub-channel-mode>] was parsed, but the
sub-channel mode was ignored. With RW or RW_RAW, 96 bytes of
sub-channel data follow each sector in the data file (see cdrdao(1)),
as written by cdrdao read-cd --read-subchan rw or rw_raw. Their
sectors were read 2352 bytes apart instead of 2448, so all audio
after the first sector was misaligned.

Record the mode and add the sub-channel data to the track's block
size. Reject unknown sub-channel modes, as is done for track modes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cdda-rw-raw.toc describes two audio tracks with raw P-W sub-channel
data after each sector, as cdrdao read-cd --read-subchan rw_raw writes
them: one data file with a byte offset and a length for each track,
and a two sector START pregap in track 2.

Open it from outside its directory and check the track positions and
that audio reads leave out the sub-channel data.

Add cdda.toc to check_DATA, as the test already reads it, and skip the
new audio-only image in check_fuzzyiso.sh like cdda.bin.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@nicosp

nicosp commented Oct 22, 2026

Copy link
Copy Markdown
Author

This is split out of #106: the first four commits of that PR, without the emulated READ CD. It's here in case MMC commands on images aren't wanted, so the TOC parsing and audio read fixes can still go in. If #106 is accepted as is, this one can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant