VirtualBox

source: vbox/trunk/src/VBox/Additions/WINNT/SharedFolders/testcase/queryvolinfo-1.cpp@ 92162

Last change on this file since 92162 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 Author Date Id Revision
File size: 5.3 KB
Line 
1/* $Id: queryvolinfo-1.cpp 82968 2020-02-04 10:35:17Z vboxsync $ */
2/** @file
3 * VirtualBox Windows Guest Shared Folders FSD - Simple Testcase.
4 */
5
6/*
7 * Copyright (C) 2019-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
18#include <iprt/nt/nt-and-windows.h>
19#include <stdio.h>
20#include <string.h>
21
22static const char * const g_apszVolInfoNames[] =
23{
24 "0",
25 "FileFsVolumeInformation",
26 "FileFsLabelInformation",
27 "FileFsSizeInformation", /**< FILE_FS_SIZE_INFORMATION */
28 "FileFsDeviceInformation",
29 "FileFsAttributeInformation",
30 "FileFsControlInformation",
31 "FileFsFullSizeInformation",
32 "FileFsObjectIdInformation",
33 "FileFsDriverPathInformation",
34 "FileFsVolumeFlagsInformation",
35 "FileFsSectorSizeInformation",
36 "FileFsDataCopyInformation",
37 "FileFsMaximumInformation",
38 "FileFsMaximumInformation+1",
39 "FileFsMaximumInformation+2",
40 "FileFsMaximumInformation+3",
41 "FileFsMaximumInformation+4",
42 "FileFsMaximumInformation+5",
43 "FileFsMaximumInformation+6",
44 "FileFsMaximumInformation+7",
45 "FileFsMaximumInformation+8",
46 "FileFsMaximumInformation+9",
47};
48
49static const char *GetStatusName(NTSTATUS rcNt)
50{
51 switch (rcNt)
52 {
53 case STATUS_SUCCESS: return " (STATUS_SUCCESS)";
54 case STATUS_INVALID_INFO_CLASS: return " (STATUS_INVALID_INFO_CLASS)";
55 case STATUS_INVALID_PARAMETER: return " (STATUS_INVALID_PARAMETER)";
56 case STATUS_INVALID_DEVICE_REQUEST: return " (STATUS_INVALID_DEVICE_REQUEST)";
57 case STATUS_NO_SUCH_DEVICE: return " (STATUS_NO_SUCH_DEVICE)";
58 case STATUS_NOT_SUPPORTED: return " (STATUS_NOT_SUPPORTED)";
59 }
60 return "";
61}
62
63static void DoQueries(HANDLE hFile)
64{
65 union
66 {
67 uint8_t abBuf[4096];
68 struct
69 {
70 LARGE_INTEGER VolumeCreationTime;
71 ULONG VolumeSerialNumber;
72 ULONG VolumeLabelLength;
73 BOOLEAN SupportsObjects;
74 BOOLEAN Padding;
75 WCHAR VolumeLabel[63];
76 } VolInfo;
77 } uBuf;
78
79 IO_STATUS_BLOCK const VirginIos = RTNT_IO_STATUS_BLOCK_INITIALIZER;
80 for (unsigned iClass = 0; iClass < RT_ELEMENTS(g_apszVolInfoNames); iClass++)
81 {
82 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
83 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &uBuf, sizeof(uBuf), (FS_INFORMATION_CLASS)iClass);
84 printf(" %45s: rcNt=%#x%s", g_apszVolInfoNames[iClass], rcNt, GetStatusName(rcNt));
85 if ( Ios.Information == VirginIos.Information
86 && Ios.Status == VirginIos.Status)
87 printf(" Ios=<not modified>\n", Ios.Status, Ios.Information);
88 else
89 printf(" Ios.Status=%#x%s Ios.Information=%p\n", Ios.Status, GetStatusName(Ios.Status), Ios.Information);
90 if (NT_SUCCESS(rcNt))
91 {
92 ULONG const cbNominal = Ios.Information;
93 for (ULONG cbLess = 0; cbLess < 8; cbLess++)
94 {
95 memset(&uBuf, 0xff, sizeof(uBuf));
96 rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &uBuf, cbNominal - cbLess, (FS_INFORMATION_CLASS)iClass);
97 printf(" %45s cbBuf=%u -> rcNt=%#x%s", "", cbNominal - cbLess, rcNt, GetStatusName(rcNt));
98 switch (iClass)
99 {
100 case FileFsVolumeInformation:
101 {
102 printf(" VolNmLen=%#x:", uBuf.VolInfo.VolumeLabelLength);
103 size_t const cwcMax = ( cbNominal - cbLess - 18 < uBuf.VolInfo.VolumeLabelLength
104 ? cbNominal - cbLess - 18 : uBuf.VolInfo.VolumeLabelLength) / sizeof(WCHAR);
105 for (unsigned off = 0; off < cwcMax; off++)
106 printf(" %02x", uBuf.VolInfo.VolumeLabel[off]);
107 break;
108 }
109 }
110 if ( Ios.Information == VirginIos.Information
111 && Ios.Status == VirginIos.Status)
112 printf(" Ios=<not modified>\n", Ios.Status, Ios.Information);
113 else
114 printf(" Ios.Status=%#x%s Ios.Information=%p\n", Ios.Status, GetStatusName(Ios.Status), Ios.Information);
115 }
116 }
117 }
118}
119
120
121int main(int argc, char **argv)
122{
123 for (int i = 1; i < argc; i++)
124 {
125 printf("Querying info for: %s\n", argv[i]);
126 HANDLE hFile = CreateFileA(argv[i], GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
127 NULL /*pSecAttr*/, OPEN_EXISTING,
128 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS,
129 NULL /*hTemplate*/);
130 if (hFile != INVALID_HANDLE_VALUE)
131 {
132 DoQueries(hFile);
133 CloseHandle(hFile);
134 }
135 else
136 fprintf(stderr, "error opening '%s': %u\n", GetLastError());
137 }
138 return 0;
139}
140
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