libbluray | branch: master | hpi1 <[email protected]> | Tue Nov 25 11:36:39 2014 +0200| [213f7c301d8f861259ed18aa99cc80e6b47f236f] | committer: hpi1
Move mount point resolving to separate file > http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=213f7c301d8f861259ed18aa99cc80e6b47f236f --- src/Makefile.am | 10 ++++-- src/file/mount.c | 63 +++++++++++++++++++++++++++++++++++ src/file/mount.h | 31 +++++++++++++++++ src/file/mount_darwin.c | 59 ++++++++++++++++++++++++++++++++ src/libbluray/bluray.c | 85 ++--------------------------------------------- 5 files changed, 162 insertions(+), 86 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index b262117..e48eca1 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -74,6 +74,7 @@ libbluray_la_SOURCES = \ file/file.c \ file/dirs.h \ file/dl.h \ + file/mount.h \ file/filesystem.h \ file/filesystem.c \ file/libaacs.h \ @@ -102,20 +103,23 @@ libbluray_la_SOURCES+= \ file/file_posix.c \ file/dir_posix.c \ file/dl_posix.c \ - file/dirs_darwin.c + file/dirs_darwin.c \ + file/mount_darwin.c else if HAVE_WIN32 libbluray_la_SOURCES+= \ file/file_win32.c \ file/dir_win32.c \ file/dl_win32.c \ - file/dirs_win32.c + file/dirs_win32.c \ + file/mount.c else libbluray_la_SOURCES+= \ file/file_posix.c \ file/dir_posix.c \ file/dl_posix.c \ - file/dirs_xdg.c + file/dirs_xdg.c \ + file/mount.c endif endif diff --git a/src/file/mount.c b/src/file/mount.c new file mode 100644 index 0000000..d6703fd --- /dev/null +++ b/src/file/mount.c @@ -0,0 +1,63 @@ +/* + * This file is part of libbluray + * Copyright (C) 2014 VideoLAN + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#include "mount.h" + +#include "util/strutl.h" + +#ifdef HAVE_MNTENT_H +#include <string.h> +#include <sys/stat.h> +#include <mntent.h> +#endif + +char *mount_get_mountpoint(const char *device_path) +{ +#ifdef HAVE_MNTENT_H + struct stat st; + if (stat (device_path, &st) ) { + return str_dup(device_path); + } + + /* If it's a directory, all is good */ + if (S_ISDIR(st.st_mode)) { + return str_dup(device_path); + } + + FILE *f = setmntent ("/proc/self/mounts", "r"); + if (f) { + struct mntent* m; +#ifdef HAVE_GETMNTENT_R + struct mntent mbuf; + char buf [8192]; + while ((m = getmntent_r (f, &mbuf, buf, sizeof(buf))) != NULL) { +#else + while ((m = getmntent (f)) != NULL) { +#endif + if (!strcmp (m->mnt_fsname, device_path)) { + endmntent (f); + return str_dup (m->mnt_dir); + } + } + endmntent (f); + } +#endif /* HAVE_MNTENT_H */ + + return str_dup(device_path); +} diff --git a/src/file/mount.h b/src/file/mount.h new file mode 100644 index 0000000..904b737 --- /dev/null +++ b/src/file/mount.h @@ -0,0 +1,31 @@ +/* + * This file is part of libbluray + * Copyright (C) 2014 VideoLAN + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#ifndef BD_MOUNT_H_ +#define BD_MOUNT_H_ + +#include "util/attributes.h" + +/* + * Resolve device node (/dev/sr0) to mount point + * Implemented on Linux and MacOSX + */ +BD_PRIVATE char *mount_get_mountpoint(const char *device_path); + +#endif /* BD_MOUNT_H_ */ diff --git a/src/file/mount_darwin.c b/src/file/mount_darwin.c new file mode 100644 index 0000000..deb790e --- /dev/null +++ b/src/file/mount_darwin.c @@ -0,0 +1,59 @@ +/* + * This file is part of libbluray + * Copyright (C) 2014 VideoLAN + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * <http://www.gnu.org/licenses/>. + */ + +#include "mount.h" + +#include "util/strutl.h" + +#include <string.h> + +#define _DARWIN_C_SOURCE +#include <sys/stat.h> +#include <sys/param.h> +#include <sys/ucred.h> +#include <sys/mount.h> + +char *mount_get_mountpoint(const char *device_path) +{ + struct stat st; + if (stat (device_path, &st) ) { + return str_dup(device_path); + } + + /* If it's a directory, all is good */ + if (S_ISDIR(st.st_mode)) { + return str_dup(device_path); + } + + struct statfs mbuf[128]; + int fs_count; + + if ( (fs_count = getfsstat (NULL, 0, MNT_NOWAIT)) != -1 ) { + + getfsstat (mbuf, fs_count * sizeof(mbuf[0]), MNT_NOWAIT); + + for ( int i = 0; i < fs_count; ++i) { + if (!strcmp (mbuf[i].f_mntfromname, device_path)) { + return str_dup (mbuf[i].f_mntonname); + } + } + } + + return str_dup (device_path); +} diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c index 3980039..db6a3a5 100644 --- a/src/libbluray/bluray.c +++ b/src/libbluray/bluray.c @@ -43,6 +43,7 @@ #include "decoders/m2ts_filter.h" #include "decoders/overlay.h" #include "file/file.h" +#include "file/mount.h" #ifdef USING_BDJAVA #include "bdj/bdj.h" #endif @@ -55,19 +56,6 @@ #include <inttypes.h> #include <string.h> -#ifdef HAVE_MNTENT_H -#include <sys/stat.h> -#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 - #define MAX_EVENTS 31 /* 2^n - 1 */ typedef struct bd_event_queue_s { @@ -1346,71 +1334,6 @@ static void _storage_free(BLURAY *bd) #define _storage_free(bd) do{}while(0) #endif -#ifdef HAVE_MNTENT_H -/* - * Replace device node (/dev/sr0) by mount point - * Implemented on Linux and MacOSX - */ -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; - - FILE *f = setmntent ("/proc/self/mounts", "r"); - if (!f) - return; - - struct mntent* m; -#ifdef HAVE_GETMNTENT_R - struct mntent mbuf; - char buf [8192]; - while ((m = getmntent_r (f, &mbuf, buf, sizeof(buf))) != NULL) { -#else - while ((m = getmntent (f)) != NULL) { -#endif - if (!strcmp (m->mnt_fsname, bd->device_path)) { - free(bd->device_path); - bd->device_path = str_dup (m->mnt_dir); - break; - } - } - 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 = str_dup (mbuf[i].f_mntonname); - } - } -} -#endif - /* * open / close */ @@ -1438,11 +1361,7 @@ BLURAY *bd_open(const char* device_path, const char* keyfile_path) return NULL; } - bd->device_path = str_dup(device_path); - -#if (defined HAVE_MNTENT_H || defined __APPLE__) - get_mount_point(bd); -#endif + bd->device_path = mount_get_mountpoint(device_path); _libaacs_init(bd, keyfile_path); _______________________________________________ libbluray-devel mailing list [email protected] https://mailman.videolan.org/listinfo/libbluray-devel
