source: trunk/src/kernel32/disk.cpp@ 4694

Last change on this file since 4694 was 4694, checked in by phaller, 25 years ago

debug info added

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