[brasero] Rework the way bus/target/lun is handled to remove some ifdef from the code.



commit 87472c94d8984ace4928f4cd6b698ae7ee9bb131
Author: Philippe Rouquier <bonfire-app wanadoo fr>
Date:   Tue Aug 4 15:54:35 2009 +0200

    Rework the way bus/target/lun is handled to remove some ifdef from the code.

 libbrasero-media/brasero-drive.c |   30 ++++++++----------------------
 libbrasero-media/scsi-cam.c      |   20 ++++++++++++++++++++
 libbrasero-media/scsi-device.h   |    3 +++
 libbrasero-media/scsi-netbsd.c   |    5 +++++
 libbrasero-media/scsi-sg.c       |    5 +++++
 libbrasero-media/scsi-uscsi.c    |    5 +++++
 plugins/cdrdao/burn-cdrdao.c     |   26 ++++++++++++--------------
 plugins/cdrtools/burn-cdrecord.c |   12 +++++-------
 plugins/cdrtools/burn-mkisofs.c  |   10 ++++------
 plugins/cdrtools/burn-readcd.c   |    8 ++++----
 10 files changed, 71 insertions(+), 53 deletions(-)
---
diff --git a/libbrasero-media/brasero-drive.c b/libbrasero-media/brasero-drive.c
index fd308c9..a5bb8c6 100644
--- a/libbrasero-media/brasero-drive.c
+++ b/libbrasero-media/brasero-drive.c
@@ -271,37 +271,21 @@ brasero_drive_cancel_current_operation (BraseroDrive *drive)
  * Returns the bus, target, lun ("{bus},{target},{lun}") as a string which is
  * sometimes needed by some backends like cdrecord.
  *
+ * NOTE: that function returns either bus/target/lun or the device path
+ * according to OSes. Basically it returns bus/target/lun only for FreeBSD
+ * which is the only OS in need for that. For all others it returns the device
+ * path. 
+ *
  * Return value: a string or NULL. The string must be freed when not needed
  *
  **/
 gchar *
 brasero_drive_get_bus_target_lun_string (BraseroDrive *drive)
 {
-#ifdef HAVE_CAM_LIB_H
-	struct cam_device *cam_dev;
-	char *addr;
-#endif
-
 	g_return_val_if_fail (drive != NULL, NULL);
 	g_return_val_if_fail (BRASERO_IS_DRIVE (drive), NULL);
 
-#ifdef HAVE_CAM_LIB_H
-	cam_dev = cam_open_device (brasero_drive_get_device (drive), O_RDWR);
-
-	if (cam_dev == NULL) {
-		BRASERO_MEDIA_LOG ("CAM: Failed to open %s: %s", brasero_drive_get_device (drive), g_strerror (errno));
-		return NULL;
-	}
-
-	addr = g_strdup_printf ("%i,%i,%i", cam_dev->path_id, cam_dev->target_id, cam_dev->target_lun);
-
-	cam_close_device (cam_dev);
-
-	return addr;
-#else
-
-	return NULL;
-#endif
+	return brasero_device_get_bus_target_lun (brasero_drive_get_device (drive));
 }
 
 /**
@@ -530,6 +514,8 @@ brasero_drive_get_device (BraseroDrive *drive)
  * some other OSes, like Solaris, for burning operations instead of the device
  * path.
  *
+ * If such a path is not available, it returns the device path.
+ *
  * Return value: a string holding the block device path
  **/
 const gchar *
diff --git a/libbrasero-media/scsi-cam.c b/libbrasero-media/scsi-cam.c
index 191671a..9d2f2ad 100644
--- a/libbrasero-media/scsi-cam.c
+++ b/libbrasero-media/scsi-cam.c
@@ -47,6 +47,8 @@
 #include <string.h>
 #include <sys/ioctl.h>
 
+#include <glib.h>
+
 #include "brasero-media-private.h"
 #include "scsi-command.h"
 #include "scsi-utils.h"
@@ -210,3 +212,21 @@ brasero_device_handle_close (BraseroDeviceHandle *handle)
 	g_free (handle);
 }
 
+char *
+brasero_device_get_bus_target_lun (const gchar *device)
+{
+	struct cam_device *cam_dev;
+	char *addr;
+
+	cam_dev = cam_open_device (device, O_RDWR);
+
+	if (cam_dev == NULL) {
+		BRASERO_MEDIA_LOG ("CAM: Failed to open %s: %s", device, g_strerror (errno));
+		return NULL;
+	}
+
+	addr = g_strdup_printf ("%i,%i,%i", cam_dev->path_id, cam_dev->target_id, cam_dev->target_lun);
+
+	cam_close_device (cam_dev);
+	return addr;
+}
diff --git a/libbrasero-media/scsi-device.h b/libbrasero-media/scsi-device.h
index 99b47bc..08ceb86 100644
--- a/libbrasero-media/scsi-device.h
+++ b/libbrasero-media/scsi-device.h
@@ -47,6 +47,9 @@ brasero_device_handle_open (const gchar *path,
 void
 brasero_device_handle_close (BraseroDeviceHandle *handle);
 
+char *
+brasero_device_get_bus_target_lun (const gchar *device);
+
 G_END_DECLS
 
 #endif /* _SCSI_DEVICE_H */
diff --git a/libbrasero-media/scsi-netbsd.c b/libbrasero-media/scsi-netbsd.c
index b4f5737..72fbe05 100644
--- a/libbrasero-media/scsi-netbsd.c
+++ b/libbrasero-media/scsi-netbsd.c
@@ -198,3 +198,8 @@ brasero_device_handle_close (BraseroDeviceHandle *handle)
 	g_free (handle);
 }
 
+char *
+brasero_device_get_bus_target_lun (const gchar *device)
+{
+	return strdup (device);
+}
diff --git a/libbrasero-media/scsi-sg.c b/libbrasero-media/scsi-sg.c
index c8362c1..6769a7e 100644
--- a/libbrasero-media/scsi-sg.c
+++ b/libbrasero-media/scsi-sg.c
@@ -204,3 +204,8 @@ brasero_device_handle_close (BraseroDeviceHandle *handle)
 	g_free (handle);
 }
 
+char *
+brasero_device_get_bus_target_lun (const gchar *device)
+{
+	return strdup (device);
+}
diff --git a/libbrasero-media/scsi-uscsi.c b/libbrasero-media/scsi-uscsi.c
index 6b1430f..b1f409a 100644
--- a/libbrasero-media/scsi-uscsi.c
+++ b/libbrasero-media/scsi-uscsi.c
@@ -236,3 +236,8 @@ brasero_device_handle_close (BraseroDeviceHandle *handle)
 	g_free (handle);
 }
 
+char *
+brasero_device_get_bus_target_lun (const gchar *device)
+{
+	return strdup (device);
+}
diff --git a/plugins/cdrdao/burn-cdrdao.c b/plugins/cdrdao/burn-cdrdao.c
index e67e889..d050751 100644
--- a/plugins/cdrdao/burn-cdrdao.c
+++ b/plugins/cdrdao/burn-cdrdao.c
@@ -260,13 +260,11 @@ brasero_cdrdao_set_argv_device (BraseroCdrdao *cdrdao,
 
 	g_ptr_array_add (argv, g_strdup ("--device"));
 
-#ifdef HAVE_CAM_LIB_H
-	/* FreeBSD like that better */
+	/* NOTE: that function returns either bus_target_lun or the device path
+	 * according to OSes. Basically it returns bus/target/lun only for FreeBSD
+	 * which is the only OS in need for that. For all others it returns the device
+	 * path. */
 	brasero_job_get_bus_target_lun (BRASERO_JOB (cdrdao), &device);
-#else
-	brasero_job_get_device (BRASERO_JOB (cdrdao), &device);
-#endif
-
 	g_ptr_array_add (argv, device);
 }
 
@@ -346,11 +344,11 @@ brasero_cdrdao_set_argv_record (BraseroCdrdao *cdrdao,
 		brasero_job_get_current_track (BRASERO_JOB (cdrdao), &track);
 		drive = brasero_track_disc_get_drive (BRASERO_TRACK_DISC (track));
 
-#ifdef HAVE_CAM_LIB_H
+		/* NOTE: that function returns either bus_target_lun or the device path
+		 * according to OSes. Basically it returns bus/target/lun only for FreeBSD
+		 * which is the only OS in need for that. For all others it returns the device
+		 * path. */
 		g_ptr_array_add (argv, brasero_drive_get_bus_target_lun_string (drive));
-#else
-		g_ptr_array_add (argv, g_strdup (brasero_drive_get_device (drive)));
-#endif
 	}
 	else if (brasero_track_type_get_has_image (type)) {
 		gchar *cuepath;
@@ -446,11 +444,11 @@ brasero_cdrdao_set_argv_image (BraseroCdrdao *cdrdao,
 	brasero_job_get_current_track (BRASERO_JOB (cdrdao), &track);
 	drive = brasero_track_disc_get_drive (BRASERO_TRACK_DISC (track));
 
-#ifdef HAVE_CAM_LIB_H
+	/* NOTE: that function returns either bus_target_lun or the device path
+	 * according to OSes. Basically it returns bus/target/lun only for FreeBSD
+	 * which is the only OS in need for that. For all others it returns the device
+	 * path. */
 	g_ptr_array_add (argv, brasero_drive_get_bus_target_lun_string (drive));
-#else
-	g_ptr_array_add (argv, g_strdup (brasero_drive_get_device (drive)));
-#endif
 	g_ptr_array_add (argv, g_strdup ("--read-raw"));
 
 	/* This is done so that if a cue file is required we first generate
diff --git a/plugins/cdrtools/burn-cdrecord.c b/plugins/cdrtools/burn-cdrecord.c
index 9963e6f..1b7cc8f 100644
--- a/plugins/cdrtools/burn-cdrecord.c
+++ b/plugins/cdrtools/burn-cdrecord.c
@@ -1005,8 +1005,8 @@ brasero_cdrecord_set_argv (BraseroProcess *process,
 	BraseroBurnResult result;
 	BraseroJobAction action;
 	BraseroBurnFlag flags;
+	gchar *device = NULL;
 	gchar *dev_str;
-	gchar *device;
 
 	cdrecord = BRASERO_CD_RECORD (process);
 	priv = BRASERO_CD_RECORD_PRIVATE (cdrecord);
@@ -1018,13 +1018,11 @@ brasero_cdrecord_set_argv (BraseroProcess *process,
 	g_ptr_array_add (argv, g_strdup ("cdrecord"));
 	g_ptr_array_add (argv, g_strdup ("-v"));
 
-#ifdef HAVE_CAM_LIB_H
-	/* FreeBSD like that better */
+	/* NOTE: that function returns either bus_target_lun or the device path
+	 * according to OSes. Basically it returns bus/target/lun only for FreeBSD
+	 * which is the only OS in need for that. For all others it returns the device
+	 * path. */
 	brasero_job_get_bus_target_lun (BRASERO_JOB (cdrecord), &device);
-#else
-	brasero_job_get_device (BRASERO_JOB (cdrecord), &device);
-#endif
-
 	dev_str = g_strdup_printf ("dev=%s", device);
 	g_ptr_array_add (argv, dev_str);
 	g_free (device);
diff --git a/plugins/cdrtools/burn-mkisofs.c b/plugins/cdrtools/burn-mkisofs.c
index 4b13496..15bc3a3 100644
--- a/plugins/cdrtools/burn-mkisofs.c
+++ b/plugins/cdrtools/burn-mkisofs.c
@@ -378,13 +378,11 @@ brasero_mkisofs_set_argv_image (BraseroMkisofs *mkisofs,
 
 			g_ptr_array_add (argv, g_strdup ("-M"));
 
-#ifdef HAVE_CAM_LIB_H
-	/* FreeBSD like that better */
+			/* NOTE: that function returns either bus_target_lun or the device path
+			 * according to OSes. Basically it returns bus/target/lun only for FreeBSD
+			 * which is the only OS in need for that. For all others it returns the device
+			 * path. */
 			brasero_job_get_bus_target_lun (BRASERO_JOB (mkisofs), &device);
-#else
-			brasero_job_get_device (BRASERO_JOB (mkisofs), &device);
-#endif
-
 			g_ptr_array_add (argv, device);
 		}
 	}
diff --git a/plugins/cdrtools/burn-readcd.c b/plugins/cdrtools/burn-readcd.c
index 03db3c2..e8514cf 100644
--- a/plugins/cdrtools/burn-readcd.c
+++ b/plugins/cdrtools/burn-readcd.c
@@ -344,11 +344,11 @@ brasero_readcd_set_argv (BraseroProcess *process,
 	brasero_job_get_current_track (BRASERO_JOB (readcd), &track);
 	drive = brasero_track_disc_get_drive (BRASERO_TRACK_DISC (track));
 
-#ifdef HAVE_CAM_LIB_H
+	/* NOTE: that function returns either bus_target_lun or the device path
+	 * according to OSes. Basically it returns bus/target/lun only for FreeBSD
+	 * which is the only OS in need for that. For all others it returns the device
+	 * path. */
 	device = brasero_drive_get_bus_target_lun_string (drive);
-#else
-	device = g_strdup (brasero_drive_get_device (drive));
-#endif
 
 	if (!device)
 		return BRASERO_BURN_ERR;



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