| 1 | /* $Id: disk.cpp,v 1.14 2000-08-17 18:22:18 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 |
|
|---|
| 28 | ODINDEBUGCHANNEL(KERNEL32-DISK)
|
|---|
| 29 |
|
|---|
| 30 | //******************************************************************************
|
|---|
| 31 | //******************************************************************************
|
|---|
| 32 | BOOL WIN32API SetVolumeLabelA( LPCSTR arg1, LPCSTR arg2)
|
|---|
| 33 | {
|
|---|
| 34 | dprintf(("KERNEL32: OS2SetVolumeLabelA\n"));
|
|---|
| 35 | return O32_SetVolumeLabel(arg1, arg2);
|
|---|
| 36 | }
|
|---|
| 37 | //******************************************************************************
|
|---|
| 38 | //******************************************************************************
|
|---|
| 39 | BOOL 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 | //******************************************************************************
|
|---|
| 56 | BOOL 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 | //******************************************************************************
|
|---|
| 83 | BOOL 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 |
|
|---|
| 138 | ODINFUNCTION4(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 |
|
|---|
| 172 | ODINFUNCTION4(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 | //******************************************************************************
|
|---|
| 191 | UINT 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 | //******************************************************************************
|
|---|
| 200 | UINT 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 | //******************************************************************************
|
|---|
| 213 | ODINFUNCTION8(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 | }
|
|---|
| 249 | if(lpFileSystemNameBuffer || lpMaximumComponentLength) {
|
|---|
| 250 | if(!lpFileSystemNameBuffer) {
|
|---|
| 251 | lpFileSystemNameBuffer = tmpstring;
|
|---|
| 252 | nFileSystemNameSize = sizeof(tmpstring);
|
|---|
| 253 | }
|
|---|
| 254 | rc = OSLibDosQueryVolumeFS(drive, lpFileSystemNameBuffer, nFileSystemNameSize);
|
|---|
| 255 | }
|
|---|
| 256 | if(lpMaximumComponentLength) {
|
|---|
| 257 | if(!strcmp(lpFileSystemNameBuffer, "FAT")) {
|
|---|
| 258 | *lpMaximumComponentLength = 12;
|
|---|
| 259 | }
|
|---|
| 260 | else *lpMaximumComponentLength = 255; //TODO: Always correct? (CDFS?)
|
|---|
| 261 | }
|
|---|
| 262 | if(lpFileSystemFlags) {
|
|---|
| 263 | if(strcmp(lpFileSystemNameBuffer, "FAT")) {
|
|---|
| 264 | *lpFileSystemFlags = FS_CASE_IS_PRESERVED;
|
|---|
| 265 | }
|
|---|
| 266 | else
|
|---|
| 267 | if(!strcmp(lpFileSystemNameBuffer, "CDFS")) {
|
|---|
| 268 | *lpFileSystemFlags = FS_CASE_SENSITIVE; //NT4 returns this
|
|---|
| 269 | }
|
|---|
| 270 | else
|
|---|
| 271 | if(!strcmp(lpFileSystemNameBuffer, "UDF")) {//TODO: correct?
|
|---|
| 272 | *lpFileSystemFlags = FS_CASE_SENSITIVE | FS_UNICODE_STORED_ON_DISK;
|
|---|
| 273 | }
|
|---|
| 274 | else *lpFileSystemFlags = 0;
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | if(rc) {
|
|---|
| 278 | SetLastError(rc);
|
|---|
| 279 | return FALSE;
|
|---|
| 280 | }
|
|---|
| 281 | SetLastError(ERROR_SUCCESS);
|
|---|
| 282 | return TRUE;
|
|---|
| 283 | }
|
|---|
| 284 | //******************************************************************************
|
|---|
| 285 | //******************************************************************************
|
|---|
| 286 | ODINFUNCTION8(BOOL, GetVolumeInformationW,
|
|---|
| 287 | LPCWSTR, lpRootPathName,
|
|---|
| 288 | LPWSTR, lpVolumeNameBuffer,
|
|---|
| 289 | DWORD, nVolumeNameSize,
|
|---|
| 290 | PDWORD, lpVolumeSerialNumber,
|
|---|
| 291 | PDWORD, lpMaximumComponentLength,
|
|---|
| 292 | PDWORD, lpFileSystemFlags,
|
|---|
| 293 | LPWSTR, lpFileSystemNameBuffer,
|
|---|
| 294 | DWORD, nFileSystemNameSize)
|
|---|
| 295 | {
|
|---|
| 296 | char *asciiroot,
|
|---|
| 297 | *asciivol,
|
|---|
| 298 | *asciifs;
|
|---|
| 299 | BOOL rc;
|
|---|
| 300 |
|
|---|
| 301 | // transform into ascii
|
|---|
| 302 | asciivol = (char *)malloc(nVolumeNameSize+1);
|
|---|
| 303 | asciifs = (char *)malloc(nFileSystemNameSize+1);
|
|---|
| 304 |
|
|---|
| 305 | // clear ascii buffers
|
|---|
| 306 | memset (asciivol, 0, (nVolumeNameSize + 1));
|
|---|
| 307 | memset (asciifs, 0, (nFileSystemNameSize + 1));
|
|---|
| 308 |
|
|---|
| 309 | if (lpRootPathName != NULL) // NULL is valid!
|
|---|
| 310 | asciiroot = UnicodeToAsciiString((LPWSTR)lpRootPathName);
|
|---|
| 311 | else
|
|---|
| 312 | asciiroot = NULL;
|
|---|
| 313 |
|
|---|
| 314 | rc = ODIN_GetVolumeInformationA(asciiroot,
|
|---|
| 315 | asciivol,
|
|---|
| 316 | nVolumeNameSize,
|
|---|
| 317 | lpVolumeSerialNumber,
|
|---|
| 318 | lpMaximumComponentLength,
|
|---|
| 319 | lpFileSystemFlags,
|
|---|
| 320 | asciifs,
|
|---|
| 321 | nFileSystemNameSize);
|
|---|
| 322 |
|
|---|
| 323 | if (lpVolumeNameBuffer != NULL) /* @@@PH 98/06/07 */
|
|---|
| 324 | AsciiToUnicodeN(asciivol, lpVolumeNameBuffer, nVolumeNameSize);
|
|---|
| 325 |
|
|---|
| 326 | if (lpFileSystemNameBuffer != NULL) /* @@@PH 98/06/07 */
|
|---|
| 327 | AsciiToUnicodeN(asciifs, lpFileSystemNameBuffer, nFileSystemNameSize);
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 | if (asciiroot != NULL)
|
|---|
| 331 | FreeAsciiString(asciiroot);
|
|---|
| 332 |
|
|---|
| 333 | free(asciifs);
|
|---|
| 334 | free(asciivol);
|
|---|
| 335 | return(rc);
|
|---|
| 336 | }
|
|---|
| 337 | //******************************************************************************
|
|---|
| 338 | //******************************************************************************
|
|---|
| 339 | DWORD WIN32API GetLogicalDrives(void)
|
|---|
| 340 | {
|
|---|
| 341 | dprintf(("KERNEL32: GetLogicalDrives\n"));
|
|---|
| 342 | return O32_GetLogicalDrives();
|
|---|
| 343 | }
|
|---|
| 344 | //******************************************************************************
|
|---|
| 345 | //******************************************************************************
|
|---|
| 346 | UINT WIN32API GetLogicalDriveStringsA(UINT arg1, LPSTR arg2)
|
|---|
| 347 | {
|
|---|
| 348 | dprintf(("KERNEL32: OS2GetLogicalDriveStringsA\n"));
|
|---|
| 349 | return O32_GetLogicalDriveStrings(arg1, arg2);
|
|---|
| 350 | }
|
|---|
| 351 | //******************************************************************************
|
|---|
| 352 | //******************************************************************************
|
|---|
| 353 | UINT WIN32API GetLogicalDriveStringsW(UINT nBufferLength, LPWSTR lpBuffer)
|
|---|
| 354 | {
|
|---|
| 355 | char *asciibuffer = (char *)malloc(nBufferLength+1);
|
|---|
| 356 | DWORD rc;
|
|---|
| 357 |
|
|---|
| 358 | dprintf(("KERNEL32: OS2GetLogicalDriveStringsW\n"));
|
|---|
| 359 |
|
|---|
| 360 | rc = O32_GetLogicalDriveStrings(nBufferLength, asciibuffer);
|
|---|
| 361 | if(rc) AsciiToUnicode(asciibuffer, lpBuffer);
|
|---|
| 362 | free(asciibuffer);
|
|---|
| 363 | return(rc);
|
|---|
| 364 | }
|
|---|