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>
48 char *root
; /* root dir in Unix format without trailing / */
49 char *dos_cwd
; /* cwd in DOS format without leading or trailing \ */
50 char *unix_cwd
; /* cwd in Unix format without leading or trailing / */
51 char *device
; /* raw device path */
52 char label
[12]; /* drive label */
53 DWORD serial
; /* drive serial number */
54 DRIVETYPE type
; /* drive type */
55 UINT32 flags
; /* drive flags */
56 dev_t dev
; /* unix device number */
57 ino_t ino
; /* unix inode number */
61 static const char * const DRIVE_Types
[] =
63 "floppy", /* TYPE_FLOPPY */
65 "cdrom", /* TYPE_CDROM */
66 "network" /* TYPE_NETWORK */
70 /* Known filesystem types */
78 static const FS_DESCR DRIVE_Filesystems
[] =
80 { "unix", DRIVE_CASE_SENSITIVE
| DRIVE_CASE_PRESERVING
},
81 { "msdos", DRIVE_SHORT_NAMES
},
82 { "dos", DRIVE_SHORT_NAMES
},
83 { "fat", DRIVE_SHORT_NAMES
},
84 { "vfat", DRIVE_CASE_PRESERVING
},
85 { "win95", DRIVE_CASE_PRESERVING
},
90 static DOSDRIVE DOSDrives
[MAX_DOS_DRIVES
];
91 static int DRIVE_CurDrive
= -1;
93 static HTASK16 DRIVE_LastTask
= 0;
96 /***********************************************************************
99 static DRIVETYPE
DRIVE_GetDriveType( const char *name
)
104 PROFILE_GetWineIniString( name
, "Type", "hd", buffer
, sizeof(buffer
) );
105 for (i
= 0; i
< sizeof(DRIVE_Types
)/sizeof(DRIVE_Types
[0]); i
++)
107 if (!strcasecmp( buffer
, DRIVE_Types
[i
] )) return (DRIVETYPE
)i
;
109 MSG("%s: unknown type '%s', defaulting to 'hd'.\n", name
, buffer
);
114 /***********************************************************************
117 static UINT32
DRIVE_GetFSFlags( const char *name
, const char *value
)
119 const FS_DESCR
*descr
;
121 for (descr
= DRIVE_Filesystems
; descr
->name
; descr
++)
122 if (!strcasecmp( value
, descr
->name
)) return descr
->flags
;
123 MSG("%s: unknown filesystem type '%s', defaulting to 'unix'.\n",
125 return DRIVE_CASE_SENSITIVE
| DRIVE_CASE_PRESERVING
;
129 /***********************************************************************
134 int i
, len
, count
= 0;
135 char name
[] = "Drive A";
136 char path
[MAX_PATHNAME_LEN
];
138 struct stat drive_stat_buffer
;
142 for (i
= 0, drive
= DOSDrives
; i
< MAX_DOS_DRIVES
; i
++, name
[6]++, drive
++)
144 PROFILE_GetWineIniString( name
, "Path", "", path
, sizeof(path
)-1 );
147 p
= path
+ strlen(path
) - 1;
148 while ((p
> path
) && ((*p
== '/') || (*p
== '\\'))) *p
-- = '\0';
149 if (!path
[0]) strcpy( path
, "/" );
151 if (stat( path
, &drive_stat_buffer
))
153 MSG("Could not stat %s, ignoring drive %c:\n", path
, 'A' + i
);
156 if (!S_ISDIR(drive_stat_buffer
.st_mode
))
158 MSG("%s is not a directory, ignoring drive %c:\n",
163 drive
->root
= HEAP_strdupA( SystemHeap
, 0, path
);
164 drive
->dos_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
165 drive
->unix_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
166 drive
->type
= DRIVE_GetDriveType( name
);
167 drive
->device
= NULL
;
169 drive
->dev
= drive_stat_buffer
.st_dev
;
170 drive
->ino
= drive_stat_buffer
.st_ino
;
172 /* Get the drive label */
173 PROFILE_GetWineIniString( name
, "Label", name
, drive
->label
, 12 );
174 if ((len
= strlen(drive
->label
)) < 11)
176 /* Pad label with spaces */
177 memset( drive
->label
+ len
, ' ', 11 - len
);
178 drive
->label
[12] = '\0';
181 /* Get the serial number */
182 PROFILE_GetWineIniString( name
, "Serial", "12345678",
183 buffer
, sizeof(buffer
) );
184 drive
->serial
= strtoul( buffer
, NULL
, 16 );
186 /* Get the filesystem type */
187 PROFILE_GetWineIniString( name
, "Filesystem", "unix",
188 buffer
, sizeof(buffer
) );
189 drive
->flags
= DRIVE_GetFSFlags( name
, buffer
);
192 PROFILE_GetWineIniString( name
, "Device", "",
193 buffer
, sizeof(buffer
) );
195 drive
->device
= HEAP_strdupA( SystemHeap
, 0, buffer
);
197 /* Make the first hard disk the current drive */
198 if ((DRIVE_CurDrive
== -1) && (drive
->type
== TYPE_HD
))
202 TRACE(dosfs
, "%s: path=%s type=%s label='%s' serial=%08lx flags=%08x dev=%x ino=%x\n",
203 name
, path
, DRIVE_Types
[drive
->type
],
204 drive
->label
, drive
->serial
, drive
->flags
,
205 (int)drive
->dev
, (int)drive
->ino
);
207 else WARN(dosfs
, "%s: not defined\n", name
);
212 MSG("Warning: no valid DOS drive found, check your configuration file.\n" );
213 /* Create a C drive pointing to Unix root dir */
214 DOSDrives
[2].root
= HEAP_strdupA( SystemHeap
, 0, "/" );
215 DOSDrives
[2].dos_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
216 DOSDrives
[2].unix_cwd
= HEAP_strdupA( SystemHeap
, 0, "" );
217 strcpy( DOSDrives
[2].label
, "Drive C " );
218 DOSDrives
[2].serial
= 0x12345678;
219 DOSDrives
[2].type
= TYPE_HD
;
220 DOSDrives
[2].flags
= 0;
224 /* Make sure the current drive is valid */
225 if (DRIVE_CurDrive
== -1)
227 for (i
= 0, drive
= DOSDrives
; i
< MAX_DOS_DRIVES
; i
++, drive
++)
229 if (drive
->root
&& !(drive
->flags
& DRIVE_DISABLED
))
241 /***********************************************************************
244 int DRIVE_IsValid( int drive
)
246 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
)) return 0;
247 return (DOSDrives
[drive
].root
&&
248 !(DOSDrives
[drive
].flags
& DRIVE_DISABLED
));
252 /***********************************************************************
253 * DRIVE_GetCurrentDrive
255 int DRIVE_GetCurrentDrive(void)
257 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
258 if (pTask
&& (pTask
->curdrive
& 0x80)) return pTask
->curdrive
& ~0x80;
259 return DRIVE_CurDrive
;
263 /***********************************************************************
264 * DRIVE_SetCurrentDrive
266 int DRIVE_SetCurrentDrive( int drive
)
268 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
269 if (!DRIVE_IsValid( drive
))
271 SetLastError( ERROR_INVALID_DRIVE
);
274 TRACE(dosfs
, "%c:\n", 'A' + drive
);
275 DRIVE_CurDrive
= drive
;
276 if (pTask
) pTask
->curdrive
= drive
| 0x80;
281 /***********************************************************************
282 * DRIVE_FindDriveRoot
284 * Find a drive for which the root matches the begginning of the given path.
285 * This can be used to translate a Unix path into a drive + DOS path.
286 * Return value is the drive, or -1 on error. On success, path is modified
287 * to point to the beginning of the DOS path.
289 int DRIVE_FindDriveRoot( const char **path
)
291 /* idea: check at all '/' positions.
292 * If the device and inode of that path is identical with the
293 * device and inode of the current drive then we found a solution.
294 * If there is another drive pointing to a deeper position in
295 * the file tree, we want to find that one, not the earlier solution.
297 int drive
, rootdrive
= -1;
298 char buffer
[MAX_PATHNAME_LEN
];
300 const char *p
= *path
;
303 strcpy( buffer
, "/" );
306 if (stat( buffer
, &st
) || !S_ISDIR( st
.st_mode
)) break;
310 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
312 if (!DOSDrives
[drive
].root
||
313 (DOSDrives
[drive
].flags
& DRIVE_DISABLED
)) continue;
315 if ((DOSDrives
[drive
].dev
== st
.st_dev
) &&
316 (DOSDrives
[drive
].ino
== st
.st_ino
))
323 /* Get the next path component */
326 while ((*p
== '/') || (*p
== '\\')) p
++;
328 while (!IS_END_OF_NAME(*p
)) *next
++ = *p
++;
334 TRACE(dosfs
, "%s -> drive %c:, root='%s', name='%s'\n",
335 buffer
, 'A' + rootdrive
,
336 DOSDrives
[rootdrive
].root
, *path
);
341 /***********************************************************************
344 const char * DRIVE_GetRoot( int drive
)
346 if (!DRIVE_IsValid( drive
)) return NULL
;
347 return DOSDrives
[drive
].root
;
351 /***********************************************************************
354 const char * DRIVE_GetDosCwd( int drive
)
356 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
357 if (!DRIVE_IsValid( drive
)) return NULL
;
359 /* Check if we need to change the directory to the new task. */
360 if (pTask
&& (pTask
->curdrive
& 0x80) && /* The task drive is valid */
361 ((pTask
->curdrive
& ~0x80) == drive
) && /* and it's the one we want */
362 (DRIVE_LastTask
!= GetCurrentTask())) /* and the task changed */
364 /* Perform the task-switch */
365 if (!DRIVE_Chdir( drive
, pTask
->curdir
)) DRIVE_Chdir( drive
, "\\" );
366 DRIVE_LastTask
= GetCurrentTask();
368 return DOSDrives
[drive
].dos_cwd
;
372 /***********************************************************************
375 const char * DRIVE_GetUnixCwd( int drive
)
377 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
378 if (!DRIVE_IsValid( drive
)) return NULL
;
380 /* Check if we need to change the directory to the new task. */
381 if (pTask
&& (pTask
->curdrive
& 0x80) && /* The task drive is valid */
382 ((pTask
->curdrive
& ~0x80) == drive
) && /* and it's the one we want */
383 (DRIVE_LastTask
!= GetCurrentTask())) /* and the task changed */
385 /* Perform the task-switch */
386 if (!DRIVE_Chdir( drive
, pTask
->curdir
)) DRIVE_Chdir( drive
, "\\" );
387 DRIVE_LastTask
= GetCurrentTask();
389 return DOSDrives
[drive
].unix_cwd
;
393 /***********************************************************************
396 const char * DRIVE_GetLabel( int drive
)
398 if (!DRIVE_IsValid( drive
)) return NULL
;
399 return DOSDrives
[drive
].label
;
403 /***********************************************************************
404 * DRIVE_GetSerialNumber
406 DWORD
DRIVE_GetSerialNumber( int drive
)
408 if (!DRIVE_IsValid( drive
)) return 0;
409 return DOSDrives
[drive
].serial
;
413 /***********************************************************************
414 * DRIVE_SetSerialNumber
416 int DRIVE_SetSerialNumber( int drive
, DWORD serial
)
418 if (!DRIVE_IsValid( drive
)) return 0;
419 DOSDrives
[drive
].serial
= serial
;
424 /***********************************************************************
427 DRIVETYPE
DRIVE_GetType( int drive
)
429 if (!DRIVE_IsValid( drive
)) return TYPE_INVALID
;
430 return DOSDrives
[drive
].type
;
434 /***********************************************************************
437 UINT32
DRIVE_GetFlags( int drive
)
439 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
)) return 0;
440 return DOSDrives
[drive
].flags
;
444 /***********************************************************************
447 int DRIVE_Chdir( int drive
, const char *path
)
449 DOS_FULL_NAME full_name
;
450 char buffer
[MAX_PATHNAME_LEN
];
452 BY_HANDLE_FILE_INFORMATION info
;
453 TDB
*pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
455 strcpy( buffer
, "A:" );
457 TRACE(dosfs
, "(%c:,%s)\n", buffer
[0], path
);
458 lstrcpyn32A( buffer
+ 2, path
, sizeof(buffer
) - 2 );
460 if (!DOSFS_GetFullName( buffer
, TRUE
, &full_name
)) return 0;
461 if (!FILE_Stat( full_name
.long_name
, &info
)) return 0;
462 if (!(info
.dwFileAttributes
& FILE_ATTRIBUTE_DIRECTORY
))
464 SetLastError( ERROR_FILE_NOT_FOUND
);
467 unix_cwd
= full_name
.long_name
+ strlen( DOSDrives
[drive
].root
);
468 while (*unix_cwd
== '/') unix_cwd
++;
470 TRACE(dosfs
, "(%c:): unix_cwd=%s dos_cwd=%s\n",
471 'A' + drive
, unix_cwd
, full_name
.short_name
+ 3 );
473 HeapFree( SystemHeap
, 0, DOSDrives
[drive
].dos_cwd
);
474 HeapFree( SystemHeap
, 0, DOSDrives
[drive
].unix_cwd
);
475 DOSDrives
[drive
].dos_cwd
= HEAP_strdupA( SystemHeap
, 0,
476 full_name
.short_name
+ 3 );
477 DOSDrives
[drive
].unix_cwd
= HEAP_strdupA( SystemHeap
, 0, unix_cwd
);
479 if (pTask
&& (pTask
->curdrive
& 0x80) &&
480 ((pTask
->curdrive
& ~0x80) == drive
))
482 lstrcpyn32A( pTask
->curdir
, full_name
.short_name
+ 2,
483 sizeof(pTask
->curdir
) );
484 DRIVE_LastTask
= GetCurrentTask();
490 /***********************************************************************
493 int DRIVE_Disable( int drive
)
495 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
) || !DOSDrives
[drive
].root
)
497 SetLastError( ERROR_INVALID_DRIVE
);
500 DOSDrives
[drive
].flags
|= DRIVE_DISABLED
;
505 /***********************************************************************
508 int DRIVE_Enable( int drive
)
510 if ((drive
< 0) || (drive
>= MAX_DOS_DRIVES
) || !DOSDrives
[drive
].root
)
512 SetLastError( ERROR_INVALID_DRIVE
);
515 DOSDrives
[drive
].flags
&= ~DRIVE_DISABLED
;
520 /***********************************************************************
521 * DRIVE_SetLogicalMapping
523 int DRIVE_SetLogicalMapping ( int existing_drive
, int new_drive
)
525 /* If new_drive is already valid, do nothing and return 0
526 otherwise, copy DOSDrives[existing_drive] to DOSDrives[new_drive] */
530 old
= DOSDrives
+ existing_drive
;
531 new = DOSDrives
+ new_drive
;
533 if ((existing_drive
< 0) || (existing_drive
>= MAX_DOS_DRIVES
) ||
535 (new_drive
< 0) || (new_drive
>= MAX_DOS_DRIVES
))
537 SetLastError( ERROR_INVALID_DRIVE
);
543 TRACE(dosfs
, "Can\'t map drive %c to drive %c - "
544 "drive %c already exists\n",
545 'A' + existing_drive
, 'A' + new_drive
,
547 /* it is already mapped there, so return success */
548 if (!strcmp(old
->root
,new->root
))
553 new->root
= HEAP_strdupA( SystemHeap
, 0, old
->root
);
554 new->dos_cwd
= HEAP_strdupA( SystemHeap
, 0, old
->dos_cwd
);
555 new->unix_cwd
= HEAP_strdupA( SystemHeap
, 0, old
->unix_cwd
);
556 memcpy ( new->label
, old
->label
, 12 );
557 new->serial
= old
->serial
;
558 new->type
= old
->type
;
559 new->flags
= old
->flags
;
563 TRACE(dosfs
, "Drive %c is now equal to drive %c\n",
564 'A' + new_drive
, 'A' + existing_drive
);
570 /***********************************************************************
573 * Open the drive raw device and return a Unix fd (or -1 on error).
575 int DRIVE_OpenDevice( int drive
, int flags
)
577 if (!DRIVE_IsValid( drive
)) return -1;
578 return open( DOSDrives
[drive
].device
, flags
);
582 /***********************************************************************
585 * Read raw sectors from a device
587 int DRIVE_RawRead(BYTE drive
, DWORD begin
, DWORD nr_sect
, BYTE
*dataptr
, BOOL32 fake_success
)
591 if ((fd
= DRIVE_OpenDevice( drive
, O_RDONLY
)) != -1)
593 lseek( fd
, begin
* 512, SEEK_SET
);
594 /* FIXME: check errors */
595 read( fd
, dataptr
, nr_sect
* 512 );
600 memset(dataptr
, 0, nr_sect
* 512);
603 if (begin
== 0 && nr_sect
> 1) *(dataptr
+ 512) = 0xf8;
604 if (begin
== 1) *dataptr
= 0xf8;
613 /***********************************************************************
616 * Write raw sectors to a device
618 int DRIVE_RawWrite(BYTE drive
, DWORD begin
, DWORD nr_sect
, BYTE
*dataptr
, BOOL32 fake_success
)
622 if ((fd
= DRIVE_OpenDevice( drive
, O_RDONLY
)) != -1)
624 lseek( fd
, begin
* 512, SEEK_SET
);
625 /* FIXME: check errors */
626 write( fd
, dataptr
, nr_sect
* 512 );
637 /***********************************************************************
640 static int DRIVE_GetFreeSpace( int drive
, LPULARGE_INTEGER size
,
641 LPULARGE_INTEGER available
)
644 unsigned long long bigsize
,bigavail
=0;
646 if (!DRIVE_IsValid(drive
))
648 SetLastError( ERROR_INVALID_DRIVE
);
652 /* FIXME: add autoconf check for this */
653 #if defined(__svr4__) || defined(_SCO_DS)
654 if (statfs( DOSDrives
[drive
].root
, &info
, 0, 0) < 0)
656 if (statfs( DOSDrives
[drive
].root
, &info
) < 0)
660 WARN(dosfs
, "cannot do statfs(%s)\n", DOSDrives
[drive
].root
);
664 bigsize
= (unsigned long long)info
.f_bsize
665 * (unsigned long long)info
.f_blocks
;
666 #ifdef STATFS_HAS_BAVAIL
667 bigavail
= (unsigned long long)info
.f_bavail
668 * (unsigned long long)info
.f_bsize
;
670 # ifdef STATFS_HAS_BFREE
671 bigavail
= (unsigned long long)info
.f_bfree
672 * (unsigned long long)info
.f_bsize
;
674 # error "statfs has no bfree/bavail member!"
677 size
->LowPart
= (DWORD
)bigsize
;
678 size
->HighPart
= (DWORD
)(bigsize
>>32);
679 available
->LowPart
= (DWORD
)bigavail
;
680 available
->HighPart
= (DWORD
)(bigavail
>>32);
685 /***********************************************************************
686 * GetDiskFreeSpace16 (KERNEL.422)
688 BOOL16 WINAPI
GetDiskFreeSpace16( LPCSTR root
, LPDWORD cluster_sectors
,
689 LPDWORD sector_bytes
, LPDWORD free_clusters
,
690 LPDWORD total_clusters
)
692 return GetDiskFreeSpace32A( root
, cluster_sectors
, sector_bytes
,
693 free_clusters
, total_clusters
);
697 /***********************************************************************
698 * GetDiskFreeSpace32A (KERNEL32.206)
700 * Fails if expression resulting from current drive's dir and "root"
701 * is not a root dir of the target drive.
703 * UNDOC: setting some LPDWORDs to NULL is perfectly possible
704 * if the corresponding info is unneeded.
706 * FIXME: needs to support UNC names from Win95 OSR2 on.
708 * Behaviour under Win95a:
709 * CurrDir root result
710 * "E:\\TEST" "E:" FALSE
714 * "E:\\TEST" "\\" TRUE
715 * "E:\\TEST" ":\\" FALSE
716 * "E:\\TEST" "E:\\" TRUE
717 * "E:\\TEST" "" FALSE
718 * "E:\\" "" FALSE (!)
720 * "E:\\TEST" 0x0 TRUE (!)
721 * "E:\\TEST" "C:" TRUE (when CurrDir of "C:" set to "\\")
722 * "E:\\TEST" "C:" FALSE (when CurrDir of "C:" set to "\\TEST")
724 BOOL32 WINAPI
GetDiskFreeSpace32A( LPCSTR root
, LPDWORD cluster_sectors
,
725 LPDWORD sector_bytes
, LPDWORD free_clusters
,
726 LPDWORD total_clusters
)
729 ULARGE_INTEGER size
,available
;
733 if ((!root
) || (root
== "\\"))
734 drive
= DRIVE_GetCurrentDrive();
736 if ( (strlen(root
) >= 2) && (root
[1] == ':')) /* root contains drive tag */
738 drive
= toupper(root
[0]) - 'A';
741 path
= DRIVE_GetDosCwd(drive
);
745 if (strlen(path
)) /* oops, we are in a subdir */
751 if (!DRIVE_GetFreeSpace(drive
, &size
, &available
)) return FALSE
;
753 /* Cap the size and available at 2GB as per specs. */
754 if ((size
.HighPart
) ||(size
.LowPart
> 0x7fffffff))
757 size
.LowPart
= 0x7fffffff;
759 if ((available
.HighPart
) ||(available
.LowPart
> 0x7fffffff))
761 available
.HighPart
=0;
762 available
.LowPart
= 0x7fffffff;
764 if (DRIVE_GetType(drive
)==TYPE_CDROM
) {
766 *sector_bytes
= 2048;
767 size
.LowPart
/= 2048;
768 available
.LowPart
/= 2048;
773 available
.LowPart
/= 512;
775 /* fixme: probably have to adjust those variables too for CDFS */
777 while (cluster_sec
* 65536 < size
.LowPart
) cluster_sec
*= 2;
780 *cluster_sectors
= cluster_sec
;
782 *free_clusters
= available
.LowPart
/ cluster_sec
;
784 *total_clusters
= size
.LowPart
/ cluster_sec
;
789 /***********************************************************************
790 * GetDiskFreeSpace32W (KERNEL32.207)
792 BOOL32 WINAPI
GetDiskFreeSpace32W( LPCWSTR root
, LPDWORD cluster_sectors
,
793 LPDWORD sector_bytes
, LPDWORD free_clusters
,
794 LPDWORD total_clusters
)
799 xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
800 ret
= GetDiskFreeSpace32A( xroot
,cluster_sectors
, sector_bytes
,
801 free_clusters
, total_clusters
);
802 HeapFree( GetProcessHeap(), 0, xroot
);
807 /***********************************************************************
808 * GetDiskFreeSpaceEx32A (KERNEL32.871)
810 BOOL32 WINAPI
GetDiskFreeSpaceEx32A( LPCSTR root
,
811 LPULARGE_INTEGER avail
,
812 LPULARGE_INTEGER total
,
813 LPULARGE_INTEGER totalfree
)
816 ULARGE_INTEGER size
,available
;
818 if (!root
) drive
= DRIVE_GetCurrentDrive();
821 if ((root
[1]) && ((root
[1] != ':') || (root
[2] != '\\')))
823 WARN(dosfs
, "invalid root '%s'\n", root
);
826 drive
= toupper(root
[0]) - 'A';
828 if (!DRIVE_GetFreeSpace(drive
, &size
, &available
)) return FALSE
;
829 /*FIXME: Do we have the number of bytes available to the user? */
831 totalfree
->HighPart
= size
.HighPart
;
832 totalfree
->LowPart
= size
.LowPart
;
835 avail
->HighPart
= available
.HighPart
;
836 avail
->LowPart
= available
.LowPart
;
841 /***********************************************************************
842 * GetDiskFreeSpaceEx32W (KERNEL32.873)
844 BOOL32 WINAPI
GetDiskFreeSpaceEx32W( LPCWSTR root
, LPULARGE_INTEGER avail
,
845 LPULARGE_INTEGER total
,
846 LPULARGE_INTEGER totalfree
)
851 xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
852 ret
= GetDiskFreeSpaceEx32A( xroot
, avail
, total
, totalfree
);
853 HeapFree( GetProcessHeap(), 0, xroot
);
857 /***********************************************************************
858 * GetDriveType16 (KERNEL.136)
859 * This functions returns the drivetype of a drive in Win16.
860 * Note that it returns DRIVE_REMOTE for CD-ROMs, since MSCDEX uses the
861 * remote drive API. The returnvalue DRIVE_REMOTE for CD-ROMs has been
862 * verified on Win3.11 and Windows 95. Some programs rely on it, so don't
863 * do any pseudo-clever changes.
866 * drivetype DRIVE_xxx
868 UINT16 WINAPI
GetDriveType16(
869 UINT16 drive
/* [in] number (NOT letter) of drive */
871 TRACE(dosfs
, "(%c:)\n", 'A' + drive
);
872 switch(DRIVE_GetType(drive
))
874 case TYPE_FLOPPY
: return DRIVE_REMOVABLE
;
875 case TYPE_HD
: return DRIVE_FIXED
;
876 case TYPE_CDROM
: return DRIVE_REMOTE
;
877 case TYPE_NETWORK
: return DRIVE_REMOTE
;
879 default: return DRIVE_CANNOTDETERMINE
;
884 /***********************************************************************
885 * GetDriveType32A (KERNEL32.208)
887 * Returns the type of the disk drive specified. If root is NULL the
888 * root of the current directory is used.
892 * Type of drive (from Win32 SDK):
894 * DRIVE_UNKNOWN unable to find out anything about the drive
895 * DRIVE_NO_ROOT_DIR nonexistand root dir
896 * DRIVE_REMOVABLE the disk can be removed from the machine
897 * DRIVE_FIXED the disk can not be removed from the machine
898 * DRIVE_REMOTE network disk
899 * DRIVE_CDROM CDROM drive
900 * DRIVE_RAMDISK virtual disk in ram
902 * DRIVE_DOESNOTEXIST XXX Not valid return value
903 * DRIVE_CANNOTDETERMINE XXX Not valid return value
907 * Currently returns DRIVE_DOESNOTEXIST and DRIVE_CANNOTDETERMINE
908 * when it really should return DRIVE_NO_ROOT_DIR and DRIVE_UNKNOWN.
909 * Why where the former defines used?
911 * DRIVE_RAMDISK is unsupported.
913 UINT32 WINAPI
GetDriveType32A(LPCSTR root
/* String describing drive */)
916 TRACE(dosfs
, "(%s)\n", debugstr_a(root
));
918 if (NULL
== root
) drive
= DRIVE_GetCurrentDrive();
921 if ((root
[1]) && (root
[1] != ':'))
923 WARN(dosfs
, "invalid root '%s'\n", debugstr_a(root
));
924 return DRIVE_DOESNOTEXIST
;
926 drive
= toupper(root
[0]) - 'A';
928 switch(DRIVE_GetType(drive
))
930 case TYPE_FLOPPY
: return DRIVE_REMOVABLE
;
931 case TYPE_HD
: return DRIVE_FIXED
;
932 case TYPE_CDROM
: return DRIVE_CDROM
;
933 case TYPE_NETWORK
: return DRIVE_REMOTE
;
934 case TYPE_INVALID
: return DRIVE_DOESNOTEXIST
;
935 default: return DRIVE_CANNOTDETERMINE
;
940 /***********************************************************************
941 * GetDriveType32W (KERNEL32.209)
943 UINT32 WINAPI
GetDriveType32W( LPCWSTR root
)
945 LPSTR xpath
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
946 UINT32 ret
= GetDriveType32A( xpath
);
947 HeapFree( GetProcessHeap(), 0, xpath
);
952 /***********************************************************************
953 * GetCurrentDirectory16 (KERNEL.411)
955 UINT16 WINAPI
GetCurrentDirectory16( UINT16 buflen
, LPSTR buf
)
957 return (UINT16
)GetCurrentDirectory32A( buflen
, buf
);
961 /***********************************************************************
962 * GetCurrentDirectory32A (KERNEL32.196)
964 * Returns "X:\\path\\etc\\".
966 * Despite the API description, return required length including the
967 * terminating null when buffer too small. This is the real behaviour.
969 UINT32 WINAPI
GetCurrentDirectory32A( UINT32 buflen
, LPSTR buf
)
972 const char *s
= DRIVE_GetDosCwd( DRIVE_GetCurrentDrive() );
975 ret
= strlen(s
) + 3; /* length of WHOLE current directory */
976 if (ret
>= buflen
) return ret
+ 1;
977 lstrcpyn32A( buf
, "A:\\", MIN( 4, buflen
) );
978 if (buflen
) buf
[0] += DRIVE_GetCurrentDrive();
979 if (buflen
> 3) lstrcpyn32A( buf
+ 3, s
, buflen
- 3 );
984 /***********************************************************************
985 * GetCurrentDirectory32W (KERNEL32.197)
987 UINT32 WINAPI
GetCurrentDirectory32W( UINT32 buflen
, LPWSTR buf
)
989 LPSTR xpath
= HeapAlloc( GetProcessHeap(), 0, buflen
+1 );
990 UINT32 ret
= GetCurrentDirectory32A( buflen
, xpath
);
991 lstrcpyAtoW( buf
, xpath
);
992 HeapFree( GetProcessHeap(), 0, xpath
);
997 /***********************************************************************
998 * SetCurrentDirectory (KERNEL.412)
1000 BOOL16 WINAPI
SetCurrentDirectory16( LPCSTR dir
)
1002 return SetCurrentDirectory32A( dir
);
1006 /***********************************************************************
1007 * SetCurrentDirectory32A (KERNEL32.479)
1009 BOOL32 WINAPI
SetCurrentDirectory32A( LPCSTR dir
)
1011 int olddrive
, drive
= DRIVE_GetCurrentDrive();
1014 ERR(file
,"(NULL)!\n");
1017 if (dir
[0] && (dir
[1]==':'))
1019 drive
= tolower( *dir
) - 'a';
1023 /* WARNING: we need to set the drive before the dir, as DRIVE_Chdir
1024 sets pTask->curdir only if pTask->curdrive is drive */
1025 olddrive
= drive
; /* in case DRIVE_Chdir fails */
1026 if (!(DRIVE_SetCurrentDrive( drive
)))
1028 /* FIXME: what about empty strings? Add a \\ ? */
1029 if (!DRIVE_Chdir( drive
, dir
)) {
1030 DRIVE_SetCurrentDrive(olddrive
);
1037 /***********************************************************************
1038 * SetCurrentDirectory32W (KERNEL32.480)
1040 BOOL32 WINAPI
SetCurrentDirectory32W( LPCWSTR dirW
)
1042 LPSTR dir
= HEAP_strdupWtoA( GetProcessHeap(), 0, dirW
);
1043 BOOL32 res
= SetCurrentDirectory32A( dir
);
1044 HeapFree( GetProcessHeap(), 0, dir
);
1049 /***********************************************************************
1050 * GetLogicalDriveStrings32A (KERNEL32.231)
1052 UINT32 WINAPI
GetLogicalDriveStrings32A( UINT32 len
, LPSTR buffer
)
1056 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
1057 if (DRIVE_IsValid(drive
)) count
++;
1058 if (count
* 4 * sizeof(char) <= len
)
1061 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
1062 if (DRIVE_IsValid(drive
))
1071 return count
* 4 * sizeof(char);
1075 /***********************************************************************
1076 * GetLogicalDriveStrings32W (KERNEL32.232)
1078 UINT32 WINAPI
GetLogicalDriveStrings32W( UINT32 len
, LPWSTR buffer
)
1082 for (drive
= count
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
1083 if (DRIVE_IsValid(drive
)) count
++;
1084 if (count
* 4 * sizeof(WCHAR
) <= len
)
1087 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
1088 if (DRIVE_IsValid(drive
))
1090 *p
++ = (WCHAR
)('a' + drive
);
1097 return count
* 4 * sizeof(WCHAR
);
1101 /***********************************************************************
1102 * GetLogicalDrives (KERNEL32.233)
1104 DWORD WINAPI
GetLogicalDrives(void)
1109 for (drive
= 0; drive
< MAX_DOS_DRIVES
; drive
++)
1110 if (DRIVE_IsValid(drive
)) ret
|= (1 << drive
);
1115 /***********************************************************************
1116 * GetVolumeInformation32A (KERNEL32.309)
1118 BOOL32 WINAPI
GetVolumeInformation32A( LPCSTR root
, LPSTR label
,
1119 DWORD label_len
, DWORD
*serial
,
1120 DWORD
*filename_len
, DWORD
*flags
,
1121 LPSTR fsname
, DWORD fsname_len
)
1126 /* FIXME, SetLastErrors missing */
1128 if (!root
) drive
= DRIVE_GetCurrentDrive();
1131 if ((root
[1]) && (root
[1] != ':'))
1133 WARN(dosfs
, "invalid root '%s'\n",root
);
1136 drive
= toupper(root
[0]) - 'A';
1138 if (!DRIVE_IsValid( drive
)) return FALSE
;
1141 lstrcpyn32A( label
, DRIVE_GetLabel(drive
), label_len
);
1142 for (cp
= label
; *cp
; cp
++);
1143 while (cp
!= label
&& *(cp
-1) == ' ') cp
--;
1146 if (serial
) *serial
= DRIVE_GetSerialNumber(drive
);
1148 /* Set the filesystem information */
1149 /* Note: we only emulate a FAT fs at the present */
1152 if (DOSDrives
[drive
].flags
& DRIVE_SHORT_NAMES
)
1155 *filename_len
= 255;
1157 if (flags
) *flags
= 0;
1159 /* Diablo checks that return code ... */
1160 if (DRIVE_GetType(drive
)==TYPE_CDROM
)
1161 lstrcpyn32A( fsname
, "CDFS", fsname_len
);
1163 lstrcpyn32A( fsname
, "FAT", fsname_len
);
1169 /***********************************************************************
1170 * GetVolumeInformation32W (KERNEL32.310)
1172 BOOL32 WINAPI
GetVolumeInformation32W( LPCWSTR root
, LPWSTR label
,
1173 DWORD label_len
, DWORD
*serial
,
1174 DWORD
*filename_len
, DWORD
*flags
,
1175 LPWSTR fsname
, DWORD fsname_len
)
1177 LPSTR xroot
= HEAP_strdupWtoA( GetProcessHeap(), 0, root
);
1178 LPSTR xvolname
= label
? HeapAlloc(GetProcessHeap(),0,label_len
) : NULL
;
1179 LPSTR xfsname
= fsname
? HeapAlloc(GetProcessHeap(),0,fsname_len
) : NULL
;
1180 BOOL32 ret
= GetVolumeInformation32A( xroot
, xvolname
, label_len
, serial
,
1181 filename_len
, flags
, xfsname
,
1185 if (label
) lstrcpyAtoW( label
, xvolname
);
1186 if (fsname
) lstrcpyAtoW( fsname
, xfsname
);
1188 HeapFree( GetProcessHeap(), 0, xroot
);
1189 HeapFree( GetProcessHeap(), 0, xvolname
);
1190 HeapFree( GetProcessHeap(), 0, xfsname
);
1194 BOOL32 WINAPI
SetVolumeLabel32A(LPCSTR rootpath
,LPCSTR volname
) {
1195 FIXME(dosfs
,"(%s,%s),stub!\n",rootpath
,volname
);