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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "wine/port.h"
41 #include "kernel_private.h"
42 #include "wine/library.h"
43 #include "wine/unicode.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(volume);
48 #define SUPERBLOCK_SIZE 2048
50 #define CDFRAMES_PERSEC 75
51 #define CDFRAMES_PERMIN (CDFRAMES_PERSEC * 60)
52 #define FRAME_OF_ADDR(a) ((a)[1] * CDFRAMES_PERMIN + (a)[2] * CDFRAMES_PERSEC + (a)[3])
53 #define FRAME_OF_TOC(toc, idx) FRAME_OF_ADDR((toc)->TrackData[(idx) - (toc)->FirstTrack].Address)
55 #define GETWORD(buf,off) MAKEWORD(buf[(off)],buf[(off+1)])
56 #define GETLONG(buf,off) MAKELONG(GETWORD(buf,off),GETWORD(buf,off+2))
60 FS_ERROR, /* error accessing the device */
61 FS_UNKNOWN, /* unknown file system */
67 static const WCHAR drive_types[][8] =
69 { 0 }, /* DRIVE_UNKNOWN */
70 { 0 }, /* DRIVE_NO_ROOT_DIR */
71 {'f','l','o','p','p','y',0}, /* DRIVE_REMOVABLE */
72 {'h','d',0}, /* DRIVE_FIXED */
73 {'n','e','t','w','o','r','k',0}, /* DRIVE_REMOTE */
74 {'c','d','r','o','m',0}, /* DRIVE_CDROM */
75 {'r','a','m','d','i','s','k',0} /* DRIVE_RAMDISK */
78 /* read a Unix symlink; returned buffer must be freed by caller */
79 static char *read_symlink( const char *path )
86 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, size )))
88 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
91 ret = readlink( path, buffer, size );
95 HeapFree( GetProcessHeap(), 0, buffer );
103 HeapFree( GetProcessHeap(), 0, buffer );
108 /* get the path of a dos device symlink in the $WINEPREFIX/dosdevices directory */
109 static char *get_dos_device_path( LPCWSTR name )
111 const char *config_dir = wine_get_config_dir();
115 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
116 strlen(config_dir) + sizeof("/dosdevices/") + 5 )))
118 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
121 strcpy( buffer, config_dir );
122 strcat( buffer, "/dosdevices/" );
123 dev = buffer + strlen(buffer);
124 /* no codepage conversion, DOS device names are ASCII anyway */
125 for (i = 0; i < 5; i++)
126 if (!(dev[i] = (char)tolowerW(name[i]))) break;
132 /* open a handle to a device root */
133 static BOOL open_device_root( LPCWSTR root, HANDLE *handle )
135 static const WCHAR default_rootW[] = {'\\',0};
136 UNICODE_STRING nt_name;
137 OBJECT_ATTRIBUTES attr;
141 if (!root) root = default_rootW;
142 if (!RtlDosPathNameToNtPathName_U( root, &nt_name, NULL, NULL ))
144 SetLastError( ERROR_PATH_NOT_FOUND );
147 attr.Length = sizeof(attr);
148 attr.RootDirectory = 0;
149 attr.Attributes = OBJ_CASE_INSENSITIVE;
150 attr.ObjectName = &nt_name;
151 attr.SecurityDescriptor = NULL;
152 attr.SecurityQualityOfService = NULL;
154 status = NtOpenFile( handle, 0, &attr, &io, 0,
155 FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT );
156 RtlFreeUnicodeString( &nt_name );
157 if (status != STATUS_SUCCESS)
159 SetLastError( RtlNtStatusToDosError(status) );
166 /* fetch the type of a drive from the registry */
167 static UINT get_registry_drive_type( const WCHAR *root )
169 static const WCHAR drive_types_keyW[] = {'M','a','c','h','i','n','e','\\',
170 'S','o','f','t','w','a','r','e','\\',
171 'W','i','n','e','\\',
172 'D','r','i','v','e','s',0 };
173 OBJECT_ATTRIBUTES attr;
174 UNICODE_STRING nameW;
177 UINT ret = DRIVE_UNKNOWN;
178 char tmp[32 + sizeof(KEY_VALUE_PARTIAL_INFORMATION)];
179 WCHAR driveW[] = {'A',':',0};
181 attr.Length = sizeof(attr);
182 attr.RootDirectory = 0;
183 attr.ObjectName = &nameW;
185 attr.SecurityDescriptor = NULL;
186 attr.SecurityQualityOfService = NULL;
187 RtlInitUnicodeString( &nameW, drive_types_keyW );
188 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS) return DRIVE_UNKNOWN;
190 if (root) driveW[0] = root[0];
193 WCHAR path[MAX_PATH];
194 GetCurrentDirectoryW( MAX_PATH, path );
198 RtlInitUnicodeString( &nameW, driveW );
199 if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
202 WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
204 for (i = 0; i < sizeof(drive_types)/sizeof(drive_types[0]); i++)
206 if (!strcmpiW( data, drive_types[i] ))
218 /* create symlinks for the DOS drives; helper for VOLUME_CreateDevices */
219 static int create_drives( int devices_only )
221 static const WCHAR PathW[] = {'P','a','t','h',0};
222 static const WCHAR DeviceW[] = {'D','e','v','i','c','e',0};
223 WCHAR driveW[] = {'M','a','c','h','i','n','e','\\','S','o','f','t','w','a','r','e','\\',
224 'W','i','n','e','\\','W','i','n','e','\\',
225 'C','o','n','f','i','g','\\','D','r','i','v','e',' ','A',0};
226 OBJECT_ATTRIBUTES attr;
227 UNICODE_STRING nameW;
228 char tmp[1024*sizeof(WCHAR) + sizeof(KEY_VALUE_PARTIAL_INFORMATION)];
235 attr.Length = sizeof(attr);
236 attr.RootDirectory = 0;
237 attr.ObjectName = &nameW;
239 attr.SecurityDescriptor = NULL;
240 attr.SecurityQualityOfService = NULL;
242 /* create symlinks for the drive roots */
244 if (!devices_only) for (i = 0; i < 26; i++)
246 RtlInitUnicodeString( &nameW, driveW );
247 nameW.Buffer[(nameW.Length / sizeof(WCHAR)) - 1] = 'A' + i;
248 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS) continue;
250 RtlInitUnicodeString( &nameW, PathW );
251 if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
254 WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
255 ExpandEnvironmentStringsW( data, path, sizeof(path)/sizeof(WCHAR) );
257 p = path + strlenW(path) - 1;
258 while ((p > path) && (*p == '/')) *p-- = '\0';
266 /* relative paths are relative to config dir */
267 memmove( path + 3, path, (strlenW(path) + 1) * sizeof(WCHAR) );
272 if (DefineDosDeviceW( DDD_RAW_TARGET_PATH, name, path ))
274 WideCharToMultiByte(CP_UNIXCP, 0, path, -1, dest, sizeof(dest), NULL, NULL);
275 MESSAGE( "Created symlink %s/dosdevices/%c: -> %s\n",
276 wine_get_config_dir(), 'a' + i, dest );
283 /* create symlinks for the drive devices */
285 for (i = 0; i < 26; i++)
287 RtlInitUnicodeString( &nameW, driveW );
288 nameW.Buffer[(nameW.Length / sizeof(WCHAR)) - 1] = 'A' + i;
289 if (NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) != STATUS_SUCCESS) continue;
291 RtlInitUnicodeString( &nameW, DeviceW );
292 if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation, tmp, sizeof(tmp), &dummy ))
295 WCHAR devname[] = {'A',':',':',0 };
296 WCHAR *data = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
297 WideCharToMultiByte(CP_UNIXCP, 0, data, -1, dest, sizeof(dest), NULL, NULL);
298 path = get_dos_device_path( devname );
299 p = path + strlen(path);
301 if (!symlink( dest, path ))
303 MESSAGE( "Created symlink %s/dosdevices/%c:: -> %s\n",
304 wine_get_config_dir(), 'a' + i, dest );
307 HeapFree( GetProcessHeap(), 0, path );
316 /***********************************************************************
317 * VOLUME_CreateDevices
319 * Create the device files for the new device naming scheme.
320 * Should go away after a transition period.
322 void VOLUME_CreateDevices(void)
324 const char *config_dir = wine_get_config_dir();
328 if (!(buffer = HeapAlloc( GetProcessHeap(), 0,
329 strlen(config_dir) + sizeof("/dosdevices/a::") )))
332 strcpy( buffer, config_dir );
333 strcat( buffer, "/dosdevices" );
335 if (!mkdir( buffer, 0777 )) /* we created it, so now create the devices */
339 OBJECT_ATTRIBUTES attr;
340 UNICODE_STRING nameW;
343 WCHAR com[5] = {'C','O','M','1',0};
344 WCHAR lpt[5] = {'L','P','T','1',0};
346 static const WCHAR serialportsW[] = {'M','a','c','h','i','n','e','\\',
347 'S','o','f','t','w','a','r','e','\\',
348 'W','i','n','e','\\','W','i','n','e','\\',
349 'C','o','n','f','i','g','\\',
350 'S','e','r','i','a','l','P','o','r','t','s',0};
351 static const WCHAR parallelportsW[] = {'M','a','c','h','i','n','e','\\',
352 'S','o','f','t','w','a','r','e','\\',
353 'W','i','n','e','\\','W','i','n','e','\\',
354 'C','o','n','f','i','g','\\',
355 'P','a','r','a','l','l','e','l','P','o','r','t','s',0};
357 attr.Length = sizeof(attr);
358 attr.RootDirectory = 0;
359 attr.ObjectName = &nameW;
361 attr.SecurityDescriptor = NULL;
362 attr.SecurityQualityOfService = NULL;
363 RtlInitUnicodeString( &nameW, serialportsW );
365 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
367 RtlInitUnicodeString( &nameW, com );
368 for (i = 1; i <= 9; i++)
371 if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
372 tmp, sizeof(tmp), &dummy ))
374 devnameW = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
375 if ((p = strchrW( devnameW, ',' ))) *p = 0;
376 if (DefineDosDeviceW( DDD_RAW_TARGET_PATH, com, devnameW ))
379 WideCharToMultiByte(CP_UNIXCP, 0, devnameW, -1,
380 devname, sizeof(devname), NULL, NULL);
381 MESSAGE( "Created symlink %s/dosdevices/com%d -> %s\n", config_dir, i, devname );
389 RtlInitUnicodeString( &nameW, parallelportsW );
390 if (!NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ))
392 RtlInitUnicodeString( &nameW, lpt );
393 for (i = 1; i <= 9; i++)
396 if (!NtQueryValueKey( hkey, &nameW, KeyValuePartialInformation,
397 tmp, sizeof(tmp), &dummy ))
399 devnameW = (WCHAR *)((KEY_VALUE_PARTIAL_INFORMATION *)tmp)->Data;
400 if ((p = strchrW( devnameW, ',' ))) *p = 0;
401 if (DefineDosDeviceW( DDD_RAW_TARGET_PATH, lpt, devnameW ))
404 WideCharToMultiByte(CP_UNIXCP, 0, devnameW, -1,
405 devname, sizeof(devname), NULL, NULL);
406 MESSAGE( "Created symlink %s/dosdevices/lpt%d -> %s\n", config_dir, i, devname );
413 count += create_drives( FALSE );
420 /* it is possible that the serial/parallel devices have been created but */
421 /* not the drives; check for at least one drive symlink to catch that case */
422 strcat( buffer, "/a:" );
423 for (i = 0; i < 26; i++)
425 buffer[strlen(buffer)-2] = 'a' + i;
426 if (!lstat( buffer, &st )) break;
428 if (i == 26) count += create_drives( FALSE );
431 strcat( buffer, ":" );
432 for (i = 0; i < 26; i++)
434 buffer[strlen(buffer)-3] = 'a' + i;
435 if (!lstat( buffer, &st )) break;
437 if (i == 26) count += create_drives( TRUE );
442 MESSAGE( "\nYou can now remove the [SerialPorts], [ParallelPorts], and [Drive] sections\n"
443 "in your configuration file, they are replaced by the above symlinks.\n\n" );
445 HeapFree( GetProcessHeap(), 0, buffer );
449 /******************************************************************
450 * VOLUME_FindCdRomDataBestVoldesc
452 static DWORD VOLUME_FindCdRomDataBestVoldesc( HANDLE handle )
454 BYTE cur_vd_type, max_vd_type = 0;
456 DWORD size, offs, best_offs = 0, extra_offs = 0;
458 for (offs = 0x8000; offs <= 0x9800; offs += 0x800)
460 /* if 'CDROM' occurs at position 8, this is a pre-iso9660 cd, and
461 * the volume label is displaced forward by 8
463 if (SetFilePointer( handle, offs, NULL, FILE_BEGIN ) != offs) break;
464 if (!ReadFile( handle, buffer, sizeof(buffer), &size, NULL )) break;
465 if (size != sizeof(buffer)) break;
466 /* check for non-ISO9660 signature */
467 if (!memcmp( buffer + 11, "ROM", 3 )) extra_offs = 8;
468 cur_vd_type = buffer[extra_offs];
469 if (cur_vd_type == 0xff) /* voldesc set terminator */
471 if (cur_vd_type > max_vd_type)
473 max_vd_type = cur_vd_type;
474 best_offs = offs + extra_offs;
481 /***********************************************************************
482 * VOLUME_ReadFATSuperblock
484 static enum fs_type VOLUME_ReadFATSuperblock( HANDLE handle, BYTE *buff )
488 /* try a fixed disk, with a FAT partition */
489 if (SetFilePointer( handle, 0, NULL, FILE_BEGIN ) != 0 ||
490 !ReadFile( handle, buff, SUPERBLOCK_SIZE, &size, NULL ) ||
491 size != SUPERBLOCK_SIZE)
494 if (buff[0] == 0xE9 || (buff[0] == 0xEB && buff[2] == 0x90))
496 /* guess which type of FAT we have */
497 unsigned int sz, nsect, nclust;
498 sz = GETWORD(buff, 0x16);
499 if (!sz) sz = GETLONG(buff, 0x24);
500 nsect = GETWORD(buff, 0x13);
501 if (!nsect) nsect = GETLONG(buff, 0x20);
502 nsect -= GETWORD(buff, 0x0e) + buff[0x10] * sz +
503 (GETWORD(buff, 0x11) * 32 + (GETWORD(buff, 0x0b) - 1)) / GETWORD(buff, 0x0b);
504 nclust = nsect / buff[0x0d];
508 if (buff[0x26] == 0x29 && !memcmp(buff+0x36, "FAT", 3))
510 /* FIXME: do really all FAT have their name beginning with
511 * "FAT" ? (At least FAT12, FAT16 and FAT32 have :)
516 else if (!memcmp(buff+0x52, "FAT", 3)) return FS_FAT32;
522 /***********************************************************************
523 * VOLUME_ReadCDSuperblock
525 static enum fs_type VOLUME_ReadCDSuperblock( HANDLE handle, BYTE *buff )
527 DWORD size, offs = VOLUME_FindCdRomDataBestVoldesc( handle );
529 if (!offs) return FS_UNKNOWN;
531 if (SetFilePointer( handle, offs, NULL, FILE_BEGIN ) != offs ||
532 !ReadFile( handle, buff, SUPERBLOCK_SIZE, &size, NULL ) ||
533 size != SUPERBLOCK_SIZE)
536 /* check for iso9660 present */
537 if (!memcmp(&buff[1], "CD001", 5)) return FS_ISO9660;
542 /**************************************************************************
543 * VOLUME_GetSuperblockLabel
545 static void VOLUME_GetSuperblockLabel( enum fs_type type, const BYTE *superblock,
546 WCHAR *label, DWORD len )
548 const BYTE *label_ptr = NULL;
558 label_ptr = superblock + 0x2b;
562 label_ptr = superblock + 0x47;
567 BYTE ver = superblock[0x5a];
569 if (superblock[0x58] == 0x25 && superblock[0x59] == 0x2f && /* Unicode ID */
570 ((ver == 0x40) || (ver == 0x43) || (ver == 0x45)))
571 { /* yippee, unicode */
574 if (len > 17) len = 17;
575 for (i = 0; i < len-1; i++)
576 label[i] = (superblock[40+2*i] << 8) | superblock[41+2*i];
578 while (i && label[i-1] == ' ') label[--i] = 0;
581 label_ptr = superblock + 40;
586 if (label_len) RtlMultiByteToUnicodeN( label, (len-1) * sizeof(WCHAR),
587 &label_len, label_ptr, label_len );
588 label_len /= sizeof(WCHAR);
589 label[label_len] = 0;
590 while (label_len && label[label_len-1] == ' ') label[--label_len] = 0;
594 /**************************************************************************
595 * VOLUME_SetSuperblockLabel
597 static BOOL VOLUME_SetSuperblockLabel( enum fs_type type, HANDLE handle, const WCHAR *label )
611 SetLastError( ERROR_ACCESS_DENIED );
614 RtlUnicodeToMultiByteN( label_data, sizeof(label_data), &len,
615 label, strlenW(label) * sizeof(WCHAR) );
616 if (len < sizeof(label_data))
617 memset( label_data + len, ' ', sizeof(label_data) - len );
619 return (SetFilePointer( handle, offset, NULL, FILE_BEGIN ) == offset &&
620 WriteFile( handle, label_data, sizeof(label_data), &len, NULL ));
624 /**************************************************************************
625 * VOLUME_GetSuperblockSerial
627 static DWORD VOLUME_GetSuperblockSerial( enum fs_type type, const BYTE *superblock )
635 return GETLONG( superblock, 0x27 );
637 return GETLONG( superblock, 0x33 );
643 sum[0] = sum[1] = sum[2] = sum[3] = 0;
644 for (i = 0; i < 2048; i += 4)
646 /* DON'T optimize this into DWORD !! (breaks overflow) */
647 sum[0] += superblock[i+0];
648 sum[1] += superblock[i+1];
649 sum[2] += superblock[i+2];
650 sum[3] += superblock[i+3];
653 * OK, another braindead one... argh. Just believe it.
654 * Me$$ysoft chose to reverse the serial number in NT4/W2K.
655 * It's true and nobody will ever be able to change it.
657 if (GetVersion() & 0x80000000)
658 return (sum[3] << 24) | (sum[2] << 16) | (sum[1] << 8) | sum[0];
660 return (sum[0] << 24) | (sum[1] << 16) | (sum[2] << 8) | sum[3];
667 /**************************************************************************
668 * VOLUME_GetAudioCDSerial
670 static DWORD VOLUME_GetAudioCDSerial( const CDROM_TOC *toc )
675 for (i = 0; i <= toc->LastTrack - toc->FirstTrack; i++)
676 serial += ((toc->TrackData[i].Address[1] << 16) |
677 (toc->TrackData[i].Address[2] << 8) |
678 toc->TrackData[i].Address[3]);
681 * dwStart, dwEnd collect the beginning and end of the disc respectively, in
683 * There it is collected for correcting the serial when there are less than
686 if (toc->LastTrack - toc->FirstTrack + 1 < 3)
688 DWORD dwStart = FRAME_OF_TOC(toc, toc->FirstTrack);
689 DWORD dwEnd = FRAME_OF_TOC(toc, toc->LastTrack + 1);
690 serial += dwEnd - dwStart;
696 /***********************************************************************
697 * GetVolumeInformationW (KERNEL32.@)
699 BOOL WINAPI GetVolumeInformationW( LPCWSTR root, LPWSTR label, DWORD label_len,
700 DWORD *serial, DWORD *filename_len, DWORD *flags,
701 LPWSTR fsname, DWORD fsname_len )
703 static const WCHAR audiocdW[] = {'A','u','d','i','o',' ','C','D',0};
704 static const WCHAR fatW[] = {'F','A','T',0};
705 static const WCHAR cdfsW[] = {'C','D','F','S',0};
707 WCHAR device[] = {'\\','\\','.','\\','A',':',0};
709 enum fs_type type = FS_UNKNOWN;
713 WCHAR path[MAX_PATH];
714 GetCurrentDirectoryW( MAX_PATH, path );
719 if (!root[0] || root[1] != ':')
721 SetLastError( ERROR_INVALID_NAME );
727 /* try to open the device */
729 handle = CreateFileW( device, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
730 NULL, OPEN_EXISTING, 0, 0 );
731 if (handle != INVALID_HANDLE_VALUE)
733 BYTE superblock[SUPERBLOCK_SIZE];
737 /* check for audio CD */
738 /* FIXME: we only check the first track for now */
739 if (DeviceIoControl( handle, IOCTL_CDROM_READ_TOC, NULL, 0, &toc, sizeof(toc), &br, 0 ))
741 if (!(toc.TrackData[0].Control & 0x04)) /* audio track */
743 TRACE( "%s: found audio CD\n", debugstr_w(device) );
744 if (label) lstrcpynW( label, audiocdW, label_len );
745 if (serial) *serial = VOLUME_GetAudioCDSerial( &toc );
746 CloseHandle( handle );
750 type = VOLUME_ReadCDSuperblock( handle, superblock );
754 type = VOLUME_ReadFATSuperblock( handle, superblock );
755 if (type == FS_UNKNOWN) type = VOLUME_ReadCDSuperblock( handle, superblock );
757 CloseHandle( handle );
758 TRACE( "%s: found fs type %d\n", debugstr_w(device), type );
759 if (type == FS_ERROR) return FALSE;
761 if (label && label_len) VOLUME_GetSuperblockLabel( type, superblock, label, label_len );
762 if (serial) *serial = VOLUME_GetSuperblockSerial( type, superblock );
767 TRACE( "cannot open device %s: err %ld\n", debugstr_w(device), GetLastError() );
768 if (GetLastError() != ERROR_FILE_NOT_FOUND) return FALSE;
771 /* we couldn't open the device, fallback to default strategy */
773 switch(GetDriveTypeW( root ))
776 case DRIVE_NO_ROOT_DIR:
777 SetLastError( ERROR_NOT_READY );
779 case DRIVE_REMOVABLE:
790 if (label && label_len)
792 WCHAR labelW[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','l','a','b','e','l',0};
794 labelW[0] = device[4];
795 handle = CreateFileW( labelW, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
796 OPEN_EXISTING, 0, 0 );
797 if (handle != INVALID_HANDLE_VALUE)
799 char buffer[256], *p;
802 if (!ReadFile( handle, buffer, sizeof(buffer)-1, &size, NULL )) size = 0;
803 CloseHandle( handle );
805 while (p > buffer && (p[-1] == ' ' || p[-1] == '\r' || p[-1] == '\n')) p--;
807 if (!MultiByteToWideChar( CP_UNIXCP, 0, buffer, -1, label, label_len ))
808 label[label_len-1] = 0;
814 WCHAR serialW[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','s','e','r','i','a','l',0};
816 serialW[0] = device[4];
817 handle = CreateFileW( serialW, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
818 OPEN_EXISTING, 0, 0 );
819 if (handle != INVALID_HANDLE_VALUE)
824 if (!ReadFile( handle, buffer, sizeof(buffer)-1, &size, NULL )) size = 0;
825 CloseHandle( handle );
827 *serial = strtoul( buffer, NULL, 16 );
832 fill_fs_info: /* now fill in the information that depends on the file system type */
837 if (fsname) lstrcpynW( fsname, cdfsW, fsname_len );
838 if (filename_len) *filename_len = 221;
839 if (flags) *flags = FILE_READ_ONLY_VOLUME;
843 default: /* default to FAT file system (FIXME) */
844 if (fsname) lstrcpynW( fsname, fatW, fsname_len );
845 if (filename_len) *filename_len = 255;
846 if (flags) *flags = FILE_CASE_PRESERVED_NAMES; /* FIXME */
853 /***********************************************************************
854 * GetVolumeInformationA (KERNEL32.@)
856 BOOL WINAPI GetVolumeInformationA( LPCSTR root, LPSTR label,
857 DWORD label_len, DWORD *serial,
858 DWORD *filename_len, DWORD *flags,
859 LPSTR fsname, DWORD fsname_len )
861 UNICODE_STRING rootW;
862 LPWSTR labelW, fsnameW;
865 if (root) RtlCreateUnicodeStringFromAsciiz(&rootW, root);
866 else rootW.Buffer = NULL;
867 labelW = label ? HeapAlloc(GetProcessHeap(), 0, label_len * sizeof(WCHAR)) : NULL;
868 fsnameW = fsname ? HeapAlloc(GetProcessHeap(), 0, fsname_len * sizeof(WCHAR)) : NULL;
870 if ((ret = GetVolumeInformationW(rootW.Buffer, labelW, label_len, serial,
871 filename_len, flags, fsnameW, fsname_len)))
873 if (label) WideCharToMultiByte(CP_ACP, 0, labelW, -1, label, label_len, NULL, NULL);
874 if (fsname) WideCharToMultiByte(CP_ACP, 0, fsnameW, -1, fsname, fsname_len, NULL, NULL);
877 RtlFreeUnicodeString(&rootW);
878 if (labelW) HeapFree( GetProcessHeap(), 0, labelW );
879 if (fsnameW) HeapFree( GetProcessHeap(), 0, fsnameW );
885 /***********************************************************************
886 * SetVolumeLabelW (KERNEL32.@)
888 BOOL WINAPI SetVolumeLabelW( LPCWSTR root, LPCWSTR label )
890 WCHAR device[] = {'\\','\\','.','\\','A',':',0};
892 enum fs_type type = FS_UNKNOWN;
896 WCHAR path[MAX_PATH];
897 GetCurrentDirectoryW( MAX_PATH, path );
902 if (!root[0] || root[1] != ':')
904 SetLastError( ERROR_INVALID_NAME );
910 /* try to open the device */
912 handle = CreateFileW( device, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE,
913 NULL, OPEN_EXISTING, 0, 0 );
914 if (handle == INVALID_HANDLE_VALUE)
917 handle = CreateFileW( device, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE,
918 NULL, OPEN_EXISTING, 0, 0 );
919 if (handle != INVALID_HANDLE_VALUE)
921 /* device can be read but not written, return error */
922 CloseHandle( handle );
923 SetLastError( ERROR_ACCESS_DENIED );
928 if (handle != INVALID_HANDLE_VALUE)
930 BYTE superblock[SUPERBLOCK_SIZE];
933 type = VOLUME_ReadFATSuperblock( handle, superblock );
934 ret = VOLUME_SetSuperblockLabel( type, handle, label );
935 CloseHandle( handle );
940 TRACE( "cannot open device %s: err %ld\n", debugstr_w(device), GetLastError() );
941 if (GetLastError() != ERROR_ACCESS_DENIED) return FALSE;
944 /* we couldn't open the device, fallback to default strategy */
946 switch(GetDriveTypeW( root ))
949 case DRIVE_NO_ROOT_DIR:
950 SetLastError( ERROR_NOT_READY );
952 case DRIVE_REMOVABLE:
955 WCHAR labelW[] = {'A',':','\\','.','w','i','n','d','o','w','s','-','l','a','b','e','l',0};
957 labelW[0] = device[4];
958 handle = CreateFileW( labelW, GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
959 CREATE_ALWAYS, 0, 0 );
960 if (handle != INVALID_HANDLE_VALUE)
965 if (!WideCharToMultiByte( CP_UNIXCP, 0, label, -1, buffer, sizeof(buffer), NULL, NULL ))
966 buffer[sizeof(buffer)-1] = 0;
967 WriteFile( handle, buffer, strlen(buffer), &size, NULL );
968 CloseHandle( handle );
976 SetLastError( ERROR_ACCESS_DENIED );
982 /***********************************************************************
983 * SetVolumeLabelA (KERNEL32.@)
985 BOOL WINAPI SetVolumeLabelA(LPCSTR root, LPCSTR volname)
987 UNICODE_STRING rootW, volnameW;
990 if (root) RtlCreateUnicodeStringFromAsciiz(&rootW, root);
991 else rootW.Buffer = NULL;
992 if (volname) RtlCreateUnicodeStringFromAsciiz(&volnameW, volname);
993 else volnameW.Buffer = NULL;
995 ret = SetVolumeLabelW( rootW.Buffer, volnameW.Buffer );
997 RtlFreeUnicodeString(&rootW);
998 RtlFreeUnicodeString(&volnameW);
1003 /***********************************************************************
1004 * GetVolumeNameForVolumeMountPointW (KERNEL32.@)
1006 BOOL WINAPI GetVolumeNameForVolumeMountPointW(LPCWSTR str, LPWSTR dst, DWORD size)
1008 FIXME("(%s, %p, %lx): stub\n", debugstr_w(str), dst, size);
1013 /***********************************************************************
1014 * DefineDosDeviceW (KERNEL32.@)
1016 BOOL WINAPI DefineDosDeviceW( DWORD flags, LPCWSTR devname, LPCWSTR targetpath )
1020 char *path = NULL, *target, *p;
1022 if (!(flags & DDD_REMOVE_DEFINITION))
1024 if (!(flags & DDD_RAW_TARGET_PATH))
1026 FIXME( "(0x%08lx,%s,%s) DDD_RAW_TARGET_PATH flag not set, not supported yet\n",
1027 flags, debugstr_w(devname), debugstr_w(targetpath) );
1028 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1032 len = WideCharToMultiByte( CP_UNIXCP, 0, targetpath, -1, NULL, 0, NULL, NULL );
1033 if ((target = HeapAlloc( GetProcessHeap(), 0, len )))
1035 WideCharToMultiByte( CP_UNIXCP, 0, targetpath, -1, target, len, NULL, NULL );
1036 for (p = target; *p; p++) if (*p == '\\') *p = '/';
1040 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1046 /* first check for a DOS device */
1048 if ((dosdev = RtlIsDosDeviceName_U( devname )))
1052 memcpy( name, devname + HIWORD(dosdev)/sizeof(WCHAR), LOWORD(dosdev) );
1053 name[LOWORD(dosdev)/sizeof(WCHAR)] = 0;
1054 path = get_dos_device_path( name );
1056 else if (isalphaW(devname[0]) && devname[1] == ':' && !devname[2]) /* drive mapping */
1058 path = get_dos_device_path( devname );
1060 else SetLastError( ERROR_FILE_NOT_FOUND );
1066 TRACE( "creating symlink %s -> %s\n", path, target );
1068 if (!symlink( target, path )) ret = TRUE;
1069 else FILE_SetDosError();
1073 TRACE( "removing symlink %s\n", path );
1074 if (!unlink( path )) ret = TRUE;
1075 else FILE_SetDosError();
1077 HeapFree( GetProcessHeap(), 0, path );
1079 if (target) HeapFree( GetProcessHeap(), 0, target );
1084 /***********************************************************************
1085 * DefineDosDeviceA (KERNEL32.@)
1087 BOOL WINAPI DefineDosDeviceA(DWORD flags, LPCSTR devname, LPCSTR targetpath)
1089 UNICODE_STRING d, t;
1092 if (!RtlCreateUnicodeStringFromAsciiz(&d, devname))
1094 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1097 if (!RtlCreateUnicodeStringFromAsciiz(&t, targetpath))
1099 RtlFreeUnicodeString(&d);
1100 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1103 ret = DefineDosDeviceW(flags, d.Buffer, t.Buffer);
1104 RtlFreeUnicodeString(&d);
1105 RtlFreeUnicodeString(&t);
1110 /***********************************************************************
1111 * QueryDosDeviceW (KERNEL32.@)
1113 * returns array of strings terminated by \0, terminated by \0
1115 DWORD WINAPI QueryDosDeviceW( LPCWSTR devname, LPWSTR target, DWORD bufsize )
1117 static const WCHAR auxW[] = {'A','U','X',0};
1118 static const WCHAR nulW[] = {'N','U','L',0};
1119 static const WCHAR prnW[] = {'P','R','N',0};
1120 static const WCHAR comW[] = {'C','O','M',0};
1121 static const WCHAR lptW[] = {'L','P','T',0};
1122 static const WCHAR rootW[] = {'A',':','\\',0};
1123 static const WCHAR com0W[] = {'\\','?','?','\\','C','O','M','0',0};
1124 static const WCHAR com1W[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','C','O','M','1',0,0};
1125 static const WCHAR lpt1W[] = {'\\','D','o','s','D','e','v','i','c','e','s','\\','L','P','T','1',0,0};
1127 UNICODE_STRING nt_name;
1128 ANSI_STRING unix_name;
1129 WCHAR nt_buffer[10];
1134 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1142 DWORD dosdev, ret = 0;
1144 if ((dosdev = RtlIsDosDeviceName_U( devname )))
1146 memcpy( name, devname + HIWORD(dosdev)/sizeof(WCHAR), LOWORD(dosdev) );
1147 name[LOWORD(dosdev)/sizeof(WCHAR)] = 0;
1149 else if (devname[0] && devname[1] == ':' && !devname[2])
1151 memcpy( name, devname, 3 * sizeof(WCHAR) );
1155 SetLastError( ERROR_BAD_PATHNAME );
1159 if (!(path = get_dos_device_path( name ))) return 0;
1160 link = read_symlink( path );
1161 HeapFree( GetProcessHeap(), 0, path );
1165 ret = MultiByteToWideChar( CP_UNIXCP, 0, link, -1, target, bufsize );
1166 HeapFree( GetProcessHeap(), 0, link );
1168 else if (dosdev) /* look for device defaults */
1170 if (!strcmpiW( name, auxW ))
1172 if (bufsize >= sizeof(com1W)/sizeof(WCHAR))
1174 memcpy( target, com1W, sizeof(com1W) );
1175 ret = sizeof(com1W)/sizeof(WCHAR);
1177 else SetLastError( ERROR_INSUFFICIENT_BUFFER );
1180 if (!strcmpiW( name, prnW ))
1182 if (bufsize >= sizeof(lpt1W)/sizeof(WCHAR))
1184 memcpy( target, lpt1W, sizeof(lpt1W) );
1185 ret = sizeof(lpt1W)/sizeof(WCHAR);
1187 else SetLastError( ERROR_INSUFFICIENT_BUFFER );
1191 nt_buffer[0] = '\\';
1194 nt_buffer[3] = '\\';
1195 strcpyW( nt_buffer + 4, name );
1196 RtlInitUnicodeString( &nt_name, nt_buffer );
1197 status = wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE );
1198 if (status) SetLastError( RtlNtStatusToDosError(status) );
1201 ret = MultiByteToWideChar( CP_UNIXCP, 0, unix_name.Buffer, -1, target, bufsize );
1202 RtlFreeAnsiString( &unix_name );
1208 if (ret < bufsize) target[ret++] = 0; /* add an extra null */
1209 for (p = target; *p; p++) if (*p == '/') *p = '\\';
1214 else /* return a list of all devices */
1219 if (bufsize <= (sizeof(auxW)+sizeof(nulW)+sizeof(prnW))/sizeof(WCHAR))
1221 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1225 memcpy( p, auxW, sizeof(auxW) );
1226 p += sizeof(auxW) / sizeof(WCHAR);
1227 memcpy( p, nulW, sizeof(nulW) );
1228 p += sizeof(nulW) / sizeof(WCHAR);
1229 memcpy( p, prnW, sizeof(prnW) );
1230 p += sizeof(prnW) / sizeof(WCHAR);
1232 strcpyW( nt_buffer, com0W );
1233 RtlInitUnicodeString( &nt_name, nt_buffer );
1235 for (i = 1; i <= 9; i++)
1237 nt_buffer[7] = '0' + i;
1238 if (!wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE ))
1240 RtlFreeAnsiString( &unix_name );
1241 if (p + 5 >= target + bufsize)
1243 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1252 strcpyW( nt_buffer + 4, lptW );
1253 for (i = 1; i <= 9; i++)
1255 nt_buffer[7] = '0' + i;
1256 if (!wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE ))
1258 RtlFreeAnsiString( &unix_name );
1259 if (p + 5 >= target + bufsize)
1261 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1271 strcpyW( nt_buffer + 4, rootW );
1272 RtlInitUnicodeString( &nt_name, nt_buffer );
1274 for (i = 0; i < 26; i++)
1276 nt_buffer[4] = 'a' + i;
1277 if (!wine_nt_to_unix_file_name( &nt_name, &unix_name, FILE_OPEN, TRUE ))
1279 RtlFreeAnsiString( &unix_name );
1280 if (p + 3 >= target + bufsize)
1282 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1290 *p++ = 0; /* terminating null */
1296 /***********************************************************************
1297 * QueryDosDeviceA (KERNEL32.@)
1299 * returns array of strings terminated by \0, terminated by \0
1301 DWORD WINAPI QueryDosDeviceA( LPCSTR devname, LPSTR target, DWORD bufsize )
1303 DWORD ret = 0, retW;
1304 UNICODE_STRING devnameW;
1305 LPWSTR targetW = HeapAlloc( GetProcessHeap(),0, bufsize * sizeof(WCHAR) );
1309 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1313 if (devname) RtlCreateUnicodeStringFromAsciiz(&devnameW, devname);
1314 else devnameW.Buffer = NULL;
1316 retW = QueryDosDeviceW(devnameW.Buffer, targetW, bufsize);
1318 ret = WideCharToMultiByte(CP_ACP, 0, targetW, retW, target, bufsize, NULL, NULL);
1320 RtlFreeUnicodeString(&devnameW);
1321 HeapFree(GetProcessHeap(), 0, targetW);
1326 /***********************************************************************
1327 * GetLogicalDrives (KERNEL32.@)
1329 DWORD WINAPI GetLogicalDrives(void)
1331 const char *config_dir = wine_get_config_dir();
1337 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, strlen(config_dir) + sizeof("/dosdevices/a:") )))
1339 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1342 strcpy( buffer, config_dir );
1343 strcat( buffer, "/dosdevices/a:" );
1344 dev = buffer + strlen(buffer) - 2;
1346 for (i = 0; i < 26; i++)
1349 if (!stat( buffer, &st )) ret |= (1 << i);
1351 HeapFree( GetProcessHeap(), 0, buffer );
1356 /***********************************************************************
1357 * GetLogicalDriveStringsA (KERNEL32.@)
1359 UINT WINAPI GetLogicalDriveStringsA( UINT len, LPSTR buffer )
1361 DWORD drives = GetLogicalDrives();
1364 for (drive = count = 0; drive < 26; drive++) if (drives & (1 << drive)) count++;
1365 if ((count * 4) + 1 > len) return count * 4 + 1;
1367 for (drive = 0; drive < 26; drive++)
1369 if (drives & (1 << drive))
1371 *buffer++ = 'a' + drive;
1382 /***********************************************************************
1383 * GetLogicalDriveStringsW (KERNEL32.@)
1385 UINT WINAPI GetLogicalDriveStringsW( UINT len, LPWSTR buffer )
1387 DWORD drives = GetLogicalDrives();
1390 for (drive = count = 0; drive < 26; drive++) if (drives & (1 << drive)) count++;
1391 if ((count * 4) + 1 > len) return count * 4 + 1;
1393 for (drive = 0; drive < 26; drive++)
1395 if (drives & (1 << drive))
1397 *buffer++ = 'a' + drive;
1408 /***********************************************************************
1409 * GetDriveTypeW (KERNEL32.@)
1411 * Returns the type of the disk drive specified. If root is NULL the
1412 * root of the current directory is used.
1416 * Type of drive (from Win32 SDK):
1418 * DRIVE_UNKNOWN unable to find out anything about the drive
1419 * DRIVE_NO_ROOT_DIR nonexistent root dir
1420 * DRIVE_REMOVABLE the disk can be removed from the machine
1421 * DRIVE_FIXED the disk can not be removed from the machine
1422 * DRIVE_REMOTE network disk
1423 * DRIVE_CDROM CDROM drive
1424 * DRIVE_RAMDISK virtual disk in RAM
1426 UINT WINAPI GetDriveTypeW(LPCWSTR root) /* [in] String describing drive */
1428 FILE_FS_DEVICE_INFORMATION info;
1434 if (!open_device_root( root, &handle )) return DRIVE_NO_ROOT_DIR;
1436 status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsDeviceInformation );
1438 if (status != STATUS_SUCCESS)
1440 SetLastError( RtlNtStatusToDosError(status) );
1441 ret = DRIVE_UNKNOWN;
1443 else if ((ret = get_registry_drive_type( root )) == DRIVE_UNKNOWN)
1445 switch (info.DeviceType)
1447 case FILE_DEVICE_CD_ROM_FILE_SYSTEM: ret = DRIVE_CDROM; break;
1448 case FILE_DEVICE_VIRTUAL_DISK: ret = DRIVE_RAMDISK; break;
1449 case FILE_DEVICE_NETWORK_FILE_SYSTEM: ret = DRIVE_REMOTE; break;
1450 case FILE_DEVICE_DISK_FILE_SYSTEM:
1451 if (info.Characteristics & FILE_REMOTE_DEVICE) ret = DRIVE_REMOTE;
1452 else if (info.Characteristics & FILE_REMOVABLE_MEDIA) ret = DRIVE_REMOVABLE;
1453 else ret = DRIVE_FIXED;
1456 ret = DRIVE_UNKNOWN;
1460 TRACE( "%s -> %d\n", debugstr_w(root), ret );
1465 /***********************************************************************
1466 * GetDriveTypeA (KERNEL32.@)
1468 UINT WINAPI GetDriveTypeA( LPCSTR root )
1470 UNICODE_STRING rootW;
1475 if( !RtlCreateUnicodeStringFromAsciiz(&rootW, root))
1477 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1478 return DRIVE_NO_ROOT_DIR;
1481 else rootW.Buffer = NULL;
1483 ret = GetDriveTypeW(rootW.Buffer);
1485 RtlFreeUnicodeString(&rootW);
1490 /***********************************************************************
1491 * GetDiskFreeSpaceExW (KERNEL32.@)
1493 * This function is used to acquire the size of the available and
1494 * total space on a logical volume.
1498 * Zero on failure, nonzero upon success. Use GetLastError to obtain
1499 * detailed error information.
1502 BOOL WINAPI GetDiskFreeSpaceExW( LPCWSTR root, PULARGE_INTEGER avail,
1503 PULARGE_INTEGER total, PULARGE_INTEGER totalfree )
1505 FILE_FS_SIZE_INFORMATION info;
1511 TRACE( "%s,%p,%p,%p\n", debugstr_w(root), avail, total, totalfree );
1513 if (!open_device_root( root, &handle )) return FALSE;
1515 status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsSizeInformation );
1517 if (status != STATUS_SUCCESS)
1519 SetLastError( RtlNtStatusToDosError(status) );
1523 units = info.SectorsPerAllocationUnit * info.BytesPerSector;
1524 if (total) total->QuadPart = info.TotalAllocationUnits.QuadPart * units;
1525 if (totalfree) totalfree->QuadPart = info.AvailableAllocationUnits.QuadPart * units;
1526 /* FIXME: this one should take quotas into account */
1527 if (avail) avail->QuadPart = info.AvailableAllocationUnits.QuadPart * units;
1532 /***********************************************************************
1533 * GetDiskFreeSpaceExA (KERNEL32.@)
1535 BOOL WINAPI GetDiskFreeSpaceExA( LPCSTR root, PULARGE_INTEGER avail,
1536 PULARGE_INTEGER total, PULARGE_INTEGER totalfree )
1538 UNICODE_STRING rootW;
1541 if (root) RtlCreateUnicodeStringFromAsciiz(&rootW, root);
1542 else rootW.Buffer = NULL;
1544 ret = GetDiskFreeSpaceExW( rootW.Buffer, avail, total, totalfree);
1546 RtlFreeUnicodeString(&rootW);
1551 /***********************************************************************
1552 * GetDiskFreeSpaceW (KERNEL32.@)
1554 BOOL WINAPI GetDiskFreeSpaceW( LPCWSTR root, LPDWORD cluster_sectors,
1555 LPDWORD sector_bytes, LPDWORD free_clusters,
1556 LPDWORD total_clusters )
1558 FILE_FS_SIZE_INFORMATION info;
1564 TRACE( "%s,%p,%p,%p,%p\n", debugstr_w(root),
1565 cluster_sectors, sector_bytes, free_clusters, total_clusters );
1567 if (!open_device_root( root, &handle )) return FALSE;
1569 status = NtQueryVolumeInformationFile( handle, &io, &info, sizeof(info), FileFsSizeInformation );
1571 if (status != STATUS_SUCCESS)
1573 SetLastError( RtlNtStatusToDosError(status) );
1577 units = info.SectorsPerAllocationUnit * info.BytesPerSector;
1579 /* cap the size and available at 2GB as per specs */
1580 if (info.AvailableAllocationUnits.QuadPart * units > 0x7fffffff)
1581 info.AvailableAllocationUnits.QuadPart = 0x7fffffff / units;
1582 if (info.TotalAllocationUnits.QuadPart * units > 0x7fffffff)
1583 info.TotalAllocationUnits.QuadPart = 0x7fffffff / units;
1585 if (cluster_sectors) *cluster_sectors = info.SectorsPerAllocationUnit;
1586 if (sector_bytes) *sector_bytes = info.BytesPerSector;
1587 if (free_clusters) *free_clusters = info.AvailableAllocationUnits.u.LowPart;
1588 if (total_clusters) *total_clusters = info.TotalAllocationUnits.u.LowPart;
1593 /***********************************************************************
1594 * GetDiskFreeSpaceA (KERNEL32.@)
1596 BOOL WINAPI GetDiskFreeSpaceA( LPCSTR root, LPDWORD cluster_sectors,
1597 LPDWORD sector_bytes, LPDWORD free_clusters,
1598 LPDWORD total_clusters )
1600 UNICODE_STRING rootW;
1605 if(!RtlCreateUnicodeStringFromAsciiz(&rootW, root))
1607 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1611 else rootW.Buffer = NULL;
1613 ret = GetDiskFreeSpaceW(rootW.Buffer, cluster_sectors, sector_bytes,
1614 free_clusters, total_clusters );
1615 RtlFreeUnicodeString(&rootW);