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