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-base.h"
41
#include "scsi-command.h"
42
#include "scsi-opcodes.h"
43
#include "scsi-read-disc-structure.h"
45
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
47
struct _BraseroReadDiscStructureCDB {
53
/* for formats 0x83 */
63
/* for formats 0x02, 0x06, 0x07, 0x80, 0x82 */
71
struct _BraseroReadDiscStructureCDB {
92
typedef struct _BraseroReadDiscStructureCDB BraseroReadDiscStructureCDB;
94
BRASERO_SCSI_COMMAND_DEFINE (BraseroReadDiscStructureCDB,
99
BRASERO_MEDIA_DVD_HD_DVD = 0x00,
100
BRASERO_MEDIA_BD = 0x01
102
} BraseroScsiMediaType;
104
static BraseroScsiResult
105
brasero_read_disc_structure (BraseroReadDiscStructureCDB *cdb,
106
BraseroScsiReadDiscStructureHdr **data,
108
BraseroScsiErrCode *error)
110
BraseroScsiReadDiscStructureHdr *buffer;
111
BraseroScsiReadDiscStructureHdr hdr;
112
BraseroScsiResult res;
115
if (!data || !size) {
116
BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_BAD_ARGUMENT);
117
return BRASERO_SCSI_FAILURE;
120
BRASERO_SET_16 (cdb->alloc_len, sizeof (hdr));
122
memset (&hdr, 0, sizeof (hdr));
123
res = brasero_scsi_command_issue_sync (cdb, &hdr, sizeof (hdr), error);
127
request_size = BRASERO_GET_16 (hdr.len) + sizeof (hdr.len);
128
buffer = (BraseroScsiReadDiscStructureHdr *) g_new0 (uchar, request_size);
130
BRASERO_SET_16 (cdb->alloc_len, request_size);
131
res = brasero_scsi_command_issue_sync (cdb, buffer, request_size, error);
137
if (request_size < BRASERO_GET_16 (buffer->len) + sizeof (buffer->len)) {
138
BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_SIZE_MISMATCH);
140
return BRASERO_SCSI_FAILURE;
144
*size = request_size;
150
brasero_mmc2_read_generic_structure (BraseroDeviceHandle *handle,
151
BraseroScsiGenericFormatType type,
152
BraseroScsiReadDiscStructureHdr **data,
154
BraseroScsiErrCode *error)
156
BraseroReadDiscStructureCDB *cdb;
157
BraseroScsiResult res;
159
cdb = brasero_scsi_command_new (&info, handle);
162
res = brasero_read_disc_structure (cdb, data, size, error);
163
brasero_scsi_command_free (cdb);
168
brasero_mmc2_read_dvd_structure (BraseroDeviceHandle *handle,
170
BraseroScsiDVDFormatType type,
171
BraseroScsiReadDiscStructureHdr **data,
173
BraseroScsiErrCode *error)
175
BraseroReadDiscStructureCDB *cdb;
176
BraseroScsiResult res;
178
cdb = brasero_scsi_command_new (&info, handle);
180
cdb->media_type = BRASERO_MEDIA_DVD_HD_DVD;
181
BRASERO_SET_32 (cdb->address, address);
183
res = brasero_read_disc_structure (cdb, data, size, error);
184
brasero_scsi_command_free (cdb);
189
brasero_mmc5_read_bd_structure (BraseroDeviceHandle *handle,
190
BraseroScsiBDFormatType type,
191
BraseroScsiReadDiscStructureHdr **data,
193
BraseroScsiErrCode *error)
195
BraseroReadDiscStructureCDB *cdb;
196
BraseroScsiResult res;
198
cdb = brasero_scsi_command_new (&info, handle);
200
cdb->media_type = BRASERO_MEDIA_BD;
202
res = brasero_read_disc_structure (cdb, data, size, error);
203
brasero_scsi_command_free (cdb);