2 * DOS drives handling functions
4 * Copyright 1993 Erik Bos
5 * Copyright 1996 Alexandre Julliard
12 #include <sys/types.h>
15 #if defined(__linux__) || defined(sun) || defined(hpux)
18 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
19 #include <sys/param.h>
20 #include <sys/mount.h>
21 #include <sys/errno.h>
23 #if defined(__svr4__) || defined(_SCO_DS) || defined(__EMX__)
24 #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 label[12]; /* drive label */
44 DWORD serial; /* drive serial number */
45 DRIVETYPE type; /* drive type */
46 UINT32 flags; /* drive flags */
47 dev_t dev; /* unix device number */
48 ino_t ino; /* unix inode number */
52 static const char * const DRIVE_Types[] =
54 "floppy", /* TYPE_FLOPPY */
56 "cdrom", /* TYPE_CDROM */
57 "network" /* TYPE_NETWORK */
61 /* Known filesystem types */
69 static const FS_DESCR DRIVE_Filesystems[] =
71 { "unix", DRIVE_CASE_SENSITIVE | DRIVE_CASE_PRESERVING },
72 { "msdos", DRIVE_SHORT_NAMES },
73 { "dos", DRIVE_SHORT_NAMES },
74 { "fat", DRIVE_SHORT_NAMES },
75 { "vfat", DRIVE_CASE_PRESERVING },
76 { "win95", DRIVE_CASE_PRESERVING },
81 static DOSDRIVE DOSDrives[MAX_DOS_DRIVES];
82 static int DRIVE_CurDrive = -1;
84 static HTASK16 DRIVE_LastTask = 0;
87 /***********************************************************************
90 static DRIVETYPE DRIVE_GetDriveType( const char *name )
95 PROFILE_GetWineIniString( name, "Type", "hd", buffer, sizeof(buffer) );
96 for (i = 0; i < sizeof(DRIVE_Types)/sizeof(DRIVE_Types[0]); i++)
98 if (!lstrcmpi32A( buffer, DRIVE_Types[i] )) return (DRIVETYPE)i;
100 fprintf( stderr, "%s: unknown type '%s', defaulting to 'hd'.\n",
106 /***********************************************************************
109 static UINT32 DRIVE_GetFSFlags( const char *name, const char *value )
111 const FS_DESCR *descr;
113 for (descr = DRIVE_Filesystems; descr->name; descr++)
114 if (!lstrcmpi32A( value, descr->name )) return descr->flags;
115 fprintf( stderr, "%s: unknown filesystem type '%s', defaulting to 'unix'.\n",
117 return DRIVE_CASE_SENSITIVE | DRIVE_CASE_PRESERVING;
121 /***********************************************************************
126 int i, len, count = 0;
127 char name[] = "Drive A";
128 char path[MAX_PATHNAME_LEN];
130 struct stat drive_stat_buffer;
134 for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, name[6]++, drive++)
136 PROFILE_GetWineIniString( name, "Path", "", path, sizeof(path)-1 );
139 p = path + strlen(path) - 1;
140 while ((p > path) && ((*p == '/') || (*p == '\\'))) *p-- = '\0';
141 if (!path[0]) strcpy( path, "/" );
143 if (stat( path, &drive_stat_buffer ))
145 fprintf( stderr, "Could not stat %s, ignoring drive %c:\n",
149 if (!S_ISDIR(drive_stat_buffer.st_mode))
151 fprintf( stderr, "%s is not a directory, ignoring drive %c:\n",
156 drive->root = HEAP_strdupA( SystemHeap, 0, path );
157 drive->dos_cwd = HEAP_strdupA( SystemHeap, 0, "" );
158 drive->unix_cwd = HEAP_strdupA( SystemHeap, 0, "" );
159 drive->type = DRIVE_GetDriveType( name );
161 drive->dev = drive_stat_buffer.st_dev;
162 drive->ino = drive_stat_buffer.st_ino;
164 /* Get the drive label */
165 PROFILE_GetWineIniString( name, "Label", name, drive->label, 12 );
166 if ((len = strlen(drive->label)) < 11)
168 /* Pad label with spaces */
169 memset( drive->label + len, ' ', 11 - len );
170 drive->label[12] = '\0';
173 /* Get the serial number */
174 PROFILE_GetWineIniString( name, "Serial", "12345678",
175 buffer, sizeof(buffer) );
176 drive->serial = strtoul( buffer, NULL, 16 );
178 /* Get the filesystem type */
179 PROFILE_GetWineIniString( name, "Filesystem", "unix",
180 buffer, sizeof(buffer) );
181 drive->flags = DRIVE_GetFSFlags( name, buffer );
183 /* Make the first hard disk the current drive */
184 if ((DRIVE_CurDrive == -1) && (drive->type == TYPE_HD))
188 dprintf_dosfs( stddeb, "%s: path=%s type=%s label='%s' serial=%08lx flags=%08x dev=%x ino=%x\n",
189 name, path, DRIVE_Types[drive->type],
190 drive->label, drive->serial, drive->flags,
191 (int)drive->dev, (int)drive->ino );
193 else dprintf_dosfs( stddeb, "%s: not defined\n", name );
198 fprintf( stderr, "Warning: no valid DOS drive found, check your configuration file.\n" );
199 /* Create a C drive pointing to Unix root dir */
200 DOSDrives[2].root = HEAP_strdupA( SystemHeap, 0, "/" );
201 DOSDrives[2].dos_cwd = HEAP_strdupA( SystemHeap, 0, "" );
202 DOSDrives[2].unix_cwd = HEAP_strdupA( SystemHeap, 0, "" );
203 strcpy( DOSDrives[2].label, "Drive C " );
204 DOSDrives[2].serial = 0x12345678;
205 DOSDrives[2].type = TYPE_HD;
206 DOSDrives[2].flags = 0;
210 /* Make sure the current drive is valid */
211 if (DRIVE_CurDrive == -1)
213 for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, drive++)
215 if (drive->root && !(drive->flags & DRIVE_DISABLED))
227 /***********************************************************************
230 int DRIVE_IsValid( int drive )
232 if ((drive < 0) || (drive >= MAX_DOS_DRIVES)) return 0;
233 return (DOSDrives[drive].root &&
234 !(DOSDrives[drive].flags & DRIVE_DISABLED));
238 /***********************************************************************
239 * DRIVE_GetCurrentDrive
241 int DRIVE_GetCurrentDrive(void)
243 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
244 if (pTask && (pTask->curdrive & 0x80)) return pTask->curdrive & ~0x80;
245 return DRIVE_CurDrive;
249 /***********************************************************************
250 * DRIVE_SetCurrentDrive
252 int DRIVE_SetCurrentDrive( int drive )
254 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
255 if (!DRIVE_IsValid( drive ))
257 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
260 dprintf_dosfs( stddeb, "DRIVE_SetCurrentDrive: %c:\n", 'A' + drive );
261 DRIVE_CurDrive = drive;
262 if (pTask) pTask->curdrive = drive | 0x80;
267 /***********************************************************************
268 * DRIVE_FindDriveRoot
270 * Find a drive for which the root matches the begginning of the given path.
271 * This can be used to translate a Unix path into a drive + DOS path.
272 * Return value is the drive, or -1 on error. On success, path is modified
273 * to point to the beginning of the DOS path.
275 int DRIVE_FindDriveRoot( const char **path )
277 /* idea: check at all '/' positions.
278 * If the device and inode of that path is identical with the
279 * device and inode of the current drive then we found a solution.
280 * If there is another drive pointing to a deeper position in
281 * the file tree, we want to find that one, not the earlier solution.
283 int drive, rootdrive = -1;
284 char buffer[MAX_PATHNAME_LEN];
286 const char *p = *path;
289 strcpy( buffer, "/" );
292 if (stat( buffer, &st ) || !S_ISDIR( st.st_mode )) break;
296 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
298 if (!DOSDrives[drive].root ||
299 (DOSDrives[drive].flags & DRIVE_DISABLED)) continue;
301 if ((DOSDrives[drive].dev == st.st_dev) &&
302 (DOSDrives[drive].ino == st.st_ino))
309 /* Get the next path component */
312 while ((*p == '/') || (*p == '\\')) p++;
314 while (!IS_END_OF_NAME(*p)) *next++ = *p++;
320 dprintf_dosfs( stddeb, "DRIVE_FindDriveRoot: %s -> drive %c:, root='%s', name='%s'\n",
321 buffer, 'A' + rootdrive,
322 DOSDrives[rootdrive].root, *path );
327 /***********************************************************************
330 const char * DRIVE_GetRoot( int drive )
332 if (!DRIVE_IsValid( drive )) return NULL;
333 return DOSDrives[drive].root;
337 /***********************************************************************
340 const char * DRIVE_GetDosCwd( int drive )
342 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
343 if (!DRIVE_IsValid( drive )) return NULL;
345 /* Check if we need to change the directory to the new task. */
346 if (pTask && (pTask->curdrive & 0x80) && /* The task drive is valid */
347 ((pTask->curdrive & ~0x80) == drive) && /* and it's the one we want */
348 (DRIVE_LastTask != GetCurrentTask())) /* and the task changed */
350 /* Perform the task-switch */
351 if (!DRIVE_Chdir( drive, pTask->curdir )) DRIVE_Chdir( drive, "\\" );
352 DRIVE_LastTask = GetCurrentTask();
354 return DOSDrives[drive].dos_cwd;
358 /***********************************************************************
361 const char * DRIVE_GetUnixCwd( int drive )
363 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
364 if (!DRIVE_IsValid( drive )) return NULL;
366 /* Check if we need to change the directory to the new task. */
367 if (pTask && (pTask->curdrive & 0x80) && /* The task drive is valid */
368 ((pTask->curdrive & ~0x80) == drive) && /* and it's the one we want */
369 (DRIVE_LastTask != GetCurrentTask())) /* and the task changed */
371 /* Perform the task-switch */
372 if (!DRIVE_Chdir( drive, pTask->curdir )) DRIVE_Chdir( drive, "\\" );
373 DRIVE_LastTask = GetCurrentTask();
375 return DOSDrives[drive].unix_cwd;
379 /***********************************************************************
382 const char * DRIVE_GetLabel( int drive )
384 if (!DRIVE_IsValid( drive )) return NULL;
385 return DOSDrives[drive].label;
389 /***********************************************************************
390 * DRIVE_GetSerialNumber
392 DWORD DRIVE_GetSerialNumber( int drive )
394 if (!DRIVE_IsValid( drive )) return 0;
395 return DOSDrives[drive].serial;
399 /***********************************************************************
400 * DRIVE_SetSerialNumber
402 int DRIVE_SetSerialNumber( int drive, DWORD serial )
404 if (!DRIVE_IsValid( drive )) return 0;
405 DOSDrives[drive].serial = serial;
410 /***********************************************************************
413 DRIVETYPE DRIVE_GetType( int drive )
415 if (!DRIVE_IsValid( drive )) return TYPE_INVALID;
416 return DOSDrives[drive].type;
420 /***********************************************************************
423 UINT32 DRIVE_GetFlags( int drive )
425 if ((drive < 0) || (drive >= MAX_DOS_DRIVES)) return 0;
426 return DOSDrives[drive].flags;
430 /***********************************************************************
433 int DRIVE_Chdir( int drive, const char *path )
435 DOS_FULL_NAME full_name;
436 char buffer[MAX_PATHNAME_LEN];
438 BY_HANDLE_FILE_INFORMATION info;
439 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
441 dprintf_dosfs( stddeb, "DRIVE_Chdir(%c:,%s)\n", 'A' + drive, path );
442 strcpy( buffer, "A:" );
444 lstrcpyn32A( buffer + 2, path, sizeof(buffer) - 2 );
446 if (!DOSFS_GetFullName( buffer, TRUE, &full_name )) return 0;
447 if (!FILE_Stat( full_name.long_name, &info )) return 0;
448 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
450 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
453 unix_cwd = full_name.long_name + strlen( DOSDrives[drive].root );
454 while (*unix_cwd == '/') unix_cwd++;
456 dprintf_dosfs( stddeb, "DRIVE_Chdir(%c:): unix_cwd=%s dos_cwd=%s\n",
457 'A' + drive, unix_cwd, full_name.short_name + 3 );
459 HeapFree( SystemHeap, 0, DOSDrives[drive].dos_cwd );
460 HeapFree( SystemHeap, 0, DOSDrives[drive].unix_cwd );
461 DOSDrives[drive].dos_cwd = HEAP_strdupA( SystemHeap, 0,
462 full_name.short_name + 3 );
463 DOSDrives[drive].unix_cwd = HEAP_strdupA( SystemHeap, 0, unix_cwd );
465 if (pTask && (pTask->curdrive & 0x80) &&
466 ((pTask->curdrive & ~0x80) == drive))
468 lstrcpyn32A( pTask->curdir, full_name.short_name + 2,
469 sizeof(pTask->curdir) );
470 DRIVE_LastTask = GetCurrentTask();
476 /***********************************************************************
479 int DRIVE_Disable( int drive )
481 if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root)
483 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
486 DOSDrives[drive].flags |= DRIVE_DISABLED;
491 /***********************************************************************
494 int DRIVE_Enable( int drive )
496 if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root)
498 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
501 DOSDrives[drive].flags &= ~DRIVE_DISABLED;
506 /***********************************************************************
507 * DRIVE_SetLogicalMapping
509 int DRIVE_SetLogicalMapping ( int existing_drive, int new_drive )
511 /* If new_drive is already valid, do nothing and return 0
512 otherwise, copy DOSDrives[existing_drive] to DOSDrives[new_drive] */
516 old = DOSDrives + existing_drive;
517 new = DOSDrives + new_drive;
519 if ((existing_drive < 0) || (existing_drive >= MAX_DOS_DRIVES) ||
521 (new_drive < 0) || (new_drive >= MAX_DOS_DRIVES))
523 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
529 dprintf_dosfs ( stddeb, "Can\'t map drive %c to drive %c - "
530 "drive %c already exists\n",
531 'A' + existing_drive, 'A' + new_drive,
536 new->root = HEAP_strdupA( SystemHeap, 0, old->root );
537 new->dos_cwd = HEAP_strdupA( SystemHeap, 0, old->dos_cwd );
538 new->unix_cwd = HEAP_strdupA( SystemHeap, 0, old->unix_cwd );
539 memcpy ( new->label, old->label, 12 );
540 new->serial = old->serial;
541 new->type = old->type;
542 new->flags = old->flags;
546 dprintf_dosfs ( stddeb, "Drive %c is now equal to drive %c\n",
547 'A' + new_drive, 'A' + existing_drive );
554 /***********************************************************************
557 static int DRIVE_GetFreeSpace( int drive, DWORD *size, DWORD *available )
561 if (!DRIVE_IsValid(drive))
563 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
567 #if defined(__svr4__) || defined(_SCO_DS)
568 if (statfs( DOSDrives[drive].root, &info, 0, 0) < 0)
570 if (statfs( DOSDrives[drive].root, &info) < 0)
574 fprintf(stderr,"dosfs: cannot do statfs(%s)\n", DOSDrives[drive].root);
578 *size = info.f_bsize * info.f_blocks;
579 #if defined(__svr4__) || defined(_SCO_DS) || defined(__EMX__)
580 *available = info.f_bfree * info.f_bsize;
582 *available = info.f_bavail * info.f_bsize;
588 /***********************************************************************
589 * GetDiskFreeSpace16 (KERNEL.422)
591 BOOL16 WINAPI GetDiskFreeSpace16( LPCSTR root, LPDWORD cluster_sectors,
592 LPDWORD sector_bytes, LPDWORD free_clusters,
593 LPDWORD total_clusters )
595 return GetDiskFreeSpace32A( root, cluster_sectors, sector_bytes,
596 free_clusters, total_clusters );
600 /***********************************************************************
601 * GetDiskFreeSpace32A (KERNEL32.206)
603 BOOL32 WINAPI GetDiskFreeSpace32A( LPCSTR root, LPDWORD cluster_sectors,
604 LPDWORD sector_bytes, LPDWORD free_clusters,
605 LPDWORD total_clusters )
608 DWORD size,available;
610 if (!root) drive = DRIVE_GetCurrentDrive();
613 if ((root[1]) && ((root[1] != ':') || (root[2] != '\\')))
615 fprintf( stderr, "GetDiskFreeSpaceA: invalid root '%s'\n", root );
618 drive = toupper(root[0]) - 'A';
620 if (!DRIVE_GetFreeSpace(drive, &size, &available)) return FALSE;
622 /* Cap the size and available at 2GB as per specs. */
623 if (size > 0x7fffffff) size = 0x7fffffff;
624 if (available > 0x7fffffff) available = 0x7fffffff;
626 if (DRIVE_GetType(drive)==TYPE_CDROM) {
627 *sector_bytes = 2048;
635 /* fixme: probably have to adjust those variables too for CDFS */
636 *cluster_sectors = 1;
637 while (*cluster_sectors * 65530 < size) *cluster_sectors *= 2;
638 *free_clusters = available/ *cluster_sectors;
639 *total_clusters = size/ *cluster_sectors;
644 /***********************************************************************
645 * GetDiskFreeSpace32W (KERNEL32.207)
647 BOOL32 WINAPI GetDiskFreeSpace32W( LPCWSTR root, LPDWORD cluster_sectors,
648 LPDWORD sector_bytes, LPDWORD free_clusters,
649 LPDWORD total_clusters )
654 xroot = HEAP_strdupWtoA( GetProcessHeap(), 0, root);
655 ret = GetDiskFreeSpace32A( xroot,cluster_sectors, sector_bytes,
656 free_clusters, total_clusters );
657 HeapFree( GetProcessHeap(), 0, xroot );
662 /***********************************************************************
663 * GetDiskFreeSpaceEx32A (KERNEL32.871)
665 BOOL32 WINAPI GetDiskFreeSpaceEx32A( LPCSTR root,
666 LPULARGE_INTEGER avail,
667 LPULARGE_INTEGER total,
668 LPULARGE_INTEGER totalfree)
671 DWORD size,available;
673 if (!root) drive = DRIVE_GetCurrentDrive();
676 if ((root[1]) && ((root[1] != ':') || (root[2] != '\\')))
678 fprintf( stderr, "GetDiskFreeSpaceExA: invalid root '%s'\n",
682 drive = toupper(root[0]) - 'A';
684 if (!DRIVE_GetFreeSpace(drive, &size, &available)) return FALSE;
685 /*FIXME: Do we have the number of bytes available to the user? */
686 avail->HighPart = total->HighPart = 0;
687 avail->LowPart = available;
688 total->LowPart = size;
691 totalfree->HighPart =0;
692 totalfree->LowPart= available;
697 /***********************************************************************
698 * GetDiskFreeSpaceEx32W (KERNEL32.873)
700 BOOL32 WINAPI GetDiskFreeSpaceEx32W( LPCWSTR root, LPULARGE_INTEGER avail,
701 LPULARGE_INTEGER total,
702 LPULARGE_INTEGER totalfree)
707 xroot = HEAP_strdupWtoA( GetProcessHeap(), 0, root);
708 ret = GetDiskFreeSpaceEx32A( xroot, avail, total, totalfree);
709 HeapFree( GetProcessHeap(), 0, xroot );
713 /***********************************************************************
714 * GetDriveType16 (KERNEL.136)
716 UINT16 WINAPI GetDriveType16( UINT16 drive )
718 dprintf_dosfs( stddeb, "GetDriveType16(%c:)\n", 'A' + drive );
719 switch(DRIVE_GetType(drive))
721 case TYPE_FLOPPY: return DRIVE_REMOVABLE;
722 case TYPE_HD: return DRIVE_FIXED;
723 case TYPE_CDROM: return DRIVE_REMOTE;
724 case TYPE_NETWORK: return DRIVE_REMOTE;
726 default: return DRIVE_CANNOTDETERMINE;
731 /***********************************************************************
732 * GetDriveType32A (KERNEL32.208)
734 UINT32 WINAPI GetDriveType32A( LPCSTR root )
736 dprintf_dosfs( stddeb, "GetDriveType32A(%s)\n", root );
737 if ((root[1]) && (root[1] != ':'))
739 fprintf( stderr, "GetDriveType32A: invalid root '%s'\n", root );
740 return DRIVE_DOESNOTEXIST;
742 switch(DRIVE_GetType(toupper(root[0]) - 'A'))
744 case TYPE_FLOPPY: return DRIVE_REMOVABLE;
745 case TYPE_HD: return DRIVE_FIXED;
746 case TYPE_CDROM: return DRIVE_CDROM;
747 case TYPE_NETWORK: return DRIVE_REMOTE;
749 default: return DRIVE_CANNOTDETERMINE;
754 /***********************************************************************
755 * GetDriveType32W (KERNEL32.209)
757 UINT32 WINAPI GetDriveType32W( LPCWSTR root )
759 LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, root );
760 UINT32 ret = GetDriveType32A( xpath );
761 HeapFree( GetProcessHeap(), 0, xpath );
766 /***********************************************************************
767 * GetCurrentDirectory16 (KERNEL.411)
769 UINT16 WINAPI GetCurrentDirectory16( UINT16 buflen, LPSTR buf )
771 return (UINT16)GetCurrentDirectory32A( buflen, buf );
775 /***********************************************************************
776 * GetCurrentDirectory32A (KERNEL32.196)
778 * Returns "X:\\path\\etc\\".
780 UINT32 WINAPI GetCurrentDirectory32A( UINT32 buflen, LPSTR buf )
783 const char *s = DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() );
785 lstrcpyn32A( buf, pref, MIN( 4, buflen ) );
786 if (buflen) buf[0] += DRIVE_GetCurrentDrive();
787 if (buflen > 3) lstrcpyn32A( buf + 3, s, buflen - 3 );
788 return strlen(s) + 3; /* length of WHOLE current directory */
792 /***********************************************************************
793 * GetCurrentDirectory32W (KERNEL32.197)
795 UINT32 WINAPI GetCurrentDirectory32W( UINT32 buflen, LPWSTR buf )
797 LPSTR xpath = HeapAlloc( GetProcessHeap(), 0, buflen+1 );
798 UINT32 ret = GetCurrentDirectory32A( buflen, xpath );
799 lstrcpyAtoW( buf, xpath );
800 HeapFree( GetProcessHeap(), 0, xpath );
805 /***********************************************************************
806 * SetCurrentDirectory (KERNEL.412)
808 BOOL16 WINAPI SetCurrentDirectory16( LPCSTR dir )
810 return SetCurrentDirectory32A( dir );
814 /***********************************************************************
815 * SetCurrentDirectory32A (KERNEL32.479)
817 BOOL32 WINAPI SetCurrentDirectory32A( LPCSTR dir )
819 int drive = DRIVE_GetCurrentDrive();
821 if (dir[0] && (dir[1]==':'))
823 drive = tolower( *dir ) - 'a';
824 if (!DRIVE_IsValid( drive ))
826 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
831 /* FIXME: what about empty strings? Add a \\ ? */
832 if (!DRIVE_Chdir( drive, dir )) return FALSE;
833 if (drive == DRIVE_GetCurrentDrive()) return TRUE;
834 return DRIVE_SetCurrentDrive( drive );
838 /***********************************************************************
839 * SetCurrentDirectory32W (KERNEL32.480)
841 BOOL32 WINAPI SetCurrentDirectory32W( LPCWSTR dirW )
843 LPSTR dir = HEAP_strdupWtoA( GetProcessHeap(), 0, dirW );
844 BOOL32 res = SetCurrentDirectory32A( dir );
845 HeapFree( GetProcessHeap(), 0, dir );
850 /***********************************************************************
851 * GetLogicalDriveStrings32A (KERNEL32.231)
853 UINT32 WINAPI GetLogicalDriveStrings32A( UINT32 len, LPSTR buffer )
857 for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
858 if (DRIVE_IsValid(drive)) count++;
859 if (count * 4 * sizeof(char) <= len)
862 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
863 if (DRIVE_IsValid(drive))
872 return count * 4 * sizeof(char);
876 /***********************************************************************
877 * GetLogicalDriveStrings32W (KERNEL32.232)
879 UINT32 WINAPI GetLogicalDriveStrings32W( UINT32 len, LPWSTR buffer )
883 for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
884 if (DRIVE_IsValid(drive)) count++;
885 if (count * 4 * sizeof(WCHAR) <= len)
888 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
889 if (DRIVE_IsValid(drive))
891 *p++ = (WCHAR)('a' + drive);
898 return count * 4 * sizeof(WCHAR);
902 /***********************************************************************
903 * GetLogicalDrives (KERNEL32.233)
905 DWORD WINAPI GetLogicalDrives(void)
910 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
911 if (DRIVE_IsValid(drive)) ret |= (1 << drive);
916 /***********************************************************************
917 * GetVolumeInformation32A (KERNEL32.309)
919 BOOL32 WINAPI GetVolumeInformation32A( LPCSTR root, LPSTR label,
920 DWORD label_len, DWORD *serial,
921 DWORD *filename_len, DWORD *flags,
922 LPSTR fsname, DWORD fsname_len )
926 /* FIXME, SetLastErrors missing */
928 if (!root) drive = DRIVE_GetCurrentDrive();
931 if ((root[1]) && (root[1] != ':'))
933 fprintf( stderr, "GetVolumeInformation: invalid root '%s'\n",root);
936 drive = toupper(root[0]) - 'A';
938 if (!DRIVE_IsValid( drive )) return FALSE;
939 if (label) lstrcpyn32A( label, DOSDrives[drive].label, label_len );
940 if (serial) *serial = DOSDrives[drive].serial;
942 /* Set the filesystem information */
943 /* Note: we only emulate a FAT fs at the present */
945 if (filename_len) *filename_len = 12;
946 if (flags) *flags = 0;
948 /* Diablo checks that return code ... */
949 if (DRIVE_GetType(drive)==TYPE_CDROM)
950 lstrcpyn32A( fsname, "CDFS", fsname_len );
952 lstrcpyn32A( fsname, "FAT", fsname_len );
958 /***********************************************************************
959 * GetVolumeInformation32W (KERNEL32.310)
961 BOOL32 WINAPI GetVolumeInformation32W( LPCWSTR root, LPWSTR label,
962 DWORD label_len, DWORD *serial,
963 DWORD *filename_len, DWORD *flags,
964 LPWSTR fsname, DWORD fsname_len )
966 LPSTR xroot = HEAP_strdupWtoA( GetProcessHeap(), 0, root );
967 LPSTR xvolname = label ? HeapAlloc(GetProcessHeap(),0,label_len) : NULL;
968 LPSTR xfsname = fsname ? HeapAlloc(GetProcessHeap(),0,fsname_len) : NULL;
969 BOOL32 ret = GetVolumeInformation32A( xroot, xvolname, label_len, serial,
970 filename_len, flags, xfsname,
974 if (label) lstrcpyAtoW( label, xvolname );
975 if (fsname) lstrcpyAtoW( fsname, xfsname );
977 HeapFree( GetProcessHeap(), 0, xroot );
978 HeapFree( GetProcessHeap(), 0, xvolname );
979 HeapFree( GetProcessHeap(), 0, xfsname );