~ubuntu-branches/ubuntu/utopic/binkd/utopic-proposed

« back to all changes in this revision

Viewing changes to os2/getfree.c

  • Committer: Bazaar Package Importer
  • Author(s): Marco d'Itri
  • Date: 2002-03-24 22:52:25 UTC
  • Revision ID: james.westby@ubuntu.com-20020324225225-7ru6itlapn03nl35
Tags: upstream-0.9.5a
ImportĀ upstreamĀ versionĀ 0.9.5a

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: getfree.c,v 2.2 2001/04/25 20:07:36 gul Exp $
 
3
 *
 
4
 * Revision history:
 
5
 * $Log: getfree.c,v $
 
6
 * Revision 2.2  2001/04/25 20:07:36  gul
 
7
 * bugfix
 
8
 *
 
9
 * Revision 2.1  2001/04/23 07:58:57  gul
 
10
 * getfree() on large drives fixed
 
11
 *
 
12
 * Revision 2.0  2001/01/10 12:12:40  gul
 
13
 * Binkd is under CVS again
 
14
 *
 
15
 *
 
16
 */
 
17
#ifdef __WATCOMC__
 
18
  #define __IBMC__ 0
 
19
  #define __IBMCPP__ 0
 
20
#endif
 
21
 
 
22
#define INCL_DOS
 
23
#include <os2.h>
 
24
#include <ctype.h>
 
25
#include <limits.h>
 
26
 
 
27
extern void Log (int lev, char *s,...);
 
28
 
 
29
unsigned long getfree (char *path)
 
30
{
 
31
  FSALLOCATE fsa;
 
32
  ULONG disknum = 0;
 
33
  APIRET rc;
 
34
 
 
35
  if (isalpha (path[0]) && path[1] == ':')
 
36
    disknum = toupper (path[0]) - 'A' + 1;
 
37
 
 
38
  rc = DosQueryFSInfo (disknum,             /* Drive number            */
 
39
                       FSIL_ALLOC,          /* Level 1 allocation info */
 
40
                       (PVOID) & fsa,       /* Buffer                  */
 
41
                       sizeof (fsa));       /* Size of buffer          */
 
42
 
 
43
  if (rc)
 
44
  {
 
45
    Log (1, "DosQueryFSInfo error: return code = %u", rc);
 
46
    return ULONG_MAX;                       /* Assume enough disk space */
 
47
  }
 
48
  else
 
49
  {
 
50
    if (fsa.cSectorUnit * fsa.cbSector >= 1024)
 
51
      return fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector / 1024);
 
52
    else
 
53
      return fsa.cUnitAvail / (1024 / (fsa.cSectorUnit * fsa.cbSector));
 
54
  }
 
55
}