ReactOS  0.4.12-dev-918-g6c6e7b8
shellext.h
Go to the documentation of this file.
1 /* Copyright (c) Mark Harmstone 2016-17
2  *
3  * This file is part of WinBtrfs.
4  *
5  * WinBtrfs is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public Licence as published by
7  * the Free Software Foundation, either version 3 of the Licence, or
8  * (at your option) any later version.
9  *
10  * WinBtrfs is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public Licence for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public Licence
16  * along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */
17 
18 #pragma once
19 
20 /* C++ backwards-compatibility */
21 #ifdef __REACTOS__
22 #if defined(_MSC_VER) && (_MSC_VER < 1900)
23 #define noexcept
24 #endif
25 #endif
26 
27 #define ISOLATION_AWARE_ENABLED 1
28 #define STRSAFE_NO_DEPRECATE
29 
30 #ifndef __REACTOS__
31 #define WINVER 0x0A00 // Windows 10
32 #define _WIN32_WINNT 0x0A00
33 #endif
34 
35 #ifndef __REACTOS__
36 #include <windows.h>
37 #include <winternl.h>
38 #else
39 #define WIN32_NO_STATUS
40 #include <windef.h>
41 #include <winbase.h>
42 #include <strsafe.h>
43 #include <ndk/iofuncs.h>
44 #include <ndk/obfuncs.h>
45 #endif
46 #include <string>
47 #include <vector>
48 #include <stdint.h>
49 #ifndef __REACTOS__
50 #include "../btrfs.h"
51 #include "../btrfsioctl.h"
52 #else
53 #include "btrfs.h"
54 #include "btrfsioctl.h"
55 #endif
56 
57 using namespace std;
58 
59 #ifndef __REACTOS__
60 #define STATUS_SUCCESS (NTSTATUS)0x00000000
61 #define STATUS_BUFFER_OVERFLOW (NTSTATUS)0x80000005
62 #define STATUS_END_OF_FILE (NTSTATUS)0xc0000011
63 #define STATUS_MORE_PROCESSING_REQUIRED (NTSTATUS)0xc0000016
64 #define STATUS_BUFFER_TOO_SMALL (NTSTATUS)0xc0000023
65 #define STATUS_DEVICE_NOT_READY (NTSTATUS)0xc00000a3
66 #define STATUS_CANNOT_DELETE (NTSTATUS)0xc0000121
67 #define STATUS_NOT_FOUND (NTSTATUS)0xc0000225
68 #endif
69 
70 #define BLOCK_FLAG_DATA 0x001
71 #define BLOCK_FLAG_SYSTEM 0x002
72 #define BLOCK_FLAG_METADATA 0x004
73 #define BLOCK_FLAG_RAID0 0x008
74 #define BLOCK_FLAG_RAID1 0x010
75 #define BLOCK_FLAG_DUPLICATE 0x020
76 #define BLOCK_FLAG_RAID10 0x040
77 #define BLOCK_FLAG_RAID5 0x080
78 #define BLOCK_FLAG_RAID6 0x100
79 
80 #define BTRFS_TYPE_FILE 1
81 #define BTRFS_TYPE_DIRECTORY 2
82 #define BTRFS_TYPE_CHARDEV 3
83 #define BTRFS_TYPE_BLOCKDEV 4
84 #define BTRFS_TYPE_FIFO 5
85 #define BTRFS_TYPE_SOCKET 6
86 #define BTRFS_TYPE_SYMLINK 7
87 
88 #ifdef _MSC_VER
89 #define funcname __FUNCTION__
90 #else
91 #define funcname __func__
92 #endif
93 
94 #ifdef _MSC_VER
95 #pragma warning(disable: 4800)
96 #endif
97 
98 #ifdef __cplusplus
99 extern "C" {
100 #endif
101 #ifndef __REACTOS__
105 
108 #endif
109 
111  PULONG UnicodeStringActualWCharCount, PCCH UTF8StringSource,
113 
115  PULONG UTF8StringActualByteCount, PCWCH UnicodeStringSource,
117 
118 #ifndef __REACTOS__
120 
122 
124 #ifdef __cplusplus
125 }
126 #endif
127 #else
128 BOOL
129 WINAPI
131 BOOL
132 WINAPI
134 #ifdef __cplusplus
135 }
136 #endif
137 #endif
138 
139 #ifndef __REACTOS__
140 typedef struct _REPARSE_DATA_BUFFER {
144 
145  union {
146  struct {
154 
155  struct {
160  WCHAR PathBuffer[1];
162 
163  struct {
166  };
168 
169 #define SYMLINK_FLAG_RELATIVE 1
170 #endif
171 
172 #ifndef FILE_SUPPORTS_BLOCK_REFCOUNTING
173 
174 typedef struct _DUPLICATE_EXTENTS_DATA {
180 
181 #define FSCTL_DUPLICATE_EXTENTS_TO_FILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 209, METHOD_BUFFERED, FILE_WRITE_ACCESS)
182 
190 
196 
197 #define FSCTL_GET_INTEGRITY_INFORMATION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 159, METHOD_BUFFERED, FILE_ANY_ACCESS)
198 #define FSCTL_SET_INTEGRITY_INFORMATION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 160, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
199 
200 #endif
201 
202 class win_handle {
203 public:
205 #ifdef __REACTOS__
207 #endif
208  }
209 
211  h = nh;
212  }
213 
215  if (h != INVALID_HANDLE_VALUE)
216  CloseHandle(h);
217  }
218 
219  operator HANDLE() const {
220  return h;
221  }
222 
224  if (h != INVALID_HANDLE_VALUE)
225  CloseHandle(h);
226 
227  h = nh;
228 
229  return *this;
230  }
231 
233  return &h;
234  }
235 
236 private:
237 #ifndef __REACTOS__
239 #else
240  HANDLE h;
241 #endif
242 };
243 
244 class fff_handle {
245 public:
247 #ifdef __REACTOS__
249 #endif
250  }
251 
253  h = nh;
254  }
255 
257  if (h != INVALID_HANDLE_VALUE)
258  FindClose(h);
259  }
260 
261  operator HANDLE() const {
262  return h;
263  }
264 
266  if (h != INVALID_HANDLE_VALUE)
267  FindClose(h);
268 
269  h = nh;
270 
271  return *this;
272  }
273 
275  return &h;
276  }
277 
278 private:
279 #ifndef __REACTOS__
281 #else
282  HANDLE h;
283 #endif
284 };
285 
286 class nt_handle {
287 public:
289 #ifdef __REACTOS__
291 #endif
292  }
293 
295  h = nh;
296  }
297 
299  if (h != INVALID_HANDLE_VALUE)
300  NtClose(h);
301  }
302 
303  operator HANDLE() const {
304  return h;
305  }
306 
308  if (h != INVALID_HANDLE_VALUE)
309  NtClose(h);
310 
311  h = nh;
312 
313  return *this;
314  }
315 
317  return &h;
318  }
319 
320 private:
321 #ifndef __REACTOS__
323 #else
324  HANDLE h;
325 #endif
326 };
327 
328 class string_error : public exception {
329 public:
330  string_error(int resno, ...);
331 
332  const char* what() const noexcept {
333  return msg.c_str();
334  }
335 
336 private:
337  string msg;
338 };
339 
340 
341 class last_error : public exception {
342 public:
343  last_error(DWORD errnum);
344 
345  const char* what() const noexcept {
346  return msg.c_str();
347  }
348 
349 private:
350  string msg;
351 };
352 
353 class ntstatus_error : public exception {
354 public:
356 
357  const char* what() const noexcept {
358  return msg.c_str();
359  }
360 
361 private:
362  string msg;
363 };
364 
365 #ifdef __REACTOS__
366 inline wstring to_wstring(uint8_t a) { WCHAR buffer[16]; swprintf(buffer, L"%d", a); return wstring(buffer); }
367 inline wstring to_wstring(uint16_t a) { WCHAR buffer[16]; swprintf(buffer, L"%d", a); return wstring(buffer); }
368 inline wstring to_wstring(uint32_t a) { WCHAR buffer[32]; swprintf(buffer, L"%ld", a); return wstring(buffer); }
369 inline wstring to_wstring(uint64_t a) { WCHAR buffer[64]; swprintf(buffer, L"%I64d", a); return wstring(buffer); }
370 #endif
371 
372 extern HMODULE module;
373 void format_size(uint64_t size, wstring& s, bool show_bytes);
374 void set_dpi_aware();
377 bool load_string(HMODULE module, UINT id, wstring& s);
378 void wstring_sprintf(wstring& s, wstring fmt, ...);
380 void utf8_to_utf16(const string& utf8, wstring& utf16);
381 void utf16_to_utf8(const wstring& utf16, string& utf8);
382 void error_message(HWND hwnd, const char* msg);
void wstring_sprintf(wstring &s, wstring fmt,...)
Definition: main.cpp:225
signed char * PCHAR
Definition: retypes.h:7
CONST WCHAR * PCWCH
Definition: ntbasedef.h:418
nt_handle()
Definition: shellext.h:288
struct _FSCTL_GET_INTEGRITY_INFORMATION_BUFFER * PFSCTL_GET_INTEGRITY_INFORMATION_BUFFER
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
nt_handle & operator=(const HANDLE nh)
Definition: shellext.h:307
struct _REPARSE_DATA_BUFFER::@300::@302 SymbolicLinkReparseBuffer
struct _FSCTL_GET_INTEGRITY_INFORMATION_BUFFER FSCTL_GET_INTEGRITY_INFORMATION_BUFFER
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:719
#define CloseHandle
Definition: compat.h:398
HMODULE module
Definition: main.cpp:47
VOID(* PIO_APC_ROUTINE)(IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN ULONG Reserved)
Definition: nt_native.h:877
const char * what() const noexcept
Definition: shellext.h:357
string msg
Definition: shellext.h:337
ntstatus_error(NTSTATUS Status)
Definition: main.cpp:748
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:738
_In_ USHORT _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _Reserved_ ULONG _In_opt_ PVOID _In_opt_ const WSK_CLIENT_CONNECTION_DISPATCH _In_opt_ PEPROCESS _In_opt_ PETHREAD _In_opt_ PSECURITY_DESCRIPTOR SecurityDescriptor
Definition: wsk.h:182
fff_handle(HANDLE nh)
Definition: shellext.h:252
uint16_t * PWSTR
Definition: typedefs.h:54
LONG NTSTATUS
Definition: precomp.h:26
void set_dpi_aware()
Definition: main.cpp:50
fff_handle & operator=(const HANDLE nh)
Definition: shellext.h:265
struct _REPARSE_DATA_BUFFER::@300::@303 MountPointReparseBuffer
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG _In_ ULONG OutputBufferLength
Definition: fltkernel.h:1374
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
GLuint buffer
Definition: glext.h:5915
#define NTSYSCALLAPI
Definition: ntbasedef.h:204
NTSYSCALLAPI NTSTATUS NTAPI NtFsControlFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength)
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
NTSTATUS WINAPI NtSetEaFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length)
void utf8_to_utf16(const string &utf8, wstring &utf16)
Definition: main.cpp:667
TCHAR * cmdline
Definition: stretchblt.cpp:32
HANDLE * operator &()
Definition: shellext.h:232
unsigned short int uint16_t
Definition: acefiex.h:54
Definition: features.h:417
void format_size(uint64_t size, wstring &s, bool show_bytes)
Definition: main.cpp:65
Definition: match.c:390
wstring format_message(ULONG last_error)
Definition: main.cpp:164
USHORT PrintNameOffset
Definition: shellext.h:149
CHAR InputBuffer[80]
Definition: conmgr.c:33
void utf16_to_utf8(const wstring &utf16, string &utf8)
Definition: main.cpp:694
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
~win_handle()
Definition: shellext.h:214
bool load_string(HMODULE module, UINT id, wstring &s)
Definition: main.cpp:206
string_error(int resno,...)
Definition: main.cpp:640
HANDLE FileHandle
Definition: stats.c:38
WCHAR PathBuffer[1]
Definition: shellext.h:152
const char * what() const noexcept
Definition: shellext.h:345
NTSTATUS(* NTAPI)(IN PFILE_FULL_EA_INFORMATION EaBuffer, IN ULONG EaLength, OUT PULONG ErrorOffset)
Definition: IoEaTest.cpp:117
win_handle(HANDLE nh)
Definition: shellext.h:210
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD SECURITY_INFORMATION
Definition: ms-dtyp.idl:311
static PVOID ptr
Definition: dispmode.c:27
USHORT SubstituteNameLength
Definition: shellext.h:148
UCHAR DataBuffer[1]
Definition: shellext.h:164
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ SECURITY_INFORMATION SecurityInformation
Definition: fltkernel.h:1339
struct _FSCTL_SET_INTEGRITY_INFORMATION_BUFFER FSCTL_SET_INTEGRITY_INFORMATION_BUFFER
Definition: bufpool.h:45
_Must_inspect_result_ __drv_aliasesMem _In_ PDEVICE_OBJECT _In_opt_ PVOID _In_ ULONG _Out_opt_ PVOID OutputBuffer
Definition: iofuncs.h:713
static FILE_INFO_BY_HANDLE_CLASS
Definition: file.c:36
win_handle & operator=(const HANDLE nh)
Definition: shellext.h:223
*UnicodeStringActualByteCount PWSTR _In_ ULONG _Out_ PULONG _In_ ULONG UTF8StringByteCount
Definition: rtlfuncs.h:2665
HANDLE h
Definition: shellext.h:280
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
_In_ HANDLE Handle
Definition: extypes.h:390
LARGE_INTEGER SourceFileOffset
Definition: shellext.h:176
CONST CHAR * PCCH
Definition: ntbasedef.h:399
GLsizeiptr size
Definition: glext.h:5919
__wchar_t WCHAR
Definition: xmlstorage.h:180
struct _REPARSE_DATA_BUFFER::@300::@304 GenericReparseBuffer
#define swprintf(buf, format,...)
Definition: sprintf.c:56
#define WINAPI
Definition: msvc.h:8
*UTF8StringActualByteCount PCHAR _In_ ULONG _Out_ PULONG _In_ ULONG UnicodeStringByteCount
Definition: rtlfuncs.h:2652
unsigned short WORD
Definition: ntddk_ex.h:93
string msg
Definition: shellext.h:350
PVOID HANDLE
Definition: typedefs.h:71
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL WINAPI GetFileInformationByHandleEx(HANDLE handle, FILE_INFO_BY_HANDLE_CLASS class, LPVOID info, DWORD size)
NTSTATUS WINAPI NtSetSecurityObject(HANDLE Handle, SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR SecurityDescriptor)
*UTF8StringActualByteCount PCHAR UTF8StringDestination
Definition: rtlfuncs.h:2648
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
void command_line_to_args(LPWSTR cmdline, vector< wstring > args)
Definition: main.cpp:610
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:719
win_handle()
Definition: shellext.h:204
unsigned char UCHAR
Definition: xmlstorage.h:181
nt_handle(HANDLE nh)
Definition: shellext.h:294
USHORT ReparseDataLength
Definition: shellext.h:142
static const WCHAR L[]
Definition: oid.c:1250
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
struct _DUPLICATE_EXTENTS_DATA DUPLICATE_EXTENTS_DATA
NTSTATUS NTAPI NtQueryInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
_In_ HANDLE hFile
Definition: mswsock.h:90
BYTE uint8_t
Definition: msvideo1.c:66
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ ULONG InputBufferLength
Definition: fltkernel.h:1372
Status
Definition: gdiplustypes.h:24
struct _REPARSE_DATA_BUFFER REPARSE_DATA_BUFFER
const char * what() const noexcept
Definition: shellext.h:332
last_error(DWORD errnum)
Definition: main.cpp:721
string msg
Definition: shellext.h:362
~fff_handle()
Definition: shellext.h:256
UINT64 uint64_t
Definition: types.h:77
unsigned short USHORT
Definition: pedump.c:61
HANDLE h
Definition: shellext.h:322
struct _FSCTL_SET_INTEGRITY_INFORMATION_BUFFER * PFSCTL_SET_INTEGRITY_INFORMATION_BUFFER
*UTF8StringActualByteCount PCHAR _In_ ULONG UTF8StringMaxByteCount
Definition: rtlfuncs.h:2648
NTSTATUS WINAPI RtlUTF8ToUnicodeN(PWSTR UnicodeStringDestination, ULONG UnicodeStringMaxWCharCount, PULONG UnicodeStringActualWCharCount, PCCH UTF8StringSource, ULONG UTF8StringByteCount)
Definition: reactos.cpp:21
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
unsigned int * PULONG
Definition: retypes.h:1
unsigned int UINT
Definition: ndis.h:50
LARGE_INTEGER TargetFileOffset
Definition: shellext.h:177
UINT32 uint32_t
Definition: types.h:75
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG FsControlCode
Definition: fltkernel.h:1369
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
#define msg(x)
Definition: auth_time.c:54
BOOL WINAPI SetFileInformationByHandle(HANDLE hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, LPVOID lpFileInformation, DWORD dwBufferSize)
Definition: reactos.cpp:177
*UTF8StringActualByteCount PCHAR _In_ ULONG _Out_ PULONG UTF8StringActualByteCount
Definition: rtlfuncs.h:2648
USHORT SubstituteNameOffset
Definition: shellext.h:147
unsigned int ULONG
Definition: retypes.h:1
#define const
Definition: zconf.h:230
struct _DUPLICATE_EXTENTS_DATA * PDUPLICATE_EXTENTS_DATA
fff_handle()
Definition: shellext.h:246
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
HANDLE * operator &()
Definition: shellext.h:274
WCHAR * LPWSTR
Definition: xmlstorage.h:184
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK io
Definition: file.c:100
~nt_handle()
Definition: shellext.h:298
LARGE_INTEGER ByteCount
Definition: shellext.h:178
Definition: dsound.c:943
HANDLE * operator &()
Definition: shellext.h:316
USHORT PrintNameLength
Definition: shellext.h:150
struct _REPARSE_DATA_BUFFER * PREPARSE_DATA_BUFFER
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
HANDLE h
Definition: shellext.h:238
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:716
*UnicodeStringActualByteCount PWSTR UnicodeStringDestination
Definition: rtlfuncs.h:2661
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
NTSTATUS NTAPI RtlUnicodeToUTF8N(PCHAR UTF8StringDestination, ULONG UTF8StringMaxByteCount, PULONG UTF8StringActualByteCount, PCWCH UnicodeStringSource, ULONG UnicodeStringByteCount)