VirtualBox

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

Last change on this file since 70428 was 69111, checked in by vboxsync, 7 years ago

(C) year

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 8.6 KB
Line 
1/* $Id: fs-nt.cpp 69111 2017-10-17 14:26:02Z vboxsync $ */
2/** @file
3 * IPRT - File System, Native NT.
4 */
5
6/*
7 * Copyright (C) 2006-2017 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/err.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
198RTR3DECL(int) RTFsQueryType(const char *pszFsPath, PRTFSTYPE penmType)
199{
200 /*
201 * Validate input.
202 */
203 *penmType = RTFSTYPE_UNKNOWN;
204 AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER);
205 AssertReturn(*pszFsPath, VERR_INVALID_PARAMETER);
206
207 /*
208 * Open the file/dir/whatever.
209 */
210 HANDLE hFile;
211 int rc = RTNtPathOpen(pszFsPath,
212 GENERIC_READ,
213 FILE_ATTRIBUTE_NORMAL,
214 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
215 FILE_OPEN,
216 FILE_OPEN_FOR_BACKUP_INTENT,
217 OBJ_CASE_INSENSITIVE,
218 &hFile,
219 NULL);
220 if (RT_SUCCESS(rc))
221 {
222 /*
223 * Get the file system name.
224 */
225 union
226 {
227 FILE_FS_ATTRIBUTE_INFORMATION FsAttrInfo;
228 uint8_t abBuf[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 4096];
229 } u;
230 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
231 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &u, sizeof(u), FileFsAttributeInformation);
232 if (NT_SUCCESS(rcNt))
233 {
234#define IS_FS(a_szName) \
235 rtNtCompWideStrAndAscii(u.FsAttrInfo.FileSystemName, u.FsAttrInfo.FileSystemNameLength, RT_STR_TUPLE(a_szName))
236 if (IS_FS("NTFS"))
237 *penmType = RTFSTYPE_NTFS;
238 else if (IS_FS("FAT"))
239 *penmType = RTFSTYPE_FAT;
240 else if (IS_FS("FAT32"))
241 *penmType = RTFSTYPE_FAT;
242 else if (IS_FS("VBoxSharedFolderFS"))
243 *penmType = RTFSTYPE_VBOXSHF;
244#undef IS_FS
245 }
246 else
247 rc = RTErrConvertFromNtStatus(rcNt);
248
249 RTNtPathClose(hFile);
250 }
251 return rc;
252}
253
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