home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / INSTALL2.TD0 / SOURCES.LIF / DISKSIZE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-09-27  |  3.7 KB  |  143 lines

  1. /*=============================================================================
  2.  
  3.      The INSTALL program source code, object code, sample  script files,
  4.      executable  program,  and  documentation  are  subject to copyright
  5.      protection under the laws of the United States and other countries.
  6.  
  7.      This software is licensed, not sold, and may only be  redistributed
  8.      in  executable format and only in accordance with the provisions of
  9.      the INSTALL Source Code License Agreement.
  10.  
  11.         INSTALL is Copyright(C) 1987-1990 by Knowledge Dynamics Corp
  12.        Highway Contract 4 Box 185-H, Canyon Lake, TX (USA) 78133-3508
  13.               512-964-3994 (Voice)   512-964-3958 (24-hr FAX)
  14.  
  15.                       All rights reserved worldwide.
  16.  
  17. ===============================================================================
  18.  
  19. FILENAME:
  20.     disksize.c
  21.  
  22. AUTHOR:
  23.     eric jon heflin
  24.  
  25. PUBLIC FUNCTIONS:
  26.     getdrives() - get all valid disk drive letters
  27.     disk_size() - get disk total capacity
  28.     disk_free() - get disk free space
  29.  
  30. LOCAL FUNCTIONS:
  31.     get_fs_info() - get file system information
  32.  
  33. DESCRIPTION:
  34.     This file implements DOS logical disk functions.
  35.  
  36. REVISION HISTORY:
  37.     DATE:    AUTHOR:            DESCRIPTION OF CHANGES:
  38.     891031    allyn jordan    Beginning of detailed comments.
  39.     891112    ejh                Cosmetic changes.
  40.     900102    ejh                Cosmetic changes.
  41.     900115    ejh                Added lint-suggested changes.
  42.     900124    ejh                Added OS/2 compatibility.
  43.     900127    ejh                Added Lattice C 6.0 compatibility.
  44.  
  45. ==============================================================================*/
  46.  
  47. #include <ctype.h>
  48. #include "install.h"
  49. #include <string.h>
  50. #if defined(LATTICE)
  51. #undef LATTICE
  52. #include <dos.h>
  53. #define LATTICE
  54. #endif
  55.  
  56. /* local prototypes */
  57. static int get_fs_info(P1(int drive));
  58.  
  59. /* local vars */
  60. static long secs_per_unit;
  61. static long total_units;
  62. static long free_units;
  63. static word bytes_per_sector;
  64.  
  65. /*
  66.  *    Return the highest allowable drive number.  Since the DOS 3.X call
  67.  *    appears to be unreliable, an attempt is made to change to each of
  68.  *    the drives.  If the changes is unsuccessful, then the drive does not
  69.  *    actually exist.
  70.  *
  71.  *    The return value is a vector of avail drive letters.  For example,
  72.  *    if the return == "\1\0\1\0\1\0" then valid drives are A, C, & E.
  73.  */
  74.  
  75. byte *getdrives(P1(void))
  76.     {                    /* getdrives */
  77.     static byte disk[26];
  78.     word current = (word)getdisk();    /* get current default */
  79.     int drive;
  80.  
  81.     memset(disk, 0, sizeof (disk));
  82.     for (drive = 0;  drive < sizeof (disk);  ++drive)
  83.         {
  84.         setdisk(drive);
  85.         if (getdisk() == drive)
  86.             disk[drive] = 1;
  87.         }
  88.     setdisk(current);
  89.     return disk;
  90.     }                /* getdrives */
  91.  
  92.  
  93. /*
  94.  *    disk_size() and disk_free() return the total disk capacity and free
  95.  *    space, respectively.  If there is an error, -1L is returned instead.
  96.  */
  97.  
  98. long disk_size(P1(byte drive))
  99. /* drive: A, B, C etc */
  100.     {                    /* disk_size */
  101.     if(get_fs_info(drive) != 0)
  102.         return -1L;
  103.     return total_units * secs_per_unit * bytes_per_sector;
  104.     }                    /* disk_size */
  105.  
  106.  
  107. long disk_free(P1(byte drive))
  108. /* drive: A, B, C etc */
  109.     {                    /* disk_free */
  110.     if(get_fs_info(drive) != 0)
  111.         return -1L;
  112.     return free_units * secs_per_unit * bytes_per_sector;
  113.     }                    /* disk_free */
  114.  
  115. /*
  116.  *    Low level function common to disk_free() and disk_size().
  117.  *
  118.  *  Drive is A, B, C, etc.
  119.  */
  120.  
  121. static int get_fs_info(P1(drive))
  122.     {
  123.     union REGS r;
  124.  
  125.     r.h.dl = (byte)(toupper(drive) - 'A' + 1);
  126.     r.h.ah = 0x36;
  127.     int80x86(0x21, &r, &r, NULL);
  128.     if (r.x.ax == 0xFFFF)
  129.         {
  130.         wputs(error_w, "Unable to access disk drive %c:", drive);
  131.         put_error(error_w);
  132.         return -1;
  133.         }
  134.     secs_per_unit = r.x.ax;
  135.     free_units = r.x.bx;
  136.     bytes_per_sector = r.x.cx;
  137.     total_units = r.x.dx;
  138.     return 0;
  139.     }
  140.  
  141. /* end-of-file */
  142.  
  143.