[brasero] lock/unlock drive tray through MMC commands and not HAL



commit fb0f2298e99b79320894b450fe97b4b67802bbb6
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Fri Jul 10 14:31:50 2009 +0200

    lock/unlock drive tray through MMC commands and not HAL

 libbrasero-media/Makefile.am                       |    3 +-
 libbrasero-media/brasero-drive.c                   |   64 +++++---------
 libbrasero-media/brasero-medium-monitor.c          |    2 +-
 libbrasero-media/brasero-volume.c                  |    1 -
 libbrasero-media/scsi-opcodes.h                    |    6 ++
 .../scsi-prevent-allow-medium-removal.c            |   93 ++++++++++++++++++++
 libbrasero-media/scsi-sbc.h                        |    5 +
 7 files changed, 131 insertions(+), 43 deletions(-)
---
diff --git a/libbrasero-media/Makefile.am b/libbrasero-media/Makefile.am
index be5baa5..459e7db 100644
--- a/libbrasero-media/Makefile.am
+++ b/libbrasero-media/Makefile.am
@@ -129,7 +129,8 @@ libbrasero_media_la_SOURCES =		\
 	brasero-medium-selection-priv.h         \
 	brasero-gio-operation.h         \
 	brasero-gio-operation.c         \
-	scsi-inquiry.c
+	scsi-inquiry.c         \
+	scsi-prevent-allow-medium-removal.c
 
 # FreeBSD's SCSI CAM interface
 if HAVE_CAM_LIB_H
diff --git a/libbrasero-media/brasero-drive.c b/libbrasero-media/brasero-drive.c
index 4dd7de2..186a945 100644
--- a/libbrasero-media/brasero-drive.c
+++ b/libbrasero-media/brasero-drive.c
@@ -44,11 +44,11 @@
 
 #include "brasero-media-private.h"
 #include "brasero-gio-operation.h"
+#include "burn-hal-watch.h"
 
 #include "brasero-medium.h"
 #include "brasero-volume.h"
 #include "brasero-drive.h"
-#include "burn-hal-watch.h"
 
 #include "scsi-device.h"
 #include "scsi-utils.h"
@@ -57,6 +57,7 @@
 #include "scsi-mmc2.h"
 #include "scsi-status-page.h"
 #include "scsi-mode-pages.h"
+#include "scsi-sbc.h"
 
 #if defined(HAVE_STRUCT_USCSI_CMD)
 #define BLOCK_DEVICE	"block.solaris.raw_device"
@@ -352,12 +353,10 @@ brasero_drive_lock (BraseroDrive *drive,
 		    const gchar *reason,
 		    gchar **reason_for_failure)
 {
+	BraseroDeviceHandle *handle;
 	BraseroDrivePrivate *priv;
-	BraseroHALWatch *watch;
-	LibHalContext *ctx;
-	DBusError error;
+	const gchar *device;
 	gboolean result;
-	gchar *failure;
 
 	g_return_val_if_fail (drive != NULL, FALSE);
 	g_return_val_if_fail (BRASERO_IS_DRIVE (drive), FALSE);
@@ -366,31 +365,17 @@ brasero_drive_lock (BraseroDrive *drive,
 	if (!priv->gdrive)
 		return FALSE;
 
-	watch = brasero_hal_watch_get_default ();
-	ctx = brasero_hal_watch_get_ctx (watch);
-
-	dbus_error_init (&error);
-	result = libhal_device_lock (ctx,
-				     priv->udi,
-				     reason,
-				     &failure,
-				     &error);
-
-	if (dbus_error_is_set (&error))
-		dbus_error_free (&error);
-
-	if (reason_for_failure)
-		*reason_for_failure = g_strdup (failure);
-
-	if (failure)
-		dbus_free (failure);
+	device = brasero_drive_get_device (drive);
+	handle = brasero_device_handle_open (device, FALSE, NULL);
+	if (!handle)
+		return FALSE;
 
-	if (result) {
-		BRASERO_MEDIA_LOG ("Device locked");
-	}
-	else {
+	result = (brasero_sbc_medium_removal (handle, 1, NULL) == BRASERO_SCSI_OK);
+	if (!result) {
 		BRASERO_MEDIA_LOG ("Device failed to lock");
 	}
+	else
+		BRASERO_MEDIA_LOG ("Device locked");
 
 	return result;
 }
@@ -406,10 +391,9 @@ brasero_drive_lock (BraseroDrive *drive,
 gboolean
 brasero_drive_unlock (BraseroDrive *drive)
 {
+	BraseroDeviceHandle *handle;
 	BraseroDrivePrivate *priv;
-	BraseroHALWatch *watch;
-	LibHalContext *ctx;
-	DBusError error;
+	const gchar *device;
 	gboolean result;
 
 	g_return_val_if_fail (drive != NULL, FALSE);
@@ -419,18 +403,18 @@ brasero_drive_unlock (BraseroDrive *drive)
 	if (!priv->gdrive)
 		return FALSE;
 
-	watch = brasero_hal_watch_get_default ();
-	ctx = brasero_hal_watch_get_ctx (watch);
-
-	dbus_error_init (&error);
-	result = libhal_device_unlock (ctx,
-				       priv->udi,
-				       &error);
+	device = brasero_drive_get_device (drive);
+	handle = brasero_device_handle_open (device, FALSE, NULL);
+	if (!handle)
+		return FALSE;
 
-	if (dbus_error_is_set (&error))
-		dbus_error_free (&error);
+	result = (brasero_sbc_medium_removal (handle, 0, NULL) == BRASERO_SCSI_OK);
+	if (!result) {
+		BRASERO_MEDIA_LOG ("Device failed to unlock");
+	}
+	else
+		BRASERO_MEDIA_LOG ("Device unlocked");
 
-	BRASERO_MEDIA_LOG ("Device unlocked");
 	return result;
 }
 
diff --git a/libbrasero-media/brasero-medium-monitor.c b/libbrasero-media/brasero-medium-monitor.c
index 9c826e3..5d42556 100644
--- a/libbrasero-media/brasero-medium-monitor.c
+++ b/libbrasero-media/brasero-medium-monitor.c
@@ -394,7 +394,7 @@ brasero_medium_monitor_disconnected_cb (GVolumeMonitor *monitor,
 
 	priv = BRASERO_MEDIUM_MONITOR_PRIVATE (self);
 
-	BRASERO_MEDIA_LOG ("HAL signal device removed");
+	BRASERO_MEDIA_LOG ("Device removed");
 
 	for (iter = priv->drives; iter; iter = next) {
 		GDrive *gdrive_iter;
diff --git a/libbrasero-media/brasero-volume.c b/libbrasero-media/brasero-volume.c
index e7a8890..4365412 100644
--- a/libbrasero-media/brasero-volume.c
+++ b/libbrasero-media/brasero-volume.c
@@ -418,7 +418,6 @@ last_chance:
 		name = g_strdup_printf (_("Data %s"), type);
 	}
 	else {
-		/* NOTE for translators: the first %s is the disc type. */
 		name = g_strdup (type);
 	}
 
diff --git a/libbrasero-media/scsi-opcodes.h b/libbrasero-media/scsi-opcodes.h
index d7d5f62..c48f1ca 100644
--- a/libbrasero-media/scsi-opcodes.h
+++ b/libbrasero-media/scsi-opcodes.h
@@ -36,6 +36,12 @@
 G_BEGIN_DECLS
 
 /**
+ *	SBC1
+ */
+
+#define BRASERO_PREVENT_ALLOW_MEDIUM_REMOVAL_OPCODE		0x1E
+
+/**
  *	SPC1
  */
 
diff --git a/libbrasero-media/scsi-prevent-allow-medium-removal.c b/libbrasero-media/scsi-prevent-allow-medium-removal.c
new file mode 100644
index 0000000..8c9e5e9
--- /dev/null
+++ b/libbrasero-media/scsi-prevent-allow-medium-removal.c
@@ -0,0 +1,93 @@
+/* -*- 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>
+ *
+ * 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 <glib.h>
+
+#include "scsi-error.h"
+#include "scsi-utils.h"
+#include "scsi-base.h"
+#include "scsi-command.h"
+#include "scsi-opcodes.h"
+
+#if G_BYTE_ORDER == G_LITTLE_ENDIAN
+
+struct _BraseroScsiPreventAllowMediumRemovalUnitCDB {
+	uchar opcode;
+
+	uchar res1			[3];
+
+	uchar prevent			:2;
+	uchar res4			:6;
+
+	uchar ctl;
+};
+
+#else
+
+struct _BraseroScsiPreventAllowMediumRemovalUnitCDB {
+	uchar opcode;
+
+	uchar res1			[3];
+
+	uchar res4			:6;
+	uchar prevent			:2;
+
+	uchar ctl;
+};
+
+#endif
+
+typedef struct _BraseroScsiPreventAllowMediumRemovalUnitCDB BraseroScsiPreventAllowMediumRemovalUnitCDB;
+
+BRASERO_SCSI_COMMAND_DEFINE (BraseroScsiPreventAllowMediumRemovalUnitCDB,
+			     PREVENT_ALLOW_MEDIUM_REMOVAL,
+			     BRASERO_SCSI_READ);
+
+BraseroScsiResult
+brasero_sbc_medium_removal (BraseroDeviceHandle *handle,
+                            int prevent_removal,
+                            BraseroScsiErrCode *error)
+{
+	BraseroScsiPreventAllowMediumRemovalUnitCDB *cdb;
+	BraseroScsiResult res;
+
+	cdb = brasero_scsi_command_new (&info, handle);
+	cdb->prevent = prevent_removal;
+	res = brasero_scsi_command_issue_sync (cdb,
+					       NULL,
+					       0,
+					       error);
+	brasero_scsi_command_free (cdb);
+	return res;
+}
diff --git a/libbrasero-media/scsi-sbc.h b/libbrasero-media/scsi-sbc.h
index 305c2be..2394b40 100644
--- a/libbrasero-media/scsi-sbc.h
+++ b/libbrasero-media/scsi-sbc.h
@@ -39,6 +39,11 @@
 G_BEGIN_DECLS
 
 BraseroScsiResult
+brasero_sbc_medium_removal (BraseroDeviceHandle *handle,
+                            int prevent_removal,
+                            BraseroScsiErrCode *error);
+
+BraseroScsiResult
 brasero_sbc_read10_block (BraseroDeviceHandle *handle,
 			  int start,
 			  int num_blocks,



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