hal/hald/linux block_class_device.c, 1.86, 1.87 bus_device.c, 1.19,
1.20 class_device.c, 1.29, 1.30 common.c, 1.15, 1.16 common.h,
1.10, 1.11 net_class_device.c, 1.21, 1.22 osspec.c, 1.52,
1.53 platform_bus_device.c, 1.6, 1.7
David Zeuthen
david at freedesktop.org
Mon Dec 13 18:57:50 PST 2004
Update of /cvs/hal/hal/hald/linux
In directory gabe:/tmp/cvs-serv31002/hald/linux
Modified Files:
block_class_device.c bus_device.c class_device.c common.c
common.h net_class_device.c osspec.c platform_bus_device.c
Log Message:
2004-12-13 David Zeuthen <davidz at redhat.com>
Merged all changes from the stable branch so HEAD is on par.
Index: block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -d -r1.86 -r1.87
--- block_class_device.c 19 Oct 2004 22:58:03 -0000 1.86
+++ block_class_device.c 14 Dec 2004 02:57:48 -0000 1.87
@@ -71,8 +71,6 @@
* @{
*/
-static void etc_mtab_process_all_block_devices (dbus_bool_t force);
-
static char *block_class_compute_udi (HalDevice * d, int append_num);
#if 0
@@ -198,7 +196,6 @@
{
HalDevice *d;
HalDevice *parent;
- char *parent_sysfs_path;
ClassAsyncData *cad;
struct sysfs_device *sysdevice;
@@ -220,10 +217,12 @@
sysdevice = sysfs_get_classdev_device (class_device);
if (sysdevice == NULL) {
- parent_sysfs_path = get_parent_sysfs_path (path);
+ parent = find_closest_ancestor (path);
hal_device_property_set_bool (d, "block.is_volume", TRUE);
} else {
- parent_sysfs_path = sysdevice->path;
+ parent = hal_device_store_match_key_value_string (hald_get_gdl (),
+ "linux.sysfs_path_device",
+ sysdevice->path);
hal_device_property_set_bool (d, "block.is_volume", FALSE);
}
@@ -256,15 +255,21 @@
* sure to be added before us (we probe devices in the right order
* and we reorder hotplug events)
*/
- parent = hal_device_store_match_key_value_string (hald_get_gdl (),
- "linux.sysfs_path_device",
- parent_sysfs_path);
if (parent == NULL) {
hal_device_store_remove (hald_get_tdl (), d);
d = NULL;
goto out;
}
+ /* Never add e.g. /dev/hdd4 as child of /dev/hdd if /dev/hdd is without partitions (e.g. zip disks) */
+ if (hal_device_has_property (parent, "storage.no_partitions_hint")) {
+ if (hal_device_property_get_bool (parent, "storage.no_partitions_hint")) {
+ hal_device_store_remove (hald_get_tdl (), d);
+ d = NULL;
+ goto out;
+ }
+ }
+
class_device_got_parent_device (hald_get_tdl (), parent, cad);
out:
@@ -349,7 +354,7 @@
}
/* while we're at it, check if we support media changed */
- if (ioctl (fd, CDROM_MEDIA_CHANGED) >= 0) {
+ if (capabilities & CDC_MEDIA_CHANGED) {
hal_device_property_set_bool (d, "storage.cdrom.support_media_changed", TRUE);
} else {
hal_device_property_set_bool (d, "storage.cdrom.support_media_changed", FALSE);
@@ -376,6 +381,8 @@
static void
force_unmount (HalDevice * d)
{
+ const char *storudi;
+ HalDevice *stordev;
const char *device_file;
const char *device_mount_point;
const char *umount_argv[4] = { "/bin/umount", "-l", NULL, NULL };
@@ -384,8 +391,19 @@
int umount_exitcode;
device_file = hal_device_property_get_string (d, "block.device");
- device_mount_point =
- hal_device_property_get_string (d, "volume.mount_point");
+ device_mount_point = hal_device_property_get_string (d, "volume.mount_point");
+
+ /* Only attempt to 'umount -l' if some hal policy piece are performing policy on the device */
+ storudi = hal_device_property_get_string (d, "block.storage_device");
+ if (storudi == NULL)
+ return;
+ stordev = hal_device_store_find (hald_get_gdl (), storudi);
+ if (stordev == NULL)
+ return;
+ HAL_INFO (("foo = %d", hal_device_property_get_bool (stordev, "storage.policy.should_mount")));
+ if ((!hal_device_has_property (stordev, "storage.policy.should_mount")) ||
+ (!hal_device_property_get_bool (stordev, "storage.policy.should_mount")))
+ return;
umount_argv[2] = device_file;
@@ -861,7 +879,17 @@
break;
case CDS_DISC_OK:
- got_media = TRUE;
+ /* some CD-ROMs report CDS_DISK_OK even with an open
+ * tray; if media check has the same value two times in
+ * a row then this seems to be the case and we must not
+ * report that there is a media in it. */
+ if (hal_device_property_get_bool (d, "storage.cdrom.support_media_changed") &&
+ ioctl (fd, CDROM_MEDIA_CHANGED, CDSL_CURRENT) &&
+ ioctl (fd, CDROM_MEDIA_CHANGED, CDSL_CURRENT)) {
+ /*HAL_INFO (("CD-ROM drive %s: media checking is broken, assuming no CD is inside.", device_file));*/
+ } else {
+ got_media = TRUE;
+ }
break;
case -1:
@@ -948,7 +976,7 @@
child = get_child_device_gdl (d);
if (child == NULL) {
- get_child_device_tdl (d);
+ child = get_child_device_tdl (d);
}
if (child != NULL) {
return FALSE;
@@ -1366,43 +1394,19 @@
HAL_INFO (("Bus type is %s!",
hal_device_property_get_string (parent, "info.bus")));
- if (strcmp (hal_device_property_get_string (parent, "info.bus"),
- "ide") == 0) {
+ if (strcmp (hal_device_property_get_string (parent, "info.bus"), "ide") == 0) {
const char *ide_name;
char *model;
char *media;
+ /* Be conservative and don't poll IDE drives at all */
+ hal_device_property_set_bool (d, "storage.media_check_enabled", FALSE);
- /* blacklist the broken ide-cs driver */
- if (physdev != NULL) {
- size_t len;
- char buf[256];
- const char *physdev_sysfs_path;
-
- snprintf (buf, 256, "%s/devices/ide", sysfs_mount_path);
- len = strlen (buf);
-
- physdev_sysfs_path = hal_device_property_get_string (physdev, "linux.sysfs_path");
-
- if (strncmp (physdev_sysfs_path, buf, len) == 0) {
- hal_device_property_set_bool (stordev, "storage.media_check_enabled", FALSE);
- }
-
- HAL_INFO (("Working around broken ide-cs driver for %s", physdev->udi));
- }
-
-
- ide_name = get_last_element (hal_device_property_get_string
- (d, "linux.sysfs_path"));
-
+ ide_name = get_last_element (hal_device_property_get_string (d, "linux.sysfs_path"));
model = read_single_line ("/proc/ide/%s/model", ide_name);
if (model != NULL) {
- hal_device_property_set_string (stordev,
- "storage.model",
- model);
- hal_device_property_set_string (d,
- "info.product",
- model);
+ hal_device_property_set_string (stordev, "storage.model", model);
+ hal_device_property_set_string (d, "info.product", model);
}
/* According to the function proc_ide_read_media() in
@@ -1411,38 +1415,21 @@
* "UNKNOWN"
*/
- /** @todo Given floppy how
- * do we determine it's LS120?
- */
-
- media = read_single_line ("/proc/ide/%s/media",
- ide_name);
+ media = read_single_line ("/proc/ide/%s/media", ide_name);
if (media != NULL) {
- hal_device_property_set_string (stordev,
- "storage.drive_type",
- media);
+ hal_device_property_set_string (stordev, "storage.drive_type", media);
/* Set for removable media */
if (strcmp (media, "disk") == 0) {
/* left blank */
} else if (strcmp (media, "cdrom") == 0) {
has_removable_media = TRUE;
+ /* cdroms are the only IDE devices that are safe to poll */
+ hal_device_property_set_bool (d, "storage.media_check_enabled", TRUE);
} else if (strcmp (media, "floppy") == 0) {
has_removable_media = TRUE;
-
- /* I've got a LS120 that identifies as a
- * floppy; polling doesn't work so disable
- * media check and automount
- */
- hal_device_property_set_bool (
- d, "storage.media_check_enabled", FALSE);
- hal_device_property_set_bool (
- d, "storage.automount_enabled_hint", FALSE);
-
} else if (strcmp (media, "tape") == 0) {
has_removable_media = TRUE;
-
- /* TODO: Someone test with tape drives! */
}
}
@@ -1459,12 +1446,9 @@
did = drive_id_open_node(device_file);
if (drive_id_probe(did, DRIVE_ID_ATA) == 0) {
if (did->serial[0] != '\0')
- hal_device_property_set_string (stordev,
- "storage.serial",
- did->serial);
+ hal_device_property_set_string (stordev, "storage.serial", did->serial);
if (did->firmware[0] != '\0')
- hal_device_property_set_string (stordev,
- "storage.firmware_version",
+ hal_device_property_set_string (stordev, "storage.firmware_version",
did->firmware);
}
drive_id_close(did);
@@ -2020,6 +2004,7 @@
static gboolean
mtab_handle_storage (HalDevice *d)
{
+ const char *device_file;
HalDevice *child;
int major, minor;
dbus_bool_t found_mount_point;
@@ -2037,11 +2022,15 @@
major = hal_device_property_get_int (d, "block.major");
minor = hal_device_property_get_int (d, "block.minor");
+ device_file = hal_device_property_get_string (d, "block.device");
+
/* See if we already got children */
child = get_child_device_gdl (d);
- if (child == NULL)
- get_child_device_tdl (d);
+
+ if (child == NULL) {
+ child = get_child_device_tdl (d);
+ }
/* Search all mount points */
found_mount_point = FALSE;
@@ -2049,8 +2038,13 @@
mp = &mount_points[i];
- if (mp->major != major || mp->minor != minor)
- continue;
+ if (strcmp (device_file, mp->device) == 0) {
+ /* looks good */
+ } else {
+ /* device file don't match; try matching up major/minor numbers */
+ if (mp->major != major || mp->minor != minor)
+ continue;
+ }
if (child != NULL ) {
found_mount_point = TRUE;
@@ -2073,6 +2067,7 @@
static gboolean
mtab_handle_volume (HalDevice *d)
{
+ const char *device_file;
int major, minor;
dbus_bool_t found_mount_point;
struct mount_point_s *mp;
@@ -2082,6 +2077,7 @@
major = hal_device_property_get_int (d, "block.major");
minor = hal_device_property_get_int (d, "block.minor");
+ device_file = hal_device_property_get_string (d, "block.device");
/* these are handled in mtab_handle_storage */
storudi = hal_device_property_get_string (d, "block.storage_device");
@@ -2095,36 +2091,27 @@
found_mount_point = FALSE;
for (i = 0; i < num_mount_points; i++) {
mp = &mount_points[i];
-
- if (mp->major == major && mp->minor == minor) {
+
+
+ /* match on both device file and major/minor numbers */
+ if ((strcmp (device_file, mp->device) == 0) || (mp->major == major && mp->minor == minor)) {
const char *existing_block_device;
dbus_bool_t was_mounted;
device_property_atomic_update_begin ();
- existing_block_device =
- hal_device_property_get_string (d,
- "block.device");
+ existing_block_device = hal_device_property_get_string (d, "block.device");
- was_mounted =
- hal_device_property_get_bool (d,
- "volume.is_mounted");
+ was_mounted = hal_device_property_get_bool (d, "volume.is_mounted");
/* Yay! Found a mount point; set properties accordingly */
- hal_device_property_set_string (d,
- "volume.mount_point",
- mp->mount_point);
- hal_device_property_set_string (d, "volume.fstype",
- mp->fs_type);
- hal_device_property_set_bool (d,
- "volume.is_mounted",
- TRUE);
+ hal_device_property_set_string (d, "volume.mount_point", mp->mount_point);
+ hal_device_property_set_string (d, "volume.fstype", mp->fs_type);
+ hal_device_property_set_bool (d, "volume.is_mounted", TRUE);
/* only overwrite block.device if it's not set */
- if (existing_block_device == NULL ||
- (existing_block_device != NULL &&
- strcmp (existing_block_device,
- "") == 0)) {
+ if (existing_block_device == NULL || (existing_block_device != NULL &&
+ strcmp (existing_block_device, "") == 0)) {
hal_device_property_set_string (d,
"block.device",
mp->
@@ -2239,7 +2226,7 @@
*
* @param force Force reading of mtab
*/
-static void
+void
etc_mtab_process_all_block_devices (dbus_bool_t force)
{
/* Start or continue watching /etc */
Index: bus_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/bus_device.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- bus_device.c 28 Aug 2004 13:35:47 -0000 1.19
+++ bus_device.c 14 Dec 2004 02:57:48 -0000 1.20
@@ -87,7 +87,6 @@
{
HalDevice *d;
HalDevice *parent;
- char *parent_sysfs_path;
BusAsyncData *bad;
char buf[256];
@@ -107,8 +106,6 @@
snprintf (buf, sizeof(buf), "%s.linux.sysfs_path", self->hal_bus_name);
hal_device_property_set_string (d, buf, path);
- parent_sysfs_path = get_parent_sysfs_path (path);
-
bad = g_new0 (BusAsyncData, 1);
bad->device = d;
bad->handler = self;
@@ -121,13 +118,13 @@
goto out;
}
+
/* Find parent; this can happen synchronously as our parent is
* sure to be added before us (we probe devices in the right order
* and we reorder hotplug events)
*/
- parent = hal_device_store_match_key_value_string (hald_get_gdl (),
- "linux.sysfs_path_device",
- parent_sysfs_path);
+ parent = find_closest_ancestor (path);
+
if (parent == NULL) {
hal_device_store_remove (hald_get_tdl (), d);
d = NULL;
@@ -137,7 +134,6 @@
bus_device_got_parent (hald_get_gdl(), parent, bad);
out:
- free (parent_sysfs_path);
return d;
}
Index: class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/class_device.c,v
retrieving revision 1.29
retrieving revision 1.30
diff -u -d -r1.29 -r1.30
--- class_device.c 19 Oct 2004 22:58:03 -0000 1.29
+++ class_device.c 14 Dec 2004 02:57:48 -0000 1.30
@@ -202,15 +202,11 @@
} else {
if (sysdevice != NULL) {
- what_to_find = get_parent_sysfs_path (sysdevice->path);
+ hal_target = find_closest_ancestor (sysdevice->path);
} else {
- what_to_find = "(none)"; /* DZE: Yikes, hack to get added as a child to 'computer'? */
+ hal_target = find_computer ();
}
- /* find the sysdevice we should be a child of */
- hal_target = hal_device_store_match_key_value_string (hald_get_gdl (),
- "linux.sysfs_path_device",
- what_to_find);
if (hal_target == NULL)
goto error;
Index: common.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/common.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- common.c 2 Sep 2004 21:45:49 -0000 1.15
+++ common.c 14 Dec 2004 02:57:48 -0000 1.16
@@ -590,13 +590,57 @@
return computed_udi;
}
+/** Find the closest ancestor by looking at sysfs paths
+ *
+ * @param sysfs_path Path into sysfs, e.g. /sys/devices/pci0000:00/0000:00:1d.7/usb1/1-0:1.0
+ * @return Parent Hal Device Object or #NULL if there is none
+ */
+HalDevice *
+find_closest_ancestor (const char *sysfs_path)
+{
+ char buf[512];
+ HalDevice *parent;
+
+ parent = NULL;
+
+ strncpy (buf, sysfs_path, sizeof (buf));
+ do {
+ char *p;
+
+ p = strrchr (buf, '/');
+ if (p == NULL)
+ break;
+ *p = '\0';
+
+ parent = hal_device_store_match_key_value_string (hald_get_gdl (),
+ "linux.sysfs_path_device",
+ buf);
+ if (parent != NULL)
+ break;
+
+ } while (TRUE);
+
+ return parent;
+}
+
+HalDevice * find_computer ()
+{
+ HalDevice *d;
+ d = hal_device_store_match_key_value_string (hald_get_gdl (),
+ "linux.sysfs_path_device",
+ "(none)");
+ return d;
+}
+
+
/** Given a sysfs-path for a device, this functions finds the sysfs
* path representing the parent of the given device by truncation.
*
* @param path Sysfs-path of device to find parent for
- * @return Path for parent; must be freed by caller
+ * @return Path for parent or NULL if there is no parent;
+ * must be freed by caller
*/
-char *
+static char *
get_parent_sysfs_path (const char *path)
{
int i;
Index: common.h
===================================================================
RCS file: /cvs/hal/hal/hald/linux/common.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- common.h 1 Sep 2004 17:38:58 -0000 1.10
+++ common.h 14 Dec 2004 02:57:48 -0000 1.11
@@ -68,7 +68,9 @@
char *rename_and_merge (HalDevice *d, ComputeFDI naming_func, const char *namespace);
-char *get_parent_sysfs_path (const char *path);
+HalDevice * find_closest_ancestor (const char *sysfs_path);
+
+HalDevice * find_computer ();
dbus_bool_t class_device_get_major_minor (const char *sysfs_path, int *major, int *minor);
@@ -93,6 +95,8 @@
dbus_bool_t got_parent (const char *sysfs_path);
+void etc_mtab_process_all_block_devices (dbus_bool_t force);
+
extern char sysfs_mount_path[SYSFS_PATH_MAX];
Index: net_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/net_class_device.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- net_class_device.c 26 Oct 2004 17:35:21 -0000 1.21
+++ net_class_device.c 14 Dec 2004 02:57:48 -0000 1.22
@@ -260,10 +260,11 @@
else
hal_device_property_set_bool (d, "net.80203.link", FALSE);
+ close (sockfd);
+
/* Also get the link rate */
mii_get_rate (d);
- close (sockfd);
}
static void
Index: osspec.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/osspec.c,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- osspec.c 26 Oct 2004 17:35:21 -0000 1.52
+++ osspec.c 14 Dec 2004 02:57:48 -0000 1.53
@@ -42,6 +42,7 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/utsname.h>
+#include <sys/stat.h>
#include <time.h>
#include <glib.h>
@@ -630,7 +631,7 @@
GError *err;
GDir *dir;
const gchar *f;
-
+
bus = g_hash_table_lookup (sysfs_to_bus_map, path);
if (bus != NULL) {
for (i = 0; bus_device_handlers[i] != NULL; i++) {
@@ -681,22 +682,29 @@
h_string_pair_new (g_strdup (path), g_strdup (bus)));
goto found;
}
- return;
found:
/* visit children */
+ err = NULL;
if ((dir = g_dir_open (path, 0, &err)) == NULL) {
- HAL_ERROR (("Unable to open %: %s", path, err->message));
+ /*HAL_ERROR (("Unable to open directory: %s", path, err->message));*/
g_error_free (err);
goto error;
}
while ((f = g_dir_read_name (dir)) != NULL) {
gchar path_child[SYSFS_PATH_MAX];
-
+ struct stat statbuf;
+
g_snprintf (path_child, SYSFS_PATH_MAX, "%s/%s", path, f);
-
- compute_coldplug_visit_device (path_child, coldplug_list);
+
+ if (lstat (path_child, &statbuf) == 0) {
+
+ if (!S_ISLNK (statbuf.st_mode)) {
+ /* recursion fun */
+ compute_coldplug_visit_device (path_child, coldplug_list);
+ }
+ }
}
g_dir_close (dir);
Index: platform_bus_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/platform_bus_device.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- platform_bus_device.c 8 Oct 2004 22:07:27 -0000 1.6
+++ platform_bus_device.c 14 Dec 2004 02:57:48 -0000 1.7
@@ -204,6 +204,17 @@
"storage");
}
+static void
+platform_device_in_gdl (BusDeviceHandler *self,
+ HalDevice *d,
+ const char *udi)
+{
+ if (hal_device_has_capability (d, "storage")) {
+ /* Check the mtab to see if the device is mounted */
+ etc_mtab_process_all_block_devices (TRUE);
+ }
+}
+
/** Method specialisations for bustype pci */
BusDeviceHandler platform_bus_handler = {
@@ -216,7 +227,7 @@
platform_device_compute_udi, /**< UDI computing function */
platform_device_pre_process, /**< add more properties */
platform_device_got_udi, /**< got UDI */
- bus_device_in_gdl, /**< in GDL */
+ platform_device_in_gdl, /**< in GDL */
"platform", /**< sysfs bus name */
"platform" /**< namespace */
};
More information about the hal-commit
mailing list