home *** CD-ROM | disk | FTP | other *** search
- /*=============================================================================
-
- The INSTALL program source code, object code, sample script files,
- executable program, and documentation are subject to copyright
- protection under the laws of the United States and other countries.
-
- This software is licensed, not sold, and may only be redistributed
- in executable format and only in accordance with the provisions of
- the INSTALL Source Code License Agreement.
-
- INSTALL is Copyright(C) 1987-1990 by Knowledge Dynamics Corp
- Highway Contract 4 Box 185-H, Canyon Lake, TX (USA) 78133-3508
- 512-964-3994 (Voice) 512-964-3958 (24-hr FAX)
-
- All rights reserved worldwide.
-
- ===============================================================================
-
- FILENAME:
- disksize.c
-
- AUTHOR:
- eric jon heflin
-
- PUBLIC FUNCTIONS:
- getdrives() - get all valid disk drive letters
- disk_size() - get disk total capacity
- disk_free() - get disk free space
-
- LOCAL FUNCTIONS:
- get_fs_info() - get file system information
-
- DESCRIPTION:
- This file implements DOS logical disk functions.
-
- REVISION HISTORY:
- DATE: AUTHOR: DESCRIPTION OF CHANGES:
- 891031 allyn jordan Beginning of detailed comments.
- 891112 ejh Cosmetic changes.
- 900102 ejh Cosmetic changes.
- 900115 ejh Added lint-suggested changes.
- 900124 ejh Added OS/2 compatibility.
- 900127 ejh Added Lattice C 6.0 compatibility.
-
- ==============================================================================*/
-
- #include <ctype.h>
- #include "install.h"
- #include <string.h>
- #if defined(LATTICE)
- #undef LATTICE
- #include <dos.h>
- #define LATTICE
- #endif
-
- /* local prototypes */
- static int get_fs_info(P1(int drive));
-
- /* local vars */
- static long secs_per_unit;
- static long total_units;
- static long free_units;
- static word bytes_per_sector;
-
- /*
- * Return the highest allowable drive number. Since the DOS 3.X call
- * appears to be unreliable, an attempt is made to change to each of
- * the drives. If the changes is unsuccessful, then the drive does not
- * actually exist.
- *
- * The return value is a vector of avail drive letters. For example,
- * if the return == "\1\0\1\0\1\0" then valid drives are A, C, & E.
- */
-
- byte *getdrives(P1(void))
- { /* getdrives */
- static byte disk[26];
- word current = (word)getdisk(); /* get current default */
- int drive;
-
- memset(disk, 0, sizeof (disk));
- for (drive = 0; drive < sizeof (disk); ++drive)
- {
- setdisk(drive);
- if (getdisk() == drive)
- disk[drive] = 1;
- }
- setdisk(current);
- return disk;
- } /* getdrives */
-
-
- /*
- * disk_size() and disk_free() return the total disk capacity and free
- * space, respectively. If there is an error, -1L is returned instead.
- */
-
- long disk_size(P1(byte drive))
- /* drive: A, B, C etc */
- { /* disk_size */
- if(get_fs_info(drive) != 0)
- return -1L;
- return total_units * secs_per_unit * bytes_per_sector;
- } /* disk_size */
-
-
- long disk_free(P1(byte drive))
- /* drive: A, B, C etc */
- { /* disk_free */
- if(get_fs_info(drive) != 0)
- return -1L;
- return free_units * secs_per_unit * bytes_per_sector;
- } /* disk_free */
-
- /*
- * Low level function common to disk_free() and disk_size().
- *
- * Drive is A, B, C, etc.
- */
-
- static int get_fs_info(P1(drive))
- {
- union REGS r;
-
- r.h.dl = (byte)(toupper(drive) - 'A' + 1);
- r.h.ah = 0x36;
- int80x86(0x21, &r, &r, NULL);
- if (r.x.ax == 0xFFFF)
- {
- wputs(error_w, "Unable to access disk drive %c:", drive);
- put_error(error_w);
- return -1;
- }
- secs_per_unit = r.x.ax;
- free_units = r.x.bx;
- bytes_per_sector = r.x.cx;
- total_units = r.x.dx;
- return 0;
- }
-
- /* end-of-file */
-
-