]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/winapi.h
19July06
[bacula/bacula] / bacula / src / lib / 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    Copyright (C) 2003-2006 Kern Sibbald
10
11    This program is free software; you can redistribute it and/or
12    modify it under the terms of the GNU General Public License
13    version 2 as amended with additional clauses defined in the
14    file LICENSE in the main source directory.
15
16    This program is distributed in the hope that it will be useful,
17    but WITHOUT ANY WARRANTY; without even the implied warranty of
18    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
19    the file LICENSE for additional details.
20
21  */
22
23 #ifndef __WINAPI_H
24 #define __WINAPI_H
25
26 #if defined(HAVE_WIN32)
27 /*
28  * Commented out native.h include statement, which is not distributed with the
29  * free version of VC++, and which is not used in bacula.
30  * 
31  * #if !defined(HAVE_MINGW) // native.h not present on mingw
32  * #include <native.h>
33  * #endif
34  */
35 #include <windef.h>
36 #endif
37
38 #if defined(HAVE_CYGWIN) || defined(HAVE_WIN32)
39
40 #ifndef POOLMEM
41 typedef char POOLMEM;
42 #endif
43
44 // unicode enabling of win 32 needs some defines and functions
45
46 // using an average of 3 bytes per character is probably fine in
47 // practice but I believe that Windows actually uses UTF-16 encoding
48 // as opposed to UCS2 which means characters 0x10000-0x10ffff are
49 // valid and result in 4 byte UTF-8 encodings.
50 #define MAX_PATH_UTF8    MAX_PATH*4  // strict upper bound on UTF-16 to UTF-8 conversion
51 // from
52 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileattributesex.asp
53 // In the ANSI version of this function, the name is limited to
54 // MAX_PATH characters. To extend this limit to 32,767 wide
55 // characters, call the Unicode version of the function and prepend
56 // "\\?\" to the path. For more information, see Naming a File.
57 #define MAX_PATH_W 32767
58
59 int wchar_2_UTF8(char *pszUTF, const WCHAR *pszUCS, int cchChar = MAX_PATH_UTF8);
60 int UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF);
61 int make_win32_path_UTF8_2_wchar(POOLMEM **pszUCS, const char *pszUTF, BOOL* pBIsRawPath = NULL);
62
63
64 /* In ADVAPI32.DLL */
65
66 typedef BOOL (WINAPI * t_OpenProcessToken)(HANDLE, DWORD, PHANDLE);
67 typedef BOOL (WINAPI * t_AdjustTokenPrivileges)(HANDLE, BOOL,
68           PTOKEN_PRIVILEGES, DWORD, PTOKEN_PRIVILEGES, PDWORD);
69 typedef BOOL (WINAPI * t_LookupPrivilegeValue)(LPCTSTR, LPCTSTR, PLUID);
70
71 extern t_OpenProcessToken      p_OpenProcessToken;
72 extern t_AdjustTokenPrivileges p_AdjustTokenPrivileges;
73 extern t_LookupPrivilegeValue  p_LookupPrivilegeValue;
74
75 /* In MSVCRT.DLL */
76 typedef int (__cdecl * t_wunlink) (const wchar_t *);
77 typedef int (__cdecl * t_wmkdir) (const wchar_t *);
78 typedef int (__cdecl * t_wopen)  (const wchar_t *, int, ...);
79
80 extern t_wunlink   p_wunlink;
81 extern t_wmkdir    p_wmkdir;
82 extern t_wopen     p_wopen;
83
84 /* In KERNEL32.DLL */
85 typedef BOOL (WINAPI * t_GetFileAttributesExA)(LPCSTR, GET_FILEEX_INFO_LEVELS,
86        LPVOID);
87 typedef BOOL (WINAPI * t_GetFileAttributesExW)(LPCWSTR, GET_FILEEX_INFO_LEVELS,
88        LPVOID);
89
90 typedef DWORD (WINAPI * t_GetFileAttributesA)(LPCSTR);
91 typedef DWORD (WINAPI * t_GetFileAttributesW)(LPCWSTR);
92 typedef BOOL (WINAPI * t_SetFileAttributesA)(LPCSTR, DWORD);
93 typedef BOOL (WINAPI * t_SetFileAttributesW)(LPCWSTR, DWORD);
94
95 typedef HANDLE (WINAPI * t_CreateFileA) (LPCSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES,
96         DWORD , DWORD, HANDLE);
97 typedef HANDLE (WINAPI * t_CreateFileW) (LPCWSTR, DWORD ,DWORD, LPSECURITY_ATTRIBUTES,
98         DWORD , DWORD, HANDLE);
99
100 typedef BOOL (WINAPI * t_CreateDirectoryA) (LPCSTR, LPSECURITY_ATTRIBUTES);
101 typedef BOOL (WINAPI * t_CreateDirectoryW) (LPCWSTR, LPSECURITY_ATTRIBUTES);
102
103 typedef BOOL (WINAPI * t_SetProcessShutdownParameters)(DWORD, DWORD);
104 typedef BOOL (WINAPI * t_BackupRead)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
105 typedef BOOL (WINAPI * t_BackupWrite)(HANDLE,LPBYTE,DWORD,LPDWORD,BOOL,BOOL,LPVOID*);
106
107 typedef int (WINAPI * t_WideCharToMultiByte) (UINT CodePage, DWORD , LPCWSTR, int,
108                                               LPSTR, int, LPCSTR, LPBOOL);
109
110 typedef int (WINAPI * t_MultiByteToWideChar) (UINT, DWORD, LPCSTR, int, LPWSTR, int);
111 typedef HANDLE (WINAPI * t_FindFirstFileA) (LPCSTR, LPWIN32_FIND_DATAA);
112 typedef HANDLE (WINAPI * t_FindFirstFileW) (LPCWSTR, LPWIN32_FIND_DATAW);
113
114 typedef BOOL (WINAPI * t_FindNextFileA) (HANDLE, LPWIN32_FIND_DATAA);
115 typedef BOOL (WINAPI * t_FindNextFileW) (HANDLE, LPWIN32_FIND_DATAW);
116
117 typedef BOOL (WINAPI * t_SetCurrentDirectoryA) (LPCSTR);
118 typedef BOOL (WINAPI * t_SetCurrentDirectoryW) (LPCWSTR);
119
120 typedef DWORD (WINAPI * t_GetCurrentDirectoryA) (DWORD, LPSTR);
121 typedef DWORD (WINAPI * t_GetCurrentDirectoryW) (DWORD, LPWSTR);
122
123 typedef BOOL (WINAPI * t_GetVolumePathNameW) (LPCWSTR, LPWSTR, DWORD);
124 typedef BOOL (WINAPI * t_GetVolumeNameForVolumeMountPointW) (LPCWSTR, LPWSTR, DWORD);
125   
126 extern t_GetFileAttributesA   p_GetFileAttributesA;
127 extern t_GetFileAttributesW   p_GetFileAttributesW;
128
129 extern t_GetFileAttributesExA   p_GetFileAttributesExA;
130 extern t_GetFileAttributesExW   p_GetFileAttributesExW;
131
132 extern t_SetFileAttributesA   p_SetFileAttributesA;
133 extern t_SetFileAttributesW   p_SetFileAttributesW;
134
135 extern t_CreateFileA   p_CreateFileA;
136 extern t_CreateFileW   p_CreateFileW;
137
138 extern t_CreateDirectoryA   p_CreateDirectoryA;
139 extern t_CreateDirectoryW   p_CreateDirectoryW;
140
141 extern t_SetProcessShutdownParameters p_SetProcessShutdownParameters;
142 extern t_BackupRead         p_BackupRead;
143 extern t_BackupWrite        p_BackupWrite;
144
145 extern t_WideCharToMultiByte p_WideCharToMultiByte;
146 extern t_MultiByteToWideChar p_MultiByteToWideChar;
147
148 extern t_FindFirstFileA p_FindFirstFileA;
149 extern t_FindFirstFileW p_FindFirstFileW;
150
151 extern t_FindNextFileA p_FindNextFileA;
152 extern t_FindNextFileW p_FindNextFileW;
153
154 extern t_SetCurrentDirectoryA p_SetCurrentDirectoryA;
155 extern t_SetCurrentDirectoryW p_SetCurrentDirectoryW;
156
157 extern t_GetCurrentDirectoryA p_GetCurrentDirectoryA;
158 extern t_GetCurrentDirectoryW p_GetCurrentDirectoryW;
159
160 extern t_GetVolumePathNameW p_GetVolumePathNameW;
161 extern t_GetVolumeNameForVolumeMountPointW p_GetVolumeNameForVolumeMountPointW;
162           
163 #ifdef WIN32_VSS
164 class  VSSClient;
165 extern VSSClient* g_pVSSClient;
166 #endif
167
168 void InitWinAPIWrapper();
169 #endif
170
171 #endif /* __WINAPI_H */