1 /* --------------------------------------------------------------------------
2 
3    MusicBrainz -- The Internet music metadatabase
4 
5    Copyright (C) 2009 Shunsuke Kuroda
6    Copyright (C) 2006 Matthias Friedrich
7    Copyright (C) 2000 Robert Kaye
8    Copyright (C) 1999 Marc E E van Woerkom
9 
10    This library is free software; you can redistribute it and/or
11    modify it under the terms of the GNU Lesser General Public
12    License as published by the Free Software Foundation; either
13    version 2.1 of the License, or (at your option) any later version.
14 
15    This library is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    Lesser General Public License for more details.
19 
20    You should have received a copy of the GNU Lesser General Public
21    License along with this library; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301  USA
24 
25 --------------------------------------------------------------------------- */
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <string.h>
29 #include <fcntl.h>
30 #include <assert.h>
31 #include <unistd.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <sys/ioctl.h>
35 #include <sys/cdio.h>
36 
37 
38 #include "discid/discid.h"
39 #include "discid/discid_private.h"
40 #include "unix.h"
41 
42 #define NUM_CANDIDATES 2
43 
44 static char *device_candidates[NUM_CANDIDATES] = {"/vol/dev/aliases/cdrom0",
45 					         "/volumes/dev/aliases/cdrom0"};
46 
mb_disc_unix_read_toc_header(int fd,mb_disc_toc * toc)47 int mb_disc_unix_read_toc_header(int fd, mb_disc_toc *toc) {
48 	struct cdrom_tochdr th;
49 
50 	int ret = ioctl(fd, CDROMREADTOCHDR, &th);
51 
52 	if ( ret < 0 )
53 		return ret; /* error */
54 
55 	toc->first_track_num = th.cdth_trk0;
56 	toc->last_track_num = th.cdth_trk1;
57 
58 	return ret;
59 }
60 
61 
mb_disc_unix_read_toc_entry(int fd,int track_num,mb_disc_toc_track * track)62 int mb_disc_unix_read_toc_entry(int fd, int track_num, mb_disc_toc_track *track) {
63 	struct cdrom_tocentry te;
64 	int ret;
65 
66 	memset(&te, 0, sizeof te);
67 	te.cdte_track = track_num;
68 	te.cdte_format = CDROM_LBA;
69 
70 	ret = ioctl(fd, CDROMREADTOCENTRY, &te);
71 
72 	if ( ret < 0 )
73 		return 0; /* error */
74 
75 	assert( te.cdte_format == CDROM_LBA );
76 	track->address = te.cdte_addr.lba;
77 	track->control = te.cdte_ctrl;
78 
79 	return 1;
80 }
81 
mb_disc_unix_read_mcn(int fd,mb_disc_private * disc)82 void mb_disc_unix_read_mcn(int fd, mb_disc_private *disc) {
83 	return;
84 }
85 
mb_disc_unix_read_isrc(int fd,mb_disc_private * disc,int track_num)86 void mb_disc_unix_read_isrc(int fd, mb_disc_private *disc, int track_num) {
87 	return;
88 }
89 
mb_disc_get_default_device_unportable(void)90 char *mb_disc_get_default_device_unportable(void) {
91 	return mb_disc_unix_find_device(device_candidates, NUM_CANDIDATES);
92 }
93 
mb_disc_has_feature_unportable(enum discid_feature feature)94 int mb_disc_has_feature_unportable(enum discid_feature feature) {
95 	switch(feature) {
96 		case DISCID_FEATURE_READ:
97 			return 1;
98 		default:
99 			return 0;
100 	}
101 }
102 
mb_disc_read_unportable(mb_disc_private * disc,const char * device,unsigned int features)103 int mb_disc_read_unportable(mb_disc_private *disc, const char *device,
104 			    unsigned int features) {
105 	return mb_disc_unix_read(disc, device, features);
106 }
107 
108 /* EOF */
109