1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
|
/* --------------------------------------------------------------------------
MusicBrainz -- The Internet music metadatabase
Copyright (C) 2000 Robert Kaye
Copyright (C) 1999 Marc E E van Woerkom
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
$Id: mb_darwin.cpp,v 1.2 2003/04/01 02:31:35 robert Exp $
----------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <assert.h>
#include <IOKit/storage/IOCDTypes.h>
#include <IOKit/storage/IOCDMediaBSDClient.h>
#include "mb.h"
#include "diskid.h"
#include "config.h"
MUSICBRAINZ_DEVICE DEFAULT_DEVICE = "/dev/rdisk1";
bool DiskId::ReadTOC(MUSICBRAINZ_DEVICE device,
MUSICBRAINZ_CDINFO& cdinfo)
{
int fd;
int i;
dk_cd_read_toc_t toc;
CDTOC *cdToc;
if (device == NULL)
{
device = DEFAULT_DEVICE;
}
fd = open(device, O_RDONLY | O_NONBLOCK);
if (fd < 0)
{
char err[256];
sprintf(err, "Cannot open '%s'", device);
ReportError(err);
return false;
}
memset(&toc, 0, sizeof(toc));
toc.format = kCDTOCFormatTOC;
toc.formatAsTime = 0;
toc.buffer = new char[1024];
toc.bufferLength = 1024;
if (ioctl(fd, DKIOCCDREADTOC, &toc) < 0 )
{
delete [] (char *)toc.buffer;
return false;
}
if ( toc.bufferLength < sizeof(CDTOC) )
{
delete [] (char *)toc.buffer;
return false;
}
cdToc = (CDTOC *)toc.buffer;
int numTracks = CDTOCGetDescriptorCount(cdToc);
for(i = 3; i < numTracks; i++)
cdinfo.FrameOffset[i-2] = CDConvertMSFToLBA(cdToc->descriptors[i].p) + 150;
cdinfo.FrameOffset[0] = CDConvertMSFToLBA(cdToc->descriptors[2].p) + 150;
cdinfo.FirstTrack = 1;
cdinfo.LastTrack = numTracks - 3;
close(fd);
delete [] (char *)toc.buffer;
return true;
}
|