VirtualBox

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

Last change on this file since 4512 was 4071, checked in by vboxsync, 17 years ago

Biggest check-in ever. New source code headers for all (C) innotek files.

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