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

« back to all changes in this revision

Viewing changes to src/scsi-uscsi.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
 
 *            scsi-uscsi.c
3
 
 *
4
 
 *  Wed Oct 18 14:39:28 2008
5
 
 *  Copyright  2008  Lin Ma
6
 
 *  <lin.ma@sun.com>
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
 
 
37
 
#include <sys/scsi/scsi.h>
38
 
#include <sys/scsi/impl/uscsi.h>
39
 
 
40
 
#include "scsi-command.h"
41
 
#include "burn-debug.h"
42
 
#include "scsi-utils.h"
43
 
#include "scsi-error.h"
44
 
#include "scsi-sense-data.h"
45
 
 
46
 
struct _BraseroDeviceHandle {
47
 
        int fd;
48
 
};
49
 
 
50
 
struct _BraseroScsiCmd {
51
 
        uchar cmd [BRASERO_SCSI_CMD_MAX_LEN];
52
 
        BraseroDeviceHandle *handle;
53
 
 
54
 
        const BraseroScsiCmdInfo *info;
55
 
};
56
 
typedef struct _BraseroScsiCmd BraseroScsiCmd;
57
 
 
58
 
#define BRASERO_SCSI_CMD_OPCODE_OFF                     0
59
 
#define BRASERO_SCSI_CMD_SET_OPCODE(command)            (command->cmd [BRASERO_SCSI_CMD_OPCODE_OFF] = command->info->opcode)
60
 
 
61
 
#define OPEN_FLAGS                      O_RDONLY /*|O_EXCL */|O_NONBLOCK
62
 
 
63
 
/**
64
 
 * This is to send a command
65
 
 */
66
 
BraseroScsiResult
67
 
brasero_scsi_command_issue_sync (gpointer command,
68
 
                                 gpointer buffer,
69
 
                                 int size,
70
 
                                 BraseroScsiErrCode *error)
71
 
{
72
 
        uchar sense_buffer [BRASERO_SENSE_DATA_SIZE];
73
 
        struct uscsi_cmd transport;
74
 
        BraseroScsiResult res;
75
 
        BraseroScsiCmd *cmd;
76
 
        short timeout = 10;
77
 
 
78
 
        memset (&sense_buffer, 0, BRASERO_SENSE_DATA_SIZE);
79
 
        memset (&transport, 0, sizeof (struct uscsi_cmd));
80
 
 
81
 
        cmd = command;
82
 
 
83
 
        if (cmd->info->direction & BRASERO_SCSI_READ)
84
 
                transport.uscsi_flags = USCSI_READ;
85
 
        else if (cmd->info->direction & BRASERO_SCSI_WRITE)
86
 
                transport.uscsi_flags = USCSI_WRITE;
87
 
 
88
 
        transport.uscsi_cdb = (caddr_t) cmd->cmd;
89
 
        g_debug("cmd: %s\n", transport.uscsi_cdb);
90
 
        transport.uscsi_cdblen = (uchar_t) cmd->info->size;
91
 
        transport.uscsi_bufaddr = (caddr_t) buffer;
92
 
        transport.uscsi_buflen = (size_t) size;
93
 
        transport.uscsi_timeout = timeout;
94
 
 
95
 
        /* where to output the scsi sense buffer */
96
 
        transport.uscsi_flags |= USCSI_RQENABLE;
97
 
        transport.uscsi_rqbuf = sense_buffer;
98
 
        transport.uscsi_rqlen = BRASERO_SENSE_DATA_SIZE;
99
 
 
100
 
        /* NOTE only for TEST UNIT READY, REQUEST/MODE SENSE, INQUIRY,
101
 
         * READ CAPACITY, READ BUFFER, READ and LOG SENSE are allowed with it */
102
 
        res = ioctl (cmd->handle->fd, USCSICMD, &transport);
103
 
        if (res) {
104
 
                BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_ERRNO);
105
 
                g_debug("ioctl ERR: %s\n", g_strerror(errno));
106
 
                return BRASERO_SCSI_FAILURE;
107
 
        }
108
 
 
109
 
        if ((transport.uscsi_status & STATUS_MASK) == STATUS_GOOD)
110
 
                return BRASERO_SCSI_OK;
111
 
 
112
 
        if ((transport.uscsi_rqstatus & STATUS_MASK == STATUS_CHECK)
113
 
            && transport.uscsi_rqlen)
114
 
                return brasero_sense_data_process (sense_buffer, error);
115
 
 
116
 
        return BRASERO_SCSI_FAILURE;
117
 
}
118
 
 
119
 
gpointer
120
 
brasero_scsi_command_new (const BraseroScsiCmdInfo *info,
121
 
                          BraseroDeviceHandle *handle) 
122
 
{
123
 
        BraseroScsiCmd *cmd;
124
 
 
125
 
        /* make sure we can set the flags of the descriptor */
126
 
 
127
 
        /* allocate the command */
128
 
        cmd = g_new0 (BraseroScsiCmd, 1);
129
 
        cmd->info = info;
130
 
        cmd->handle = handle;
131
 
 
132
 
        BRASERO_SCSI_CMD_SET_OPCODE (cmd);
133
 
        return cmd;
134
 
}
135
 
 
136
 
BraseroScsiResult
137
 
brasero_scsi_command_free (gpointer cmd)
138
 
{
139
 
        g_free (cmd);
140
 
        return BRASERO_SCSI_OK;
141
 
}
142
 
 
143
 
/**
144
 
 * This is to open a device
145
 
 */
146
 
 
147
 
BraseroDeviceHandle *
148
 
brasero_device_handle_open (const gchar *path,
149
 
                            BraseroScsiErrCode *code)
150
 
{
151
 
        int fd;
152
 
        BraseroDeviceHandle *handle;
153
 
        const gchar *blockdisk = "/dev/dsk/";
154
 
        gchar *rawdisk = NULL;
155
 
 
156
 
        fd = open (path, OPEN_FLAGS);
157
 
        if (fd < 0) {
158
 
                if (errno == EAGAIN
159
 
                ||  errno == EWOULDBLOCK
160
 
                ||  errno == EBUSY)
161
 
                        *code = BRASERO_SCSI_NOT_READY;
162
 
                else
163
 
                        *code = BRASERO_SCSI_ERRNO;
164
 
 
165
 
                g_debug("open ERR: %s\n", g_strerror(errno));
166
 
                return NULL;
167
 
        }
168
 
 
169
 
        handle = g_new (BraseroDeviceHandle, 1);
170
 
        handle->fd = fd;
171
 
 
172
 
        return handle;
173
 
}
174
 
 
175
 
void
176
 
brasero_device_handle_close (BraseroDeviceHandle *handle)
177
 
{
178
 
        close (handle->fd);
179
 
        g_free (handle);
180
 
}
181