Author: philippr Date: Sun Feb 17 13:01:47 2008 New Revision: 641 URL: http://svn.gnome.org/viewvc/brasero?rev=641&view=rev
Log: 2008-02-17 Philippe Rouquier <[EMAIL PROTECTED]> Add FreeBSD support Patch and work by Joe Marcus Clarke <[EMAIL PROTECTED]> * configure.in: * src/Makefile.am: * src/scsi-cam.c: (brasero_scsi_command_issue_sync), (brasero_scsi_command_new), (brasero_scsi_command_free), (brasero_device_handle_open), (brasero_device_handle_close), (brasero_device_handle_get_fd): * src/scsi-sg.c: Added: trunk/src/scsi-cam.c Modified: trunk/ChangeLog trunk/configure.in trunk/src/Makefile.am trunk/src/scsi-sg.c Modified: trunk/configure.in ============================================================================== --- trunk/configure.in (original) +++ trunk/configure.in Sun Feb 17 13:01:47 2008 @@ -39,15 +39,24 @@ AC_HEADER_STDC dnl ***************** SCSI related ***************************** +AC_SUBST(BRASERO_SCSI_LIBS) +AC_CHECK_HEADERS([camlib.h],[has_cam="yes"],[has_cam="no"]) + +if test x"$has_cam" = x"yes"; then + BRASERO_SCSI_LIBS="-lcam" +else dnl ***************** check for linux sg interface ************* AC_CHECK_TYPES([sg_io_hdr_t],[has_sg="yes"],[has_sg="no"], [#include <sys/types.h> #include <scsi/sg.h>]) -if test x"$has_sg" = "xno"; then +if test x"$has_sg" = x"no"; then AC_ERROR([Linux sg interface headers could not be found]) fi +fi +AM_CONDITIONAL(HAVE_CAM_LIB_H, test x"$has_cam" = "xyes") +AM_CONDITIONAL(HAVE_SG_IO_HDR_T, test x"$has_sg" = "xyes") dnl ***************** LARGE FILE SUPPORT *********************** @@ -111,7 +120,7 @@ AC_SUBST(BRASERO_CFLAGS) AC_SUBST(BRASERO_LIBS) BRASERO_CFLAGS="$BRASERO_BASE_CFLAGS $BRASERO_GSTREAMER_CFLAGS $BRASERO_GNOMEVFS_CFLAGS $BRASERO_CFLAGS $CFLAGS" -BRASERO_LIBS="$BRASERO_BASE_LIBS $BRASERO_BASE_LIBS $BRASERO_GNOMEVFS_LIBS $BRASERO_LIBS $LDFLAGS" +BRASERO_LIBS="$BRASERO_BASE_LIBS $BRASERO_GSTREAMER_LIBS $BRASERO_GNOMEVFS_LIBS $BRASERO_LIBS $BRASERO_SCSI_LIBS $LDFLAGS" dnl ****************check for libburn (optional)************** LIBBURN_REQUIRED=0.4.0 Modified: trunk/src/Makefile.am ============================================================================== --- trunk/src/Makefile.am (original) +++ trunk/src/Makefile.am Sun Feb 17 13:01:47 2008 @@ -21,8 +21,6 @@ AM_CFLAGS = -g -EXTRA_DIST = cd-content-marshal.list - GLIB_GENMARSHAL=`pkg-config --variable=glib_genmarshal glib-2.0` RECMARSHALFILES = brasero-marshal.h brasero-marshal.c brasero-marshal.h: brasero-marshal.list @@ -148,7 +146,6 @@ scsi-read-toc-pma-atip.h \ scsi-sense-data.c \ scsi-sense-data.h \ - scsi-sg.c \ scsi-utils.h \ scsi-q-subchannel.h \ scsi-error.c \ @@ -240,6 +237,16 @@ brasero_SOURCES += brasero-file-monitor.c brasero-file-monitor.h endif +# FreeBSD's SCSI CAM interface +if HAVE_CAM_LIB_H +brasero_SOURCES += scsi-cam.c +endif + +# Linux's SCSI CAM interface +if HAVE_SG_IO_HDR_T +brasero_SOURCES += scsi-sg.c +endif + brasero_LDADD = \ $(BRASERO_LIBS) Added: trunk/src/scsi-cam.c ============================================================================== --- (empty file) +++ trunk/src/scsi-cam.c Sun Feb 17 13:01:47 2008 @@ -0,0 +1,191 @@ +/*************************************************************************** + * scsi-cam.c + * + * Saturday February 16, 2008 + * Copyright 2008 Joe Marcus Clarke + * <[EMAIL PROTECTED]> + ****************************************************************************/ + +/* + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301, USA + */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <errno.h> +#include <unistd.h> +#include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <string.h> +#include <sys/ioctl.h> + +#include "scsi-command.h" +#include "burn-debug.h" +#include "scsi-utils.h" +#include "scsi-error.h" +#include "scsi-sense-data.h" + +/* FreeBSD's SCSI CAM interface */ + +#include <camlib.h> +#include <cam/scsi/scsi_message.h> + +struct _BraseroDeviceHandle { + struct cam_device *cam; + int fd; +}; + +struct _BraseroScsiCmd { + uchar cmd [BRASERO_SCSI_CMD_MAX_LEN]; + BraseroDeviceHandle *handle; + + const BraseroScsiCmdInfo *info; +}; +typedef struct _BraseroScsiCmd BraseroScsiCmd; + +#define BRASERO_SCSI_CMD_OPCODE_OFF 0 +#define BRASERO_SCSI_CMD_SET_OPCODE(command) (command->cmd [BRASERO_SCSI_CMD_OPCODE_OFF] = command->info->opcode) + +#define OPEN_FLAGS O_RDONLY /*|O_EXCL */|O_NONBLOCK + +BraseroScsiResult +brasero_scsi_command_issue_sync (gpointer command, + gpointer buffer, + int size, + BraseroScsiErrCode *error) +{ + int timeout; + BraseroScsiCmd *cmd; + union ccb cam_ccb; + int direction = -1; + + timeout = 10; + + memset (&cam_ccb, 0, sizeof(cam_ccb)); + cmd = command; + + cam_ccb.ccb_h.path_id = cmd->handle->cam->path_id; + cam_ccb.ccb_h.target_id = cmd->handle->cam->target_id; + cam_ccb.ccb_h.target_lun = cmd->handle->cam->target_lun; + + if (cmd->info->direction & BRASERO_SCSI_READ) + direction = CAM_DIR_IN; + else if (cmd->info->direction & BRASERO_SCSI_WRITE) + direction = CAM_DIR_OUT; + + g_assert (direction > -1); + + cam_fill_csio(&cam_ccb.csio, + 1, + NULL, + direction, + MSG_SIMPLE_Q_TAG, + buffer, + size, + sizeof(cam_ccb.csio.sense_data), + cmd->info->size, + timeout * 1000); + + memcpy (cam_ccb.csio.cdb_io.cdb_bytes, cmd->cmd, + BRASERO_SCSI_CMD_MAX_LEN); + + if (cam_send_ccb (cmd->handle->cam, &cam_ccb) == -1) { + BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_ERRNO); + return BRASERO_SCSI_FAILURE; + } + + if ((cam_ccb.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { + BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_ERRNO); + return BRASERO_SCSI_FAILURE; + } + + return BRASERO_SCSI_OK; +} + +gpointer +brasero_scsi_command_new (const BraseroScsiCmdInfo *info, + BraseroDeviceHandle *handle) +{ + BraseroScsiCmd *cmd; + + /* make sure we can set the flags of the descriptor */ + + /* allocate the command */ + cmd = g_new0 (BraseroScsiCmd, 1); + cmd->info = info; + cmd->handle = handle; + + BRASERO_SCSI_CMD_SET_OPCODE (cmd); + return cmd; +} + +BraseroScsiResult +brasero_scsi_command_free (gpointer cmd) +{ + g_free (cmd); + return BRASERO_SCSI_OK; +} + +/** + * This is to open a device + */ + +BraseroDeviceHandle * +brasero_device_handle_open (const gchar *path, + BraseroScsiErrCode *code) +{ + int fd; + BraseroDeviceHandle *handle; + struct cam_device *cam; + + g_assert (path != NULL); + + /* cam_open_device() fails unless we use O_RDWR */ + cam = cam_open_device (path, O_RDWR); + fd = open (path, OPEN_FLAGS); + if (cam && fd > -1) { + handle = g_new0 (BraseroDeviceHandle, 1); + handle->cam = cam; + handle->fd = fd; + } + + return handle; +} + +void +brasero_device_handle_close (BraseroDeviceHandle *handle) +{ + g_assert (handle != NULL); + + if (handle->cam) + cam_close_device (handle->cam); + + close (handle->fd); + + g_free (handle); +} + +int +brasero_device_handle_get_fd (BraseroDeviceHandle *handle) +{ + g_assert (handle != NULL); + + return handle->fd; +} + Modified: trunk/src/scsi-sg.c ============================================================================== --- trunk/src/scsi-sg.c (original) +++ trunk/src/scsi-sg.c Sun Feb 17 13:01:47 2008 @@ -34,7 +34,9 @@ #include <fcntl.h> #include <string.h> #include <sys/ioctl.h> + #include <scsi/scsi.h> +#include <scsi/sg.h> #include "scsi-command.h" #include "burn-debug.h" @@ -42,11 +44,6 @@ #include "scsi-error.h" #include "scsi-sense-data.h" -/* Only work for linux when it has the SG interface */ -#if HAVE_SG_IO_HDR_T - -#include <scsi/sg.h> - struct _BraseroDeviceHandle { int fd; }; @@ -198,4 +195,3 @@ return handle->fd; } -#endif /* HAVE_SG_IO_HDR_T */ _______________________________________________ SVN-commits-list mailing list (read only) http://mail.gnome.org/mailman/listinfo/svn-commits-list Want to limit the commits to a few modules? Go to above URL, log in to edit your options and select the modules ('topics') you want. Module maintainer? It is possible to set the reply-to to your development mailing list. Email [EMAIL PROTECTED] if interested.