1 | /* $Id: disk.cpp,v 1.16 2000-09-04 18:24:42 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 | #include "oslibdos.h"
|
---|
23 | #include "exceptutil.h"
|
---|
24 |
|
---|
25 | #define DBG_LOCALLOG DBG_disk
|
---|
26 | #include "dbglocal.h"
|
---|
27 |
|
---|
28 |
|
---|
29 | ODINDEBUGCHANNEL(KERNEL32-DISK)
|
---|
30 |
|
---|
31 | //******************************************************************************
|
---|
32 | //******************************************************************************
|
---|
33 | BOOL WIN32API SetVolumeLabelA( LPCSTR arg1, LPCSTR arg2)
|
---|
34 | {
|
---|
35 | dprintf(("KERNEL32: OS2SetVolumeLabelA\n"));
|
---|
36 | return O32_SetVolumeLabel(arg1, arg2);
|
---|
37 | }
|
---|
38 | //******************************************************************************
|
---|
39 | //******************************************************************************
|
---|
40 | BOOL WIN32API SetVolumeLabelW(LPCWSTR lpRootPathName, LPCWSTR lpVolumeName)
|
---|
41 | {
|
---|
42 | char *asciiroot, *asciivolname;
|
---|
43 | BOOL rc;
|
---|
44 |
|
---|
45 | dprintf(("KERNEL32: OS2SetVolumeLabelW\n"));
|
---|
46 | asciiroot = UnicodeToAsciiString((LPWSTR)lpRootPathName);
|
---|
47 | asciivolname = UnicodeToAsciiString((LPWSTR)lpVolumeName);
|
---|
48 | rc = O32_SetVolumeLabel(asciiroot, asciivolname);
|
---|
49 | FreeAsciiString(asciivolname);
|
---|
50 | FreeAsciiString(asciiroot);
|
---|
51 | return(rc);
|
---|
52 | }
|
---|
53 |
|
---|
54 | //******************************************************************************
|
---|
55 | //SvL: 24-6-'97 - Added
|
---|
56 | //******************************************************************************
|
---|
57 | BOOL WIN32API GetDiskFreeSpaceA( LPCSTR arg1, PDWORD arg2, PDWORD arg3, PDWORD arg4, PDWORD arg5)
|
---|
58 | {
|
---|
59 | BOOL rc;
|
---|
60 | DWORD dwSectorsPerCluster; // address of sectors per cluster ter
|
---|
61 | DWORD dwBytesPerSector; // address of bytes per sector
|
---|
62 | DWORD dwNumberOfFreeClusters; // address of number of free clusters
|
---|
63 | DWORD dwTotalNumberOfClusters; // address of total number of clusters
|
---|
64 | dprintf(("KERNEL32: GetDiskFreeSpaceA %s, 0x%08X, 0x%08X, 0x%08X, 0x%08X,\n",
|
---|
65 | arg1!=NULL?arg1:"NULL", arg2,arg3,arg4,arg5));
|
---|
66 |
|
---|
67 | rc = OSLibGetDiskFreeSpace((LPSTR)arg1, &dwSectorsPerCluster, &dwBytesPerSector,
|
---|
68 | &dwNumberOfFreeClusters, &dwTotalNumberOfClusters);
|
---|
69 | if(rc)
|
---|
70 | {
|
---|
71 | if (arg2!=NULL)
|
---|
72 | *arg2 = dwSectorsPerCluster;
|
---|
73 | if (arg3!=NULL)
|
---|
74 | *arg3 = dwBytesPerSector;
|
---|
75 | if (arg4!=NULL)
|
---|
76 | *arg4 = dwNumberOfFreeClusters;
|
---|
77 | if (arg5!=NULL)
|
---|
78 | *arg5 = dwTotalNumberOfClusters;
|
---|
79 | }
|
---|
80 | dprintf((" returned %d\n",rc));
|
---|
81 | return rc;
|
---|
82 | }
|
---|
83 | //******************************************************************************
|
---|
84 | //******************************************************************************
|
---|
85 | BOOL WIN32API GetDiskFreeSpaceW(LPCWSTR arg1, PDWORD arg2, PDWORD arg3, PDWORD arg4, PDWORD arg5)
|
---|
86 | {
|
---|
87 | BOOL rc;
|
---|
88 | char *astring;
|
---|
89 |
|
---|
90 | dprintf(("KERNEL32: OS2GetDiskFreeSpaceW\n"));
|
---|
91 | astring = UnicodeToAsciiString((LPWSTR)arg1);
|
---|
92 | rc = GetDiskFreeSpaceA(astring, arg2, arg3, arg4, arg5);
|
---|
93 | FreeAsciiString(astring);
|
---|
94 | return(rc);
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | /*****************************************************************************
|
---|
99 | * Name : GetDiskFreeSpaceEx
|
---|
100 | * Purpose :
|
---|
101 | * Parameters: lpDirectoryName [in] Pointer to a null-terminated string that
|
---|
102 | * specifies a directory on the disk of interest.
|
---|
103 | * This string can be a UNC name. If this
|
---|
104 | * parameter is a UNC name, you must follow it
|
---|
105 | * with an additional backslash. For example, you
|
---|
106 | * would specify \\MyServer\MyShare as
|
---|
107 | * \\MyServer\MyShare\.
|
---|
108 | * If lpDirectoryName is NULL, the
|
---|
109 | * GetDiskFreeSpaceEx function obtains
|
---|
110 | * information about the object store.
|
---|
111 | * Note that lpDirectoryName does not have to
|
---|
112 | * specify the root directory on a disk. The
|
---|
113 | * function accepts any directory on the disk.
|
---|
114 | *
|
---|
115 | * lpFreeBytesAvailableToCaller
|
---|
116 | * [out] Pointer to a variable to receive the
|
---|
117 | * total number of free bytes on the disk that
|
---|
118 | * are available to the user associated with the
|
---|
119 | * calling thread.
|
---|
120 | * lpTotalNumberOfBytes
|
---|
121 | * [out] Pointer to a variable to receive the
|
---|
122 | * total number of bytes on the disk that are
|
---|
123 | * available to the user associated with the
|
---|
124 | * calling thread.
|
---|
125 | * lpTotalNumberOfFreeBytes
|
---|
126 | * [out] Pointer to a variable to receive the
|
---|
127 | * total number of free bytes on the disk.
|
---|
128 | * This parameter can be NULL.
|
---|
129 | * Variables :
|
---|
130 | * Result : Nonzero indicates success. Zero indicates failure. To get
|
---|
131 | * extended error information, call GetLastError.
|
---|
132 | * Remark : Note that the values obtained by this function are of type
|
---|
133 | * ULARGE_INTEGER. Be careful not to truncate these values to
|
---|
134 | * 32 bits.
|
---|
135 | * Status :
|
---|
136 | *
|
---|
137 | * Author : Patrick Haller [Fri, 2000/01/08 23:44]
|
---|
138 | *****************************************************************************/
|
---|
139 |
|
---|
140 | ODINFUNCTION4(BOOL,GetDiskFreeSpaceExA,
|
---|
141 | LPCSTR, lpDirectoryName,
|
---|
142 | PULARGE_INTEGER, lpFreeBytesAvailableToCaller,
|
---|
143 | PULARGE_INTEGER, lpTotalNumberOfBytes,
|
---|
144 | PULARGE_INTEGER, lpTotalNumberOfFreeBytes )
|
---|
145 | {
|
---|
146 | BOOL rc;
|
---|
147 | DWORD dwSectorsPerCluster; // address of sectors per cluster ter
|
---|
148 | DWORD dwBytesPerSector; // address of bytes per sector
|
---|
149 | DWORD dwNumberOfFreeClusters; // address of number of free clusters
|
---|
150 | DWORD dwTotalNumberOfClusters; // address of total number of clusters
|
---|
151 |
|
---|
152 | rc = GetDiskFreeSpaceA(lpDirectoryName, &dwSectorsPerCluster, &dwBytesPerSector,
|
---|
153 | &dwNumberOfFreeClusters, &dwTotalNumberOfClusters);
|
---|
154 | if(rc)
|
---|
155 | {
|
---|
156 | if(lpFreeBytesAvailableToCaller!=NULL) {
|
---|
157 | Mul32x32to64(lpFreeBytesAvailableToCaller, dwNumberOfFreeClusters, (dwSectorsPerCluster*dwBytesPerSector));
|
---|
158 | dprintf(("lpFreeBytesAvailableToCaller %x%x", lpFreeBytesAvailableToCaller->LowPart, lpFreeBytesAvailableToCaller->HighPart));
|
---|
159 | }
|
---|
160 | if(lpTotalNumberOfBytes!=NULL) {
|
---|
161 | Mul32x32to64(lpTotalNumberOfBytes, dwTotalNumberOfClusters, (dwSectorsPerCluster*dwBytesPerSector));
|
---|
162 | dprintf(("lpTotalNumberOfBytes %x%x", lpTotalNumberOfBytes->LowPart, lpTotalNumberOfBytes->HighPart));
|
---|
163 | }
|
---|
164 | if(lpTotalNumberOfFreeBytes!=NULL) {
|
---|
165 | memcpy(lpTotalNumberOfFreeBytes, lpFreeBytesAvailableToCaller, sizeof(*lpFreeBytesAvailableToCaller));
|
---|
166 | dprintf(("lpTotalNumberOfFreeBytes %x%x", lpTotalNumberOfFreeBytes->LowPart, lpTotalNumberOfFreeBytes->HighPart));
|
---|
167 | }
|
---|
168 | }
|
---|
169 | return rc;
|
---|
170 | }
|
---|
171 |
|
---|
172 |
|
---|
173 | ODINFUNCTION4(BOOL,GetDiskFreeSpaceExW,
|
---|
174 | LPCWSTR, lpDirectoryName,
|
---|
175 | PULARGE_INTEGER, lpFreeBytesAvailableToCaller,
|
---|
176 | PULARGE_INTEGER, lpTotalNumberOfBytes,
|
---|
177 | PULARGE_INTEGER, lpTotalNumberOfFreeBytes )
|
---|
178 | {
|
---|
179 | BOOL rc;
|
---|
180 | char *astring;
|
---|
181 |
|
---|
182 | dprintf(("KERNEL32: OS2GetDiskFreeSpaceExW\n"));
|
---|
183 | astring = UnicodeToAsciiString((LPWSTR)lpDirectoryName);
|
---|
184 | rc = GetDiskFreeSpaceExA(astring, lpFreeBytesAvailableToCaller, lpTotalNumberOfBytes, lpTotalNumberOfFreeBytes);
|
---|
185 | FreeAsciiString(astring);
|
---|
186 | return(rc);
|
---|
187 | }
|
---|
188 |
|
---|
189 |
|
---|
190 | //******************************************************************************
|
---|
191 | //******************************************************************************
|
---|
192 | UINT WIN32API GetDriveTypeA( LPCSTR arg1)
|
---|
193 | {
|
---|
194 | UINT rc;
|
---|
195 | rc = O32_GetDriveType(arg1);
|
---|
196 | dprintf(("KERNEL32: GetDriveType %s = %d\n", arg1,rc));
|
---|
197 | return rc;
|
---|
198 | }
|
---|
199 | //******************************************************************************
|
---|
200 | //******************************************************************************
|
---|
201 | UINT WIN32API GetDriveTypeW(LPCWSTR arg1)
|
---|
202 | {
|
---|
203 | UINT rc;
|
---|
204 | char *astring;
|
---|
205 |
|
---|
206 | astring = UnicodeToAsciiString((LPWSTR)arg1);
|
---|
207 | dprintf(("KERNEL32: OS2GetDriveTypeW %s", astring));
|
---|
208 | rc = O32_GetDriveType(astring);
|
---|
209 | FreeAsciiString(astring);
|
---|
210 | return(rc);
|
---|
211 | }
|
---|
212 | //******************************************************************************
|
---|
213 | //******************************************************************************
|
---|
214 | ODINFUNCTION8(BOOL, GetVolumeInformationA,
|
---|
215 | LPCSTR, lpRootPathName,
|
---|
216 | LPSTR, lpVolumeNameBuffer,
|
---|
217 | DWORD, nVolumeNameSize,
|
---|
218 | PDWORD, lpVolumeSerialNumber,
|
---|
219 | PDWORD, lpMaximumComponentLength,
|
---|
220 | PDWORD, lpFileSystemFlags,
|
---|
221 | LPSTR, lpFileSystemNameBuffer,
|
---|
222 | DWORD, nFileSystemNameSize)
|
---|
223 | {
|
---|
224 | CHAR tmpstring[256];
|
---|
225 | ULONG drive;
|
---|
226 | BOOL rc;
|
---|
227 |
|
---|
228 | dprintf(("GetVolumeInformationA %s", lpRootPathName));
|
---|
229 |
|
---|
230 | if(lpRootPathName == NULL) {
|
---|
231 | GetCurrentDirectoryA(sizeof(tmpstring), tmpstring);
|
---|
232 | lpRootPathName = tmpstring;
|
---|
233 | }
|
---|
234 |
|
---|
235 | if('A' <= *lpRootPathName && *lpRootPathName <= 'Z') {
|
---|
236 | drive = *lpRootPathName - 'A' + 1;
|
---|
237 | }
|
---|
238 | else
|
---|
239 | if('a' <= *lpRootPathName && *lpRootPathName <= 'z') {
|
---|
240 | drive = *lpRootPathName - 'a' + 1;
|
---|
241 | }
|
---|
242 | else {
|
---|
243 | SetLastError(ERROR_INVALID_PARAMETER);
|
---|
244 | return FALSE;
|
---|
245 | }
|
---|
246 |
|
---|
247 | if(lpVolumeSerialNumber || lpVolumeNameBuffer) {
|
---|
248 | rc = OSLibDosQueryVolumeSerialAndName(drive, lpVolumeSerialNumber, lpVolumeNameBuffer, nVolumeNameSize);
|
---|
249 | if(lpVolumeSerialNumber) {
|
---|
250 | dprintf2(("Volume serial number: %x", *lpVolumeSerialNumber));
|
---|
251 | }
|
---|
252 | if(lpVolumeNameBuffer) {
|
---|
253 | dprintf2(("Volume name: %s", lpVolumeNameBuffer));
|
---|
254 | }
|
---|
255 | }
|
---|
256 | if(lpFileSystemNameBuffer || lpMaximumComponentLength) {
|
---|
257 | if(!lpFileSystemNameBuffer) {
|
---|
258 | lpFileSystemNameBuffer = tmpstring;
|
---|
259 | nFileSystemNameSize = sizeof(tmpstring);
|
---|
260 | }
|
---|
261 | rc = OSLibDosQueryVolumeFS(drive, lpFileSystemNameBuffer, nFileSystemNameSize);
|
---|
262 | if(lpFileSystemNameBuffer) {
|
---|
263 | dprintf2(("File system name: %s", lpFileSystemNameBuffer));
|
---|
264 | }
|
---|
265 | }
|
---|
266 | if(lpMaximumComponentLength) {
|
---|
267 | if(!strcmp(lpFileSystemNameBuffer, "FAT")) {
|
---|
268 | *lpMaximumComponentLength = 12;
|
---|
269 | }
|
---|
270 | else *lpMaximumComponentLength = 255; //TODO: Always correct? (CDFS?)
|
---|
271 | }
|
---|
272 | if(lpFileSystemFlags) {
|
---|
273 | if(strcmp(lpFileSystemNameBuffer, "FAT")) {
|
---|
274 | *lpFileSystemFlags = FS_CASE_IS_PRESERVED;
|
---|
275 | }
|
---|
276 | else
|
---|
277 | if(!strcmp(lpFileSystemNameBuffer, "CDFS")) {
|
---|
278 | *lpFileSystemFlags = FS_CASE_SENSITIVE; //NT4 returns this
|
---|
279 | }
|
---|
280 | else
|
---|
281 | if(!strcmp(lpFileSystemNameBuffer, "UDF")) {//TODO: correct?
|
---|
282 | *lpFileSystemFlags = FS_CASE_SENSITIVE | FS_UNICODE_STORED_ON_DISK;
|
---|
283 | }
|
---|
284 | else *lpFileSystemFlags = 0;
|
---|
285 |
|
---|
286 | dprintf2(("File system flags: %x", lpFileSystemFlags));
|
---|
287 | }
|
---|
288 |
|
---|
289 | if(rc) {
|
---|
290 | SetLastError(rc);
|
---|
291 | return FALSE;
|
---|
292 | }
|
---|
293 | SetLastError(ERROR_SUCCESS);
|
---|
294 | return TRUE;
|
---|
295 | }
|
---|
296 | //******************************************************************************
|
---|
297 | //******************************************************************************
|
---|
298 | ODINFUNCTION8(BOOL, GetVolumeInformationW,
|
---|
299 | LPCWSTR, lpRootPathName,
|
---|
300 | LPWSTR, lpVolumeNameBuffer,
|
---|
301 | DWORD, nVolumeNameSize,
|
---|
302 | PDWORD, lpVolumeSerialNumber,
|
---|
303 | PDWORD, lpMaximumComponentLength,
|
---|
304 | PDWORD, lpFileSystemFlags,
|
---|
305 | LPWSTR, lpFileSystemNameBuffer,
|
---|
306 | DWORD, nFileSystemNameSize)
|
---|
307 | {
|
---|
308 | char *asciiroot,
|
---|
309 | *asciivol,
|
---|
310 | *asciifs;
|
---|
311 | BOOL rc;
|
---|
312 |
|
---|
313 | // transform into ascii
|
---|
314 | asciivol = (char *)malloc(nVolumeNameSize+1);
|
---|
315 | asciifs = (char *)malloc(nFileSystemNameSize+1);
|
---|
316 |
|
---|
317 | // clear ascii buffers
|
---|
318 | memset (asciivol, 0, (nVolumeNameSize + 1));
|
---|
319 | memset (asciifs, 0, (nFileSystemNameSize + 1));
|
---|
320 |
|
---|
321 | if (lpRootPathName != NULL) // NULL is valid!
|
---|
322 | asciiroot = UnicodeToAsciiString((LPWSTR)lpRootPathName);
|
---|
323 | else
|
---|
324 | asciiroot = NULL;
|
---|
325 |
|
---|
326 | rc = ODIN_GetVolumeInformationA(asciiroot,
|
---|
327 | asciivol,
|
---|
328 | nVolumeNameSize,
|
---|
329 | lpVolumeSerialNumber,
|
---|
330 | lpMaximumComponentLength,
|
---|
331 | lpFileSystemFlags,
|
---|
332 | asciifs,
|
---|
333 | nFileSystemNameSize);
|
---|
334 |
|
---|
335 | if (lpVolumeNameBuffer != NULL) /* @@@PH 98/06/07 */
|
---|
336 | AsciiToUnicodeN(asciivol, lpVolumeNameBuffer, nVolumeNameSize);
|
---|
337 |
|
---|
338 | if (lpFileSystemNameBuffer != NULL) /* @@@PH 98/06/07 */
|
---|
339 | AsciiToUnicodeN(asciifs, lpFileSystemNameBuffer, nFileSystemNameSize);
|
---|
340 |
|
---|
341 |
|
---|
342 | if (asciiroot != NULL)
|
---|
343 | FreeAsciiString(asciiroot);
|
---|
344 |
|
---|
345 | free(asciifs);
|
---|
346 | free(asciivol);
|
---|
347 | return(rc);
|
---|
348 | }
|
---|
349 | //******************************************************************************
|
---|
350 | //******************************************************************************
|
---|
351 | DWORD WIN32API GetLogicalDrives(void)
|
---|
352 | {
|
---|
353 | dprintf(("KERNEL32: GetLogicalDrives\n"));
|
---|
354 | return O32_GetLogicalDrives();
|
---|
355 | }
|
---|
356 | //******************************************************************************
|
---|
357 | //******************************************************************************
|
---|
358 | UINT WIN32API GetLogicalDriveStringsA(UINT arg1, LPSTR arg2)
|
---|
359 | {
|
---|
360 | dprintf(("KERNEL32: OS2GetLogicalDriveStringsA\n"));
|
---|
361 | return O32_GetLogicalDriveStrings(arg1, arg2);
|
---|
362 | }
|
---|
363 | //******************************************************************************
|
---|
364 | //******************************************************************************
|
---|
365 | UINT WIN32API GetLogicalDriveStringsW(UINT nBufferLength, LPWSTR lpBuffer)
|
---|
366 | {
|
---|
367 | char *asciibuffer = (char *)malloc(nBufferLength+1);
|
---|
368 | DWORD rc;
|
---|
369 |
|
---|
370 | dprintf(("KERNEL32: OS2GetLogicalDriveStringsW\n"));
|
---|
371 |
|
---|
372 | rc = O32_GetLogicalDriveStrings(nBufferLength, asciibuffer);
|
---|
373 | if(rc) AsciiToUnicode(asciibuffer, lpBuffer);
|
---|
374 | free(asciibuffer);
|
---|
375 | return(rc);
|
---|
376 | }
|
---|