hal/hald/linux block_class_device.c,1.16,1.17

David Zeuthen david at pdx.freedesktop.org
Fri Apr 30 10:01:25 PDT 2004


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

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

	* doc/TODO: update TODO note about fs detection

2004-04-30  Kay Sievers  <kay.sievers at vrfy.org>

	* hald/Makefile.am (hald_SOURCES): add volume_id/volume_id.[ch]

	* hald/linux/block_class_device.c (detect_fs): use utility in new 
	subdirectory volume_id

	* hald/linux/volume_id/volume_id.[ch]: new files



Index: block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- a/block_class_device.c	26 Apr 2004 20:08:58 -0000	1.16
+++ b/block_class_device.c	30 Apr 2004 17:01:23 -0000	1.17
@@ -57,6 +57,7 @@
 #include "class_device.h"
 #include "common.h"
  
+#include "volume_id/volume_id.h"
 #include "linux_dvd_rw_utils.h"
 
 /**
@@ -587,70 +588,31 @@
 	}
 }
 
-static dbus_bool_t
-detect_fs_fat (HalDevice *d)
+static void
+detect_fs (HalDevice *d)
 {
-	int i, len;
-	int fd;
+	struct volume_id *vid;
 	const char *device_file;
-	unsigned char data[512];
-	char label[12];
-	dbus_bool_t matched = FALSE;
-
-	/* See http://www.win.tue.nl/~aeb/linux/fs/fat/fat-1.html for
-	 * more information
-	 */
+	int rc;
 
 	device_file = hal_device_property_get_string (d, "block.device");
+	vid = volume_id_open_node(device_file);
+	if (vid == NULL)
+		return;
 
-	fd = open (device_file, O_RDONLY);
-	if (fd < 0)
-		return FALSE;
-
-	if (512 != read (fd, data, 512))
-		goto out;
-
-	/* signature must be 0x55aa on the last two bytes of the first 512
-	 * byte sector */
-	if (data[510] != 0x55 && 
-	    data[511] != 0xaa)
-		goto out;
-
-	memset (label, 0, 12);
+	rc = volume_id_probe(vid, ALL);
+	if (rc != 0)
+		return;
 
-	if (data[82] == 'F' &&
-	    data[83] == 'A' &&
-	    data[84] == 'T' &&
-	    data[85] == '3' &&
-	    data[86] == '2' ) {
-		/* FAT32 */
-		memcpy (label, data+71, 11);
-		hal_device_property_set_string (d, "block.fstype", "vfat");
-		matched = TRUE;
-	} else if (data[54] == 'F' &&
-		   data[55] == 'A' &&
-		   data[56] == 'T' ) {
-		/* FAT12/FAT16/FAT */
-		memcpy (label, data+43, 11);
-		hal_device_property_set_string (d, "block.fstype", "vfat");
-		matched = TRUE;
-	}
+	hal_device_property_set_string (d, "block.fstype", vid->fs_name);
+	if (vid->label_string[0] != '\0')
+		hal_device_property_set_string (d, "block.volume_label", vid->label_string);
+	if (vid->uuid_string[0] != '\0')
+		hal_device_property_set_string (d, "block.volume_uuid", vid->uuid_string);
 
-	len = strlen (label);
-	for (i=len-1; i>=0 && isspace (label[i]); --i)
-		label[i] = '\0';
-	hal_device_property_set_string (d, "block.volume_label", label);
-	
-out:
-	close (fd);
-	return matched;
-}
+	volume_id_close(vid);
 
-static void
-detect_fs (HalDevice *d)
-{
-	if (detect_fs_fat(d))
-		return;
+	return;
 }
 
 static void 





More information about the hal-commit mailing list