*: Updated copyright to 2009 and normalized name & email.
[kbuild-mirror.git] / src / kmk / w32 / tstFileInfo.c
blob53a09621f8b9e2e2a509a1a154a61ddb7fb630fb
1 /* $Id: $ */
2 /** @file
3 * Test program for some NtQueryInformationFile functionality.
4 */
6 /*
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/>
28 #include <stdio.h>
29 #include <Windows.h>
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
75 ULONG FileNameLength;
76 WCHAR FileName[1];
77 } FILE_NAME_INFORMATION, *PFILE_NAME_INFORMATION;
79 typedef LONG NTSTATUS;
81 typedef struct _IO_STATUS_BLOCK
83 union
85 NTSTATUS Status;
86 PVOID Pointer;
88 ULONG_PTR Information;
89 } IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
91 NTSYSAPI
92 NTSTATUS
93 NTAPI
94 NtQueryInformationFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FileInformation,
95 ULONG Length, FILE_INFORMATION_CLASS FileInformationClass);
99 int main(int argc, char **argv)
101 int rc = 0;
102 int i;
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],
112 GENERIC_READ,
113 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
114 NULL,
115 OPEN_EXISTING,
116 FILE_FLAG_BACKUP_SEMANTICS,
117 NULL);
118 if (hFile)
120 long rcNt;
121 char abBuf[4096];
122 IO_STATUS_BLOCK Ios;
124 memset(abBuf, 0, sizeof(abBuf));
125 memset(&Ios, 0, sizeof(Ios));
126 rcNt = pfnNtQueryInformationFile(hFile, &Ios, abBuf, sizeof(abBuf), FileNameInformation);
127 if (rcNt >= 0)
129 PFILE_NAME_INFORMATION pFileNameInfo = (PFILE_NAME_INFORMATION)abBuf;
130 printf("#%d: %s - rcNt=%#x - FileNameInformation:\n"
131 " FileName: %ls\n"
132 " FileNameLength: %lu\n",
133 i, argv[i], rcNt,
134 pFileNameInfo->FileName,
135 pFileNameInfo->FileNameLength
138 else
139 printf("#%d: %s - rcNt=%#x - FileNameInformation!\n", i, argv[i], rcNt);
141 CloseHandle(hFile);
143 else
145 printf("#%d: %s - open failed, last error %d\n", i, argv[i], GetLastError());
146 rc = 1;
149 return rc;