VirtualBox

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

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1/* $Id: queryvolinfo-1.cpp 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * VirtualBox Windows Guest Shared Folders FSD - Simple Testcase.
4 */
5
6/*
7 * Copyright (C) 2019-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28#include <iprt/nt/nt-and-windows.h>
29#include <stdio.h>
30#include <string.h>
31
32static const char * const g_apszVolInfoNames[] =
33{
34 "0",
35 "FileFsVolumeInformation",
36 "FileFsLabelInformation",
37 "FileFsSizeInformation", /**< FILE_FS_SIZE_INFORMATION */
38 "FileFsDeviceInformation",
39 "FileFsAttributeInformation",
40 "FileFsControlInformation",
41 "FileFsFullSizeInformation",
42 "FileFsObjectIdInformation",
43 "FileFsDriverPathInformation",
44 "FileFsVolumeFlagsInformation",
45 "FileFsSectorSizeInformation",
46 "FileFsDataCopyInformation",
47 "FileFsMaximumInformation",
48 "FileFsMaximumInformation+1",
49 "FileFsMaximumInformation+2",
50 "FileFsMaximumInformation+3",
51 "FileFsMaximumInformation+4",
52 "FileFsMaximumInformation+5",
53 "FileFsMaximumInformation+6",
54 "FileFsMaximumInformation+7",
55 "FileFsMaximumInformation+8",
56 "FileFsMaximumInformation+9",
57};
58
59static const char *GetStatusName(NTSTATUS rcNt)
60{
61 switch (rcNt)
62 {
63 case STATUS_SUCCESS: return " (STATUS_SUCCESS)";
64 case STATUS_INVALID_INFO_CLASS: return " (STATUS_INVALID_INFO_CLASS)";
65 case STATUS_INVALID_PARAMETER: return " (STATUS_INVALID_PARAMETER)";
66 case STATUS_INVALID_DEVICE_REQUEST: return " (STATUS_INVALID_DEVICE_REQUEST)";
67 case STATUS_NO_SUCH_DEVICE: return " (STATUS_NO_SUCH_DEVICE)";
68 case STATUS_NOT_SUPPORTED: return " (STATUS_NOT_SUPPORTED)";
69 }
70 return "";
71}
72
73static void DoQueries(HANDLE hFile)
74{
75 union
76 {
77 uint8_t abBuf[4096];
78 struct
79 {
80 LARGE_INTEGER VolumeCreationTime;
81 ULONG VolumeSerialNumber;
82 ULONG VolumeLabelLength;
83 BOOLEAN SupportsObjects;
84 BOOLEAN Padding;
85 WCHAR VolumeLabel[63];
86 } VolInfo;
87 } uBuf;
88
89 IO_STATUS_BLOCK const VirginIos = RTNT_IO_STATUS_BLOCK_INITIALIZER;
90 for (unsigned iClass = 0; iClass < RT_ELEMENTS(g_apszVolInfoNames); iClass++)
91 {
92 IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
93 NTSTATUS rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &uBuf, sizeof(uBuf), (FS_INFORMATION_CLASS)iClass);
94 printf(" %45s: rcNt=%#x%s", g_apszVolInfoNames[iClass], rcNt, GetStatusName(rcNt));
95 if ( Ios.Information == VirginIos.Information
96 && Ios.Status == VirginIos.Status)
97 printf(" Ios=<not modified>\n", Ios.Status, Ios.Information);
98 else
99 printf(" Ios.Status=%#x%s Ios.Information=%p\n", Ios.Status, GetStatusName(Ios.Status), Ios.Information);
100 if (NT_SUCCESS(rcNt))
101 {
102 ULONG const cbNominal = Ios.Information;
103 for (ULONG cbLess = 0; cbLess < 8; cbLess++)
104 {
105 memset(&uBuf, 0xff, sizeof(uBuf));
106 rcNt = NtQueryVolumeInformationFile(hFile, &Ios, &uBuf, cbNominal - cbLess, (FS_INFORMATION_CLASS)iClass);
107 printf(" %45s cbBuf=%u -> rcNt=%#x%s", "", cbNominal - cbLess, rcNt, GetStatusName(rcNt));
108 switch (iClass)
109 {
110 case FileFsVolumeInformation:
111 {
112 printf(" VolNmLen=%#x:", uBuf.VolInfo.VolumeLabelLength);
113 size_t const cwcMax = ( cbNominal - cbLess - 18 < uBuf.VolInfo.VolumeLabelLength
114 ? cbNominal - cbLess - 18 : uBuf.VolInfo.VolumeLabelLength) / sizeof(WCHAR);
115 for (unsigned off = 0; off < cwcMax; off++)
116 printf(" %02x", uBuf.VolInfo.VolumeLabel[off]);
117 break;
118 }
119 }
120 if ( Ios.Information == VirginIos.Information
121 && Ios.Status == VirginIos.Status)
122 printf(" Ios=<not modified>\n", Ios.Status, Ios.Information);
123 else
124 printf(" Ios.Status=%#x%s Ios.Information=%p\n", Ios.Status, GetStatusName(Ios.Status), Ios.Information);
125 }
126 }
127 }
128}
129
130
131int main(int argc, char **argv)
132{
133 for (int i = 1; i < argc; i++)
134 {
135 printf("Querying info for: %s\n", argv[i]);
136 HANDLE hFile = CreateFileA(argv[i], GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
137 NULL /*pSecAttr*/, OPEN_EXISTING,
138 FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS,
139 NULL /*hTemplate*/);
140 if (hFile != INVALID_HANDLE_VALUE)
141 {
142 DoQueries(hFile);
143 CloseHandle(hFile);
144 }
145 else
146 fprintf(stderr, "error opening '%s': %u\n", GetLastError());
147 }
148 return 0;
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