Release 970305
[wine/multimedia.git] / files / drive.c
blobdabebf891f7a6d3c4ef6b0adabdd0bd05ca6d82e
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__)
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 } DOSDRIVE;
49 static const char * const DRIVE_Types[] =
51 "floppy", /* TYPE_FLOPPY */
52 "hd", /* TYPE_HD */
53 "cdrom", /* TYPE_CDROM */
54 "network" /* TYPE_NETWORK */
58 /* Known filesystem types */
60 typedef struct
62 const char *name;
63 UINT32 flags;
64 } FS_DESCR;
66 static const FS_DESCR DRIVE_Filesystems[] =
68 { "unix", DRIVE_CASE_SENSITIVE | DRIVE_CASE_PRESERVING },
69 { "msdos", DRIVE_SHORT_NAMES },
70 { "dos", DRIVE_SHORT_NAMES },
71 { "fat", DRIVE_SHORT_NAMES },
72 { "vfat", DRIVE_CASE_PRESERVING },
73 { "win95", DRIVE_CASE_PRESERVING },
74 { NULL, 0 }
78 static DOSDRIVE DOSDrives[MAX_DOS_DRIVES];
79 static int DRIVE_CurDrive = -1;
81 static HTASK16 DRIVE_LastTask = 0;
84 /***********************************************************************
85 * DRIVE_GetDriveType
87 static DRIVETYPE DRIVE_GetDriveType( const char *name )
89 char buffer[20];
90 int i;
92 PROFILE_GetWineIniString( name, "Type", "hd", buffer, sizeof(buffer) );
93 for (i = 0; i < sizeof(DRIVE_Types)/sizeof(DRIVE_Types[0]); i++)
95 if (!lstrcmpi32A( buffer, DRIVE_Types[i] )) return (DRIVETYPE)i;
97 fprintf( stderr, "%s: unknown type '%s', defaulting to 'hd'.\n",
98 name, buffer );
99 return TYPE_HD;
103 /***********************************************************************
104 * DRIVE_GetFSFlags
106 static UINT32 DRIVE_GetFSFlags( const char *name, const char *value )
108 const FS_DESCR *descr;
110 for (descr = DRIVE_Filesystems; descr->name; descr++)
111 if (!lstrcmpi32A( value, descr->name )) return descr->flags;
112 fprintf( stderr, "%s: unknown filesystem type '%s', defaulting to 'unix'.\n",
113 name, value );
114 return DRIVE_CASE_SENSITIVE | DRIVE_CASE_PRESERVING;
118 /***********************************************************************
119 * DRIVE_Init
121 int DRIVE_Init(void)
123 int i, len, count = 0;
124 char name[] = "Drive A";
125 char path[MAX_PATHNAME_LEN];
126 char buffer[20];
127 char *p;
128 DOSDRIVE *drive;
130 for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, name[6]++, drive++)
132 PROFILE_GetWineIniString( name, "Path", "", path, sizeof(path)-1 );
133 if (path[0])
135 p = path + strlen(path) - 1;
136 while ((p > path) && ((*p == '/') || (*p == '\\'))) *p-- = '\0';
137 if (strlen(path))
138 drive->root = HEAP_strdupA( SystemHeap, 0, path );
139 else
140 drive->root = HEAP_strdupA( SystemHeap, 0, "/" );
141 drive->dos_cwd = HEAP_strdupA( SystemHeap, 0, "" );
142 drive->unix_cwd = HEAP_strdupA( SystemHeap, 0, "" );
143 drive->type = DRIVE_GetDriveType( name );
144 drive->flags = 0;
146 /* Get the drive label */
147 PROFILE_GetWineIniString( name, "Label", name, drive->label, 12 );
148 if ((len = strlen(drive->label)) < 11)
150 /* Pad label with spaces */
151 memset( drive->label + len, ' ', 11 - len );
152 drive->label[12] = '\0';
155 /* Get the serial number */
156 PROFILE_GetWineIniString( name, "Serial", "12345678",
157 buffer, sizeof(buffer) );
158 drive->serial = strtoul( buffer, NULL, 16 );
160 /* Get the filesystem type */
161 PROFILE_GetWineIniString( name, "Filesystem", "unix",
162 buffer, sizeof(buffer) );
163 drive->flags = DRIVE_GetFSFlags( name, buffer );
165 /* Make the first hard disk the current drive */
166 if ((DRIVE_CurDrive == -1) && (drive->type == TYPE_HD))
167 DRIVE_CurDrive = i;
169 count++;
170 dprintf_dosfs( stddeb, "%s: path=%s type=%s label='%s' serial=%08lx flags=%08x\n",
171 name, path, DRIVE_Types[drive->type],
172 drive->label, drive->serial, drive->flags );
174 else dprintf_dosfs( stddeb, "%s: not defined\n", name );
177 if (!count)
179 fprintf( stderr, "Warning: no valid DOS drive found, check your configuration file.\n" );
180 /* Create a C drive pointing to Unix root dir */
181 DOSDrives[2].root = HEAP_strdupA( SystemHeap, 0, "/" );
182 DOSDrives[2].dos_cwd = HEAP_strdupA( SystemHeap, 0, "" );
183 DOSDrives[2].unix_cwd = HEAP_strdupA( SystemHeap, 0, "" );
184 strcpy( DOSDrives[2].label, "Drive C " );
185 DOSDrives[2].serial = 0x12345678;
186 DOSDrives[2].type = TYPE_HD;
187 DOSDrives[2].flags = 0;
188 DRIVE_CurDrive = 2;
191 /* Make sure the current drive is valid */
192 if (DRIVE_CurDrive == -1)
194 for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, drive++)
196 if (drive->root && !(drive->flags & DRIVE_DISABLED))
198 DRIVE_CurDrive = i;
199 break;
204 return 1;
208 /***********************************************************************
209 * DRIVE_IsValid
211 int DRIVE_IsValid( int drive )
213 if ((drive < 0) || (drive >= MAX_DOS_DRIVES)) return 0;
214 return (DOSDrives[drive].root &&
215 !(DOSDrives[drive].flags & DRIVE_DISABLED));
219 /***********************************************************************
220 * DRIVE_GetCurrentDrive
222 int DRIVE_GetCurrentDrive(void)
224 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
225 if (pTask && (pTask->curdrive & 0x80)) return pTask->curdrive & ~0x80;
226 return DRIVE_CurDrive;
230 /***********************************************************************
231 * DRIVE_SetCurrentDrive
233 int DRIVE_SetCurrentDrive( int drive )
235 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
236 if (!DRIVE_IsValid( drive ))
238 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
239 return 0;
241 dprintf_dosfs( stddeb, "DRIVE_SetCurrentDrive: %c:\n", 'A' + drive );
242 DRIVE_CurDrive = drive;
243 if (pTask) pTask->curdrive = drive | 0x80;
244 return 1;
248 /***********************************************************************
249 * DRIVE_FindDriveRoot
251 * Find a drive for which the root matches the begginning of the given path.
252 * This can be used to translate a Unix path into a drive + DOS path.
253 * Return value is the drive, or -1 on error. On success, path is modified
254 * to point to the beginning of the DOS path.
255 * FIXME: this only does a textual comparison of the path names, and won't
256 * work well in the presence of symbolic links.
258 int DRIVE_FindDriveRoot( const char **path )
260 int drive, rootdrive = -1;
261 const char *p1, *p2;
263 dprintf_dosfs( stddeb, "DRIVE_FindDriveRoot: searching '%s'\n", *path );
264 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
266 if (!DOSDrives[drive].root ||
267 (DOSDrives[drive].flags & DRIVE_DISABLED)) continue;
268 p1 = *path;
269 p2 = DOSDrives[drive].root;
270 dprintf_dosfs( stddeb, "DRIVE_FindDriveRoot: checking %c: '%s'\n",
271 'A' + drive, p2 );
273 while (*p2 == '/') p2++;
274 if (!*p2)
276 rootdrive = drive;
277 continue; /* Look if there's a better match */
279 for (;;)
281 while ((*p1 == '\\') || (*p1 == '/')) p1++;
282 while (*p2 == '/') p2++;
283 while ((*p1 == *p2) && (*p2) && (*p2 != '/')) p1++, p2++;
284 if (!*p2)
286 if (IS_END_OF_NAME(*p1)) /* OK, found it */
288 *path = p1;
289 return drive;
292 else if (*p2 == '/')
294 if (IS_END_OF_NAME(*p1))
295 continue; /* Go to next path element */
297 break; /* No match, go to next drive */
300 return rootdrive;
304 /***********************************************************************
305 * DRIVE_GetRoot
307 const char * DRIVE_GetRoot( int drive )
309 if (!DRIVE_IsValid( drive )) return NULL;
310 return DOSDrives[drive].root;
314 /***********************************************************************
315 * DRIVE_GetDosCwd
317 const char * DRIVE_GetDosCwd( int drive )
319 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
320 if (!DRIVE_IsValid( drive )) return NULL;
322 /* Check if we need to change the directory to the new task. */
323 if (pTask && (pTask->curdrive & 0x80) && /* The task drive is valid */
324 ((pTask->curdrive & ~0x80) == drive) && /* and it's the one we want */
325 (DRIVE_LastTask != GetCurrentTask())) /* and the task changed */
327 /* Perform the task-switch */
328 if (!DRIVE_Chdir( drive, pTask->curdir )) DRIVE_Chdir( drive, "\\" );
329 DRIVE_LastTask = GetCurrentTask();
331 return DOSDrives[drive].dos_cwd;
335 /***********************************************************************
336 * DRIVE_GetUnixCwd
338 const char * DRIVE_GetUnixCwd( 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].unix_cwd;
356 /***********************************************************************
357 * DRIVE_GetLabel
359 const char * DRIVE_GetLabel( int drive )
361 if (!DRIVE_IsValid( drive )) return NULL;
362 return DOSDrives[drive].label;
366 /***********************************************************************
367 * DRIVE_GetSerialNumber
369 DWORD DRIVE_GetSerialNumber( int drive )
371 if (!DRIVE_IsValid( drive )) return 0;
372 return DOSDrives[drive].serial;
376 /***********************************************************************
377 * DRIVE_SetSerialNumber
379 int DRIVE_SetSerialNumber( int drive, DWORD serial )
381 if (!DRIVE_IsValid( drive )) return 0;
382 DOSDrives[drive].serial = serial;
383 return 1;
387 /***********************************************************************
388 * DRIVE_GetType
390 DRIVETYPE DRIVE_GetType( int drive )
392 if (!DRIVE_IsValid( drive )) return TYPE_INVALID;
393 return DOSDrives[drive].type;
397 /***********************************************************************
398 * DRIVE_GetFlags
400 UINT32 DRIVE_GetFlags( int drive )
402 if ((drive < 0) || (drive >= MAX_DOS_DRIVES)) return 0;
403 return DOSDrives[drive].flags;
407 /***********************************************************************
408 * DRIVE_Chdir
410 int DRIVE_Chdir( int drive, const char *path )
412 DOS_FULL_NAME full_name;
413 char buffer[MAX_PATHNAME_LEN];
414 LPSTR unix_cwd;
415 BY_HANDLE_FILE_INFORMATION info;
416 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
418 dprintf_dosfs( stddeb, "DRIVE_Chdir(%c:,%s)\n", 'A' + drive, path );
419 strcpy( buffer, "A:" );
420 buffer[0] += drive;
421 lstrcpyn32A( buffer + 2, path, sizeof(buffer) - 2 );
423 if (!DOSFS_GetFullName( buffer, TRUE, &full_name )) return 0;
424 if (!FILE_Stat( full_name.long_name, &info )) return 0;
425 if (!(info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
427 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
428 return 0;
430 unix_cwd = full_name.long_name + strlen( DOSDrives[drive].root );
431 while (*unix_cwd == '/') unix_cwd++;
433 dprintf_dosfs( stddeb, "DRIVE_Chdir(%c:): unix_cwd=%s dos_cwd=%s\n",
434 'A' + drive, unix_cwd, full_name.short_name + 3 );
436 HeapFree( SystemHeap, 0, DOSDrives[drive].dos_cwd );
437 HeapFree( SystemHeap, 0, DOSDrives[drive].unix_cwd );
438 DOSDrives[drive].dos_cwd = HEAP_strdupA( SystemHeap, 0,
439 full_name.short_name + 3 );
440 DOSDrives[drive].unix_cwd = HEAP_strdupA( SystemHeap, 0, unix_cwd );
442 if (pTask && (pTask->curdrive & 0x80) &&
443 ((pTask->curdrive & ~0x80) == drive))
445 lstrcpyn32A( pTask->curdir, full_name.short_name + 2,
446 sizeof(pTask->curdir) );
447 DRIVE_LastTask = GetCurrentTask();
449 return 1;
453 /***********************************************************************
454 * DRIVE_Disable
456 int DRIVE_Disable( int drive )
458 if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root)
460 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
461 return 0;
463 DOSDrives[drive].flags |= DRIVE_DISABLED;
464 return 1;
468 /***********************************************************************
469 * DRIVE_Enable
471 int DRIVE_Enable( int drive )
473 if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root)
475 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
476 return 0;
478 DOSDrives[drive].flags &= ~DRIVE_DISABLED;
479 return 1;
483 /***********************************************************************
484 * DRIVE_GetFreeSpace
486 static int DRIVE_GetFreeSpace( int drive, DWORD *size, DWORD *available )
488 struct statfs info;
490 if (!DRIVE_IsValid(drive))
492 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
493 return 0;
496 #if defined(__svr4__) || defined(_SCO_DS)
497 if (statfs( DOSDrives[drive].root, &info, 0, 0) < 0)
498 #else
499 if (statfs( DOSDrives[drive].root, &info) < 0)
500 #endif
502 FILE_SetDosError();
503 fprintf(stderr,"dosfs: cannot do statfs(%s)\n", DOSDrives[drive].root);
504 return 0;
507 *size = info.f_bsize * info.f_blocks;
508 #if defined(__svr4__) || defined(_SCO_DS) || defined(__EMX__)
509 *available = info.f_bfree * info.f_bsize;
510 #else
511 *available = info.f_bavail * info.f_bsize;
512 #endif
513 return 1;
517 /***********************************************************************
518 * GetDiskFreeSpace16 (KERNEL.422)
520 BOOL16 GetDiskFreeSpace16( LPCSTR root, LPDWORD cluster_sectors,
521 LPDWORD sector_bytes, LPDWORD free_clusters,
522 LPDWORD total_clusters )
524 return GetDiskFreeSpace32A( root, cluster_sectors, sector_bytes,
525 free_clusters, total_clusters );
529 /***********************************************************************
530 * GetDiskFreeSpace32A (KERNEL32.206)
532 BOOL32 GetDiskFreeSpace32A( LPCSTR root, LPDWORD cluster_sectors,
533 LPDWORD sector_bytes, LPDWORD free_clusters,
534 LPDWORD total_clusters )
536 int drive;
537 DWORD size,available;
539 if (!root) drive = DRIVE_GetCurrentDrive();
540 else
542 if ((root[1] != ':') || (root[2] != '\\'))
544 fprintf( stderr, "GetDiskFreeSpaceA: invalid root '%s'\n", root );
545 return FALSE;
547 drive = toupper(root[0]) - 'A';
549 if (!DRIVE_GetFreeSpace(drive, &size, &available)) return FALSE;
551 *sector_bytes = 512;
552 size /= 512;
553 available /= 512;
554 *cluster_sectors = 1;
555 while (*cluster_sectors * 65530 < size) *cluster_sectors *= 2;
556 *free_clusters = available/ *cluster_sectors;
557 *total_clusters = size/ *cluster_sectors;
558 return TRUE;
562 /***********************************************************************
563 * GetDiskFreeSpace32W (KERNEL32.207)
565 BOOL32 GetDiskFreeSpace32W( LPCWSTR root, LPDWORD cluster_sectors,
566 LPDWORD sector_bytes, LPDWORD free_clusters,
567 LPDWORD total_clusters )
569 LPSTR xroot;
570 BOOL32 ret;
572 xroot = HEAP_strdupWtoA( GetProcessHeap(), 0, root);
573 ret = GetDiskFreeSpace32A( xroot,cluster_sectors, sector_bytes,
574 free_clusters, total_clusters );
575 HeapFree( GetProcessHeap(), 0, xroot );
576 return ret;
580 /***********************************************************************
581 * GetDriveType16 (KERNEL.136)
583 UINT16 GetDriveType16( UINT16 drive )
585 dprintf_dosfs( stddeb, "GetDriveType16(%c:)\n", 'A' + drive );
586 switch(DRIVE_GetType(drive))
588 case TYPE_FLOPPY: return DRIVE_REMOVABLE;
589 case TYPE_HD: return DRIVE_FIXED;
590 case TYPE_CDROM: return DRIVE_REMOTE;
591 case TYPE_NETWORK: return DRIVE_REMOTE;
592 case TYPE_INVALID:
593 default: return DRIVE_CANNOTDETERMINE;
598 /***********************************************************************
599 * GetDriveType32A (KERNEL32.208)
601 UINT32 GetDriveType32A( LPCSTR root )
603 dprintf_dosfs( stddeb, "GetDriveType32A(%s)\n", root );
604 if (root[1] != ':')
606 fprintf( stderr, "GetDriveType32A: invalid root '%s'\n", root );
607 return DRIVE_DOESNOTEXIST;
609 switch(DRIVE_GetType(toupper(root[0]) - 'A'))
611 case TYPE_FLOPPY: return DRIVE_REMOVABLE;
612 case TYPE_HD: return DRIVE_FIXED;
613 case TYPE_CDROM: return DRIVE_CDROM;
614 case TYPE_NETWORK: return DRIVE_REMOTE;
615 case TYPE_INVALID:
616 default: return DRIVE_CANNOTDETERMINE;
621 /***********************************************************************
622 * GetDriveType32W (KERNEL32.209)
624 UINT32 GetDriveType32W( LPCWSTR root )
626 LPSTR xpath = HEAP_strdupWtoA( GetProcessHeap(), 0, root );
627 UINT32 ret = GetDriveType32A( xpath );
628 HeapFree( GetProcessHeap(), 0, xpath );
629 return ret;
633 /***********************************************************************
634 * GetCurrentDirectory16 (KERNEL.411)
636 UINT16 GetCurrentDirectory16( UINT16 buflen, LPSTR buf )
638 return (UINT16)GetCurrentDirectory32A( buflen, buf );
642 /***********************************************************************
643 * GetCurrentDirectory32A (KERNEL32.196)
645 * Returns "X:\\path\\etc\\".
647 UINT32 GetCurrentDirectory32A( UINT32 buflen, LPSTR buf )
649 char *pref = "A:\\";
650 const char *s = DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() );
651 if (!s)
653 *buf = '\0';
654 return 0;
656 lstrcpyn32A( buf, pref, MIN( 4, buflen ) );
657 if (buflen) buf[0] += DRIVE_GetCurrentDrive();
658 if (buflen > 3) lstrcpyn32A( buf + 3, s, buflen - 3 );
659 return strlen(s) + 3; /* length of WHOLE current directory */
663 /***********************************************************************
664 * GetCurrentDirectory32W (KERNEL32.197)
666 UINT32 GetCurrentDirectory32W( UINT32 buflen, LPWSTR buf )
668 LPSTR xpath = HeapAlloc( GetProcessHeap(), 0, buflen+1 );
669 UINT32 ret = GetCurrentDirectory32A( buflen, xpath );
670 lstrcpyAtoW( buf, xpath );
671 HeapFree( GetProcessHeap(), 0, xpath );
672 return ret;
676 /***********************************************************************
677 * SetCurrentDirectory (KERNEL.412)
679 BOOL16 SetCurrentDirectory16( LPCSTR dir )
681 return SetCurrentDirectory32A( dir );
685 /***********************************************************************
686 * SetCurrentDirectory32A (KERNEL32.479)
688 BOOL32 SetCurrentDirectory32A( LPCSTR dir )
690 int drive = DRIVE_GetCurrentDrive();
692 if (dir[0] && (dir[1]==':'))
694 drive = tolower( *dir ) - 'a';
695 if (!DRIVE_IsValid( drive ))
697 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
698 return FALSE;
700 dir += 2;
702 /* FIXME: what about empty strings? Add a \\ ? */
703 if (!DRIVE_Chdir( drive, dir )) return FALSE;
704 if (drive == DRIVE_GetCurrentDrive()) return TRUE;
705 return DRIVE_SetCurrentDrive( drive );
709 /***********************************************************************
710 * SetCurrentDirectory32W (KERNEL32.480)
712 BOOL32 SetCurrentDirectory32W( LPCWSTR dirW )
714 LPSTR dir = HEAP_strdupWtoA( GetProcessHeap(), 0, dirW );
715 BOOL32 res = SetCurrentDirectory32A( dir );
716 HeapFree( GetProcessHeap(), 0, dir );
717 return res;
721 /***********************************************************************
722 * GetLogicalDriveStrings32A (KERNEL32.231)
724 UINT32 GetLogicalDriveStrings32A( UINT32 len, LPSTR buffer )
726 int drive, count;
728 for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
729 if (DRIVE_IsValid(drive)) count++;
730 if (count * 4 * sizeof(char) <= len)
732 LPSTR p = buffer;
733 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
734 if (DRIVE_IsValid(drive))
736 *p++ = 'a' + drive;
737 *p++ = ':';
738 *p++ = '\\';
739 *p++ = '\0';
741 *p = '\0';
743 return count * 4 * sizeof(char);
747 /***********************************************************************
748 * GetLogicalDriveStrings32W (KERNEL32.232)
750 UINT32 GetLogicalDriveStrings32W( UINT32 len, LPWSTR buffer )
752 int drive, count;
754 for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
755 if (DRIVE_IsValid(drive)) count++;
756 if (count * 4 * sizeof(WCHAR) <= len)
758 LPWSTR p = buffer;
759 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
760 if (DRIVE_IsValid(drive))
762 *p++ = (WCHAR)('a' + drive);
763 *p++ = (WCHAR)':';
764 *p++ = (WCHAR)'\\';
765 *p++ = (WCHAR)'\0';
767 *p = (WCHAR)'\0';
769 return count * 4 * sizeof(WCHAR);
773 /***********************************************************************
774 * GetLogicalDrives (KERNEL32.233)
776 DWORD GetLogicalDrives(void)
778 DWORD ret = 0;
779 int drive;
781 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
782 if (DRIVE_IsValid(drive)) ret |= (1 << drive);
783 return ret;
787 /***********************************************************************
788 * GetVolumeInformation32A (KERNEL32.309)
790 BOOL32 GetVolumeInformation32A( LPCSTR root, LPSTR label, DWORD label_len,
791 DWORD *serial, DWORD *filename_len,
792 DWORD *flags, LPSTR fsname, DWORD fsname_len )
794 int drive;
796 /* FIXME, SetLastErrors missing */
798 if (!root) drive = DRIVE_GetCurrentDrive();
799 else
801 if ((root[1] != ':') || (root[2] != '\\'))
803 fprintf( stderr, "GetVolumeInformation: invalid root '%s'\n",root);
804 return FALSE;
806 drive = toupper(root[0]) - 'A';
808 if (!DRIVE_IsValid( drive )) return FALSE;
809 if (label) lstrcpyn32A( label, DOSDrives[drive].label, label_len );
810 if (serial) *serial = DOSDrives[drive].serial;
812 /* Set the filesystem information */
813 /* Note: we only emulate a FAT fs at the present */
815 if (filename_len) *filename_len = 12;
816 if (flags) *flags = 0;
817 if (fsname) lstrcpyn32A( fsname, "FAT", fsname_len );
818 return TRUE;
822 /***********************************************************************
823 * GetVolumeInformation32W (KERNEL32.310)
825 BOOL32 GetVolumeInformation32W( LPCWSTR root, LPWSTR label, DWORD label_len,
826 DWORD *serial, DWORD *filename_len,
827 DWORD *flags, LPWSTR fsname, DWORD fsname_len)
829 LPSTR xroot = HEAP_strdupWtoA( GetProcessHeap(), 0, root );
830 LPSTR xvolname = label ? HeapAlloc(GetProcessHeap(),0,label_len) : NULL;
831 LPSTR xfsname = fsname ? HeapAlloc(GetProcessHeap(),0,fsname_len) : NULL;
832 BOOL32 ret = GetVolumeInformation32A( xroot, xvolname, label_len, serial,
833 filename_len, flags, xfsname,
834 fsname_len );
835 if (ret)
837 if (label) lstrcpyAtoW( label, xvolname );
838 if (fsname) lstrcpyAtoW( fsname, xfsname );
840 HeapFree( GetProcessHeap(), 0, xroot );
841 HeapFree( GetProcessHeap(), 0, xvolname );
842 HeapFree( GetProcessHeap(), 0, xfsname );
843 return ret;