2 * DOS drives handling functions
4 * Copyright 1993 Erik Bos
5 * Copyright 1996 Alexandre Julliard
12 #include <sys/types.h>
16 #if defined(__linux__) || defined(sun) || defined(hpux)
19 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
20 #include <sys/param.h>
21 #include <sys/mount.h>
22 #include <sys/errno.h>
24 #if defined(__svr4__) || defined(_SCO_DS) || defined(__EMX__)
25 #include <sys/statfs.h>
40 char *root
; /* root dir in Unix format without trailing / */
41 char *dos_cwd
; /* cwd in DOS format without leading or trailing \ */
42 char *unix_cwd
; /* cwd in Unix format without leading or trailing / */
43 char *device
; /* raw device path */
44 char label
[12]; /* drive label */
45 DWORD serial
; /* drive serial number */
46 DRIVETYPE type
; /* drive type */
47 UINT32 flags
; /* drive flags */
48 dev_t dev
; /* unix device number */
49 ino_t ino
; /* unix inode number */
53 static const char * const DRIVE_Types
[] =
55 "floppy", /* TYPE_FLOPPY */
57 "cdrom", /* TYPE_CDROM */
58 "network" /* TYPE_NETWORK */
62 /* Known filesystem types */
70 static const FS_DESCR DRIVE_Filesystems
[] =
72 { "unix", DRIVE_CASE_SENSITIVE
| DRIVE_CASE_PRESERVING
},
73 { "msdos", DRIVE_SHORT_NAMES
},
74 { "dos", DRIVE_SHORT_NAMES
},
75 { "fat", DRIVE_SHORT_NAMES
},
76 { "vfat", DRIVE_CASE_PRESERVING
},
77 { "win95", DRIVE_CASE_PRESERVING
},
82 static DOSDRIVE DOSDrives
[MAX_DOS_DRIVES
];
83 static int DRIVE_CurDrive
= -1;
85 static HTASK16 DRIVE_LastTask
= 0;
88 /***********************************************************************
91 static DRIVETYPE
DRIVE_GetDriveType( const char *name
)
96 PROFILE_GetWineIniString( name
, "Type", "hd", buffer
, sizeof(buffer
) );
97 for (i
= 0; i
< sizeof(DRIVE_Types
)/sizeof(DRIVE_Types
[0]); i
++)
99 if (!lstrcmpi32A( buffer
, DRIVE_Types
[i
] )) return (DRIVETYPE
)i
;
101 fprintf( stderr
, "%s: unknown type '%s', defaulting to 'hd'.\n",
107 /***********************************************************************
110 static UINT32
DRIVE_GetFSFlags( const char *name
, const char *value
)
112 const FS_DESCR
*descr
;
114 for (descr
= DRIVE_Filesystems
; descr
->name
; descr
++)
115 if (!lstrcmpi32A( value
, descr
->name
)) return descr
->flags
;
116 fprintf( stderr
, "%s: unknown filesystem type '%s', defaulting to 'unix'.\n",
118 return DRIVE_CASE_SENSITIVE
| DRIVE_CASE_PRESERVING
;
122 /***********************************************************************
127 int i
, len
, count
= 0;
128 char name
[] = "Drive A";
129 char path
[MAX_PATHNAME_LEN
];
131 struct stat drive_stat_buffer
;
135 for (i
= 0, drive
= DOSDrives
; i
< MAX_DOS_DRIVES
; i
++, name
[6]++, drive
++)
137 PROFILE_GetWineIniString( name
, "Path", "", path
, sizeof(path
)-1 );
140 p
= path
+ strlen(path
) - 1;
141 while ((p
> path
) && ((*p
== '/') || (*p
== '\\'))) *p
-- = '\0';
142 if (!path
[0]) strcpy( path
, "/" );
144 if (stat( path
, &drive_stat_buffer
))
146 fprintf( stderr
, "Could not stat %s, ignoring drive %c:\n",
150 if (!S_ISDIR(drive_stat_buffer
.st_mode
))
152 fprintf( stderr
, "%s is not a directory, ignoring drive %c:\n",
157 drive
->root
= HEAP_strdupA( SystemHeap
, 0, path
);
158 drive
->dos_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
159 drive
->unix_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
160 drive
->type
= DRIVE_GetDriveType( name
);
161 drive
->device
= NULL
;
163 drive
->dev
= drive_stat_buffer
.st_dev
;
164 drive
->ino
= drive_stat_buffer
.st_ino
;
166 /* Get the drive label */
167 PROFILE_GetWineIniString( name
, "Label", name
, drive
->label
, 12 );
168 if ((len
= strlen(drive
->label
)) < 11)
170 /* Pad label with spaces */
171 memset( drive
->label
+ len
, ' ', 11 - len
);
172 drive
->label
[12] = '\0';
175 /* Get the serial number */
176 PROFILE_GetWineIniString( name
, "Serial", "12345678",
177 buffer
, sizeof(buffer
) );
178 drive
->serial
= strtoul( buffer
, NULL
, 16 );
180 /* Get the filesystem type */
181 PROFILE_GetWineIniString( name
, "Filesystem", "unix",
182 buffer
, sizeof(buffer
) );
183 drive
->flags
= DRIVE_GetFSFlags( name
, buffer
);
186 PROFILE_GetWineIniString( name
, "Device", "",
187 buffer
, sizeof(buffer
) );
189 drive
->device
= HEAP_strdupA( SystemHeap
, 0, buffer
);
191 /* Make the first hard disk the current drive */
192 if ((DRIVE_CurDrive
== -1) && (drive
->type
== TYPE_HD
))
196 dprintf_info(dosfs
, "%s: path=%s type=%s label='%s' serial=%08lx flags=%08x dev=%x ino=%x\n",
197 name
, path
, DRIVE_Types
[drive
->type
],
198 drive
->label
, drive
->serial
, drive
->flags
,
199 (int)drive
->dev
, (int)drive
->ino
);
201 else dprintf_warn(dosfs
, "%s: not defined\n", name
);
206 fprintf( stderr
, "Warning: no valid DOS drive found, check your configuration file.\n" );
207 /* Create a C drive pointing to Unix root dir */
208 DOSDrives
[2].root
= HEAP_strdupA( SystemHeap
, 0, "/" );
209 DOSDrives
[2].dos_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
210 DOSDrives
[2].unix_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
211 strcpy( DOSDrives
[2].label
, "Drive C " );
212 DOSDrives
[2].serial
= 0x12345678;
213 DOSDrives
[2].type
= TYPE_HD
;
214 DOSDrives
[2].flags
= 0;
218 /* Make sure the current drive is valid */
219 if (DRIVE_CurDrive
== -1)
221 for (i
= 0, drive
= DOSDrives
; i
< MAX_DOS_DRIVES
; i
++, drive
++)
223 if (drive
->root
&& !(drive
->flags
& DRIVE_DISABLED
))
235 /***********************************************************************
238 int DRIVE_IsValid( int drive
)
240 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
)) return 0;
241 return (DOSDrives
[drive
].root
&&
242 !(DOSDrives
[drive
].flags
& DRIVE_DISABLED
));
246 /***********************************************************************
247 * DRIVE_GetCurrentDrive
249 int DRIVE_GetCurrentDrive(void)
251 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
252 if (pTask
&& (pTask
->curdrive
& 0x80)) return pTask
->curdrive
& ~0x80;
253 return DRIVE_CurDrive
;
257 /***********************************************************************
258 * DRIVE_SetCurrentDrive
260 int DRIVE_SetCurrentDrive( int drive
)
262 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
263 if (!DRIVE_IsValid( drive
))
265 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
268 dprintf_info(dosfs
, "DRIVE_SetCurrentDrive: %c:\n", 'A' + drive
);
269 DRIVE_CurDrive
= drive
;
270 if (pTask
) pTask
->curdrive
= drive
| 0x80;
275 /***********************************************************************
276 * DRIVE_FindDriveRoot
278 * Find a drive for which the root matches the begginning of the given path.
279 * This can be used to translate a Unix path into a drive + DOS path.
280 * Return value is the drive, or -1 on error. On success, path is modified
281 * to point to the beginning of the DOS path.
283 int DRIVE_FindDriveRoot( const char **path
)
285 /* idea: check at all '/' positions.
286 * If the device and inode of that path is identical with the
287 * device and inode of the current drive then we found a solution.
288 * If there is another drive pointing to a deeper position in
289 * the file tree, we want to find that one, not the earlier solution.
291 int drive
, rootdrive
= -1;
292 char buffer
[MAX_PATHNAME_LEN
];
294 const char *p
= *path
;
297 strcpy( buffer
, "/" );
300 if (stat( buffer
, &st
) || !S_ISDIR( st
.st_mode
)) break;
304 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
306 if (!DOSDrives
[drive
].root
||
307 (DOSDrives
[drive
].flags
& DRIVE_DISABLED
)) continue;
309 if ((DOSDrives
[drive
].dev
== st
.st_dev
) &&
310 (DOSDrives
[drive
].ino
== st
.st_ino
))
317 /* Get the next path component */
320 while ((*p
== '/') || (*p
== '\\')) p
++;
322 while (!IS_END_OF_NAME(*p
)) *next
++ = *p
++;
328 dprintf_info(dosfs
, "DRIVE_FindDriveRoot: %s -> drive %c:, root='%s', name='%s'\n",
329 buffer
, 'A' + rootdrive
,
330 DOSDrives
[rootdrive
].root
, *path
);
335 /***********************************************************************
338 const char * DRIVE_GetRoot( int drive
)
340 if (!DRIVE_IsValid( drive
)) return NULL
;
341 return DOSDrives
[drive
].root
;
345 /***********************************************************************
348 const char * DRIVE_GetDosCwd( int drive
)
350 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
351 if (!DRIVE_IsValid( drive
)) return NULL
;
353 /* Check if we need to change the directory to the new task. */
354 if (pTask
&& (pTask
->curdrive
& 0x80) && /* The task drive is valid */
355 ((pTask
->curdrive
& ~0x80) == drive
) && /* and it's the one we want */
356 (DRIVE_LastTask
!= GetCurrentTask())) /* and the task changed */
358 /* Perform the task-switch */
359 if (!DRIVE_Chdir( drive
, pTask
->curdir
)) DRIVE_Chdir( drive
, "\\" );
360 DRIVE_LastTask
= GetCurrentTask();
362 return DOSDrives
[drive
].dos_cwd
;
366 /***********************************************************************
369 const char * DRIVE_GetUnixCwd( int drive
)
371 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
372 if (!DRIVE_IsValid( drive
)) return NULL
;
374 /* Check if we need to change the directory to the new task. */
375 if (pTask
&& (pTask
->curdrive
& 0x80) && /* The task drive is valid */
376 ((pTask
->curdrive
& ~0x80) == drive
) && /* and it's the one we want */
377 (DRIVE_LastTask
!= GetCurrentTask())) /* and the task changed */
379 /* Perform the task-switch */
380 if (!DRIVE_Chdir( drive
, pTask
->curdir
)) DRIVE_Chdir( drive
, "\\" );
381 DRIVE_LastTask
= GetCurrentTask();
383 return DOSDrives
[drive
].unix_cwd
;
387 /***********************************************************************
390 const char * DRIVE_GetLabel( int drive
)
392 if (!DRIVE_IsValid( drive
)) return NULL
;
393 return DOSDrives
[drive
].label
;
397 /***********************************************************************
398 * DRIVE_GetSerialNumber
400 DWORD
DRIVE_GetSerialNumber( int drive
)
402 if (!DRIVE_IsValid( drive
)) return 0;
403 return DOSDrives
[drive
].serial
;
407 /***********************************************************************
408 * DRIVE_SetSerialNumber
410 int DRIVE_SetSerialNumber( int drive
, DWORD serial
)
412 if (!DRIVE_IsValid( drive
)) return 0;
413 DOSDrives
[drive
].serial
= serial
;
418 /***********************************************************************
421 DRIVETYPE
DRIVE_GetType( int drive
)
423 if (!DRIVE_IsValid( drive
)) return TYPE_INVALID
;
424 return DOSDrives
[drive
].type
;
428 /***********************************************************************
431 UINT32
DRIVE_GetFlags( int drive
)
433 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
)) return 0;
434 return DOSDrives
[drive
].flags
;
438 /***********************************************************************
441 int DRIVE_Chdir( int drive
, const char *path
)
443 DOS_FULL_NAME full_name
;
444 char buffer
[MAX_PATHNAME_LEN
];
446 BY_HANDLE_FILE_INFORMATION info
;
447 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
449 dprintf_info(dosfs
, "DRIVE_Chdir(%c:,%s)\n", 'A' + drive
, path
);
450 strcpy( buffer
, "A:" );
452 lstrcpyn32A( buffer
+ 2, path
, sizeof(buffer
) - 2 );
454 if (!DOSFS_GetFullName( buffer
, TRUE
, &full_name
)) return 0;
455 if (!FILE_Stat( full_name
.long_name
, &info
)) return 0;
456 if (!(info
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
458 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
461 unix_cwd
= full_name
.long_name
+ strlen( DOSDrives
[drive
].root
);
462 while (*unix_cwd
== '/') unix_cwd
++;
464 dprintf_info(dosfs
, "DRIVE_Chdir(%c:): unix_cwd=%s dos_cwd=%s\n",
465 'A' + drive
, unix_cwd
, full_name
.short_name
+ 3 );
467 HeapFree( SystemHeap
, 0, DOSDrives
[drive
].dos_cwd
);
468 HeapFree( SystemHeap
, 0, DOSDrives
[drive
].unix_cwd
);
469 DOSDrives
[drive
].dos_cwd
= HEAP_strdupA( SystemHeap
, 0,
470 full_name
.short_name
+ 3 );
471 DOSDrives
[drive
].unix_cwd
= HEAP_strdupA( SystemHeap
, 0, unix_cwd
);
473 if (pTask
&& (pTask
->curdrive
& 0x80) &&
474 ((pTask
->curdrive
& ~0x80) == drive
))
476 lstrcpyn32A( pTask
->curdir
, full_name
.short_name
+ 2,
477 sizeof(pTask
->curdir
) );
478 DRIVE_LastTask
= GetCurrentTask();
484 /***********************************************************************
487 int DRIVE_Disable( int drive
)
489 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
) || !DOSDrives
[drive
].root
)
491 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
494 DOSDrives
[drive
].flags
|= DRIVE_DISABLED
;
499 /***********************************************************************
502 int DRIVE_Enable( int drive
)
504 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
) || !DOSDrives
[drive
].root
)
506 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
509 DOSDrives
[drive
].flags
&= ~DRIVE_DISABLED
;
514 /***********************************************************************
515 * DRIVE_SetLogicalMapping
517 int DRIVE_SetLogicalMapping ( int existing_drive
, int new_drive
)
519 /* If new_drive is already valid, do nothing and return 0
520 otherwise, copy DOSDrives[existing_drive] to DOSDrives[new_drive] */
524 old
= DOSDrives
+ existing_drive
;
525 new = DOSDrives
+ new_drive
;
527 if ((existing_drive
< 0) || (existing_drive
>= MAX_DOS_DRIVES
) ||
529 (new_drive
< 0) || (new_drive
>= MAX_DOS_DRIVES
))
531 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
537 dprintf_info(dosfs
, "Can\'t map drive %c to drive %c - "
538 "drive %c already exists\n",
539 'A' + existing_drive
, 'A' + new_drive
,
544 new->root
= HEAP_strdupA( SystemHeap
, 0, old
->root
);
545 new->dos_cwd
= HEAP_strdupA( SystemHeap
, 0, old
->dos_cwd
);
546 new->unix_cwd
= HEAP_strdupA( SystemHeap
, 0, old
->unix_cwd
);
547 memcpy ( new->label
, old
->label
, 12 );
548 new->serial
= old
->serial
;
549 new->type
= old
->type
;
550 new->flags
= old
->flags
;
554 dprintf_info(dosfs
, "Drive %c is now equal to drive %c\n",
555 'A' + new_drive
, 'A' + existing_drive
);
561 /***********************************************************************
564 * Open the drive raw device and return a Unix fd (or -1 on error).
566 int DRIVE_OpenDevice( int drive
, int flags
)
568 if (!DRIVE_IsValid( drive
)) return -1;
569 return open( DOSDrives
[drive
].device
, flags
);
573 /***********************************************************************
576 static int DRIVE_GetFreeSpace( int drive
, DWORD
*size
, DWORD
*available
)
580 if (!DRIVE_IsValid(drive
))
582 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
586 #if defined(__svr4__) || defined(_SCO_DS)
587 if (statfs( DOSDrives
[drive
].root
, &info
, 0, 0) < 0)
589 if (statfs( DOSDrives
[drive
].root
, &info
) < 0)
593 fprintf(stderr
,"dosfs: cannot do statfs(%s)\n", DOSDrives
[drive
].root
);
597 *size
= info
.f_bsize
* info
.f_blocks
;
598 #if defined(__svr4__) || defined(_SCO_DS) || defined(__EMX__)
599 *available
= info
.f_bfree
* info
.f_bsize
;
601 *available
= info
.f_bavail
* info
.f_bsize
;
607 /***********************************************************************
608 * GetDiskFreeSpace16 (KERNEL.422)
610 BOOL16 WINAPI
GetDiskFreeSpace16( LPCSTR root
, LPDWORD cluster_sectors
,
611 LPDWORD sector_bytes
, LPDWORD free_clusters
,
612 LPDWORD total_clusters
)
614 return GetDiskFreeSpace32A( root
, cluster_sectors
, sector_bytes
,
615 free_clusters
, total_clusters
);
619 /***********************************************************************
620 * GetDiskFreeSpace32A (KERNEL32.206)
622 BOOL32 WINAPI
GetDiskFreeSpace32A( LPCSTR root
, LPDWORD cluster_sectors
,
623 LPDWORD sector_bytes
, LPDWORD free_clusters
,
624 LPDWORD total_clusters
)
627 DWORD size
,available
;
629 if (!root
) drive
= DRIVE_GetCurrentDrive();
632 if ((root
[1]) && ((root
[1] != ':') || (root
[2] != '\\')))
634 fprintf( stderr
, "GetDiskFreeSpaceA: invalid root '%s'\n", root
);
637 drive
= toupper(root
[0]) - 'A';
639 if (!DRIVE_GetFreeSpace(drive
, &size
, &available
)) return FALSE
;
641 /* Cap the size and available at 2GB as per specs. */
642 if (size
> 0x7fffffff) size
= 0x7fffffff;
643 if (available
> 0x7fffffff) available
= 0x7fffffff;
645 if (DRIVE_GetType(drive
)==TYPE_CDROM
) {
646 *sector_bytes
= 2048;
654 /* fixme: probably have to adjust those variables too for CDFS */
655 *cluster_sectors
= 1;
656 while (*cluster_sectors
* 65530 < size
) *cluster_sectors
*= 2;
657 *free_clusters
= available
/ *cluster_sectors
;
658 *total_clusters
= size
/ *cluster_sectors
;
663 /***********************************************************************
664 * GetDiskFreeSpace32W (KERNEL32.207)
666 BOOL32 WINAPI
GetDiskFreeSpace32W( LPCWSTR root
, LPDWORD cluster_sectors
,
667 LPDWORD sector_bytes
, LPDWORD free_clusters
,
668 LPDWORD total_clusters
)
673 xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
674 ret
= GetDiskFreeSpace32A( xroot
,cluster_sectors
, sector_bytes
,
675 free_clusters
, total_clusters
);
676 HeapFree( GetProcessHeap(), 0, xroot
);
681 /***********************************************************************
682 * GetDiskFreeSpaceEx32A (KERNEL32.871)
684 BOOL32 WINAPI
GetDiskFreeSpaceEx32A( LPCSTR root
,
685 LPULARGE_INTEGER avail
,
686 LPULARGE_INTEGER total
,
687 LPULARGE_INTEGER totalfree
)
690 DWORD size
,available
;
692 if (!root
) drive
= DRIVE_GetCurrentDrive();
695 if ((root
[1]) && ((root
[1] != ':') || (root
[2] != '\\')))
697 fprintf( stderr
, "GetDiskFreeSpaceExA: invalid root '%s'\n",
701 drive
= toupper(root
[0]) - 'A';
703 if (!DRIVE_GetFreeSpace(drive
, &size
, &available
)) return FALSE
;
704 /*FIXME: Do we have the number of bytes available to the user? */
705 avail
->HighPart
= total
->HighPart
= 0;
706 avail
->LowPart
= available
;
707 total
->LowPart
= size
;
710 totalfree
->HighPart
=0;
711 totalfree
->LowPart
= available
;
716 /***********************************************************************
717 * GetDiskFreeSpaceEx32W (KERNEL32.873)
719 BOOL32 WINAPI
GetDiskFreeSpaceEx32W( LPCWSTR root
, LPULARGE_INTEGER avail
,
720 LPULARGE_INTEGER total
,
721 LPULARGE_INTEGER totalfree
)
726 xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
727 ret
= GetDiskFreeSpaceEx32A( xroot
, avail
, total
, totalfree
);
728 HeapFree( GetProcessHeap(), 0, xroot
);
732 /***********************************************************************
733 * GetDriveType16 (KERNEL.136)
735 UINT16 WINAPI
GetDriveType16( UINT16 drive
)
737 dprintf_info(dosfs
, "GetDriveType16(%c:)\n", 'A' + drive
);
738 switch(DRIVE_GetType(drive
))
740 case TYPE_FLOPPY
: return DRIVE_REMOVABLE
;
741 case TYPE_HD
: return DRIVE_FIXED
;
742 case TYPE_CDROM
: return DRIVE_REMOTE
;
743 case TYPE_NETWORK
: return DRIVE_REMOTE
;
745 default: return DRIVE_CANNOTDETERMINE
;
750 /***********************************************************************
751 * GetDriveType32A (KERNEL32.208)
753 UINT32 WINAPI
GetDriveType32A( LPCSTR root
)
755 dprintf_info(dosfs
, "GetDriveType32A(%s)\n", root
);
756 if ((root
[1]) && (root
[1] != ':'))
758 fprintf( stderr
, "GetDriveType32A: invalid root '%s'\n", root
);
759 return DRIVE_DOESNOTEXIST
;
761 switch(DRIVE_GetType(toupper(root
[0]) - 'A'))
763 case TYPE_FLOPPY
: return DRIVE_REMOVABLE
;
764 case TYPE_HD
: return DRIVE_FIXED
;
765 case TYPE_CDROM
: return DRIVE_CDROM
;
766 case TYPE_NETWORK
: return DRIVE_REMOTE
;
768 default: return DRIVE_CANNOTDETERMINE
;
773 /***********************************************************************
774 * GetDriveType32W (KERNEL32.209)
776 UINT32 WINAPI
GetDriveType32W( LPCWSTR root
)
778 LPSTR xpath
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
779 UINT32 ret
= GetDriveType32A( xpath
);
780 HeapFree( GetProcessHeap(), 0, xpath
);
785 /***********************************************************************
786 * GetCurrentDirectory16 (KERNEL.411)
788 UINT16 WINAPI
GetCurrentDirectory16( UINT16 buflen
, LPSTR buf
)
790 return (UINT16
)GetCurrentDirectory32A( buflen
, buf
);
794 /***********************************************************************
795 * GetCurrentDirectory32A (KERNEL32.196)
797 * Returns "X:\\path\\etc\\".
799 UINT32 WINAPI
GetCurrentDirectory32A( UINT32 buflen
, LPSTR buf
)
802 const char *s
= DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() );
804 lstrcpyn32A( buf
, pref
, MIN( 4, buflen
) );
805 if (buflen
) buf
[0] += DRIVE_GetCurrentDrive();
806 if (buflen
> 3) lstrcpyn32A( buf
+ 3, s
, buflen
- 3 );
807 return strlen(s
) + 3; /* length of WHOLE current directory */
811 /***********************************************************************
812 * GetCurrentDirectory32W (KERNEL32.197)
814 UINT32 WINAPI
GetCurrentDirectory32W( UINT32 buflen
, LPWSTR buf
)
816 LPSTR xpath
= HeapAlloc( GetProcessHeap(), 0, buflen
+1 );
817 UINT32 ret
= GetCurrentDirectory32A( buflen
, xpath
);
818 lstrcpyAtoW( buf
, xpath
);
819 HeapFree( GetProcessHeap(), 0, xpath
);
824 /***********************************************************************
825 * SetCurrentDirectory (KERNEL.412)
827 BOOL16 WINAPI
SetCurrentDirectory16( LPCSTR dir
)
829 return SetCurrentDirectory32A( dir
);
833 /***********************************************************************
834 * SetCurrentDirectory32A (KERNEL32.479)
836 BOOL32 WINAPI
SetCurrentDirectory32A( LPCSTR dir
)
838 int drive
= DRIVE_GetCurrentDrive();
840 if (dir
[0] && (dir
[1]==':'))
842 drive
= tolower( *dir
) - 'a';
843 if (!DRIVE_IsValid( drive
))
845 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
850 /* FIXME: what about empty strings? Add a \\ ? */
851 if (!DRIVE_Chdir( drive
, dir
)) return FALSE
;
852 if (drive
== DRIVE_GetCurrentDrive()) return TRUE
;
853 return DRIVE_SetCurrentDrive( drive
);
857 /***********************************************************************
858 * SetCurrentDirectory32W (KERNEL32.480)
860 BOOL32 WINAPI
SetCurrentDirectory32W( LPCWSTR dirW
)
862 LPSTR dir
= HEAP_strdupWtoA( GetProcessHeap(), 0, dirW
);
863 BOOL32 res
= SetCurrentDirectory32A( dir
);
864 HeapFree( GetProcessHeap(), 0, dir
);
869 /***********************************************************************
870 * GetLogicalDriveStrings32A (KERNEL32.231)
872 UINT32 WINAPI
GetLogicalDriveStrings32A( UINT32 len
, LPSTR buffer
)
876 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
877 if (DRIVE_IsValid(drive
)) count
++;
878 if (count
* 4 * sizeof(char) <= len
)
881 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
882 if (DRIVE_IsValid(drive
))
891 return count
* 4 * sizeof(char);
895 /***********************************************************************
896 * GetLogicalDriveStrings32W (KERNEL32.232)
898 UINT32 WINAPI
GetLogicalDriveStrings32W( UINT32 len
, LPWSTR buffer
)
902 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
903 if (DRIVE_IsValid(drive
)) count
++;
904 if (count
* 4 * sizeof(WCHAR
) <= len
)
907 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
908 if (DRIVE_IsValid(drive
))
910 *p
++ = (WCHAR
)('a' + drive
);
917 return count
* 4 * sizeof(WCHAR
);
921 /***********************************************************************
922 * GetLogicalDrives (KERNEL32.233)
924 DWORD WINAPI
GetLogicalDrives(void)
929 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
930 if (DRIVE_IsValid(drive
)) ret
|= (1 << drive
);
935 /***********************************************************************
936 * GetVolumeInformation32A (KERNEL32.309)
938 BOOL32 WINAPI
GetVolumeInformation32A( LPCSTR root
, LPSTR label
,
939 DWORD label_len
, DWORD
*serial
,
940 DWORD
*filename_len
, DWORD
*flags
,
941 LPSTR fsname
, DWORD fsname_len
)
945 /* FIXME, SetLastErrors missing */
947 if (!root
) drive
= DRIVE_GetCurrentDrive();
950 if ((root
[1]) && (root
[1] != ':'))
952 fprintf( stderr
, "GetVolumeInformation: invalid root '%s'\n",root
);
955 drive
= toupper(root
[0]) - 'A';
957 if (!DRIVE_IsValid( drive
)) return FALSE
;
958 if (label
) lstrcpyn32A( label
, DOSDrives
[drive
].label
, label_len
);
959 if (serial
) *serial
= DOSDrives
[drive
].serial
;
961 /* Set the filesystem information */
962 /* Note: we only emulate a FAT fs at the present */
964 if (filename_len
) *filename_len
= 12;
965 if (flags
) *flags
= 0;
967 /* Diablo checks that return code ... */
968 if (DRIVE_GetType(drive
)==TYPE_CDROM
)
969 lstrcpyn32A( fsname
, "CDFS", fsname_len
);
971 lstrcpyn32A( fsname
, "FAT", fsname_len
);
977 /***********************************************************************
978 * GetVolumeInformation32W (KERNEL32.310)
980 BOOL32 WINAPI
GetVolumeInformation32W( LPCWSTR root
, LPWSTR label
,
981 DWORD label_len
, DWORD
*serial
,
982 DWORD
*filename_len
, DWORD
*flags
,
983 LPWSTR fsname
, DWORD fsname_len
)
985 LPSTR xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
986 LPSTR xvolname
= label
? HeapAlloc(GetProcessHeap(),0,label_len
) : NULL
;
987 LPSTR xfsname
= fsname
? HeapAlloc(GetProcessHeap(),0,fsname_len
) : NULL
;
988 BOOL32 ret
= GetVolumeInformation32A( xroot
, xvolname
, label_len
, serial
,
989 filename_len
, flags
, xfsname
,
993 if (label
) lstrcpyAtoW( label
, xvolname
);
994 if (fsname
) lstrcpyAtoW( fsname
, xfsname
);
996 HeapFree( GetProcessHeap(), 0, xroot
);
997 HeapFree( GetProcessHeap(), 0, xvolname
);
998 HeapFree( GetProcessHeap(), 0, xfsname
);