0e2db43884392be2d7052bab22c27faba5d257ee
[wimlib] / include / wimlib / win32_common.h
1 #ifndef _WIMLIB_WIN32_COMMON_H
2 #define _WIMLIB_WIN32_COMMON_H
3
4 #include <ntstatus.h>
5 #include <windows.h>
6 #include <winternl.h>
7
8 #ifdef ERROR
9 #  undef ERROR
10 #endif
11 #include "wimlib/types.h"
12 #include "wimlib/win32.h"
13
14 /* ntdll functions  */
15
16 extern NTSTATUS (WINAPI *func_NtCreateFile)(PHANDLE FileHandle,
17                                             ACCESS_MASK DesiredAccess,
18                                             POBJECT_ATTRIBUTES ObjectAttributes,
19                                             PIO_STATUS_BLOCK IoStatusBlock,
20                                             PLARGE_INTEGER AllocationSize,
21                                             ULONG FileAttributes,
22                                             ULONG ShareAccess,
23                                             ULONG CreateDisposition,
24                                             ULONG CreateOptions,
25                                             PVOID EaBuffer,
26                                             ULONG EaLength);
27
28 #ifndef FILE_OPENED
29 #  define FILE_OPENED 0x00000001
30 #endif
31
32 extern NTSTATUS (WINAPI *func_NtOpenFile) (PHANDLE FileHandle,
33                                            ACCESS_MASK DesiredAccess,
34                                            POBJECT_ATTRIBUTES ObjectAttributes,
35                                            PIO_STATUS_BLOCK IoStatusBlock,
36                                            ULONG ShareAccess,
37                                            ULONG OpenOptions);
38
39 extern NTSTATUS (WINAPI *func_NtReadFile) (HANDLE FileHandle,
40                                            HANDLE Event,
41                                            PIO_APC_ROUTINE ApcRoutine,
42                                            PVOID ApcContext,
43                                            PIO_STATUS_BLOCK IoStatusBlock,
44                                            PVOID Buffer,
45                                            ULONG Length,
46                                            PLARGE_INTEGER ByteOffset,
47                                            PULONG Key);
48
49 extern NTSTATUS (WINAPI *func_NtWriteFile) (HANDLE FileHandle,
50                                             HANDLE Event,
51                                             PIO_APC_ROUTINE ApcRoutine,
52                                             PVOID ApcContext,
53                                             PIO_STATUS_BLOCK IoStatusBlock,
54                                             PVOID Buffer,
55                                             ULONG Length,
56                                             PLARGE_INTEGER ByteOffset,
57                                             PULONG Key);
58
59 extern NTSTATUS (WINAPI *func_NtQueryInformationFile)(HANDLE FileHandle,
60                                                       PIO_STATUS_BLOCK IoStatusBlock,
61                                                       PVOID FileInformation,
62                                                       ULONG Length,
63                                                       FILE_INFORMATION_CLASS FileInformationClass);
64
65 extern NTSTATUS (WINAPI *func_NtQuerySecurityObject)(HANDLE handle,
66                                                      SECURITY_INFORMATION SecurityInformation,
67                                                      PSECURITY_DESCRIPTOR SecurityDescriptor,
68                                                      ULONG Length,
69                                                      PULONG LengthNeeded);
70
71 extern NTSTATUS (WINAPI *func_NtQueryDirectoryFile) (HANDLE FileHandle,
72                                                      HANDLE Event,
73                                                      PIO_APC_ROUTINE ApcRoutine,
74                                                      PVOID ApcContext,
75                                                      PIO_STATUS_BLOCK IoStatusBlock,
76                                                      PVOID FileInformation,
77                                                      ULONG Length,
78                                                      FILE_INFORMATION_CLASS FileInformationClass,
79                                                      BOOLEAN ReturnSingleEntry,
80                                                      PUNICODE_STRING FileName,
81                                                      BOOLEAN RestartScan);
82
83 extern NTSTATUS (WINAPI *func_NtQueryVolumeInformationFile) (HANDLE FileHandle,
84                                                              PIO_STATUS_BLOCK IoStatusBlock,
85                                                              PVOID FsInformation,
86                                                              ULONG Length,
87                                                              FS_INFORMATION_CLASS FsInformationClass);
88
89 extern NTSTATUS (WINAPI *func_NtSetInformationFile)(HANDLE FileHandle,
90                                                     PIO_STATUS_BLOCK IoStatusBlock,
91                                                     PVOID FileInformation,
92                                                     ULONG Length,
93                                                     FILE_INFORMATION_CLASS FileInformationClass);
94
95 extern NTSTATUS (WINAPI *func_NtSetSecurityObject)(HANDLE Handle,
96                                                    SECURITY_INFORMATION SecurityInformation,
97                                                    PSECURITY_DESCRIPTOR SecurityDescriptor);
98
99 extern NTSTATUS (WINAPI *func_NtFsControlFile) (HANDLE FileHandle,
100                                                 HANDLE Event,
101                                                 PIO_APC_ROUTINE ApcRoutine,
102                                                 PVOID ApcContext,
103                                                 PIO_STATUS_BLOCK IoStatusBlock,
104                                                 ULONG FsControlCode,
105                                                 PVOID InputBuffer,
106                                                 ULONG InputBufferLength,
107                                                 PVOID OutputBuffer,
108                                                 ULONG OutputBufferLength);
109
110 extern NTSTATUS (WINAPI *func_NtClose) (HANDLE Handle);
111
112 extern DWORD (WINAPI *func_RtlNtStatusToDosError)(NTSTATUS status);
113
114 typedef struct _RTLP_CURDIR_REF {
115         LONG RefCount;
116         HANDLE Handle;
117 } RTLP_CURDIR_REF, *PRTLP_CURDIR_REF;
118
119 typedef struct _RTL_RELATIVE_NAME_U {
120         UNICODE_STRING RelativeName;
121         HANDLE ContainingDirectory;
122         PRTLP_CURDIR_REF CurDirRef;
123 } RTL_RELATIVE_NAME_U, *PRTL_RELATIVE_NAME_U;
124
125 extern BOOLEAN (WINAPI *func_RtlDosPathNameToNtPathName_U)
126                 (IN PCWSTR DosName,
127                  OUT PUNICODE_STRING NtName,
128                  OUT PCWSTR *PartName,
129                  OUT PRTL_RELATIVE_NAME_U RelativeName);
130
131 extern NTSTATUS (WINAPI *func_RtlDosPathNameToNtPathName_U_WithStatus)
132                 (IN PCWSTR DosName,
133                  OUT PUNICODE_STRING NtName,
134                  OUT PCWSTR *PartName,
135                  OUT PRTL_RELATIVE_NAME_U RelativeName);
136
137 extern NTSTATUS (WINAPI *func_RtlCreateSystemVolumeInformationFolder)
138                         (PCUNICODE_STRING VolumeRootPath);
139
140 #define FSCTL_SET_PERSISTENT_VOLUME_STATE 0x90238
141
142 #define PERSISTENT_VOLUME_STATE_SHORT_NAME_CREATION_DISABLED 0x00000001
143
144 typedef struct _FILE_FS_PERSISTENT_VOLUME_INFORMATION {
145         ULONG VolumeFlags;
146         ULONG FlagMask;
147         ULONG Version;
148         ULONG Reserved;
149 } FILE_FS_PERSISTENT_VOLUME_INFORMATION, *PFILE_FS_PERSISTENT_VOLUME_INFORMATION;
150
151 extern int
152 win32_path_to_nt_path(const wchar_t *win32_path, UNICODE_STRING *nt_path);
153
154 extern int
155 win32_get_drive_path(const wchar_t *file_path, wchar_t drive_path[7]);
156
157 extern bool
158 win32_try_to_attach_wof(const wchar_t *drive);
159
160 extern void
161 win32_warning(DWORD err, const wchar_t *format, ...) _cold_attribute;
162
163 extern void
164 win32_error(DWORD err, const wchar_t *format, ...) _cold_attribute;
165
166 extern void
167 winnt_warning(NTSTATUS status, const wchar_t *format, ...) _cold_attribute;
168
169 extern void
170 winnt_error(NTSTATUS status, const wchar_t *format, ...) _cold_attribute;
171
172 #endif /* _WIMLIB_WIN32_COMMON_H */