hal/libhal-storage libhal-storage.c, 1.5, 1.6 libhal-storage.h, 1.5, 1.6

David Zeuthen david at freedesktop.org
Wed Oct 13 11:50:47 PDT 2004


Update of /cvs/hal/hal/libhal-storage
In directory gabe:/tmp/cvs-serv10994/libhal-storage

Modified Files:
	libhal-storage.c libhal-storage.h 
Log Message:
2004-10-13  David Zeuthen  <davidz at redhat.com>

	* doc/spec/hal-spec.xml.in: Add docs for is_ascii attribute on the
	match directive.
	
	* fdi/90defaultpolicy/storage-policy.fdi: Don't add volume policy
	if the drive has the no_partitions_hint set to TRUE. Require label
	to be ASCII if using the label as a mount point. Use whitelist of
	msdos partition types if volume stems from a drive with a msdos
	partition table.
	
	* hald/device_info.c (handle_match): Add the is_ascii match check.
	
	* libhal-storage/libhal-storage.c:
	(hal_drive_free): Free newly added fields
	(hal_volume_free): Free newly added fields
	(hal_drive_from_udi): Add should_mount, mount_filesystem, 	
	desired_mount_point properties
	(hal_volume_from_udi): Add should_mount, mount_filesystem, 	
	desired_mount_point properties
	(hal_drive_policy_default_get_mount_root): New function
	(hal_drive_policy_default_use_managed_keyword): New function
	(hal_drive_policy_default_get_managed_keyword_primary): New function
	(hal_drive_policy_default_get_managed_keyword_secondary): New function
	(hal_drive_policy_is_mountable): New function
	(hal_drive_policy_get_desired_mount_point): New function
	(hal_drive_policy_get_mount_options): New function
	(hal_drive_policy_get_mount_fs): New function
	(hal_volume_policy_is_mountable): New function
	(hal_volume_policy_get_desired_mount_point): New function
	(hal_volume_policy_get_mount_options): New function
	(hal_volume_policy_get_mount_fs): New function
	(hal_drive_no_partitions_hint): New function

	* libhal-storage/libhal-storage.h: Add prototypes for new functions



Index: libhal-storage.c
===================================================================
RCS file: /cvs/hal/hal/libhal-storage/libhal-storage.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- libhal-storage.c	27 Sep 2004 16:37:47 -0000	1.5
+++ libhal-storage.c	13 Oct 2004 18:50:45 -0000	1.6
@@ -617,7 +617,7 @@
 
 /*************************************************************************/
 
-
+#define MOUNT_OPTIONS_SIZE 256
 
 struct HalDrive_s {
 	char *udi;
@@ -645,6 +645,16 @@
 	char *serial;
 	char *firmware_version;
 	HalDriveCdromCaps cdrom_caps;
+
+	char *desired_mount_point;
+	char *mount_filesystem;
+	dbus_bool_t should_mount;
+
+	dbus_bool_t no_partitions_hint;
+
+	LibHalContext *hal_ctx;
+
+	char mount_options[MOUNT_OPTIONS_SIZE];
 };
 
 struct HalVolume_s {
@@ -679,6 +689,12 @@
 
 	unsigned int block_size;
 	unsigned int num_blocks;
+
+	char *desired_mount_point;
+	char *mount_filesystem;
+	dbus_bool_t should_mount;
+
+	char mount_options[MOUNT_OPTIONS_SIZE];
 };
 
 const char *
@@ -711,6 +727,8 @@
 	hal_free_string (drive->physical_device);
 	hal_free_string (drive->serial);
 	hal_free_string (drive->firmware_version);
+	hal_free_string (drive->desired_mount_point);
+	hal_free_string (drive->mount_filesystem);
 }
 
 
@@ -731,6 +749,8 @@
 	hal_free_string (vol->mount_point);
 	hal_free_string (vol->fsversion);
 	hal_free_string (vol->uuid);
+	hal_free_string (vol->desired_mount_point);
+	hal_free_string (vol->mount_filesystem);
 }
 
 
@@ -743,7 +763,6 @@
 #define HAL_PROP_EXTRACT_BOOL(_property_, _where_) else if (strcmp (key, _property_) == 0 && type == DBUS_TYPE_BOOLEAN) _where_ = hal_psi_get_bool (&it)
 #define HAL_PROP_EXTRACT_BOOL_BITFIELD(_property_, _where_, _field_) else if (strcmp (key, _property_) == 0 && type == DBUS_TYPE_BOOLEAN) _where_ |= hal_psi_get_bool (&it) ? _field_ : 0
 
-
 /** Given a UDI for a HAL device of capability 'storage', this
  *  function retrieves all the relevant properties into convenient
  *  in-process data structures.
@@ -772,6 +791,8 @@
 		goto error;
 	memset (drive, 0x00, sizeof (HalDrive));
 
+	drive->hal_ctx = hal_ctx;
+
 	drive->udi = strdup (udi);
 	if (drive->udi == NULL)
 		goto error;
@@ -819,6 +840,12 @@
 		HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdrw", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDRW);
 		HAL_PROP_EXTRACT_BOOL_BITFIELD ("storage.cdrom.dvdram", drive->cdrom_caps, HAL_DRIVE_CDROM_CAPS_DVDRAM);
 
+		HAL_PROP_EXTRACT_BOOL   ("storage.policy.should_mount",        drive->should_mount);
+		HAL_PROP_EXTRACT_STRING ("storage.policy.desired_mount_point", drive->desired_mount_point);
+		HAL_PROP_EXTRACT_STRING ("storage.policy.mount_filesystem",    drive->mount_filesystem);
+
+		HAL_PROP_EXTRACT_BOOL   ("storage.no_partitions_hint",        drive->no_partitions_hint);
+
 		HAL_PROP_EXTRACT_END;
 	}
 
@@ -970,6 +997,10 @@
 		HAL_PROP_EXTRACT_BOOL   ("volume.disc.is_blank",      vol->disc_is_blank);
 		HAL_PROP_EXTRACT_BOOL   ("volume.disc.is_rewritable", vol->disc_is_rewritable);
 
+		HAL_PROP_EXTRACT_BOOL   ("volume.policy.should_mount",        vol->should_mount);
+		HAL_PROP_EXTRACT_STRING ("volume.policy.desired_mount_point", vol->desired_mount_point);
+		HAL_PROP_EXTRACT_STRING ("volume.policy.mount_filesystem",    vol->mount_filesystem);
+
 		HAL_PROP_EXTRACT_END;
 	}
 
@@ -1364,5 +1395,190 @@
 	return result;
 }
 
+/*************************************************************************/
+
+char *
+hal_drive_policy_default_get_mount_root (LibHalContext *hal_ctx)
+{
+	return hal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
+					       "storage.policy.default.mount_root");
+}
+
+dbus_bool_t
+hal_drive_policy_default_use_managed_keyword (LibHalContext *hal_ctx)
+{
+	return hal_device_get_property_bool (hal_ctx, "/org/freedesktop/Hal/devices/computer",
+					     "storage.policy.default.use_managed_keyword");
+}
+
+char *
+hal_drive_policy_default_get_managed_keyword_primary (LibHalContext *hal_ctx)
+{
+	return hal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
+					       "storage.policy.default.managed_keyword.primary");
+}
+
+char *
+hal_drive_policy_default_get_managed_keyword_secondary (LibHalContext *hal_ctx)
+{
+	return hal_device_get_property_string (hal_ctx, "/org/freedesktop/Hal/devices/computer",
+					       "storage.policy.default.managed_keyword.secondary");
+}
+
+/*************************************************************************/
+
+dbus_bool_t
+hal_drive_policy_is_mountable (HalDrive *drive, HalStoragePolicy *policy)
+{
+	return drive->should_mount && drive->no_partitions_hint;
+}
+
+const char *
+hal_drive_policy_get_desired_mount_point (HalDrive *drive, HalStoragePolicy *policy)
+{
+	return drive->desired_mount_point;
+}
+
+/* safely strcat() at most the remaining space in 'dst' */
+#define strcat_len(dst, src, dstmaxlen) do {    \
+	dst[dstmaxlen - 1] = '\0'; \
+	strncat (dst, src, dstmaxlen - strlen (dst) - 1); \
+} while(0)
+
+
+const char *
+hal_drive_policy_get_mount_options (HalDrive *drive, HalStoragePolicy *policy)
+{
+	const char *result;
+	LibHalPropertySet *properties;
+	LibHalPropertySetIterator it;
+	char stor_mount_option_default_begin[] = "storage.policy.default.mount_option.";
+	char stor_mount_option_begin[] = "storage.policy.mount_option.";
+
+	result = NULL;
+	drive->mount_options[0] = '\0';
+
+	/* first collect from root computer device */
+	properties = hal_device_get_all_properties (drive->hal_ctx, "/org/freedesktop/Hal/devices/computer");
+	if (properties == NULL)
+		goto error;
+	for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
+		int type;
+		char *key;
+		
+		type = hal_psi_get_type (&it);
+		key = hal_psi_get_key (&it);
+		if (strncmp (key, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin) - 1) == 0) {
+			if (strlen (drive->mount_options) > 0)
+				strcat_len (drive->mount_options, ",", MOUNT_OPTIONS_SIZE);
+			strcat_len (drive->mount_options, key + sizeof(stor_mount_option_default_begin)-1, MOUNT_OPTIONS_SIZE);
+		}
+	}
+	hal_free_property_set (properties);
+
+	/* append options from the specific drive */
+	properties = hal_device_get_all_properties (drive->hal_ctx, drive->udi);
+	if (properties == NULL)
+		goto error;
+	for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
+		int type;
+		char *key;		
+		type = hal_psi_get_type (&it);
+		key = hal_psi_get_key (&it);
+		if (strncmp (key, stor_mount_option_begin, sizeof (stor_mount_option_begin) - 1) == 0) {
+			if (strlen (drive->mount_options) > 0)
+				strcat_len (drive->mount_options, ",", MOUNT_OPTIONS_SIZE);
+			strcat_len (drive->mount_options, key + sizeof (stor_mount_option_begin)-1, MOUNT_OPTIONS_SIZE);
+		}
+	}
+
+	result = drive->mount_options;
+
+error:
+	hal_free_property_set (properties);
+	return result;
+}
+
+const char *
+hal_drive_policy_get_mount_fs (HalDrive *drive, HalStoragePolicy *policy)
+{
+	return drive->mount_filesystem;
+}
+
+
+dbus_bool_t
+hal_volume_policy_is_mountable (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
+{
+	return drive->should_mount && volume->should_mount;
+}
+
+const char *hal_volume_policy_get_desired_mount_point (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
+{
+	return volume->desired_mount_point;
+}
+
+const char *hal_volume_policy_get_mount_options (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
+{
+	const char *result;
+	LibHalPropertySet *properties;
+	LibHalPropertySetIterator it;
+	char stor_mount_option_default_begin[] = "storage.policy.default.mount_option.";
+	char vol_mount_option_begin[] = "volume.policy.mount_option.";
+
+	result = NULL;
+	volume->mount_options[0] = '\0';
+
+	/* first collect from root computer device */
+	properties = hal_device_get_all_properties (drive->hal_ctx, "/org/freedesktop/Hal/devices/computer");
+	if (properties == NULL)
+		goto error;
+	for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
+		int type;
+		char *key;
+		
+		type = hal_psi_get_type (&it);
+		key = hal_psi_get_key (&it);
+		if (strncmp (key, stor_mount_option_default_begin, sizeof (stor_mount_option_default_begin) - 1) == 0) {
+			if (strlen (volume->mount_options) > 0)
+				strcat_len (volume->mount_options, ",", MOUNT_OPTIONS_SIZE);
+			strcat_len (volume->mount_options, key + sizeof(stor_mount_option_default_begin)-1, MOUNT_OPTIONS_SIZE);
+		}
+	}
+	hal_free_property_set (properties);
+
+	/* append options from the specific volume */
+	properties = hal_device_get_all_properties (drive->hal_ctx, volume->udi);
+	if (properties == NULL)
+		goto error;
+	for (hal_psi_init (&it, properties); hal_psi_has_more (&it); hal_psi_next (&it)) {
+		int type;
+		char *key;		
+		type = hal_psi_get_type (&it);
+		key = hal_psi_get_key (&it);
+		if (strncmp (key, vol_mount_option_begin, sizeof (vol_mount_option_begin) - 1) == 0) {
+			if (strlen (volume->mount_options) > 0)
+				strcat_len (volume->mount_options, ",", MOUNT_OPTIONS_SIZE);
+			strcat_len (volume->mount_options, key + sizeof (vol_mount_option_begin)-1, MOUNT_OPTIONS_SIZE);
+		}
+	}
+
+	result = volume->mount_options;
+
+error:
+	hal_free_property_set (properties);
+
+	return result;
+}
+
+const char *hal_volume_policy_get_mount_fs (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy)
+{
+	return volume->mount_filesystem;
+}
+
+dbus_bool_t       
+hal_drive_no_partitions_hint (HalDrive *drive)
+{
+	return drive->no_partitions_hint;
+}
 
 /** @} */

Index: libhal-storage.h
===================================================================
RCS file: /cvs/hal/hal/libhal-storage/libhal-storage.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- libhal-storage.h	8 Oct 2004 16:40:24 -0000	1.5
+++ libhal-storage.h	13 Oct 2004 18:50:45 -0000	1.6
@@ -171,6 +171,7 @@
 
 dbus_bool_t       hal_drive_is_hotpluggable             (HalDrive      *drive);
 dbus_bool_t       hal_drive_uses_removable_media        (HalDrive      *drive);
+dbus_bool_t       hal_drive_no_partitions_hint          (HalDrive      *drive);
 dbus_bool_t       hal_drive_requires_eject              (HalDrive      *drive);
 HalDriveType      hal_drive_get_type                    (HalDrive      *drive);
 HalDriveBus       hal_drive_get_bus                     (HalDrive      *drive);
@@ -192,9 +193,20 @@
 char             *hal_drive_policy_compute_display_name (HalDrive      *drive, HalVolume *volume, HalStoragePolicy *policy);
 char             *hal_drive_policy_compute_icon_name    (HalDrive      *drive, HalVolume *volume, HalStoragePolicy *policy);
 
+dbus_bool_t       hal_drive_policy_is_mountable        (HalDrive      *drive, HalStoragePolicy *policy);
+const char       *hal_drive_policy_get_desired_mount_point (HalDrive      *drive, HalStoragePolicy *policy);
+const char       *hal_drive_policy_get_mount_options   (HalDrive      *drive, HalStoragePolicy *policy);
+const char       *hal_drive_policy_get_mount_fs        (HalDrive      *drive, HalStoragePolicy *policy);
+
 char            **hal_drive_find_all_volumes            (LibHalContext *hal_ctx, HalDrive *drive, int *num_volumes);
 
 
+char        *hal_drive_policy_default_get_mount_root                (LibHalContext *hal_ctx);
+dbus_bool_t  hal_drive_policy_default_use_managed_keyword           (LibHalContext *hal_ctx);
+char        *hal_drive_policy_default_get_managed_keyword_primary   (LibHalContext *hal_ctx);
+char        *hal_drive_policy_default_get_managed_keyword_secondary (LibHalContext *hal_ctx);
+
+
 typedef enum {
 	HAL_VOLUME_USAGE_MOUNTABLE_FILESYSTEM,
 	HAL_VOLUME_USAGE_PARTITION_TABLE,
@@ -247,8 +259,12 @@
 char             *hal_volume_policy_compute_display_name   (HalDrive      *drive, HalVolume    *volume, HalStoragePolicy *policy);
 char             *hal_volume_policy_compute_icon_name      (HalDrive      *drive, HalVolume    *volume, HalStoragePolicy *policy);
 
-dbus_bool_t       hal_volume_policy_should_be_visible      (HalDrive      *drive, HalVolume    *volume, HalStoragePolicy *policy, const char *target_moint_point);
+dbus_bool_t       hal_volume_policy_should_be_visible      (HalDrive      *drive, HalVolume    *volume, HalStoragePolicy *policy, const char *target_mount_point);
 
+dbus_bool_t       hal_volume_policy_is_mountable        (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy);
+const char       *hal_volume_policy_get_desired_mount_point (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy);
+const char       *hal_volume_policy_get_mount_options   (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy);
+const char       *hal_volume_policy_get_mount_fs        (HalDrive *drive, HalVolume *volume, HalStoragePolicy *policy);
 
 /** @} */
 




More information about the hal-commit mailing list