Release 961013
[wine/multimedia.git] / files / drive.c
blob9210de7b954b7a1eff48ac7c163c043cee5b0e69
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)
23 #include <sys/statfs.h>
24 #endif
26 #include "windows.h"
27 #include "winbase.h"
28 #include "dos_fs.h"
29 #include "drive.h"
30 #include "file.h"
31 #include "msdos.h"
32 #include "options.h"
33 #include "task.h"
34 #include "xmalloc.h"
35 #include "string32.h"
36 #include "stddebug.h"
37 #include "debug.h"
39 typedef struct
41 char *root; /* root dir in Unix format without trailing / */
42 char *dos_cwd; /* cwd in DOS format without leading or trailing \ */
43 char *unix_cwd; /* cwd in Unix format without leading or trailing / */
44 char label[12]; /* drive label */
45 DWORD serial; /* drive serial number */
46 DRIVETYPE type; /* drive type */
47 UINT32 flags; /* drive flags */
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 char *p;
130 DOSDRIVE *drive;
132 for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, name[6]++, drive++)
134 PROFILE_GetWineIniString( name, "Path", "", path, sizeof(path)-1 );
135 if (path[0])
137 p = path + strlen(path) - 1;
138 while ((p > path) && ((*p == '/') || (*p == '\\'))) *p-- = '\0';
139 drive->root = xstrdup( path );
140 drive->dos_cwd = xstrdup( "" );
141 drive->unix_cwd = xstrdup( "" );
142 drive->type = DRIVE_GetDriveType( name );
143 drive->flags = 0;
145 /* Get the drive label */
146 PROFILE_GetWineIniString( name, "Label", name, drive->label, 12 );
147 if ((len = strlen(drive->label)) < 11)
149 /* Pad label with spaces */
150 memset( drive->label + len, ' ', 11 - len );
151 drive->label[12] = '\0';
154 /* Get the serial number */
155 PROFILE_GetWineIniString( name, "Serial", "12345678",
156 buffer, sizeof(buffer) );
157 drive->serial = strtoul( buffer, NULL, 16 );
159 /* Get the filesystem type */
160 PROFILE_GetWineIniString( name, "Filesystem", "unix",
161 buffer, sizeof(buffer) );
162 drive->flags = DRIVE_GetFSFlags( name, buffer );
164 /* Make the first hard disk the current drive */
165 if ((DRIVE_CurDrive == -1) && (drive->type == TYPE_HD))
166 DRIVE_CurDrive = i;
168 count++;
169 dprintf_dosfs( stddeb, "%s: path=%s type=%s label='%s' serial=%08lx flags=%08x\n",
170 name, path, DRIVE_Types[drive->type],
171 drive->label, drive->serial, drive->flags );
173 else dprintf_dosfs( stddeb, "%s: not defined\n", name );
176 if (!count)
178 fprintf( stderr, "Warning: no valid DOS drive found, check your configuration file.\n" );
179 /* Create a C drive pointing to Unix root dir */
180 DOSDrives[2].root = xstrdup( "/" );
181 DOSDrives[2].dos_cwd = xstrdup( "" );
182 DOSDrives[2].unix_cwd = xstrdup( "" );
183 strcpy( DOSDrives[2].label, "Drive C " );
184 DOSDrives[2].serial = 0x12345678;
185 DOSDrives[2].type = TYPE_HD;
186 DOSDrives[2].flags = 0;
187 DRIVE_CurDrive = 2;
190 /* Make sure the current drive is valid */
191 if (DRIVE_CurDrive == -1)
193 for (i = 0, drive = DOSDrives; i < MAX_DOS_DRIVES; i++, drive++)
195 if (drive->root && !(drive->flags & DRIVE_DISABLED))
197 DRIVE_CurDrive = i;
198 break;
203 return 1;
207 /***********************************************************************
208 * DRIVE_IsValid
210 int DRIVE_IsValid( int drive )
212 if ((drive < 0) || (drive >= MAX_DOS_DRIVES)) return 0;
213 return (DOSDrives[drive].root &&
214 !(DOSDrives[drive].flags & DRIVE_DISABLED));
218 /***********************************************************************
219 * DRIVE_GetCurrentDrive
221 int DRIVE_GetCurrentDrive(void)
223 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
224 if (pTask && (pTask->curdrive & 0x80)) return pTask->curdrive & ~0x80;
225 return DRIVE_CurDrive;
229 /***********************************************************************
230 * DRIVE_SetCurrentDrive
232 int DRIVE_SetCurrentDrive( int drive )
234 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
235 if (!DRIVE_IsValid( drive ))
237 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
238 return 0;
240 dprintf_dosfs( stddeb, "DRIVE_SetCurrentDrive: %c:\n", 'A' + drive );
241 DRIVE_CurDrive = drive;
242 if (pTask) pTask->curdrive = drive | 0x80;
243 return 1;
247 /***********************************************************************
248 * DRIVE_FindDriveRoot
250 * Find a drive for which the root matches the begginning of the given path.
251 * This can be used to translate a Unix path into a drive + DOS path.
252 * Return value is the drive, or -1 on error. On success, path is modified
253 * to point to the beginning of the DOS path.
254 * FIXME: this only does a textual comparison of the path names, and won't
255 * work well in the presence of symbolic links.
257 int DRIVE_FindDriveRoot( const char **path )
259 int drive, rootdrive = -1;
260 const char *p1, *p2;
262 dprintf_dosfs( stddeb, "DRIVE_FindDriveRoot: searching '%s'\n", *path );
263 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
265 if (!DOSDrives[drive].root ||
266 (DOSDrives[drive].flags & DRIVE_DISABLED)) continue;
267 p1 = *path;
268 p2 = DOSDrives[drive].root;
269 dprintf_dosfs( stddeb, "DRIVE_FindDriveRoot: checking %c: '%s'\n",
270 'A' + drive, p2 );
272 while (*p2 == '/') p2++;
273 if (!*p2)
275 rootdrive = drive;
276 continue; /* Look if there's a better match */
278 for (;;)
280 while ((*p1 == '\\') || (*p1 == '/')) p1++;
281 while (*p2 == '/') p2++;
282 while ((*p1 == *p2) && (*p2) && (*p2 != '/')) p1++, p2++;
283 if (!*p2)
285 if (IS_END_OF_NAME(*p1)) /* OK, found it */
287 *path = p1;
288 return drive;
291 else if (*p2 == '/')
293 if (IS_END_OF_NAME(*p1))
294 continue; /* Go to next path element */
296 break; /* No match, go to next drive */
299 return rootdrive;
303 /***********************************************************************
304 * DRIVE_GetRoot
306 const char * DRIVE_GetRoot( int drive )
308 if (!DRIVE_IsValid( drive )) return NULL;
309 return DOSDrives[drive].root;
313 /***********************************************************************
314 * DRIVE_GetDosCwd
316 const char * DRIVE_GetDosCwd( int drive )
318 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
319 if (!DRIVE_IsValid( drive )) return NULL;
321 /* Check if we need to change the directory to the new task. */
322 if (pTask && (pTask->curdrive & 0x80) && /* The task drive is valid */
323 ((pTask->curdrive & ~0x80) == drive) && /* and it's the one we want */
324 (DRIVE_LastTask != GetCurrentTask())) /* and the task changed */
326 /* Perform the task-switch */
327 if (!DRIVE_Chdir( drive, pTask->curdir )) DRIVE_Chdir( drive, "\\" );
328 DRIVE_LastTask = GetCurrentTask();
330 return DOSDrives[drive].dos_cwd;
334 /***********************************************************************
335 * DRIVE_GetUnixCwd
337 const char * DRIVE_GetUnixCwd( int drive )
339 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
340 if (!DRIVE_IsValid( drive )) return NULL;
342 /* Check if we need to change the directory to the new task. */
343 if (pTask && (pTask->curdrive & 0x80) && /* The task drive is valid */
344 ((pTask->curdrive & ~0x80) == drive) && /* and it's the one we want */
345 (DRIVE_LastTask != GetCurrentTask())) /* and the task changed */
347 /* Perform the task-switch */
348 if (!DRIVE_Chdir( drive, pTask->curdir )) DRIVE_Chdir( drive, "\\" );
349 DRIVE_LastTask = GetCurrentTask();
351 return DOSDrives[drive].unix_cwd;
355 /***********************************************************************
356 * DRIVE_GetLabel
358 const char * DRIVE_GetLabel( int drive )
360 if (!DRIVE_IsValid( drive )) return NULL;
361 return DOSDrives[drive].label;
365 /***********************************************************************
366 * DRIVE_GetSerialNumber
368 DWORD DRIVE_GetSerialNumber( int drive )
370 if (!DRIVE_IsValid( drive )) return 0;
371 return DOSDrives[drive].serial;
375 /***********************************************************************
376 * DRIVE_SetSerialNumber
378 int DRIVE_SetSerialNumber( int drive, DWORD serial )
380 if (!DRIVE_IsValid( drive )) return 0;
381 DOSDrives[drive].serial = serial;
382 return 1;
386 /***********************************************************************
387 * DRIVE_GetType
389 DRIVETYPE DRIVE_GetType( int drive )
391 if (!DRIVE_IsValid( drive )) return TYPE_INVALID;
392 return DOSDrives[drive].type;
396 /***********************************************************************
397 * DRIVE_GetFlags
399 UINT32 DRIVE_GetFlags( int drive )
401 if ((drive < 0) || (drive >= MAX_DOS_DRIVES)) return 0;
402 return DOSDrives[drive].flags;
406 /***********************************************************************
407 * DRIVE_Chdir
409 int DRIVE_Chdir( int drive, const char *path )
411 char buffer[MAX_PATHNAME_LEN];
412 const char *unix_cwd, *dos_cwd;
413 BYTE attr;
414 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
416 dprintf_dosfs( stddeb, "DRIVE_Chdir(%c:,%s)\n", 'A' + drive, path );
417 strcpy( buffer, "A:" );
418 buffer[0] += drive;
419 lstrcpyn32A( buffer + 2, path, sizeof(buffer) - 2 );
421 if (!(unix_cwd = DOSFS_GetUnixFileName( buffer, TRUE ))) return 0;
422 if (!FILE_Stat( unix_cwd, &attr, NULL, NULL, NULL )) return 0;
423 if (!(attr & FA_DIRECTORY))
425 DOS_ERROR( ER_FileNotFound, EC_NotFound, SA_Abort, EL_Disk );
426 return 0;
428 unix_cwd += strlen( DOSDrives[drive].root );
429 while (*unix_cwd == '/') unix_cwd++;
430 buffer[2] = '/';
431 lstrcpyn32A( buffer + 3, unix_cwd, sizeof(buffer) - 3 );
432 if (!(dos_cwd = DOSFS_GetDosTrueName( buffer, TRUE ))) return 0;
434 dprintf_dosfs( stddeb, "DRIVE_Chdir(%c:): unix_cwd=%s dos_cwd=%s\n",
435 'A' + drive, unix_cwd, dos_cwd + 3 );
437 free( DOSDrives[drive].dos_cwd );
438 free( DOSDrives[drive].unix_cwd );
439 DOSDrives[drive].dos_cwd = xstrdup( dos_cwd + 3 );
440 DOSDrives[drive].unix_cwd = xstrdup( unix_cwd );
442 if (pTask && (pTask->curdrive & 0x80) &&
443 ((pTask->curdrive & ~0x80) == drive))
445 lstrcpyn32A( pTask->curdir, dos_cwd + 2, sizeof(pTask->curdir) );
446 DRIVE_LastTask = GetCurrentTask();
448 return 1;
452 /***********************************************************************
453 * DRIVE_Disable
455 int DRIVE_Disable( int drive )
457 if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root)
459 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
460 return 0;
462 DOSDrives[drive].flags |= DRIVE_DISABLED;
463 return 1;
467 /***********************************************************************
468 * DRIVE_Enable
470 int DRIVE_Enable( int drive )
472 if ((drive < 0) || (drive >= MAX_DOS_DRIVES) || !DOSDrives[drive].root)
474 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
475 return 0;
477 DOSDrives[drive].flags &= ~DRIVE_DISABLED;
478 return 1;
482 /***********************************************************************
483 * DRIVE_GetFreeSpace
485 static int DRIVE_GetFreeSpace( int drive, DWORD *size, DWORD *available )
487 struct statfs info;
489 if (!DRIVE_IsValid(drive))
491 DOS_ERROR( ER_InvalidDrive, EC_MediaError, SA_Abort, EL_Disk );
492 return 0;
495 #if defined(__svr4__) || defined(_SCO_DS)
496 if (statfs( DOSDrives[drive].root, &info, 0, 0) < 0)
497 #else
498 if (statfs( DOSDrives[drive].root, &info) < 0)
499 #endif
501 FILE_SetDosError();
502 fprintf(stderr,"dosfs: cannot do statfs(%s)\n", DOSDrives[drive].root);
503 return 0;
506 *size = info.f_bsize * info.f_blocks;
507 #if defined(__svr4__) || defined(_SCO_DS)
508 *available = info.f_bfree * info.f_bsize;
509 #else
510 *available = info.f_bavail * info.f_bsize;
511 #endif
512 return 1;
516 /***********************************************************************
517 * GetDiskFreeSpace16 (KERNEL.422)
519 BOOL16 GetDiskFreeSpace16( LPCSTR root, LPDWORD cluster_sectors,
520 LPDWORD sector_bytes, LPDWORD free_clusters,
521 LPDWORD total_clusters )
523 return GetDiskFreeSpace32A( root, cluster_sectors, sector_bytes,
524 free_clusters, total_clusters );
528 /***********************************************************************
529 * GetDiskFreeSpaceA (KERNEL32.206)
531 BOOL32 GetDiskFreeSpace32A( LPCSTR root, LPDWORD cluster_sectors,
532 LPDWORD sector_bytes, LPDWORD free_clusters,
533 LPDWORD total_clusters )
535 int drive;
536 DWORD size,available;
538 if (!root) drive = DRIVE_GetCurrentDrive();
539 else
541 if ((root[1] != ':') || (root[2] != '\\'))
543 fprintf( stderr, "GetDiskFreeSpaceA: invalid root '%s'\n", root );
544 return FALSE;
546 drive = toupper(root[0]) - 'A';
548 if (!DRIVE_GetFreeSpace(drive, &size, &available)) return FALSE;
550 *sector_bytes = 512;
551 size /= 512;
552 available /= 512;
553 *cluster_sectors = 1;
554 while (*cluster_sectors * 65530 < size) *cluster_sectors *= 2;
555 *free_clusters = available/ *cluster_sectors;
556 *total_clusters = size/ *cluster_sectors;
557 return TRUE;
561 /***********************************************************************
562 * GetDiskFreeSpaceW (KERNEL32.207)
564 BOOL32 GetDiskFreeSpace32W( LPCWSTR root, LPDWORD cluster_sectors,
565 LPDWORD sector_bytes, LPDWORD free_clusters,
566 LPDWORD total_clusters )
568 LPSTR xroot;
569 BOOL ret;
571 xroot = STRING32_DupUniToAnsi(root);
572 ret = GetDiskFreeSpace32A( xroot,cluster_sectors, sector_bytes,
573 free_clusters, total_clusters );
574 free( xroot );
575 return ret;
579 /***********************************************************************
580 * GetDriveType16 (KERNEL.136)
582 UINT16 GetDriveType16( UINT16 drive )
584 dprintf_dosfs( stddeb, "GetDriveType(%c:)\n", 'A' + drive );
585 switch(DRIVE_GetType(drive))
587 case TYPE_FLOPPY: return DRIVE_REMOVABLE;
588 case TYPE_HD: return DRIVE_FIXED;
589 case TYPE_CDROM: return DRIVE_REMOTE;
590 case TYPE_NETWORK: return DRIVE_REMOTE;
591 case TYPE_INVALID:
592 default: return DRIVE_CANNOTDETERMINE;
597 /***********************************************************************
598 * GetDriveType32A (KERNEL32.208)
600 UINT32 GetDriveType32A( LPCSTR root )
602 dprintf_dosfs( stddeb, "GetDriveType32A(%s)\n", root );
603 if ((root[1] != ':') || (root[2] != '\\'))
605 fprintf( stderr, "GetDriveType32A: invalid root '%s'\n", root );
606 return DRIVE_DOESNOTEXIST;
608 switch(DRIVE_GetType(toupper(root[0]) - 'A'))
610 case TYPE_FLOPPY: return DRIVE_REMOVABLE;
611 case TYPE_HD: return DRIVE_FIXED;
612 case TYPE_CDROM: return DRIVE_CDROM;
613 case TYPE_NETWORK: return DRIVE_REMOTE;
614 case TYPE_INVALID:
615 default: return DRIVE_CANNOTDETERMINE;
620 /***********************************************************************
621 * GetDriveType32W (KERNEL32.209)
623 UINT32 GetDriveType32W( LPCWSTR root )
625 LPSTR xpath=STRING32_DupUniToAnsi(root);
626 UINT32 ret;
628 ret = GetDriveType32A(xpath);
629 free(xpath);
630 return ret;
634 /***********************************************************************
635 * GetCurrentDirectory16 (KERNEL.411)
637 UINT16 GetCurrentDirectory16( UINT16 buflen, LPSTR buf )
639 return (UINT16)GetCurrentDirectory32A( buflen, buf );
643 /***********************************************************************
644 * GetCurrentDirectory32A (KERNEL32.196)
646 * Returns "X:\\path\\etc\\".
648 UINT32 GetCurrentDirectory32A( UINT32 buflen, LPSTR buf )
650 char *pref = "A:\\";
651 const char *s = DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() );
652 if (!s)
654 *buf = '\0';
655 return 0;
657 lstrcpyn32A( buf, pref, 3 );
658 if (buflen) buf[0] += DRIVE_GetCurrentDrive();
659 if (buflen >= 3) lstrcpyn32A( buf + 3, s, buflen - 3 );
660 return strlen(s) + 3; /* length of WHOLE current directory */
664 /***********************************************************************
665 * GetCurrentDirectory32W (KERNEL32.197)
667 UINT32 GetCurrentDirectory32W( UINT32 buflen, LPWSTR buf )
669 LPSTR xpath=(char*)xmalloc(buflen+1);
670 UINT32 ret;
672 ret = GetCurrentDirectory32A(buflen,xpath);
673 STRING32_AnsiToUni(buf,xpath);
674 free(xpath);
675 return ret;
679 /***********************************************************************
680 * SetCurrentDirectory (KERNEL.412)
682 BOOL32 SetCurrentDirectory( LPCSTR dir )
684 return DRIVE_Chdir( DRIVE_GetCurrentDrive(), dir );
688 /***********************************************************************
689 * GetLogicalDriveStrings32A (KERNEL32.231)
691 UINT32 GetLogicalDriveStrings32A( UINT32 len, LPSTR buffer )
693 int drive, count;
695 for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
696 if (DRIVE_IsValid(drive)) count++;
697 if (count * 4 * sizeof(char) <= len)
699 LPSTR p = buffer;
700 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
701 if (DRIVE_IsValid(drive))
703 *p++ = 'a' + drive;
704 *p++ = ':';
705 *p++ = '\\';
706 *p++ = '\0';
708 *p = '\0';
710 return count * 4 * sizeof(char);
714 /***********************************************************************
715 * GetLogicalDriveStrings32W (KERNEL32.232)
717 UINT32 GetLogicalDriveStrings32W( UINT32 len, LPWSTR buffer )
719 int drive, count;
721 for (drive = count = 0; drive < MAX_DOS_DRIVES; drive++)
722 if (DRIVE_IsValid(drive)) count++;
723 if (count * 4 * sizeof(WCHAR) <= len)
725 LPWSTR p = buffer;
726 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
727 if (DRIVE_IsValid(drive))
729 *p++ = (WCHAR)('a' + drive);
730 *p++ = (WCHAR)':';
731 *p++ = (WCHAR)'\\';
732 *p++ = (WCHAR)'\0';
734 *p = (WCHAR)'\0';
736 return count * 4 * sizeof(WCHAR);
740 /***********************************************************************
741 * GetLogicalDrives (KERNEL32.233)
743 DWORD GetLogicalDrives(void)
745 DWORD ret = 0;
746 int drive;
748 for (drive = 0; drive < MAX_DOS_DRIVES; drive++)
749 if (DRIVE_IsValid(drive)) ret |= (1 << drive);
750 return ret;
754 /***********************************************************************
755 * GetVolumeInformation32A (KERNEL32.309)
757 BOOL32 GetVolumeInformation32A( LPCSTR root, LPSTR label, DWORD label_len,
758 DWORD *serial, DWORD *filename_len,
759 DWORD *flags, LPSTR fsname, DWORD fsname_len )
761 int drive;
763 /* FIXME, SetLastErrors missing */
765 if (!root) drive = DRIVE_GetCurrentDrive();
766 else
768 if ((root[1] != ':') || (root[2] != '\\'))
770 fprintf( stderr, "GetVolumeInformation: invalid root '%s'\n",root);
771 return FALSE;
773 drive = toupper(root[0]) - 'A';
775 if (!DRIVE_IsValid( drive )) return FALSE;
776 if (label) lstrcpyn32A( label, DOSDrives[drive].label, label_len );
777 if (serial) *serial = DOSDrives[drive].serial;
779 /* Set the filesystem information */
780 /* Note: we only emulate a FAT fs at the present */
782 if (filename_len) *filename_len = 12;
783 if (flags) *flags = 0;
784 if (fsname) lstrcpyn32A( fsname, "FAT", fsname_len );
785 return TRUE;
789 /***********************************************************************
790 * GetVolumeInformation32W (KERNEL32.310)
792 BOOL32 GetVolumeInformation32W( LPCWSTR root, LPWSTR label, DWORD label_len,
793 DWORD *serial, DWORD *filename_len,
794 DWORD *flags, LPWSTR fsname, DWORD fsname_len)
796 LPSTR xroot = STRING32_DupUniToAnsi(root);
797 LPSTR xvolname = (char*)xmalloc( label_len );
798 LPSTR xfsname = (char*)xmalloc( fsname_len );
799 BOOL32 ret = GetVolumeInformation32A( xroot, xvolname, label_len, serial,
800 filename_len, flags, xfsname,
801 fsname_len );
802 if (ret)
804 STRING32_AnsiToUni( label, xvolname );
805 STRING32_AnsiToUni( fsname, xfsname );
807 free(xroot);
808 free(xvolname);
809 free(xfsname);
810 return ret;