~noskcaj/ubuntu/vivid/brasero/3.12

« back to all changes in this revision

Viewing changes to src/scsi/scsi-read-disc-info.c

  • Committer: Bazaar Package Importer
  • Author(s): Mario Danic
  • Date: 2007-06-04 14:06:16 UTC
  • mto: (1.4.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20070604140616-gtp1vsiuqr5grutk
Tags: upstream-0.5.90
ImportĀ upstreamĀ versionĀ 0.5.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
 *            scsi-read-disc-info.c
 
3
 *
 
4
 *  Thu Oct 26 16:51:36 2006
 
5
 *  Copyright  2006  Rouquier Philippe
 
6
 *  <bonfire-app@wanadoo.fr>
 
7
 ****************************************************************************/
 
8
 
 
9
/*
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 * 
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU Library General Public License for more details.
 
19
 * 
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 
23
 */
 
24
 
 
25
#include <fcntl.h>
 
26
 
 
27
#ifdef HAVE_CONFIG_H
 
28
#  include <config.h>
 
29
#endif
 
30
 
 
31
#include <glib.h>
 
32
 
 
33
#include "scsi-error.h"
 
34
#include "scsi-utils.h"
 
35
#include "scsi-base.h"
 
36
#include "scsi-command.h"
 
37
#include "scsi-opcodes.h"
 
38
#include "scsi-read-disc-info.h"
 
39
 
 
40
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
 
41
 
 
42
struct _BraseroRdDiscInfoCDB {
 
43
        uchar opcode;
 
44
 
 
45
        uchar data_type         :3;
 
46
        uchar reserved0         :5;
 
47
 
 
48
        uchar reserved1         [5];
 
49
        uchar alloc_len         [2];
 
50
 
 
51
        uchar ctl;
 
52
};
 
53
 
 
54
#else
 
55
 
 
56
struct _BraseroRdDiscInfoCDB {
 
57
        uchar opcode;
 
58
 
 
59
        uchar reserved0         :5;
 
60
        uchar data_type         :3;
 
61
 
 
62
        uchar reserved1         [5];
 
63
        uchar alloc_len         [2];
 
64
 
 
65
        uchar ctl;
 
66
};
 
67
 
 
68
#endif
 
69
 
 
70
typedef struct _BraseroRdDiscInfoCDB BraseroRdDiscInfoCDB;
 
71
 
 
72
BRASERO_SCSI_COMMAND_DEFINE (BraseroRdDiscInfoCDB,
 
73
                             READ_DISC_INFORMATION,
 
74
                             O_RDONLY,
 
75
                             BRASERO_SCSI_READ);
 
76
 
 
77
typedef enum {
 
78
BRASERO_DISC_INFO_STD           = 0x00,
 
79
BRASERO_DISC_INFO_TRACK_RES     = 0x01,
 
80
BRASERO_DISC_INFO_POW_RES       = 0x02,
 
81
        /* reserved */
 
82
} BraseroDiscInfoType;
 
83
 
 
84
 
 
85
BraseroScsiResult
 
86
brasero_mmc1_read_disc_information_std (int fd,
 
87
                                        BraseroScsiDiscInfoStd **info_return,
 
88
                                        int *size,
 
89
                                        BraseroScsiErrCode *error)
 
90
{
 
91
        BraseroScsiDiscInfoStd std_info;
 
92
        BraseroScsiDiscInfoStd *buffer;
 
93
        BraseroRdDiscInfoCDB *cdb;
 
94
        BraseroScsiResult res;
 
95
        int request_size;
 
96
 
 
97
        if (!info_return || !size) {
 
98
                BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_BAD_ARGUMENT);
 
99
                return BRASERO_SCSI_FAILURE;
 
100
        }
 
101
 
 
102
        cdb = brasero_scsi_command_new (&info, fd);
 
103
        cdb->data_type = BRASERO_DISC_INFO_STD;
 
104
        BRASERO_SET_16 (cdb->alloc_len, sizeof (BraseroScsiDiscInfoStd));
 
105
 
 
106
        memset (&std_info, 0, sizeof (BraseroScsiDiscInfoStd));
 
107
        res = brasero_scsi_command_issue_sync (cdb,
 
108
                                               &std_info,
 
109
                                               sizeof (BraseroScsiDiscInfoStd),
 
110
                                               error);
 
111
        if (res)
 
112
                goto end;
 
113
 
 
114
        request_size = BRASERO_GET_16 (std_info.len) + 
 
115
                       sizeof (std_info.len);
 
116
        buffer = (BraseroScsiDiscInfoStd *) g_new0 (uchar, request_size);
 
117
 
 
118
        BRASERO_SET_16 (cdb->alloc_len, request_size);
 
119
        res = brasero_scsi_command_issue_sync (cdb, buffer, request_size, error);
 
120
        if (res) {
 
121
                g_free (buffer);
 
122
                goto end;
 
123
        }
 
124
 
 
125
        if (request_size != BRASERO_GET_16 (buffer->len) + sizeof (buffer->len)) {
 
126
                BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_SIZE_MISMATCH);
 
127
 
 
128
                res = BRASERO_SCSI_FAILURE;
 
129
                g_free (buffer);
 
130
                goto end;
 
131
        }
 
132
 
 
133
        *info_return = buffer;
 
134
        *size = request_size;
 
135
 
 
136
end:
 
137
 
 
138
        brasero_scsi_command_free (cdb);
 
139
        return res;
 
140
}
 
141
 
 
142
BraseroScsiResult
 
143
brasero_mmc5_read_disc_information_tracks (int fd,
 
144
                                           BraseroScsiTrackResInfo *info_return,
 
145
                                           int size,
 
146
                                           BraseroScsiErrCode *error)
 
147
{
 
148
        BraseroRdDiscInfoCDB *cdb;
 
149
        BraseroScsiResult res;
 
150
 
 
151
        cdb = brasero_scsi_command_new (&info, fd);
 
152
        cdb->data_type = BRASERO_DISC_INFO_TRACK_RES;
 
153
        BRASERO_SET_16 (cdb->alloc_len, size);
 
154
 
 
155
        memset (info_return, 0, size);
 
156
        res = brasero_scsi_command_issue_sync (cdb, info_return, size, error);
 
157
        brasero_scsi_command_free (cdb);
 
158
        return res;
 
159
}
 
160
 
 
161
BraseroScsiResult
 
162
brasero_mmc5_read_disc_information_pows (int fd,
 
163
                                         BraseroScsiPOWResInfo *info_return,
 
164
                                         int size,
 
165
                                         BraseroScsiErrCode *error)
 
166
{
 
167
        BraseroRdDiscInfoCDB *cdb;
 
168
        BraseroScsiResult res;
 
169
 
 
170
        cdb = brasero_scsi_command_new (&info, fd);
 
171
        cdb->data_type = BRASERO_DISC_INFO_POW_RES;
 
172
        BRASERO_SET_16 (cdb->alloc_len, size);
 
173
 
 
174
        memset (info_return, 0, size);
 
175
        res = brasero_scsi_command_issue_sync (cdb, info_return, size, error);
 
176
        brasero_scsi_command_free (cdb);
 
177
        return res;
 
178
}