[libbluray-devel] [PATCH] Implement get_mount_point for OSX.

Konstantin Pavlov thresh at videolan.org
Mon Mar 19 08:55:24 CET 2012


---
 src/libbluray/bluray.c |   42 +++++++++++++++++++++++++++++++++++++++---
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index f8c1f0b..0431422 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -52,6 +52,14 @@
 #include <mntent.h>
 #endif
 
+#ifdef __APPLE__
+#define _DARWIN_C_SOURCE
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/ucred.h>
+#include <sys/mount.h>
+#endif
+
 typedef int     (*fptr_int)();
 typedef int32_t (*fptr_int32)();
 typedef void*   (*fptr_p_void)();
@@ -912,11 +920,11 @@ static void _fill_disc_info(BLURAY *bd)
     }
 }
 
-#ifdef __linux__
 /*
  * Replace device node (/dev/sr0) by mount point
- * Implemented on Linux only at the moment, could be added for other OS
+ * Implemented on Linux and MacOSX
  */
+#ifdef __linux__
 static void get_mount_point(BLURAY *bd)
 {
     struct stat st;
@@ -944,6 +952,34 @@ static void get_mount_point(BLURAY *bd)
     endmntent (f);
 }
 #endif
+#ifdef __APPLE__
+static void get_mount_point(BLURAY *bd)
+{
+    struct stat st;
+    if (stat (bd->device_path, &st) )
+        return;
+
+    /* If it's a directory, all is good */
+    if (S_ISDIR(st.st_mode))
+        return;
+
+    struct statfs mbuf[128];
+    int fs_count;
+
+    if ( (fs_count = getfsstat (NULL, 0, MNT_NOWAIT)) == -1 ) {
+        return;
+    }
+
+    getfsstat (mbuf, fs_count * sizeof(mbuf[0]), MNT_NOWAIT);
+
+    for ( int i = 0; i < fs_count; ++i) {
+        if (!strcmp (mbuf[i].f_mntfromname, bd->device_path)) {
+            free(bd->device_path);
+            bd->device_path = strdup (mbuf[i].f_mntonname);
+        }
+    }
+}
+#endif
 
 /*
  * open / close
@@ -967,7 +1003,7 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path)
 
     bd->device_path = strdup(device_path);
 
-#ifdef __linux__
+#if (defined __linux__ || defined __APPLE__)
     get_mount_point(bd);
 #endif
 
-- 
1.7.9.2



More information about the libbluray-devel mailing list