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

« back to all changes in this revision

Viewing changes to src/scsi-sg.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
 
/***************************************************************************
2
 
 *            burn-sg.c
3
 
 *
4
 
 *  Wed Oct 18 14:39:28 2006
5
 
 *  Copyright  2006  Rouquier Philippe
6
 
 *  <Rouquier Philippe@localhost.localdomain>
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
 
#ifdef HAVE_CONFIG_H
26
 
#  include <config.h>
27
 
#endif
28
 
 
29
 
#include <errno.h>
30
 
#include <unistd.h>
31
 
#include <stdlib.h>
32
 
#include <sys/types.h>
33
 
#include <sys/stat.h>
34
 
#include <fcntl.h>
35
 
#include <string.h>
36
 
#include <sys/ioctl.h>
37
 
 
38
 
#include <scsi/scsi.h>
39
 
#include <scsi/sg.h>
40
 
 
41
 
#include "scsi-command.h"
42
 
#include "burn-debug.h"
43
 
#include "scsi-utils.h"
44
 
#include "scsi-error.h"
45
 
#include "scsi-sense-data.h"
46
 
 
47
 
struct _BraseroDeviceHandle {
48
 
        int fd;
49
 
};
50
 
 
51
 
struct _BraseroScsiCmd {
52
 
        uchar cmd [BRASERO_SCSI_CMD_MAX_LEN];
53
 
        BraseroDeviceHandle *handle;
54
 
 
55
 
        const BraseroScsiCmdInfo *info;
56
 
};
57
 
typedef struct _BraseroScsiCmd BraseroScsiCmd;
58
 
 
59
 
#define BRASERO_SCSI_CMD_OPCODE_OFF                     0
60
 
#define BRASERO_SCSI_CMD_SET_OPCODE(command)            (command->cmd [BRASERO_SCSI_CMD_OPCODE_OFF] = command->info->opcode)
61
 
 
62
 
#define OPEN_FLAGS                      O_RDONLY /*|O_EXCL */|O_NONBLOCK
63
 
 
64
 
/**
65
 
 * This is to send a command
66
 
 */
67
 
 
68
 
static void
69
 
brasero_sg_command_setup (struct sg_io_hdr *transport,
70
 
                          uchar *sense_data,
71
 
                          BraseroScsiCmd *cmd,
72
 
                          uchar *buffer,
73
 
                          int size)
74
 
{
75
 
        memset (sense_data, 0, BRASERO_SENSE_DATA_SIZE);
76
 
        memset (transport, 0, sizeof (struct sg_io_hdr));
77
 
        
78
 
        transport->interface_id = 'S';                          /* mandatory */
79
 
//      transport->flags = SG_FLAG_LUN_INHIBIT|SG_FLAG_DIRECT_IO;
80
 
        transport->cmdp = cmd->cmd;
81
 
        transport->cmd_len = cmd->info->size;
82
 
        transport->dxferp = buffer;
83
 
        transport->dxfer_len = size;
84
 
 
85
 
        /* where to output the scsi sense buffer */
86
 
        transport->sbp = sense_data;
87
 
        transport->mx_sb_len = BRASERO_SENSE_DATA_SIZE;
88
 
 
89
 
        if (cmd->info->direction & BRASERO_SCSI_READ)
90
 
                transport->dxfer_direction = SG_DXFER_FROM_DEV;
91
 
        else if (cmd->info->direction & BRASERO_SCSI_WRITE)
92
 
                transport->dxfer_direction = SG_DXFER_TO_DEV;
93
 
}
94
 
 
95
 
BraseroScsiResult
96
 
brasero_scsi_command_issue_sync (gpointer command,
97
 
                                 gpointer buffer,
98
 
                                 int size,
99
 
                                 BraseroScsiErrCode *error)
100
 
{
101
 
        uchar sense_buffer [BRASERO_SENSE_DATA_SIZE];
102
 
        struct sg_io_hdr transport;
103
 
        BraseroScsiResult res;
104
 
        BraseroScsiCmd *cmd;
105
 
 
106
 
        cmd = command;
107
 
        brasero_sg_command_setup (&transport,
108
 
                                  sense_buffer,
109
 
                                  cmd,
110
 
                                  buffer,
111
 
                                  size);
112
 
 
113
 
        /* NOTE on SG_IO: only for TEST UNIT READY, REQUEST/MODE SENSE, INQUIRY,
114
 
         * READ CAPACITY, READ BUFFER, READ and LOG SENSE are allowed with it */
115
 
        res = ioctl (cmd->handle->fd, SG_IO, &transport);
116
 
        if (res) {
117
 
                BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_ERRNO);
118
 
                return BRASERO_SCSI_FAILURE;
119
 
        }
120
 
 
121
 
        if ((transport.info & SG_INFO_OK_MASK) == SG_INFO_OK)
122
 
                return BRASERO_SCSI_OK;
123
 
 
124
 
        if ((transport.masked_status & CHECK_CONDITION) && transport.sb_len_wr)
125
 
                return brasero_sense_data_process (sense_buffer, error);
126
 
 
127
 
        return BRASERO_SCSI_FAILURE;
128
 
}
129
 
 
130
 
gpointer
131
 
brasero_scsi_command_new (const BraseroScsiCmdInfo *info,
132
 
                          BraseroDeviceHandle *handle) 
133
 
{
134
 
        BraseroScsiCmd *cmd;
135
 
 
136
 
        /* make sure we can set the flags of the descriptor */
137
 
 
138
 
        /* allocate the command */
139
 
        cmd = g_new0 (BraseroScsiCmd, 1);
140
 
        cmd->info = info;
141
 
        cmd->handle = handle;
142
 
 
143
 
        BRASERO_SCSI_CMD_SET_OPCODE (cmd);
144
 
        return cmd;
145
 
}
146
 
 
147
 
BraseroScsiResult
148
 
brasero_scsi_command_free (gpointer cmd)
149
 
{
150
 
        g_free (cmd);
151
 
        return BRASERO_SCSI_OK;
152
 
}
153
 
 
154
 
/**
155
 
 * This is to open a device
156
 
 */
157
 
 
158
 
BraseroDeviceHandle *
159
 
brasero_device_handle_open (const gchar *path,
160
 
                            BraseroScsiErrCode *code)
161
 
{
162
 
        int fd;
163
 
        BraseroDeviceHandle *handle;
164
 
 
165
 
        fd = open (path, OPEN_FLAGS);
166
 
        if (fd < 0) {
167
 
                if (errno == EAGAIN
168
 
                ||  errno == EWOULDBLOCK
169
 
                ||  errno == EBUSY)
170
 
                        *code = BRASERO_SCSI_NOT_READY;
171
 
                else
172
 
                        *code = BRASERO_SCSI_ERRNO;
173
 
 
174
 
                return NULL;
175
 
        }
176
 
 
177
 
        handle = g_new (BraseroDeviceHandle, 1);
178
 
        handle->fd = fd;
179
 
 
180
 
        return handle;
181
 
}
182
 
 
183
 
void
184
 
brasero_device_handle_close (BraseroDeviceHandle *handle)
185
 
{
186
 
        close (handle->fd);
187
 
        g_free (handle);
188
 
}
189