Dear All,
I have problem with working cdrom programming. I can get cdrom (cd audio) data toc but I can’t get the track raw data. I using devctl to access the cdrom. Detail below is my code.
int main(int argc, char** argv)
{
struct _cdrom_read_toc cdtoc;
strcut _cdrom_raw_data rawdata;
int error, fd;
if(fd = open("/dev/cd0", O_RDONLY)== -1)
{
fprintf(stderr,"Error with open device file: %s\n", strerror(errno));
exit(-1);
}
if(error = devctl(fd, DCMD_CAM_CDROMREADTOC, &cdtoc, sizeof(cdtoc), NULL))
{
fprintf(stderr,"Get cd toc failure: %s\n", strerror(error));
exit(-1);
}
rawdata.lba = 0;
rawdata.nsectors = 14494; //the second track start at 3:13:19
rawdata.mode = CDDA;
if(error = devctl(fd, CDMD_CAM_CDROMREAD, &rawdata, sizeof(rawdata), NULL))
{
fprintf(stderr,"Get cd raw data failure: %s\n", strerror(error));
exit(-1);
}
.......
......
}
The output srceen show:
Get cd raw data failure: Invalid argument
Or I use read function to get data but the result still the same
…
char buf[2352];
int addr;
…
//after get cd toc
addr = 150; // The frist track start at 0:2:0
lseek(fd, addr * 2352, SEEK_SET);
error = read(fd, buf, sizeof(buf));
if(error != 2352)
{
fprintf(stderr,“Reading cd raw data failure: %s\n”, strerror(errno));
exit(-1);
}
…
Output show:
Reading cd raw data failure: Invalid argument
I don’t what worng in here. Please help me solve this problem. Thank you very much.
Can I using ioctl in here? I have searched long time on internet but don’t have guide for this issue. ioctl only using on Linux version right?
Please help me. Thank you.
James