2 * DOS drives handling functions
4 * Copyright 1993 Erik Bos
5 * Copyright 1996 Alexandre Julliard
11 #include <sys/types.h>
14 #if defined(__linux__) || defined(sun) || defined(hpux)
17 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
18 #include <sys/param.h>
19 #include <sys/mount.h>
20 #include <sys/errno.h>
22 #if defined(__svr4__) || defined(_SCO_DS) || defined(__EMX__)
23 #include <sys/statfs.h>
39 char *root
; /* root dir in Unix format without trailing / */
40 char *dos_cwd
; /* cwd in DOS format without leading or trailing \ */
41 char *unix_cwd
; /* cwd in Unix format without leading or trailing / */
42 char label
[12]; /* drive label */
43 DWORD serial
; /* drive serial number */
44 DRIVETYPE type
; /* drive type */
45 UINT32 flags
; /* drive flags */
46 dev_t dev
; /* unix device number */
47 ino_t ino
; /* unix inode number */
51 static const char * const DRIVE_Types
[] =
53 "floppy", /* TYPE_FLOPPY */
55 "cdrom", /* TYPE_CDROM */
56 "network" /* TYPE_NETWORK */
60 /* Known filesystem types */
68 static const FS_DESCR DRIVE_Filesystems
[] =
70 { "unix", DRIVE_CASE_SENSITIVE
| DRIVE_CASE_PRESERVING
},
71 { "msdos", DRIVE_SHORT_NAMES
},
72 { "dos", DRIVE_SHORT_NAMES
},
73 { "fat", DRIVE_SHORT_NAMES
},
74 { "vfat", DRIVE_CASE_PRESERVING
},
75 { "win95", DRIVE_CASE_PRESERVING
},
80 static DOSDRIVE DOSDrives
[MAX_DOS_DRIVES
];
81 static int DRIVE_CurDrive
= -1;
83 static HTASK16 DRIVE_LastTask
= 0;
86 /***********************************************************************
89 static DRIVETYPE
DRIVE_GetDriveType( const char *name
)
94 PROFILE_GetWineIniString( name
, "Type", "hd", buffer
, sizeof(buffer
) );
95 for (i
= 0; i
< sizeof(DRIVE_Types
)/sizeof(DRIVE_Types
[0]); i
++)
97 if (!lstrcmpi32A( buffer
, DRIVE_Types
[i
] )) return (DRIVETYPE
)i
;
99 fprintf( stderr
, "%s: unknown type '%s', defaulting to 'hd'.\n",
105 /***********************************************************************
108 static UINT32
DRIVE_GetFSFlags( const char *name
, const char *value
)
110 const FS_DESCR
*descr
;
112 for (descr
= DRIVE_Filesystems
; descr
->name
; descr
++)
113 if (!lstrcmpi32A( value
, descr
->name
)) return descr
->flags
;
114 fprintf( stderr
, "%s: unknown filesystem type '%s', defaulting to 'unix'.\n",
116 return DRIVE_CASE_SENSITIVE
| DRIVE_CASE_PRESERVING
;
120 /***********************************************************************
125 int i
, len
, count
= 0;
126 char name
[] = "Drive A";
127 char path
[MAX_PATHNAME_LEN
];
129 struct stat drive_stat_buffer
;
133 for (i
= 0, drive
= DOSDrives
; i
< MAX_DOS_DRIVES
; i
++, name
[6]++, drive
++)
135 PROFILE_GetWineIniString( name
, "Path", "", path
, sizeof(path
)-1 );
138 p
= path
+ strlen(path
) - 1;
139 while ((p
> path
) && ((*p
== '/') || (*p
== '\\'))) *p
-- = '\0';
140 if (!path
[0]) strcpy( path
, "/" );
142 if (stat( path
, &drive_stat_buffer
))
144 fprintf( stderr
, "Could not stat %s, ignoring drive %c:\n",
148 if (!S_ISDIR(drive_stat_buffer
.st_mode
))
150 fprintf( stderr
, "%s is not a directory, ignoring drive %c:\n",
155 drive
->root
= HEAP_strdupA( SystemHeap
, 0, path
);
156 drive
->dos_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
157 drive
->unix_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
158 drive
->type
= DRIVE_GetDriveType( name
);
160 drive
->dev
= drive_stat_buffer
.st_dev
;
161 drive
->ino
= drive_stat_buffer
.st_ino
;
163 /* Get the drive label */
164 PROFILE_GetWineIniString( name
, "Label", name
, drive
->label
, 12 );
165 if ((len
= strlen(drive
->label
)) < 11)
167 /* Pad label with spaces */
168 memset( drive
->label
+ len
, ' ', 11 - len
);
169 drive
->label
[12] = '\0';
172 /* Get the serial number */
173 PROFILE_GetWineIniString( name
, "Serial", "12345678",
174 buffer
, sizeof(buffer
) );
175 drive
->serial
= strtoul( buffer
, NULL
, 16 );
177 /* Get the filesystem type */
178 PROFILE_GetWineIniString( name
, "Filesystem", "unix",
179 buffer
, sizeof(buffer
) );
180 drive
->flags
= DRIVE_GetFSFlags( name
, buffer
);
182 /* Make the first hard disk the current drive */
183 if ((DRIVE_CurDrive
== -1) && (drive
->type
== TYPE_HD
))
187 dprintf_dosfs( stddeb
, "%s: path=%s type=%s label='%s' serial=%08lx flags=%08x dev=%x ino=%x\n",
188 name
, path
, DRIVE_Types
[drive
->type
],
189 drive
->label
, drive
->serial
, drive
->flags
,
190 (int)drive
->dev
, (int)drive
->ino
);
192 else dprintf_dosfs( stddeb
, "%s: not defined\n", name
);
197 fprintf( stderr
, "Warning: no valid DOS drive found, check your configuration file.\n" );
198 /* Create a C drive pointing to Unix root dir */
199 DOSDrives
[2].root
= HEAP_strdupA( SystemHeap
, 0, "/" );
200 DOSDrives
[2].dos_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
201 DOSDrives
[2].unix_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
202 strcpy( DOSDrives
[2].label
, "Drive C " );
203 DOSDrives
[2].serial
= 0x12345678;
204 DOSDrives
[2].type
= TYPE_HD
;
205 DOSDrives
[2].flags
= 0;
209 /* Make sure the current drive is valid */
210 if (DRIVE_CurDrive
== -1)
212 for (i
= 0, drive
= DOSDrives
; i
< MAX_DOS_DRIVES
; i
++, drive
++)
214 if (drive
->root
&& !(drive
->flags
& DRIVE_DISABLED
))
226 /***********************************************************************
229 int DRIVE_IsValid( int drive
)
231 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
)) return 0;
232 return (DOSDrives
[drive
].root
&&
233 !(DOSDrives
[drive
].flags
& DRIVE_DISABLED
));
237 /***********************************************************************
238 * DRIVE_GetCurrentDrive
240 int DRIVE_GetCurrentDrive(void)
242 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
243 if (pTask
&& (pTask
->curdrive
& 0x80)) return pTask
->curdrive
& ~0x80;
244 return DRIVE_CurDrive
;
248 /***********************************************************************
249 * DRIVE_SetCurrentDrive
251 int DRIVE_SetCurrentDrive( int drive
)
253 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
254 if (!DRIVE_IsValid( drive
))
256 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
259 dprintf_dosfs( stddeb
, "DRIVE_SetCurrentDrive: %c:\n", 'A' + drive
);
260 DRIVE_CurDrive
= drive
;
261 if (pTask
) pTask
->curdrive
= drive
| 0x80;
266 /***********************************************************************
267 * DRIVE_FindDriveRoot
269 * Find a drive for which the root matches the begginning of the given path.
270 * This can be used to translate a Unix path into a drive + DOS path.
271 * Return value is the drive, or -1 on error. On success, path is modified
272 * to point to the beginning of the DOS path.
274 int DRIVE_FindDriveRoot( const char **path
)
276 /* idea: check at all '/' positions.
277 * If the device and inode of that path is identical with the
278 * device and inode of the current drive then we found a solution.
279 * If there is another drive pointing to a deeper position in
280 * the file tree, we want to find that one, not the earlier solution.
282 int drive
, rootdrive
= -1;
283 char buffer
[MAX_PATHNAME_LEN
];
285 const char *p
= *path
;
288 strcpy( buffer
, "/" );
291 if (stat( buffer
, &st
) || !S_ISDIR( st
.st_mode
)) break;
295 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
297 if (!DOSDrives
[drive
].root
||
298 (DOSDrives
[drive
].flags
& DRIVE_DISABLED
)) continue;
300 if ((DOSDrives
[drive
].dev
== st
.st_dev
) &&
301 (DOSDrives
[drive
].ino
== st
.st_ino
))
308 /* Get the next path component */
311 while ((*p
== '/') || (*p
== '\\')) p
++;
313 while (!IS_END_OF_NAME(*p
)) *next
++ = *p
++;
318 dprintf_dosfs( stddeb
, "DRIVE_FindDriveRoot: %s -> drive %c:, root='%s', name='%s'\n",
319 buffer
, 'A' + rootdrive
,
320 DOSDrives
[rootdrive
].root
, *path
);
325 /***********************************************************************
328 const char * DRIVE_GetRoot( int drive
)
330 if (!DRIVE_IsValid( drive
)) return NULL
;
331 return DOSDrives
[drive
].root
;
335 /***********************************************************************
338 const char * DRIVE_GetDosCwd( int drive
)
340 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
341 if (!DRIVE_IsValid( drive
)) return NULL
;
343 /* Check if we need to change the directory to the new task. */
344 if (pTask
&& (pTask
->curdrive
& 0x80) && /* The task drive is valid */
345 ((pTask
->curdrive
& ~0x80) == drive
) && /* and it's the one we want */
346 (DRIVE_LastTask
!= GetCurrentTask())) /* and the task changed */
348 /* Perform the task-switch */
349 if (!DRIVE_Chdir( drive
, pTask
->curdir
)) DRIVE_Chdir( drive
, "\\" );
350 DRIVE_LastTask
= GetCurrentTask();
352 return DOSDrives
[drive
].dos_cwd
;
356 /***********************************************************************
359 const char * DRIVE_GetUnixCwd( int drive
)
361 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
362 if (!DRIVE_IsValid( drive
)) return NULL
;
364 /* Check if we need to change the directory to the new task. */
365 if (pTask
&& (pTask
->curdrive
& 0x80) && /* The task drive is valid */
366 ((pTask
->curdrive
& ~0x80) == drive
) && /* and it's the one we want */
367 (DRIVE_LastTask
!= GetCurrentTask())) /* and the task changed */
369 /* Perform the task-switch */
370 if (!DRIVE_Chdir( drive
, pTask
->curdir
)) DRIVE_Chdir( drive
, "\\" );
371 DRIVE_LastTask
= GetCurrentTask();
373 return DOSDrives
[drive
].unix_cwd
;
377 /***********************************************************************
380 const char * DRIVE_GetLabel( int drive
)
382 if (!DRIVE_IsValid( drive
)) return NULL
;
383 return DOSDrives
[drive
].label
;
387 /***********************************************************************
388 * DRIVE_GetSerialNumber
390 DWORD
DRIVE_GetSerialNumber( int drive
)
392 if (!DRIVE_IsValid( drive
)) return 0;
393 return DOSDrives
[drive
].serial
;
397 /***********************************************************************
398 * DRIVE_SetSerialNumber
400 int DRIVE_SetSerialNumber( int drive
, DWORD serial
)
402 if (!DRIVE_IsValid( drive
)) return 0;
403 DOSDrives
[drive
].serial
= serial
;
408 /***********************************************************************
411 DRIVETYPE
DRIVE_GetType( int drive
)
413 if (!DRIVE_IsValid( drive
)) return TYPE_INVALID
;
414 return DOSDrives
[drive
].type
;
418 /***********************************************************************
421 UINT32
DRIVE_GetFlags( int drive
)
423 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
)) return 0;
424 return DOSDrives
[drive
].flags
;
428 /***********************************************************************
431 int DRIVE_Chdir( int drive
, const char *path
)
433 DOS_FULL_NAME full_name
;
434 char buffer
[MAX_PATHNAME_LEN
];
436 BY_HANDLE_FILE_INFORMATION info
;
437 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
439 dprintf_dosfs( stddeb
, "DRIVE_Chdir(%c:,%s)\n", 'A' + drive
, path
);
440 strcpy( buffer
, "A:" );
442 lstrcpyn32A( buffer
+ 2, path
, sizeof(buffer
) - 2 );
444 if (!DOSFS_GetFullName( buffer
, TRUE
, &full_name
)) return 0;
445 if (!FILE_Stat( full_name
.long_name
, &info
)) return 0;
446 if (!(info
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
448 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
451 unix_cwd
= full_name
.long_name
+ strlen( DOSDrives
[drive
].root
);
452 while (*unix_cwd
== '/') unix_cwd
++;
454 dprintf_dosfs( stddeb
, "DRIVE_Chdir(%c:): unix_cwd=%s dos_cwd=%s\n",
455 'A' + drive
, unix_cwd
, full_name
.short_name
+ 3 );
457 HeapFree( SystemHeap
, 0, DOSDrives
[drive
].dos_cwd
);
458 HeapFree( SystemHeap
, 0, DOSDrives
[drive
].unix_cwd
);
459 DOSDrives
[drive
].dos_cwd
= HEAP_strdupA( SystemHeap
, 0,
460 full_name
.short_name
+ 3 );
461 DOSDrives
[drive
].unix_cwd
= HEAP_strdupA( SystemHeap
, 0, unix_cwd
);
463 if (pTask
&& (pTask
->curdrive
& 0x80) &&
464 ((pTask
->curdrive
& ~0x80) == drive
))
466 lstrcpyn32A( pTask
->curdir
, full_name
.short_name
+ 2,
467 sizeof(pTask
->curdir
) );
468 DRIVE_LastTask
= GetCurrentTask();
474 /***********************************************************************
477 int DRIVE_Disable( int drive
)
479 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
) || !DOSDrives
[drive
].root
)
481 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
484 DOSDrives
[drive
].flags
|= DRIVE_DISABLED
;
489 /***********************************************************************
492 int DRIVE_Enable( int drive
)
494 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
) || !DOSDrives
[drive
].root
)
496 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
499 DOSDrives
[drive
].flags
&= ~DRIVE_DISABLED
;
504 /***********************************************************************
507 static int DRIVE_GetFreeSpace( int drive
, DWORD
*size
, DWORD
*available
)
511 if (!DRIVE_IsValid(drive
))
513 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
517 #if defined(__svr4__) || defined(_SCO_DS)
518 if (statfs( DOSDrives
[drive
].root
, &info
, 0, 0) < 0)
520 if (statfs( DOSDrives
[drive
].root
, &info
) < 0)
524 fprintf(stderr
,"dosfs: cannot do statfs(%s)\n", DOSDrives
[drive
].root
);
528 *size
= info
.f_bsize
* info
.f_blocks
;
529 #if defined(__svr4__) || defined(_SCO_DS) || defined(__EMX__)
530 *available
= info
.f_bfree
* info
.f_bsize
;
532 *available
= info
.f_bavail
* info
.f_bsize
;
538 /***********************************************************************
539 * GetDiskFreeSpace16 (KERNEL.422)
541 BOOL16 WINAPI
GetDiskFreeSpace16( LPCSTR root
, LPDWORD cluster_sectors
,
542 LPDWORD sector_bytes
, LPDWORD free_clusters
,
543 LPDWORD total_clusters
)
545 return GetDiskFreeSpace32A( root
, cluster_sectors
, sector_bytes
,
546 free_clusters
, total_clusters
);
550 /***********************************************************************
551 * GetDiskFreeSpace32A (KERNEL32.206)
553 BOOL32 WINAPI
GetDiskFreeSpace32A( LPCSTR root
, LPDWORD cluster_sectors
,
554 LPDWORD sector_bytes
, LPDWORD free_clusters
,
555 LPDWORD total_clusters
)
558 DWORD size
,available
;
560 if (!root
) drive
= DRIVE_GetCurrentDrive();
563 if ((root
[1] != ':') || (root
[2] != '\\'))
565 fprintf( stderr
, "GetDiskFreeSpaceA: invalid root '%s'\n", root
);
568 drive
= toupper(root
[0]) - 'A';
570 if (!DRIVE_GetFreeSpace(drive
, &size
, &available
)) return FALSE
;
575 *cluster_sectors
= 1;
576 while (*cluster_sectors
* 65530 < size
) *cluster_sectors
*= 2;
577 *free_clusters
= available
/ *cluster_sectors
;
578 *total_clusters
= size
/ *cluster_sectors
;
583 /***********************************************************************
584 * GetDiskFreeSpace32W (KERNEL32.207)
586 BOOL32 WINAPI
GetDiskFreeSpace32W( LPCWSTR root
, LPDWORD cluster_sectors
,
587 LPDWORD sector_bytes
, LPDWORD free_clusters
,
588 LPDWORD total_clusters
)
593 xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
594 ret
= GetDiskFreeSpace32A( xroot
,cluster_sectors
, sector_bytes
,
595 free_clusters
, total_clusters
);
596 HeapFree( GetProcessHeap(), 0, xroot
);
601 /***********************************************************************
602 * GetDriveType16 (KERNEL.136)
604 UINT16 WINAPI
GetDriveType16( UINT16 drive
)
606 dprintf_dosfs( stddeb
, "GetDriveType16(%c:)\n", 'A' + drive
);
607 switch(DRIVE_GetType(drive
))
609 case TYPE_FLOPPY
: return DRIVE_REMOVABLE
;
610 case TYPE_HD
: return DRIVE_FIXED
;
611 case TYPE_CDROM
: return DRIVE_REMOTE
;
612 case TYPE_NETWORK
: return DRIVE_REMOTE
;
614 default: return DRIVE_CANNOTDETERMINE
;
619 /***********************************************************************
620 * GetDriveType32A (KERNEL32.208)
622 UINT32 WINAPI
GetDriveType32A( LPCSTR root
)
624 dprintf_dosfs( stddeb
, "GetDriveType32A(%s)\n", root
);
627 fprintf( stderr
, "GetDriveType32A: invalid root '%s'\n", root
);
628 return DRIVE_DOESNOTEXIST
;
630 switch(DRIVE_GetType(toupper(root
[0]) - 'A'))
632 case TYPE_FLOPPY
: return DRIVE_REMOVABLE
;
633 case TYPE_HD
: return DRIVE_FIXED
;
634 case TYPE_CDROM
: return DRIVE_CDROM
;
635 case TYPE_NETWORK
: return DRIVE_REMOTE
;
637 default: return DRIVE_CANNOTDETERMINE
;
642 /***********************************************************************
643 * GetDriveType32W (KERNEL32.209)
645 UINT32 WINAPI
GetDriveType32W( LPCWSTR root
)
647 LPSTR xpath
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
648 UINT32 ret
= GetDriveType32A( xpath
);
649 HeapFree( GetProcessHeap(), 0, xpath
);
654 /***********************************************************************
655 * GetCurrentDirectory16 (KERNEL.411)
657 UINT16 WINAPI
GetCurrentDirectory16( UINT16 buflen
, LPSTR buf
)
659 return (UINT16
)GetCurrentDirectory32A( buflen
, buf
);
663 /***********************************************************************
664 * GetCurrentDirectory32A (KERNEL32.196)
666 * Returns "X:\\path\\etc\\".
668 UINT32 WINAPI
GetCurrentDirectory32A( UINT32 buflen
, LPSTR buf
)
671 const char *s
= DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() );
677 lstrcpyn32A( buf
, pref
, MIN( 4, buflen
) );
678 if (buflen
) buf
[0] += DRIVE_GetCurrentDrive();
679 if (buflen
> 3) lstrcpyn32A( buf
+ 3, s
, buflen
- 3 );
680 return strlen(s
) + 3; /* length of WHOLE current directory */
684 /***********************************************************************
685 * GetCurrentDirectory32W (KERNEL32.197)
687 UINT32 WINAPI
GetCurrentDirectory32W( UINT32 buflen
, LPWSTR buf
)
689 LPSTR xpath
= HeapAlloc( GetProcessHeap(), 0, buflen
+1 );
690 UINT32 ret
= GetCurrentDirectory32A( buflen
, xpath
);
691 lstrcpyAtoW( buf
, xpath
);
692 HeapFree( GetProcessHeap(), 0, xpath
);
697 /***********************************************************************
698 * SetCurrentDirectory (KERNEL.412)
700 BOOL16 WINAPI
SetCurrentDirectory16( LPCSTR dir
)
702 return SetCurrentDirectory32A( dir
);
706 /***********************************************************************
707 * SetCurrentDirectory32A (KERNEL32.479)
709 BOOL32 WINAPI
SetCurrentDirectory32A( LPCSTR dir
)
711 int drive
= DRIVE_GetCurrentDrive();
713 if (dir
[0] && (dir
[1]==':'))
715 drive
= tolower( *dir
) - 'a';
716 if (!DRIVE_IsValid( drive
))
718 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
723 /* FIXME: what about empty strings? Add a \\ ? */
724 if (!DRIVE_Chdir( drive
, dir
)) return FALSE
;
725 if (drive
== DRIVE_GetCurrentDrive()) return TRUE
;
726 return DRIVE_SetCurrentDrive( drive
);
730 /***********************************************************************
731 * SetCurrentDirectory32W (KERNEL32.480)
733 BOOL32 WINAPI
SetCurrentDirectory32W( LPCWSTR dirW
)
735 LPSTR dir
= HEAP_strdupWtoA( GetProcessHeap(), 0, dirW
);
736 BOOL32 res
= SetCurrentDirectory32A( dir
);
737 HeapFree( GetProcessHeap(), 0, dir
);
742 /***********************************************************************
743 * GetLogicalDriveStrings32A (KERNEL32.231)
745 UINT32 WINAPI
GetLogicalDriveStrings32A( UINT32 len
, LPSTR buffer
)
749 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
750 if (DRIVE_IsValid(drive
)) count
++;
751 if (count
* 4 * sizeof(char) <= len
)
754 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
755 if (DRIVE_IsValid(drive
))
764 return count
* 4 * sizeof(char);
768 /***********************************************************************
769 * GetLogicalDriveStrings32W (KERNEL32.232)
771 UINT32 WINAPI
GetLogicalDriveStrings32W( UINT32 len
, LPWSTR buffer
)
775 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
776 if (DRIVE_IsValid(drive
)) count
++;
777 if (count
* 4 * sizeof(WCHAR
) <= len
)
780 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
781 if (DRIVE_IsValid(drive
))
783 *p
++ = (WCHAR
)('a' + drive
);
790 return count
* 4 * sizeof(WCHAR
);
794 /***********************************************************************
795 * GetLogicalDrives (KERNEL32.233)
797 DWORD WINAPI
GetLogicalDrives(void)
802 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
803 if (DRIVE_IsValid(drive
)) ret
|= (1 << drive
);
808 /***********************************************************************
809 * GetVolumeInformation32A (KERNEL32.309)
811 BOOL32 WINAPI
GetVolumeInformation32A( LPCSTR root
, LPSTR label
,
812 DWORD label_len
, DWORD
*serial
,
813 DWORD
*filename_len
, DWORD
*flags
,
814 LPSTR fsname
, DWORD fsname_len
)
818 /* FIXME, SetLastErrors missing */
820 if (!root
) drive
= DRIVE_GetCurrentDrive();
823 if ((root
[1] != ':') || (root
[2] != '\\'))
825 fprintf( stderr
, "GetVolumeInformation: invalid root '%s'\n",root
);
828 drive
= toupper(root
[0]) - 'A';
830 if (!DRIVE_IsValid( drive
)) return FALSE
;
831 if (label
) lstrcpyn32A( label
, DOSDrives
[drive
].label
, label_len
);
832 if (serial
) *serial
= DOSDrives
[drive
].serial
;
834 /* Set the filesystem information */
835 /* Note: we only emulate a FAT fs at the present */
837 if (filename_len
) *filename_len
= 12;
838 if (flags
) *flags
= 0;
839 if (fsname
) lstrcpyn32A( fsname
, "FAT", fsname_len
);
844 /***********************************************************************
845 * GetVolumeInformation32W (KERNEL32.310)
847 BOOL32 WINAPI
GetVolumeInformation32W( LPCWSTR root
, LPWSTR label
,
848 DWORD label_len
, DWORD
*serial
,
849 DWORD
*filename_len
, DWORD
*flags
,
850 LPWSTR fsname
, DWORD fsname_len
)
852 LPSTR xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
853 LPSTR xvolname
= label
? HeapAlloc(GetProcessHeap(),0,label_len
) : NULL
;
854 LPSTR xfsname
= fsname
? HeapAlloc(GetProcessHeap(),0,fsname_len
) : NULL
;
855 BOOL32 ret
= GetVolumeInformation32A( xroot
, xvolname
, label_len
, serial
,
856 filename_len
, flags
, xfsname
,
860 if (label
) lstrcpyAtoW( label
, xvolname
);
861 if (fsname
) lstrcpyAtoW( fsname
, xfsname
);
863 HeapFree( GetProcessHeap(), 0, xroot
);
864 HeapFree( GetProcessHeap(), 0, xvolname
);
865 HeapFree( GetProcessHeap(), 0, xfsname
);