hal/hald/linux block_class_device.c,1.44,1.45
David Zeuthen
david at freedesktop.org
Tue Jul 27 13:26:53 PDT 2004
Update of /cvs/hal/hal/hald/linux
In directory pdx:/tmp/cvs-serv27814/hald/linux
Modified Files:
block_class_device.c
Log Message:
2004-07-27 David Zeuthen <david at fubar.dk>
* hald/linux/block_class_device.c (detect_media): A mounted
disc wasn't detected; this is now 'fixed'. Spotted by Sjoerd Simons.
(is_mounted): New function to determine if a filesystem on a
device file is mounted
Index: block_class_device.c
===================================================================
RCS file: /cvs/hal/hal/hald/linux/block_class_device.c,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- block_class_device.c 22 Jul 2004 19:06:01 -0000 1.44
+++ block_class_device.c 27 Jul 2004 20:26:50 -0000 1.45
@@ -48,6 +48,7 @@
#include <linux/cdrom.h>
#include <linux/fs.h>
#include <glib.h>
+#include <mntent.h>
#include "../hald.h"
#include "../hald_dbus.h"
@@ -404,6 +405,39 @@
}
+/** Check if a filesystem on a special device file is mounted
+ *
+ * @param device_file Special device file, e.g. /dev/cdrom
+ * @return TRUE iff there is a filesystem system mounted
+ * on the special device file
+ */
+static dbus_bool_t
+is_mounted (const char *device_file)
+{
+ FILE *f;
+ dbus_bool_t rc;
+ struct mntent mnt;
+ struct mntent *mnte;
+ char buf[512];
+
+ rc = FALSE;
+
+ if ((f = setmntent ("/etc/mtab", "r")) == NULL)
+ goto out;
+
+ while ((mnte = getmntent_r (f, &mnt, buf, sizeof(buf))) != NULL) {
+ if (strcmp (device_file, mnt.mnt_fsname) == 0) {
+ rc = TRUE;
+ goto out1;
+ }
+ }
+
+out1:
+ endmntent (f);
+out:
+ return rc;
+}
+
/** Check for media on a block device that is not a volume
*
* @param d Device to inspect; can be any device, but
@@ -625,13 +659,25 @@
/* this means the disc is mounted or some other app,
* like a cd burner, has opened O_EXCL */
if (errno == EBUSY) {
- /*HAL_INFO (("*** EBUSY for %s", device_file));*/
+ /*HAL_INFO(("*** EBUSY for %s", device_file));*/
+
+ /* HOWEVER, when starting hald a disc may be
+ * mounted; so check /etc/mtab to see if it
+ * actually is mounted. If it is we open
+ * without O_EXCL
+ */
+ if (is_mounted (device_file)) {
+ fd = open (device_file, O_RDONLY | O_NONBLOCK);
+ if (fd == -1)
+ return FALSE;
+ } else {
+ return FALSE;
+ }
+ } else {
+ /* open failed */
+ HAL_INFO (("open(\"%s\", O_RDONLY|O_NONBLOCK|O_EXCL) failed, " "errno=%d", device_file, errno));
return FALSE;
}
-
- /* open failed */
- HAL_INFO (("open(\"%s\", O_RDONLY|O_NONBLOCK|O_EXCL) failed, " "errno=%d", device_file, errno));
- return FALSE;
}
/* respect policy */
More information about the hal-commit
mailing list