1 | /* $Id: disk.cpp,v 1.11 2000-05-20 13:30:27 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 Disk API functions for OS/2
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 |
|
---|
13 |
|
---|
14 | #include <odin.h>
|
---|
15 | #include <odinwrap.h>
|
---|
16 | #include <os2sel.h>
|
---|
17 |
|
---|
18 | #include <os2win.h>
|
---|
19 | #include <stdlib.h>
|
---|
20 | #include <string.h>
|
---|
21 | #include "unicode.h"
|
---|
22 |
|
---|
23 | #define DBG_LOCALLOG DBG_disk
|
---|
24 | #include "dbglocal.h"
|
---|
25 |
|
---|
26 |
|
---|
27 | ODINDEBUGCHANNEL(KERNEL32-DISK)
|
---|
28 |
|
---|
29 | //******************************************************************************
|
---|
30 | //******************************************************************************
|
---|
31 | BOOL WIN32API SetVolumeLabelA( LPCSTR arg1, LPCSTR arg2)
|
---|
32 | {
|
---|
33 | dprintf(("KERNEL32: OS2SetVolumeLabelA\n"));
|
---|
34 | return O32_SetVolumeLabel(arg1, arg2);
|
---|
35 | }
|
---|
36 | //******************************************************************************
|
---|
37 | //******************************************************************************
|
---|
38 | BOOL WIN32API SetVolumeLabelW(LPCWSTR lpRootPathName, LPCWSTR lpVolumeName)
|
---|
39 | {
|
---|
40 | char *asciiroot, *asciivolname;
|
---|
41 | BOOL rc;
|
---|
42 |
|
---|
43 | dprintf(("KERNEL32: OS2SetVolumeLabelW\n"));
|
---|
44 | asciiroot = UnicodeToAsciiString((LPWSTR)lpRootPathName);
|
---|
45 | asciivolname = UnicodeToAsciiString((LPWSTR)lpVolumeName);
|
---|
46 | rc = O32_SetVolumeLabel(asciiroot, asciivolname);
|
---|
47 | FreeAsciiString(asciivolname);
|
---|
48 | FreeAsciiString(asciiroot);
|
---|
49 | return(rc);
|
---|
50 | }
|
---|
51 |
|
---|
52 | //******************************************************************************
|
---|
53 | //SvL: 24-6-'97 - Added
|
---|
54 | //******************************************************************************
|
---|
55 | BOOL WIN32API GetDiskFreeSpaceA( LPCSTR arg1, PDWORD arg2, PDWORD arg3, PDWORD arg4, PDWORD arg5)
|
---|
56 | {
|
---|
57 | BOOL rc;
|
---|
58 | DWORD dwSectorsPerCluster; // address of sectors per cluster ter
|
---|
59 | DWORD dwBytesPerSector; // address of bytes per sector
|
---|
60 | DWORD dwNumberOfFreeClusters; // address of number of free clusters
|
---|
61 | DWORD dwTotalNumberOfClusters; // address of total number of clusters
|
---|
62 | dprintf(("KERNEL32: OS2GetDiskFreeSpaceA %s, 0x%08X, 0x%08X, 0x%08X, 0x%08X,\n",
|
---|
63 | arg1!=NULL?arg1:"NULL", arg2,arg3,arg4,arg5));
|
---|
64 | rc = O32_GetDiskFreeSpace(arg1, &dwSectorsPerCluster, &dwBytesPerSector,
|
---|
65 | &dwNumberOfFreeClusters, &dwTotalNumberOfClusters);
|
---|
66 | if(rc)
|
---|
67 | {
|
---|
68 | if (arg2!=NULL)
|
---|
69 | *arg2 = dwSectorsPerCluster;
|
---|
70 | if (arg3!=NULL)
|
---|
71 | *arg3 = dwBytesPerSector;
|
---|
72 | if (arg4!=NULL)
|
---|
73 | *arg4 = dwNumberOfFreeClusters;
|
---|
74 | if (arg5!=NULL)
|
---|
75 | *arg5 = dwTotalNumberOfClusters;
|
---|
76 | }
|
---|
77 | dprintf((" returned %d\n",rc));
|
---|
78 | return rc;
|
---|
79 | }
|
---|
80 | //******************************************************************************
|
---|
81 | //******************************************************************************
|
---|
82 | BOOL WIN32API GetDiskFreeSpaceW(LPCWSTR arg1, PDWORD arg2, PDWORD arg3, PDWORD arg4, PDWORD arg5)
|
---|
83 | {
|
---|
84 | BOOL rc;
|
---|
85 | char *astring;
|
---|
86 |
|
---|
87 | dprintf(("KERNEL32: OS2GetDiskFreeSpaceW\n"));
|
---|
88 | astring = UnicodeToAsciiString((LPWSTR)arg1);
|
---|
89 | rc = O32_GetDiskFreeSpace(astring, arg2, arg3, arg4, arg5);
|
---|
90 | FreeAsciiString(astring);
|
---|
91 | return(rc);
|
---|
92 | }
|
---|
93 |
|
---|
94 |
|
---|
95 | /*****************************************************************************
|
---|
96 | * Name : GetDiskFreeSpaceEx
|
---|
97 | * Purpose :
|
---|
98 | * Parameters: lpDirectoryName [in] Pointer to a null-terminated string that
|
---|
99 | * specifies a directory on the disk of interest.
|
---|
100 | * This string can be a UNC name. If this
|
---|
101 | * parameter is a UNC name, you must follow it
|
---|
102 | * with an additional backslash. For example, you
|
---|
103 | * would specify \\MyServer\MyShare as
|
---|
104 | * \\MyServer\MyShare\.
|
---|
105 | * If lpDirectoryName is NULL, the
|
---|
106 | * GetDiskFreeSpaceEx function obtains
|
---|
107 | * information about the object store.
|
---|
108 | * Note that lpDirectoryName does not have to
|
---|
109 | * specify the root directory on a disk. The
|
---|
110 | * function accepts any directory on the disk.
|
---|
111 | *
|
---|
112 | * lpFreeBytesAvailableToCaller
|
---|
113 | * [out] Pointer to a variable to receive the
|
---|
114 | * total number of free bytes on the disk that
|
---|
115 | * are available to the user associated with the
|
---|
116 | * calling thread.
|
---|
117 | * lpTotalNumberOfBytes
|
---|
118 | * [out] Pointer to a variable to receive the
|
---|
119 | * total number of bytes on the disk that are
|
---|
120 | * available to the user associated with the
|
---|
121 | * calling thread.
|
---|
122 | * lpTotalNumberOfFreeBytes
|
---|
123 | * [out] Pointer to a variable to receive the
|
---|
124 | * total number of free bytes on the disk.
|
---|
125 | * This parameter can be NULL.
|
---|
126 | * Variables :
|
---|
127 | * Result : Nonzero indicates success. Zero indicates failure. To get
|
---|
128 | * extended error information, call GetLastError.
|
---|
129 | * Remark : Note that the values obtained by this function are of type
|
---|
130 | * ULARGE_INTEGER. Be careful not to truncate these values to
|
---|
131 | * 32 bits.
|
---|
132 | * Status :
|
---|
133 | *
|
---|
134 | * Author : Patrick Haller [Fri, 2000/01/08 23:44]
|
---|
135 | *****************************************************************************/
|
---|
136 |
|
---|
137 | ODINFUNCTION4(BOOL,GetDiskFreeSpaceExA,
|
---|
138 | LPCSTR, lpDirectoryName,
|
---|
139 | PULARGE_INTEGER, lpFreeBytesAvailableToCaller,
|
---|
140 | PULARGE_INTEGER, lpTotalNumberOfBytes,
|
---|
141 | PULARGE_INTEGER, lpTotalNumberOfFreeBytes )
|
---|
142 | {
|
---|
143 | BOOL rc;
|
---|
144 | DWORD dwSectorsPerCluster; // address of sectors per cluster ter
|
---|
145 | DWORD dwBytesPerSector; // address of bytes per sector
|
---|
146 | DWORD dwNumberOfFreeClusters; // address of number of free clusters
|
---|
147 | DWORD dwTotalNumberOfClusters; // address of total number of clusters
|
---|
148 |
|
---|
149 | rc = O32_GetDiskFreeSpace(lpDirectoryName, &dwSectorsPerCluster, &dwBytesPerSector,
|
---|
150 | &dwNumberOfFreeClusters, &dwTotalNumberOfClusters);
|
---|
151 | if(rc)
|
---|
152 | {
|
---|
153 | //TODO: Fill in high part (overflow possible)!!!!!!
|
---|
154 | if(lpFreeBytesAvailableToCaller!=NULL) {
|
---|
155 | lpFreeBytesAvailableToCaller->LowPart = dwNumberOfFreeClusters*dwSectorsPerCluster*dwBytesPerSector;
|
---|
156 | lpFreeBytesAvailableToCaller->HighPart = 0;
|
---|
157 | }
|
---|
158 | if(lpTotalNumberOfBytes!=NULL) {
|
---|
159 | lpTotalNumberOfBytes->LowPart = dwTotalNumberOfClusters*dwSectorsPerCluster*dwBytesPerSector;
|
---|
160 | lpTotalNumberOfBytes->HighPart = 0;
|
---|
161 | }
|
---|
162 | if(lpTotalNumberOfFreeBytes!=NULL) {
|
---|
163 | lpTotalNumberOfFreeBytes->LowPart = dwNumberOfFreeClusters*dwSectorsPerCluster*dwBytesPerSector;
|
---|
164 | lpTotalNumberOfFreeBytes->HighPart = 0;
|
---|
165 | }
|
---|
166 | }
|
---|
167 | return rc;
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | ODINFUNCTION4(BOOL,GetDiskFreeSpaceExW,
|
---|
172 | LPCWSTR, lpDirectoryName,
|
---|
173 | PULARGE_INTEGER, lpFreeBytesAvailableToCaller,
|
---|
174 | PULARGE_INTEGER, lpTotalNumberOfBytes,
|
---|
175 | PULARGE_INTEGER, lpTotalNumberOfFreeBytes )
|
---|
176 | {
|
---|
177 | BOOL rc;
|
---|
178 | char *astring;
|
---|
179 |
|
---|
180 | dprintf(("KERNEL32: OS2GetDiskFreeSpaceExW\n"));
|
---|
181 | astring = UnicodeToAsciiString((LPWSTR)lpDirectoryName);
|
---|
182 | rc = GetDiskFreeSpaceExA(astring, lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes);
|
---|
183 | FreeAsciiString(astring);
|
---|
184 | return(rc);
|
---|
185 | }
|
---|
186 |
|
---|
187 |
|
---|
188 | //******************************************************************************
|
---|
189 | //******************************************************************************
|
---|
190 | UINT WIN32API GetDriveTypeA( LPCSTR arg1)
|
---|
191 | {
|
---|
192 | UINT rc;
|
---|
193 | rc = O32_GetDriveType(arg1);
|
---|
194 | dprintf(("KERNEL32: GetDriveType %s = %d\n", arg1,rc));
|
---|
195 | return rc;
|
---|
196 | }
|
---|
197 | //******************************************************************************
|
---|
198 | //******************************************************************************
|
---|
199 | UINT WIN32API GetDriveTypeW(LPCWSTR arg1)
|
---|
200 | {
|
---|
201 | UINT rc;
|
---|
202 | char *astring;
|
---|
203 |
|
---|
204 | astring = UnicodeToAsciiString((LPWSTR)arg1);
|
---|
205 | dprintf(("KERNEL32: OS2GetDriveTypeW %s", astring));
|
---|
206 | rc = O32_GetDriveType(astring);
|
---|
207 | FreeAsciiString(astring);
|
---|
208 | return(rc);
|
---|
209 | }
|
---|
210 | //******************************************************************************
|
---|
211 | //******************************************************************************
|
---|
212 | ODINFUNCTION8(BOOL, GetVolumeInformationA,
|
---|
213 | LPCSTR, lpRootPathName,
|
---|
214 | LPSTR, lpVolumeNameBuffer,
|
---|
215 | DWORD, nVolumeNameSize,
|
---|
216 | PDWORD, lpVolumeSerialNumber,
|
---|
217 | PDWORD, lpMaximumComponentLength,
|
---|
218 | PDWORD, lpFileSystemFlags,
|
---|
219 | LPSTR, lpFileSystemNameBuffer,
|
---|
220 | DWORD, nFileSystemNameSize)
|
---|
221 | {
|
---|
222 | dprintf(("GetVolumeInformationA %s", lpRootPathName));
|
---|
223 | return O32_GetVolumeInformation(lpRootPathName,
|
---|
224 | lpVolumeNameBuffer,
|
---|
225 | nVolumeNameSize,
|
---|
226 | lpVolumeSerialNumber,
|
---|
227 | lpMaximumComponentLength,
|
---|
228 | lpFileSystemFlags,
|
---|
229 | lpFileSystemNameBuffer,
|
---|
230 | nFileSystemNameSize);
|
---|
231 | }
|
---|
232 | //******************************************************************************
|
---|
233 | //******************************************************************************
|
---|
234 |
|
---|
235 | ODINFUNCTION8(BOOL, GetVolumeInformationW,
|
---|
236 | LPCWSTR, lpRootPathName,
|
---|
237 | LPWSTR, lpVolumeNameBuffer,
|
---|
238 | DWORD, nVolumeNameSize,
|
---|
239 | PDWORD, lpVolumeSerialNumber,
|
---|
240 | PDWORD, lpMaximumComponentLength,
|
---|
241 | PDWORD, lpFileSystemFlags,
|
---|
242 | LPWSTR, lpFileSystemNameBuffer,
|
---|
243 | DWORD, nFileSystemNameSize)
|
---|
244 | {
|
---|
245 | char *asciiroot,
|
---|
246 | *asciivol,
|
---|
247 | *asciifs;
|
---|
248 | BOOL rc;
|
---|
249 |
|
---|
250 | // transform into ascii
|
---|
251 | asciivol = (char *)malloc(nVolumeNameSize+1);
|
---|
252 | asciifs = (char *)malloc(nFileSystemNameSize+1);
|
---|
253 |
|
---|
254 | // clear ascii buffers
|
---|
255 | memset (asciivol, 0, (nVolumeNameSize + 1));
|
---|
256 | memset (asciifs, 0, (nFileSystemNameSize + 1));
|
---|
257 |
|
---|
258 | if (lpRootPathName != NULL) // NULL is valid!
|
---|
259 | asciiroot = UnicodeToAsciiString((LPWSTR)lpRootPathName);
|
---|
260 | else
|
---|
261 | asciiroot = NULL;
|
---|
262 |
|
---|
263 | // @@@PH switch to ODIN_
|
---|
264 | rc = GetVolumeInformationA(asciiroot,
|
---|
265 | asciivol,
|
---|
266 | nVolumeNameSize,
|
---|
267 | lpVolumeSerialNumber,
|
---|
268 | lpMaximumComponentLength,
|
---|
269 | lpFileSystemFlags,
|
---|
270 | asciifs,
|
---|
271 | nFileSystemNameSize);
|
---|
272 |
|
---|
273 | if (lpVolumeNameBuffer != NULL) /* @@@PH 98/06/07 */
|
---|
274 | AsciiToUnicodeN(asciivol, lpVolumeNameBuffer, nVolumeNameSize);
|
---|
275 |
|
---|
276 | if (lpFileSystemNameBuffer != NULL) /* @@@PH 98/06/07 */
|
---|
277 | AsciiToUnicodeN(asciifs, lpFileSystemNameBuffer, nFileSystemNameSize);
|
---|
278 |
|
---|
279 |
|
---|
280 | if (asciiroot != NULL)
|
---|
281 | FreeAsciiString(asciiroot);
|
---|
282 |
|
---|
283 | free(asciifs);
|
---|
284 | free(asciivol);
|
---|
285 | return(rc);
|
---|
286 | }
|
---|
287 | //******************************************************************************
|
---|
288 | //******************************************************************************
|
---|
289 | DWORD WIN32API GetLogicalDrives(void)
|
---|
290 | {
|
---|
291 | dprintf(("KERNEL32: GetLogicalDrives\n"));
|
---|
292 | return O32_GetLogicalDrives();
|
---|
293 | }
|
---|
294 | //******************************************************************************
|
---|
295 | //******************************************************************************
|
---|
296 | UINT WIN32API GetLogicalDriveStringsA(UINT arg1, LPSTR arg2)
|
---|
297 | {
|
---|
298 | dprintf(("KERNEL32: OS2GetLogicalDriveStringsA\n"));
|
---|
299 | return O32_GetLogicalDriveStrings(arg1, arg2);
|
---|
300 | }
|
---|
301 | //******************************************************************************
|
---|
302 | //******************************************************************************
|
---|
303 | UINT WIN32API GetLogicalDriveStringsW(UINT nBufferLength, LPWSTR lpBuffer)
|
---|
304 | {
|
---|
305 | char *asciibuffer = (char *)malloc(nBufferLength+1);
|
---|
306 | DWORD rc;
|
---|
307 |
|
---|
308 | dprintf(("KERNEL32: OS2GetLogicalDriveStringsW\n"));
|
---|
309 |
|
---|
310 | rc = O32_GetLogicalDriveStrings(nBufferLength, asciibuffer);
|
---|
311 | if(rc) AsciiToUnicode(asciibuffer, lpBuffer);
|
---|
312 | free(asciibuffer);
|
---|
313 | return(rc);
|
---|
314 | }
|
---|