Release 970824
[wine/multimedia.git] / files / drive.c
blobcee484a38e726165768b441317a41a9ce7a256fe
1 /*
2 * DOS drives handling functions
4 * Copyright 1993 Erik Bos
5 * Copyright 1996 Alexandre Julliard
6 */
8 #include <ctype.h>
9 #include <string.h>
10 #include <stdlib.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
14 #if defined(__linux__) || defined(sun) || defined(hpux)
15 #include <sys/vfs.h>
16 #endif
17 #if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__OpenBSD__)
18 #include <sys/param.h>
19 #include <sys/mount.h>
20 #include <sys/errno.h>
21 #endif
22 #if defined(__svr4__) || defined(_SCO_DS) || defined(__EMX__)
23 #include <sys/statfs.h>
24 #endif
26 #include "windows.h"
27 #include "winbase.h"
28 #include "drive.h"
29 #include "file.h"
30 #include "heap.h"
31 #include "msdos.h"
32 #include "options.h"
33 #include "task.h"
34 #include "stddebug.h"
35 #include "debug.h"
37 typedef struct
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 */
48 } DOSDRIVE;
51 static const char * const DRIVE_Types[] =
53 "floppy", /* TYPE_FLOPPY */
54 "hd", /* TYPE_HD */
55 "cdrom", /* TYPE_CDROM */
56 "network" /* TYPE_NETWORK */
60 /* Known filesystem types */
62 typedef struct
64 const char *name;
65 UINT32 flags;
66 } FS_DESCR;
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 },
76 { NULL, 0 }
80 static DOSDRIVE DOSDrives[MAX_DOS_DRIVES];
81 static int DRIVE_CurDrive = -1;
83 static HTASK16 DRIVE_LastTask = 0;
86 /***********************************************************************
87 * DRIVE_GetDriveType
89 static DRIVETYPE DRIVE_GetDriveType( const char *name )
91 char buffer[20];
92 int i;
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",
100 name, buffer );
101 return TYPE_HD;
105 /***********************************************************************
106 * DRIVE_GetFSFlags
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",
115 name, value );
116 return DRIVE_CASE_SENSITIVE | DRIVE_CASE_PRESERVING;
120 /***********************************************************************
121 * DRIVE_Init
123 int DRIVE_Init(void)
125 int i, len, count = 0;
126 char name[] = "Drive A";
127 char path[MAX_PATHNAME_LEN];
128 char buffer[20];
129 struct stat drive_stat_buffer;
130 char *p;
131 DOSDRIVE *drive;
133 for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, name[6]++, drive++)
135 PROFILE_GetWineIniString( name, "Path", "", path, sizeof(path)-1 );
136 if (path[0])
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",
145 path, 'A' + i );
146 continue;
148 if (!S_ISDIR(drive_stat_buffer.st_mode))
150 fprintf( stderr, "%s is not a directory, ignoring drive %c:\n",
151 path, 'A' + i );
152 continue;
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 );
159 drive->flags = 0;
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))
184 DRIVE_CurDrive = i;
186 count++;
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 );
195 if (!count)
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;
206 DRIVE_CurDrive = 2;
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))
216 DRIVE_CurDrive = i;
217 break;
222 return 1;
226 /***********************************************************************
227 * DRIVE_IsValid
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 );
257 return 0;
259 dprintf_dosfs( stddeb, "DRIVE_SetCurrentDrive: %c:\n", 'A' + drive );
260 DRIVE_CurDrive = drive;
261 if (pTask) pTask->curdrive = drive | 0x80;
262 return 1;
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];
284 char *next = buffer;
285 const char *p = *path;
286 struct stat st;
288 strcpy( buffer, "/" );
289 for (;;)
291 if (stat( buffer, &st ) || !S_ISDIR( st.st_mode )) break;
293 /* Find the drive */
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))
303 rootdrive = drive;
304 *path = p;
308 /* Get the next path component */
310 *next++ = '/';
311 while ((*p == '/') || (*p == '\\')) p++;
312 if (!*p) break;
313 while (!IS_END_OF_NAME(*p)) *next++ = *p++;
314 *next = 0;
317 if (rootdrive != -1)
318 dprintf_dosfs( stddeb, "DRIVE_FindDriveRoot: %s -> drive %c:, root='%s', name='%s'\n",
319 buffer, 'A' + rootdrive,
320 DOSDrives[rootdrive].root, *path );
321 return rootdrive;
325 /***********************************************************************
326 * DRIVE_GetRoot
328 const char * DRIVE_GetRoot( int drive )
330 if (!DRIVE_IsValid( drive )) return NULL;
331 return DOSDrives[drive].root;
335 /***********************************************************************
336 * DRIVE_GetDosCwd
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 /***********************************************************************
357 * DRIVE_GetUnixCwd
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 /***********************************************************************
378 * DRIVE_GetLabel
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;
404 return 1;
408 /***********************************************************************
409 * DRIVE_GetType
411 DRIVETYPE DRIVE_GetType( int drive )
413 if (!DRIVE_IsValid( drive )) return TYPE_INVALID;
414 return DOSDrives[drive].type;
418 /***********************************************************************
419 * DRIVE_GetFlags
421 UINT32 DRIVE_GetFlags( int drive )
423 if ((drive < 0) || (drive >= MAX_DOS_DRIVES)) return 0;
424 return DOSDrives[drive].flags;
428 /***********************************************************************
429 * DRIVE_Chdir
431 int DRIVE_Chdir( int drive, const char *path )
433 DOS_FULL_NAME full_name;
434 char buffer[MAX_PATHNAME_LEN];
435 LPSTR unix_cwd;
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:" );
441 buffer[0] += drive;
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 );
449 return 0;
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();
470 return 1;
474 /***********************************************************************
475 * DRIVE_Disable
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 );
482 return 0;
484 DOSDrives[drive].flags |= DRIVE_DISABLED;
485 return 1;
489 /***********************************************************************
490 * DRIVE_Enable
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 );
497 return 0;
499 DOSDrives[drive].flags &= ~DRIVE_DISABLED;
500 return 1;
504 /***********************************************************************
505 * DRIVE_GetFreeSpace
507 static int DRIVE_GetFreeSpace( int drive, DWORD *size, DWORD *available )
509 struct statfs info;
511 if (!DRIVE_IsValid(drive))
513 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
514 return 0;
517 #if defined(__svr4__) || defined(_SCO_DS)
518 if (statfs( DOSDrives[drive].root, &info, 0, 0) < 0)
519 #else
520 if (statfs( DOSDrives[drive].root, &info) < 0)
521 #endif
523 FILE_SetDosError();
524 fprintf(stderr,"dosfs: cannot do statfs(%s)\n", DOSDrives[drive].root);
525 return 0;
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;
531 #else
532 *available = info.f_bavail * info.f_bsize;
533 #endif
534 return 1;
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 )
557 int drive;
558 DWORD size,available;
560 if (!root) drive = DRIVE_GetCurrentDrive();
561 else
563 if ((root[1] != ':') || (root[2] != '\\'))
565 fprintf( stderr, "GetDiskFreeSpaceA: invalid root '%s'\n", root );
566 return FALSE;
568 drive = toupper(root[0]) - 'A';
570 if (!DRIVE_GetFreeSpace(drive, &size, &available)) return FALSE;
572 *sector_bytes = 512;
573 size /= 512;
574 available /= 512;
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;
579 return TRUE;
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 )
590 LPSTR xroot;
591 BOOL32 ret;
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 );
597 return ret;
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;
613 case TYPE_INVALID:
614 default: return DRIVE_CANNOTDETERMINE;
619 /***********************************************************************
620 * GetDriveType32A (KERNEL32.208)
622 UINT32 WINAPI GetDriveType32A( LPCSTR root )
624 dprintf_dosfs( stddeb, "GetDriveType32A(%s)\n", root );
625 if (root[1] != ':')
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;
636 case TYPE_INVALID:
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 );
650 return ret;
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 )
670 char *pref = "A:\\";
671 const char *s = DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() );
672 if (!s)
674 *buf = '\0';
675 return 0;
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 );
693 return ret;
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 );
719 return FALSE;
721 dir += 2;
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 );
738 return res;
742 /***********************************************************************
743 * GetLogicalDriveStrings32A (KERNEL32.231)
745 UINT32 WINAPI GetLogicalDriveStrings32A( UINT32 len, LPSTR buffer )
747 int drive, count;
749 for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
750 if (DRIVE_IsValid(drive)) count++;
751 if (count * 4 * sizeof(char) <= len)
753 LPSTR p = buffer;
754 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
755 if (DRIVE_IsValid(drive))
757 *p++ = 'a' + drive;
758 *p++ = ':';
759 *p++ = '\\';
760 *p++ = '\0';
762 *p = '\0';
764 return count * 4 * sizeof(char);
768 /***********************************************************************
769 * GetLogicalDriveStrings32W (KERNEL32.232)
771 UINT32 WINAPI GetLogicalDriveStrings32W( UINT32 len, LPWSTR buffer )
773 int drive, count;
775 for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
776 if (DRIVE_IsValid(drive)) count++;
777 if (count * 4 * sizeof(WCHAR) <= len)
779 LPWSTR p = buffer;
780 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
781 if (DRIVE_IsValid(drive))
783 *p++ = (WCHAR)('a' + drive);
784 *p++ = (WCHAR)':';
785 *p++ = (WCHAR)'\\';
786 *p++ = (WCHAR)'\0';
788 *p = (WCHAR)'\0';
790 return count * 4 * sizeof(WCHAR);
794 /***********************************************************************
795 * GetLogicalDrives (KERNEL32.233)
797 DWORD WINAPI GetLogicalDrives(void)
799 DWORD ret = 0;
800 int drive;
802 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
803 if (DRIVE_IsValid(drive)) ret |= (1 << drive);
804 return ret;
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 )
816 int drive;
818 /* FIXME, SetLastErrors missing */
820 if (!root) drive = DRIVE_GetCurrentDrive();
821 else
823 if ((root[1] != ':') || (root[2] != '\\'))
825 fprintf( stderr, "GetVolumeInformation: invalid root '%s'\n",root);
826 return FALSE;
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 );
840 return TRUE;
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,
857 fsname_len );
858 if (ret)
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 );
866 return ret;