brasero r1163 - in trunk: . src



Author: philippr
Date: Sun Aug 24 18:40:50 2008
New Revision: 1163
URL: http://svn.gnome.org/viewvc/brasero?rev=1163&view=rev

Log:
	Implemented READ (10) function and use it when possible

	* src/Makefile.am:
	* src/burn-volume-source.c (brasero_volume_source_read_fd),
	(brasero_volume_source_readcd_device_handle),
	(brasero_volume_source_read10_device_handle),
	(brasero_volume_source_open_device_handle):
	* src/scsi-opcodes.h:
	* src/scsi-read10.c (brasero_sbc_read10_block):


Added:
   trunk/src/scsi-read10.c
Modified:
   trunk/ChangeLog
   trunk/src/Makefile.am
   trunk/src/burn-volume-source.c
   trunk/src/scsi-opcodes.h

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Sun Aug 24 18:40:50 2008
@@ -268,7 +268,9 @@
 	brasero-video-tree-model.c         \
 	brasero-video-tree-model.h         \
 	scsi-write-page.h         \
-	scsi-mode-select.c
+	scsi-mode-select.c         \
+	scsi-read10.c         \
+	scsi-sbc.h
 
 if BUILD_INOTIFY
 brasero_SOURCES += brasero-file-monitor.c brasero-file-monitor.h

Modified: trunk/src/burn-volume-source.c
==============================================================================
--- trunk/src/burn-volume-source.c	(original)
+++ trunk/src/burn-volume-source.c	Sun Aug 24 18:40:50 2008
@@ -35,6 +35,8 @@
 #include "burn-iso9660.h"
 
 #include "scsi-mmc1.h"
+#include "scsi-mmc2.h"
+#include "scsi-sbc.h"
 
 static gint64
 brasero_volume_source_seek_device_handle (BraseroVolSrc *src,
@@ -86,6 +88,8 @@
 {
 	guint64 bytes_read;
 
+	BRASERO_BURN_LOG ("Using fread()");
+
 	bytes_read = fread (buffer, 1, ISO9660_BLOCK_SIZE * blocks, src->data);
 	if (bytes_read != ISO9660_BLOCK_SIZE * blocks) {
 		BRASERO_BURN_LOG ("fread () failed (%s)", strerror (errno));
@@ -100,15 +104,15 @@
 }
 
 static gboolean
-brasero_volume_source_read_device_handle (BraseroVolSrc *src,
-					  gchar *buffer,
-					  guint blocks,
-					  GError **error)
+brasero_volume_source_readcd_device_handle (BraseroVolSrc *src,
+					    gchar *buffer,
+					    guint blocks,
+					    GError **error)
 {
 	BraseroScsiResult result;
 	BraseroScsiErrCode code;
 
-	BRASERO_BURN_LOG ("Reading with track mode %i", src->data_mode);
+	BRASERO_BURN_LOG ("Using READCD. Reading with track mode %i", src->data_mode);
 	result = brasero_mmc1_read_block (src->data,
 					  TRUE,
 					  src->data_mode,
@@ -165,6 +169,35 @@
 	return FALSE;
 }
 
+static gboolean
+brasero_volume_source_read10_device_handle (BraseroVolSrc *src,
+					    gchar *buffer,
+					    guint blocks,
+					    GError **error)
+{
+	BraseroScsiResult result;
+	BraseroScsiErrCode code;
+
+	BRASERO_BURN_LOG ("Using READ10");
+	result = brasero_sbc_read10_block (src->data,
+					   src->position,
+					   blocks,
+					   (unsigned char *) buffer,
+					   blocks * ISO9660_BLOCK_SIZE,
+					   &code);
+	if (result == BRASERO_SCSI_OK) {
+		src->position += blocks;
+		return TRUE;
+	}
+
+	g_set_error (error,
+		     BRASERO_BURN_ERROR,
+		     BRASERO_BURN_ERROR_GENERAL,
+		     brasero_scsi_strerror (code));
+
+	return FALSE;
+}
+
 void
 brasero_volume_source_close (BraseroVolSrc *src)
 {
@@ -245,13 +278,37 @@
 brasero_volume_source_open_device_handle (BraseroDeviceHandle *handle,
 					  GError **error)
 {
+	int size;
 	BraseroVolSrc *src;
+	BraseroScsiResult result;
+	BraseroScsiGetConfigHdr *hdr = NULL;
 
 	src = g_new0 (BraseroVolSrc, 1);
 	src->ref = 1;
 	src->data = handle;
 	src->seek = brasero_volume_source_seek_device_handle;
-	src->read = brasero_volume_source_read_device_handle;
+
+	/* check which read function should be used. */
+	result = brasero_mmc2_get_configuration_feature (handle,
+							 BRASERO_SCSI_FEAT_RD_DVD,
+							 &hdr,
+							 &size,
+							 NULL);
+	if (result != BRASERO_SCSI_OK) {
+		BRASERO_BURN_LOG ("GET CONFIGURATION failed for feature READ DVD. Using READCD.");
+		src->read = brasero_volume_source_readcd_device_handle;
+	}
+	else if (!hdr->desc->current) {
+		BRASERO_BURN_LOG ("READ DVD not current. Using READCD.");
+		src->read = brasero_volume_source_readcd_device_handle;
+		g_free (hdr);
+	}
+	else {
+		BRASERO_BURN_LOG ("READ DVD current. Using READ10");
+		src->read = brasero_volume_source_read10_device_handle;
+		g_free (hdr);
+	}
+
 	return src;
 }
 

Modified: trunk/src/scsi-opcodes.h
==============================================================================
--- trunk/src/scsi-opcodes.h	(original)
+++ trunk/src/scsi-opcodes.h	Sun Aug 24 18:40:50 2008
@@ -63,6 +63,7 @@
 #define BRASERO_GET_CONFIGURATION_OPCODE		0x46
 #define BRASERO_READ_CAPACITY_OPCODE			0x25
 #define BRASERO_READ_FORMAT_CAPACITIES_OPCODE		0x23
+#define BRASERO_READ10_OPCODE				0x28
 
 /**
  *	MMC3

Added: trunk/src/scsi-read10.c
==============================================================================
--- (empty file)
+++ trunk/src/scsi-read10.c	Sun Aug 24 18:40:50 2008
@@ -0,0 +1,115 @@
+/***************************************************************************
+ *            scsi-read10.c
+ *
+ *  Sun Jan 27 20:39:40 2008
+ *  Copyright  2008  Philippe Rouquier
+ *  <bonfire-app wanadoo fr>
+ ****************************************************************************/
+
+/*
+ * Brasero 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.
+ * 
+ * Brasero 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 _BraseroRead10CDB {
+	uchar opcode;
+
+	uchar reladr		:1;
+	uchar reserved1		:2;
+	uchar FUA		:1;
+	uchar DPO		:1;
+	uchar reserved2		:3;
+
+	uchar start_address	[4];
+
+	uchar reserved3;
+
+	uchar len		[2];	
+
+	uchar ctl;
+};
+
+#else
+
+struct _BraseroRead10CDB {
+	uchar opcode;
+
+	uchar reserved2		:3;
+	uchar DPO		:1;
+	uchar FUA		:1;
+	uchar reserved1		:2;
+	uchar reladr		:1;
+
+	uchar start_address	[4];
+
+	uchar reserved3;
+
+	uchar len		[2];	
+
+	uchar ctl;
+};
+
+#endif
+
+typedef struct _BraseroRead10CDB BraseroRead10CDB;
+
+BRASERO_SCSI_COMMAND_DEFINE (BraseroRead10CDB,
+			     READ10,
+			     BRASERO_SCSI_READ);
+
+BraseroScsiResult
+brasero_sbc_read10_block (BraseroDeviceHandle *handle,
+			  int start,
+			  int num_blocks,
+			  unsigned char *buffer,
+			  int buffer_size,
+			  BraseroScsiErrCode *error)
+{
+	BraseroRead10CDB *cdb;
+	BraseroScsiResult res;
+
+	cdb = brasero_scsi_command_new (&info, handle);
+	BRASERO_SET_32 (cdb->start_address, start);
+
+	/* NOTE: if we just want to test if block is readable len can be 0 */
+	BRASERO_SET_16 (cdb->len, num_blocks);
+
+	/* reladr should be 0 */
+	/* DPO should be 0 */
+
+	/* This is to force reading media ==> no caching */
+	cdb->FUA = 1;
+
+	memset (buffer, 0, buffer_size);
+	res = brasero_scsi_command_issue_sync (cdb,
+					       buffer,
+					       buffer_size,
+					       error);
+	brasero_scsi_command_free (cdb);
+	return res;
+}



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