2003-03-24 19:01:09 +00:00
|
|
|
|
/*
|
2004-06-05 02:49:21 +00:00
|
|
|
|
$Id: sector.c,v 1.10 2004/06/05 02:49:21 rocky Exp $
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-11 12:17:17 +00:00
|
|
|
|
Copyright (C) 2004 Rocky Bernstein <rocky@panix.com>
|
2003-03-24 19:01:09 +00:00
|
|
|
|
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
|
|
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
|
# include "config.h"
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
2003-04-22 12:09:08 +00:00
|
|
|
|
#include <cdio/sector.h>
|
|
|
|
|
|
#include <cdio/util.h>
|
2004-05-19 03:00:03 +00:00
|
|
|
|
#include <cdio/logging.h>
|
2003-03-24 19:01:09 +00:00
|
|
|
|
#include "cdio_assert.h"
|
|
|
|
|
|
|
2003-09-11 02:50:06 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2004-06-05 02:49:21 +00:00
|
|
|
|
static const char _rcsid[] = "$Id: sector.c,v 1.10 2004/06/05 02:49:21 rocky Exp $";
|
2003-09-11 02:50:06 +00:00
|
|
|
|
|
|
|
|
|
|
lba_t
|
|
|
|
|
|
cdio_lba_to_lsn (lba_t lba)
|
|
|
|
|
|
{
|
2004-05-09 16:53:01 +00:00
|
|
|
|
if (CDIO_INVALID_LBA == lba) return CDIO_INVALID_LSN;
|
2003-09-11 02:50:06 +00:00
|
|
|
|
return lba - CDIO_PREGAP_SECTORS;
|
|
|
|
|
|
}
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
2004-05-11 02:15:42 +00:00
|
|
|
|
/*
|
|
|
|
|
|
The below is adapted from cdparanoia code which claims it is
|
|
|
|
|
|
straight from the MMC3 spec.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
void
|
2004-05-11 02:15:42 +00:00
|
|
|
|
cdio_lsn_to_msf (lsn_t lsn, msf_t *msf)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
2004-05-11 02:15:42 +00:00
|
|
|
|
int m, s, f;
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
cdio_assert (msf != 0);
|
|
|
|
|
|
|
2004-05-11 02:15:42 +00:00
|
|
|
|
if ( lsn >= -CDIO_PREGAP_SECTORS ){
|
|
|
|
|
|
m = (lsn + CDIO_PREGAP_SECTORS) / CDIO_CD_FRAMES_PER_MIN;
|
|
|
|
|
|
lsn -= m * CDIO_CD_FRAMES_PER_MIN;
|
|
|
|
|
|
s = (lsn + CDIO_PREGAP_SECTORS) / CDIO_CD_FRAMES_PER_SEC;
|
|
|
|
|
|
lsn -= s * CDIO_CD_FRAMES_PER_SEC;
|
|
|
|
|
|
f = lsn + CDIO_PREGAP_SECTORS;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
m = (lsn + CDIO_CD_MAX_LSN) / CDIO_CD_FRAMES_PER_MIN;
|
|
|
|
|
|
lsn -= m * (CDIO_CD_FRAMES_PER_MIN);
|
|
|
|
|
|
s = (lsn+CDIO_CD_MAX_LSN) / CDIO_CD_FRAMES_PER_SEC;
|
|
|
|
|
|
lsn -= s * CDIO_CD_FRAMES_PER_SEC;
|
|
|
|
|
|
f = lsn + CDIO_CD_MAX_LSN;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-19 03:00:03 +00:00
|
|
|
|
if (m > 99) {
|
|
|
|
|
|
cdio_warn ("number of minutes (%d) truncated to 99.", m);
|
|
|
|
|
|
m = 99;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-11 02:15:42 +00:00
|
|
|
|
msf->m = to_bcd8 (m);
|
|
|
|
|
|
msf->s = to_bcd8 (s);
|
|
|
|
|
|
msf->f = to_bcd8 (f);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-09-11 02:50:06 +00:00
|
|
|
|
/* warning, returns new allocated string */
|
|
|
|
|
|
char *
|
|
|
|
|
|
cdio_lba_to_msf_str (lba_t lba)
|
2003-04-11 17:33:03 +00:00
|
|
|
|
{
|
2003-09-11 02:50:06 +00:00
|
|
|
|
|
2004-05-09 16:53:01 +00:00
|
|
|
|
if (CDIO_INVALID_LBA == lba) {
|
|
|
|
|
|
return strdup("*INVALID");
|
|
|
|
|
|
} else {
|
|
|
|
|
|
msf_t msf = { .m = 0, .s = 0, .f = 0 };
|
|
|
|
|
|
cdio_lba_to_msf (lba, &msf);
|
|
|
|
|
|
return cdio_msf_to_str(&msf);
|
|
|
|
|
|
}
|
2003-04-11 17:33:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lba_t
|
|
|
|
|
|
cdio_lsn_to_lba (lsn_t lsn)
|
|
|
|
|
|
{
|
2004-05-07 10:59:12 +00:00
|
|
|
|
if (CDIO_INVALID_LSN == lsn) return CDIO_INVALID_LBA;
|
2003-04-11 17:33:03 +00:00
|
|
|
|
return lsn + CDIO_PREGAP_SECTORS;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
void
|
2004-05-11 02:15:42 +00:00
|
|
|
|
cdio_lba_to_msf (lba_t lba, msf_t *msf)
|
2003-03-24 19:01:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
cdio_assert (msf != 0);
|
2004-05-11 02:15:42 +00:00
|
|
|
|
cdio_lsn_to_msf(cdio_lba_to_lsn(lba), msf);
|
2003-03-24 19:01:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-11 02:15:42 +00:00
|
|
|
|
lba_t
|
2003-03-24 19:01:09 +00:00
|
|
|
|
cdio_msf_to_lba (const msf_t *msf)
|
|
|
|
|
|
{
|
|
|
|
|
|
uint32_t lba = 0;
|
|
|
|
|
|
|
|
|
|
|
|
cdio_assert (msf != 0);
|
|
|
|
|
|
|
|
|
|
|
|
lba = from_bcd8 (msf->m);
|
2004-05-11 02:15:42 +00:00
|
|
|
|
lba *= CDIO_CD_SECS_PER_MIN;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
lba += from_bcd8 (msf->s);
|
2004-05-11 02:15:42 +00:00
|
|
|
|
lba *= CDIO_CD_FRAMES_PER_SEC;
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
lba += from_bcd8 (msf->f);
|
|
|
|
|
|
|
|
|
|
|
|
return lba;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-11 02:15:42 +00:00
|
|
|
|
lba_t
|
2003-03-24 19:01:09 +00:00
|
|
|
|
cdio_msf_to_lsn (const msf_t *msf)
|
|
|
|
|
|
{
|
|
|
|
|
|
return cdio_lba_to_lsn(cdio_msf_to_lba (msf));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2004-05-09 16:53:01 +00:00
|
|
|
|
/* warning, returns new allocated string */
|
|
|
|
|
|
char *
|
|
|
|
|
|
cdio_msf_to_str (const msf_t *msf)
|
|
|
|
|
|
{
|
|
|
|
|
|
char buf[16];
|
|
|
|
|
|
|
2004-06-05 02:49:21 +00:00
|
|
|
|
snprintf (buf, sizeof (buf), "%.2x:%.2x.%.2x", msf->m, msf->s, msf->f);
|
2004-05-09 16:53:01 +00:00
|
|
|
|
return strdup (buf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2003-03-24 19:01:09 +00:00
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* Local variables:
|
|
|
|
|
|
* c-file-style: "gnu"
|
|
|
|
|
|
* tab-width: 8
|
|
|
|
|
|
* indent-tabs-mode: nil
|
|
|
|
|
|
* End:
|
|
|
|
|
|
*/
|