~ubuntu-branches/debian/wheezy/brasero/wheezy

« back to all changes in this revision

Viewing changes to libbrasero-media/scsi-get-performance.c

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette, Pedro Fragoso, Luca Bruno, Josselin Mouette, Emilio Pozuelo Monfort
  • Date: 2009-06-24 18:59:46 UTC
  • mfrom: (1.2.13 upstream)
  • Revision ID: james.westby@ubuntu.com-20090624185946-iyxkgf3gjptir5y3
Tags: 2.26.2-1
[ Pedro Fragoso ]
* Add myself to Maintainer field
  - Thanks Ondřej Surý
* New upstream version (Closes: #528945)
  - Split package into brasero, libbrasero-media0 and libbrasero-dev
  - Add Replaces to libbrasero-media0
  - Bump libgtk to 2.14.0
  - Remove libnotify Build-dep
  - Add Build-dep libnautilus-extension-dev (>= 2.22.2)
    and install it.
  - Add Build-dep to libsm-dev
  - Add Build-dep on intltool
* Install omf files to prevent crash on Help
* Move gstreamer0.10-plugins-bad to Suggests, and add
  dvdauthor and vcdimager
* Recommends gvfs (Closes: #491827)
* Pass --disable-scrollkeeper in DEB_CONFIGURE_EXTRA_FLAGS
* debian/patches/007-fix-gnome-doc-utils-path.patch:
  - Removed, not needed anymore
* debian/patches/008-fix-volume-identifier-crash.patch:
  - Removed, merged upstream
* debian/patches/011_nautilus_menu_move.patch:
 - Move CD/DVD Creator Menu to Acessories, taken from Ubuntu

[ Luca Bruno ]
* debian/control.in:
  - Add Build-Depend gtk-doc-tools 1.9.
* debian/patches/006-fix-libdvdcss.patch:
  - Removed as applied upstream.

[ Josselin Mouette ]
* New upstream release.
* Update build-dependencies.
* Move the translations and data to a new brasero-common package.
* Rewrite the descriptions.
* Add -dev depends to the development package.
* Remove inappropriate recommends in the library package.
* Let’s not forget dvd+rw-tools so that we can write DVDs too.
* Rework dependencies accordingly.
* Put the nautilus extension in brasero.
* Conflict against nautilus-cd-burner to avoid having two burning 
  extensions.
* Include clean-la.mk and gnome-version.mk; build-depend on 
  gnome-pkg-tools 0.7.
* Don’t run dh_makeshlibs on brasero and libbrasero-plugins.
* 011_nautilus_menu_move.patch: add NoDisplay=true, this icon is 
  duplicating existing functionality (brasero icon in sound&video 
  menu, and nautilus autorun).
* Update list of copyright holders.

[ Emilio Pozuelo Monfort ]
* debian/copyright: updated.

[ Josselin Mouette ]
* copyright: improve indentation, and point to versioned LGPL.
* 090_relibtoolize.patch: add a relibtoolization patch to avoid the 
  rpath crap.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 <glib.h>
 
36
 
 
37
#include "brasero-media-private.h"
 
38
 
 
39
#include "scsi-error.h"
 
40
#include "scsi-utils.h"
 
41
#include "scsi-command.h"
 
42
#include "scsi-opcodes.h"
 
43
#include "scsi-get-performance.h"
 
44
 
 
45
/**
 
46
 * GET PERMORMANCE command description  (MMC2)
 
47
 */
 
48
 
 
49
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
 
50
 
 
51
struct _BraseroGetPerformanceCDB {
 
52
        uchar opcode            :8;
 
53
 
 
54
        uchar except            :2;
 
55
        uchar write             :1;
 
56
        uchar tolerance         :2;
 
57
        uchar reserved0         :3;
 
58
 
 
59
        uchar start_lba         [4];
 
60
 
 
61
        uchar reserved1         [2];
 
62
 
 
63
        uchar max_desc          [2];
 
64
 
 
65
        uchar type;
 
66
        uchar ctl;
 
67
};
 
68
 
 
69
#else
 
70
 
 
71
struct _BraseroGetPerformanceCDB {
 
72
        uchar opcode            :8;
 
73
 
 
74
        uchar reserved0         :3;
 
75
        uchar tolerance         :2;
 
76
        uchar write             :1;
 
77
        uchar except            :2;
 
78
 
 
79
        uchar start_lba         [4];
 
80
 
 
81
        uchar reserved1         [2];
 
82
 
 
83
        uchar max_desc          [2];
 
84
 
 
85
        uchar type;
 
86
        uchar ctl;
 
87
};
 
88
 
 
89
#endif
 
90
 
 
91
typedef struct _BraseroGetPerformanceCDB BraseroGetPerformanceCDB;
 
92
 
 
93
BRASERO_SCSI_COMMAND_DEFINE (BraseroGetPerformanceCDB,
 
94
                             GET_PERFORMANCE,
 
95
                             BRASERO_SCSI_READ);
 
96
 
 
97
/* used to choose which GET PERFORMANCE response we want */
 
98
#define BRASERO_GET_PERFORMANCE_PERF_TYPE               0x00
 
99
#define BRASERO_GET_PERFORMANCE_UNUSABLE_AREA_TYPE      0x01
 
100
#define BRASERO_GET_PERFORMANCE_DEFECT_STATUS_TYPE      0x02
 
101
#define BRASERO_GET_PERFORMANCE_WR_SPEED_TYPE           0x03
 
102
#define BRASERO_GET_PERFORMANCE_DBI_TYPE                0x04
 
103
#define BRASERO_GET_PERFORMANCE_DBI_CACHE_TYPE          0x05
 
104
 
 
105
static BraseroScsiGetPerfData *
 
106
brasero_get_performance_get_buffer (BraseroGetPerformanceCDB *cdb,
 
107
                                    gint sizeof_descriptors,
 
108
                                    BraseroScsiGetPerfHdr *hdr,
 
109
                                    BraseroScsiErrCode *error)
 
110
{
 
111
        BraseroScsiGetPerfData *buffer;
 
112
        BraseroScsiResult res;
 
113
        int request_size;
 
114
        int desc_num;
 
115
 
 
116
        /* ... check the request size ... */
 
117
        request_size = BRASERO_GET_32 (hdr->len) +
 
118
                       G_STRUCT_OFFSET (BraseroScsiGetPerfHdr, len) +
 
119
                       sizeof (hdr->len);
 
120
 
 
121
        /* ... check the request size ... */
 
122
        if (request_size > 2048) {
 
123
                BRASERO_MEDIA_LOG ("Oversized data (%i) setting to max (2048)", request_size);
 
124
                request_size = 2048;
 
125
        }
 
126
        else if ((request_size - sizeof (hdr)) % sizeof_descriptors) {
 
127
                BRASERO_MEDIA_LOG ("Unaligned data (%i) setting to max (2048)", request_size);
 
128
                request_size = 2048;
 
129
        }
 
130
        else if (request_size < sizeof (hdr)) {
 
131
                BRASERO_MEDIA_LOG ("Undersized data (%i) setting to max (2048)", request_size);
 
132
                request_size = 2048;
 
133
        }
 
134
 
 
135
        desc_num = (request_size - sizeof (BraseroScsiGetPerfHdr)) / sizeof_descriptors;
 
136
 
 
137
        /* ... allocate a buffer and re-issue the command */
 
138
        buffer = (BraseroScsiGetPerfData *) g_new0 (uchar, request_size);
 
139
 
 
140
        BRASERO_SET_16 (cdb->max_desc, desc_num);
 
141
        res = brasero_scsi_command_issue_sync (cdb, buffer, request_size, error);
 
142
        if (res) {
 
143
                g_free (buffer);
 
144
                return NULL;
 
145
        }
 
146
 
 
147
        return buffer;
 
148
}
 
149
 
 
150
static BraseroScsiResult
 
151
brasero_get_performance (BraseroGetPerformanceCDB *cdb,
 
152
                         gint sizeof_descriptors,
 
153
                         BraseroScsiGetPerfData **data,
 
154
                         int *data_size,
 
155
                         BraseroScsiErrCode *error)
 
156
{
 
157
        BraseroScsiGetPerfData *buffer;
 
158
        BraseroScsiGetPerfHdr hdr;
 
159
        BraseroScsiResult res;
 
160
        int request_size;
 
161
        int buffer_size;
 
162
 
 
163
        if (!data || !data_size) {
 
164
                BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_BAD_ARGUMENT);
 
165
                return BRASERO_SCSI_FAILURE;
 
166
        }
 
167
 
 
168
        /* Issue the command once to get the size ... */
 
169
        memset (&hdr, 0, sizeof (hdr));
 
170
        BRASERO_SET_16 (cdb->max_desc, 0);
 
171
        res = brasero_scsi_command_issue_sync (cdb, &hdr, sizeof (hdr), error);
 
172
        if (res)
 
173
                return res;
 
174
 
 
175
        /* ... get the request size ... */
 
176
        request_size = BRASERO_GET_32 (hdr.len) +
 
177
                       G_STRUCT_OFFSET (BraseroScsiGetPerfHdr, len) +
 
178
                       sizeof (hdr.len);
 
179
 
 
180
        /* ... get the answer itself. */
 
181
        buffer = brasero_get_performance_get_buffer (cdb,
 
182
                                                     sizeof_descriptors,
 
183
                                                     &hdr,
 
184
                                                     error);
 
185
        if (!buffer)
 
186
                return BRASERO_SCSI_FAILURE;
 
187
 
 
188
        /* make sure the response has the requested size */
 
189
        buffer_size = BRASERO_GET_32 (buffer->hdr.len) +
 
190
                      G_STRUCT_OFFSET (BraseroScsiGetPerfHdr, len) +
 
191
                      sizeof (buffer->hdr.len);
 
192
 
 
193
        if (request_size < buffer_size) {
 
194
                BraseroScsiGetPerfHdr *tmp_hdr;
 
195
 
 
196
                /* Strangely some drives returns a buffer size that is bigger
 
197
                 * than the one they returned on the first time. So redo whole
 
198
                 * operation again but this time with the new size we got */
 
199
                BRASERO_MEDIA_LOG ("Sizes mismatch asked %i / received %i\n"
 
200
                                   "Re-issuing the command with received size",
 
201
                                   request_size,
 
202
                                   buffer_size);
 
203
 
 
204
                tmp_hdr = &buffer->hdr;
 
205
                request_size = buffer_size;
 
206
                buffer = brasero_get_performance_get_buffer (cdb,
 
207
                                                             sizeof_descriptors,
 
208
                                                             tmp_hdr,
 
209
                                                             error);
 
210
                buffer_size = BRASERO_GET_32 (buffer->hdr.len) +
 
211
                              G_STRUCT_OFFSET (BraseroScsiGetPerfHdr, len) +
 
212
                              sizeof (buffer->hdr.len);
 
213
                
 
214
                g_free (tmp_hdr);
 
215
        }
 
216
        else if (request_size > buffer_size)
 
217
                BRASERO_MEDIA_LOG ("Sizes mismatch asked %i / received %i",
 
218
                                  request_size,
 
219
                                  buffer_size);
 
220
        *data = buffer;
 
221
        *data_size = MIN (buffer_size, request_size);
 
222
 
 
223
        return res;
 
224
}
 
225
 
 
226
/**
 
227
 * MMC3 command extension
 
228
 */
 
229
 
 
230
BraseroScsiResult
 
231
brasero_mmc3_get_performance_wrt_spd_desc (BraseroDeviceHandle *handle,
 
232
                                           BraseroScsiGetPerfData **data,
 
233
                                           int *size,
 
234
                                           BraseroScsiErrCode *error)
 
235
{
 
236
        BraseroGetPerformanceCDB *cdb;
 
237
        BraseroScsiResult res;
 
238
 
 
239
        cdb = brasero_scsi_command_new (&info, handle);
 
240
        cdb->type = BRASERO_GET_PERFORMANCE_WR_SPEED_TYPE;
 
241
 
 
242
        res = brasero_get_performance (cdb, sizeof (BraseroScsiWrtSpdDesc), data, size, error);
 
243
        brasero_scsi_command_free (cdb);
 
244
        return res;
 
245
}
 
246