]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/win32/winapi.h
Properly save RecyclePoolId
[bacula/bacula] / bacula / src / win32 / winapi.h
1 /*
2  * Windows APIs that are different for each system.
3  *   We use pointers to the entry points so that a
4  *   single binary will run on all Windows systems.
5  *
6  *     Kern Sibbald MMIII
7  */
8 /*
9    Bacula® - The Network Backup Solution
10
11    Copyright (C) 2003-2007 Free Software Foundation Europe e.V.
12
13    The main author of Bacula is Kern Sibbald, with contributions from
14    many others, a complete list can be found in the file AUTHORS.
15    This program is Free Software; you can redistribute it and/or
16    modify it under the terms of version two of the GNU General Public
17    License as published by the Free Software Foundation and included
18    in the file LICENSE.
19
20    This program is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23    General Public License for more details.
24
25    You should have received a copy of the GNU General Public License
26    along with this program; if not, write to the Free Software
27    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28    02110-1301, USA.
29
30    Bacula® is a registered trademark of John Walker.
31    The licensor of Bacula is the Free Software Foundation Europe
32    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
33    Switzerland, email:ftf@fsfeurope.org.
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 // from
62 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileattributesex.asp
63 // In the ANSI version of this function, the name is limited to
64 // MAX_PATH characters. To extend this limit to 32,767 wide
65 // characters, call the Unicode version of the function and prepend
66 // "\\?\" to the path. For more information, see Naming a File.
67 #define MAX_PATH_W 32767
68
69 int wchar_2_UTF8(char *pszUTF, const WCHAR *pszUCS, int cchChar = MAX_PATH_UTF8);
70 int UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF);
71 int make_win32_path_UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF, BOOL* pBIsRawPath = NULL);
72
73 // init with win9x, but maybe set to NT in InitWinAPI
74 extern DWORD DLL_IMP_EXP g_platform_id;
75 extern DWORD DLL_IMP_EXP g_MinorVersion;
76 extern DWORD DLL_IMP_EXP g_MajorVersion;
77
78 /* In ADVAPI32.DLL */
79 typedef BOOL (WINAPI * t_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
80 typedef BOOL (WINAPI * t_AdjustTokenPrivileges)(HANDLE, BOOL,
81           PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
82 typedef BOOL (WINAPI * t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);
83
84 extern t_OpenProcessToken      DLL_IMP_EXP p_OpenProcessToken;
85 extern t_AdjustTokenPrivileges DLL_IMP_EXP p_AdjustTokenPrivileges;
86 extern t_LookupPrivilegeValue  DLL_IMP_EXP p_LookupPrivilegeValue;
87
88 /* In MSVCRT.DLL */
89 typedef int (__cdecl * t_wunlink) (const wchar_t *);
90 typedef int (__cdecl * t_wmkdir) (const wchar_t *);
91 typedef int (__cdecl * t_wopen)  (const wchar_t *, int, ...);
92
93 extern t_wunlink   DLL_IMP_EXP p_wunlink;
94 extern t_wmkdir    DLL_IMP_EXP p_wmkdir;
95
96 /* In KERNEL32.DLL */
97 typedef BOOL (WINAPI * t_GetFileAttributesExA)(LPCSTR, GET_FILEEX_INFO_LEVELS,
98        LPVOID);
99 typedef BOOL (WINAPI * t_GetFileAttributesExW)(LPCWSTR, GET_FILEEX_INFO_LEVELS,
100        LPVOID);
101
102 typedef DWORD (WINAPI * t_GetFileAttributesA)(LPCSTR);
103 typedef DWORD (WINAPI * t_GetFileAttributesW)(LPCWSTR);
104 typedef BOOL (WINAPI * t_SetFileAttributesA)(LPCSTR, DWORD);
105 typedef BOOL (WINAPI * t_SetFileAttributesW)(LPCWSTR, DWORD);
106
107 typedef HANDLE (WINAPI * t_CreateFileA) (LPCSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES,
108         DWORD , DWORD, HANDLE);
109 typedef HANDLE (WINAPI * t_CreateFileW) (LPCWSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES,
110         DWORD , DWORD, HANDLE);
111
112 typedef BOOL (WINAPI * t_CreateDirectoryA) (LPCSTR, LPSECURITY_ATTRIBUTES);
113 typedef BOOL (WINAPI * t_CreateDirectoryW) (LPCWSTR, LPSECURITY_ATTRIBUTES);
114
115 typedef BOOL (WINAPI * t_SetProcessShutdownParameters)(DWORD, DWORD);
116 typedef BOOL (WINAPI * t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
117 typedef BOOL (WINAPI * t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
118
119 typedef int (WINAPI * t_WideCharToMultiByte) (UINT CodePage, DWORD , LPCWSTR, int,
120                                               LPSTR, int, LPCSTR, LPBOOL);
121
122 typedef int (WINAPI * t_MultiByteToWideChar) (UINT, DWORD, LPCSTR, int, LPWSTR, int);
123 typedef HANDLE (WINAPI * t_FindFirstFileA) (LPCSTR, LPWIN32_FIND_DATAA);
124 typedef HANDLE (WINAPI * t_FindFirstFileW) (LPCWSTR, LPWIN32_FIND_DATAW);
125
126 typedef BOOL (WINAPI * t_FindNextFileA) (HANDLE, LPWIN32_FIND_DATAA);
127 typedef BOOL (WINAPI * t_FindNextFileW) (HANDLE, LPWIN32_FIND_DATAW);
128
129 typedef BOOL (WINAPI * t_SetCurrentDirectoryA) (LPCSTR);
130 typedef BOOL (WINAPI * t_SetCurrentDirectoryW) (LPCWSTR);
131
132 typedef DWORD (WINAPI * t_GetCurrentDirectoryA) (DWORD, LPSTR);
133 typedef DWORD (WINAPI * t_GetCurrentDirectoryW) (DWORD, LPWSTR);
134
135 typedef BOOL (WINAPI * t_GetVolumePathNameW) (LPCWSTR, LPWSTR, DWORD);
136 typedef BOOL (WINAPI * t_GetVolumeNameForVolumeMountPointW) (LPCWSTR, LPWSTR, DWORD);
137
138 typedef BOOL (WINAPI * t_AttachConsole) (DWORD);
139
140 extern t_GetFileAttributesA   DLL_IMP_EXP p_GetFileAttributesA;
141 extern t_GetFileAttributesW   DLL_IMP_EXP p_GetFileAttributesW;
142
143 extern t_GetFileAttributesExA   DLL_IMP_EXP p_GetFileAttributesExA;
144 extern t_GetFileAttributesExW   DLL_IMP_EXP p_GetFileAttributesExW;
145
146 extern t_SetFileAttributesA   DLL_IMP_EXP p_SetFileAttributesA;
147 extern t_SetFileAttributesW   DLL_IMP_EXP p_SetFileAttributesW;
148
149 extern t_CreateFileA   DLL_IMP_EXP p_CreateFileA;
150 extern t_CreateFileW   DLL_IMP_EXP p_CreateFileW;
151
152 extern t_CreateDirectoryA   DLL_IMP_EXP p_CreateDirectoryA;
153 extern t_CreateDirectoryW   DLL_IMP_EXP p_CreateDirectoryW;
154
155 extern t_SetProcessShutdownParameters DLL_IMP_EXP p_SetProcessShutdownParameters;
156 extern t_BackupRead         DLL_IMP_EXP p_BackupRead;
157 extern t_BackupWrite        DLL_IMP_EXP p_BackupWrite;
158
159 extern t_WideCharToMultiByte DLL_IMP_EXP p_WideCharToMultiByte;
160 extern t_MultiByteToWideChar DLL_IMP_EXP p_MultiByteToWideChar;
161
162 extern t_FindFirstFileA DLL_IMP_EXP p_FindFirstFileA;
163 extern t_FindFirstFileW DLL_IMP_EXP p_FindFirstFileW;
164
165 extern t_FindNextFileA DLL_IMP_EXP p_FindNextFileA;
166 extern t_FindNextFileW DLL_IMP_EXP p_FindNextFileW;
167
168 extern t_SetCurrentDirectoryA DLL_IMP_EXP p_SetCurrentDirectoryA;
169 extern t_SetCurrentDirectoryW DLL_IMP_EXP p_SetCurrentDirectoryW;
170
171 extern t_GetCurrentDirectoryA DLL_IMP_EXP p_GetCurrentDirectoryA;
172 extern t_GetCurrentDirectoryW DLL_IMP_EXP p_GetCurrentDirectoryW;
173
174 extern t_GetVolumePathNameW DLL_IMP_EXP p_GetVolumePathNameW;
175 extern t_GetVolumeNameForVolumeMountPointW DLL_IMP_EXP p_GetVolumeNameForVolumeMountPointW;
176
177 extern t_AttachConsole DLL_IMP_EXP p_AttachConsole;
178
179 void InitWinAPIWrapper();
180
181 /* In SHFolder.dll on older systems, and now Shell32.dll */
182 typedef BOOL (WINAPI * t_SHGetFolderPath)(HWND, int, HANDLE, DWORD, LPTSTR);
183 extern t_SHGetFolderPath  DLL_IMP_EXP p_SHGetFolderPath;
184
185 #endif
186
187 #endif /* __WINAPI_H */