push 0f15bbd80d260bbd8adf052e820484a405c49375
[wine/hacks.git] / dlls / kernel32 / volume.c
blob655fda15411129cbd0f4758fe6886fa7557c81d3
1 /*
2 * Volume management functions
4 * Copyright 1993 Erik Bos
5 * Copyright 1996, 2004 Alexandre Julliard
6 * Copyright 1999 Petr Tomasek
7 * Copyright 2000 Andreas Mohr
8 * Copyright 2003 Eric Pouech
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
25 #include "config.h"
26 #include "wine/port.h"
28 #include <stdarg.h>
29 #include <stdlib.h>
30 #include <stdio.h>
32 #include "ntstatus.h"
33 #define WIN32_NO_STATUS
34 #include "windef.h"
35 #include "winbase.h"
36 #include "winnls.h"
37 #include "winternl.h"
38 #include "winioctl.h"
39 #include "ntddcdrm.h"
40 #include "kernel_private.h"
41 #include "wine/library.h"
42 #include "wine/unicode.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(volume);
47 #define SUPERBLOCK_SIZE 2048
49 #define CDFRAMES_PERSEC 75
50 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
51 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
52 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc)->TrackData[(idx) - (toc)->FirstTrack].Address)
54 #define GETWORD(buf,off) MAKEWORD(buf[(off)],buf[(off+1)])
55 #define GETLONG(buf,off) MAKELONG(GETWORD(buf,off),GETWORD(buf,off+2))
57 enum fs_type
59 FS_ERROR, /* error accessing the device */
60 FS_UNKNOWN, /* unknown file system */
61 FS_PLACEHOLDER, /* Wine placeholder for drive device */
62 FS_FAT1216,
63 FS_FAT32,
64 FS_ISO9660
67 static const char wine_placeholder[] = "Wine device placeholder";
69 static const WCHAR drive_types[][8] =
71 { 0 }, /* DRIVE_UNKNOWN */
72 { 0 }, /* DRIVE_NO_ROOT_DIR */
73 {'f','l','o','p','p','y',0}, /* DRIVE_REMOVABLE */
74 {'h','d',0}, /* DRIVE_FIXED */
75 {'n','e','t','w','o','r','k',0}, /* DRIVE_REMOTE */
76 {'c','d','r','o','m',0}, /* DRIVE_CDROM */
77 {'r','a','m','d','i','s','k',0} /* DRIVE_RAMDISK */
80 /* read a Unix symlink; returned buffer must be freed by caller */
81 static char *read_symlink( const char *path )
83 char *buffer;
84 int ret, size = 128;
86 for (;;)
88 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
90 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
91 return 0;
93 ret = readlink( path, buffer, size );
94 if (ret == -1)
96 FILE_SetDosError();
97 HeapFree( GetProcessHeap(), 0, buffer );
98 return 0;
100 if (ret != size)
102 buffer[ret] = 0;
103 return buffer;
105 HeapFree( GetProcessHeap(), 0, buffer );
106 size *= 2;
110 /* get the path of a dos device symlink in the $WINEPREFIX/dosdevices directory */
111 static char *get_dos_device_path( LPCWSTR name )
113 const char *config_dir = wine_get_config_dir();
114 char *buffer, *dev;
115 int i;
117 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
118 strlen(config_dir) + sizeof("/dosdevices/") + 5 )))
120 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
121 return NULL;
123 strcpy( buffer, config_dir );
124 strcat( buffer, "/dosdevices/" );
125 dev = buffer + strlen(buffer);
126 /* no codepage conversion, DOS device names are ASCII anyway */
127 for (i = 0; i < 5; i++)
128 if (!(dev[i] = (char)tolowerW(name[i]))) break;
129 dev[5] = 0;
130 return buffer;
134 /* open a handle to a device root */
135 static BOOL open_device_root( LPCWSTR root, HANDLE *handle )
137 static const WCHAR default_rootW[] = {'\\',0};
138 UNICODE_STRING nt_name;
139 OBJECT_ATTRIBUTES attr;
140 IO_STATUS_BLOCK io;
141 NTSTATUS status;
143 if (!root) root = default_rootW;
144 if (!RtlDosPathNameToNtPathName_U( root, &nt_name, NULL, NULL ))
146 SetLastError( ERROR_PATH_NOT_FOUND );
147 return FALSE;
149 attr.Length = sizeof(attr);
150 attr.RootDirectory = 0;
151 attr.Attributes = OBJ_CASE_INSENSITIVE;
152 attr.ObjectName = &nt_name;
153 attr.SecurityDescriptor = NULL;
154 attr.SecurityQualityOfService = NULL;
156 status = NtOpenFile( handle, 0, &attr, &io, 0,
157 FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
158 RtlFreeUnicodeString( &nt_name );
159 if (status != STATUS_SUCCESS)
161 SetLastError( RtlNtStatusToDosError(status) );
162 return FALSE;
164 return TRUE;
167 /* get the label by reading it from a file at the root of the filesystem */
168 static void get_filesystem_label( const WCHAR *device, WCHAR *label, DWORD len )
170 HANDLE handle;
171 WCHAR labelW[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','l','a','b','e','l',0};
173 labelW[0] = device[4];
174 handle = CreateFileW( labelW, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
175 OPEN_EXISTING, 0, 0 );
176 if (handle != INVALID_HANDLE_VALUE)
178 char buffer[256], *p;
179 DWORD size;
181 if (!ReadFile( handle, buffer, sizeof(buffer)-1, &size, NULL )) size = 0;
182 CloseHandle( handle );
183 p = buffer + size;
184 while (p > buffer && (p[-1] == ' ' || p[-1] == '\r' || p[-1] == '\n')) p--;
185 *p = 0;
186 if (!MultiByteToWideChar( CP_UNIXCP, 0, buffer, -1, label, len ))
187 label[len-1] = 0;
189 else label[0] = 0;
192 /* get the serial number by reading it from a file at the root of the filesystem */
193 static DWORD get_filesystem_serial( const WCHAR *device )
195 HANDLE handle;
196 WCHAR serialW[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','s','e','r','i','a','l',0};
198 serialW[0] = device[4];
199 handle = CreateFileW( serialW, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
200 OPEN_EXISTING, 0, 0 );
201 if (handle != INVALID_HANDLE_VALUE)
203 char buffer[32];
204 DWORD size;
206 if (!ReadFile( handle, buffer, sizeof(buffer)-1, &size, NULL )) size = 0;
207 CloseHandle( handle );
208 buffer[size] = 0;
209 return strtoul( buffer, NULL, 16 );
211 else return 0;
214 /* fetch the type of a drive from the registry */
215 static UINT get_registry_drive_type( const WCHAR *root )
217 static const WCHAR drive_types_keyW[] = {'M','a','c','h','i','n','e','\\',
218 'S','o','f','t','w','a','r','e','\\',
219 'W','i','n','e','\\',
220 'D','r','i','v','e','s',0 };
221 OBJECT_ATTRIBUTES attr;
222 UNICODE_STRING nameW;
223 HANDLE hkey;
224 DWORD dummy;
225 UINT ret = DRIVE_UNKNOWN;
226 char tmp[32 + sizeof(KEY_VALUE_PARTIAL_INFORMATION)];
227 WCHAR driveW[] = {'A',':',0};
229 attr.Length = sizeof(attr);
230 attr.RootDirectory = 0;
231 attr.ObjectName = &nameW;
232 attr.Attributes = 0;
233 attr.SecurityDescriptor = NULL;
234 attr.SecurityQualityOfService = NULL;
235 RtlInitUnicodeString( &nameW, drive_types_keyW );
236 /* @@ Wine registry key: HKLM\Software\Wine\Drives */
237 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS) return DRIVE_UNKNOWN;
239 if (root) driveW[0] = root[0];
240 else
242 WCHAR path[MAX_PATH];
243 GetCurrentDirectoryW( MAX_PATH, path );
244 driveW[0] = path[0];
247 RtlInitUnicodeString( &nameW, driveW );
248 if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
250 unsigned int i;
251 WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
253 for (i = 0; i < sizeof(drive_types)/sizeof(drive_types[0]); i++)
255 if (!strcmpiW( data, drive_types[i] ))
257 ret = i;
258 break;
262 NtClose( hkey );
263 return ret;
267 /******************************************************************
268 * VOLUME_FindCdRomDataBestVoldesc
270 static DWORD VOLUME_FindCdRomDataBestVoldesc( HANDLE handle )
272 BYTE cur_vd_type, max_vd_type = 0;
273 BYTE buffer[0x800];
274 DWORD size, offs, best_offs = 0, extra_offs = 0;
276 for (offs = 0x8000; offs <= 0x9800; offs += 0x800)
278 /* if 'CDROM' occurs at position 8, this is a pre-iso9660 cd, and
279 * the volume label is displaced forward by 8
281 if (SetFilePointer( handle, offs, NULL, FILE_BEGIN ) != offs) break;
282 if (!ReadFile( handle, buffer, sizeof(buffer), &size, NULL )) break;
283 if (size != sizeof(buffer)) break;
284 /* check for non-ISO9660 signature */
285 if (!memcmp( buffer + 11, "ROM", 3 )) extra_offs = 8;
286 cur_vd_type = buffer[extra_offs];
287 if (cur_vd_type == 0xff) /* voldesc set terminator */
288 break;
289 if (cur_vd_type > max_vd_type)
291 max_vd_type = cur_vd_type;
292 best_offs = offs + extra_offs;
295 return best_offs;
299 /***********************************************************************
300 * VOLUME_ReadFATSuperblock
302 static enum fs_type VOLUME_ReadFATSuperblock( HANDLE handle, BYTE *buff )
304 DWORD size;
306 /* try a fixed disk, with a FAT partition */
307 if (SetFilePointer( handle, 0, NULL, FILE_BEGIN ) != 0 ||
308 !ReadFile( handle, buff, SUPERBLOCK_SIZE, &size, NULL ))
309 return FS_ERROR;
311 if (size >= sizeof(wine_placeholder)-1 &&
312 !memcmp( buff, wine_placeholder, sizeof(wine_placeholder)-1 ))
313 return FS_PLACEHOLDER;
315 if (size != SUPERBLOCK_SIZE) return FS_ERROR;
317 /* FIXME: do really all FAT have their name beginning with
318 * "FAT" ? (At least FAT12, FAT16 and FAT32 have :)
320 if (!memcmp(buff+0x36, "FAT", 3) || !memcmp(buff+0x52, "FAT", 3))
322 /* guess which type of FAT we have */
323 int reasonable;
324 unsigned int sectors,
325 sect_per_fat,
326 total_sectors,
327 num_boot_sectors,
328 num_fats,
329 num_root_dir_ents,
330 bytes_per_sector,
331 sectors_per_cluster,
332 nclust;
333 sect_per_fat = GETWORD(buff, 0x16);
334 if (!sect_per_fat) sect_per_fat = GETLONG(buff, 0x24);
335 total_sectors = GETWORD(buff, 0x13);
336 if (!total_sectors)
337 total_sectors = GETLONG(buff, 0x20);
338 num_boot_sectors = GETWORD(buff, 0x0e);
339 num_fats = buff[0x10];
340 num_root_dir_ents = GETWORD(buff, 0x11);
341 bytes_per_sector = GETWORD(buff, 0x0b);
342 sectors_per_cluster = buff[0x0d];
343 /* check if the parameters are reasonable and will not cause
344 * arithmetic errors in the calculation */
345 reasonable = num_boot_sectors < 16 &&
346 num_fats < 16 &&
347 bytes_per_sector >= 512 && bytes_per_sector % 512 == 0 &&
348 sectors_per_cluster > 1;
349 if (!reasonable) return FS_UNKNOWN;
350 sectors = total_sectors - num_boot_sectors - num_fats * sect_per_fat -
351 (num_root_dir_ents * 32 + bytes_per_sector - 1) / bytes_per_sector;
352 nclust = sectors / sectors_per_cluster;
353 if ((buff[0x42] == 0x28 || buff[0x42] == 0x29) &&
354 !memcmp(buff+0x52, "FAT", 3)) return FS_FAT32;
355 if (nclust < 65525)
357 if ((buff[0x26] == 0x28 || buff[0x26] == 0x29) &&
358 !memcmp(buff+0x36, "FAT", 3))
359 return FS_FAT1216;
362 return FS_UNKNOWN;
366 /***********************************************************************
367 * VOLUME_ReadCDSuperblock
369 static enum fs_type VOLUME_ReadCDSuperblock( HANDLE handle, BYTE *buff )
371 DWORD size, offs = VOLUME_FindCdRomDataBestVoldesc( handle );
373 if (!offs) return FS_UNKNOWN;
375 if (SetFilePointer( handle, offs, NULL, FILE_BEGIN ) != offs ||
376 !ReadFile( handle, buff, SUPERBLOCK_SIZE, &size, NULL ) ||
377 size != SUPERBLOCK_SIZE)
378 return FS_ERROR;
380 /* check for iso9660 present */
381 if (!memcmp(&buff[1], "CD001", 5)) return FS_ISO9660;
382 return FS_UNKNOWN;
386 /**************************************************************************
387 * VOLUME_GetSuperblockLabel
389 static void VOLUME_GetSuperblockLabel( const WCHAR *device, enum fs_type type, const BYTE *superblock,
390 WCHAR *label, DWORD len )
392 const BYTE *label_ptr = NULL;
393 DWORD label_len;
395 switch(type)
397 case FS_ERROR:
398 case FS_UNKNOWN:
399 label_len = 0;
400 break;
401 case FS_PLACEHOLDER:
402 get_filesystem_label( device, label, len );
403 break;
404 case FS_FAT1216:
405 label_ptr = superblock + 0x2b;
406 label_len = 11;
407 break;
408 case FS_FAT32:
409 label_ptr = superblock + 0x47;
410 label_len = 11;
411 break;
412 case FS_ISO9660:
414 BYTE ver = superblock[0x5a];
416 if (superblock[0x58] == 0x25 && superblock[0x59] == 0x2f && /* Unicode ID */
417 ((ver == 0x40) || (ver == 0x43) || (ver == 0x45)))
418 { /* yippee, unicode */
419 unsigned int i;
421 if (len > 17) len = 17;
422 for (i = 0; i < len-1; i++)
423 label[i] = (superblock[40+2*i] << 8) | superblock[41+2*i];
424 label[i] = 0;
425 while (i && label[i-1] == ' ') label[--i] = 0;
426 return;
428 label_ptr = superblock + 40;
429 label_len = 32;
430 break;
433 if (label_len) RtlMultiByteToUnicodeN( label, (len-1) * sizeof(WCHAR),
434 &label_len, (LPCSTR)label_ptr, label_len );
435 label_len /= sizeof(WCHAR);
436 label[label_len] = 0;
437 while (label_len && label[label_len-1] == ' ') label[--label_len] = 0;
441 /**************************************************************************
442 * VOLUME_GetSuperblockSerial
444 static DWORD VOLUME_GetSuperblockSerial( const WCHAR *device, enum fs_type type, const BYTE *superblock )
446 switch(type)
448 case FS_ERROR:
449 case FS_UNKNOWN:
450 break;
451 case FS_PLACEHOLDER:
452 return get_filesystem_serial( device );
453 case FS_FAT1216:
454 return GETLONG( superblock, 0x27 );
455 case FS_FAT32:
456 return GETLONG( superblock, 0x33 );
457 case FS_ISO9660:
459 BYTE sum[4];
460 int i;
462 sum[0] = sum[1] = sum[2] = sum[3] = 0;
463 for (i = 0; i < 2048; i += 4)
465 /* DON'T optimize this into DWORD !! (breaks overflow) */
466 sum[0] += superblock[i+0];
467 sum[1] += superblock[i+1];
468 sum[2] += superblock[i+2];
469 sum[3] += superblock[i+3];
472 * OK, another braindead one... argh. Just believe it.
473 * Me$$ysoft chose to reverse the serial number in NT4/W2K.
474 * It's true and nobody will ever be able to change it.
476 if (GetVersion() & 0x80000000)
477 return (sum[3] << 24) | (sum[2] << 16) | (sum[1] << 8) | sum[0];
478 else
479 return (sum[0] << 24) | (sum[1] << 16) | (sum[2] << 8) | sum[3];
482 return 0;
486 /**************************************************************************
487 * VOLUME_GetAudioCDSerial
489 static DWORD VOLUME_GetAudioCDSerial( const CDROM_TOC *toc )
491 DWORD serial = 0;
492 int i;
494 for (i = 0; i <= toc->LastTrack - toc->FirstTrack; i++)
495 serial += ((toc->TrackData[i].Address[1] << 16) |
496 (toc->TrackData[i].Address[2] << 8) |
497 toc->TrackData[i].Address[3]);
500 * dwStart, dwEnd collect the beginning and end of the disc respectively, in
501 * frames.
502 * There it is collected for correcting the serial when there are less than
503 * 3 tracks.
505 if (toc->LastTrack - toc->FirstTrack + 1 < 3)
507 DWORD dwStart = FRAME_OF_TOC(toc, toc->FirstTrack);
508 DWORD dwEnd = FRAME_OF_TOC(toc, toc->LastTrack + 1);
509 serial += dwEnd - dwStart;
511 return serial;
515 /***********************************************************************
516 * GetVolumeInformationW (KERNEL32.@)
518 BOOL WINAPI GetVolumeInformationW( LPCWSTR root, LPWSTR label, DWORD label_len,
519 DWORD *serial, DWORD *filename_len, DWORD *flags,
520 LPWSTR fsname, DWORD fsname_len )
522 static const WCHAR audiocdW[] = {'A','u','d','i','o',' ','C','D',0};
523 static const WCHAR fatW[] = {'F','A','T',0};
524 static const WCHAR ntfsW[] = {'N','T','F','S',0};
525 static const WCHAR cdfsW[] = {'C','D','F','S',0};
527 WCHAR device[] = {'\\','\\','.','\\','A',':',0};
528 HANDLE handle;
529 enum fs_type type = FS_UNKNOWN;
531 if (!root)
533 WCHAR path[MAX_PATH];
534 GetCurrentDirectoryW( MAX_PATH, path );
535 device[4] = path[0];
537 else
539 if (!root[0] || root[1] != ':')
541 SetLastError( ERROR_INVALID_NAME );
542 return FALSE;
544 device[4] = root[0];
547 /* try to open the device */
549 handle = CreateFileW( device, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
550 NULL, OPEN_EXISTING, 0, 0 );
551 if (handle != INVALID_HANDLE_VALUE)
553 BYTE superblock[SUPERBLOCK_SIZE];
554 CDROM_TOC toc;
555 DWORD br;
557 /* check for audio CD */
558 /* FIXME: we only check the first track for now */
559 if (DeviceIoControl( handle, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, 0 ))
561 if (!(toc.TrackData[0].Control & 0x04)) /* audio track */
563 TRACE( "%s: found audio CD\n", debugstr_w(device) );
564 if (label) lstrcpynW( label, audiocdW, label_len );
565 if (serial) *serial = VOLUME_GetAudioCDSerial( &toc );
566 CloseHandle( handle );
567 type = FS_ISO9660;
568 goto fill_fs_info;
570 type = VOLUME_ReadCDSuperblock( handle, superblock );
572 else
574 type = VOLUME_ReadFATSuperblock( handle, superblock );
575 if (type == FS_UNKNOWN) type = VOLUME_ReadCDSuperblock( handle, superblock );
577 CloseHandle( handle );
578 TRACE( "%s: found fs type %d\n", debugstr_w(device), type );
579 if (type == FS_ERROR) return FALSE;
581 if (label && label_len) VOLUME_GetSuperblockLabel( device, type, superblock, label, label_len );
582 if (serial) *serial = VOLUME_GetSuperblockSerial( device, type, superblock );
583 goto fill_fs_info;
585 else TRACE( "cannot open device %s: err %d\n", debugstr_w(device), GetLastError() );
587 /* we couldn't open the device, fallback to default strategy */
589 switch(GetDriveTypeW( root ))
591 case DRIVE_UNKNOWN:
592 case DRIVE_NO_ROOT_DIR:
593 SetLastError( ERROR_NOT_READY );
594 return FALSE;
595 case DRIVE_REMOVABLE:
596 case DRIVE_FIXED:
597 case DRIVE_REMOTE:
598 case DRIVE_RAMDISK:
599 type = FS_UNKNOWN;
600 break;
601 case DRIVE_CDROM:
602 type = FS_ISO9660;
603 break;
606 if (label && label_len) get_filesystem_label( device, label, label_len );
607 if (serial) *serial = get_filesystem_serial( device );
609 fill_fs_info: /* now fill in the information that depends on the file system type */
611 switch(type)
613 case FS_ISO9660:
614 if (fsname) lstrcpynW( fsname, cdfsW, fsname_len );
615 if (filename_len) *filename_len = 221;
616 if (flags) *flags = FILE_READ_ONLY_VOLUME;
617 break;
618 case FS_FAT1216:
619 case FS_FAT32:
620 if (fsname) lstrcpynW( fsname, fatW, fsname_len );
621 if (filename_len) *filename_len = 255;
622 if (flags) *flags = FILE_CASE_PRESERVED_NAMES; /* FIXME */
623 break;
624 default:
625 if (fsname) lstrcpynW( fsname, ntfsW, fsname_len );
626 if (filename_len) *filename_len = 255;
627 if (flags) *flags = FILE_CASE_PRESERVED_NAMES;
628 break;
630 return TRUE;
634 /***********************************************************************
635 * GetVolumeInformationA (KERNEL32.@)
637 BOOL WINAPI GetVolumeInformationA( LPCSTR root, LPSTR label,
638 DWORD label_len, DWORD *serial,
639 DWORD *filename_len, DWORD *flags,
640 LPSTR fsname, DWORD fsname_len )
642 WCHAR *rootW = NULL;
643 LPWSTR labelW, fsnameW;
644 BOOL ret;
646 if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
648 labelW = label ? HeapAlloc(GetProcessHeap(), 0, label_len * sizeof(WCHAR)) : NULL;
649 fsnameW = fsname ? HeapAlloc(GetProcessHeap(), 0, fsname_len * sizeof(WCHAR)) : NULL;
651 if ((ret = GetVolumeInformationW(rootW, labelW, label_len, serial,
652 filename_len, flags, fsnameW, fsname_len)))
654 if (label) FILE_name_WtoA( labelW, -1, label, label_len );
655 if (fsname) FILE_name_WtoA( fsnameW, -1, fsname, fsname_len );
658 HeapFree( GetProcessHeap(), 0, labelW );
659 HeapFree( GetProcessHeap(), 0, fsnameW );
660 return ret;
665 /***********************************************************************
666 * SetVolumeLabelW (KERNEL32.@)
668 BOOL WINAPI SetVolumeLabelW( LPCWSTR root, LPCWSTR label )
670 WCHAR device[] = {'\\','\\','.','\\','A',':',0};
671 HANDLE handle;
672 enum fs_type type = FS_UNKNOWN;
674 if (!root)
676 WCHAR path[MAX_PATH];
677 GetCurrentDirectoryW( MAX_PATH, path );
678 device[4] = path[0];
680 else
682 if (!root[0] || root[1] != ':')
684 SetLastError( ERROR_INVALID_NAME );
685 return FALSE;
687 device[4] = root[0];
690 /* try to open the device */
692 handle = CreateFileW( device, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
693 NULL, OPEN_EXISTING, 0, 0 );
694 if (handle != INVALID_HANDLE_VALUE)
696 BYTE superblock[SUPERBLOCK_SIZE];
698 type = VOLUME_ReadFATSuperblock( handle, superblock );
699 if (type == FS_UNKNOWN) type = VOLUME_ReadCDSuperblock( handle, superblock );
700 CloseHandle( handle );
701 if (type != FS_UNKNOWN)
703 /* we can't set the label on FAT or CDROM file systems */
704 TRACE( "cannot set label on device %s type %d\n", debugstr_w(device), type );
705 SetLastError( ERROR_ACCESS_DENIED );
706 return FALSE;
709 else
711 TRACE( "cannot open device %s: err %d\n", debugstr_w(device), GetLastError() );
712 if (GetLastError() == ERROR_ACCESS_DENIED) return FALSE;
715 /* we couldn't open the device, fallback to default strategy */
717 switch(GetDriveTypeW( root ))
719 case DRIVE_UNKNOWN:
720 case DRIVE_NO_ROOT_DIR:
721 SetLastError( ERROR_NOT_READY );
722 break;
723 case DRIVE_REMOVABLE:
724 case DRIVE_FIXED:
726 WCHAR labelW[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','l','a','b','e','l',0};
728 labelW[0] = device[4];
729 handle = CreateFileW( labelW, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
730 CREATE_ALWAYS, 0, 0 );
731 if (handle != INVALID_HANDLE_VALUE)
733 char buffer[64];
734 DWORD size;
736 if (!WideCharToMultiByte( CP_UNIXCP, 0, label, -1, buffer, sizeof(buffer), NULL, NULL ))
737 buffer[sizeof(buffer)-1] = 0;
738 WriteFile( handle, buffer, strlen(buffer), &size, NULL );
739 CloseHandle( handle );
740 return TRUE;
742 break;
744 case DRIVE_REMOTE:
745 case DRIVE_RAMDISK:
746 case DRIVE_CDROM:
747 SetLastError( ERROR_ACCESS_DENIED );
748 break;
750 return FALSE;
753 /***********************************************************************
754 * SetVolumeLabelA (KERNEL32.@)
756 BOOL WINAPI SetVolumeLabelA(LPCSTR root, LPCSTR volname)
758 WCHAR *rootW = NULL, *volnameW = NULL;
759 BOOL ret;
761 if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
762 if (volname && !(volnameW = FILE_name_AtoW( volname, TRUE ))) return FALSE;
763 ret = SetVolumeLabelW( rootW, volnameW );
764 HeapFree( GetProcessHeap(), 0, volnameW );
765 return ret;
769 /***********************************************************************
770 * GetVolumeNameForVolumeMountPointA (KERNEL32.@)
772 BOOL WINAPI GetVolumeNameForVolumeMountPointA( LPCSTR path, LPSTR volume, DWORD size )
774 BOOL ret;
775 WCHAR volumeW[50], *pathW = NULL;
776 DWORD len = min( sizeof(volumeW) / sizeof(WCHAR), size );
778 TRACE("(%s, %p, %x)\n", debugstr_a(path), volume, size);
780 if (!path || !(pathW = FILE_name_AtoW( path, TRUE )))
781 return FALSE;
783 if ((ret = GetVolumeNameForVolumeMountPointW( pathW, volumeW, len )))
784 FILE_name_WtoA( volumeW, -1, volume, len );
786 HeapFree( GetProcessHeap(), 0, pathW );
787 return ret;
790 /***********************************************************************
791 * GetVolumeNameForVolumeMountPointW (KERNEL32.@)
793 BOOL WINAPI GetVolumeNameForVolumeMountPointW( LPCWSTR path, LPWSTR volume, DWORD size )
795 BOOL ret = FALSE;
796 static const WCHAR fmt[] =
797 { '\\','\\','?','\\','V','o','l','u','m','e','{','%','0','2','x','}','\\',0 };
799 TRACE("(%s, %p, %x)\n", debugstr_w(path), volume, size);
801 if (!path || !path[0]) return FALSE;
803 if (size >= sizeof(fmt) / sizeof(WCHAR))
805 /* FIXME: will break when we support volume mounts */
806 sprintfW( volume, fmt, tolowerW( path[0] ) - 'a' );
807 ret = TRUE;
809 return ret;
812 /***********************************************************************
813 * DefineDosDeviceW (KERNEL32.@)
815 BOOL WINAPI DefineDosDeviceW( DWORD flags, LPCWSTR devname, LPCWSTR targetpath )
817 DWORD len, dosdev;
818 BOOL ret = FALSE;
819 char *path = NULL, *target, *p;
821 TRACE("%x, %s, %s\n", flags, debugstr_w(devname), debugstr_w(targetpath));
823 if (!(flags & DDD_REMOVE_DEFINITION))
825 if (!(flags & DDD_RAW_TARGET_PATH))
827 FIXME( "(0x%08x,%s,%s) DDD_RAW_TARGET_PATH flag not set, not supported yet\n",
828 flags, debugstr_w(devname), debugstr_w(targetpath) );
829 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
830 return FALSE;
833 len = WideCharToMultiByte( CP_UNIXCP, 0, targetpath, -1, NULL, 0, NULL, NULL );
834 if ((target = HeapAlloc( GetProcessHeap(), 0, len )))
836 WideCharToMultiByte( CP_UNIXCP, 0, targetpath, -1, target, len, NULL, NULL );
837 for (p = target; *p; p++) if (*p == '\\') *p = '/';
839 else
841 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
842 return FALSE;
845 else target = NULL;
847 /* first check for a DOS device */
849 if ((dosdev = RtlIsDosDeviceName_U( devname )))
851 WCHAR name[5];
853 memcpy( name, devname + HIWORD(dosdev)/sizeof(WCHAR), LOWORD(dosdev) );
854 name[LOWORD(dosdev)/sizeof(WCHAR)] = 0;
855 path = get_dos_device_path( name );
857 else if (isalphaW(devname[0]) && devname[1] == ':' && !devname[2]) /* drive mapping */
859 path = get_dos_device_path( devname );
861 else SetLastError( ERROR_FILE_NOT_FOUND );
863 if (path)
865 if (target)
867 TRACE( "creating symlink %s -> %s\n", path, target );
868 unlink( path );
869 if (!symlink( target, path )) ret = TRUE;
870 else FILE_SetDosError();
872 else
874 TRACE( "removing symlink %s\n", path );
875 if (!unlink( path )) ret = TRUE;
876 else FILE_SetDosError();
878 HeapFree( GetProcessHeap(), 0, path );
880 HeapFree( GetProcessHeap(), 0, target );
881 return ret;
885 /***********************************************************************
886 * DefineDosDeviceA (KERNEL32.@)
888 BOOL WINAPI DefineDosDeviceA(DWORD flags, LPCSTR devname, LPCSTR targetpath)
890 WCHAR *devW, *targetW = NULL;
891 BOOL ret;
893 if (!(devW = FILE_name_AtoW( devname, FALSE ))) return FALSE;
894 if (targetpath && !(targetW = FILE_name_AtoW( targetpath, TRUE ))) return FALSE;
895 ret = DefineDosDeviceW(flags, devW, targetW);
896 HeapFree( GetProcessHeap(), 0, targetW );
897 return ret;
901 /***********************************************************************
902 * QueryDosDeviceW (KERNEL32.@)
904 * returns array of strings terminated by \0, terminated by \0
906 DWORD WINAPI QueryDosDeviceW( LPCWSTR devname, LPWSTR target, DWORD bufsize )
908 static const WCHAR auxW[] = {'A','U','X',0};
909 static const WCHAR nulW[] = {'N','U','L',0};
910 static const WCHAR prnW[] = {'P','R','N',0};
911 static const WCHAR comW[] = {'C','O','M',0};
912 static const WCHAR lptW[] = {'L','P','T',0};
913 static const WCHAR rootW[] = {'A',':','\\',0};
914 static const WCHAR com0W[] = {'\\','?','?','\\','C','O','M','0',0};
915 static const WCHAR com1W[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','C','O','M','1',0,0};
916 static const WCHAR lpt1W[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','L','P','T','1',0,0};
918 UNICODE_STRING nt_name;
919 ANSI_STRING unix_name;
920 WCHAR nt_buffer[10];
921 NTSTATUS status;
923 if (!bufsize)
925 SetLastError( ERROR_INSUFFICIENT_BUFFER );
926 return 0;
929 if (devname)
931 WCHAR *p, name[5];
932 char *path, *link;
933 DWORD dosdev, ret = 0;
935 if ((dosdev = RtlIsDosDeviceName_U( devname )))
937 memcpy( name, devname + HIWORD(dosdev)/sizeof(WCHAR), LOWORD(dosdev) );
938 name[LOWORD(dosdev)/sizeof(WCHAR)] = 0;
940 else if (devname[0] && devname[1] == ':' && !devname[2])
942 memcpy( name, devname, 3 * sizeof(WCHAR) );
944 else
946 SetLastError( ERROR_BAD_PATHNAME );
947 return 0;
950 if (!(path = get_dos_device_path( name ))) return 0;
951 link = read_symlink( path );
952 HeapFree( GetProcessHeap(), 0, path );
954 if (link)
956 ret = MultiByteToWideChar( CP_UNIXCP, 0, link, -1, target, bufsize );
957 HeapFree( GetProcessHeap(), 0, link );
959 else if (dosdev) /* look for device defaults */
961 if (!strcmpiW( name, auxW ))
963 if (bufsize >= sizeof(com1W)/sizeof(WCHAR))
965 memcpy( target, com1W, sizeof(com1W) );
966 ret = sizeof(com1W)/sizeof(WCHAR);
968 else SetLastError( ERROR_INSUFFICIENT_BUFFER );
969 return ret;
971 if (!strcmpiW( name, prnW ))
973 if (bufsize >= sizeof(lpt1W)/sizeof(WCHAR))
975 memcpy( target, lpt1W, sizeof(lpt1W) );
976 ret = sizeof(lpt1W)/sizeof(WCHAR);
978 else SetLastError( ERROR_INSUFFICIENT_BUFFER );
979 return ret;
982 nt_buffer[0] = '\\';
983 nt_buffer[1] = '?';
984 nt_buffer[2] = '?';
985 nt_buffer[3] = '\\';
986 strcpyW( nt_buffer + 4, name );
987 RtlInitUnicodeString( &nt_name, nt_buffer );
988 status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE );
989 if (status) SetLastError( RtlNtStatusToDosError(status) );
990 else
992 ret = MultiByteToWideChar( CP_UNIXCP, 0, unix_name.Buffer, -1, target, bufsize );
993 RtlFreeAnsiString( &unix_name );
997 if (ret)
999 if (ret < bufsize) target[ret++] = 0; /* add an extra null */
1000 for (p = target; *p; p++) if (*p == '/') *p = '\\';
1003 return ret;
1005 else /* return a list of all devices */
1007 WCHAR *p = target;
1008 int i;
1010 if (bufsize <= (sizeof(auxW)+sizeof(nulW)+sizeof(prnW))/sizeof(WCHAR))
1012 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1013 return 0;
1016 memcpy( p, auxW, sizeof(auxW) );
1017 p += sizeof(auxW) / sizeof(WCHAR);
1018 memcpy( p, nulW, sizeof(nulW) );
1019 p += sizeof(nulW) / sizeof(WCHAR);
1020 memcpy( p, prnW, sizeof(prnW) );
1021 p += sizeof(prnW) / sizeof(WCHAR);
1023 strcpyW( nt_buffer, com0W );
1024 RtlInitUnicodeString( &nt_name, nt_buffer );
1026 for (i = 1; i <= 9; i++)
1028 nt_buffer[7] = '0' + i;
1029 if (!wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE ))
1031 RtlFreeAnsiString( &unix_name );
1032 if (p + 5 >= target + bufsize)
1034 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1035 return 0;
1037 strcpyW( p, comW );
1038 p[3] = '0' + i;
1039 p[4] = 0;
1040 p += 5;
1043 strcpyW( nt_buffer + 4, lptW );
1044 for (i = 1; i <= 9; i++)
1046 nt_buffer[7] = '0' + i;
1047 if (!wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE ))
1049 RtlFreeAnsiString( &unix_name );
1050 if (p + 5 >= target + bufsize)
1052 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1053 return 0;
1055 strcpyW( p, lptW );
1056 p[3] = '0' + i;
1057 p[4] = 0;
1058 p += 5;
1062 strcpyW( nt_buffer + 4, rootW );
1063 RtlInitUnicodeString( &nt_name, nt_buffer );
1065 for (i = 0; i < 26; i++)
1067 nt_buffer[4] = 'a' + i;
1068 if (!wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE ))
1070 RtlFreeAnsiString( &unix_name );
1071 if (p + 3 >= target + bufsize)
1073 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1074 return 0;
1076 *p++ = 'A' + i;
1077 *p++ = ':';
1078 *p++ = 0;
1081 *p++ = 0; /* terminating null */
1082 return p - target;
1087 /***********************************************************************
1088 * QueryDosDeviceA (KERNEL32.@)
1090 * returns array of strings terminated by \0, terminated by \0
1092 DWORD WINAPI QueryDosDeviceA( LPCSTR devname, LPSTR target, DWORD bufsize )
1094 DWORD ret = 0, retW;
1095 WCHAR *devnameW = NULL;
1096 LPWSTR targetW;
1098 if (devname && !(devnameW = FILE_name_AtoW( devname, FALSE ))) return 0;
1100 targetW = HeapAlloc( GetProcessHeap(),0, bufsize * sizeof(WCHAR) );
1101 if (!targetW)
1103 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1104 return 0;
1107 retW = QueryDosDeviceW(devnameW, targetW, bufsize);
1109 ret = FILE_name_WtoA( targetW, retW, target, bufsize );
1111 HeapFree(GetProcessHeap(), 0, targetW);
1112 return ret;
1116 /***********************************************************************
1117 * GetLogicalDrives (KERNEL32.@)
1119 DWORD WINAPI GetLogicalDrives(void)
1121 const char *config_dir = wine_get_config_dir();
1122 struct stat st;
1123 char *buffer, *dev;
1124 DWORD ret = 0;
1125 int i;
1127 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, strlen(config_dir) + sizeof("/dosdevices/a:") )))
1129 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1130 return 0;
1132 strcpy( buffer, config_dir );
1133 strcat( buffer, "/dosdevices/a:" );
1134 dev = buffer + strlen(buffer) - 2;
1136 for (i = 0; i < 26; i++)
1138 *dev = 'a' + i;
1139 if (!stat( buffer, &st )) ret |= (1 << i);
1141 HeapFree( GetProcessHeap(), 0, buffer );
1142 return ret;
1146 /***********************************************************************
1147 * GetLogicalDriveStringsA (KERNEL32.@)
1149 UINT WINAPI GetLogicalDriveStringsA( UINT len, LPSTR buffer )
1151 DWORD drives = GetLogicalDrives();
1152 UINT drive, count;
1154 for (drive = count = 0; drive < 26; drive++) if (drives & (1 << drive)) count++;
1155 if ((count * 4) + 1 > len) return count * 4 + 1;
1157 for (drive = 0; drive < 26; drive++)
1159 if (drives & (1 << drive))
1161 *buffer++ = 'a' + drive;
1162 *buffer++ = ':';
1163 *buffer++ = '\\';
1164 *buffer++ = 0;
1167 *buffer = 0;
1168 return count * 4;
1172 /***********************************************************************
1173 * GetLogicalDriveStringsW (KERNEL32.@)
1175 UINT WINAPI GetLogicalDriveStringsW( UINT len, LPWSTR buffer )
1177 DWORD drives = GetLogicalDrives();
1178 UINT drive, count;
1180 for (drive = count = 0; drive < 26; drive++) if (drives & (1 << drive)) count++;
1181 if ((count * 4) + 1 > len) return count * 4 + 1;
1183 for (drive = 0; drive < 26; drive++)
1185 if (drives & (1 << drive))
1187 *buffer++ = 'a' + drive;
1188 *buffer++ = ':';
1189 *buffer++ = '\\';
1190 *buffer++ = 0;
1193 *buffer = 0;
1194 return count * 4;
1198 /***********************************************************************
1199 * GetDriveTypeW (KERNEL32.@)
1201 * Returns the type of the disk drive specified. If root is NULL the
1202 * root of the current directory is used.
1204 * RETURNS
1206 * Type of drive (from Win32 SDK):
1208 * DRIVE_UNKNOWN unable to find out anything about the drive
1209 * DRIVE_NO_ROOT_DIR nonexistent root dir
1210 * DRIVE_REMOVABLE the disk can be removed from the machine
1211 * DRIVE_FIXED the disk cannot be removed from the machine
1212 * DRIVE_REMOTE network disk
1213 * DRIVE_CDROM CDROM drive
1214 * DRIVE_RAMDISK virtual disk in RAM
1216 UINT WINAPI GetDriveTypeW(LPCWSTR root) /* [in] String describing drive */
1218 FILE_FS_DEVICE_INFORMATION info;
1219 IO_STATUS_BLOCK io;
1220 NTSTATUS status;
1221 HANDLE handle;
1222 UINT ret;
1224 if (!open_device_root( root, &handle )) return DRIVE_NO_ROOT_DIR;
1226 status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsDeviceInformation );
1227 NtClose( handle );
1228 if (status != STATUS_SUCCESS)
1230 SetLastError( RtlNtStatusToDosError(status) );
1231 ret = DRIVE_UNKNOWN;
1233 else if ((ret = get_registry_drive_type( root )) == DRIVE_UNKNOWN)
1235 switch (info.DeviceType)
1237 case FILE_DEVICE_CD_ROM_FILE_SYSTEM: ret = DRIVE_CDROM; break;
1238 case FILE_DEVICE_VIRTUAL_DISK: ret = DRIVE_RAMDISK; break;
1239 case FILE_DEVICE_NETWORK_FILE_SYSTEM: ret = DRIVE_REMOTE; break;
1240 case FILE_DEVICE_DISK_FILE_SYSTEM:
1241 if (info.Characteristics & FILE_REMOTE_DEVICE) ret = DRIVE_REMOTE;
1242 else if (info.Characteristics & FILE_REMOVABLE_MEDIA) ret = DRIVE_REMOVABLE;
1243 else ret = DRIVE_FIXED;
1244 break;
1245 default:
1246 ret = DRIVE_UNKNOWN;
1247 break;
1250 TRACE( "%s -> %d\n", debugstr_w(root), ret );
1251 return ret;
1255 /***********************************************************************
1256 * GetDriveTypeA (KERNEL32.@)
1258 * See GetDriveTypeW.
1260 UINT WINAPI GetDriveTypeA( LPCSTR root )
1262 WCHAR *rootW = NULL;
1264 if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return DRIVE_NO_ROOT_DIR;
1265 return GetDriveTypeW( rootW );
1269 /***********************************************************************
1270 * GetDiskFreeSpaceExW (KERNEL32.@)
1272 * This function is used to acquire the size of the available and
1273 * total space on a logical volume.
1275 * RETURNS
1277 * Zero on failure, nonzero upon success. Use GetLastError to obtain
1278 * detailed error information.
1281 BOOL WINAPI GetDiskFreeSpaceExW( LPCWSTR root, PULARGE_INTEGER avail,
1282 PULARGE_INTEGER total, PULARGE_INTEGER totalfree )
1284 FILE_FS_SIZE_INFORMATION info;
1285 IO_STATUS_BLOCK io;
1286 NTSTATUS status;
1287 HANDLE handle;
1288 UINT units;
1290 TRACE( "%s,%p,%p,%p\n", debugstr_w(root), avail, total, totalfree );
1292 if (!open_device_root( root, &handle )) return FALSE;
1294 status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsSizeInformation );
1295 NtClose( handle );
1296 if (status != STATUS_SUCCESS)
1298 SetLastError( RtlNtStatusToDosError(status) );
1299 return FALSE;
1302 units = info.SectorsPerAllocationUnit * info.BytesPerSector;
1303 if (total) total->QuadPart = info.TotalAllocationUnits.QuadPart * units;
1304 if (totalfree) totalfree->QuadPart = info.AvailableAllocationUnits.QuadPart * units;
1305 /* FIXME: this one should take quotas into account */
1306 if (avail) avail->QuadPart = info.AvailableAllocationUnits.QuadPart * units;
1307 return TRUE;
1311 /***********************************************************************
1312 * GetDiskFreeSpaceExA (KERNEL32.@)
1314 * See GetDiskFreeSpaceExW.
1316 BOOL WINAPI GetDiskFreeSpaceExA( LPCSTR root, PULARGE_INTEGER avail,
1317 PULARGE_INTEGER total, PULARGE_INTEGER totalfree )
1319 WCHAR *rootW = NULL;
1321 if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
1322 return GetDiskFreeSpaceExW( rootW, avail, total, totalfree );
1326 /***********************************************************************
1327 * GetDiskFreeSpaceW (KERNEL32.@)
1329 BOOL WINAPI GetDiskFreeSpaceW( LPCWSTR root, LPDWORD cluster_sectors,
1330 LPDWORD sector_bytes, LPDWORD free_clusters,
1331 LPDWORD total_clusters )
1333 FILE_FS_SIZE_INFORMATION info;
1334 IO_STATUS_BLOCK io;
1335 NTSTATUS status;
1336 HANDLE handle;
1337 UINT units;
1339 TRACE( "%s,%p,%p,%p,%p\n", debugstr_w(root),
1340 cluster_sectors, sector_bytes, free_clusters, total_clusters );
1342 if (!open_device_root( root, &handle )) return FALSE;
1344 status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsSizeInformation );
1345 NtClose( handle );
1346 if (status != STATUS_SUCCESS)
1348 SetLastError( RtlNtStatusToDosError(status) );
1349 return FALSE;
1352 units = info.SectorsPerAllocationUnit * info.BytesPerSector;
1354 if( GetVersion() & 0x80000000) { /* win3.x, 9x, ME */
1355 /* cap the size and available at 2GB as per specs */
1356 if (info.TotalAllocationUnits.QuadPart * units > 0x7fffffff) {
1357 info.TotalAllocationUnits.QuadPart = 0x7fffffff / units;
1358 if (info.AvailableAllocationUnits.QuadPart * units > 0x7fffffff)
1359 info.AvailableAllocationUnits.QuadPart = 0x7fffffff / units;
1361 /* nr. of clusters is always <= 65335 */
1362 while( info.TotalAllocationUnits.QuadPart > 65535 ) {
1363 info.TotalAllocationUnits.QuadPart /= 2;
1364 info.AvailableAllocationUnits.QuadPart /= 2;
1365 info.SectorsPerAllocationUnit *= 2;
1369 if (cluster_sectors) *cluster_sectors = info.SectorsPerAllocationUnit;
1370 if (sector_bytes) *sector_bytes = info.BytesPerSector;
1371 if (free_clusters) *free_clusters = info.AvailableAllocationUnits.u.LowPart;
1372 if (total_clusters) *total_clusters = info.TotalAllocationUnits.u.LowPart;
1373 return TRUE;
1377 /***********************************************************************
1378 * GetDiskFreeSpaceA (KERNEL32.@)
1380 BOOL WINAPI GetDiskFreeSpaceA( LPCSTR root, LPDWORD cluster_sectors,
1381 LPDWORD sector_bytes, LPDWORD free_clusters,
1382 LPDWORD total_clusters )
1384 WCHAR *rootW = NULL;
1386 if (root && !(rootW = FILE_name_AtoW( root, FALSE ))) return FALSE;
1387 return GetDiskFreeSpaceW( rootW, cluster_sectors, sector_bytes, free_clusters, total_clusters );
1390 /***********************************************************************
1391 * GetVolumePathNameA (KERNEL32.@)
1393 BOOL WINAPI GetVolumePathNameA(LPCSTR filename, LPSTR volumepathname, DWORD buflen)
1395 FIXME("(%s, %p, %d), stub!\n", debugstr_a(filename), volumepathname, buflen);
1396 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1397 return FALSE;
1400 /***********************************************************************
1401 * GetVolumePathNameW (KERNEL32.@)
1403 BOOL WINAPI GetVolumePathNameW(LPCWSTR filename, LPWSTR volumepathname, DWORD buflen)
1405 FIXME("(%s, %p, %d), stub!\n", debugstr_w(filename), volumepathname, buflen);
1406 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1407 return FALSE;
1410 /***********************************************************************
1411 * FindFirstVolumeA (KERNEL32.@)
1413 HANDLE WINAPI FindFirstVolumeA(LPSTR volume, DWORD len)
1415 FIXME("(%p, %d), stub!\n", volume, len);
1416 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1417 return INVALID_HANDLE_VALUE;
1420 /***********************************************************************
1421 * FindFirstVolumeW (KERNEL32.@)
1423 HANDLE WINAPI FindFirstVolumeW(LPWSTR volume, DWORD len)
1425 FIXME("(%p, %d), stub!\n", volume, len);
1426 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1427 return INVALID_HANDLE_VALUE;
1430 /***********************************************************************
1431 * FindFirstVolumeMountPointA (KERNEL32.@)
1433 HANDLE WINAPI FindFirstVolumeMountPointA(LPCSTR root, LPSTR mount_point, DWORD len)
1435 FIXME("(%s, %p, %d), stub!\n", debugstr_a(root), mount_point, len);
1436 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1437 return INVALID_HANDLE_VALUE;
1440 /***********************************************************************
1441 * FindFirstVolumeMountPointW (KERNEL32.@)
1443 HANDLE WINAPI FindFirstVolumeMountPointW(LPCWSTR root, LPWSTR mount_point, DWORD len)
1445 FIXME("(%s, %p, %d), stub!\n", debugstr_w(root), mount_point, len);
1446 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1447 return INVALID_HANDLE_VALUE;
1450 /***********************************************************************
1451 * FindVolumeClose (KERNEL32.@)
1453 BOOL WINAPI FindVolumeClose(HANDLE handle)
1455 FIXME("(%p), stub!\n", handle);
1456 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1457 return FALSE;
1460 /***********************************************************************
1461 * FindVolumeMountPointClose (KERNEL32.@)
1463 BOOL WINAPI FindVolumeMountPointClose(HANDLE h)
1465 FIXME("(%p), stub!\n", h);
1466 return FALSE;