1 | /* $Id: queryfileinfo-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 |
|
---|
21 | static const char * const g_apszFileInfoNames[] =
|
---|
22 | {
|
---|
23 | "0",
|
---|
24 | "FileDirectoryInformation",
|
---|
25 | "FileFullDirectoryInformation",
|
---|
26 | "FileBothDirectoryInformation",
|
---|
27 | "FileBasicInformation",
|
---|
28 | "FileStandardInformation",
|
---|
29 | "FileInternalInformation",
|
---|
30 | "FileEaInformation",
|
---|
31 | "FileAccessInformation",
|
---|
32 | "FileNameInformation",
|
---|
33 | "FileRenameInformation",
|
---|
34 | "FileLinkInformation",
|
---|
35 | "FileNamesInformation",
|
---|
36 | "FileDispositionInformation",
|
---|
37 | "FilePositionInformation",
|
---|
38 | "FileFullEaInformation",
|
---|
39 | "FileModeInformation",
|
---|
40 | "FileAlignmentInformation",
|
---|
41 | "FileAllInformation",
|
---|
42 | "FileAllocationInformation",
|
---|
43 | "FileEndOfFileInformation",
|
---|
44 | "FileAlternateNameInformation",
|
---|
45 | "FileStreamInformation",
|
---|
46 | "FilePipeInformation",
|
---|
47 | "FilePipeLocalInformation",
|
---|
48 | "FilePipeRemoteInformation",
|
---|
49 | "FileMailslotQueryInformation",
|
---|
50 | "FileMailslotSetInformation",
|
---|
51 | "FileCompressionInformation",
|
---|
52 | "FileObjectIdInformation",
|
---|
53 | "FileCompletionInformation",
|
---|
54 | "FileMoveClusterInformation",
|
---|
55 | "FileQuotaInformation",
|
---|
56 | "FileReparsePointInformation",
|
---|
57 | "FileNetworkOpenInformation",
|
---|
58 | "FileAttributeTagInformation",
|
---|
59 | "FileTrackingInformation",
|
---|
60 | "FileIdBothDirectoryInformation",
|
---|
61 | "FileIdFullDirectoryInformation",
|
---|
62 | "FileValidDataLengthInformation",
|
---|
63 | "FileShortNameInformation",
|
---|
64 | "FileIoCompletionNotificationInformation",
|
---|
65 | "FileIoStatusBlockRangeInformation",
|
---|
66 | "FileIoPriorityHintInformation",
|
---|
67 | "FileSfioReserveInformation",
|
---|
68 | "FileSfioVolumeInformation",
|
---|
69 | "FileHardLinkInformation",
|
---|
70 | "FileProcessIdsUsingFileInformation",
|
---|
71 | "FileNormalizedNameInformation",
|
---|
72 | "FileNetworkPhysicalNameInformation",
|
---|
73 | "FileIdGlobalTxDirectoryInformation",
|
---|
74 | "FileIsRemoteDeviceInformation",
|
---|
75 | "FileUnusedInformation",
|
---|
76 | "FileNumaNodeInformation",
|
---|
77 | "FileStandardLinkInformation",
|
---|
78 | "FileRemoteProtocolInformation",
|
---|
79 | "FileRenameInformationBypassAccessCheck",
|
---|
80 | "FileLinkInformationBypassAccessCheck",
|
---|
81 | "FileVolumeNameInformation",
|
---|
82 | "FileIdInformation",
|
---|
83 | "FileIdExtdDirectoryInformation",
|
---|
84 | "FileReplaceCompletionInformation",
|
---|
85 | "FileHardLinkFullIdInformation",
|
---|
86 | "FileIdExtdBothDirectoryInformation",
|
---|
87 | "FileDispositionInformationEx",
|
---|
88 | "FileRenameInformationEx",
|
---|
89 | "FileRenameInformationExBypassAccessCheck",
|
---|
90 | "FileDesiredStorageClassInformation",
|
---|
91 | "FileStatInformation",
|
---|
92 | "FileMemoryPartitionInformation",
|
---|
93 | "FileStatLxInformation",
|
---|
94 | "FileCaseSensitiveInformation",
|
---|
95 | "FileLinkInformationEx",
|
---|
96 | "FileLinkInformationExBypassAccessCheck",
|
---|
97 | "FileStorageReserveIdInformation",
|
---|
98 | "FileCaseSensitiveInformationForceAccessCheck",
|
---|
99 | "FileMaximumInformation",
|
---|
100 | "FileMaximumInformation+1",
|
---|
101 | "FileMaximumInformation+2",
|
---|
102 | "FileMaximumInformation+3",
|
---|
103 | "FileMaximumInformation+4",
|
---|
104 | "FileMaximumInformation+5",
|
---|
105 | "FileMaximumInformation+6",
|
---|
106 | "FileMaximumInformation+7",
|
---|
107 | "FileMaximumInformation+8",
|
---|
108 | "FileMaximumInformation+9",
|
---|
109 | "FileMaximumInformation+10",
|
---|
110 | "FileMaximumInformation+11",
|
---|
111 | "FileMaximumInformation+12",
|
---|
112 | };
|
---|
113 |
|
---|
114 | static const char *GetStatusName(NTSTATUS rcNt)
|
---|
115 | {
|
---|
116 | switch (rcNt)
|
---|
117 | {
|
---|
118 | case STATUS_SUCCESS: return " (STATUS_SUCCESS)";
|
---|
119 | case STATUS_INVALID_INFO_CLASS: return " (STATUS_INVALID_INFO_CLASS)";
|
---|
120 | case STATUS_INVALID_PARAMETER: return " (STATUS_INVALID_PARAMETER)";
|
---|
121 | case STATUS_INVALID_DEVICE_REQUEST: return " (STATUS_INVALID_DEVICE_REQUEST)";
|
---|
122 | case STATUS_NO_SUCH_DEVICE: return " (STATUS_NO_SUCH_DEVICE)";
|
---|
123 | case STATUS_NOT_SUPPORTED: return " (STATUS_NOT_SUPPORTED)";
|
---|
124 | }
|
---|
125 | return "";
|
---|
126 | }
|
---|
127 |
|
---|
128 | static void DoQueries(HANDLE hFile)
|
---|
129 | {
|
---|
130 | union
|
---|
131 | {
|
---|
132 | uint8_t abBuf[4096];
|
---|
133 | } uBuf;
|
---|
134 |
|
---|
135 | IO_STATUS_BLOCK const VirginIos = RTNT_IO_STATUS_BLOCK_INITIALIZER;
|
---|
136 | for (unsigned iClass = 0; iClass < RT_ELEMENTS(g_apszFileInfoNames); iClass++)
|
---|
137 | {
|
---|
138 | IO_STATUS_BLOCK Ios = RTNT_IO_STATUS_BLOCK_INITIALIZER;
|
---|
139 | NTSTATUS rcNt = NtQueryInformationFile(hFile, &Ios, &uBuf, sizeof(uBuf), (FILE_INFORMATION_CLASS)iClass);
|
---|
140 | printf(" %45s: rcNt=%#x%s", g_apszFileInfoNames[iClass], rcNt, GetStatusName(rcNt));
|
---|
141 | if ( Ios.Information == VirginIos.Information
|
---|
142 | && Ios.Status == VirginIos.Status)
|
---|
143 | printf(" Ios=<not modified>\n", Ios.Status, Ios.Information);
|
---|
144 | else
|
---|
145 | printf(" Ios.Status=%#x%s Ios.Information=%p\n", Ios.Status, GetStatusName(Ios.Status), Ios.Information);
|
---|
146 | if (NT_SUCCESS(rcNt))
|
---|
147 | {
|
---|
148 | }
|
---|
149 | }
|
---|
150 | }
|
---|
151 |
|
---|
152 |
|
---|
153 | int main(int argc, char **argv)
|
---|
154 | {
|
---|
155 | for (int i = 1; i < argc; i++)
|
---|
156 | {
|
---|
157 | printf("Querying info for: %s\n", argv[i]);
|
---|
158 | HANDLE hFile = CreateFileA(argv[i], GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
|
---|
159 | NULL /*pSecAttr*/, OPEN_EXISTING,
|
---|
160 | FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS,
|
---|
161 | NULL /*hTemplate*/);
|
---|
162 | if (hFile != INVALID_HANDLE_VALUE)
|
---|
163 | {
|
---|
164 | DoQueries(hFile);
|
---|
165 | CloseHandle(hFile);
|
---|
166 | }
|
---|
167 | else
|
---|
168 | fprintf(stderr, "error opening '%s': %u\n", GetLastError());
|
---|
169 | }
|
---|
170 | return 0;
|
---|
171 | }
|
---|
172 |
|
---|