2 * DOS drives handling functions
4 * Copyright 1993 Erik Bos
5 * Copyright 1996 Alexandre Julliard
14 #include <sys/types.h>
20 #ifdef HAVE_SYS_PARAM_H
21 # include <sys/param.h>
23 #ifdef STATFS_DEFINED_BY_SYS_VFS
26 # ifdef STATFS_DEFINED_BY_SYS_MOUNT
27 # include <sys/mount.h>
29 # ifdef STATFS_DEFINED_BY_SYS_STATFS
30 # include <sys/statfs.h>
36 #include "wine/winbase16.h" /* for GetCurrentTask */
37 #include "wine/winestring.h" /* for lstrcpyAtoW */
49 char *root
; /* root dir in Unix format without trailing / */
50 char *dos_cwd
; /* cwd in DOS format without leading or trailing \ */
51 char *unix_cwd
; /* cwd in Unix format without leading or trailing / */
52 char *device
; /* raw device path */
53 char label
[12]; /* drive label */
54 DWORD serial
; /* drive serial number */
55 DRIVETYPE type
; /* drive type */
56 UINT flags
; /* drive flags */
57 dev_t dev
; /* unix device number */
58 ino_t ino
; /* unix inode number */
62 static const char * const DRIVE_Types
[] =
64 "floppy", /* TYPE_FLOPPY */
66 "cdrom", /* TYPE_CDROM */
67 "network" /* TYPE_NETWORK */
71 /* Known filesystem types */
79 static const FS_DESCR DRIVE_Filesystems
[] =
81 { "unix", DRIVE_CASE_SENSITIVE
| DRIVE_CASE_PRESERVING
},
82 { "msdos", DRIVE_SHORT_NAMES
},
83 { "dos", DRIVE_SHORT_NAMES
},
84 { "fat", DRIVE_SHORT_NAMES
},
85 { "vfat", DRIVE_CASE_PRESERVING
},
86 { "win95", DRIVE_CASE_PRESERVING
},
91 static DOSDRIVE DOSDrives
[MAX_DOS_DRIVES
];
92 static int DRIVE_CurDrive
= -1;
94 static HTASK16 DRIVE_LastTask
= 0;
97 /***********************************************************************
100 static DRIVETYPE
DRIVE_GetDriveType( const char *name
)
105 PROFILE_GetWineIniString( name
, "Type", "hd", buffer
, sizeof(buffer
) );
106 for (i
= 0; i
< sizeof(DRIVE_Types
)/sizeof(DRIVE_Types
[0]); i
++)
108 if (!strcasecmp( buffer
, DRIVE_Types
[i
] )) return (DRIVETYPE
)i
;
110 MSG("%s: unknown type '%s', defaulting to 'hd'.\n", name
, buffer
);
115 /***********************************************************************
118 static UINT
DRIVE_GetFSFlags( const char *name
, const char *value
)
120 const FS_DESCR
*descr
;
122 for (descr
= DRIVE_Filesystems
; descr
->name
; descr
++)
123 if (!strcasecmp( value
, descr
->name
)) return descr
->flags
;
124 MSG("%s: unknown filesystem type '%s', defaulting to 'win95'.\n",
126 return DRIVE_CASE_PRESERVING
;
130 /***********************************************************************
135 int i
, len
, count
= 0;
136 char name
[] = "Drive A";
137 char path
[MAX_PATHNAME_LEN
];
139 struct stat drive_stat_buffer
;
143 for (i
= 0, drive
= DOSDrives
; i
< MAX_DOS_DRIVES
; i
++, name
[6]++, drive
++)
145 PROFILE_GetWineIniString( name
, "Path", "", path
, sizeof(path
)-1 );
148 p
= path
+ strlen(path
) - 1;
149 while ((p
> path
) && ((*p
== '/') || (*p
== '\\'))) *p
-- = '\0';
150 if (!path
[0]) strcpy( path
, "/" );
152 if (stat( path
, &drive_stat_buffer
))
154 MSG("Could not stat %s, ignoring drive %c:\n", path
, 'A' + i
);
157 if (!S_ISDIR(drive_stat_buffer
.st_mode
))
159 MSG("%s is not a directory, ignoring drive %c:\n",
164 drive
->root
= HEAP_strdupA( SystemHeap
, 0, path
);
165 drive
->dos_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
166 drive
->unix_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
167 drive
->type
= DRIVE_GetDriveType( name
);
168 drive
->device
= NULL
;
170 drive
->dev
= drive_stat_buffer
.st_dev
;
171 drive
->ino
= drive_stat_buffer
.st_ino
;
173 /* Get the drive label */
174 PROFILE_GetWineIniString( name
, "Label", name
, drive
->label
, 12 );
175 if ((len
= strlen(drive
->label
)) < 11)
177 /* Pad label with spaces */
178 memset( drive
->label
+ len
, ' ', 11 - len
);
179 drive
->label
[12] = '\0';
182 /* Get the serial number */
183 PROFILE_GetWineIniString( name
, "Serial", "12345678",
184 buffer
, sizeof(buffer
) );
185 drive
->serial
= strtoul( buffer
, NULL
, 16 );
187 /* Get the filesystem type */
188 PROFILE_GetWineIniString( name
, "Filesystem", "win95",
189 buffer
, sizeof(buffer
) );
190 drive
->flags
= DRIVE_GetFSFlags( name
, buffer
);
193 PROFILE_GetWineIniString( name
, "Device", "",
194 buffer
, sizeof(buffer
) );
196 drive
->device
= HEAP_strdupA( SystemHeap
, 0, buffer
);
198 /* Make the first hard disk the current drive */
199 if ((DRIVE_CurDrive
== -1) && (drive
->type
== TYPE_HD
))
203 TRACE(dosfs
, "%s: path=%s type=%s label='%s' serial=%08lx flags=%08x dev=%x ino=%x\n",
204 name
, path
, DRIVE_Types
[drive
->type
],
205 drive
->label
, drive
->serial
, drive
->flags
,
206 (int)drive
->dev
, (int)drive
->ino
);
208 else WARN(dosfs
, "%s: not defined\n", name
);
213 MSG("Warning: no valid DOS drive found, check your configuration file.\n" );
214 /* Create a C drive pointing to Unix root dir */
215 DOSDrives
[2].root
= HEAP_strdupA( SystemHeap
, 0, "/" );
216 DOSDrives
[2].dos_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
217 DOSDrives
[2].unix_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
218 strcpy( DOSDrives
[2].label
, "Drive C " );
219 DOSDrives
[2].serial
= 0x12345678;
220 DOSDrives
[2].type
= TYPE_HD
;
221 DOSDrives
[2].flags
= 0;
225 /* Make sure the current drive is valid */
226 if (DRIVE_CurDrive
== -1)
228 for (i
= 0, drive
= DOSDrives
; i
< MAX_DOS_DRIVES
; i
++, drive
++)
230 if (drive
->root
&& !(drive
->flags
& DRIVE_DISABLED
))
242 /***********************************************************************
245 int DRIVE_IsValid( int drive
)
247 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
)) return 0;
248 return (DOSDrives
[drive
].root
&&
249 !(DOSDrives
[drive
].flags
& DRIVE_DISABLED
));
253 /***********************************************************************
254 * DRIVE_GetCurrentDrive
256 int DRIVE_GetCurrentDrive(void)
258 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
259 if (pTask
&& (pTask
->curdrive
& 0x80)) return pTask
->curdrive
& ~0x80;
260 return DRIVE_CurDrive
;
264 /***********************************************************************
265 * DRIVE_SetCurrentDrive
267 int DRIVE_SetCurrentDrive( int drive
)
269 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
270 if (!DRIVE_IsValid( drive
))
272 SetLastError( ERROR_INVALID_DRIVE
);
275 TRACE(dosfs
, "%c:\n", 'A' + drive
);
276 DRIVE_CurDrive
= drive
;
277 if (pTask
) pTask
->curdrive
= drive
| 0x80;
282 /***********************************************************************
283 * DRIVE_FindDriveRoot
285 * Find a drive for which the root matches the begginning of the given path.
286 * This can be used to translate a Unix path into a drive + DOS path.
287 * Return value is the drive, or -1 on error. On success, path is modified
288 * to point to the beginning of the DOS path.
290 int DRIVE_FindDriveRoot( const char **path
)
292 /* idea: check at all '/' positions.
293 * If the device and inode of that path is identical with the
294 * device and inode of the current drive then we found a solution.
295 * If there is another drive pointing to a deeper position in
296 * the file tree, we want to find that one, not the earlier solution.
298 int drive
, rootdrive
= -1;
299 char buffer
[MAX_PATHNAME_LEN
];
301 const char *p
= *path
;
304 strcpy( buffer
, "/" );
307 if (stat( buffer
, &st
) || !S_ISDIR( st
.st_mode
)) break;
311 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
313 if (!DOSDrives
[drive
].root
||
314 (DOSDrives
[drive
].flags
& DRIVE_DISABLED
)) continue;
316 if ((DOSDrives
[drive
].dev
== st
.st_dev
) &&
317 (DOSDrives
[drive
].ino
== st
.st_ino
))
324 /* Get the next path component */
327 while ((*p
== '/') || (*p
== '\\')) p
++;
329 while (!IS_END_OF_NAME(*p
)) *next
++ = *p
++;
335 TRACE(dosfs
, "%s -> drive %c:, root='%s', name='%s'\n",
336 buffer
, 'A' + rootdrive
,
337 DOSDrives
[rootdrive
].root
, *path
);
342 /***********************************************************************
345 const char * DRIVE_GetRoot( int drive
)
347 if (!DRIVE_IsValid( drive
)) return NULL
;
348 return DOSDrives
[drive
].root
;
352 /***********************************************************************
355 const char * DRIVE_GetDosCwd( int drive
)
357 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
358 if (!DRIVE_IsValid( drive
)) return NULL
;
360 /* Check if we need to change the directory to the new task. */
361 if (pTask
&& (pTask
->curdrive
& 0x80) && /* The task drive is valid */
362 ((pTask
->curdrive
& ~0x80) == drive
) && /* and it's the one we want */
363 (DRIVE_LastTask
!= GetCurrentTask())) /* and the task changed */
365 /* Perform the task-switch */
366 if (!DRIVE_Chdir( drive
, pTask
->curdir
)) DRIVE_Chdir( drive
, "\\" );
367 DRIVE_LastTask
= GetCurrentTask();
369 return DOSDrives
[drive
].dos_cwd
;
373 /***********************************************************************
376 const char * DRIVE_GetUnixCwd( int drive
)
378 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
379 if (!DRIVE_IsValid( drive
)) return NULL
;
381 /* Check if we need to change the directory to the new task. */
382 if (pTask
&& (pTask
->curdrive
& 0x80) && /* The task drive is valid */
383 ((pTask
->curdrive
& ~0x80) == drive
) && /* and it's the one we want */
384 (DRIVE_LastTask
!= GetCurrentTask())) /* and the task changed */
386 /* Perform the task-switch */
387 if (!DRIVE_Chdir( drive
, pTask
->curdir
)) DRIVE_Chdir( drive
, "\\" );
388 DRIVE_LastTask
= GetCurrentTask();
390 return DOSDrives
[drive
].unix_cwd
;
394 /***********************************************************************
397 const char * DRIVE_GetLabel( int drive
)
399 if (!DRIVE_IsValid( drive
)) return NULL
;
400 return DOSDrives
[drive
].label
;
404 /***********************************************************************
405 * DRIVE_GetSerialNumber
407 DWORD
DRIVE_GetSerialNumber( int drive
)
409 if (!DRIVE_IsValid( drive
)) return 0;
410 return DOSDrives
[drive
].serial
;
414 /***********************************************************************
415 * DRIVE_SetSerialNumber
417 int DRIVE_SetSerialNumber( int drive
, DWORD serial
)
419 if (!DRIVE_IsValid( drive
)) return 0;
420 DOSDrives
[drive
].serial
= serial
;
425 /***********************************************************************
428 DRIVETYPE
DRIVE_GetType( int drive
)
430 if (!DRIVE_IsValid( drive
)) return TYPE_INVALID
;
431 return DOSDrives
[drive
].type
;
435 /***********************************************************************
438 UINT
DRIVE_GetFlags( int drive
)
440 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
)) return 0;
441 return DOSDrives
[drive
].flags
;
445 /***********************************************************************
448 int DRIVE_Chdir( int drive
, const char *path
)
450 DOS_FULL_NAME full_name
;
451 char buffer
[MAX_PATHNAME_LEN
];
453 BY_HANDLE_FILE_INFORMATION info
;
454 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
456 strcpy( buffer
, "A:" );
458 TRACE(dosfs
, "(%c:,%s)\n", buffer
[0], path
);
459 lstrcpynA( buffer
+ 2, path
, sizeof(buffer
) - 2 );
461 if (!DOSFS_GetFullName( buffer
, TRUE
, &full_name
)) return 0;
462 if (!FILE_Stat( full_name
.long_name
, &info
)) return 0;
463 if (!(info
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
465 SetLastError( ERROR_FILE_NOT_FOUND
);
468 unix_cwd
= full_name
.long_name
+ strlen( DOSDrives
[drive
].root
);
469 while (*unix_cwd
== '/') unix_cwd
++;
471 TRACE(dosfs
, "(%c:): unix_cwd=%s dos_cwd=%s\n",
472 'A' + drive
, unix_cwd
, full_name
.short_name
+ 3 );
474 HeapFree( SystemHeap
, 0, DOSDrives
[drive
].dos_cwd
);
475 HeapFree( SystemHeap
, 0, DOSDrives
[drive
].unix_cwd
);
476 DOSDrives
[drive
].dos_cwd
= HEAP_strdupA( SystemHeap
, 0,
477 full_name
.short_name
+ 3 );
478 DOSDrives
[drive
].unix_cwd
= HEAP_strdupA( SystemHeap
, 0, unix_cwd
);
480 if (pTask
&& (pTask
->curdrive
& 0x80) &&
481 ((pTask
->curdrive
& ~0x80) == drive
))
483 lstrcpynA( pTask
->curdir
, full_name
.short_name
+ 2,
484 sizeof(pTask
->curdir
) );
485 DRIVE_LastTask
= GetCurrentTask();
491 /***********************************************************************
494 int DRIVE_Disable( int drive
)
496 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
) || !DOSDrives
[drive
].root
)
498 SetLastError( ERROR_INVALID_DRIVE
);
501 DOSDrives
[drive
].flags
|= DRIVE_DISABLED
;
506 /***********************************************************************
509 int DRIVE_Enable( int drive
)
511 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
) || !DOSDrives
[drive
].root
)
513 SetLastError( ERROR_INVALID_DRIVE
);
516 DOSDrives
[drive
].flags
&= ~DRIVE_DISABLED
;
521 /***********************************************************************
522 * DRIVE_SetLogicalMapping
524 int DRIVE_SetLogicalMapping ( int existing_drive
, int new_drive
)
526 /* If new_drive is already valid, do nothing and return 0
527 otherwise, copy DOSDrives[existing_drive] to DOSDrives[new_drive] */
531 old
= DOSDrives
+ existing_drive
;
532 new = DOSDrives
+ new_drive
;
534 if ((existing_drive
< 0) || (existing_drive
>= MAX_DOS_DRIVES
) ||
536 (new_drive
< 0) || (new_drive
>= MAX_DOS_DRIVES
))
538 SetLastError( ERROR_INVALID_DRIVE
);
544 TRACE(dosfs
, "Can\'t map drive %c to drive %c - "
545 "drive %c already exists\n",
546 'A' + existing_drive
, 'A' + new_drive
,
548 /* it is already mapped there, so return success */
549 if (!strcmp(old
->root
,new->root
))
554 new->root
= HEAP_strdupA( SystemHeap
, 0, old
->root
);
555 new->dos_cwd
= HEAP_strdupA( SystemHeap
, 0, old
->dos_cwd
);
556 new->unix_cwd
= HEAP_strdupA( SystemHeap
, 0, old
->unix_cwd
);
557 memcpy ( new->label
, old
->label
, 12 );
558 new->serial
= old
->serial
;
559 new->type
= old
->type
;
560 new->flags
= old
->flags
;
564 TRACE(dosfs
, "Drive %c is now equal to drive %c\n",
565 'A' + new_drive
, 'A' + existing_drive
);
571 /***********************************************************************
574 * Open the drive raw device and return a Unix fd (or -1 on error).
576 int DRIVE_OpenDevice( int drive
, int flags
)
578 if (!DRIVE_IsValid( drive
)) return -1;
579 return open( DOSDrives
[drive
].device
, flags
);
583 /***********************************************************************
586 * Read raw sectors from a device
588 int DRIVE_RawRead(BYTE drive
, DWORD begin
, DWORD nr_sect
, BYTE
*dataptr
, BOOL fake_success
)
592 if ((fd
= DRIVE_OpenDevice( drive
, O_RDONLY
)) != -1)
594 lseek( fd
, begin
* 512, SEEK_SET
);
595 /* FIXME: check errors */
596 read( fd
, dataptr
, nr_sect
* 512 );
601 memset(dataptr
, 0, nr_sect
* 512);
604 if (begin
== 0 && nr_sect
> 1) *(dataptr
+ 512) = 0xf8;
605 if (begin
== 1) *dataptr
= 0xf8;
614 /***********************************************************************
617 * Write raw sectors to a device
619 int DRIVE_RawWrite(BYTE drive
, DWORD begin
, DWORD nr_sect
, BYTE
*dataptr
, BOOL fake_success
)
623 if ((fd
= DRIVE_OpenDevice( drive
, O_RDONLY
)) != -1)
625 lseek( fd
, begin
* 512, SEEK_SET
);
626 /* FIXME: check errors */
627 write( fd
, dataptr
, nr_sect
* 512 );
638 /***********************************************************************
641 static int DRIVE_GetFreeSpace( int drive
, PULARGE_INTEGER size
,
642 PULARGE_INTEGER available
)
645 unsigned long long bigsize
,bigavail
=0;
647 if (!DRIVE_IsValid(drive
))
649 SetLastError( ERROR_INVALID_DRIVE
);
653 /* FIXME: add autoconf check for this */
654 #if defined(__svr4__) || defined(_SCO_DS)
655 if (statfs( DOSDrives
[drive
].root
, &info
, 0, 0) < 0)
657 if (statfs( DOSDrives
[drive
].root
, &info
) < 0)
661 WARN(dosfs
, "cannot do statfs(%s)\n", DOSDrives
[drive
].root
);
665 bigsize
= (unsigned long long)info
.f_bsize
666 * (unsigned long long)info
.f_blocks
;
667 #ifdef STATFS_HAS_BAVAIL
668 bigavail
= (unsigned long long)info
.f_bavail
669 * (unsigned long long)info
.f_bsize
;
671 # ifdef STATFS_HAS_BFREE
672 bigavail
= (unsigned long long)info
.f_bfree
673 * (unsigned long long)info
.f_bsize
;
675 # error "statfs has no bfree/bavail member!"
678 size
->LowPart
= (DWORD
)bigsize
;
679 size
->HighPart
= (DWORD
)(bigsize
>>32);
680 available
->LowPart
= (DWORD
)bigavail
;
681 available
->HighPart
= (DWORD
)(bigavail
>>32);
686 /***********************************************************************
687 * GetDiskFreeSpace16 (KERNEL.422)
689 BOOL16 WINAPI
GetDiskFreeSpace16( LPCSTR root
, LPDWORD cluster_sectors
,
690 LPDWORD sector_bytes
, LPDWORD free_clusters
,
691 LPDWORD total_clusters
)
693 return GetDiskFreeSpaceA( root
, cluster_sectors
, sector_bytes
,
694 free_clusters
, total_clusters
);
698 /***********************************************************************
699 * GetDiskFreeSpace32A (KERNEL32.206)
701 * Fails if expression resulting from current drive's dir and "root"
702 * is not a root dir of the target drive.
704 * UNDOC: setting some LPDWORDs to NULL is perfectly possible
705 * if the corresponding info is unneeded.
707 * FIXME: needs to support UNC names from Win95 OSR2 on.
709 * Behaviour under Win95a:
710 * CurrDir root result
711 * "E:\\TEST" "E:" FALSE
715 * "E:\\TEST" "\\" TRUE
716 * "E:\\TEST" ":\\" FALSE
717 * "E:\\TEST" "E:\\" TRUE
718 * "E:\\TEST" "" FALSE
719 * "E:\\" "" FALSE (!)
721 * "E:\\TEST" 0x0 TRUE (!)
722 * "E:\\TEST" "C:" TRUE (when CurrDir of "C:" set to "\\")
723 * "E:\\TEST" "C:" FALSE (when CurrDir of "C:" set to "\\TEST")
725 BOOL WINAPI
GetDiskFreeSpaceA( LPCSTR root
, LPDWORD cluster_sectors
,
726 LPDWORD sector_bytes
, LPDWORD free_clusters
,
727 LPDWORD total_clusters
)
730 ULARGE_INTEGER size
,available
;
734 if ((!root
) || (root
== "\\"))
735 drive
= DRIVE_GetCurrentDrive();
737 if ( (strlen(root
) >= 2) && (root
[1] == ':')) /* root contains drive tag */
739 drive
= toupper(root
[0]) - 'A';
742 path
= DRIVE_GetDosCwd(drive
);
746 if (strlen(path
)) /* oops, we are in a subdir */
752 if (!DRIVE_GetFreeSpace(drive
, &size
, &available
)) return FALSE
;
754 /* Cap the size and available at 2GB as per specs. */
755 if ((size
.HighPart
) ||(size
.LowPart
> 0x7fffffff))
758 size
.LowPart
= 0x7fffffff;
760 if ((available
.HighPart
) ||(available
.LowPart
> 0x7fffffff))
762 available
.HighPart
=0;
763 available
.LowPart
= 0x7fffffff;
765 if (DRIVE_GetType(drive
)==TYPE_CDROM
) {
767 *sector_bytes
= 2048;
768 size
.LowPart
/= 2048;
769 available
.LowPart
/= 2048;
774 available
.LowPart
/= 512;
776 /* fixme: probably have to adjust those variables too for CDFS */
778 while (cluster_sec
* 65536 < size
.LowPart
) cluster_sec
*= 2;
781 *cluster_sectors
= cluster_sec
;
783 *free_clusters
= available
.LowPart
/ cluster_sec
;
785 *total_clusters
= size
.LowPart
/ cluster_sec
;
790 /***********************************************************************
791 * GetDiskFreeSpace32W (KERNEL32.207)
793 BOOL WINAPI
GetDiskFreeSpaceW( LPCWSTR root
, LPDWORD cluster_sectors
,
794 LPDWORD sector_bytes
, LPDWORD free_clusters
,
795 LPDWORD total_clusters
)
800 xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
801 ret
= GetDiskFreeSpaceA( xroot
,cluster_sectors
, sector_bytes
,
802 free_clusters
, total_clusters
);
803 HeapFree( GetProcessHeap(), 0, xroot
);
808 /***********************************************************************
809 * GetDiskFreeSpaceEx32A (KERNEL32.871)
811 BOOL WINAPI
GetDiskFreeSpaceExA( LPCSTR root
,
812 PULARGE_INTEGER avail
,
813 PULARGE_INTEGER total
,
814 PULARGE_INTEGER totalfree
)
817 ULARGE_INTEGER size
,available
;
819 if (!root
) drive
= DRIVE_GetCurrentDrive();
822 if ((root
[1]) && ((root
[1] != ':') || (root
[2] != '\\')))
824 WARN(dosfs
, "invalid root '%s'\n", root
);
827 drive
= toupper(root
[0]) - 'A';
829 if (!DRIVE_GetFreeSpace(drive
, &size
, &available
)) return FALSE
;
830 /*FIXME: Do we have the number of bytes available to the user? */
832 totalfree
->HighPart
= size
.HighPart
;
833 totalfree
->LowPart
= size
.LowPart
;
836 avail
->HighPart
= available
.HighPart
;
837 avail
->LowPart
= available
.LowPart
;
842 /***********************************************************************
843 * GetDiskFreeSpaceEx32W (KERNEL32.873)
845 BOOL WINAPI
GetDiskFreeSpaceExW( LPCWSTR root
, PULARGE_INTEGER avail
,
846 PULARGE_INTEGER total
,
847 PULARGE_INTEGER totalfree
)
852 xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
853 ret
= GetDiskFreeSpaceExA( xroot
, avail
, total
, totalfree
);
854 HeapFree( GetProcessHeap(), 0, xroot
);
858 /***********************************************************************
859 * GetDriveType16 (KERNEL.136)
860 * This functions returns the drivetype of a drive in Win16.
861 * Note that it returns DRIVE_REMOTE for CD-ROMs, since MSCDEX uses the
862 * remote drive API. The returnvalue DRIVE_REMOTE for CD-ROMs has been
863 * verified on Win3.11 and Windows 95. Some programs rely on it, so don't
864 * do any pseudo-clever changes.
867 * drivetype DRIVE_xxx
869 UINT16 WINAPI
GetDriveType16(
870 UINT16 drive
/* [in] number (NOT letter) of drive */
872 TRACE(dosfs
, "(%c:)\n", 'A' + drive
);
873 switch(DRIVE_GetType(drive
))
875 case TYPE_FLOPPY
: return DRIVE_REMOVABLE
;
876 case TYPE_HD
: return DRIVE_FIXED
;
877 case TYPE_CDROM
: return DRIVE_REMOTE
;
878 case TYPE_NETWORK
: return DRIVE_REMOTE
;
880 default: return DRIVE_CANNOTDETERMINE
;
885 /***********************************************************************
886 * GetDriveType32A (KERNEL32.208)
888 * Returns the type of the disk drive specified. If root is NULL the
889 * root of the current directory is used.
893 * Type of drive (from Win32 SDK):
895 * DRIVE_UNKNOWN unable to find out anything about the drive
896 * DRIVE_NO_ROOT_DIR nonexistand root dir
897 * DRIVE_REMOVABLE the disk can be removed from the machine
898 * DRIVE_FIXED the disk can not be removed from the machine
899 * DRIVE_REMOTE network disk
900 * DRIVE_CDROM CDROM drive
901 * DRIVE_RAMDISK virtual disk in ram
903 * DRIVE_DOESNOTEXIST XXX Not valid return value
904 * DRIVE_CANNOTDETERMINE XXX Not valid return value
908 * Currently returns DRIVE_DOESNOTEXIST and DRIVE_CANNOTDETERMINE
909 * when it really should return DRIVE_NO_ROOT_DIR and DRIVE_UNKNOWN.
910 * Why where the former defines used?
912 * DRIVE_RAMDISK is unsupported.
914 UINT WINAPI
GetDriveTypeA(LPCSTR root
/* String describing drive */)
917 TRACE(dosfs
, "(%s)\n", debugstr_a(root
));
919 if (NULL
== root
) drive
= DRIVE_GetCurrentDrive();
922 if ((root
[1]) && (root
[1] != ':'))
924 WARN(dosfs
, "invalid root '%s'\n", debugstr_a(root
));
925 return DRIVE_DOESNOTEXIST
;
927 drive
= toupper(root
[0]) - 'A';
929 switch(DRIVE_GetType(drive
))
931 case TYPE_FLOPPY
: return DRIVE_REMOVABLE
;
932 case TYPE_HD
: return DRIVE_FIXED
;
933 case TYPE_CDROM
: return DRIVE_CDROM
;
934 case TYPE_NETWORK
: return DRIVE_REMOTE
;
935 case TYPE_INVALID
: return DRIVE_DOESNOTEXIST
;
936 default: return DRIVE_CANNOTDETERMINE
;
941 /***********************************************************************
942 * GetDriveType32W (KERNEL32.209)
944 UINT WINAPI
GetDriveTypeW( LPCWSTR root
)
946 LPSTR xpath
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
947 UINT ret
= GetDriveTypeA( xpath
);
948 HeapFree( GetProcessHeap(), 0, xpath
);
953 /***********************************************************************
954 * GetCurrentDirectory16 (KERNEL.411)
956 UINT16 WINAPI
GetCurrentDirectory16( UINT16 buflen
, LPSTR buf
)
958 return (UINT16
)GetCurrentDirectoryA( buflen
, buf
);
962 /***********************************************************************
963 * GetCurrentDirectory32A (KERNEL32.196)
965 * Returns "X:\\path\\etc\\".
967 * Despite the API description, return required length including the
968 * terminating null when buffer too small. This is the real behaviour.
970 UINT WINAPI
GetCurrentDirectoryA( UINT buflen
, LPSTR buf
)
973 const char *s
= DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() );
976 ret
= strlen(s
) + 3; /* length of WHOLE current directory */
977 if (ret
>= buflen
) return ret
+ 1;
978 lstrcpynA( buf
, "A:\\", MIN( 4, buflen
) );
979 if (buflen
) buf
[0] += DRIVE_GetCurrentDrive();
980 if (buflen
> 3) lstrcpynA( buf
+ 3, s
, buflen
- 3 );
985 /***********************************************************************
986 * GetCurrentDirectory32W (KERNEL32.197)
988 UINT WINAPI
GetCurrentDirectoryW( UINT buflen
, LPWSTR buf
)
990 LPSTR xpath
= HeapAlloc( GetProcessHeap(), 0, buflen
+1 );
991 UINT ret
= GetCurrentDirectoryA( buflen
, xpath
);
992 lstrcpyAtoW( buf
, xpath
);
993 HeapFree( GetProcessHeap(), 0, xpath
);
998 /***********************************************************************
999 * SetCurrentDirectory (KERNEL.412)
1001 BOOL16 WINAPI
SetCurrentDirectory16( LPCSTR dir
)
1003 return SetCurrentDirectoryA( dir
);
1007 /***********************************************************************
1008 * SetCurrentDirectory32A (KERNEL32.479)
1010 BOOL WINAPI
SetCurrentDirectoryA( LPCSTR dir
)
1012 int olddrive
, drive
= DRIVE_GetCurrentDrive();
1015 ERR(file
,"(NULL)!\n");
1018 if (dir
[0] && (dir
[1]==':'))
1020 drive
= tolower( *dir
) - 'a';
1024 /* WARNING: we need to set the drive before the dir, as DRIVE_Chdir
1025 sets pTask->curdir only if pTask->curdrive is drive */
1026 olddrive
= drive
; /* in case DRIVE_Chdir fails */
1027 if (!(DRIVE_SetCurrentDrive( drive
)))
1029 /* FIXME: what about empty strings? Add a \\ ? */
1030 if (!DRIVE_Chdir( drive
, dir
)) {
1031 DRIVE_SetCurrentDrive(olddrive
);
1038 /***********************************************************************
1039 * SetCurrentDirectory32W (KERNEL32.480)
1041 BOOL WINAPI
SetCurrentDirectoryW( LPCWSTR dirW
)
1043 LPSTR dir
= HEAP_strdupWtoA( GetProcessHeap(), 0, dirW
);
1044 BOOL res
= SetCurrentDirectoryA( dir
);
1045 HeapFree( GetProcessHeap(), 0, dir
);
1050 /***********************************************************************
1051 * GetLogicalDriveStrings32A (KERNEL32.231)
1053 UINT WINAPI
GetLogicalDriveStringsA( UINT len
, LPSTR buffer
)
1057 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
1058 if (DRIVE_IsValid(drive
)) count
++;
1059 if (count
* 4 * sizeof(char) <= len
)
1062 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
1063 if (DRIVE_IsValid(drive
))
1072 return count
* 4 * sizeof(char);
1076 /***********************************************************************
1077 * GetLogicalDriveStrings32W (KERNEL32.232)
1079 UINT WINAPI
GetLogicalDriveStringsW( UINT len
, LPWSTR buffer
)
1083 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
1084 if (DRIVE_IsValid(drive
)) count
++;
1085 if (count
* 4 * sizeof(WCHAR
) <= len
)
1088 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
1089 if (DRIVE_IsValid(drive
))
1091 *p
++ = (WCHAR
)('a' + drive
);
1098 return count
* 4 * sizeof(WCHAR
);
1102 /***********************************************************************
1103 * GetLogicalDrives (KERNEL32.233)
1105 DWORD WINAPI
GetLogicalDrives(void)
1110 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
1111 if (DRIVE_IsValid(drive
)) ret
|= (1 << drive
);
1116 /***********************************************************************
1117 * GetVolumeInformation32A (KERNEL32.309)
1119 BOOL WINAPI
GetVolumeInformationA( LPCSTR root
, LPSTR label
,
1120 DWORD label_len
, DWORD
*serial
,
1121 DWORD
*filename_len
, DWORD
*flags
,
1122 LPSTR fsname
, DWORD fsname_len
)
1127 /* FIXME, SetLastErrors missing */
1129 if (!root
) drive
= DRIVE_GetCurrentDrive();
1132 if ((root
[1]) && (root
[1] != ':'))
1134 WARN(dosfs
, "invalid root '%s'\n",root
);
1137 drive
= toupper(root
[0]) - 'A';
1139 if (!DRIVE_IsValid( drive
)) return FALSE
;
1142 lstrcpynA( label
, DRIVE_GetLabel(drive
), label_len
);
1143 for (cp
= label
; *cp
; cp
++);
1144 while (cp
!= label
&& *(cp
-1) == ' ') cp
--;
1147 if (serial
) *serial
= DRIVE_GetSerialNumber(drive
);
1149 /* Set the filesystem information */
1150 /* Note: we only emulate a FAT fs at the present */
1153 if (DOSDrives
[drive
].flags
& DRIVE_SHORT_NAMES
)
1156 *filename_len
= 255;
1161 if (DOSDrives
[drive
].flags
& DRIVE_CASE_SENSITIVE
)
1162 *flags
|=FS_CASE_SENSITIVE
;
1163 if (DOSDrives
[drive
].flags
& DRIVE_CASE_PRESERVING
)
1164 *flags
|=FS_CASE_IS_PRESERVED
;
1167 /* Diablo checks that return code ... */
1168 if (DRIVE_GetType(drive
)==TYPE_CDROM
)
1169 lstrcpynA( fsname
, "CDFS", fsname_len
);
1171 lstrcpynA( fsname
, "FAT", fsname_len
);
1177 /***********************************************************************
1178 * GetVolumeInformation32W (KERNEL32.310)
1180 BOOL WINAPI
GetVolumeInformationW( LPCWSTR root
, LPWSTR label
,
1181 DWORD label_len
, DWORD
*serial
,
1182 DWORD
*filename_len
, DWORD
*flags
,
1183 LPWSTR fsname
, DWORD fsname_len
)
1185 LPSTR xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
1186 LPSTR xvolname
= label
? HeapAlloc(GetProcessHeap(),0,label_len
) : NULL
;
1187 LPSTR xfsname
= fsname
? HeapAlloc(GetProcessHeap(),0,fsname_len
) : NULL
;
1188 BOOL ret
= GetVolumeInformationA( xroot
, xvolname
, label_len
, serial
,
1189 filename_len
, flags
, xfsname
,
1193 if (label
) lstrcpyAtoW( label
, xvolname
);
1194 if (fsname
) lstrcpyAtoW( fsname
, xfsname
);
1196 HeapFree( GetProcessHeap(), 0, xroot
);
1197 HeapFree( GetProcessHeap(), 0, xvolname
);
1198 HeapFree( GetProcessHeap(), 0, xfsname
);
1202 BOOL WINAPI
SetVolumeLabelA(LPCSTR rootpath
,LPCSTR volname
) {
1203 FIXME(dosfs
,"(%s,%s),stub!\n",rootpath
,volname
);