mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-06 18:54:14 +08:00
mdbx: use getmntent() for determine filesystem type.
Change-Id: I92921c5083a822c891889668e51726e2f1ce98cd
This commit is contained in:
parent
4e4a56eda2
commit
2f383d8de3
@ -962,7 +962,6 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) {
|
|||||||
if (mdbx_GetFileInformationByHandleEx(handle, FileRemoteProtocolInfo,
|
if (mdbx_GetFileInformationByHandleEx(handle, FileRemoteProtocolInfo,
|
||||||
&RemoteProtocolInfo,
|
&RemoteProtocolInfo,
|
||||||
sizeof(RemoteProtocolInfo))) {
|
sizeof(RemoteProtocolInfo))) {
|
||||||
|
|
||||||
if ((RemoteProtocolInfo.Flags & REMOTE_PROTOCOL_INFO_FLAG_OFFLINE) &&
|
if ((RemoteProtocolInfo.Flags & REMOTE_PROTOCOL_INFO_FLAG_OFFLINE) &&
|
||||||
!(flags & MDBX_RDONLY))
|
!(flags & MDBX_RDONLY))
|
||||||
return ERROR_FILE_OFFLINE;
|
return ERROR_FILE_OFFLINE;
|
||||||
@ -1115,9 +1114,43 @@ static int mdbx_check_fs_local(mdbx_filehandle_t handle, int flags) {
|
|||||||
const char *const name = statfs_info.f_fstypename;
|
const char *const name = statfs_info.f_fstypename;
|
||||||
const size_t name_len = sizeof(statfs_info.f_fstypename);
|
const size_t name_len = sizeof(statfs_info.f_fstypename);
|
||||||
#else
|
#else
|
||||||
const char *const name = "";
|
|
||||||
const unsigned name_len = 0;
|
const char *name = "";
|
||||||
|
unsigned name_len = 0;
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
if (fstat(handle, &st))
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
char pathbuf[PATH_MAX];
|
||||||
|
FILE *mounted = nullptr;
|
||||||
|
#if defined(__linux__) || defined(__gnu_linux__)
|
||||||
|
mounted = setmntent("/proc/mounts", "r");
|
||||||
|
#endif /* Linux */
|
||||||
|
if (!mounted)
|
||||||
|
mounted = setmntent("/etc/mtab", "r");
|
||||||
|
if (mounted) {
|
||||||
|
const struct mntent *ent;
|
||||||
|
#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || \
|
||||||
|
(defined(_DEFAULT_SOURCE) && __GLIBC_PREREQ(2, 19))
|
||||||
|
struct mntent entbuf;
|
||||||
|
while (nullptr !=
|
||||||
|
(ent = getmntent_r(mounted, &entbuf, pathbuf, sizeof(pathbuf))))
|
||||||
|
#else
|
||||||
|
while (nullptr != (ent = getmntent(mounted))))
|
||||||
#endif
|
#endif
|
||||||
|
{
|
||||||
|
struct stat mnt;
|
||||||
|
if (!stat(ent->mnt_dir, &mnt) && mnt.st_dev == st.st_dev) {
|
||||||
|
name =
|
||||||
|
strncpy(pathbuf, ent->mnt_fsname, name_len = sizeof(pathbuf) - 1);
|
||||||
|
pathbuf[name_len] = 0;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
endmntent(mounted);
|
||||||
|
}
|
||||||
|
#endif /* !xBSD */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (name_len) {
|
if (name_len) {
|
||||||
|
@ -89,6 +89,10 @@
|
|||||||
#include <sys/vmmeter.h>
|
#include <sys/vmmeter.h>
|
||||||
#else
|
#else
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
|
#if !(defined(__sun) || defined(__SVR4) || defined(__svr4__) || \
|
||||||
|
defined(_WIN32) || defined(_WIN64))
|
||||||
|
#include <mntent.h>
|
||||||
|
#endif /* !Solaris */
|
||||||
#endif /* !xBSD */
|
#endif /* !xBSD */
|
||||||
|
|
||||||
#if defined(__FreeBSD__) || __has_include(<malloc_np.h>)
|
#if defined(__FreeBSD__) || __has_include(<malloc_np.h>)
|
||||||
@ -125,6 +129,7 @@
|
|||||||
|
|
||||||
#if defined(__sun) || defined(__SVR4) || defined(__svr4__)
|
#if defined(__sun) || defined(__SVR4) || defined(__svr4__)
|
||||||
#include <kstat.h>
|
#include <kstat.h>
|
||||||
|
#include <sys/mnttab.h>
|
||||||
/* On Solaris, it's easier to add a missing prototype rather than find a
|
/* On Solaris, it's easier to add a missing prototype rather than find a
|
||||||
* combination of #defines that break nothing. */
|
* combination of #defines that break nothing. */
|
||||||
__extern_C key_t ftok(const char *, int);
|
__extern_C key_t ftok(const char *, int);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user