ReactOS 0.4.16-dev-117-g38f21f9
reactos.cpp
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: BtrFS FSD for ReactOS
4 * FILE: dll/shellext/shellbtrfs/reactos.cpp
5 * PURPOSE: ReactOS glue for Win8.1
6 * PROGRAMMERS: Pierre Schweitzer <pierre@reactos.org>
7 */
8
9#include "shellext.h"
10#include <initguid.h>
11#include <ntddstor.h>
12#define RtlUTF8ToUnicodeN RtlUTF8ToUnicodeN_
13#include <ndk/rtlfuncs.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18/* So that we can link */
19DEFINE_GUID(CLSID_WICImagingFactory, 0xcacaf262,0x9370,0x4615,0xa1,0x3b,0x9f,0x55,0x39,0xda,0x4c,0x0a);
20
21/* Copied from ntoskrnl_vista */
23 PULONG uni_bytes_written,
24 PCCH utf8_src, ULONG utf8_bytes)
25{
27 ULONG i, j;
28 ULONG written;
29 ULONG ch;
30 ULONG utf8_trail_bytes;
31 WCHAR utf16_ch[3];
32 ULONG utf16_ch_len;
33
34 if (!utf8_src)
36 if (!uni_bytes_written)
38
39 written = 0;
41
42 for (i = 0; i < utf8_bytes; i++)
43 {
44 /* read UTF-8 lead byte */
45 ch = (BYTE)utf8_src[i];
46 utf8_trail_bytes = 0;
47 if (ch >= 0xf5)
48 {
49 ch = 0xfffd;
51 }
52 else if (ch >= 0xf0)
53 {
54 ch &= 0x07;
55 utf8_trail_bytes = 3;
56 }
57 else if (ch >= 0xe0)
58 {
59 ch &= 0x0f;
60 utf8_trail_bytes = 2;
61 }
62 else if (ch >= 0xc2)
63 {
64 ch &= 0x1f;
65 utf8_trail_bytes = 1;
66 }
67 else if (ch >= 0x80)
68 {
69 /* overlong or trail byte */
70 ch = 0xfffd;
72 }
73
74 /* read UTF-8 trail bytes */
75 if (i + utf8_trail_bytes < utf8_bytes)
76 {
77 for (j = 0; j < utf8_trail_bytes; j++)
78 {
79 if ((utf8_src[i + 1] & 0xc0) == 0x80)
80 {
81 ch <<= 6;
82 ch |= utf8_src[i + 1] & 0x3f;
83 i++;
84 }
85 else
86 {
87 ch = 0xfffd;
88 utf8_trail_bytes = 0;
90 break;
91 }
92 }
93 }
94 else
95 {
96 ch = 0xfffd;
97 utf8_trail_bytes = 0;
99 i = utf8_bytes;
100 }
101
102 /* encode ch as UTF-16 */
103 if ((ch > 0x10ffff) ||
104 (ch >= 0xd800 && ch <= 0xdfff) ||
105 (utf8_trail_bytes == 2 && ch < 0x00800) ||
106 (utf8_trail_bytes == 3 && ch < 0x10000))
107 {
108 /* invalid codepoint or overlong encoding */
109 utf16_ch[0] = 0xfffd;
110 utf16_ch[1] = 0xfffd;
111 utf16_ch[2] = 0xfffd;
112 utf16_ch_len = utf8_trail_bytes;
114 }
115 else if (ch >= 0x10000)
116 {
117 /* surrogate pair */
118 ch -= 0x010000;
119 utf16_ch[0] = 0xd800 + (ch >> 10 & 0x3ff);
120 utf16_ch[1] = 0xdc00 + (ch >> 0 & 0x3ff);
121 utf16_ch_len = 2;
122 }
123 else
124 {
125 /* single unit */
126 utf16_ch[0] = ch;
127 utf16_ch_len = 1;
128 }
129
130 if (!uni_dest)
131 {
132 written += utf16_ch_len;
133 continue;
134 }
135
136 for (j = 0; j < utf16_ch_len; j++)
137 {
138 if (uni_bytes_max >= sizeof(WCHAR))
139 {
140 *uni_dest++ = utf16_ch[j];
141 uni_bytes_max -= sizeof(WCHAR);
142 written++;
143 }
144 else
145 {
146 uni_bytes_max = 0;
148 }
149 }
150 }
151
152 *uni_bytes_written = written * sizeof(WCHAR);
153 return status;
154}
155
156/* Quick and dirty table for conversion */
157FILE_INFORMATION_CLASS ConvertToFileInfo[MaximumFileInfoByHandleClass] =
158{
163};
164
165/* Taken from kernel32 */
166DWORD
168{
169 DWORD dwErrCode;
170 dwErrCode = RtlNtStatusToDosError(Status);
171 SetLastError(dwErrCode);
172 return dwErrCode;
173}
174
175/* Quick implementation, still going farther than Wine implementation */
176BOOL
177WINAPI
180 LPVOID lpFileInformation,
181 DWORD dwBufferSize)
182{
185 FILE_INFORMATION_CLASS FileInfoClass;
186
187 FileInfoClass = (FILE_INFORMATION_CLASS)-1;
188
189 /* Attempt to convert the class */
190 if (FileInformationClass < MaximumFileInfoByHandleClass)
191 {
193 }
194
195 /* If wrong, bail out */
196 if (FileInfoClass == -1)
197 {
199 return FALSE;
200 }
201
202 /* And set the information */
203 Status = NtSetInformationFile(hFile, &IoStatusBlock, lpFileInformation,
204 dwBufferSize, FileInfoClass);
205
206 if (!NT_SUCCESS(Status))
207 {
209 return FALSE;
210 }
211
212 return TRUE;
213}
214#ifdef __cplusplus
215}
216#endif
LONG NTSTATUS
Definition: precomp.h:26
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
@ FileEndOfFileInformation
Definition: from_kernel.h:81
@ FileCompressionInformation
Definition: from_kernel.h:89
@ FileRenameInformation
Definition: from_kernel.h:71
@ FileIoPriorityHintInformation
Definition: from_kernel.h:104
@ FileAttributeTagInformation
Definition: from_kernel.h:96
@ FileIdBothDirectoryInformation
Definition: from_kernel.h:98
@ FileNameInformation
Definition: from_kernel.h:70
@ FileAllocationInformation
Definition: from_kernel.h:80
@ FileStreamInformation
Definition: from_kernel.h:83
@ FileBasicInformation
Definition: from_kernel.h:65
@ FileDispositionInformation
Definition: from_kernel.h:74
enum _FILE_INFORMATION_CLASS FILE_INFORMATION_CLASS
Definition: directory.c:44
Status
Definition: gdiplustypes.h:25
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
@ FileRemoteProtocolInformation
Definition: winternl.h:501
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
static FILE_INFO_BY_HANDLE_CLASS
Definition: file.c:36
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
_In_ HANDLE hFile
Definition: mswsock.h:90
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
CONST CHAR * PCCH
Definition: ntbasedef.h:392
#define STATUS_INVALID_PARAMETER_4
Definition: ntstatus.h:478
#define STATUS_SOME_NOT_MAPPED
Definition: ntstatus.h:86
#define FileStandardInformation
Definition: propsheet.cpp:61
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8)
Definition: guiddef.h:68
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:167
FILE_INFORMATION_CLASS ConvertToFileInfo[MaximumFileInfoByHandleClass]
Definition: reactos.cpp:157
#define RtlUTF8ToUnicodeN
Definition: reactos.cpp:12
BOOL WINAPI SetFileInformationByHandle(HANDLE hFile, FILE_INFO_BY_HANDLE_CLASS FileInformationClass, LPVOID lpFileInformation, DWORD dwBufferSize)
Definition: reactos.cpp:178
#define STATUS_SUCCESS
Definition: shellext.h:65
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
Definition: ps.c:97
uint16_t * PWSTR
Definition: typedefs.h:56
uint32_t * PULONG
Definition: typedefs.h:59
#define IN
Definition: typedefs.h:39
uint32_t ULONG
Definition: typedefs.h:59
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define WINAPI
Definition: msvc.h:6
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned char BYTE
Definition: xxhash.c:193