ReactOS 0.4.15-dev-7958-gcd0bb1a
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#include <ndk/rtlfuncs.h>
46#endif
47#include <string>
48#ifdef __REACTOS__
49#define string_view string
50#define wstring_view wstring
51#endif
52#include <vector>
53#include <stdint.h>
54#ifndef __REACTOS__
55#include "../btrfs.h"
56#include "../btrfsioctl.h"
57#else
58#include "btrfs.h"
59#include "btrfsioctl.h"
60#endif
61
62using namespace std;
63
64#ifndef __REACTOS__
65#define STATUS_SUCCESS (NTSTATUS)0x00000000
66#define STATUS_BUFFER_OVERFLOW (NTSTATUS)0x80000005
67#define STATUS_END_OF_FILE (NTSTATUS)0xc0000011
68#define STATUS_MORE_PROCESSING_REQUIRED (NTSTATUS)0xc0000016
69#define STATUS_BUFFER_TOO_SMALL (NTSTATUS)0xc0000023
70#define STATUS_DEVICE_NOT_READY (NTSTATUS)0xc00000a3
71#define STATUS_CANNOT_DELETE (NTSTATUS)0xc0000121
72#define STATUS_NOT_FOUND (NTSTATUS)0xc0000225
73#endif
74
75#define BLOCK_FLAG_DATA 0x001
76#define BLOCK_FLAG_SYSTEM 0x002
77#define BLOCK_FLAG_METADATA 0x004
78#define BLOCK_FLAG_RAID0 0x008
79#define BLOCK_FLAG_RAID1 0x010
80#define BLOCK_FLAG_DUPLICATE 0x020
81#define BLOCK_FLAG_RAID10 0x040
82#define BLOCK_FLAG_RAID5 0x080
83#define BLOCK_FLAG_RAID6 0x100
84
85#define BTRFS_TYPE_FILE 1
86#define BTRFS_TYPE_DIRECTORY 2
87#define BTRFS_TYPE_CHARDEV 3
88#define BTRFS_TYPE_BLOCKDEV 4
89#define BTRFS_TYPE_FIFO 5
90#define BTRFS_TYPE_SOCKET 6
91#define BTRFS_TYPE_SYMLINK 7
92
93#ifdef _MSC_VER
94#define funcname __FUNCTION__
95#else
96#define funcname __func__
97#endif
98
99#ifdef _MSC_VER
100#pragma warning(disable: 4800)
101#endif
102
103#ifdef __cplusplus
104extern "C" {
105#endif
106#ifndef __REACTOS__
109
111
113
114#ifdef _MSC_VER
118
120
122
123#define FileBasicInformation (FILE_INFORMATION_CLASS)4
124#define FileStandardInformation (FILE_INFORMATION_CLASS)5
125#define FileDispositionInformation (FILE_INFORMATION_CLASS)13
126#define FileEndOfFileInformation (FILE_INFORMATION_CLASS)20
127#define FileStreamInformation (FILE_INFORMATION_CLASS)22
128
129typedef enum _FSINFOCLASS {
140 FileFsSectorSizeInformation,
141 FileFsDataCopyInformation,
142 FileFsMetadataSizeInformation,
143 FileFsFullSizeInformationEx,
146
147typedef struct _FILE_STREAM_INFORMATION {
152 WCHAR StreamName[1];
154#endif
155
158#endif
159#ifdef __cplusplus
160}
161#endif
162
163#ifndef __REACTOS__
164typedef struct _REPARSE_DATA_BUFFER {
168
169 union {
170 struct {
178
179 struct {
184 WCHAR PathBuffer[1];
186
187 struct {
190 };
192
193#define SYMLINK_FLAG_RELATIVE 1
194#endif
195
196#ifndef FILE_SUPPORTS_BLOCK_REFCOUNTING
197
204
205#define FSCTL_DUPLICATE_EXTENTS_TO_FILE CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 209, METHOD_BUFFERED, FILE_WRITE_ACCESS)
206
214
220
221#define FSCTL_GET_INTEGRITY_INFORMATION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 159, METHOD_BUFFERED, FILE_ANY_ACCESS)
222#define FSCTL_SET_INTEGRITY_INFORMATION CTL_CODE(FILE_DEVICE_FILE_SYSTEM, 160, METHOD_BUFFERED, FILE_READ_DATA | FILE_WRITE_DATA)
223
224#endif
225
227public:
229#ifdef __REACTOS__
231#endif
232 }
233
235 h = nh;
236 }
237
239 if (h != INVALID_HANDLE_VALUE)
240 CloseHandle(h);
241 }
242
243 operator HANDLE() const {
244 return h;
245 }
246
248 if (h != INVALID_HANDLE_VALUE)
249 CloseHandle(h);
250
251 h = nh;
252
253 return *this;
254 }
255
257 return &h;
258 }
259
260private:
261#ifndef __REACTOS__
263#else
264 HANDLE h;
265#endif
266};
267
269public:
271#ifdef __REACTOS__
273#endif
274 }
275
277 h = nh;
278 }
279
281 if (h != INVALID_HANDLE_VALUE)
282 FindClose(h);
283 }
284
285 operator HANDLE() const {
286 return h;
287 }
288
290 if (h != INVALID_HANDLE_VALUE)
291 FindClose(h);
292
293 h = nh;
294
295 return *this;
296 }
297
299 return &h;
300 }
301
302private:
303#ifndef __REACTOS__
305#else
306 HANDLE h;
307#endif
308};
309
311public:
313#ifdef __REACTOS__
315#endif
316 }
317
319 h = nh;
320 }
321
323 if (h != INVALID_HANDLE_VALUE)
324 NtClose(h);
325 }
326
327 operator HANDLE() const {
328 return h;
329 }
330
332 if (h != INVALID_HANDLE_VALUE)
333 NtClose(h);
334
335 h = nh;
336
337 return *this;
338 }
339
341 return &h;
342 }
343
344private:
345#ifndef __REACTOS__
347#else
348 HANDLE h;
349#endif
350};
351
352class string_error : public exception {
353public:
354 string_error(int resno, ...);
355
356 const char* what() const noexcept {
357 return msg.c_str();
358 }
359
360private:
361 string msg;
362};
363
364
365class last_error : public exception {
366public:
367 last_error(DWORD errnum);
368
369 const char* what() const noexcept {
370 return msg.c_str();
371 }
372
373private:
374 string msg;
375};
376
377class ntstatus_error : public exception {
378public:
380
381 const char* what() const noexcept {
382 return msg.c_str();
383 }
384
386
387private:
388 string msg;
389};
390
391#ifdef __REACTOS__
392inline wstring to_wstring(uint8_t a) { WCHAR buffer[16]; swprintf(buffer, L"%d", a); return wstring(buffer); }
393inline wstring to_wstring(uint16_t a) { WCHAR buffer[16]; swprintf(buffer, L"%d", a); return wstring(buffer); }
394inline wstring to_wstring(uint32_t a) { WCHAR buffer[32]; swprintf(buffer, L"%ld", a); return wstring(buffer); }
395inline wstring to_wstring(uint64_t a) { WCHAR buffer[64]; swprintf(buffer, L"%I64d", a); return wstring(buffer); }
396#endif
397
398extern HMODULE module;
399void format_size(uint64_t size, wstring& s, bool show_bytes);
400void set_dpi_aware();
403bool load_string(HMODULE module, UINT id, wstring& s);
404void wstring_sprintf(wstring& s, wstring fmt, ...);
406wstring utf8_to_utf16(const string_view& utf8);
407void error_message(HWND hwnd, const char* msg);
unsigned short int uint16_t
Definition: acefiex.h:54
#define msg(x)
Definition: auth_time.c:54
LONG NTSTATUS
Definition: precomp.h:26
Definition: bufpool.h:45
~fff_handle()
Definition: shellext.h:280
fff_handle(HANDLE nh)
Definition: shellext.h:276
HANDLE * operator&()
Definition: shellext.h:298
HANDLE h
Definition: shellext.h:304
fff_handle()
Definition: shellext.h:270
fff_handle & operator=(const HANDLE nh)
Definition: shellext.h:289
string msg
Definition: shellext.h:374
const char * what() const noexcept
Definition: shellext.h:369
HANDLE * operator&()
Definition: shellext.h:340
nt_handle()
Definition: shellext.h:312
HANDLE h
Definition: shellext.h:346
nt_handle(HANDLE nh)
Definition: shellext.h:318
~nt_handle()
Definition: shellext.h:322
nt_handle & operator=(const HANDLE nh)
Definition: shellext.h:331
NTSTATUS Status
Definition: shellext.h:385
const char * what() const noexcept
Definition: shellext.h:381
string msg
Definition: shellext.h:388
string msg
Definition: shellext.h:361
const char * what() const noexcept
Definition: shellext.h:356
HANDLE * operator&()
Definition: shellext.h:256
HANDLE h
Definition: shellext.h:262
win_handle & operator=(const HANDLE nh)
Definition: shellext.h:247
~win_handle()
Definition: shellext.h:238
win_handle(HANDLE nh)
Definition: shellext.h:234
win_handle()
Definition: shellext.h:228
UINT32 uint32_t
Definition: types.h:75
UINT64 uint64_t
Definition: types.h:77
#define CloseHandle
Definition: compat.h:739
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
BOOL WINAPI FindClose(HANDLE hFindFile)
Definition: find.c:502
#define swprintf
Definition: precomp.h:40
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:731
unsigned long DWORD
Definition: ntddk_ex.h:95
unsigned short WORD
Definition: ntddk_ex.h:93
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG _In_ FS_INFORMATION_CLASS FsInformationClass
Definition: fltkernel.h:1330
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ ULONG FsControlCode
Definition: fltkernel.h:1370
_Must_inspect_result_ _In_opt_ PFLT_INSTANCE _Out_ PHANDLE FileHandle
Definition: fltkernel.h:1231
_Must_inspect_result_ _In_ PFILE_OBJECT _In_ SECURITY_INFORMATION SecurityInformation
Definition: fltkernel.h:1340
enum _FSINFOCLASS * PFS_INFORMATION_CLASS
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
_FSINFOCLASS
Definition: from_kernel.h:218
@ FileFsVolumeFlagsInformation
Definition: from_kernel.h:228
@ FileFsControlInformation
Definition: from_kernel.h:224
@ FileFsDeviceInformation
Definition: from_kernel.h:222
@ FileFsLabelInformation
Definition: from_kernel.h:220
@ FileFsAttributeInformation
Definition: from_kernel.h:223
@ FileFsVolumeInformation
Definition: from_kernel.h:219
@ FileFsSizeInformation
Definition: from_kernel.h:221
@ FileFsMaximumInformation
Definition: from_kernel.h:229
enum _FSINFOCLASS FS_INFORMATION_CLASS
ULONG Handle
Definition: gdb_input.c:15
Status
Definition: gdiplustypes.h:25
GLdouble s
Definition: gl.h:2039
GLsizeiptr size
Definition: glext.h:5919
GLuint buffer
Definition: glext.h:5915
GLenum GLsizei len
Definition: glext.h:6722
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
struct _FILE_STREAM_INFORMATION * PFILE_STREAM_INFORMATION
struct _FILE_STREAM_INFORMATION FILE_STREAM_INFORMATION
static PVOID ptr
Definition: dispmode.c:27
static HANDLE PIO_APC_ROUTINE PVOID PIO_STATUS_BLOCK io
Definition: file.c:100
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
static OUT PIO_STATUS_BLOCK OUT PVOID IN ULONG IN FILE_INFORMATION_CLASS FileInformationClass
Definition: pipe.c:75
DWORD SECURITY_INFORMATION
Definition: ms-dtyp.idl:311
BYTE uint8_t
Definition: msvideo1.c:66
_In_ HANDLE hFile
Definition: mswsock.h:90
Definition: features.h:417
unsigned int UINT
Definition: ndis.h:50
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE _In_opt_ PVOID ApcContext
Definition: iofuncs.h:727
_In_opt_ HANDLE _In_opt_ PIO_APC_ROUTINE ApcRoutine
Definition: iofuncs.h:726
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
Definition: iofunc.c:3096
NTSYSAPI NTSTATUS NTAPI NtQueryInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, OUT PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3402
NTSYSAPI NTSTATUS NTAPI NtFsControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
VOID(* PIO_APC_ROUTINE)(IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN ULONG Reserved)
Definition: nt_native.h:877
#define NTSYSCALLAPI
Definition: ntbasedef.h:204
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define FileFsDriverPathInformation
Definition: ntifs_ex.h:391
#define FileFsFullSizeInformation
Definition: ntifs_ex.h:389
#define FileFsObjectIdInformation
Definition: ntifs_ex.h:390
#define L(x)
Definition: ntvdm.h:50
unsigned short USHORT
Definition: pedump.c:61
struct _FSCTL_GET_INTEGRITY_INFORMATION_BUFFER * PFSCTL_GET_INTEGRITY_INFORMATION_BUFFER
struct _FSCTL_SET_INTEGRITY_INFORMATION_BUFFER * PFSCTL_SET_INTEGRITY_INFORMATION_BUFFER
NTSTATUS NTAPI NtQueryVolumeInformationFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID FsInformation, ULONG Length, FS_INFORMATION_CLASS FsInformationClass)
HMODULE module
Definition: main.cpp:47
struct _FSCTL_GET_INTEGRITY_INFORMATION_BUFFER FSCTL_GET_INTEGRITY_INFORMATION_BUFFER
NTSTATUS WINAPI NtSetEaFile(HANDLE FileHandle, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length)
bool load_string(HMODULE module, UINT id, wstring &s)
Definition: main.cpp:206
void set_dpi_aware()
Definition: main.cpp:50
wstring format_message(ULONG last_error)
Definition: main.cpp:164
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:783
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
void wstring_sprintf(wstring &s, wstring fmt,...)
Definition: main.cpp:225
void format_size(uint64_t size, wstring &s, bool show_bytes)
Definition: main.cpp:65
struct _REPARSE_DATA_BUFFER REPARSE_DATA_BUFFER
struct _DUPLICATE_EXTENTS_DATA DUPLICATE_EXTENTS_DATA
struct _REPARSE_DATA_BUFFER * PREPARSE_DATA_BUFFER
struct _DUPLICATE_EXTENTS_DATA * PDUPLICATE_EXTENTS_DATA
void command_line_to_args(LPWSTR cmdline, vector< wstring > &args)
Definition: main.cpp:645
struct _FSCTL_SET_INTEGRITY_INFORMATION_BUFFER FSCTL_SET_INTEGRITY_INFORMATION_BUFFER
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:734
NTSTATUS WINAPI NtSetSecurityObject(HANDLE Handle, SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR SecurityDescriptor)
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)
TCHAR * cmdline
Definition: stretchblt.cpp:32
LARGE_INTEGER ByteCount
Definition: shellext.h:202
LARGE_INTEGER SourceFileOffset
Definition: shellext.h:200
LARGE_INTEGER TargetFileOffset
Definition: shellext.h:201
LARGE_INTEGER StreamSize
Definition: winternl.h:721
LARGE_INTEGER StreamAllocationSize
Definition: winternl.h:722
USHORT SubstituteNameLength
Definition: shellext.h:172
struct _REPARSE_DATA_BUFFER::@318::@321 MountPointReparseBuffer
WCHAR PathBuffer[1]
Definition: shellext.h:176
USHORT PrintNameOffset
Definition: shellext.h:173
USHORT SubstituteNameOffset
Definition: shellext.h:171
USHORT PrintNameLength
Definition: shellext.h:174
struct _REPARSE_DATA_BUFFER::@318::@320 SymbolicLinkReparseBuffer
USHORT ReparseDataLength
Definition: shellext.h:166
struct _REPARSE_DATA_BUFFER::@318::@322 GenericReparseBuffer
UCHAR DataBuffer[1]
Definition: shellext.h:188
Definition: match.c:390
Definition: dsound.c:943
uint32_t * PULONG
Definition: typedefs.h:59
#define NTAPI
Definition: typedefs.h:36
PVOID HANDLE
Definition: typedefs.h:73
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFREQUEST _In_ size_t OutputBufferLength
Definition: wdfio.h:320
_In_ WDFREQUEST _In_ size_t _In_ size_t InputBufferLength
Definition: wdfio.h:322
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR OutputBuffer
Definition: wdfiotarget.h:863
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR InputBuffer
Definition: wdfiotarget.h:953
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define WINAPI
Definition: msvc.h:6
_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:191
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define const
Definition: zconf.h:233