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>
5  *
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.
10  *
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.
18  *
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.
23  *
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.
29  */
30 
31 #ifdef HAVE_CONFIG_H
32 #  include <config.h>
33 #endif
34 
35 #include "scsi-spc1.h"
36 
37 #include "scsi-error.h"
38 #include "scsi-utils.h"
39 #include "scsi-base.h"
40 #include "scsi-command.h"
41 #include "scsi-opcodes.h"
42 #include "scsi-inquiry.h"
43 
44 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
45 
46 struct _BraseroInquiryCDB {
47 	uchar opcode;
48 
49 	uchar evpd			:1;
50 	uchar cmd_dt			:1;
51 	uchar reserved0		:6;
52 
53 	uchar op_code;
54 
55 	uchar reserved1;
56 
57 	uchar alloc_len;
58 
59 	uchar ctl;
60 };
61 
62 #else
63 
64 struct _BraseroInquiryCDB {
65 	uchar opcode;
66 
67 	uchar reserved0		:6;
68 	uchar cmd_dt			:1;
69 	uchar evpd			:1;
70 
71 	uchar op_code;
72 
73 	uchar reserved1;
74 
75 	uchar alloc_len;
76 
77 	uchar ctl;
78 };
79 
80 #endif
81 
82 typedef struct _BraseroInquiryCDB BraseroInquiryCDB;
83 
84 BRASERO_SCSI_COMMAND_DEFINE (BraseroInquiryCDB,
85 			     INQUIRY,
86 			     BRASERO_SCSI_READ);
87 
88 BraseroScsiResult
brasero_spc1_inquiry(BraseroDeviceHandle * handle,BraseroScsiInquiry * hdr,BraseroScsiErrCode * error)89 brasero_spc1_inquiry (BraseroDeviceHandle *handle,
90                       BraseroScsiInquiry *hdr,
91                       BraseroScsiErrCode *error)
92 {
93 	BraseroInquiryCDB *cdb;
94 	BraseroScsiResult res;
95 
96 	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
97 
98 	cdb = brasero_scsi_command_new (&info, handle);
99 	cdb->alloc_len = sizeof (BraseroScsiInquiry);
100 
101 	memset (hdr, 0, sizeof (BraseroScsiInquiry));
102 	res = brasero_scsi_command_issue_sync (cdb,
103 					       hdr,
104 					       sizeof (BraseroScsiInquiry),
105 					       error);
106 	brasero_scsi_command_free (cdb);
107 	return res;
108 }
109 
110 BraseroScsiResult
brasero_spc1_inquiry_is_optical_drive(BraseroDeviceHandle * handle,BraseroScsiErrCode * error)111 brasero_spc1_inquiry_is_optical_drive (BraseroDeviceHandle *handle,
112                                        BraseroScsiErrCode *error)
113 {
114 	BraseroInquiryCDB *cdb;
115 	BraseroScsiInquiry hdr;
116 	BraseroScsiResult res;
117 
118 	g_return_val_if_fail (handle != NULL, BRASERO_SCSI_FAILURE);
119 
120 	cdb = brasero_scsi_command_new (&info, handle);
121 	cdb->alloc_len = sizeof (hdr);
122 
123 	memset (&hdr, 0, sizeof (hdr));
124 	res = brasero_scsi_command_issue_sync (cdb,
125 					       &hdr,
126 					       sizeof (hdr),
127 					       error);
128 	brasero_scsi_command_free (cdb);
129 
130 	if (res != BRASERO_SCSI_OK)
131 		return res;
132 
133 	/* NOTE: 0x05 is for CD/DVD players */
134 	return hdr.type == 0x05? BRASERO_SCSI_OK:BRASERO_SCSI_RECOVERABLE;
135 }
136 
137 
138