There is a problem with the libcdio documentation in the section titled,
"6.2 block addressing (MSF, LSN, LBA)". This is accessible on the web at
http://www.gnu.org/software/**libcdio/libcdio.html#Sectors<http://www.gnu.org/software/libcdio/libcdio.html#Sectors>
.
The last part of the section says, "So to convert a LBA into an LSN you
just add 150." To begin with, this is backwards. The code looks like this:
#define CDIO_PREGAP_SECTORS 150
lba_t
cdio_lba_to_lsn (lba_t lba)
{
if (CDIO_INVALID_LBA == lba) return CDIO_INVALID_LSN;
return lba - CDIO_PREGAP_SECTORS;
}
Clearly, to convert from LBA to LSN you subtract 150, not add 150.
Alright, so that is relatively minor.
The thing I've struggled with the most over time is that what libcdio
calls LSN is what the MMC spec calls LBA. You can see this most clearly in
the function cdio_lsn_to_msf. That function follows the precise formula in
MMC-3 Draft Revision 10g on page 282 for converting from MMC's LBA to MSF.
But, note that the function is called cdio_lsn_to_msf because what libcdio
calls an LSN is an LBA in the MMC spec.
You can also see this in the MMC commands themselves. Although they take
LSN parameters, there is no conversion from LSN to LBA, even though MMC
itself expects LBA. Note that macros such as CDIO_MMC_SET_READ_LBA are
passed unmodified LSNs. Again, that is because what libcdio calls an LSN
is what MMC calls an LBA.
So what is my point? This is confusing to people developing applications.
libcdio's LSN is really MMC's LBA. What libcdio calls LBA is not what MMC
calls LBA. libcdio's LBA is basically a non-negative version of MMC's LBA
(because the program area starts at MMC LBA = -150 and libcdio_LBA =
MMC_LBA + 150.)
Now curiously enough, libcdio is not the only library suffering from this
delusion. Take libcddb. It calls things LBAs, but expects what libcdio
calls an LBA rather than what MMC calls an LBA. You can see this in sample
code where cdio_get_track_lba is used to call cddb_track_set_frame_offset.
It almost seems like a conspiracy.
Is there a way out of the madness? Or do we just need better
documentation?
Rob