3 * Test program for some NtQueryInformationFile functionality.
7 * Copyright (c) 2007-2009 knut st. osmundsen <bird-kBuild-spamix@anduin.net>
9 * This file is part of kBuild.
11 * kBuild is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
16 * kBuild is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with kBuild. If not, see <http://www.gnu.org/licenses/>
31 typedef enum _FILE_INFORMATION_CLASS
{
32 FileDirectoryInformation
= 1,
33 FileFullDirectoryInformation
, // 2
34 FileBothDirectoryInformation
, // 3
35 FileBasicInformation
, // 4 wdm
36 FileStandardInformation
, // 5 wdm
37 FileInternalInformation
, // 6
38 FileEaInformation
, // 7
39 FileAccessInformation
, // 8
40 FileNameInformation
, // 9
41 FileRenameInformation
, // 10
42 FileLinkInformation
, // 11
43 FileNamesInformation
, // 12
44 FileDispositionInformation
, // 13
45 FilePositionInformation
, // 14 wdm
46 FileFullEaInformation
, // 15
47 FileModeInformation
, // 16
48 FileAlignmentInformation
, // 17
49 FileAllInformation
, // 18
50 FileAllocationInformation
, // 19
51 FileEndOfFileInformation
, // 20 wdm
52 FileAlternateNameInformation
, // 21
53 FileStreamInformation
, // 22
54 FilePipeInformation
, // 23
55 FilePipeLocalInformation
, // 24
56 FilePipeRemoteInformation
, // 25
57 FileMailslotQueryInformation
, // 26
58 FileMailslotSetInformation
, // 27
59 FileCompressionInformation
, // 28
60 FileObjectIdInformation
, // 29
61 FileCompletionInformation
, // 30
62 FileMoveClusterInformation
, // 31
63 FileQuotaInformation
, // 32
64 FileReparsePointInformation
, // 33
65 FileNetworkOpenInformation
, // 34
66 FileAttributeTagInformation
, // 35
67 FileTrackingInformation
, // 36
68 FileIdBothDirectoryInformation
, // 37
69 FileIdFullDirectoryInformation
, // 38
70 FileMaximumInformation
71 } FILE_INFORMATION_CLASS
, *PFILE_INFORMATION_CLASS
;
73 typedef struct _FILE_NAME_INFORMATION
77 } FILE_NAME_INFORMATION
, *PFILE_NAME_INFORMATION
;
79 typedef LONG NTSTATUS
;
81 typedef struct _IO_STATUS_BLOCK
88 ULONG_PTR Information
;
89 } IO_STATUS_BLOCK
, *PIO_STATUS_BLOCK
;
94 NtQueryInformationFile(HANDLE FileHandle
, PIO_STATUS_BLOCK IoStatusBlock
, PVOID FileInformation
,
95 ULONG Length
, FILE_INFORMATION_CLASS FileInformationClass
);
99 int main(int argc
, char **argv
)
104 NTSTATUS (NTAPI
*pfnNtQueryInformationFile
)(HANDLE FileHandle
, PIO_STATUS_BLOCK IoStatusBlock
, PVOID FileInformation
,
105 ULONG Length
, FILE_INFORMATION_CLASS FileInformationClass
);
107 pfnNtQueryInformationFile
= GetProcAddress(LoadLibrary("ntdll.dll"), "NtQueryInformationFile");
109 for (i
= 1; i
< argc
; i
++)
111 HANDLE hFile
= CreateFile(argv
[i
],
113 FILE_SHARE_READ
| FILE_SHARE_WRITE
| FILE_SHARE_DELETE
,
116 FILE_FLAG_BACKUP_SEMANTICS
,
124 memset(abBuf
, 0, sizeof(abBuf
));
125 memset(&Ios
, 0, sizeof(Ios
));
126 rcNt
= pfnNtQueryInformationFile(hFile
, &Ios
, abBuf
, sizeof(abBuf
), FileNameInformation
);
129 PFILE_NAME_INFORMATION pFileNameInfo
= (PFILE_NAME_INFORMATION
)abBuf
;
130 printf("#%d: %s - rcNt=%#x - FileNameInformation:\n"
132 " FileNameLength: %lu\n",
134 pFileNameInfo
->FileName
,
135 pFileNameInfo
->FileNameLength
139 printf("#%d: %s - rcNt=%#x - FileNameInformation!\n", i
, argv
[i
], rcNt
);
145 printf("#%d: %s - open failed, last error %d\n", i
, argv
[i
], GetLastError());