hal: Branch 'origin'

Richard Hughes hughsient at kemper.freedesktop.org
Mon Jan 1 14:17:42 PST 2007


 hald/freebsd/addons/addon-storage.c  |    7 ++++
 hald/freebsd/libprobe/hfp-cdrom.c    |   50 +++++++++++++++++++++++++++++------
 hald/freebsd/libprobe/hfp-cdrom.h    |    4 +-
 hald/freebsd/probing/probe-storage.c |   15 +++++++---
 hald/freebsd/probing/probe-volume.c  |    2 -
 5 files changed, 62 insertions(+), 16 deletions(-)

New commits:
diff-tree 5a809031ebb898497b1003af1d8e6c739f565c1d (from 71b2a0b15a55d4d8f2739297b9998f721053bff4)
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Sun Dec 24 18:57:39 2006 -0500

    fix ATA support for FreeBSD 5.X
    
    Allow volume probing to work for ATA devices (e.g. CD-ROMs) under FreeBSD
    5.X.  The initial support for 5.X was incomplete.

diff --git a/hald/freebsd/addons/addon-storage.c b/hald/freebsd/addons/addon-storage.c
index 8a11670..c327749 100644
--- a/hald/freebsd/addons/addon-storage.c
+++ b/hald/freebsd/addons/addon-storage.c
@@ -40,6 +40,7 @@ static struct
 {
   const struct timeval	update_interval;
   char			*device_file;
+  char			*parent;
   boolean		is_cdrom;
   boolean		had_media;
   struct timeval	next_update;
@@ -78,7 +79,7 @@ hf_addon_storage_update (void)
     {
       HFPCDROM *cdrom;
 
-      cdrom = hfp_cdrom_new(addon.device_file);
+      cdrom = hfp_cdrom_new(addon.device_file, addon.parent);
       if (cdrom)
 	{
 	  if (hfp_cdrom_test_unit_ready(cdrom))
@@ -128,6 +129,10 @@ main (int argc, char **argv)
   if (! drive_type)
     goto end;
 
+  addon.parent = getenv("HAL_PROP_INFO_PARENT");
+  if (! addon.parent)
+    goto end;
+
   /* give a meaningful process title for ps(1) */
   setproctitle("%s", addon.device_file);
 
diff --git a/hald/freebsd/libprobe/hfp-cdrom.c b/hald/freebsd/libprobe/hfp-cdrom.c
index 286dd29..11d6fa3 100644
--- a/hald/freebsd/libprobe/hfp-cdrom.c
+++ b/hald/freebsd/libprobe/hfp-cdrom.c
@@ -42,18 +42,24 @@
 
 struct _HFPCDROM
 {
-  struct cam_device	*cam;	/* for SCSI drives */
-  int			fd;	/* for ATAPI drives */
+  struct cam_device	*cam;		/* for SCSI drives */
+  int			fd;		/* for ATAPI drives */
+  int			channel;	/* for ATAPI on 5.X */
+  int			device;		/* for ATAPI on 5.X */
   boolean		fd_owned;
 };
 
 static HFPCDROM *
-hfp_cdrom_new_real (boolean has_fd, int fd, const char *path)
+hfp_cdrom_new_real (boolean has_fd,
+                    int fd,
+                    const char *path,
+                    const char *parent)
 {
   HFPCDROM *cdrom = NULL;
   struct cam_device *cam;
 
   assert(path != NULL);
+  assert(parent != NULL);
 
   /* cam_open_device() fails unless we use O_RDWR */
   cam = cam_open_device(path, O_RDWR);
@@ -65,13 +71,33 @@ hfp_cdrom_new_real (boolean has_fd, int 
     }
   else
     {
+#ifndef IOCATAREQUEST
+      fd = open("/dev/ata", O_RDONLY);
+#else
       if (! has_fd)
 	fd = open(path, O_RDONLY);
+#endif
       if (fd >= 0)
 	{
 	  cdrom = hfp_new0(HFPCDROM, 1);
 	  cdrom->fd = fd;
+#ifndef IOCATAREQUEST
+          cdrom->fd_owned = TRUE;
+          cdrom->channel = libhal_device_get_property_int(hfp_ctx,
+                                                          parent,
+							  "ide.host",
+							  &hfp_error);
+	  dbus_error_free(&hfp_error);
+	  cdrom->device = libhal_device_get_property_int(hfp_ctx,
+                                                         parent,
+							 "ide.channel",
+							 &hfp_error);
+	  dbus_error_free(&hfp_error);
+#else
 	  cdrom->fd_owned = ! has_fd;
+	  cdrom->channel = -1;
+	  cdrom->device = -1;
+#endif
 	}
     }
 
@@ -79,19 +105,21 @@ hfp_cdrom_new_real (boolean has_fd, int 
 }
 
 HFPCDROM *
-hfp_cdrom_new (const char *path)
+hfp_cdrom_new (const char *path, const char *parent)
 {
   assert(path != NULL);
+  assert(parent != NULL);
 
-  return hfp_cdrom_new_real(FALSE, -1, path);
+  return hfp_cdrom_new_real(FALSE, -1, path, parent);
 }
 
 HFPCDROM *
-hfp_cdrom_new_from_fd (int fd, const char *path)
+hfp_cdrom_new_from_fd (int fd, const char *path, const char *parent)
 {
   assert(path != NULL);
+  assert(parent != NULL);
 
-  return hfp_cdrom_new_real(TRUE, fd, path);
+  return hfp_cdrom_new_real(TRUE, fd, path, parent);
 }
 
 boolean
@@ -144,11 +172,17 @@ hfp_cdrom_send_ccb (HFPCDROM *cdrom,
 #else
       struct ata_cmd iocmd;
 
+      /* Better to assert here than panic the machine. */
+      /* XXX Should this be a conditional?  How likely is this? */
+      assert(cdrom->channel >= 0);
+      assert(cdrom->device >= 0 && cdrom->device < 2);
+
       memset(&iocmd, 0, sizeof(iocmd));
       iocmd.u.request.flags = ATA_CMD_ATAPI;
       iocmd.u.request.timeout = timeout;
       iocmd.cmd = ATAREQUEST;
-      iocmd.device = -1;
+      iocmd.channel = cdrom->channel;
+      iocmd.device = cdrom->device;
       memcpy(iocmd.u.request.u.atapi.ccb, ccb, 16);
 
       if (data)
diff --git a/hald/freebsd/libprobe/hfp-cdrom.h b/hald/freebsd/libprobe/hfp-cdrom.h
index 6b69f0f..584b98e 100644
--- a/hald/freebsd/libprobe/hfp-cdrom.h
+++ b/hald/freebsd/libprobe/hfp-cdrom.h
@@ -145,8 +145,8 @@ typedef struct
   u_int16_t   reserved4;
 } HFPCDROMCapabilities;
 
-HFPCDROM *hfp_cdrom_new (const char *path);
-HFPCDROM *hfp_cdrom_new_from_fd (int fd, const char *path);
+HFPCDROM *hfp_cdrom_new (const char *path, const char *parent);
+HFPCDROM *hfp_cdrom_new_from_fd (int fd, const char *path, const char *parent);
 
 boolean hfp_cdrom_send_ccb (HFPCDROM *cdrom,
 			    char ccb[16],
diff --git a/hald/freebsd/probing/probe-storage.c b/hald/freebsd/probing/probe-storage.c
index c875542..1d06c32 100644
--- a/hald/freebsd/probing/probe-storage.c
+++ b/hald/freebsd/probing/probe-storage.c
@@ -43,7 +43,8 @@
 #include "freebsd_dvd_rw_utils.h"
 
 static void
-hf_probe_storage_get_cdrom_capabilities (const char *device_file)
+hf_probe_storage_get_cdrom_capabilities (const char *device_file,
+                                         const char *parent)
 {
   HFPCDROM *cdrom;
   HFPCDROMCapabilities caps;
@@ -54,8 +55,9 @@ hf_probe_storage_get_cdrom_capabilities 
   char *write_speeds;
 
   g_return_if_fail(device_file != NULL);
+  g_return_if_fail(parent != NULL);
 
-  cdrom = hfp_cdrom_new(device_file);
+  cdrom = hfp_cdrom_new(device_file, parent);
   if (! cdrom)
     {
       hfp_warning("unable to open CD-ROM device %s", device_file);
@@ -150,6 +152,7 @@ main (int argc, char **argv)
 {
   char *device_file;
   char *drive_type;
+  char *parent;
   int ret = 0;			/* no media/filesystem */
   gboolean has_children;
   gboolean only_check_for_media;
@@ -166,6 +169,10 @@ main (int argc, char **argv)
   if (! drive_type)
     goto end;
 
+  parent = getenv("HAL_PROP_INFO_PARENT");
+  if (! parent)
+    goto end;
+
   /* give a meaningful process title for ps(1) */
   setproctitle("%s", device_file);
 
@@ -175,13 +182,13 @@ main (int argc, char **argv)
   is_cdrom = ! strcmp(drive_type, "cdrom");
 
   if (! only_check_for_media && is_cdrom)
-    hf_probe_storage_get_cdrom_capabilities(device_file);
+    hf_probe_storage_get_cdrom_capabilities(device_file, parent);
 
   if (is_cdrom)
     {
       HFPCDROM *cdrom;
 
-      cdrom = hfp_cdrom_new(device_file);
+      cdrom = hfp_cdrom_new(device_file, parent);
       if (! cdrom)
 	goto end;
 
diff --git a/hald/freebsd/probing/probe-volume.c b/hald/freebsd/probing/probe-volume.c
index b8f0a96..259f3e3 100644
--- a/hald/freebsd/probing/probe-volume.c
+++ b/hald/freebsd/probing/probe-volume.c
@@ -364,7 +364,7 @@ main (int argc, char **argv)
 
       /* the following code was adapted from linux's probe-volume.c */
 
-      cdrom = hfp_cdrom_new_from_fd(fd, device_file);
+      cdrom = hfp_cdrom_new_from_fd(fd, device_file, parent_udi);
       if (cdrom)
 	{
 	  type = get_disc_type(cdrom);


More information about the hal-commit mailing list