- Timestamp:
- Nov 9, 2016 5:03:40 PM (8 years ago)
- Location:
- trunk/src/VBox/Runtime
- Files:
-
- 3 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/Makefile.kmk
r64340 r64619 792 792 r3/nt/fs-nt.cpp \ 793 793 r3/nt/pathint-nt.cpp \ 794 r3/nt/RTFileQueryFsSizes-nt.cpp \ 794 795 r3/nt/RTProcQueryParent-r3-nt.cpp \ 795 796 r3/win/env-win.cpp \ -
trunk/src/VBox/Runtime/r3/nt/RTFileQueryFsSizes-nt.cpp
r64613 r64619 1 1 /* $Id$ */ 2 2 /** @file 3 * IPRT - File System, Native NT.3 * IPRT - RTFileQueryFsSizes, Native NT. 4 4 */ 5 5 … … 29 29 * Header Files * 30 30 *********************************************************************************************************************************/ 31 #define LOG_GROUP RTLOGGROUP_F S31 #define LOG_GROUP RTLOGGROUP_FILE 32 32 #include "internal-r3-nt.h" 33 33 34 #include <iprt/fs.h> 35 #include <iprt/path.h> 36 #include <iprt/string.h> 37 #include <iprt/param.h> 34 #include <iprt/file.h> 38 35 #include <iprt/err.h> 39 #include <iprt/log.h>40 #include <iprt/assert.h>41 #include "internal/fs.h"42 36 43 37 44 38 45 46 RTR3DECL(int) RTFsQuerySizes(const char *pszFsPath, RTFOFF *pcbTotal, RTFOFF *pcbFree, 47 uint32_t *pcbBlock, uint32_t *pcbSector) 39 RTR3DECL(int) RTFileQueryFsSizes(RTFILE hFile, PRTFOFF pcbTotal, RTFOFF *pcbFree, 40 uint32_t *pcbBlock, uint32_t *pcbSector) 48 41 { 49 AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER);42 int rc; 50 43 51 44 /* 52 * Open the file/dir/whatever.45 * Get the volume information. 53 46 */ 54 HANDLE hFile; 55 int rc = RTNtPathOpen(pszFsPath, 56 GENERIC_READ, 57 FILE_ATTRIBUTE_NORMAL, 58 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, 59 FILE_OPEN, 60 FILE_OPEN_FOR_BACKUP_INTENT, 61 OBJ_CASE_INSENSITIVE, 62 &hFile, 63 NULL); 64 if (RT_SUCCESS(rc)) 47 FILE_FS_SIZE_INFORMATION FsSizeInfo; 48 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER; 49 NTSTATUS rcNt = NtQueryVolumeInformationFile((HANDLE)RTFileToNative(hFile), &Ios, 50 &FsSizeInfo, sizeof(FsSizeInfo), FileFsSizeInformation); 51 if (NT_SUCCESS(rcNt)) 65 52 { 66 53 /* 67 * Get the volume information.54 * Calculate the return values. 68 55 */ 69 FILE_FS_SIZE_INFORMATION FsSizeInfo; 70 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER; 71 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &FsSizeInfo, sizeof(FsSizeInfo), FileFsSizeInformation); 72 if (NT_SUCCESS(rcNt)) 56 if (pcbTotal) 73 57 { 74 /* 75 * Calculate the return values. 76 */ 77 if (pcbTotal) 78 { 79 *pcbTotal = FsSizeInfo.TotalAllocationUnits.QuadPart 80 * FsSizeInfo.SectorsPerAllocationUnit 81 * FsSizeInfo.BytesPerSector; 82 if ( *pcbTotal / FsSizeInfo.SectorsPerAllocationUnit / FsSizeInfo.BytesPerSector 83 != FsSizeInfo.TotalAllocationUnits.QuadPart) 84 *pcbTotal = UINT64_MAX; 85 } 58 *pcbTotal = FsSizeInfo.TotalAllocationUnits.QuadPart 59 * FsSizeInfo.SectorsPerAllocationUnit 60 * FsSizeInfo.BytesPerSector; 61 if ( *pcbTotal / FsSizeInfo.SectorsPerAllocationUnit / FsSizeInfo.BytesPerSector 62 != FsSizeInfo.TotalAllocationUnits.QuadPart) 63 *pcbTotal = UINT64_MAX; 64 } 86 65 87 88 89 90 91 92 93 94 95 66 if (pcbFree) 67 { 68 *pcbFree = FsSizeInfo.AvailableAllocationUnits.QuadPart 69 * FsSizeInfo.SectorsPerAllocationUnit 70 * FsSizeInfo.BytesPerSector; 71 if ( *pcbFree / FsSizeInfo.SectorsPerAllocationUnit / FsSizeInfo.BytesPerSector 72 != FsSizeInfo.AvailableAllocationUnits.QuadPart) 73 *pcbFree = UINT64_MAX; 74 } 96 75 97 if (pcbBlock) 98 { 99 *pcbBlock = FsSizeInfo.SectorsPerAllocationUnit * FsSizeInfo.BytesPerSector; 100 if (*pcbBlock / FsSizeInfo.BytesPerSector != FsSizeInfo.SectorsPerAllocationUnit) 101 rc = VERR_OUT_OF_RANGE; 102 } 76 rc = VINF_SUCCESS; 77 if (pcbBlock) 78 { 79 *pcbBlock = FsSizeInfo.SectorsPerAllocationUnit * FsSizeInfo.BytesPerSector; 80 if (*pcbBlock / FsSizeInfo.BytesPerSector != FsSizeInfo.SectorsPerAllocationUnit) 81 rc = VERR_OUT_OF_RANGE; 82 } 103 83 104 105 106 107 108 84 if (pcbSector) 85 *pcbSector = FsSizeInfo.BytesPerSector; 86 } 87 else 88 rc = RTErrConvertFromNtStatus(rcNt); 109 89 110 RTNtPathClose(hFile);111 }112 90 return rc; 113 91 } 114 92 115 116 RTR3DECL(int) RTFsQuerySerial(const char *pszFsPath, uint32_t *pu32Serial)117 {118 /*119 * Validate & get valid root path.120 */121 AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER);122 AssertPtrReturn(pu32Serial, VERR_INVALID_POINTER);123 124 /*125 * Open the file/dir/whatever.126 */127 HANDLE hFile;128 int rc = RTNtPathOpen(pszFsPath,129 GENERIC_READ,130 FILE_ATTRIBUTE_NORMAL,131 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,132 FILE_OPEN,133 FILE_OPEN_FOR_BACKUP_INTENT,134 OBJ_CASE_INSENSITIVE,135 &hFile,136 NULL);137 if (RT_SUCCESS(rc))138 {139 /*140 * Get the volume information.141 */142 union143 {144 FILE_FS_VOLUME_INFORMATION FsVolInfo;145 uint8_t abBuf[sizeof(FILE_FS_VOLUME_INFORMATION) + 4096];146 } u;147 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;148 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &u, sizeof(u), FileFsVolumeInformation);149 if (NT_SUCCESS(rcNt))150 *pu32Serial = u.FsVolInfo.VolumeSerialNumber;151 else152 rc = RTErrConvertFromNtStatus(rcNt);153 154 RTNtPathClose(hFile);155 }156 return rc;157 }158 159 160 RTR3DECL(int) RTFsQueryProperties(const char *pszFsPath, PRTFSPROPERTIES pProperties)161 {162 /*163 * Validate & get valid root path.164 */165 AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER);166 AssertPtrReturn(pProperties, VERR_INVALID_POINTER);167 168 /*169 * Open the file/dir/whatever.170 */171 HANDLE hFile;172 int rc = RTNtPathOpen(pszFsPath,173 GENERIC_READ,174 FILE_ATTRIBUTE_NORMAL,175 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,176 FILE_OPEN,177 FILE_OPEN_FOR_BACKUP_INTENT,178 OBJ_CASE_INSENSITIVE,179 &hFile,180 NULL);181 if (RT_SUCCESS(rc))182 {183 /*184 * Get the volume information.185 */186 union187 {188 FILE_FS_ATTRIBUTE_INFORMATION FsAttrInfo;189 uint8_t abBuf[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 4096];190 } u;191 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;192 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &u, sizeof(u), FileFsAttributeInformation);193 if (NT_SUCCESS(rcNt))194 {195 FILE_FS_DEVICE_INFORMATION FsDevInfo;196 rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &FsDevInfo, sizeof(FsDevInfo), FileFsDeviceInformation);197 if (NT_SUCCESS(rcNt))198 {199 /*200 * Fill in the return structure.201 */202 memset(pProperties, 0, sizeof(*pProperties));203 pProperties->cbMaxComponent = u.FsAttrInfo.MaximumComponentNameLength;204 pProperties->fFileCompression = !!(u.FsAttrInfo.FileSystemAttributes & FILE_FILE_COMPRESSION);205 pProperties->fCompressed = !!(u.FsAttrInfo.FileSystemAttributes & FILE_VOLUME_IS_COMPRESSED);206 pProperties->fReadOnly = !!(u.FsAttrInfo.FileSystemAttributes & FILE_READ_ONLY_VOLUME);207 pProperties->fSupportsUnicode = !!(u.FsAttrInfo.FileSystemAttributes & FILE_UNICODE_ON_DISK);208 pProperties->fCaseSensitive = false; /* win32 is case preserving only */209 /** @todo r=bird: What about FILE_CASE_SENSITIVE_SEARCH ? Is this set for NTFS210 * as well perchance? If so, better mention it instead of just setting211 * fCaseSensitive to false. */212 213 /* figure the remote stuff */214 pProperties->fRemote = RT_BOOL(FsDevInfo.Characteristics & FILE_REMOTE_DEVICE);215 }216 else217 rc = RTErrConvertFromNtStatus(rcNt);218 }219 else220 rc = RTErrConvertFromNtStatus(rcNt);221 222 RTNtPathClose(hFile);223 }224 return rc;225 }226 227 228 RTR3DECL(bool) RTFsIsCaseSensitive(const char *pszFsPath)229 {230 RT_NOREF_PV(pszFsPath);231 return false;232 }233 234 235 RTR3DECL(int) RTFsQueryType(const char *pszFsPath, PRTFSTYPE penmType)236 {237 /*238 * Validate input.239 */240 *penmType = RTFSTYPE_UNKNOWN;241 AssertPtrReturn(pszFsPath, VERR_INVALID_POINTER);242 AssertReturn(*pszFsPath, VERR_INVALID_PARAMETER);243 244 /*245 * Open the file/dir/whatever.246 */247 HANDLE hFile;248 int rc = RTNtPathOpen(pszFsPath,249 GENERIC_READ,250 FILE_ATTRIBUTE_NORMAL,251 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,252 FILE_OPEN,253 FILE_OPEN_FOR_BACKUP_INTENT,254 OBJ_CASE_INSENSITIVE,255 &hFile,256 NULL);257 if (RT_SUCCESS(rc))258 {259 /*260 * Get the file system name.261 */262 union263 {264 FILE_FS_ATTRIBUTE_INFORMATION FsAttrInfo;265 uint8_t abBuf[sizeof(FILE_FS_ATTRIBUTE_INFORMATION) + 4096];266 } u;267 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;268 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &u, sizeof(u), FileFsAttributeInformation);269 if (NT_SUCCESS(rcNt))270 {271 #define IS_FS(a_szName) \272 rtNtCompWideStrAndAscii(u.FsAttrInfo.FileSystemName, u.FsAttrInfo.FileSystemNameLength, RT_STR_TUPLE(a_szName))273 if (IS_FS("NTFS"))274 *penmType = RTFSTYPE_NTFS;275 else if (IS_FS("FAT"))276 *penmType = RTFSTYPE_FAT;277 else if (IS_FS("FAT32"))278 *penmType = RTFSTYPE_FAT;279 else if (IS_FS("VBoxSharedFolderFS"))280 *penmType = RTFSTYPE_VBOXSHF;281 #undef IS_FS282 }283 else284 rc = RTErrConvertFromNtStatus(rcNt);285 286 RTNtPathClose(hFile);287 }288 return rc;289 }290 -
trunk/src/VBox/Runtime/r3/nt/fs-nt.cpp
r62584 r64619 33 33 34 34 #include <iprt/fs.h> 35 #include <iprt/file.h> 35 36 #include <iprt/path.h> 36 37 #include <iprt/string.h> … … 64 65 if (RT_SUCCESS(rc)) 65 66 { 66 /* 67 * Get the volume information. 68 */ 69 FILE_FS_SIZE_INFORMATION FsSizeInfo; 70 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER; 71 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &FsSizeInfo, sizeof(FsSizeInfo), FileFsSizeInformation); 72 if (NT_SUCCESS(rcNt)) 73 { 74 /* 75 * Calculate the return values. 76 */ 77 if (pcbTotal) 78 { 79 *pcbTotal = FsSizeInfo.TotalAllocationUnits.QuadPart 80 * FsSizeInfo.SectorsPerAllocationUnit 81 * FsSizeInfo.BytesPerSector; 82 if ( *pcbTotal / FsSizeInfo.SectorsPerAllocationUnit / FsSizeInfo.BytesPerSector 83 != FsSizeInfo.TotalAllocationUnits.QuadPart) 84 *pcbTotal = UINT64_MAX; 85 } 86 87 if (pcbFree) 88 { 89 *pcbFree = FsSizeInfo.AvailableAllocationUnits.QuadPart 90 * FsSizeInfo.SectorsPerAllocationUnit 91 * FsSizeInfo.BytesPerSector; 92 if ( *pcbFree / FsSizeInfo.SectorsPerAllocationUnit / FsSizeInfo.BytesPerSector 93 != FsSizeInfo.AvailableAllocationUnits.QuadPart) 94 *pcbFree = UINT64_MAX; 95 } 96 97 if (pcbBlock) 98 { 99 *pcbBlock = FsSizeInfo.SectorsPerAllocationUnit * FsSizeInfo.BytesPerSector; 100 if (*pcbBlock / FsSizeInfo.BytesPerSector != FsSizeInfo.SectorsPerAllocationUnit) 101 rc = VERR_OUT_OF_RANGE; 102 } 103 104 if (pcbSector) 105 *pcbSector = FsSizeInfo.BytesPerSector; 106 } 107 else 108 rc = RTErrConvertFromNtStatus(rcNt); 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); 109 72 110 73 RTNtPathClose(hFile); -
trunk/src/VBox/Runtime/r3/win/fileio-win.cpp
r62592 r64619 1004 1004 1005 1005 1006 RTR3DECL(int) RTFileQueryFsSizes(RTFILE hFile, PRTFOFF pcbTotal, RTFOFF *pcbFree, 1007 uint32_t *pcbBlock, uint32_t *pcbSector) 1008 { 1009 /** @todo implement this using NtQueryVolumeInformationFile(hFile,,,, 1010 * FileFsSizeInformation). */ 1011 RT_NOREF_PV(hFile); RT_NOREF_PV(pcbTotal); RT_NOREF_PV(pcbFree); RT_NOREF_PV(pcbBlock); RT_NOREF_PV(pcbSector); 1012 return VERR_NOT_SUPPORTED; 1013 } 1006 /* RTFileQueryFsSizes is implemented by ../nt/RTFileQueryFsSizes-nt.cpp */ 1014 1007 1015 1008
Note:
See TracChangeset
for help on using the changeset viewer.