Merge branch 'master' into 'master'
[brasero.git] / libbrasero-media / scsi-read10.c
blobbd5d79d5aaf3993531521b1fb07e5329d3514417
1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
2 /*
3 * Libbrasero-media
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.
31 #ifdef HAVE_CONFIG_H
32 # include <config.h>
33 #endif
35 #include <glib.h>
37 #include "scsi-sbc.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"
45 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
47 struct _BraseroRead10CDB {
48 uchar opcode;
50 uchar reladr :1;
51 uchar reserved1 :2;
52 uchar FUA :1;
53 uchar DPO :1;
54 uchar reserved2 :3;
56 uchar start_address [4];
58 uchar reserved3;
60 uchar len [2];
62 uchar ctl;
65 #else
67 struct _BraseroRead10CDB {
68 uchar opcode;
70 uchar reserved2 :3;
71 uchar DPO :1;
72 uchar FUA :1;
73 uchar reserved1 :2;
74 uchar reladr :1;
76 uchar start_address [4];
78 uchar reserved3;
80 uchar len [2];
82 uchar ctl;
85 #endif
87 typedef struct _BraseroRead10CDB BraseroRead10CDB;
89 BRASERO_SCSI_COMMAND_DEFINE (BraseroRead10CDB,
90 READ10,
91 BRASERO_SCSI_READ);
93 BraseroScsiResult
94 brasero_sbc_read10_block (BraseroDeviceHandle *handle,
95 int start,
96 int num_blocks,
97 unsigned char *buffer,
98 int buffer_size,
99 BraseroScsiErrCode *error)
101 BraseroRead10CDB *cdb;
102 BraseroScsiResult res;
104 g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
106 cdb = brasero_scsi_command_new (&info, handle);
107 BRASERO_SET_32 (cdb->start_address, start);
109 /* NOTE: if we just want to test if block is readable len can be 0 */
110 BRASERO_SET_16 (cdb->len, num_blocks);
112 /* reladr should be 0 */
113 /* DPO should be 0 */
115 /* This is to force reading media ==> no caching (set to 1) */
116 /* On the other hand caching improves dramatically the performances. */
117 cdb->FUA = 0;
119 memset (buffer, 0, buffer_size);
120 res = brasero_scsi_command_issue_sync (cdb,
121 buffer,
122 buffer_size,
123 error);
124 brasero_scsi_command_free (cdb);
125 return res;