Add experimental support for Windows VSS
[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_NtFsControlFile) (HANDLE FileHandle,
105                                                 HANDLE Event,
106                                                 PIO_APC_ROUTINE ApcRoutine,
107                                                 PVOID ApcContext,
108                                                 PIO_STATUS_BLOCK IoStatusBlock,
109                                                 ULONG FsControlCode,
110                                                 PVOID InputBuffer,
111                                                 ULONG InputBufferLength,
112                                                 PVOID OutputBuffer,
113                                                 ULONG OutputBufferLength);
114
115 extern NTSTATUS (WINAPI *func_NtClose) (HANDLE Handle);
116
117 extern DWORD (WINAPI *func_RtlNtStatusToDosError)(NTSTATUS status);
118
119 typedef struct _RTLP_CURDIR_REF {
120         LONG RefCount;
121         HANDLE Handle;
122 } RTLP_CURDIR_REF, *PRTLP_CURDIR_REF;
123
124 typedef struct _RTL_RELATIVE_NAME_U {
125         UNICODE_STRING RelativeName;
126         HANDLE ContainingDirectory;
127         PRTLP_CURDIR_REF CurDirRef;
128 } RTL_RELATIVE_NAME_U, *PRTL_RELATIVE_NAME_U;
129
130 extern BOOLEAN (WINAPI *func_RtlDosPathNameToNtPathName_U)
131                 (IN PCWSTR DosName,
132                  OUT PUNICODE_STRING NtName,
133                  OUT PCWSTR *PartName,
134                  OUT PRTL_RELATIVE_NAME_U RelativeName);
135
136 extern NTSTATUS (WINAPI *func_RtlDosPathNameToNtPathName_U_WithStatus)
137                 (IN PCWSTR DosName,
138                  OUT PUNICODE_STRING NtName,
139                  OUT PCWSTR *PartName,
140                  OUT PRTL_RELATIVE_NAME_U RelativeName);
141
142 extern NTSTATUS (WINAPI *func_RtlCreateSystemVolumeInformationFolder)
143                         (PCUNICODE_STRING VolumeRootPath);
144
145 #define FSCTL_SET_PERSISTENT_VOLUME_STATE 0x90238
146
147 #define PERSISTENT_VOLUME_STATE_SHORT_NAME_CREATION_DISABLED 0x00000001
148
149 typedef struct _FILE_FS_PERSISTENT_VOLUME_INFORMATION {
150         ULONG VolumeFlags;
151         ULONG FlagMask;
152         ULONG Version;
153         ULONG Reserved;
154 } FILE_FS_PERSISTENT_VOLUME_INFORMATION, *PFILE_FS_PERSISTENT_VOLUME_INFORMATION;
155
156 extern int
157 win32_path_to_nt_path(const wchar_t *win32_path, UNICODE_STRING *nt_path);
158
159 extern int
160 win32_get_drive_path(const wchar_t *file_path, wchar_t drive_path[7]);
161
162 extern bool
163 win32_try_to_attach_wof(const wchar_t *drive);
164
165 extern void
166 win32_warning(DWORD err, const wchar_t *format, ...) _cold_attribute;
167
168 extern void
169 win32_error(DWORD err, const wchar_t *format, ...) _cold_attribute;
170
171 extern void
172 winnt_warning(NTSTATUS status, const wchar_t *format, ...) _cold_attribute;
173
174 extern void
175 winnt_error(NTSTATUS status, const wchar_t *format, ...) _cold_attribute;
176
177 #endif /* _WIMLIB_WIN32_COMMON_H */