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