1
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
4
* Copyright (C) Philippe Rouquier 2005-2009 <bonfire-app@wanadoo.fr>
6
* Libbrasero-media is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* The Libbrasero-media authors hereby grant permission for non-GPL compatible
12
* GStreamer plugins to be used and distributed together with GStreamer
13
* and Libbrasero-media. This permission is above and beyond the permissions granted
14
* by the GPL license by which Libbrasero-media is covered. If you modify this code
15
* you may extend this exception to your version of the code, but you are not
16
* obligated to do so. If you do not wish to do so, delete this exception
17
* statement from your version.
19
* Libbrasero-media is distributed in the hope that it will be useful,
20
* but WITHOUT ANY WARRANTY; without even the implied warranty of
21
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
* GNU Library General Public License for more details.
24
* You should have received a copy of the GNU General Public License
25
* along with this program; if not, write to:
26
* The Free Software Foundation, Inc.,
27
* 51 Franklin Street, Fifth Floor
28
* Boston, MA 02110-1301, USA.
37
#include "brasero-media-private.h"
39
#include "scsi-error.h"
40
#include "scsi-utils.h"
41
#include "scsi-base.h"
42
#include "scsi-command.h"
43
#include "scsi-opcodes.h"
44
#include "scsi-read-track-information.h"
46
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
48
struct _BraseroRdTrackInfoCDB {
51
uchar addr_num_type :2;
52
uchar open :1; /* MMC5 field only */
55
uchar blk_addr_trk_ses_num [4];
65
struct _BraseroRdTrackInfoCDB {
70
uchar addr_num_type :2;
72
uchar blk_addr_trk_ses_num [4];
82
typedef struct _BraseroRdTrackInfoCDB BraseroRdTrackInfoCDB;
84
BRASERO_SCSI_COMMAND_DEFINE (BraseroRdTrackInfoCDB,
85
READ_TRACK_INFORMATION,
89
BRASERO_FIELD_LBA = 0x00,
90
BRASERO_FIELD_TRACK_NUM = 0x01,
91
BRASERO_FIELD_SESSION_NUM = 0x02,
95
#define BRASERO_SCSI_INCOMPLETE_TRACK 0xFF
97
static BraseroScsiResult
98
brasero_read_track_info (BraseroRdTrackInfoCDB *cdb,
99
BraseroScsiTrackInfo *info,
101
BraseroScsiErrCode *error)
103
BraseroScsiTrackInfo hdr;
104
BraseroScsiResult res;
107
if (!info || !size) {
108
BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_BAD_ARGUMENT);
109
return BRASERO_SCSI_FAILURE;
112
/* first ask the drive how long should the data be and then ... */
114
memset (&hdr, 0, sizeof (info));
115
BRASERO_SET_16 (cdb->alloc_len, datasize);
116
res = brasero_scsi_command_issue_sync (cdb, &hdr, datasize, error);
120
/* ... check the size in case of a buggy firmware ... */
121
if (BRASERO_GET_16 (hdr.len) + sizeof (hdr.len) >= datasize) {
122
datasize = BRASERO_GET_16 (hdr.len) + sizeof (hdr.len);
124
if (datasize > *size) {
125
/* it must not be over sizeof (BraseroScsiTrackInfo) */
126
if (datasize > sizeof (BraseroScsiTrackInfo)) {
127
BRASERO_MEDIA_LOG ("Oversized data received (%i) setting to %i", datasize, *size);
133
else if (*size < datasize) {
134
BRASERO_MEDIA_LOG ("Oversized data required (%i) setting to %i", *size, datasize);
139
BRASERO_MEDIA_LOG ("Undersized data received (%i) setting to %i", datasize, *size);
143
/* ... and re-issue the command */
144
memset (info, 0, sizeof (BraseroScsiTrackInfo));
145
BRASERO_SET_16 (cdb->alloc_len, datasize);
146
res = brasero_scsi_command_issue_sync (cdb, info, datasize, error);
147
if (res == BRASERO_SCSI_OK) {
148
if (datasize != BRASERO_GET_16 (info->len) + sizeof (info->len))
149
BRASERO_MEDIA_LOG ("Sizes mismatch asked %i / received %i",
151
BRASERO_GET_16 (info->len) + sizeof (info->len));
153
*size = MIN (datasize, BRASERO_GET_16 (info->len) + sizeof (info->len));
161
* NOTE: if media is a CD and track_num = 0 then returns leadin
162
* but since the other media don't have a leadin they error out.
163
* if track_num = 255 returns last incomplete track.
167
brasero_mmc1_read_track_info (BraseroDeviceHandle *handle,
169
BraseroScsiTrackInfo *track_info,
171
BraseroScsiErrCode *error)
173
BraseroRdTrackInfoCDB *cdb;
174
BraseroScsiResult res;
176
cdb = brasero_scsi_command_new (&info, handle);
177
cdb->addr_num_type = BRASERO_FIELD_TRACK_NUM;
178
BRASERO_SET_32 (cdb->blk_addr_trk_ses_num, track_num);
180
res = brasero_read_track_info (cdb, track_info, size, error);
181
brasero_scsi_command_free (cdb);