File: interface.c

package info (click to toggle)
libcdio-paranoia 10.2%2B2.0.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 9,604 kB
  • sloc: ansic: 8,127; makefile: 289; sh: 269; cpp: 160; perl: 32; ruby: 25
file content (208 lines) | stat: -rw-r--r-- 4,976 bytes parent folder | download | duplicates (5)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
/*
  Copyright (C) 2005, 2008 Rocky Bernstein <rocky@gnu.org>
  Copyright (C) 2014 Robert Kausch <robert.kausch@freac.org>
  Copyright (C) 1998 Monty xiphmont@mit.edu

  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 3 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, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************
 * Top-level interface module for cdrom drive access.  SCSI, ATAPI, etc
 *    specific stuff are in other modules.  Note that SCSI does use
 *    specialized ioctls; these appear in common_interface.c where the
 *    generic_scsi stuff is in scsi_interface.c.
 *
 ******************************************************************/

#include "common_interface.h"
#include "low_interface.h"
#include "utils.h"
#include <cdio/bytesex.h>
#include <cdio/mmc.h>
#include <cdio/paranoia/version.h>

extern const char *cdio_cddap_version(void){
  return LIBCDIO_PARANOIA_VERSION;
}

static void _clean_messages(cdrom_drive_t *d)
{
  if(d){
    if(d->messagebuf)free(d->messagebuf);
    if(d->errorbuf)free(d->errorbuf);
    d->messagebuf=NULL;
    d->errorbuf=NULL;
  }
}

/*!
  Closes d and releases all storage associated with it except
  the internal p_cdio pointer.

  @param d cdrom_drive_t object to be closed.
  @return 0 if passed a null pointer and 1 if not in which case
  some work was probably done.

  @see cdio_cddap_close
*/
bool
cdio_cddap_close_no_free_cdio(cdrom_drive_t *d)
{
  if(d){
    if(d->opened)
      d->enable_cdda(d,0);

    _clean_messages(d);
    if (d->cdda_device_name) free(d->cdda_device_name);
    if (d->drive_model)      free(d->drive_model);
    d->cdda_device_name = d->drive_model = NULL;
    free(d);
    return true;
  }
  return false;
}

/*!
  Closes d and releases all storage associated with it.
  Doubles as "cdrom_drive_free()".

  @param d cdrom_drive_t object to be closed.
  @return 0 if passed a null pointer and 1 if not in which case
  some work was probably done.

  @see cdio_cddap_close_no_free_cdio
*/
int
cdio_cddap_close(cdrom_drive_t *d)
{
  if (d) {
    CdIo_t *p_cdio = d->p_cdio;
    cdio_cddap_close_no_free_cdio(d);
    cdio_destroy (p_cdio);
    return 1;
  }
  return 0;
}

/* finish initializing the drive! */
int
cdio_cddap_open(cdrom_drive_t *d)
{
  int ret;
  if(d->opened)return(0);

  if ( (ret=cddap_init_drive(d)) )
    return(ret);

  /* Check TOC, enable for CDDA */

  /* Some drives happily return a TOC even if there is no disc... */
  {
    int i;
    for(i=0; i<d->tracks; i++)
      if(d->disc_toc[i].dwStartSector<0 ||
	 d->disc_toc[i+1].dwStartSector==0){
	d->opened=0;
	cderror(d,"009: CDROM reporting illegal table of contents\n");
	return(-9);
      }
  }

  if((ret=d->enable_cdda(d,1)))
    return(ret);

  /*  d->select_speed(d,d->maxspeed); most drives are full speed by default */

  if ( -1 == d->bigendianp ) {
    d->bigendianp = data_bigendianp(d);
  }


  return(0);
}

int
cdio_cddap_speed_set(cdrom_drive_t *d, int speed)
{
  if(d->set_speed)
    if(!d->set_speed(d, speed))return 0;

  cderror(d,"405: Option not supported by drive\n");
  return -405;
}

long
cdio_cddap_read_timed(cdrom_drive_t *d, void *buffer, lsn_t beginsector,
		long sectors, int *ms)
{
  if(ms)*ms= -1;
  if (d->opened) {
    if (sectors>0) {
      sectors=d->read_audio(d, buffer, beginsector, sectors);

      if (sectors > 0) {
	/* byteswap? */
	if ( d->bigendianp == -1 ) /* not determined yet */
	  d->bigendianp = data_bigendianp(d);

	if ( buffer && d->b_swap_bytes && d->bigendianp != bigendianp() ) {
	  int i;
	  uint16_t *p=(uint16_t *)buffer;
	  long els=sectors*CDIO_CD_FRAMESIZE_RAW/2;

	  for(i=0;i<els;i++)
	    p[i]=UINT16_SWAP_LE_BE_C(p[i]);
	}
      }
    }
    if(ms)*ms=d->last_milliseconds;
    return(sectors);
  }

  cderror(d,"400: Device not open\n");
  return(-400);
}

long cdio_cddap_read(cdrom_drive_t *d, void *buffer, lsn_t beginsector, long sectors){
  return cdda_read_timed(d,buffer,beginsector,sectors,NULL);
}

void
cdio_cddap_verbose_set(cdrom_drive_t *d,int err_action, int mes_action)
{
  d->messagedest=mes_action;
  d->errordest=err_action;
}

extern char *
cdio_cddap_messages(cdrom_drive_t *d)
{
  char *ret=d->messagebuf;
  d->messagebuf=NULL;
  return(ret);
}

extern char *
cdio_cddap_errors(cdrom_drive_t *d)
{
  char *ret=d->errorbuf;
  d->errorbuf=NULL;
  return(ret);
}

extern void
cdio_cddap_free_messages(char *psz_messages)
{
  if (psz_messages != NULL)
    free(psz_messages);
}