home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 1 / FFMCD01.bin / bbs / libdisks / d700t799 / disk713.lha / Free / Source / dos.c next >
Encoding:
C/C++ Source or Header  |  1992-08-19  |  2.6 KB  |  110 lines

  1. /***************************************************************************
  2.  * dos.c:    AmigaDOS and Requestor related functions.
  3.  *
  4.  * Part of...
  5.  *
  6.  *    FREE:    Display free space on your disk volumes.
  7.  *        Author:  Daniel J. Barrett, barrett@cs.umass.edu.
  8.  *
  9.  * This program is Freely Distributable.  Make all the copies you want
  10.  * and give them away.  Use this code in any way you like.
  11. ***************************************************************************/
  12.  
  13.  
  14. #include "free.h"
  15.  
  16. /* Given a disk volume name, return how much space is on it.  The units
  17.  * of space are either bytes or blocks, depending on whether the user
  18.  * specified the option OPT_BLOCKS or not. */
  19.  
  20. long GetMem(char *volume)
  21. {
  22.     long freeSpace;
  23.     struct FileLock *lock;
  24.  
  25.     if (lock = (struct FileLock *)Lock(volume, ACCESS_READ))
  26.     {
  27.         freeSpace = AvailSpace(lock);
  28.         UnLock((BPTR)lock);
  29.     }
  30.     else
  31.         freeSpace = NO_DRIVE;
  32.     return(freeSpace);
  33. }
  34.  
  35.  
  36. /* This function comes from Tom Smythe's "avail()" function.
  37.  * Given a lock on a disk, calculate how much space is left on the disk
  38.  * and return that value.  The value is in bytes, by default; but if the
  39.  * user specified the option OPT_BLOCKS on the command-line, it's in 
  40.  * blocks. */
  41.  
  42. long AvailSpace(struct FileLock *disk)
  43. {
  44.     struct InfoData *info;
  45.     long answer;
  46.  
  47.     info = AllocMem((long)sizeof(struct InfoData), MEMF_PUBLIC);
  48.     if (!info)
  49.         ExitCleanly(ERROR_CANT_MALLOC, RETURN_FAIL);
  50.  
  51.     else if (!Info((BPTR)disk, info))
  52.     {
  53.         ErrorMsg(ERROR_INFO);
  54.         answer = NO_DRIVE;
  55.     }
  56.  
  57.     else
  58.     {
  59.         answer = (info->id_NumBlocks - info->id_NumBlocksUsed);
  60.         if (!(flags & FLAG_BLOCKS))
  61.             answer *= info->id_BytesPerBlock;
  62.     }
  63.  
  64.     if (info)
  65.         FreeMem(info, (long)sizeof(struct InfoData));
  66.  
  67.     return(answer);
  68. }
  69.  
  70.  
  71. /* Return the amount of free RAM on the system, broken into CHIP and
  72.  * FAST RAM. */
  73.  
  74. void GetFreeRam(long *chip, long *fast)
  75. {
  76.     Forbid();
  77.     *chip = AvailMem(MEMF_CHIP);
  78.     *fast = AvailMem(MEMF_FAST);
  79.     Permit();
  80. }
  81.  
  82.  
  83. /***************************************************************************
  84. * Enable and disable system requestors.
  85. ***************************************************************************/
  86.  
  87. static APTR oldWindowPtr;        /* Pointer to current window.  */
  88. static struct Process *theProc;        /* Pointer to current process. */
  89.  
  90.  
  91. /* Turn off system requestors for this process. */
  92.  
  93. void DisableRequestors(void)
  94. {
  95.     theProc = (struct Process *)FindTask(NULL);
  96.     oldWindowPtr = theProc->pr_WindowPtr;
  97.     theProc->pr_WindowPtr = (APTR)(-1L);
  98. }
  99.  
  100.  
  101. /*
  102.  * Turn on system requestors for this process, after they have been
  103.  * turned off by DisableRequestors(), above.
  104.  */
  105.  
  106. void EnableRequestors(void)
  107. {
  108.     theProc->pr_WindowPtr = oldWindowPtr;
  109. }
  110.