[vlc-devel] [PATCH] udev discovery: fix bluray
Rafaël Carré
funman at videolan.org
Tue Dec 27 18:53:46 CET 2011
- the scheme is wrong (bd instead of bluray)
- libbluray needs to access the mount point, not the devnode
we parse /proc/mounts to find where this devnode is mounted
note: the 2 discs I have have no spaces in their label (replaced by _)
I anm not sure if it's legal for discs to have spaces, but for some
other device it appears in /proc/mounts as \040 (octal)
---
modules/services_discovery/udev.c | 52 +++++++++++++++++++++++++++++++++++-
1 files changed, 50 insertions(+), 2 deletions(-)
diff --git a/modules/services_discovery/udev.c b/modules/services_discovery/udev.c
index 385a52b..cbaec54 100644
--- a/modules/services_discovery/udev.c
+++ b/modules/services_discovery/udev.c
@@ -29,11 +29,13 @@
#include <vlc_services_discovery.h>
#include <vlc_plugin.h>
#include <vlc_url.h>
+#include <vlc_fs.h>
#ifdef HAVE_SEARCH_H
# include <search.h>
#endif
#include <poll.h>
#include <errno.h>
+#include <stdio.h>
static int OpenV4L (vlc_object_t *);
#ifdef HAVE_ALSA
@@ -540,6 +542,41 @@ int OpenALSA (vlc_object_t *obj)
/*** Discs support ***/
+static char *get_mount_point (const char *devnode)
+{
+ char *mnt = NULL;
+ char *line = NULL;
+ size_t len = 0;
+ size_t devlen = strlen(devnode);
+ FILE *f = vlc_fopen("/proc/mounts", "r");
+
+ if (!f)
+ return NULL;
+
+ while (getline(&line, &len, f) != -1) {
+ if (strncmp(line, devnode, devlen))
+ continue;
+
+ /* if device is not followed immediately by a space it's not the one */
+ /* e.g. when looking for "/dev/sda1", "/dev/sda XXX" won't match */
+ char *space = strchr(line, ' ');
+ if (space != &line[devlen])
+ continue;
+
+ space = strchr(space + 1, ' '); /* space points just after the mount dir */
+ if (!space) /* corrupted line ? */
+ break;
+
+ *space = '\0';
+ /* FIXME : spaces (at least) are octal escaped */
+ mnt = strdup(&line[devlen+1]);
+ }
+
+ free(line);
+ fclose(f);
+ return mnt;
+}
+
static char *disc_get_mrl (struct udev_device *dev)
{
const char *val;
@@ -563,7 +600,7 @@ static char *disc_get_mrl (struct udev_device *dev)
val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_BD");
if (val && atoi (val))
- scheme = "bd";
+ scheme = "bluray";
#ifdef LOL
val = udev_device_get_property_value (dev, "ID_CDROM_MEDIA_HDDVD");
if (val && atoi (val))
@@ -576,7 +613,18 @@ static char *disc_get_mrl (struct udev_device *dev)
return NULL;
val = udev_device_get_devnode (dev);
- return make_URI (val, scheme);
+ char *uri = NULL;
+ if (!strcmp(scheme, "bluray")) {
+ /* bluray needs the mount point, not the device node */
+ char *mount = get_mount_point(val);
+ if (mount) {
+ uri = make_URI (mount, scheme);
+ free(mount);
+ }
+ } else {
+ uri = make_URI (val, scheme);
+ }
+ return uri;
}
static char *disc_get_name (struct udev_device *dev)
--
1.7.7.3
More information about the vlc-devel
mailing list