summaryrefslogtreecommitdiffstats
path: root/private/crt32/direct/drivfree.c
blob: 3ff8b77a5bc5c9063dccd8612959b8487998e7cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/***
*drivfree.c - Get the size of a disk
*
*	Copyright (c) 1991, Microsoft Corporation. All rights reserved.
*
*Purpose:
*	This file has _getdiskfree()
*
*Revision History:
*	08-21-91  PHG	Module created for Win32
*	10-24-91  GJF	Added LPDWORD casts to make MIPS compiler happy.
*			ASSUMES THAT sizeof(unsigned) == sizeof(DWORD).
*
*******************************************************************************/

#include <cruntime.h>
#include <direct.h>
#include <oscalls.h>

/***
*int _getdiskfree(drivenum, diskfree)  - get size of a specified disk
*
*Purpose:
*	Gets the size of the current or specified disk drive
*
*Entry:
*	int drivenum - 0 for current drive, or drive 1-26
*
*Exit:
*	returns 0 if succeeds
*	returns system error code on error.
*
*Exceptions:
*
*******************************************************************************/

#if !defined(_WIN32_)
#error ERROR - ONLY WIN32 TARGET SUPPORTED!
#endif

unsigned _CALLTYPE1 _getdiskfree(unsigned uDrive, struct _diskfree_t * pdf)
{
    char    szRoot[] = "?:\\";
    char    szCur[MAX_PATH];

    if (uDrive == 0) {
	GetCurrentDirectory(MAX_PATH, szCur);
	if ((szCur[0] == '\\') && (szCur[1] == '\\')) {
	    return (ERROR_INVALID_PARAMETER);
	}
	szRoot[0] = szCur[0];
    }
    else if (uDrive > 26) {
	return (ERROR_INVALID_PARAMETER);
    }
    else {
	szRoot[0] = (char)uDrive + (char)('A' - 1);
    }


    if (!GetDiskFreeSpace(szRoot,
			  (LPDWORD)&(pdf->sectors_per_cluster),
			  (LPDWORD)&(pdf->bytes_per_sector),
			  (LPDWORD)&(pdf->avail_clusters),
			  (LPDWORD)&(pdf->total_clusters))) {
	return ((int)GetLastError());
    }
    return (0);
}