]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/winapi.h
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / win32 / winapi.h
1 /*
2    Bacula® - The Network Backup Solution
3
4    Copyright (C) 2003-2010 Free Software Foundation Europe e.V.
5
6    The main author of Bacula is Kern Sibbald, with contributions from
7    many others, a complete list can be found in the file AUTHORS.
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    General Public License for more details.
17
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22
23    Bacula® is a registered trademark of Kern Sibbald.
24    The licensor of Bacula is the Free Software Foundation Europe
25    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26    Switzerland, email:ftf@fsfeurope.org.
27 */
28 /*
29  * Windows APIs that are different for each system.
30  *   We use pointers to the entry points so that a
31  *   single binary will run on all Windows systems.
32  *
33  *     Kern Sibbald MMIII
34  */
35
36 #ifndef __WINAPI_H
37 #define __WINAPI_H
38
39 #if defined(HAVE_WIN32)
40 /*
41  * Commented out native.h include statement, which is not distributed with the
42  * free version of VC++, and which is not used in bacula.
43  * 
44  * #if !defined(HAVE_MINGW) // native.h not present on mingw
45  * #include <native.h>
46  * #endif
47  */
48 #include <windef.h>
49
50 #ifndef POOLMEM
51 typedef char POOLMEM;
52 #endif
53
54 // unicode enabling of win 32 needs some defines and functions
55
56 // using an average of 3 bytes per character is probably fine in
57 // practice but I believe that Windows actually uses UTF-16 encoding
58 // as opposed to UCS2 which means characters 0x10000-0x10ffff are
59 // valid and result in 4 byte UTF-8 encodings.
60 #define MAX_PATH_UTF8    MAX_PATH*4  // strict upper bound on UTF-16 to UTF-8 conversion
61
62 // from
63 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileattributesex.asp
64 // In the ANSI version of this function, the name is limited to
65 // MAX_PATH characters. To extend this limit to 32,767 wide
66 // characters, call the Unicode version of the function and prepend
67 // "\\?\" to the path. For more information, see Naming a File.
68 #define MAX_PATH_W 32767
69
70 int wchar_2_UTF8(POOLMEM **pszUTF, const wchar_t *pszUCS);
71 int wchar_2_UTF8(char *pszUTF, const WCHAR *pszUCS, int cchChar = MAX_PATH_UTF8);
72 int UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF);
73 int make_win32_path_UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF, BOOL* pBIsRawPath = NULL);
74
75 // init with win9x, but maybe set to NT in InitWinAPI
76 extern DWORD DLL_IMP_EXP g_platform_id;
77 extern DWORD DLL_IMP_EXP g_MinorVersion;
78 extern DWORD DLL_IMP_EXP g_MajorVersion;
79
80 /* In ADVAPI32.DLL */
81 typedef BOOL (WINAPI * t_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
82 typedef BOOL (WINAPI * t_AdjustTokenPrivileges)(HANDLE, BOOL,
83           PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
84 typedef BOOL (WINAPI * t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);
85
86 extern t_OpenProcessToken      DLL_IMP_EXP p_OpenProcessToken;
87 extern t_AdjustTokenPrivileges DLL_IMP_EXP p_AdjustTokenPrivileges;
88 extern t_LookupPrivilegeValue  DLL_IMP_EXP p_LookupPrivilegeValue;
89
90 /* In MSVCRT.DLL */
91 typedef int (__cdecl * t_wunlink) (const wchar_t *);
92 typedef int (__cdecl * t_wmkdir) (const wchar_t *);
93 typedef int (__cdecl * t_wopen)  (const wchar_t *, int, ...);
94
95 extern t_wunlink   DLL_IMP_EXP p_wunlink;
96 extern t_wmkdir    DLL_IMP_EXP p_wmkdir;
97
98 /* In KERNEL32.DLL */
99 typedef BOOL (WINAPI * t_GetFileAttributesExA)(LPCSTR, GET_FILEEX_INFO_LEVELS,
100        LPVOID);
101 typedef BOOL (WINAPI * t_GetFileAttributesExW)(LPCWSTR, GET_FILEEX_INFO_LEVELS,
102        LPVOID);
103
104 typedef DWORD (WINAPI * t_GetFileAttributesA)(LPCSTR);
105 typedef DWORD (WINAPI * t_GetFileAttributesW)(LPCWSTR);
106 typedef BOOL (WINAPI * t_SetFileAttributesA)(LPCSTR, DWORD);
107 typedef BOOL (WINAPI * t_SetFileAttributesW)(LPCWSTR, DWORD);
108
109 typedef HANDLE (WINAPI * t_CreateFileA) (LPCSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES,
110         DWORD , DWORD, HANDLE);
111 typedef HANDLE (WINAPI * t_CreateFileW) (LPCWSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES,
112         DWORD , DWORD, HANDLE);
113
114 typedef BOOL (WINAPI * t_CreateDirectoryA) (LPCSTR, LPSECURITY_ATTRIBUTES);
115 typedef BOOL (WINAPI * t_CreateDirectoryW) (LPCWSTR, LPSECURITY_ATTRIBUTES);
116
117 typedef BOOL (WINAPI * t_SetProcessShutdownParameters)(DWORD, DWORD);
118 typedef BOOL (WINAPI * t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
119 typedef BOOL (WINAPI * t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
120
121 typedef int (WINAPI * t_WideCharToMultiByte) (UINT CodePage, DWORD , LPCWSTR, int,
122                                               LPSTR, int, LPCSTR, LPBOOL);
123
124 typedef int (WINAPI * t_MultiByteToWideChar) (UINT, DWORD, LPCSTR, int, LPWSTR, int);
125 typedef HANDLE (WINAPI * t_FindFirstFileA) (LPCSTR, LPWIN32_FIND_DATAA);
126 typedef HANDLE (WINAPI * t_FindFirstFileW) (LPCWSTR, LPWIN32_FIND_DATAW);
127
128 typedef BOOL (WINAPI * t_FindNextFileA) (HANDLE, LPWIN32_FIND_DATAA);
129 typedef BOOL (WINAPI * t_FindNextFileW) (HANDLE, LPWIN32_FIND_DATAW);
130
131 typedef BOOL (WINAPI * t_SetCurrentDirectoryA) (LPCSTR);
132 typedef BOOL (WINAPI * t_SetCurrentDirectoryW) (LPCWSTR);
133
134 typedef DWORD (WINAPI * t_GetCurrentDirectoryA) (DWORD, LPSTR);
135 typedef DWORD (WINAPI * t_GetCurrentDirectoryW) (DWORD, LPWSTR);
136
137 typedef BOOL (WINAPI * t_GetVolumePathNameW) (LPCWSTR, LPWSTR, DWORD);
138 typedef BOOL (WINAPI * t_GetVolumeNameForVolumeMountPointW) (LPCWSTR, LPWSTR, DWORD);
139
140 typedef BOOL (WINAPI * t_AttachConsole) (DWORD);
141
142 typedef BOOL (WINAPI *t_CreateProcessA) (
143    LPCSTR,
144    LPSTR,
145    LPSECURITY_ATTRIBUTES,
146    LPSECURITY_ATTRIBUTES,
147    BOOL,
148    DWORD,
149    PVOID,
150    LPCSTR,
151    LPSTARTUPINFOA,
152    LPPROCESS_INFORMATION);
153 typedef BOOL (WINAPI *t_CreateProcessW) (
154    LPCWSTR,
155    LPWSTR,
156    LPSECURITY_ATTRIBUTES,
157    LPSECURITY_ATTRIBUTES,
158    BOOL,
159    DWORD,
160    PVOID,
161    LPCWSTR,
162    LPSTARTUPINFOW,
163    LPPROCESS_INFORMATION);
164
165 extern t_CreateProcessA DLL_IMP_EXP p_CreateProcessA;
166 extern t_CreateProcessW DLL_IMP_EXP p_CreateProcessW;
167
168 extern t_GetFileAttributesA   DLL_IMP_EXP p_GetFileAttributesA;
169 extern t_GetFileAttributesW   DLL_IMP_EXP p_GetFileAttributesW;
170
171 extern t_GetFileAttributesExA   DLL_IMP_EXP p_GetFileAttributesExA;
172 extern t_GetFileAttributesExW   DLL_IMP_EXP p_GetFileAttributesExW;
173
174 extern t_SetFileAttributesA   DLL_IMP_EXP p_SetFileAttributesA;
175 extern t_SetFileAttributesW   DLL_IMP_EXP p_SetFileAttributesW;
176
177 extern t_CreateFileA   DLL_IMP_EXP p_CreateFileA;
178 extern t_CreateFileW   DLL_IMP_EXP p_CreateFileW;
179
180 extern t_CreateDirectoryA   DLL_IMP_EXP p_CreateDirectoryA;
181 extern t_CreateDirectoryW   DLL_IMP_EXP p_CreateDirectoryW;
182
183 extern t_SetProcessShutdownParameters DLL_IMP_EXP p_SetProcessShutdownParameters;
184 extern t_BackupRead         DLL_IMP_EXP p_BackupRead;
185 extern t_BackupWrite        DLL_IMP_EXP p_BackupWrite;
186
187 extern t_WideCharToMultiByte DLL_IMP_EXP p_WideCharToMultiByte;
188 extern t_MultiByteToWideChar DLL_IMP_EXP p_MultiByteToWideChar;
189
190 extern t_FindFirstFileA DLL_IMP_EXP p_FindFirstFileA;
191 extern t_FindFirstFileW DLL_IMP_EXP p_FindFirstFileW;
192
193 extern t_FindNextFileA DLL_IMP_EXP p_FindNextFileA;
194 extern t_FindNextFileW DLL_IMP_EXP p_FindNextFileW;
195
196 extern t_SetCurrentDirectoryA DLL_IMP_EXP p_SetCurrentDirectoryA;
197 extern t_SetCurrentDirectoryW DLL_IMP_EXP p_SetCurrentDirectoryW;
198
199 extern t_GetCurrentDirectoryA DLL_IMP_EXP p_GetCurrentDirectoryA;
200 extern t_GetCurrentDirectoryW DLL_IMP_EXP p_GetCurrentDirectoryW;
201
202 extern t_GetVolumePathNameW DLL_IMP_EXP p_GetVolumePathNameW;
203 extern t_GetVolumeNameForVolumeMountPointW DLL_IMP_EXP p_GetVolumeNameForVolumeMountPointW;
204
205 extern t_AttachConsole DLL_IMP_EXP p_AttachConsole;
206
207 void InitWinAPIWrapper();
208
209 /* In SHFolder.dll on older systems, and now Shell32.dll */
210 typedef BOOL (WINAPI * t_SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR);
211 extern t_SHGetFolderPath  DLL_IMP_EXP p_SHGetFolderPath;
212
213 #endif
214
215 #endif /* __WINAPI_H */