VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/posix/fs-posix.cpp@ 26255

Last change on this file since 26255 was 26255, checked in by vboxsync, 15 years ago

fs-posix.cpp: {0} initializer warnings.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1/* $Id: fs-posix.cpp 26255 2010-02-05 00:58:47Z 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.215389.xyz. 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 <iprt/err.h>
41#include <iprt/log.h>
42#include <iprt/assert.h>
43#include "internal/fs.h"
44#include "internal/path.h"
45
46
47
48RTR3DECL(int) RTFsQuerySizes(const char *pszFsPath, RTFOFF *pcbTotal, RTFOFF *pcbFree,
49 uint32_t *pcbBlock, uint32_t *pcbSector)
50{
51 /*
52 * Validate input.
53 */
54 AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER);
55
56 /*
57 * Convert the path and query the information.
58 */
59 char *pszNativeFsPath;
60 int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
61 if (RT_SUCCESS(rc))
62 {
63 /** @todo I'm not quite sure if statvfs was properly specified by SuS, I have to check my own
64 * implementation and FreeBSD before this can eventually be promoted to posix. */
65 struct statvfs StatVFS;
66 RT_ZERO(StatVFS);
67 if (!statvfs(pszNativeFsPath, &StatVFS))
68 {
69 /*
70 * Calc the returned values.
71 */
72 if (pcbTotal)
73 *pcbTotal = (RTFOFF)StatVFS.f_blocks * StatVFS.f_frsize;
74 if (pcbFree)
75 *pcbFree = (RTFOFF)StatVFS.f_bavail * StatVFS.f_frsize;
76 if (pcbBlock)
77 *pcbBlock = StatVFS.f_frsize;
78 /* no idea how to get the sector... */
79 if (pcbSector)
80 *pcbSector = 512;
81 }
82 else
83 rc = RTErrConvertFromErrno(errno);
84 rtPathFreeNative(pszNativeFsPath);
85 }
86
87 LogFlow(("RTFsQuerySizes(%p:{%s}, %p:{%RTfoff}, %p:{%RTfoff}, %p:{%RX32}, %p:{%RX32}): returns %Rrc\n",
88 pszFsPath, pszFsPath, pcbTotal, pcbTotal ? *pcbTotal : 0, pcbFree, pcbFree ? *pcbFree : 0,
89 pcbBlock, pcbBlock ? *pcbBlock : 0, pcbSector, pcbSector ? *pcbSector : 0, rc));
90 return rc;
91}
92
93
94RTR3DECL(int) RTFsQuerySerial(const char *pszFsPath, uint32_t *pu32Serial)
95{
96 /*
97 * Validate input.
98 */
99 AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER);
100 AssertMsgReturn(VALID_PTR(pu32Serial), ("%p", pu32Serial), VERR_INVALID_PARAMETER);
101
102 /*
103 * Conver the path and query the stats.
104 * We're simply return the device id.
105 */
106 char *pszNativeFsPath;
107 int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
108 if (RT_SUCCESS(rc))
109 {
110 struct stat Stat;
111 if (!stat(pszNativeFsPath, &Stat))
112 {
113 if (pu32Serial)
114 *pu32Serial = (uint32_t)Stat.st_dev;
115 }
116 else
117 rc = RTErrConvertFromErrno(errno);
118 rtPathFreeNative(pszNativeFsPath);
119 }
120 LogFlow(("RTFsQuerySerial(%p:{%s}, %p:{%RX32}: returns %Rrc\n",
121 pszFsPath, pszFsPath, pu32Serial, pu32Serial ? *pu32Serial : 0, rc));
122 return rc;
123}
124
125
126RTR3DECL(int) RTFsQueryProperties(const char *pszFsPath, PRTFSPROPERTIES pProperties)
127{
128 /*
129 * Validate.
130 */
131 AssertMsgReturn(VALID_PTR(pszFsPath) && *pszFsPath, ("%p", pszFsPath), VERR_INVALID_PARAMETER);
132 AssertMsgReturn(VALID_PTR(pProperties), ("%p", pProperties), VERR_INVALID_PARAMETER);
133
134 /*
135 * Convert the path and query the information.
136 */
137 char *pszNativeFsPath;
138 int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
139 if (RT_SUCCESS(rc))
140 {
141 struct statvfs StatVFS;
142 RT_ZERO(StatVFS);
143 if (!statvfs(pszNativeFsPath, &StatVFS))
144 {
145 /*
146 * Calc/fake the returned values.
147 */
148 pProperties->cbMaxComponent = StatVFS.f_namemax;
149 pProperties->fCaseSensitive = true;
150 pProperties->fCompressed = false;
151 pProperties->fFileCompression = false;
152 pProperties->fReadOnly = !!(StatVFS.f_flag & ST_RDONLY);
153 pProperties->fRemote = false;
154 pProperties->fSupportsUnicode = true;
155 }
156 else
157 rc = RTErrConvertFromErrno(errno);
158 rtPathFreeNative(pszNativeFsPath);
159 }
160
161 LogFlow(("RTFsQueryProperties(%p:{%s}, %p:{.cbMaxComponent=%u, .fCaseSensitive=%RTbool}): returns %Rrc\n",
162 pszFsPath, pszFsPath, pProperties, pProperties->cbMaxComponent, pProperties->fReadOnly));
163 return VINF_SUCCESS;
164}
165
Note: See TracBrowser for help on using the repository browser.

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