libcdio-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Libcdio-devel] lsn versus lba versus msf


From: Robert William Fuller
Subject: Re: [Libcdio-devel] lsn versus lba versus msf
Date: Mon, 19 Nov 2012 16:13:57 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.10) Gecko/20121027 Icedove/10.0.10

On 11/19/2012 03:38 PM, Rocky Bernstein wrote:
libcdio was developed far before libcddb so it probably got the mistake
from libcdio. For libcdio's confusion, you probably have to go back to
vcdimager.

I was hoping for a conspiracy.  That would have been cooler :-)

But my recollection was that LBA referred to one of two things, I think
FreeBSD was different than other places, but I'm not sure and would have to
dig down and we had to pick one.

I see another reason that it might be this way. The primary (ab)users of lba are the cdrdao, nrg, and bin/cue drivers. I suspect negative offsets don't work so well with image files.

I ended up with some code in my ripper which is pretty ugly because I misunderstood LBA vs LSN vs MSF. I fixed it by some ugly hack that I commented like this:

    // intentionally call qsc_lba_to_ascii with an lsn

So, my code does the right thing, but it took me half a day to figure out how and why (I wrote it in 2008 and did not leave myself good documentation.) In the interest of helping future hackers, it seems like we should somehow fix this.

But that was then and this is now. If someone has a suggestion and and
there is consensus on it, things can change.

I am unsure how to move forward with this without breaking interfaces, but I am thinking about it. Maybe breaking some interfaces is okay? (In particular the ones with lba in the name. As it turns out, there aren't that many.)

Rob

On Mon, Nov 19, 2012 at 3:31 PM, Robert William Fuller<
address@hidden>  wrote:

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







reply via email to

[Prev in Thread] Current Thread [Next in Thread]