VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/posix/RTFsMountpointsEnum-posix.cpp@ 103914

Last change on this file since 103914 was 102652, checked in by vboxsync, 12 months ago

IPRT: Implemented RTFsMountpointsEnum(). Extended tstRTFsQueries testcase [more blind Solaris build fixes]. bugref:10415

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.6 KB
Line 
1/* $Id: RTFsMountpointsEnum-posix.cpp 102652 2023-12-20 13:10:20Z vboxsync $ */
2/** @file
3 * IPRT - File System, RTFsMountpointsEnum, POSIX.
4 */
5
6/*
7 * Copyright (C) 2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37
38/*********************************************************************************************************************************
39* Header Files *
40*********************************************************************************************************************************/
41#define LOG_GROUP RTLOGGROUP_FS
42#include <sys/statvfs.h>
43#include <errno.h>
44#include <stdio.h>
45#ifdef RT_OS_LINUX
46# include <mntent.h>
47#endif
48#if defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
49# include <sys/mount.h>
50#endif
51#if defined(RT_OS_SOLARIS)
52# include <sys/mnttab.h>
53#endif
54
55#include <iprt/fs.h>
56#include "internal/iprt.h"
57
58#include <iprt/assert.h>
59#include <iprt/errcore.h>
60#include <iprt/log.h>
61#include "internal/fs.h"
62#include "internal/path.h"
63
64
65RTR3DECL(int) RTFsMountpointsEnum(PFNRTFSMOUNTPOINTENUM pfnCallback, void *pvUser)
66{
67 AssertPtrReturn(pfnCallback, VERR_INVALID_POINTER);
68 /* pvUser is optional. */
69
70 int rc = VINF_SUCCESS;
71
72#if defined(RT_OS_LINUX)
73 FILE *pFile = setmntent("/proc/mounts", "r");
74 if (!pFile)
75 pFile = setmntent(_PATH_MOUNTED, "r");
76 if (pFile)
77 {
78 struct mntent *pEntry;
79 while ((pEntry = getmntent(pFile)) != NULL)
80 {
81 rc = pfnCallback(pEntry->mnt_dir, pvUser);
82 if (RT_FAILURE(rc))
83 break;
84 }
85 endmntent(pFile);
86 }
87 else
88 rc = VERR_ACCESS_DENIED;
89#elif defined(RT_OS_SOLARIS)
90 FILE *pFile = fopen("/etc/mnttab", "r");
91 if (pFile)
92 {
93 struct mnttab Entry;
94 while (getmntent(pFile, &Entry) == 0)
95 {
96 rc = pfnCallback(Entry.mnt_mountp, pvUser);
97 if (RT_FAILURE(rc))
98 break;
99 }
100 fclose(pFile);
101 }
102 else
103 rc = VERR_ACCESS_DENIED;
104#elif defined(RT_OS_DARWIN) || defined(RT_OS_FREEBSD)
105 struct statfs *pEntry;
106 errno = 0;
107 int cEntries = getmntinfo(&pEntry, MNT_NOWAIT);
108 if (errno == 0)
109 {
110 for (; cEntries-- > 0; pEntry++)
111 {
112 rc = pfnCallback(pEntry->f_mntonname, pvUser);
113 if (RT_FAILURE(rc))
114 break;
115 }
116 }
117 else
118 rc = RTErrConvertFromErrno(errno);
119#else
120 rc = VERR_NOT_IMPLEMENTED;
121#endif
122
123 return rc;
124}
125
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette