2 * DOS drives handling functions
4 * Copyright 1993 Erik Bos
5 * Copyright 1996 Alexandre Julliard
14 #include <sys/types.h>
22 #ifdef HAVE_SYS_PARAM_H
23 # include <sys/param.h>
25 #ifdef HAVE_SYS_MOUNT_H
26 # include <sys/mount.h>
28 #ifdef HAVE_SYS_STATFS_H
29 # include <sys/statfs.h>
44 char *root
; /* root dir in Unix format without trailing / */
45 char *dos_cwd
; /* cwd in DOS format without leading or trailing \ */
46 char *unix_cwd
; /* cwd in Unix format without leading or trailing / */
47 char *device
; /* raw device path */
48 char label
[12]; /* drive label */
49 DWORD serial
; /* drive serial number */
50 DRIVETYPE type
; /* drive type */
51 UINT32 flags
; /* drive flags */
52 dev_t dev
; /* unix device number */
53 ino_t ino
; /* unix inode number */
57 static const char * const DRIVE_Types
[] =
59 "floppy", /* TYPE_FLOPPY */
61 "cdrom", /* TYPE_CDROM */
62 "network" /* TYPE_NETWORK */
66 /* Known filesystem types */
74 static const FS_DESCR DRIVE_Filesystems
[] =
76 { "unix", DRIVE_CASE_SENSITIVE
| DRIVE_CASE_PRESERVING
},
77 { "msdos", DRIVE_SHORT_NAMES
},
78 { "dos", DRIVE_SHORT_NAMES
},
79 { "fat", DRIVE_SHORT_NAMES
},
80 { "vfat", DRIVE_CASE_PRESERVING
},
81 { "win95", DRIVE_CASE_PRESERVING
},
86 static DOSDRIVE DOSDrives
[MAX_DOS_DRIVES
];
87 static int DRIVE_CurDrive
= -1;
89 static HTASK16 DRIVE_LastTask
= 0;
92 /***********************************************************************
95 static DRIVETYPE
DRIVE_GetDriveType( const char *name
)
100 PROFILE_GetWineIniString( name
, "Type", "hd", buffer
, sizeof(buffer
) );
101 for (i
= 0; i
< sizeof(DRIVE_Types
)/sizeof(DRIVE_Types
[0]); i
++)
103 if (!lstrcmpi32A( buffer
, DRIVE_Types
[i
] )) return (DRIVETYPE
)i
;
105 MSG("%s: unknown type '%s', defaulting to 'hd'.\n", name
, buffer
);
110 /***********************************************************************
113 static UINT32
DRIVE_GetFSFlags( const char *name
, const char *value
)
115 const FS_DESCR
*descr
;
117 for (descr
= DRIVE_Filesystems
; descr
->name
; descr
++)
118 if (!lstrcmpi32A( value
, descr
->name
)) return descr
->flags
;
119 MSG("%s: unknown filesystem type '%s', defaulting to 'unix'.\n",
121 return DRIVE_CASE_SENSITIVE
| DRIVE_CASE_PRESERVING
;
125 /***********************************************************************
130 int i
, len
, count
= 0;
131 char name
[] = "Drive A";
132 char path
[MAX_PATHNAME_LEN
];
134 struct stat drive_stat_buffer
;
138 for (i
= 0, drive
= DOSDrives
; i
< MAX_DOS_DRIVES
; i
++, name
[6]++, drive
++)
140 PROFILE_GetWineIniString( name
, "Path", "", path
, sizeof(path
)-1 );
143 p
= path
+ strlen(path
) - 1;
144 while ((p
> path
) && ((*p
== '/') || (*p
== '\\'))) *p
-- = '\0';
145 if (!path
[0]) strcpy( path
, "/" );
147 if (stat( path
, &drive_stat_buffer
))
149 MSG("Could not stat %s, ignoring drive %c:\n", path
, 'A' + i
);
152 if (!S_ISDIR(drive_stat_buffer
.st_mode
))
154 MSG("%s is not a directory, ignoring drive %c:\n",
159 drive
->root
= HEAP_strdupA( SystemHeap
, 0, path
);
160 drive
->dos_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
161 drive
->unix_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
162 drive
->type
= DRIVE_GetDriveType( name
);
163 drive
->device
= NULL
;
165 drive
->dev
= drive_stat_buffer
.st_dev
;
166 drive
->ino
= drive_stat_buffer
.st_ino
;
168 /* Get the drive label */
169 PROFILE_GetWineIniString( name
, "Label", name
, drive
->label
, 12 );
170 if ((len
= strlen(drive
->label
)) < 11)
172 /* Pad label with spaces */
173 memset( drive
->label
+ len
, ' ', 11 - len
);
174 drive
->label
[12] = '\0';
177 /* Get the serial number */
178 PROFILE_GetWineIniString( name
, "Serial", "12345678",
179 buffer
, sizeof(buffer
) );
180 drive
->serial
= strtoul( buffer
, NULL
, 16 );
182 /* Get the filesystem type */
183 PROFILE_GetWineIniString( name
, "Filesystem", "unix",
184 buffer
, sizeof(buffer
) );
185 drive
->flags
= DRIVE_GetFSFlags( name
, buffer
);
188 PROFILE_GetWineIniString( name
, "Device", "",
189 buffer
, sizeof(buffer
) );
191 drive
->device
= HEAP_strdupA( SystemHeap
, 0, buffer
);
193 /* Make the first hard disk the current drive */
194 if ((DRIVE_CurDrive
== -1) && (drive
->type
== TYPE_HD
))
198 TRACE(dosfs
, "%s: path=%s type=%s label='%s' serial=%08lx flags=%08x dev=%x ino=%x\n",
199 name
, path
, DRIVE_Types
[drive
->type
],
200 drive
->label
, drive
->serial
, drive
->flags
,
201 (int)drive
->dev
, (int)drive
->ino
);
203 else WARN(dosfs
, "%s: not defined\n", name
);
208 MSG("Warning: no valid DOS drive found, check your configuration file.\n" );
209 /* Create a C drive pointing to Unix root dir */
210 DOSDrives
[2].root
= HEAP_strdupA( SystemHeap
, 0, "/" );
211 DOSDrives
[2].dos_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
212 DOSDrives
[2].unix_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
213 strcpy( DOSDrives
[2].label
, "Drive C " );
214 DOSDrives
[2].serial
= 0x12345678;
215 DOSDrives
[2].type
= TYPE_HD
;
216 DOSDrives
[2].flags
= 0;
220 /* Make sure the current drive is valid */
221 if (DRIVE_CurDrive
== -1)
223 for (i
= 0, drive
= DOSDrives
; i
< MAX_DOS_DRIVES
; i
++, drive
++)
225 if (drive
->root
&& !(drive
->flags
& DRIVE_DISABLED
))
237 /***********************************************************************
240 int DRIVE_IsValid( int drive
)
242 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
)) return 0;
243 return (DOSDrives
[drive
].root
&&
244 !(DOSDrives
[drive
].flags
& DRIVE_DISABLED
));
248 /***********************************************************************
249 * DRIVE_GetCurrentDrive
251 int DRIVE_GetCurrentDrive(void)
253 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
254 if (pTask
&& (pTask
->curdrive
& 0x80)) return pTask
->curdrive
& ~0x80;
255 return DRIVE_CurDrive
;
259 /***********************************************************************
260 * DRIVE_SetCurrentDrive
262 int DRIVE_SetCurrentDrive( int drive
)
264 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
265 if (!DRIVE_IsValid( drive
))
267 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
270 TRACE(dosfs
, "%c:\n", 'A' + drive
);
271 DRIVE_CurDrive
= drive
;
272 if (pTask
) pTask
->curdrive
= drive
| 0x80;
277 /***********************************************************************
278 * DRIVE_FindDriveRoot
280 * Find a drive for which the root matches the begginning of the given path.
281 * This can be used to translate a Unix path into a drive + DOS path.
282 * Return value is the drive, or -1 on error. On success, path is modified
283 * to point to the beginning of the DOS path.
285 int DRIVE_FindDriveRoot( const char **path
)
287 /* idea: check at all '/' positions.
288 * If the device and inode of that path is identical with the
289 * device and inode of the current drive then we found a solution.
290 * If there is another drive pointing to a deeper position in
291 * the file tree, we want to find that one, not the earlier solution.
293 int drive
, rootdrive
= -1;
294 char buffer
[MAX_PATHNAME_LEN
];
296 const char *p
= *path
;
299 strcpy( buffer
, "/" );
302 if (stat( buffer
, &st
) || !S_ISDIR( st
.st_mode
)) break;
306 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
308 if (!DOSDrives
[drive
].root
||
309 (DOSDrives
[drive
].flags
& DRIVE_DISABLED
)) continue;
311 if ((DOSDrives
[drive
].dev
== st
.st_dev
) &&
312 (DOSDrives
[drive
].ino
== st
.st_ino
))
319 /* Get the next path component */
322 while ((*p
== '/') || (*p
== '\\')) p
++;
324 while (!IS_END_OF_NAME(*p
)) *next
++ = *p
++;
330 TRACE(dosfs
, "%s -> drive %c:, root='%s', name='%s'\n",
331 buffer
, 'A' + rootdrive
,
332 DOSDrives
[rootdrive
].root
, *path
);
337 /***********************************************************************
340 const char * DRIVE_GetRoot( int drive
)
342 if (!DRIVE_IsValid( drive
)) return NULL
;
343 return DOSDrives
[drive
].root
;
347 /***********************************************************************
350 const char * DRIVE_GetDosCwd( int drive
)
352 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
353 if (!DRIVE_IsValid( drive
)) return NULL
;
355 /* Check if we need to change the directory to the new task. */
356 if (pTask
&& (pTask
->curdrive
& 0x80) && /* The task drive is valid */
357 ((pTask
->curdrive
& ~0x80) == drive
) && /* and it's the one we want */
358 (DRIVE_LastTask
!= GetCurrentTask())) /* and the task changed */
360 /* Perform the task-switch */
361 if (!DRIVE_Chdir( drive
, pTask
->curdir
)) DRIVE_Chdir( drive
, "\\" );
362 DRIVE_LastTask
= GetCurrentTask();
364 return DOSDrives
[drive
].dos_cwd
;
368 /***********************************************************************
371 const char * DRIVE_GetUnixCwd( int drive
)
373 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
374 if (!DRIVE_IsValid( drive
)) return NULL
;
376 /* Check if we need to change the directory to the new task. */
377 if (pTask
&& (pTask
->curdrive
& 0x80) && /* The task drive is valid */
378 ((pTask
->curdrive
& ~0x80) == drive
) && /* and it's the one we want */
379 (DRIVE_LastTask
!= GetCurrentTask())) /* and the task changed */
381 /* Perform the task-switch */
382 if (!DRIVE_Chdir( drive
, pTask
->curdir
)) DRIVE_Chdir( drive
, "\\" );
383 DRIVE_LastTask
= GetCurrentTask();
385 return DOSDrives
[drive
].unix_cwd
;
389 /***********************************************************************
392 const char * DRIVE_GetLabel( int drive
)
394 if (!DRIVE_IsValid( drive
)) return NULL
;
395 return DOSDrives
[drive
].label
;
399 /***********************************************************************
400 * DRIVE_GetSerialNumber
402 DWORD
DRIVE_GetSerialNumber( int drive
)
404 if (!DRIVE_IsValid( drive
)) return 0;
405 return DOSDrives
[drive
].serial
;
409 /***********************************************************************
410 * DRIVE_SetSerialNumber
412 int DRIVE_SetSerialNumber( int drive
, DWORD serial
)
414 if (!DRIVE_IsValid( drive
)) return 0;
415 DOSDrives
[drive
].serial
= serial
;
420 /***********************************************************************
423 DRIVETYPE
DRIVE_GetType( int drive
)
425 if (!DRIVE_IsValid( drive
)) return TYPE_INVALID
;
426 return DOSDrives
[drive
].type
;
430 /***********************************************************************
433 UINT32
DRIVE_GetFlags( int drive
)
435 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
)) return 0;
436 return DOSDrives
[drive
].flags
;
440 /***********************************************************************
443 int DRIVE_Chdir( int drive
, const char *path
)
445 DOS_FULL_NAME full_name
;
446 char buffer
[MAX_PATHNAME_LEN
];
448 BY_HANDLE_FILE_INFORMATION info
;
449 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
451 TRACE(dosfs
, "(%c:,%s)\n", 'A' + drive
, path
);
452 strcpy( buffer
, "A:" );
454 lstrcpyn32A( buffer
+ 2, path
, sizeof(buffer
) - 2 );
456 if (!DOSFS_GetFullName( buffer
, TRUE
, &full_name
)) return 0;
457 if (!FILE_Stat( full_name
.long_name
, &info
)) return 0;
458 if (!(info
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
460 DOS_ERROR( ER_FileNotFound
, EC_NotFound
, SA_Abort
, EL_Disk
);
463 unix_cwd
= full_name
.long_name
+ strlen( DOSDrives
[drive
].root
);
464 while (*unix_cwd
== '/') unix_cwd
++;
466 TRACE(dosfs
, "(%c:): unix_cwd=%s dos_cwd=%s\n",
467 'A' + drive
, unix_cwd
, full_name
.short_name
+ 3 );
469 HeapFree( SystemHeap
, 0, DOSDrives
[drive
].dos_cwd
);
470 HeapFree( SystemHeap
, 0, DOSDrives
[drive
].unix_cwd
);
471 DOSDrives
[drive
].dos_cwd
= HEAP_strdupA( SystemHeap
, 0,
472 full_name
.short_name
+ 3 );
473 DOSDrives
[drive
].unix_cwd
= HEAP_strdupA( SystemHeap
, 0, unix_cwd
);
475 if (pTask
&& (pTask
->curdrive
& 0x80) &&
476 ((pTask
->curdrive
& ~0x80) == drive
))
478 lstrcpyn32A( pTask
->curdir
, full_name
.short_name
+ 2,
479 sizeof(pTask
->curdir
) );
480 DRIVE_LastTask
= GetCurrentTask();
486 /***********************************************************************
489 int DRIVE_Disable( int drive
)
491 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
) || !DOSDrives
[drive
].root
)
493 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
496 DOSDrives
[drive
].flags
|= DRIVE_DISABLED
;
501 /***********************************************************************
504 int DRIVE_Enable( int drive
)
506 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
) || !DOSDrives
[drive
].root
)
508 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
511 DOSDrives
[drive
].flags
&= ~DRIVE_DISABLED
;
516 /***********************************************************************
517 * DRIVE_SetLogicalMapping
519 int DRIVE_SetLogicalMapping ( int existing_drive
, int new_drive
)
521 /* If new_drive is already valid, do nothing and return 0
522 otherwise, copy DOSDrives[existing_drive] to DOSDrives[new_drive] */
526 old
= DOSDrives
+ existing_drive
;
527 new = DOSDrives
+ new_drive
;
529 if ((existing_drive
< 0) || (existing_drive
>= MAX_DOS_DRIVES
) ||
531 (new_drive
< 0) || (new_drive
>= MAX_DOS_DRIVES
))
533 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
539 TRACE(dosfs
, "Can\'t map drive %c to drive %c - "
540 "drive %c already exists\n",
541 'A' + existing_drive
, 'A' + new_drive
,
546 new->root
= HEAP_strdupA( SystemHeap
, 0, old
->root
);
547 new->dos_cwd
= HEAP_strdupA( SystemHeap
, 0, old
->dos_cwd
);
548 new->unix_cwd
= HEAP_strdupA( SystemHeap
, 0, old
->unix_cwd
);
549 memcpy ( new->label
, old
->label
, 12 );
550 new->serial
= old
->serial
;
551 new->type
= old
->type
;
552 new->flags
= old
->flags
;
556 TRACE(dosfs
, "Drive %c is now equal to drive %c\n",
557 'A' + new_drive
, 'A' + existing_drive
);
563 /***********************************************************************
566 * Open the drive raw device and return a Unix fd (or -1 on error).
568 int DRIVE_OpenDevice( int drive
, int flags
)
570 if (!DRIVE_IsValid( drive
)) return -1;
571 return open( DOSDrives
[drive
].device
, flags
);
575 /***********************************************************************
578 static int DRIVE_GetFreeSpace( int drive
, DWORD
*size
, DWORD
*available
)
582 if (!DRIVE_IsValid(drive
))
584 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
588 /* FIXME: add autoconf check for this */
589 #if defined(__svr4__) || defined(_SCO_DS)
590 if (statfs( DOSDrives
[drive
].root
, &info
, 0, 0) < 0)
592 if (statfs( DOSDrives
[drive
].root
, &info
) < 0)
596 WARN(dosfs
, "cannot do statfs(%s)\n", DOSDrives
[drive
].root
);
600 *size
= info
.f_bsize
* info
.f_blocks
;
601 #ifdef STATFS_HAS_BAVAIL
602 *available
= info
.f_bavail
* info
.f_bsize
;
604 # ifdef STATFS_HAS_BFREE
605 *available
= info
.f_bfree
* info
.f_bsize
;
607 # error "statfs has no bfree/bavail member!"
614 /***********************************************************************
615 * GetDiskFreeSpace16 (KERNEL.422)
617 BOOL16 WINAPI
GetDiskFreeSpace16( LPCSTR root
, LPDWORD cluster_sectors
,
618 LPDWORD sector_bytes
, LPDWORD free_clusters
,
619 LPDWORD total_clusters
)
621 return GetDiskFreeSpace32A( root
, cluster_sectors
, sector_bytes
,
622 free_clusters
, total_clusters
);
626 /***********************************************************************
627 * GetDiskFreeSpace32A (KERNEL32.206)
629 BOOL32 WINAPI
GetDiskFreeSpace32A( LPCSTR root
, LPDWORD cluster_sectors
,
630 LPDWORD sector_bytes
, LPDWORD free_clusters
,
631 LPDWORD total_clusters
)
634 DWORD size
,available
;
636 if (!root
) drive
= DRIVE_GetCurrentDrive();
639 if ((root
[1]) && ((root
[1] != ':') || (root
[2] != '\\')))
641 WARN(dosfs
, "invalid root '%s'\n", root
);
644 drive
= toupper(root
[0]) - 'A';
646 if (!DRIVE_GetFreeSpace(drive
, &size
, &available
)) return FALSE
;
648 /* Cap the size and available at 2GB as per specs. */
649 if (size
> 0x7fffffff) size
= 0x7fffffff;
650 if (available
> 0x7fffffff) available
= 0x7fffffff;
652 if (DRIVE_GetType(drive
)==TYPE_CDROM
) {
653 *sector_bytes
= 2048;
661 /* fixme: probably have to adjust those variables too for CDFS */
662 *cluster_sectors
= 1;
663 while (*cluster_sectors
* 65536 < size
) *cluster_sectors
*= 2;
664 *free_clusters
= available
/ *cluster_sectors
;
665 *total_clusters
= size
/ *cluster_sectors
;
670 /***********************************************************************
671 * GetDiskFreeSpace32W (KERNEL32.207)
673 BOOL32 WINAPI
GetDiskFreeSpace32W( LPCWSTR root
, LPDWORD cluster_sectors
,
674 LPDWORD sector_bytes
, LPDWORD free_clusters
,
675 LPDWORD total_clusters
)
680 xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
681 ret
= GetDiskFreeSpace32A( xroot
,cluster_sectors
, sector_bytes
,
682 free_clusters
, total_clusters
);
683 HeapFree( GetProcessHeap(), 0, xroot
);
688 /***********************************************************************
689 * GetDiskFreeSpaceEx32A (KERNEL32.871)
691 BOOL32 WINAPI
GetDiskFreeSpaceEx32A( LPCSTR root
,
692 LPULARGE_INTEGER avail
,
693 LPULARGE_INTEGER total
,
694 LPULARGE_INTEGER totalfree
)
697 DWORD size
,available
;
699 if (!root
) drive
= DRIVE_GetCurrentDrive();
702 if ((root
[1]) && ((root
[1] != ':') || (root
[2] != '\\')))
704 WARN(dosfs
, "invalid root '%s'\n", root
);
707 drive
= toupper(root
[0]) - 'A';
709 if (!DRIVE_GetFreeSpace(drive
, &size
, &available
)) return FALSE
;
710 /*FIXME: Do we have the number of bytes available to the user? */
711 avail
->HighPart
= total
->HighPart
= 0;
712 avail
->LowPart
= available
;
713 total
->LowPart
= size
;
716 totalfree
->HighPart
=0;
717 totalfree
->LowPart
= available
;
722 /***********************************************************************
723 * GetDiskFreeSpaceEx32W (KERNEL32.873)
725 BOOL32 WINAPI
GetDiskFreeSpaceEx32W( LPCWSTR root
, LPULARGE_INTEGER avail
,
726 LPULARGE_INTEGER total
,
727 LPULARGE_INTEGER totalfree
)
732 xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
733 ret
= GetDiskFreeSpaceEx32A( xroot
, avail
, total
, totalfree
);
734 HeapFree( GetProcessHeap(), 0, xroot
);
738 /***********************************************************************
739 * GetDriveType16 (KERNEL.136)
741 UINT16 WINAPI
GetDriveType16( UINT16 drive
)
743 TRACE(dosfs
, "(%c:)\n", 'A' + drive
);
744 switch(DRIVE_GetType(drive
))
746 case TYPE_FLOPPY
: return DRIVE_REMOVABLE
;
747 case TYPE_HD
: return DRIVE_FIXED
;
748 case TYPE_CDROM
: return DRIVE_REMOTE
;
749 case TYPE_NETWORK
: return DRIVE_REMOTE
;
751 default: return DRIVE_CANNOTDETERMINE
;
756 /***********************************************************************
757 * GetDriveType32A (KERNEL32.208)
759 UINT32 WINAPI
GetDriveType32A( LPCSTR root
)
761 TRACE(dosfs
, "(%s)\n", root
);
762 if ((root
[1]) && (root
[1] != ':'))
764 WARN(dosfs
, "invalid root '%s'\n", root
);
765 return DRIVE_DOESNOTEXIST
;
767 switch(DRIVE_GetType(toupper(root
[0]) - 'A'))
769 case TYPE_FLOPPY
: return DRIVE_REMOVABLE
;
770 case TYPE_HD
: return DRIVE_FIXED
;
771 case TYPE_CDROM
: return DRIVE_CDROM
;
772 case TYPE_NETWORK
: return DRIVE_REMOTE
;
774 default: return DRIVE_CANNOTDETERMINE
;
779 /***********************************************************************
780 * GetDriveType32W (KERNEL32.209)
782 UINT32 WINAPI
GetDriveType32W( LPCWSTR root
)
784 LPSTR xpath
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
785 UINT32 ret
= GetDriveType32A( xpath
);
786 HeapFree( GetProcessHeap(), 0, xpath
);
791 /***********************************************************************
792 * GetCurrentDirectory16 (KERNEL.411)
794 UINT16 WINAPI
GetCurrentDirectory16( UINT16 buflen
, LPSTR buf
)
796 return (UINT16
)GetCurrentDirectory32A( buflen
, buf
);
800 /***********************************************************************
801 * GetCurrentDirectory32A (KERNEL32.196)
803 * Returns "X:\\path\\etc\\".
805 UINT32 WINAPI
GetCurrentDirectory32A( UINT32 buflen
, LPSTR buf
)
808 const char *s
= DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() );
810 lstrcpyn32A( buf
, pref
, MIN( 4, buflen
) );
811 if (buflen
) buf
[0] += DRIVE_GetCurrentDrive();
812 if (buflen
> 3) lstrcpyn32A( buf
+ 3, s
, buflen
- 3 );
813 return strlen(s
) + 3; /* length of WHOLE current directory */
817 /***********************************************************************
818 * GetCurrentDirectory32W (KERNEL32.197)
820 UINT32 WINAPI
GetCurrentDirectory32W( UINT32 buflen
, LPWSTR buf
)
822 LPSTR xpath
= HeapAlloc( GetProcessHeap(), 0, buflen
+1 );
823 UINT32 ret
= GetCurrentDirectory32A( buflen
, xpath
);
824 lstrcpyAtoW( buf
, xpath
);
825 HeapFree( GetProcessHeap(), 0, xpath
);
830 /***********************************************************************
831 * SetCurrentDirectory (KERNEL.412)
833 BOOL16 WINAPI
SetCurrentDirectory16( LPCSTR dir
)
835 return SetCurrentDirectory32A( dir
);
839 /***********************************************************************
840 * SetCurrentDirectory32A (KERNEL32.479)
842 BOOL32 WINAPI
SetCurrentDirectory32A( LPCSTR dir
)
844 int drive
= DRIVE_GetCurrentDrive();
846 if (dir
[0] && (dir
[1]==':'))
848 drive
= tolower( *dir
) - 'a';
849 if (!DRIVE_IsValid( drive
))
851 DOS_ERROR( ER_InvalidDrive
, EC_MediaError
, SA_Abort
, EL_Disk
);
856 /* FIXME: what about empty strings? Add a \\ ? */
857 if (!DRIVE_Chdir( drive
, dir
)) return FALSE
;
858 if (drive
== DRIVE_GetCurrentDrive()) return TRUE
;
859 return DRIVE_SetCurrentDrive( drive
);
863 /***********************************************************************
864 * SetCurrentDirectory32W (KERNEL32.480)
866 BOOL32 WINAPI
SetCurrentDirectory32W( LPCWSTR dirW
)
868 LPSTR dir
= HEAP_strdupWtoA( GetProcessHeap(), 0, dirW
);
869 BOOL32 res
= SetCurrentDirectory32A( dir
);
870 HeapFree( GetProcessHeap(), 0, dir
);
875 /***********************************************************************
876 * GetLogicalDriveStrings32A (KERNEL32.231)
878 UINT32 WINAPI
GetLogicalDriveStrings32A( UINT32 len
, LPSTR buffer
)
882 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
883 if (DRIVE_IsValid(drive
)) count
++;
884 if (count
* 4 * sizeof(char) <= len
)
887 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
888 if (DRIVE_IsValid(drive
))
897 return count
* 4 * sizeof(char);
901 /***********************************************************************
902 * GetLogicalDriveStrings32W (KERNEL32.232)
904 UINT32 WINAPI
GetLogicalDriveStrings32W( UINT32 len
, LPWSTR buffer
)
908 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
909 if (DRIVE_IsValid(drive
)) count
++;
910 if (count
* 4 * sizeof(WCHAR
) <= len
)
913 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
914 if (DRIVE_IsValid(drive
))
916 *p
++ = (WCHAR
)('a' + drive
);
923 return count
* 4 * sizeof(WCHAR
);
927 /***********************************************************************
928 * GetLogicalDrives (KERNEL32.233)
930 DWORD WINAPI
GetLogicalDrives(void)
935 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
936 if (DRIVE_IsValid(drive
)) ret
|= (1 << drive
);
941 /***********************************************************************
942 * GetVolumeInformation32A (KERNEL32.309)
944 BOOL32 WINAPI
GetVolumeInformation32A( LPCSTR root
, LPSTR label
,
945 DWORD label_len
, DWORD
*serial
,
946 DWORD
*filename_len
, DWORD
*flags
,
947 LPSTR fsname
, DWORD fsname_len
)
951 /* FIXME, SetLastErrors missing */
953 if (!root
) drive
= DRIVE_GetCurrentDrive();
956 if ((root
[1]) && (root
[1] != ':'))
958 WARN(dosfs
, "invalid root '%s'\n",root
);
961 drive
= toupper(root
[0]) - 'A';
963 if (!DRIVE_IsValid( drive
)) return FALSE
;
964 if (label
) lstrcpyn32A( label
, DOSDrives
[drive
].label
, label_len
);
965 if (serial
) *serial
= DOSDrives
[drive
].serial
;
967 /* Set the filesystem information */
968 /* Note: we only emulate a FAT fs at the present */
970 if (filename_len
) *filename_len
= 12;
971 if (flags
) *flags
= 0;
973 /* Diablo checks that return code ... */
974 if (DRIVE_GetType(drive
)==TYPE_CDROM
)
975 lstrcpyn32A( fsname
, "CDFS", fsname_len
);
977 lstrcpyn32A( fsname
, "FAT", fsname_len
);
983 /***********************************************************************
984 * GetVolumeInformation32W (KERNEL32.310)
986 BOOL32 WINAPI
GetVolumeInformation32W( LPCWSTR root
, LPWSTR label
,
987 DWORD label_len
, DWORD
*serial
,
988 DWORD
*filename_len
, DWORD
*flags
,
989 LPWSTR fsname
, DWORD fsname_len
)
991 LPSTR xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
992 LPSTR xvolname
= label
? HeapAlloc(GetProcessHeap(),0,label_len
) : NULL
;
993 LPSTR xfsname
= fsname
? HeapAlloc(GetProcessHeap(),0,fsname_len
) : NULL
;
994 BOOL32 ret
= GetVolumeInformation32A( xroot
, xvolname
, label_len
, serial
,
995 filename_len
, flags
, xfsname
,
999 if (label
) lstrcpyAtoW( label
, xvolname
);
1000 if (fsname
) lstrcpyAtoW( fsname
, xfsname
);
1002 HeapFree( GetProcessHeap(), 0, xroot
);
1003 HeapFree( GetProcessHeap(), 0, xvolname
);
1004 HeapFree( GetProcessHeap(), 0, xfsname
);