hal: Branch 'master' - 9 commits

Joe Marcus Clarke marcus at kemper.freedesktop.org
Sun Dec 23 21:37:27 PST 2007


 hald/freebsd/hf-acpi.c              |   12 ++
 hald/freebsd/hf-devd.c              |   29 ++++++
 hald/freebsd/hf-net.c               |   34 +++++++-
 hald/freebsd/hf-pci.c               |    3 
 hald/freebsd/hf-scsi.c              |    6 -
 hald/freebsd/hf-storage.c           |    9 +-
 hald/freebsd/probing/probe-volume.c |  151 +++++++++++++++++++++++-------------
 7 files changed, 183 insertions(+), 61 deletions(-)

New commits:
commit 4675ce2b7984f09241c4458154329f6cc62d27d8
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Mon Dec 24 00:34:27 2007 -0500

    remove the need for cdrtools and add MBREXT support
    
    * Do multimedia disc type detection internally instead of relying on isoinfo
      from cdrtools. [1]
    * Add MBREXT (i.e. embr) support.
    
    Submitted by:	Alexander Nedodsukov [1]

diff --git a/hald/freebsd/probing/probe-volume.c b/hald/freebsd/probing/probe-volume.c
index 9268e00..4736788 100644
--- a/hald/freebsd/probing/probe-volume.c
+++ b/hald/freebsd/probing/probe-volume.c
@@ -3,7 +3,7 @@
  *
  * probe-volume.c : volume prober
  *
- * Copyright (C) 2006 Jean-Yves Lefort <jylefort at FreeBSD.org>
+ * Copyright (C) 2006, 2007 Jean-Yves Lefort <jylefort at FreeBSD.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -35,6 +35,9 @@
 #include <sys/ioctl.h>
 #include <sys/disk.h>
 #include <sys/cdio.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <isofs/cd9660/iso.h>
 #include <glib.h>
 #include <libvolume_id.h>
 
@@ -44,6 +47,32 @@
 
 #include "freebsd_dvd_rw_utils.h"
 
+#define ISO_VOLDESC_SEC        16
+
+struct iso_path_table_entry
+{
+  char name_len               [ISODCL(1,1)];
+  char ext_attr_len           [ISODCL(2,2)];
+  char extent                 [ISODCL(3,6)];
+  char parent_no              [ISODCL(7,8)];
+  char name[1];
+};
+#define ISO_PATH_TABLE_ENTRY_SIZE         8
+
+#if __FreeBSD_version < 600101
+static uint32_t
+isonum_731(unsigned char *p)
+{
+  return (p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24);
+}
+
+static uint32_t
+isonum_732(unsigned char *p)
+{
+  return (p[3] | p[2] << 8 | p[1] << 16 | p[0] << 24);
+}
+#endif
+
 static uintmax_t
 hf_probe_volume_getenv_uintmax (const char *name)
 {
@@ -129,63 +158,76 @@ hf_probe_volume_get_disc_info (int fd,
 }
 
 static void
-hf_probe_volume_advanced_disc_detect (const char *device_file)
+hf_probe_volume_advanced_disc_detect (int fd)
 {
-  GError *err = NULL;
-  char *command;
-  int exit_status;
-  char *output;
-  char **lines;
-  int i;
-
-  g_return_if_fail(device_file != NULL);
+  size_t secsz = ISO_DEFAULT_BLOCK_SIZE;
+  int readoff;
+  struct iso_primary_descriptor desc;
+  u_char *ptbl;
+  int ptbl_size, ptbl_bsize;
+  int ptbl_lbn;
+  struct iso_path_table_entry *pte;
+  int pte_len;
+  int name_len;
+  int off;
+
+  readoff = ISO_VOLDESC_SEC * secsz;
+  do
+    {
+      if (pread(fd, &desc, sizeof desc, readoff) != sizeof desc)
+        {
+          hfp_warning("volume descriptor read error");
+	  return;
+	}
+      if (isonum_711(desc.type) == ISO_VD_END)
+        return;
+      readoff += secsz;
+    }
+  while (isonum_711(desc.type) != ISO_VD_PRIMARY);
 
-  command = g_strdup_printf("isoinfo -p -i %s", device_file);
-  if (! g_spawn_command_line_sync(command, &output, NULL, &exit_status, &err))
+  ptbl_size = isonum_733(desc.path_table_size);
+#if BYTE_ORDER == LITTLE_ENDIAN
+  ptbl_lbn = isonum_731(desc.type_l_path_table);
+#else
+  ptbl_lbn = isonum_732(desc.type_m_path_table);
+#endif
+  ptbl_bsize = (ptbl_size + secsz - 1) / secsz * secsz;
+  ptbl = g_malloc(ptbl_bsize);
+  if (ptbl == NULL)
     {
-      hfp_warning("unable to run \"%s\": %s", command, err->message);
-      g_error_free(err);
-      goto end;
+      hfp_warning("path table allocation failure");
+      return;
     }
-  if (exit_status != 0)
+  readoff = ptbl_lbn * secsz;
+  if (pread(fd, ptbl, ptbl_bsize, readoff) != ptbl_bsize)
     {
-      hfp_warning("\"%s\" returned with status %i", command, exit_status);
-      goto end;
+      g_free(ptbl);
+      hfp_warning("path table read error");
     }
-
-  lines = g_strsplit(output, "\n", 0);
-  g_free(output);
-
-  for (i = 0; lines[i]; i++)
+  for (off = 0; off < ptbl_size; off += pte_len)
     {
-      int index;
-      int pindex;
-      int extent;
-      char dirname[strlen(lines[i]) + 1];
-
-      if (sscanf(lines[i], "%i: %i %x %s", &index, &pindex, &extent, dirname) == 4)
-	{
-	  if (! g_ascii_strcasecmp(dirname, "VIDEO_TS"))
-	    {
-	      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "volume.disc.is_videodvd", TRUE, &hfp_error);
-	      break;
-	    }
-	  else if (! g_ascii_strcasecmp(dirname, "VCD"))
-	    {
-	      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "volume.disc.is_vcd", TRUE, &hfp_error);
-	      break;
-	    }
-	  else if (! g_ascii_strcasecmp(dirname, "SVCD"))
-	    {
-	      libhal_device_set_property_bool(hfp_ctx, hfp_udi, "volume.disc.is_svcd", TRUE, &hfp_error);
-	      break;
-	    }
+      pte = (struct iso_path_table_entry *)(ptbl + off);
+      name_len = *pte->name_len;
+      pte_len = ISO_PATH_TABLE_ENTRY_SIZE + name_len + (name_len % 2);
+      if (*(short *)pte->parent_no != 1)
+        continue;
+      if (name_len == 8 && strncmp(pte->name, "VIDEO_TS", 8) == 0)
+        {
+          libhal_device_set_property_bool(hfp_ctx, hfp_udi, "volume.disc.is_videodvd", TRUE, &hfp_error);
+	  break;
+	}
+      else if (name_len == 3 && strncmp(pte->name, "VCD", 8) == 0)
+        {
+          libhal_device_set_property_bool(hfp_ctx, hfp_udi, "volume.disc.is_vcd", TRUE, &hfp_error);
+	  break;
+	}
+      else if (name_len == 4 && strncmp(pte->name, "SVCD", 4) == 0)
+        {
+          libhal_device_set_property_bool(hfp_ctx, hfp_udi, "volume.disc.is_svcd", TRUE, &hfp_error);
+	  break;
 	}
     }
-  g_strfreev(lines);
-
- end:
-  g_free(command);
+  g_free(ptbl);
 }
 
 static gboolean
@@ -206,6 +248,7 @@ hf_probe_volume_get_partition_info (const char *geom_class,
   g_return_val_if_fail(offset != NULL, FALSE);
 
   if (strcmp(geom_class, "MBR") &&
+      strcmp(geom_class, "MBREXT") &&
       strcmp(geom_class, "GPT") &&
       strcmp(geom_class, "SUN") &&
       strcmp(geom_class, "APPLE"))
@@ -241,7 +284,13 @@ hf_probe_volume_get_partition_info (const char *geom_class,
       *scheme = g_strdup("apm");
     }
 
-  if (! strcmp(*scheme, "mbr"))
+  if (! strcmp(*scheme, "mbrext"))
+    {
+      g_free(*scheme);
+      *scheme = g_strdup("embr");
+    }
+
+  if (! strcmp(*scheme, "mbr") || ! strcmp(*scheme, "embr"))
     *type = g_strdup_printf("0x%x",
                             hf_probe_volume_getenv_int("HF_VOLUME_PART_TYPE"));
   else
@@ -454,7 +503,7 @@ main (int argc, char **argv)
 	}
 
       if (has_data)
-	hf_probe_volume_advanced_disc_detect(device_file);
+        hf_probe_volume_advanced_disc_detect(fd);
     }
   else
     {
commit 4f983389c13ad4ba4f4c74586a7a510b28e15b07
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Sun Dec 23 23:57:05 2007 -0500

    bump the copyright year
    
    Add 2007 to the list of copyright years.

diff --git a/hald/freebsd/hf-storage.c b/hald/freebsd/hf-storage.c
index dbbc9fd..06b5f04 100644
--- a/hald/freebsd/hf-storage.c
+++ b/hald/freebsd/hf-storage.c
@@ -3,7 +3,7 @@
  *
  * hf-storage.c : storage device support
  *
- * Copyright (C) 2006 Jean-Yves Lefort <jylefort at FreeBSD.org>
+ * Copyright (C) 2006, 2007 Jean-Yves Lefort <jylefort at FreeBSD.org>
  *                    Joe Marcus Clarke <marcus at FreeBSD.org>
  *
  * This program is free software; you can redistribute it and/or modify
commit 8ed08087c2ffe0fa55628e23b99b0ea4a4af79ed
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Sun Dec 23 23:56:43 2007 -0500

    add MBREXT support
    
    Add support for the MBREXT GEOM class.

diff --git a/hald/freebsd/hf-storage.c b/hald/freebsd/hf-storage.c
index 347aef3..dbbc9fd 100644
--- a/hald/freebsd/hf-storage.c
+++ b/hald/freebsd/hf-storage.c
@@ -102,7 +102,9 @@ hf_storage_get_disk_names (GError **err)
 static gboolean
 hf_storage_class_is_partitionable (const char *geom_class)
 {
-  return (! strcmp(geom_class, "MBR") || ! strcmp(geom_class, "GPT") ||
+  return (! strcmp(geom_class, "MBR") ||
+          ! strcmp(geom_class, "MBREXT") ||
+	  ! strcmp(geom_class, "GPT") ||
           ! strcmp(geom_class, "APPLE") || ! strcmp(geom_class, "SUN"));
 }
 
@@ -143,7 +145,8 @@ hf_storage_geom_is_swap (const Geom_Object *geom_obj)
   g_return_val_if_fail(geom_obj != NULL, FALSE);
 
   return (! strcmp(geom_obj->class, "BSD") && geom_obj->type == FS_SWAP)
-    || (! strcmp(geom_obj->class, "MBR")
+	|| ((! strcmp(geom_obj->class, "MBR") ||
+             ! strcmp(geom_obj->class, "MBREXT"))
 	&& (geom_obj->type == 0x18		/* AST Windows swapfile */
 	    || geom_obj->type == 0x42		/* SFS or Linux swap */
 	    || geom_obj->type == 0x82		/* Linux swap or Solaris x86 */
commit 5ed53cb7c5ebfdaa88c4fd561a4670bb1d17653a
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Sun Dec 23 23:50:46 2007 -0500

    add support for medium_changer devices
    
    Fix media changer support by adapting a patch from Linux's hal backend.
    
    Submitted by:	truckman

diff --git a/hald/freebsd/hf-scsi.c b/hald/freebsd/hf-scsi.c
index 41e204b..f6d0c45 100644
--- a/hald/freebsd/hf-scsi.c
+++ b/hald/freebsd/hf-scsi.c
@@ -54,7 +54,7 @@ static int hf_scsi_fd;
 static gboolean
 hf_scsi_is_cdrom (int type)
 {
-  return (type == T_CDROM || type == T_WORM || type == T_CHANGER || type == T_OPTICAL);
+  return (type == T_CDROM || type == T_WORM || type == T_OPTICAL);
 }
 
 static HalDevice *
@@ -131,11 +131,13 @@ hf_scsi_scsi_device_new (HalDevice *parent,
       hal_device_property_set_string(device, "scsi.type", "processor");
       break;
     case T_WORM:
-    case T_CHANGER:
     case T_CDROM:
     case T_OPTICAL:
       hal_device_property_set_string(device, "scsi.type", "cdrom");
       break;
+    case T_CHANGER:
+      hal_device_property_set_string(device, "scsi.type", "medium_changer");
+      break;
     case T_SCANNER:
       hal_device_property_set_string(device, "scsi.type", "scanner");
       break;
commit f92797628c430e42b30b4065a3137f3920dc27f7
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Sun Dec 23 23:48:19 2007 -0500

    probe all PCI buses
    
    Be sure to probe all PCI buses, even PCI Express.

diff --git a/hald/freebsd/hf-pci.c b/hald/freebsd/hf-pci.c
index 8709913..85c6f72 100644
--- a/hald/freebsd/hf-pci.c
+++ b/hald/freebsd/hf-pci.c
@@ -53,6 +53,7 @@
 #define PCIR_HDRTYPE			0x0e
 #define PCIM_HDRTYPE_BRIDGE		0x01
 #define PCIM_HDRTYPE_CARDBUS		0x02
+#define PCIM_MFDEV                      0x80
 
 typedef struct
 {
@@ -250,7 +251,7 @@ hf_pci_probe_bus (HalDevice *parent, int bus, bitstr_t *busmap)
             continue;	/* device ignored */
 	}
 
-      if (info->header_type == PCIM_HDRTYPE_BRIDGE || info->header_type == PCIM_HDRTYPE_CARDBUS)
+      if (info->header_type == PCIM_HDRTYPE_BRIDGE || info->header_type == PCIM_HDRTYPE_CARDBUS || (info->header_type & ~PCIM_MFDEV) == PCIM_HDRTYPE_BRIDGE || (info->header_type & ~PCIM_MFDEV) == PCIM_HDRTYPE_CARDBUS)
         /* a bridge or cardbus, probe its children */
         hf_pci_probe_bus(info->device, info->secondary_bus, busmap);
     }
commit 69cfb4475aafc8d9ed8e8f2f123297e01130ef12
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Sun Dec 23 23:45:37 2007 -0500

    add support for net.80203.rate and net.freebsd.ifindex
    
    Add support for setting a FreeBSD-specific property, net.freebsd.ifindex, and
    the net.80203.rate property.

diff --git a/hald/freebsd/hf-net.c b/hald/freebsd/hf-net.c
index 79e0a04..b5ea85f 100644
--- a/hald/freebsd/hf-net.c
+++ b/hald/freebsd/hf-net.c
@@ -4,7 +4,7 @@
  * hf-net.c : networking device support
  *
  * Copyright (C) 2006 Jean-Yves Lefort <jylefort at FreeBSD.org>
- * Copyright (C) 2006 Joe Marcus Clarke <marcus at FreeBSD.org>
+ * Copyright (C) 2006, 2007 Joe Marcus Clarke <marcus at FreeBSD.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,9 +32,12 @@
 #include <sys/ioctl.h>
 #include <sys/socket.h>
 #include <sys/sockio.h>
+#include <sys/sysctl.h>
+#include <sys/time.h>
 #include <net/if.h>
 #include <net/if_arp.h>
 #include <net/if_media.h>
+#include <net/if_mib.h>
 
 #include "../hald_dbus.h"
 #include "../logger.h"
@@ -68,6 +71,30 @@ hf_net_get_link_up (const char *interface)
   return is_up;
 }
 
+static guint64
+hf_net_get_rate (int ifindex)
+{
+  struct ifmibdata ifmd;
+  int oid[6];
+  size_t len;
+  guint64 result;
+
+  oid[0] = CTL_NET;
+  oid[1] = PF_LINK;
+  oid[2] = IFMIB_IFDATA;
+  oid[3] = ifindex;
+  oid[4] = IFDATA_GENERAL;
+
+  len = sizeof(ifmd);
+
+  if (sysctl(oid, sizeof(oid)/sizeof(int), &ifmd, &len, NULL, 0) == -1)
+    result = 0;
+  else
+    result = ifmd.ifmd_data.ifi_baudrate;
+
+  return result;
+}
+
 static void
 hf_net_device_set_link_up (HalDevice *device, gboolean is_up)
 {
@@ -84,6 +111,7 @@ hf_net_device_new (const char *interface, HalDevice *parent, GError **err)
   char *output;
   char **lines;
   int i;
+  int ifindex;
   GError *tmp_err = NULL;
   const char *mac = NULL;
   const char *media = NULL;
@@ -142,6 +170,9 @@ hf_net_device_new (const char *interface, HalDevice *parent, GError **err)
     hal_device_property_set_int(device, "net.arp_proto_hw_id", ARPHRD_IEEE802);
   /* FIXME Add additional net.arp_proto_hw_id support */
 
+  ifindex = if_nametoindex(interface);
+  hal_device_property_set_int(device, "net.freebsd.infindex", ifindex);
+
   if (is_ethernet)
     {
       dbus_uint64_t numeric_mac = 0;
@@ -168,6 +199,7 @@ hf_net_device_new (const char *interface, HalDevice *parent, GError **err)
           hal_device_add_capability(device, "net.80203");
           hal_device_property_set_string(device, "info.category", "net.80203");
           hal_device_property_set_uint64(device, "net.80203.mac_address", numeric_mac);
+	  hal_device_property_set_uint64(device, "net.80203.rate", hf_net_get_rate(ifindex));
         }
     }
   else
commit 7ba9131c962dc71b40d0b44e39a1d213a206e4a1
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Sun Dec 23 23:33:23 2007 -0500

    recover from devd being restarted
    
    Attempt to recover if we lose connectivity to the devd socket.  Without this
    hald would spin on the CPU constantly even if devd is restarted.

diff --git a/hald/freebsd/hf-devd.c b/hald/freebsd/hf-devd.c
index 383a38b..d878a45 100644
--- a/hald/freebsd/hf-devd.c
+++ b/hald/freebsd/hf-devd.c
@@ -3,7 +3,7 @@
  *
  * hf-devd.c : process devd events
  *
- * Copyright (C) 2006 Joe Marcus Clarke <marcus at FreeBSD.org>
+ * Copyright (C) 2006, 2007 Joe Marcus Clarke <marcus at FreeBSD.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -57,6 +57,10 @@ static HFDevdHandler *handlers[] = {
   &hf_pcmcia_devd_handler
 };
 
+static gboolean hf_devd_inited = FALSE;
+
+static void hf_devd_init (void);
+
 static GHashTable *
 hf_devd_parse_params (const char *str)
 {
@@ -370,16 +374,33 @@ hf_devd_event_cb (GIOChannel *source, GIOCondition condition,
 {
   char *event;
   gsize terminator;
+  GIOStatus status;
 
   if (hf_is_waiting)
     return TRUE;
 
-  if (g_io_channel_read_line(source, &event, NULL, &terminator, NULL) == G_IO_STATUS_NORMAL)
+  status = g_io_channel_read_line(source, &event, NULL, &terminator, NULL);
+
+  if (status != G_IO_STATUS_NORMAL)
     {
       event[terminator] = 0;
       hf_devd_process_event(event);
       g_free(event);
     }
+  else if (status != G_IO_STATUS_AGAIN)
+    {
+      hf_devd_init();
+      if (hf_devd_inited)
+        {
+          int fd;
+
+	  fd = g_io_channel_unix_get_fd(source);
+	  g_io_channel_shutdown(source, FALSE, NULL);
+	  close(fd);
+
+	  return FALSE;
+	}
+    }
 
   return TRUE;
 }
@@ -394,6 +415,7 @@ hf_devd_init (void)
   if (event_fd < 0)
     {
       HAL_WARNING(("failed to create event socket: %s", g_strerror(errno)));
+      hf_devd_inited = FALSE;
       return;
     }
 
@@ -405,12 +427,15 @@ hf_devd_init (void)
 
       channel = g_io_channel_unix_new(event_fd);
       g_io_add_watch(channel, G_IO_IN, hf_devd_event_cb, NULL);
+      g_io_channel_unref(channel);
+      hf_devd_inited = TRUE;
     }
   else
     {
       HAL_WARNING(("failed to connect to %s: %s", HF_DEVD_SOCK_PATH,
                    g_strerror(errno)));
       close(event_fd);
+      hf_devd_inited = FALSE;
     }
 }
 
commit 7d23d097a835be7da0590635157406b5c42e30f4
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Sun Dec 23 23:21:58 2007 -0500

    bump the copyright year
    
    Add 2007 to the copyright year list.

diff --git a/hald/freebsd/hf-acpi.c b/hald/freebsd/hf-acpi.c
index d76b98b..89243df 100644
--- a/hald/freebsd/hf-acpi.c
+++ b/hald/freebsd/hf-acpi.c
@@ -3,7 +3,7 @@
  *
  * hf-acpi.c : poll for ACPI properties
  *
- * Copyright (C) 2006 Joe Marcus Clarke <marcus at FreeBSD.org>
+ * Copyright (C) 2006, 2007 Joe Marcus Clarke <marcus at FreeBSD.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
commit 895909e93acc17355762224517743b89cbf487bc
Author: Joe Marcus Clarke <marcus at FreeBSD.org>
Date:   Sun Dec 23 23:20:50 2007 -0500

    handle the case where ACPI reports the rate as all ones
    
    Adapt a patch from the linux backend to handle the case where
    ACPI reports a rate of all ones.

diff --git a/hald/freebsd/hf-acpi.c b/hald/freebsd/hf-acpi.c
index 8097dd7..d76b98b 100644
--- a/hald/freebsd/hf-acpi.c
+++ b/hald/freebsd/hf-acpi.c
@@ -172,6 +172,16 @@ hf_acpi_poll_batt (HalDevice *device)
 
   hal_device_property_set_string(device, "battery.charge_level.unit", "mWh");
 
+  /*
+   * ACPI gives out the special 'Ones' value for rate when it's unable
+   * to calculate the true rate. We should set the rate zero, and wait
+   * or the BIOS to stabilize.
+   *
+   * full details here: http://bugzilla.gnome.org/show_bug.cgi?id=348201
+   */
+  if (rate == 0xffff)
+    rate = 0;
+
   if (battif.bif.units == ACPI_BIF_UNITS_MA)
     {
        hal_device_property_set_string(device, "battery.reporting.units", "mAh");


More information about the hal-commit mailing list