hal/hald/linux platform_bus_device.c,1.5,1.6
David Zeuthen
david at freedesktop.org
Fri Oct 8 15:07:29 PDT 2004
Update of /cvs/hal/hal/hald/linux
In directory gabe:/tmp/cvs-serv10068/hald/linux
Modified Files:
platform_bus_device.c
Log Message:
2004-10-08 David Zeuthen <david at fubar.dk>
* hald/linux/platform_bus_device.c (platform_device_accept): Check that
the floppy drive actually exists. Code snippet from Bill Nottingham
<notting at redhat.com>, see Red Hat bug 133777.
Index: platform_bus_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/platform_bus_device.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- platform_bus_device.c 11 Aug 2004 18:53:50 -0000 1.5
+++ platform_bus_device.c 8 Oct 2004 22:07:27 -0000 1.6
@@ -33,9 +33,15 @@
#include <string.h>
#include <getopt.h>
#include <assert.h>
-#include <unistd.h>
#include <stdarg.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <linux/fd.h>
+
#include "../logger.h"
#include "../device_store.h"
#include "bus_device.h"
@@ -46,6 +52,13 @@
platform_device_accept (BusDeviceHandler *self, const char *path,
struct sysfs_device *device)
{
+ int fd;
+ int number;
+ char device_file[256];
+ char fd_sysfs_path[256];
+ char name[256];
+ struct floppy_drive_struct ds;
+
if (strcmp (device->bus, "platform") != 0)
return FALSE;
@@ -53,6 +66,48 @@
if (strncmp (device->bus_id, "floppy", 6) != 0)
return FALSE;
+ sscanf (device->bus_id, "floppy%d", &number);
+
+ /* get device file */
+ snprintf (fd_sysfs_path, sizeof (fd_sysfs_path), "%s/block/fd%d",
+ sysfs_mount_path, number);
+
+ if (!class_device_get_device_file (fd_sysfs_path,
+ device_file,
+ sizeof (device_file))) {
+ HAL_ERROR (("Could not get device file floppy %d", number));
+ return FALSE;
+ }
+
+ /* Check that there actually is a drive at the other end */
+ fd = open (device_file, O_RDONLY | O_NONBLOCK);
+ if (fd < 0) {
+ HAL_ERROR (("Could not open %s", device_file));
+ return FALSE;
+ }
+
+ /* @todo Could use the name here */
+ ioctl (fd, FDRESET, NULL);
+ if (ioctl (fd, FDGETDRVTYP, name) != 0) {
+ HAL_ERROR (("FDGETDRVTYP failed for %s", device_file));
+ close (fd);
+ return FALSE;
+ }
+ HAL_INFO (("name is '%s'", name));
+
+ if (ioctl (fd, FDPOLLDRVSTAT, &ds)) {
+ HAL_ERROR (("FDPOLLDRVSTAT failed for %s", device_file));
+ close (fd);
+ return FALSE;
+ }
+ close (fd);
+
+ if (ds.track < 0) {
+ HAL_ERROR (("floppy drive %s seems not to exist", device_file));
+ return FALSE;
+ }
+
+
return TRUE;
}
More information about the hal-commit
mailing list