hal/hald/linux block_class_device.c,1.55,1.56

David Zeuthen david at freedesktop.org
Thu Aug 19 10:58:17 PDT 2004


Update of /cvs/hal/hal/hald/linux
In directory pdx:/tmp/cvs-serv20892/hald/linux

Modified Files:
	block_class_device.c 
Log Message:
2004-08-19  David Zeuthen  <david at fubar.dk>

	* tools/fstab-sync.c: Lot's of changes: remove old locking code;
	fix security issue (remove dev,suid) with the given mount options 
	(RH bug #130290); Use a, pretty lame perhaps, heuristic to add 
	noatime,sync for hotpluggable volumes smaller than 1GB. Check device 
	mentioned in /etc/fstab for symlink and if found, update the 
	block.device property in HAL if applicable; Use macros for mount
	root and noop keyword (see configure.in changes).	

	* hald/linux/block_class_device.c (volume_set_size): New function
	(detect_media): Call volume_set_size
	(block_class_pre_process): Call volume_set_size

	* doc/spec/hal-spec.xml.in: Add documentation for volume.block_size
	and volume.num_blocks.

	* configure.in: Add gobject>=2.2.2 to PKG_CHECK_MODULES. Patch from 
	Steve Grubb <linux_4ever at yahoo.com>. Added some configuration options
	for fstab-sync.



Index: block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -d -r1.55 -r1.56
--- block_class_device.c	18 Aug 2004 23:24:42 -0000	1.55
+++ block_class_device.c	19 Aug 2004 17:58:15 -0000	1.56
@@ -524,6 +524,53 @@
 
 
 static void
+volume_set_size (HalDevice *d, dbus_bool_t force)
+{
+	int fd;
+	int num_blocks;
+	int block_size;
+	const char *sysfs_path;
+	const char *storudi;
+	const char *device_file;
+	HalDevice *stordev;
+	char attr_path[SYSFS_PATH_MAX];
+	struct sysfs_attribute *attr;
+
+	storudi = hal_device_property_get_string (d, "block.storage_device");
+	stordev = hal_device_store_find (hald_get_gdl (), storudi);
+
+	if (force || hal_device_property_get_bool (stordev, "storage.media_check_enabled")) {
+
+		sysfs_path = hal_device_property_get_string (d, "linux.sysfs_path");
+		/* no-partition volumes doesn't have sysfs path */
+		if (sysfs_path == NULL)
+			sysfs_path = hal_device_property_get_string (stordev, "linux.sysfs_path");
+
+		if (sysfs_path == NULL)
+			return;
+
+		device_file = hal_device_property_get_string (d, "block.device");
+
+		snprintf (attr_path, SYSFS_PATH_MAX, "%s/size", sysfs_path);
+		attr = sysfs_open_attribute (attr_path);
+		if (sysfs_read_attribute (attr) >= 0) {
+			num_blocks = atoi (attr->value);
+
+			hal_device_property_set_int (d, "volume.num_blocks", num_blocks);
+			sysfs_close_attribute (attr);
+		}
+
+		fd = open (device_file, O_RDONLY);
+		if (fd >= 0) {
+			if (ioctl (fd, BLKSSZGET, &block_size) == 0) {
+				hal_device_property_set_int (d, "volume.block_size", block_size);
+			}
+			close (fd);
+		}
+	}
+}
+
+static void
 detect_disc (HalDevice *d, const char *device_file)
 {
 	int fd;
@@ -869,6 +916,9 @@
 		hal_device_property_set_bool (child, "volume.is_mounted", FALSE);
 		hal_device_property_set_bool (child, "volume.is_disc", is_cdrom);
 
+		/* set the size */
+		volume_set_size (child, force_poll);
+
 		if (is_cdrom )
 			detect_disc (child, device_file);
 
@@ -984,6 +1034,7 @@
 	}
 }
 
+
 static void
 block_class_pre_process (ClassDeviceHandler *self,
 			 HalDevice *d,
@@ -1127,6 +1178,7 @@
 		 * or any of it partitions are not mounted causes the loop.
 		 */
 		if (hal_device_property_get_bool (stordev, "storage.media_check_enabled")) {
+
 			vid = volume_id_open_node(device_file);
 			if (vid != NULL) {
 				if (volume_id_probe(vid, VOLUME_ID_ALL, 0) == 0) {
@@ -1134,15 +1186,18 @@
 				}
 				volume_id_close(vid);
 			}
+
 		} else {
 			/* gee, so at least set volume.fstype vfat,msdos,auto so 
 			 * mount(1) doesn't screw up and causes hotplug events
 			 *
 			 * GRRRR!!!
 			 */
-			hal_device_property_set_string (d, "volume.fstype", "vfat,msdos,auto");
+			hal_device_property_set_string (d, "volume.fstype", "vfat,auto");
 		}
 
+		volume_set_size (d, FALSE);
+
 		return;
 	}
 




More information about the hal-commit mailing list