VirtualBox

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

Last change on this file since 25776 was 8245, checked in by vboxsync, 17 years ago

rebranding: IPRT files again.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 5.6 KB
Line 
1/* $Id: fs-posix.cpp 8245 2008-04-21 17:24:28Z 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 <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 = {0};
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);
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 *pszNativeFsPath;
106 int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
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);
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 *pszNativeFsPath;
137 int rc = rtPathToNative(&pszNativeFsPath, pszFsPath);
138 if (RT_SUCCESS(rc))
139 {
140 struct statvfs StatVFS = {0};
141 if (!statvfs(pszNativeFsPath, &StatVFS))
142 {
143 /*
144 * Calc/fake the returned values.
145 */
146 pProperties->cbMaxComponent = StatVFS.f_namemax;
147 pProperties->fCaseSensitive = true;
148 pProperties->fCompressed = false;
149 pProperties->fFileCompression = false;
150 pProperties->fReadOnly = !!(StatVFS.f_flag & ST_RDONLY);
151 pProperties->fRemote = false;
152 pProperties->fSupportsUnicode = true;
153 }
154 else
155 rc = RTErrConvertFromErrno(errno);
156 rtPathFreeNative(pszNativeFsPath);
157 }
158
159 LogFlow(("RTFsQueryProperties(%p:{%s}, %p:{.cbMaxComponent=%u, .fCaseSensitive=%RTbool}): returns %Rrc\n",
160 pszFsPath, pszFsPath, pProperties, pProperties->cbMaxComponent, pProperties->fReadOnly));
161 return VINF_SUCCESS;
162}
163
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