Mercurial > dwindows
changeset 35:432c39a4ff86
New code for checking drive size on OS/2 and Windows.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Fri, 07 Sep 2001 15:27:55 +0000 |
parents | b03b24bb95f8 |
children | cddb02f847e1 |
files | compat.c dwcompat.def dwcompatw.def |
diffstat | 3 files changed, 49 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/compat.c Mon Sep 03 23:30:43 2001 +0000 +++ b/compat.c Fri Sep 07 15:27:55 2001 +0000 @@ -170,18 +170,21 @@ #if defined(__EMX__) || defined(__OS2__) ULONG aulFSInfoBuf[40] = {0}; APIRET rc = NO_ERROR; + ULONG kbytes; DosError(FERR_DISABLEHARDERR); rc = DosQueryFSInfo(drive, - FSIL_ALLOC, - (PVOID)aulFSInfoBuf, - sizeof(aulFSInfoBuf)); + FSIL_ALLOC, + (PVOID)aulFSInfoBuf, + sizeof(aulFSInfoBuf)); DosError(FERR_ENABLEHARDERR); if (rc != NO_ERROR) return 0; - return (unsigned long)((aulFSInfoBuf[3] * aulFSInfoBuf[1] * (USHORT)aulFSInfoBuf[4])/1024); + kbytes = aulFSInfoBuf[3]/1024; + + return (unsigned long)(kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]); #elif defined(__WIN32__) || defined(WINNT) char buffer[10] = "C:\\"; DWORD spc, bps, fc, tc; @@ -196,6 +199,46 @@ #endif } +/* Return in K to avoid big problems exceeding an + unsigned long when no 64bit integers are available */ +#if defined(__IBMC__) || (defined(__WIN32__) && !defined(__CYGWIN32__)) +unsigned long drivesize(int drive) +#else +unsigned long long drivesize(int drive) +#endif +{ +#if defined(__EMX__) || defined(__OS2__) + ULONG aulFSInfoBuf[40] = {0}; + APIRET rc = NO_ERROR; + ULONG kbytes; + + DosError(FERR_DISABLEHARDERR); + rc = DosQueryFSInfo(drive, + FSIL_ALLOC, + (PVOID)aulFSInfoBuf, + sizeof(aulFSInfoBuf)); + + DosError(FERR_ENABLEHARDERR); + if (rc != NO_ERROR) + return 0; + + kbytes = aulFSInfoBuf[2]/1024; + + return (unsigned long)(kbytes * aulFSInfoBuf[1] * aulFSInfoBuf[4]); +#elif defined(__WIN32__) || defined(WINNT) + char buffer[10] = "C:\\"; + DWORD spc, bps, fc, tc; + + buffer[0] = drive + 'A' - 1; + + if(GetDiskFreeSpace(buffer, &spc, &bps, &fc, &tc) == 0) + return 0; + return (unsigned long)(spc*bps*(tc/1024)); +#else + return 0; +#endif +} + int isdrive(int drive) { #if defined(__EMX__) || defined(__OS2__)