[brasero] Add NetBSD support to libbrasero-media



commit fbae46fe5b46ff7c699253689545beec1775617f
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Mon Jun 1 20:09:05 2009 +0200

    Add NetBSD support to libbrasero-media
    Author: Jared McNeill <jmcneill NetBSD org>
    Fix #583332 â?? NetBSD support
---
 configure.in                   |   10 ++-
 libbrasero-media/Makefile.am   |    5 +
 libbrasero-media/scsi-netbsd.c |  200 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 214 insertions(+), 1 deletions(-)

diff --git a/configure.in b/configure.in
index 70fee35..9f7cb31 100644
--- a/configure.in
+++ b/configure.in
@@ -86,6 +86,11 @@ AC_CHECK_TYPES([sg_io_hdr_t],[has_sg="yes"],[has_sg="no"],
 [#include <sys/types.h>
  #include <scsi/sg.h>])
 
+dnl ***************** check for netbsd *************************
+AC_CHECK_TYPES([scsireq_t],[has_scsiio="yes"],[has_scsiio="no"],
+[#include <sys/types.h>
+ #include <sys/scsiio.h>])
+
 dnl ***************** check for solaris uscsi interface ********
 AC_CHECK_TYPES([struct uscsi_cmd],[has_uscsi="yes"],[has_uscsi="no"],
 [#include <sys/types.h>
@@ -95,15 +100,18 @@ if test x"$has_cam" = x"yes"; then
     BRASERO_SCSI_LIBS="-lcam"
 elif test x"$has_sg" = x"yes"; then
 	:
+elif test x"$has_scsiio" = x"yes"; then
+	:
 elif test x"$has_uscsi" = x"yes"; then
 	:
 else
-	AC_ERROR([Support Linux SG, FreeBSD CAM, Solaris USCSI. No supported SCSI interface headers could not be found.])
+	AC_ERROR([Support Linux SG, FreeBSD CAM, NetBSD SCSIPI, Solaris USCSI. No supported SCSI interface headers could not be found.])
 fi
 
 AM_CONDITIONAL(HAVE_CAM_LIB_H, test x"$has_cam" = "xyes")
 AM_CONDITIONAL(HAVE_SG_IO_HDR_T, test x"$has_sg" = "xyes")
 AM_CONDITIONAL(HAVE_USCSI_H, test x"$has_uscsi" = "xyes")
+AM_CONDITIONAL(HAVE_SCSIIO_H, test x"$has_scsiio" = "xyes")
 
 dnl ***************** LARGE FILE SUPPORT ***********************
 
diff --git a/libbrasero-media/Makefile.am b/libbrasero-media/Makefile.am
index 192a110..8d0dc47 100644
--- a/libbrasero-media/Makefile.am
+++ b/libbrasero-media/Makefile.am
@@ -140,6 +140,11 @@ if HAVE_SG_IO_HDR_T
 libbrasero_media_la_SOURCES += scsi-sg.c
 endif
 
+# NetBSD's scsi(4)
+if HAVE_SCSIIO_H
+libbrasero_media_la_SOURCES += scsi-netbsd.c
+endif
+
 # Solaris's USCSI interface
 if HAVE_USCSI_H
 libbrasero_media_la_SOURCES += scsi-uscsi.c
diff --git a/libbrasero-media/scsi-netbsd.c b/libbrasero-media/scsi-netbsd.c
new file mode 100644
index 0000000..b4f5737
--- /dev/null
+++ b/libbrasero-media/scsi-netbsd.c
@@ -0,0 +1,200 @@
+/* $NetBSD: scsi-netbsd.c,v 1.2 2009/03/22 09:30:39 wiz Exp $ */
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ * Libbrasero-media
+ * Copyright (C) Philippe Rouquier 2005-2009 <bonfire-app wanadoo fr>
+ *               Jared D. McNeill 2009 <jmcneill NetBSD org>
+ *
+ * Libbrasero-media 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.
+ *
+ * The Libbrasero-media authors hereby grant permission for non-GPL compatible
+ * GStreamer plugins to be used and distributed together with GStreamer
+ * and Libbrasero-media. This permission is above and beyond the permissions granted
+ * by the GPL license by which Libbrasero-media is covered. If you modify this code
+ * you may extend this exception to your version of the code, but you are not
+ * obligated to do so. If you do not wish to do so, delete this exception
+ * statement from your version.
+ * 
+ * Libbrasero-media 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 <sys/scsiio.h>
+
+#include "brasero-media-private.h"
+
+#include "scsi-command.h"
+#include "scsi-utils.h"
+#include "scsi-error.h"
+#include "scsi-sense-data.h"
+
+struct _BraseroDeviceHandle {
+	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_RDWR|O_NONBLOCK)
+#define SCSIREQ_TIMEOUT			(30 * 1000)
+
+/**
+ * This is to send a command
+ */
+
+static void
+brasero_sg_command_setup (scsireq_t *req,
+			  BraseroScsiCmd *cmd,
+			  uchar *buffer,
+			  int size)
+{
+	memset (req, 0, sizeof (scsireq_t));
+
+	req->cmdlen = cmd->info->size;
+	memcpy(req->cmd, cmd->cmd, req->cmdlen);
+	req->databuf = buffer;
+	req->datalen = size;
+	req->timeout = SCSIREQ_TIMEOUT;
+
+	/* where to output the scsi sense buffer */
+	req->senselen = BRASERO_SENSE_DATA_SIZE;
+
+	if (cmd->info->direction & BRASERO_SCSI_READ)
+		req->flags = SCCMD_READ;
+	else if (cmd->info->direction & BRASERO_SCSI_WRITE)
+		req->flags = SCCMD_WRITE;
+}
+
+BraseroScsiResult
+brasero_scsi_command_issue_sync (gpointer command,
+				 gpointer buffer,
+				 int size,
+				 BraseroScsiErrCode *error)
+{
+	scsireq_t req;
+	BraseroScsiResult res;
+	BraseroScsiCmd *cmd;
+
+	cmd = command;
+	brasero_sg_command_setup (&req,
+				  cmd,
+				  buffer,
+				  size);
+
+	res = ioctl (cmd->handle->fd, SCIOCCOMMAND, &req);
+	if (res == -1) {
+		BRASERO_SCSI_SET_ERRCODE (error, BRASERO_SCSI_ERRNO);
+		return BRASERO_SCSI_FAILURE;
+	}
+
+	if (req.retsts == SCCMD_OK)
+		return BRASERO_SCSI_OK;
+
+	if (req.retsts == SCCMD_SENSE)
+		return brasero_sense_data_process (req.sense, error);
+
+	return BRASERO_SCSI_FAILURE;
+}
+
+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,
+			    gboolean exclusive,
+			    BraseroScsiErrCode *code)
+{
+	int fd;
+	int flags = OPEN_FLAGS;
+	BraseroDeviceHandle *handle;
+	gchar *rdevnode;
+
+	if (exclusive)
+		flags |= O_EXCL;
+
+	rdevnode = g_strdup_printf ("/dev/r%s", path + strlen ("/dev/"));
+	fd = open (rdevnode, flags);
+	g_free (rdevnode);
+	if (fd < 0) {
+		if (code) {
+			if (errno == EAGAIN
+			||  errno == EWOULDBLOCK
+			||  errno == EBUSY)
+				*code = BRASERO_SCSI_NOT_READY;
+			else
+				*code = BRASERO_SCSI_ERRNO;
+		}
+
+		return NULL;
+	}
+
+	handle = g_new (BraseroDeviceHandle, 1);
+	handle->fd = fd;
+
+	return handle;
+}
+
+void
+brasero_device_handle_close (BraseroDeviceHandle *handle)
+{
+	close (handle->fd);
+	g_free (handle);
+}
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]