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

Last change on this file since 4171 was 4171, checked in by sandervl, 25 years ago

more logging + DeviceIoControl handlemanager wrapper added

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