1 | /* $Id: fs-posix.cpp 26256 2010-02-05 01:04:31Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - File System, Linux.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2007 Sun Microsystems, Inc.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | *
|
---|
26 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
|
---|
27 | * Clara, CA 95054 USA or visit http://www.sun.com if you need
|
---|
28 | * additional information or have any questions.
|
---|
29 | */
|
---|
30 |
|
---|
31 |
|
---|
32 | /*******************************************************************************
|
---|
33 | * Header Files *
|
---|
34 | *******************************************************************************/
|
---|
35 | #define LOG_GROUP RTLOGGROUP_FS
|
---|
36 | #include <sys/statvfs.h>
|
---|
37 | #include <errno.h>
|
---|
38 |
|
---|
39 | #include <iprt/fs.h>
|
---|
40 | #include "internal/iprt.h"
|
---|
41 |
|
---|
42 | #include <iprt/assert.h>
|
---|
43 | #include <iprt/err.h>
|
---|
44 | #include <iprt/log.h>
|
---|
45 | #include <iprt/string.h>
|
---|
46 | #include "internal/fs.h"
|
---|
47 | #include "internal/path.h"
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
51 | RTR3DECL(int) RTFsQuerySizes(const char *pszFsPath, RTFOFF *pcbTotal, RTFOFF *pcbFree,
|
---|
52 | uint32_t *pcbBlock, uint32_t *pcbSector)
|
---|
53 | {
|
---|
54 | /*
|
---|
55 | * Validate input.
|
---|
56 | */
|
---|
57 | AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER);
|
---|
58 |
|
---|
59 | /*
|
---|
60 | * Convert the path and query the information.
|
---|
61 | */
|
---|
62 | char *pszNativeFsPath;
|
---|
63 | int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
|
---|
64 | if (RT_SUCCESS(rc))
|
---|
65 | {
|
---|
66 | /** @todo I'm not quite sure if statvfs was properly specified by SuS, I have to check my own
|
---|
67 | * implementation and FreeBSD before this can eventually be promoted to posix. */
|
---|
68 | struct statvfs StatVFS;
|
---|
69 | RT_ZERO(StatVFS);
|
---|
70 | if (!statvfs(pszNativeFsPath, &StatVFS))
|
---|
71 | {
|
---|
72 | /*
|
---|
73 | * Calc the returned values.
|
---|
74 | */
|
---|
75 | if (pcbTotal)
|
---|
76 | *pcbTotal = (RTFOFF)StatVFS.f_blocks * StatVFS.f_frsize;
|
---|
77 | if (pcbFree)
|
---|
78 | *pcbFree = (RTFOFF)StatVFS.f_bavail * StatVFS.f_frsize;
|
---|
79 | if (pcbBlock)
|
---|
80 | *pcbBlock = StatVFS.f_frsize;
|
---|
81 | /* no idea how to get the sector... */
|
---|
82 | if (pcbSector)
|
---|
83 | *pcbSector = 512;
|
---|
84 | }
|
---|
85 | else
|
---|
86 | rc = RTErrConvertFromErrno(errno);
|
---|
87 | rtPathFreeNative(pszNativeFsPath);
|
---|
88 | }
|
---|
89 |
|
---|
90 | LogFlow(("RTFsQuerySizes(%p:{%s}, %p:{%RTfoff}, %p:{%RTfoff}, %p:{%RX32}, %p:{%RX32}): returns %Rrc\n",
|
---|
91 | pszFsPath, pszFsPath, pcbTotal, pcbTotal ? *pcbTotal : 0, pcbFree, pcbFree ? *pcbFree : 0,
|
---|
92 | pcbBlock, pcbBlock ? *pcbBlock : 0, pcbSector, pcbSector ? *pcbSector : 0, rc));
|
---|
93 | return rc;
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | RTR3DECL(int) RTFsQuerySerial(const char *pszFsPath, uint32_t *pu32Serial)
|
---|
98 | {
|
---|
99 | /*
|
---|
100 | * Validate input.
|
---|
101 | */
|
---|
102 | AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER);
|
---|
103 | AssertMsgReturn(VALID_PTR(pu32Serial), ("%p", pu32Serial), VERR_INVALID_PARAMETER);
|
---|
104 |
|
---|
105 | /*
|
---|
106 | * Conver the path and query the stats.
|
---|
107 | * We're simply return the device id.
|
---|
108 | */
|
---|
109 | char *pszNativeFsPath;
|
---|
110 | int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
|
---|
111 | if (RT_SUCCESS(rc))
|
---|
112 | {
|
---|
113 | struct stat Stat;
|
---|
114 | if (!stat(pszNativeFsPath, &Stat))
|
---|
115 | {
|
---|
116 | if (pu32Serial)
|
---|
117 | *pu32Serial = (uint32_t)Stat.st_dev;
|
---|
118 | }
|
---|
119 | else
|
---|
120 | rc = RTErrConvertFromErrno(errno);
|
---|
121 | rtPathFreeNative(pszNativeFsPath);
|
---|
122 | }
|
---|
123 | LogFlow(("RTFsQuerySerial(%p:{%s}, %p:{%RX32}: returns %Rrc\n",
|
---|
124 | pszFsPath, pszFsPath, pu32Serial, pu32Serial ? *pu32Serial : 0, rc));
|
---|
125 | return rc;
|
---|
126 | }
|
---|
127 |
|
---|
128 |
|
---|
129 | RTR3DECL(int) RTFsQueryProperties(const char *pszFsPath, PRTFSPROPERTIES pProperties)
|
---|
130 | {
|
---|
131 | /*
|
---|
132 | * Validate.
|
---|
133 | */
|
---|
134 | AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER);
|
---|
135 | AssertMsgReturn(VALID_PTR(pProperties), ("%p", pProperties), VERR_INVALID_PARAMETER);
|
---|
136 |
|
---|
137 | /*
|
---|
138 | * Convert the path and query the information.
|
---|
139 | */
|
---|
140 | char *pszNativeFsPath;
|
---|
141 | int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
|
---|
142 | if (RT_SUCCESS(rc))
|
---|
143 | {
|
---|
144 | struct statvfs StatVFS;
|
---|
145 | RT_ZERO(StatVFS);
|
---|
146 | if (!statvfs(pszNativeFsPath, &StatVFS))
|
---|
147 | {
|
---|
148 | /*
|
---|
149 | * Calc/fake the returned values.
|
---|
150 | */
|
---|
151 | pProperties->cbMaxComponent = StatVFS.f_namemax;
|
---|
152 | pProperties->fCaseSensitive = true;
|
---|
153 | pProperties->fCompressed = false;
|
---|
154 | pProperties->fFileCompression = false;
|
---|
155 | pProperties->fReadOnly = !!(StatVFS.f_flag & ST_RDONLY);
|
---|
156 | pProperties->fRemote = false;
|
---|
157 | pProperties->fSupportsUnicode = true;
|
---|
158 | }
|
---|
159 | else
|
---|
160 | rc = RTErrConvertFromErrno(errno);
|
---|
161 | rtPathFreeNative(pszNativeFsPath);
|
---|
162 | }
|
---|
163 |
|
---|
164 | LogFlow(("RTFsQueryProperties(%p:{%s}, %p:{.cbMaxComponent=%u, .fCaseSensitive=%RTbool}): returns %Rrc\n",
|
---|
165 | pszFsPath, pszFsPath, pProperties, pProperties->cbMaxComponent, pProperties->fReadOnly));
|
---|
166 | return VINF_SUCCESS;
|
---|
167 | }
|
---|
168 |
|
---|