VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/nt/fs-nt.cpp@ 86186

Last change on this file since 86186 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 9.1 KB
Line 
1/* $Id: fs-nt.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * IPRT - File System, Native NT.
4 */
5
6/*
7 * Copyright (C) 2006-2020 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 "internal-r3-nt.h"
33
34#include <iprt/fs.h>
35#include <iprt/file.h>
36#include <iprt/path.h>
37#include <iprt/string.h>
38#include <iprt/param.h>
39#include <iprt/errcore.h>
40#include <iprt/log.h>
41#include <iprt/assert.h>
42#include "internal/fs.h"
43
44
45
46
47RTR3DECL(int) RTFsQuerySizes(const char *pszFsPath, RTFOFF *pcbTotal, RTFOFF *pcbFree,
48 uint32_t *pcbBlock, uint32_t *pcbSector)
49{
50 AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER);
51
52 /*
53 * Open the file/dir/whatever.
54 */
55 HANDLE hFile;
56 int rc = RTNtPathOpen(pszFsPath,
57 GENERIC_READ,
58 FILE_ATTRIBUTE_NORMAL,
59 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
60 FILE_OPEN,
61 FILE_OPEN_FOR_BACKUP_INTENT,
62 OBJ_CASE_INSENSITIVE,
63 &hFile,
64 NULL);
65 if (RT_SUCCESS(rc))
66 {
67 RTFILE hIprtFile = NIL_RTFILE;
68 rc = RTFileFromNative(&hIprtFile, (RTHCINTPTR)hFile);
69 AssertRC(rc);
70 if (RT_SUCCESS(rc))
71 rc = RTFileQueryFsSizes(hIprtFile, pcbTotal, pcbFree, pcbBlock, pcbSector);
72
73 RTNtPathClose(hFile);
74 }
75 return rc;
76}
77
78
79RTR3DECL(int) RTFsQuerySerial(const char *pszFsPath, uint32_t *pu32Serial)
80{
81 /*
82 * Validate & get valid root path.
83 */
84 AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER);
85 AssertPtrReturn(pu32Serial, VERR_INVALID_POINTER);
86
87 /*
88 * Open the file/dir/whatever.
89 */
90 HANDLE hFile;
91 int rc = RTNtPathOpen(pszFsPath,
92 GENERIC_READ,
93 FILE_ATTRIBUTE_NORMAL,
94 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
95 FILE_OPEN,
96 FILE_OPEN_FOR_BACKUP_INTENT,
97 OBJ_CASE_INSENSITIVE,
98 &hFile,
99 NULL);
100 if (RT_SUCCESS(rc))
101 {
102 /*
103 * Get the volume information.
104 */
105 union
106 {
107 FILE_FS_VOLUME_INFORMATION FsVolInfo;
108 uint8_t abBuf[sizeof(FILE_FS_VOLUME_INFORMATION) + 4096];
109 } u;
110 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
111 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &u, sizeof(u), FileFsVolumeInformation);
112 if (NT_SUCCESS(rcNt))
113 *pu32Serial = u.FsVolInfo.VolumeSerialNumber;
114 else
115 rc = RTErrConvertFromNtStatus(rcNt);
116
117 RTNtPathClose(hFile);
118 }
119 return rc;
120}
121
122
123RTR3DECL(int) RTFsQueryProperties(const char *pszFsPath, PRTFSPROPERTIES pProperties)
124{
125 /*
126 * Validate & get valid root path.
127 */
128 AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER);
129 AssertPtrReturn(pProperties, VERR_INVALID_POINTER);
130
131 /*
132 * Open the file/dir/whatever.
133 */
134 HANDLE hFile;
135 int rc = RTNtPathOpen(pszFsPath,
136 GENERIC_READ,
137 FILE_ATTRIBUTE_NORMAL,
138 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
139 FILE_OPEN,
140 FILE_OPEN_FOR_BACKUP_INTENT,
141 OBJ_CASE_INSENSITIVE,
142 &hFile,
143 NULL);
144 if (RT_SUCCESS(rc))
145 {
146 /*
147 * Get the volume information.
148 */
149 union
150 {
151 FILE_FS_ATTRIBUTE_INFORMATION FsAttrInfo;
152 uint8_t abBuf[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 4096];
153 } u;
154 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
155 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &u, sizeof(u), FileFsAttributeInformation);
156 if (NT_SUCCESS(rcNt))
157 {
158 FILE_FS_DEVICE_INFORMATION FsDevInfo;
159 rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &FsDevInfo, sizeof(FsDevInfo), FileFsDeviceInformation);
160 if (NT_SUCCESS(rcNt))
161 {
162 /*
163 * Fill in the return structure.
164 */
165 memset(pProperties, 0, sizeof(*pProperties));
166 pProperties->cbMaxComponent = u.FsAttrInfo.MaximumComponentNameLength;
167 pProperties->fFileCompression = !!(u.FsAttrInfo.FileSystemAttributes & FILE_FILE_COMPRESSION);
168 pProperties->fCompressed = !!(u.FsAttrInfo.FileSystemAttributes & FILE_VOLUME_IS_COMPRESSED);
169 pProperties->fReadOnly = !!(u.FsAttrInfo.FileSystemAttributes & FILE_READ_ONLY_VOLUME);
170 pProperties->fSupportsUnicode = !!(u.FsAttrInfo.FileSystemAttributes & FILE_UNICODE_ON_DISK);
171 pProperties->fCaseSensitive = false; /* win32 is case preserving only */
172 /** @todo r=bird: What about FILE_CASE_SENSITIVE_SEARCH ? Is this set for NTFS
173 * as well perchance? If so, better mention it instead of just setting
174 * fCaseSensitive to false. */
175
176 /* figure the remote stuff */
177 pProperties->fRemote = RT_BOOL(FsDevInfo.Characteristics & FILE_REMOTE_DEVICE);
178 }
179 else
180 rc = RTErrConvertFromNtStatus(rcNt);
181 }
182 else
183 rc = RTErrConvertFromNtStatus(rcNt);
184
185 RTNtPathClose(hFile);
186 }
187 return rc;
188}
189
190
191RTR3DECL(bool) RTFsIsCaseSensitive(const char *pszFsPath)
192{
193 RT_NOREF_PV(pszFsPath);
194 return false;
195}
196
197
198int rtNtQueryFsType(HANDLE hHandle, PRTFSTYPE penmType)
199{
200 /*
201 * Get the file system name.
202 */
203 union
204 {
205 FILE_FS_ATTRIBUTE_INFORMATION FsAttrInfo;
206 uint8_t abBuf[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 4096];
207 } u;
208 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
209 NTSTATUS rcNt = NtQueryVolumeInformationFile(hHandle, &Ios, &u, sizeof(u), FileFsAttributeInformation);
210 if (NT_SUCCESS(rcNt))
211 {
212#define IS_FS(a_szName) rtNtCompWideStrAndAscii(u.FsAttrInfo.FileSystemName, u.FsAttrInfo.FileSystemNameLength, RT_STR_TUPLE(a_szName))
213 if (IS_FS("NTFS"))
214 *penmType = RTFSTYPE_NTFS;
215 else if (IS_FS("FAT"))
216 *penmType = RTFSTYPE_FAT;
217 else if (IS_FS("FAT32"))
218 *penmType = RTFSTYPE_FAT;
219 else if (IS_FS("exFAT"))
220 *penmType = RTFSTYPE_EXFAT;
221 else if (IS_FS("UDF"))
222 *penmType = RTFSTYPE_UDF;
223 else if (IS_FS("CDFS"))
224 *penmType = RTFSTYPE_ISO9660;
225 else if (IS_FS("HPFS"))
226 *penmType = RTFSTYPE_HPFS;
227 else if (IS_FS("ReFS")) /** @todo verify ReFS signature. */
228 *penmType = RTFSTYPE_REFS;
229 else if (IS_FS("VBoxSharedFolderFS"))
230 *penmType = RTFSTYPE_VBOXSHF;
231#undef IS_FS
232 return VINF_SUCCESS;
233 }
234
235 *penmType = RTFSTYPE_UNKNOWN;
236 return RTErrConvertFromNtStatus(rcNt);
237}
238
239
240RTR3DECL(int) RTFsQueryType(const char *pszFsPath, PRTFSTYPE penmType)
241{
242 /*
243 * Validate input.
244 */
245 *penmType = RTFSTYPE_UNKNOWN;
246 AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER);
247 AssertReturn(*pszFsPath, VERR_INVALID_PARAMETER);
248
249 /*
250 * Open the file/dir/whatever.
251 */
252 HANDLE hFile;
253 int rc = RTNtPathOpen(pszFsPath,
254 GENERIC_READ,
255 FILE_ATTRIBUTE_NORMAL,
256 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
257 FILE_OPEN,
258 FILE_OPEN_FOR_BACKUP_INTENT,
259 OBJ_CASE_INSENSITIVE,
260 &hFile,
261 NULL);
262 if (RT_SUCCESS(rc))
263 {
264 rc = rtNtQueryFsType(hFile, penmType);
265 RTNtPathClose(hFile);
266 }
267 return rc;
268}
269
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