hal/hald/linux2/probing probe-storage.c, 1.3, 1.4 probe-volume.c,
1.4, 1.5
David Zeuthen
david at freedesktop.org
Mon Feb 28 11:43:31 PST 2005
Update of /cvs/hal/hal/hald/linux2/probing
In directory gabe:/tmp/cvs-serv31423/hald/linux2/probing
Modified Files:
probe-storage.c probe-volume.c
Log Message:
2005-02-28 David Zeuthen <davidz at redhat.com>
* tools/linux/hal_hotplug.c (main): Use "hal.hotplug" instead of
"hal.hotplug2" for syslog. Don't write a message for every entry.
* hald/linux2/probing/probe-volume.c (main): Only probe for fs on
optical disc if there is indeed data on the disc
* hald/linux2/probing/probe-storage.c (main): Fix up debug outputs;
don't read fs on cdrom's, only check if there is a disc. Don't use
O_NONBLOCK on non-cdrom's.
* hald/linux2/classdev.c (add_classdev_probing_helper_done): Handle
that HalDevice object is already unreffed
* hald/linux2/blockdev.c (add_blockdev_probing_helper_done): Handle
that HalDevice object is already unreffed
(block_rescan_storage_done): -do-
* hald/util.h (struct HalHelperData_s): Add already_issued_kill field
* hald/util.c (hal_util_terminate_helper): Don't kill helpers twice
and don't callback more than once
(helper_child_timeout): Don't callback more than once
(helper_device_object_finalized): Finalized; being called when
a HalDevice object is finalized; use this as hint to terminate
the helper
(helper_child_exited): Remove the weak reference to the HalDevice
object
(hal_util_helper_invoke): Create a weak reference to the HalDevice
object so we get a callback when it's finalized
* hald/hald.c (main): Bah, put LIBEXECDIR at the end so we get
the local helpers when running via run-hald.sh
Index: probe-storage.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/probing/probe-storage.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- probe-storage.c 16 Feb 2005 22:25:20 -0000 1.3
+++ probe-storage.c 28 Feb 2005 19:43:29 -0000 1.4
@@ -147,20 +147,10 @@
if (!libhal_ctx_init (ctx, &error))
goto out;
- printf ("**************************************************\n");
- printf ("**************************************************\n");
- printf ("Doing probe-storage for %s (bus %s) (drive_type %s) (--only-check-for-fs==%d)\n",
- device_file, bus, drive_type, only_check_for_fs);
- printf ("**************************************************\n");
- printf ("**************************************************\n");
+ dbg ("Doing probe-storage for %s (bus %s) (drive_type %s) (--only-check-for-fs==%d)",
+ device_file, bus, drive_type, only_check_for_fs);
if (!only_check_for_fs) {
- fd = open (device_file, O_RDONLY | O_NONBLOCK);
- if (fd < 0) {
- printf ("Cannot open %s: %s\n", device_file, strerror (errno));
- goto out;
- }
-
/* Only do drive_id on IDE and real SCSI disks - specifically
* not on USB which uses emulated SCSI since an INQUIRY on
* most USB devices may crash the storage device if the
@@ -171,19 +161,33 @@
strcmp (bus, "scsi") == 0) {
struct drive_id *did;
+ dbg ("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file);
+ fd = open (device_file, O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ dbg ("Cannot open %s: %s", device_file, strerror (errno));
+ goto out;
+ }
+ dbg ("Returned from open(2)");
+
did = drive_id_open_fd (fd);
if (drive_id_probe_all (did) == 0) {
if (did->serial[0] != '\0')
if (!libhal_device_set_property_string (ctx, udi, "storage.serial",
- did->serial, &error))
+ did->serial, &error)) {
+ close (fd);
goto out;
+ }
if (did->firmware[0] != '\0')
if (!libhal_device_set_property_string (ctx, udi, "storage.firmware_version",
- did->firmware, &error))
+ did->firmware, &error)) {
+ close (fd);
goto out;
+ }
}
- drive_id_close (did);
+ drive_id_close (did);
+
+ close (fd);
}
#if 0
@@ -206,14 +210,25 @@
int capabilities;
int read_speed, write_speed;
- if( ioctl (fd, CDROM_SET_OPTIONS, CDO_USE_FFLAGS) < 0 ) {
+ dbg ("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file);
+ fd = open (device_file, O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ dbg ("Cannot open %s: %s", device_file, strerror (errno));
+ goto out;
+ }
+ dbg ("Returned from open(2)");
+
+ if (ioctl (fd, CDROM_SET_OPTIONS, CDO_USE_FFLAGS) < 0) {
dbg ("Error: CDROM_SET_OPTIONS failed: %s\n", strerror(errno));
+ close (fd);
goto out;
}
capabilities = ioctl (fd, CDROM_GET_CAPABILITY, 0);
- if (capabilities < 0)
+ if (capabilities < 0) {
+ close (fd);
goto out;
+ }
libhal_device_set_property_bool (ctx, udi, "storage.cdrom.cdr", FALSE, &error);
libhal_device_set_property_bool (ctx, udi, "storage.cdrom.cdrw", FALSE, &error);
@@ -271,53 +286,30 @@
else
libhal_device_set_property_int (ctx, udi, "storage.cdrom.write_speed", 0, &error);
}
+
+ close (fd);
}
- close (fd);
} /* !only_check_for_fs */
ret = 0;
- /* See if we got a file system on the main block device - which
- * means doing a data (non O_NONBLOCK) open - this might fail,
- * especially if we don't have any media...
- */
- fd = open (device_file, O_RDONLY | O_NONBLOCK);
- if (fd < 0) {
- printf ("Cannot open %s: %s\n", device_file, strerror (errno));
- goto out;
- }
-
- /* probe for file system */
- vid = volume_id_open_fd (fd);
- if (vid != NULL) {
- if (volume_id_probe_all (vid, 0, 0 /* size */) == 0) {
- /* signal to hald that we've found a file system and a fakevolume
- * should be added - see hald/linux2/blockdev.c:add_blockdev_probing_helper_done()
- * and hald/linux2/blockdev.c:block_rescan_storage_done().
- */
- if (vid->usage_id == VOLUME_ID_FILESYSTEM)
- ret = 2;
- } else {
- ;
- }
- volume_id_close(vid);
- }
-
/* Also return 2 if we're a cdrom and we got a disc */
- if (ret != 2 && strcmp (drive_type, "cdrom") == 0) {
+ if (strcmp (drive_type, "cdrom") == 0) {
char *support_media_changed_str;
int support_media_changed;
int got_media;
int drive;
+ dbg ("Checking for optical disc on %s", device_file);
+
support_media_changed_str = getenv ("HAL_PROP_STORAGE_CDROM_SUPPORT_MEDIA_CHANGED");
if (support_media_changed_str != NULL && strcmp (support_media_changed_str, "true") == 0)
support_media_changed = TRUE;
else
support_media_changed = FALSE;
- close (fd);
+ dbg ("Doing open (\"%s\", O_RDONLY | O_NONBLOCK | O_EXCL)", device_file);
fd = open (device_file, O_RDONLY | O_NONBLOCK | O_EXCL);
if (fd < 0 && errno == EBUSY) {
@@ -332,6 +324,7 @@
if (!is_mounted (device_file))
goto out;
+ dbg ("Doing open (\"%s\", O_RDONLY | O_NONBLOCK)", device_file);
fd = open (device_file, O_RDONLY | O_NONBLOCK);
}
@@ -378,11 +371,43 @@
if (got_media)
ret = 2;
- }
-out:
- if (fd >= 0)
close (fd);
+ } else {
+
+ dbg ("Checking for file system on %s", device_file);
+
+ /* See if we got a file system on the main block device - which
+ * means doing a data (non O_NONBLOCK) open - this might fail,
+ * especially if we don't have any media...
+ */
+ dbg ("Doing open (\"%s\", O_RDONLY)", device_file);
+ fd = open (device_file, O_RDONLY);
+ if (fd < 0) {
+ dbg ("Cannot open %s: %s", device_file, strerror (errno));
+ goto out;
+ }
+ dbg ("Returned from open(2)");
+
+ /* probe for file system */
+ vid = volume_id_open_fd (fd);
+ if (vid != NULL) {
+ if (volume_id_probe_all (vid, 0, 0 /* size */) == 0) {
+ /* signal to hald that we've found a file system and a fakevolume
+ * should be added - see hald/linux2/blockdev.c:add_blockdev_probing_helper_done()
+ * and hald/linux2/blockdev.c:block_rescan_storage_done().
+ */
+ if (vid->usage_id == VOLUME_ID_FILESYSTEM)
+ ret = 2;
+ } else {
+ ;
+ }
+ volume_id_close(vid);
+ }
+ close (fd);
+ }
+
+out:
if (ctx != NULL) {
dbus_error_init (&error);
Index: probe-volume.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux2/probing/probe-volume.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- probe-volume.c 16 Feb 2005 22:25:20 -0000 1.4
+++ probe-volume.c 28 Feb 2005 19:43:29 -0000 1.5
@@ -137,6 +137,7 @@
unsigned int partition_number;
unsigned int block_size;
dbus_uint64_t vol_size;
+ dbus_bool_t should_probe_for_fs;
fd = -1;
@@ -177,87 +178,14 @@
if (!libhal_ctx_init (ctx, &error))
goto out;
- printf ("**************************************************\n");
- printf ("**************************************************\n");
- printf ("Doing probe-volume for %s\n", device_file);
- printf ("**************************************************\n");
- printf ("**************************************************\n");
+ dbg ("Doing probe-volume for %s\n", device_file);
fd = open (device_file, O_RDONLY);
if (fd < 0)
goto out;
- /* probe for file system */
- vid = volume_id_open_fd (fd);
- if (vid != NULL) {
- if (volume_id_probe_all (vid, 0, 0 /* size */) == 0) {
- set_volume_id_values(ctx, udi, vid);
- } else {
- libhal_device_set_property_string (ctx, udi, "info.product", "Volume", &error);
- }
- volume_id_close(vid);
- }
-
- /* get partition type (if we are from partitioned media)
- *
- * (presently we only support PC style partition tables)
- */
- if (partition_number_str != NULL) {
- if ((stordev_dev_file = libhal_device_get_property_string (
- ctx, parent_udi, "block.device", &error)) == NULL) {
- goto out;
- }
- vid = volume_id_open_node (stordev_dev_file);
- if (vid != NULL) {
- if (volume_id_probe_msdos_part_table (vid, 0) == 0) {
- dbg ("Number of partitions = %d", vid->partition_count);
-
- if (partition_number > 0 && partition_number <= vid->partition_count) {
- struct volume_id_partition *p;
- p = &vid->partitions[partition_number-1];
-
- libhal_device_set_property_int (ctx, udi,
- "volume.partition.msdos_part_table_type",
- p->partition_type_raw, &error);
-
- /* NOTE: We trust the type from the partition table
- * if it explicitly got correct entries for RAID and
- * LVM partitions.
- *
- * Btw, in general it's not a good idea to trust the
- * partition table type as many geek^Wexpert users use
- * FAT filesystems on type 0x83 which is Linux.
- *
- * Linux RAID autodetect is 0xfd and Linux LVM is 0x8e
- */
- if (p->partition_type_raw == 0xfd ||
- p->partition_type_raw == 0x8e ) {
- libhal_device_set_property_string (
- ctx, udi, "volume.fsusage", "raid", &error);
- }
-
- } else {
- dbg ("warning: partition_number=%d not in [0;%d[",
- partition_number, vid->partition_count);
- }
- }
- volume_id_close(vid);
- }
- libhal_free_string (stordev_dev_file);
- }
-
- /* block size and total size */
- if (ioctl (fd, BLKSSZGET, &block_size) == 0) {
- dbg ("volume.block_size = %d", block_size);
- libhal_device_set_property_int (ctx, udi, "volume.block_size", block_size, &error);
- }
- if (ioctl (fd, BLKGETSIZE64, &vol_size) == 0) {
- dbg ("volume.size = %llu", vol_size);
- libhal_device_set_property_uint64 (ctx, udi, "volume.size", vol_size, &error);
- }
+ should_probe_for_fs = TRUE;
- /* good so far */
- ret = 0;
if (is_disc) {
int type;
@@ -282,6 +210,7 @@
case CDS_AUDIO: /* audio CD */
libhal_device_set_property_bool (ctx, udi, "volume.disc.has_audio", TRUE, &error);
dbg ("Disc in %s has audio", device_file);
+ should_probe_for_fs = FALSE;
break;
case CDS_MIXED: /* mixed mode CD */
libhal_device_set_property_bool (ctx, udi, "volume.disc.has_audio", TRUE, &error);
@@ -298,11 +227,13 @@
case CDS_NO_INFO: /* blank or invalid CD */
libhal_device_set_property_bool (ctx, udi, "volume.disc.is_blank", TRUE, &error);
dbg ("Disc in %s is blank", device_file);
+ should_probe_for_fs = FALSE;
break;
default: /* should never see this */
libhal_device_set_property_string (ctx, udi, "volume.disc_type", "unknown", &error);
dbg ("Disc in %s returned unknown CDROM_DISC_STATUS", device_file);
+ should_probe_for_fs = FALSE;
break;
}
@@ -363,9 +294,82 @@
if (disc_is_appendable (fd)) {
libhal_device_set_property_bool (ctx, udi, "volume.disc.is_appendable", TRUE, &error);
}
-
}
+ if (should_probe_for_fs) {
+ /* probe for file system */
+ vid = volume_id_open_fd (fd);
+ if (vid != NULL) {
+ if (volume_id_probe_all (vid, 0, 0 /* size */) == 0) {
+ set_volume_id_values(ctx, udi, vid);
+ } else {
+ libhal_device_set_property_string (ctx, udi, "info.product", "Volume", &error);
+ }
+ volume_id_close(vid);
+ }
+
+ /* get partition type (if we are from partitioned media)
+ *
+ * (presently we only support PC style partition tables)
+ */
+ if (partition_number_str != NULL) {
+ if ((stordev_dev_file = libhal_device_get_property_string (
+ ctx, parent_udi, "block.device", &error)) == NULL) {
+ goto out;
+ }
+ vid = volume_id_open_node (stordev_dev_file);
+ if (vid != NULL) {
+ if (volume_id_probe_msdos_part_table (vid, 0) == 0) {
+ dbg ("Number of partitions = %d", vid->partition_count);
+
+ if (partition_number > 0 && partition_number <= vid->partition_count) {
+ struct volume_id_partition *p;
+ p = &vid->partitions[partition_number-1];
+
+ libhal_device_set_property_int (
+ ctx, udi, "volume.partition.msdos_part_table_type",
+ p->partition_type_raw, &error);
+
+ /* NOTE: We trust the type from the partition table
+ * if it explicitly got correct entries for RAID and
+ * LVM partitions.
+ *
+ * Btw, in general it's not a good idea to trust the
+ * partition table type as many geek^Wexpert users use
+ * FAT filesystems on type 0x83 which is Linux.
+ *
+ * Linux RAID autodetect is 0xfd and Linux LVM is 0x8e
+ */
+ if (p->partition_type_raw == 0xfd ||
+ p->partition_type_raw == 0x8e ) {
+ libhal_device_set_property_string (
+ ctx, udi, "volume.fsusage", "raid", &error);
+ }
+
+ } else {
+ dbg ("warning: partition_number=%d not in [0;%d[",
+ partition_number, vid->partition_count);
+ }
+ }
+ volume_id_close(vid);
+ }
+ libhal_free_string (stordev_dev_file);
+ }
+ }
+
+ /* block size and total size */
+ if (ioctl (fd, BLKSSZGET, &block_size) == 0) {
+ dbg ("volume.block_size = %d", block_size);
+ libhal_device_set_property_int (ctx, udi, "volume.block_size", block_size, &error);
+ }
+ if (ioctl (fd, BLKGETSIZE64, &vol_size) == 0) {
+ dbg ("volume.size = %llu", vol_size);
+ libhal_device_set_property_uint64 (ctx, udi, "volume.size", vol_size, &error);
+ }
+
+ /* good so far */
+ ret = 0;
+
out:
if (fd >= 0)
More information about the hal-commit
mailing list