VirtualBox

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

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

iprt: More path conversion avoidance.

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