home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / disks / disk388.lzh / Free / dos.c < prev    next >
C/C++ Source or Header  |  1990-10-23  |  2KB  |  90 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 Jay Barrett, barrett@cs.jhu.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.     lock = NULL;
  26.     if (lock = (struct FileLock *)Lock(volume, ACCESS_READ))
  27.     {
  28.         freeSpace = AvailSpace(lock);
  29.         UnLock((BPTR)lock);
  30.     }
  31.     else
  32.         freeSpace = NO_DRIVE;
  33.     return(freeSpace);
  34. }
  35.  
  36.  
  37. /* This function comes from Tom Smythe's "avail()" function.
  38.  * Given a lock on a disk, calculate how much space is left on the disk
  39.  * and return that value.  The value is in bytes, by default; but if the
  40.  * user specified the option OPT_BLOCKS on the command-line, it's in 
  41.  * blocks. */
  42.  
  43. long AvailSpace(struct FileLock *disk)
  44. {
  45.     struct InfoData *info;
  46.     long answer = 0L;
  47.  
  48.     info = AllocMem((long)sizeof(struct InfoData), MEMF_PUBLIC);
  49.     Info((BPTR)disk, info);
  50.     answer = (info->id_NumBlocks - info->id_NumBlocksUsed);
  51.     if (!(flags & FLAG_BLOCKS))
  52.         answer *= info->id_BytesPerBlock;
  53.     FreeMem(info, (long)sizeof(struct InfoData));
  54.     return(answer);
  55. }
  56.  
  57.  
  58. /* Return the amount of free RAM on the system, broken into CHIP and
  59.  * FAST RAM. */
  60.  
  61. void GetFreeRam(long *chip, long *fast)
  62. {
  63.     (*chip) = (*fast) = 0L;
  64.     Forbid();
  65.     *chip = AvailMem(MEMF_CHIP);
  66.     *fast = AvailMem(MEMF_FAST);
  67.     Permit();
  68. }
  69.  
  70.  
  71. /* Turn off system requestors for this process. */
  72.  
  73. void DisableRequestors(struct Process **proc, APTR *oldWindowPtr)
  74. {
  75.     *proc = (struct Process *)FindTask(NULL);
  76.     *oldWindowPtr = (*proc)->pr_WindowPtr;
  77.     (*proc)->pr_WindowPtr = (APTR)(-1L);
  78. }
  79.  
  80.  
  81. /* Turn on system requestors for this process, after they have been
  82.  * turned off by DisableRequestors(), above. */
  83.  
  84. void EnableRequestors(struct Process *proc, APTR oldWindowPtr)
  85. {
  86.     proc->pr_WindowPtr = oldWindowPtr;
  87. }
  88.  
  89.  
  90.