[libbluray-devel] [Git][videolan/libbluray][master] Add getfsstat() and getvfsstat() support for OpenBSD, FreeBSD, NetBSD and DragonFlyBSD
Petri Hintukainen (@hpi)
gitlab at videolan.org
Mon Sep 19 07:28:11 UTC 2022
Petri Hintukainen pushed to branch master at VideoLAN / libbluray
Commits:
25423897 by Brad Smith at 2022-09-17T23:53:20-04:00
Add getfsstat() and getvfsstat() support for OpenBSD, FreeBSD, NetBSD and DragonFlyBSD
- - - - -
3 changed files:
- Makefile.am
- configure.ac
- + src/file/mount_getfsstat.c
Changes:
=====================================
Makefile.am
=====================================
@@ -198,6 +198,14 @@ libbluray_la_SOURCES+= \
src/file/file_win32.c \
src/file/mount.c
else
+if HAVE_GETFSSTAT
+libbluray_la_SOURCES+= \
+ src/file/dir_posix.c \
+ src/file/dirs_xdg.c \
+ src/file/dl_posix.c \
+ src/file/file_posix.c \
+ src/file/mount_getfsstat.c
+else
libbluray_la_SOURCES+= \
src/file/dir_posix.c \
src/file/dirs_xdg.c \
@@ -206,6 +214,7 @@ libbluray_la_SOURCES+= \
src/file/mount.c
endif
endif
+endif
libbluray_la_LDFLAGS= -no-undefined -version-info $(LT_VERSION_INFO) -export-symbols-regex "^bd_"
libbluray_la_LIBADD= $(LIBXML2_LIBS) $(FT2_LIBS) $(FONTCONFIG_LIBS) $(LIBUDFREAD_LIBS) $(EXTRA_LIBS)
=====================================
configure.ac
=====================================
@@ -65,8 +65,16 @@ case "${host_os}" in
;;
esac
+dnl Falsely enables for NetBSD
+dnl warning: warning: reference to obsolete getfsstat(); use getvfsstat()
+AS_IF([test "${SYS}" != "netbsd"], [
+ AC_CHECK_FUNCS([getfsstat])
+])
+AC_CHECK_FUNCS([getvfsstat])
+
AM_CONDITIONAL(HAVE_WIN32, test "${SYS}" = "mingw32")
AM_CONDITIONAL(HAVE_DARWIN, test "${SYS}" = "darwin")
+AM_CONDITIONAL(HAVE_GETFSSTAT, test "${ac_cv_func_getfsstat}" = "yes" -o "${ac_cv_func_getvfsstat}" = "yes")
dnl messages
library_not_found="Could not find required library!"
=====================================
src/file/mount_getfsstat.c
=====================================
@@ -0,0 +1,93 @@
+/*
+ * 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/>.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "mount.h"
+
+#include "util/strutl.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#ifdef HAVE_GETFSSTAT
+#include <sys/mount.h>
+#else
+#include <sys/statvfs.h>
+#endif
+
+char *mount_get_mountpoint(const char *device_path)
+{
+ struct stat st;
+#ifdef HAVE_GETFSSTAT
+ struct statfs *mbuf;
+#else
+ struct statvfs *mbuf;
+#endif
+ int fs_count;
+
+ 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);
+ }
+
+#ifdef HAVE_GETFSSTAT
+ fs_count = getfsstat (NULL, 0, MNT_NOWAIT);
+#else
+ fs_count = getvfsstat (NULL, 0, ST_NOWAIT);
+#endif
+ if (fs_count == -1) {
+ return str_dup(device_path);
+ }
+
+#ifdef HAVE_GETFSSTAT
+ mbuf = calloc (fs_count, sizeof(struct statfs));
+#else
+ mbuf = calloc (fs_count, sizeof(struct statvfs));
+#endif
+ if (!mbuf) {
+ return str_dup(device_path);
+ }
+
+#ifdef HAVE_GETFSSTAT
+ fs_count = getfsstat (mbuf, fs_count * sizeof(struct statfs), MNT_NOWAIT);
+#else
+ fs_count = getvfsstat (mbuf, fs_count * sizeof(struct statvfs), ST_NOWAIT);
+#endif
+
+ char *result = NULL;
+
+ for (int i = 0; i < fs_count; ++i) {
+ if (!strcmp (mbuf[i].f_mntfromname, device_path)) {
+ result = str_dup(mbuf[i].f_mntonname);
+ break;
+ }
+ }
+
+ free (mbuf);
+ return (result) ? result : str_dup(device_path);
+}
View it on GitLab: https://code.videolan.org/videolan/libbluray/-/commit/25423897791da3141ea9033bebb43600df883a47
--
View it on GitLab: https://code.videolan.org/videolan/libbluray/-/commit/25423897791da3141ea9033bebb43600df883a47
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the libbluray-devel
mailing list