Skip to content

Commit ba1bbca

Browse files
committed
Added routine to obtain mount information for MacOS
1 parent bd8ce35 commit ba1bbca

File tree

1 file changed

+50
-20
lines changed

1 file changed

+50
-20
lines changed

src/main/runtime/system.cpp

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <lsp-plug.in/io/Dir.h>
2525
#include <lsp-plug.in/ipc/Process.h>
2626
#include <lsp-plug.in/lltl/darray.h>
27+
#include <lsp-plug.in/lltl/parray.h>
2728
#include <lsp-plug.in/runtime/system.h>
2829
#include <lsp-plug.in/stdlib/stdlib.h>
2930

@@ -49,13 +50,13 @@
4950
#include <mntent.h>
5051
#endif /* PLATFORM_LINUX */
5152

52-
#if defined PLATFORM_BSD
53+
#if defined(PLATFORM_BSD) || defined (PLATFORM_MACOSX)
5354
#include <sys/mount.h>
5455
#include <sys/param.h>
5556
#include <sys/ucred.h>
56-
#endif /* PLATFORM_BSD */
57+
#endif /* PLATFORM_BSD || PLATFORM_MACOSX */
5758

58-
#if defined PLATFORM_HAIKU
59+
#ifdef PLATFORM_HAIKU
5960
#include <posix/stdlib.h>
6061
#include <sys/mount.h>
6162
#include <sys/param.h>
@@ -1008,20 +1009,51 @@ namespace lsp
10081009
}
10091010
#endif /* PLATFORM_LINUX */
10101011

1011-
#ifdef PLATFORM_BSD
1012-
static status_t read_bsd_mntinfo(lltl::parray<volume_info_t> *volumes)
1012+
#if defined(PLATFORM_BSD) || defined(PLATFORM_MACOSX)
1013+
static status_t read_fsstat(lltl::darray<struct statfs> *list)
10131014
{
1014-
struct statfs *fsp;
1015+
if (!list->add_n(32))
1016+
return STATUS_NO_MEM;
1017+
1018+
while (true)
1019+
{
1020+
int res = getfsstat(list->array(), list->size(), MNT_NOWAIT);
1021+
if (res < 0)
1022+
{
1023+
int error = errno;
1024+
switch (error)
1025+
{
1026+
case EFAULT: return STATUS_INVALID_VALUE;
1027+
case EIO: return STATUS_IO_ERROR;
1028+
default: return STATUS_UNKNOWN_ERR;
1029+
}
1030+
}
1031+
else if (size_t(res) < list->size())
1032+
return STATUS_OK;
1033+
1034+
// Grow the size of the list
1035+
if (!list->add_n(list->size() >> 1))
1036+
return STATUS_NO_MEM;
1037+
}
1038+
}
1039+
1040+
static status_t read_fsstat_mntinfo(lltl::parray<volume_info_t> *volumes)
1041+
{
1042+
// Read fsstat data
1043+
lltl::darray<struct statfs> fspl;
1044+
status_t res = read_fsstat(&fspl);
1045+
if (res != STATUS_OK)
1046+
return res;
1047+
1048+
// Parse fsstat data
10151049
lltl::parray<volume_info_t> list;
10161050
lsp_finally { free_volume_info(&list); };
10171051

1018-
// Get mount information
1019-
int entries = getmntinfo (&fsp, MNT_NOWAIT);
1020-
if (entries < 0)
1021-
return STATUS_NOT_SUPPORTED;
1022-
1023-
for (int i=0; i < entries; ++fsp, ++i)
1052+
for (size_t i=0, n=fspl.size(); i<n; ++i)
10241053
{
1054+
// Process one single structure
1055+
const struct statfs *fsp = fspl.uget(i);
1056+
10251057
// Create record
10261058
volume_info_t *info = new volume_info_t();
10271059
if (info == NULL)
@@ -1056,7 +1088,7 @@ namespace lsp
10561088
list.swap(volumes);
10571089
return STATUS_OK;
10581090
}
1059-
#endif /* PLATFORM_BSD */
1091+
#endif /* PLATFORM_BSD || PLATFORM_MACOSX */
10601092

10611093
#ifdef PLATFORM_WINDOWS
10621094
status_t read_pathnames(const WCHAR *volume, WCHAR **list, size_t *cap)
@@ -1326,7 +1358,7 @@ namespace lsp
13261358
return STATUS_BAD_ARGUMENTS;
13271359

13281360
status_t res = STATUS_NOT_IMPLEMENTED;
1329-
#ifdef PLATFORM_LINUX
1361+
#if defined(PLATFORM_LINUX)
13301362
if ((res = read_linux_mountinfo(volumes)) != STATUS_NOT_SUPPORTED)
13311363
return res;
13321364
if ((res = read_linux_mntent("/proc/self/mounts", volumes)) != STATUS_NOT_SUPPORTED)
@@ -1335,16 +1367,14 @@ namespace lsp
13351367
return res;
13361368
if ((res = read_linux_mntent("/etc/mtab", volumes)) != STATUS_NOT_SUPPORTED)
13371369
return res;
1338-
#endif /* PLATFORM_LINUX */
1339-
#ifdef PLATFORM_BSD
1340-
if ((res = read_bsd_mntinfo(volumes)) != STATUS_NOT_SUPPORTED)
1370+
#elif defined(PLATFORM_BSD) || defined(PLATFORM_MACOSX)
1371+
if ((res = read_fsstat_mntinfo(volumes)) != STATUS_NOT_SUPPORTED)
13411372
return res;
1342-
#endif /* PLATFORM_BSD */
1343-
#ifdef PLATFORM_WINDOWS
1373+
#elif defined(PLATFORM_WINDOWS)
13441374
res = read_windows_mntinfo(volumes);
13451375
if (res == STATUS_OK)
13461376
res = read_windows_netinfo(volumes);
1347-
#endif /* PLATFORM_WINDOWS */
1377+
#endif
13481378

13491379
return res;
13501380
}

0 commit comments

Comments
 (0)