/*************************************************************************** * dos.c: AmigaDOS and Requestor related functions. * * Part of... * * FREE: Display free space on your disk volumes. * Author: Daniel Jay Barrett, barrett@cs.jhu.edu. * * This program is Freely Distributable. Make all the copies you want * and give them away. Use this code in any way you like. ***************************************************************************/ #include "free.h" /* Given a disk volume name, return how much space is on it. The units * of space are either bytes or blocks, depending on whether the user * specified the option OPT_BLOCKS or not. */ long GetMem(char *volume) { long freeSpace; struct FileLock *lock; lock = NULL; if (lock = (struct FileLock *)Lock(volume, ACCESS_READ)) { freeSpace = AvailSpace(lock); UnLock((BPTR)lock); } else freeSpace = NO_DRIVE; return(freeSpace); } /* This function comes from Tom Smythe's "avail()" function. * Given a lock on a disk, calculate how much space is left on the disk * and return that value. The value is in bytes, by default; but if the * user specified the option OPT_BLOCKS on the command-line, it's in * blocks. */ long AvailSpace(struct FileLock *disk) { struct InfoData *info; long answer = 0L; info = AllocMem((long)sizeof(struct InfoData), MEMF_PUBLIC); Info((BPTR)disk, info); answer = (info->id_NumBlocks - info->id_NumBlocksUsed); if (!(flags & FLAG_BLOCKS)) answer *= info->id_BytesPerBlock; FreeMem(info, (long)sizeof(struct InfoData)); return(answer); } /* Return the amount of free RAM on the system, broken into CHIP and * FAST RAM. */ void GetFreeRam(long *chip, long *fast) { (*chip) = (*fast) = 0L; Forbid(); *chip = AvailMem(MEMF_CHIP); *fast = AvailMem(MEMF_FAST); Permit(); } /* Turn off system requestors for this process. */ void DisableRequestors(struct Process **proc, APTR *oldWindowPtr) { *proc = (struct Process *)FindTask(NULL); *oldWindowPtr = (*proc)->pr_WindowPtr; (*proc)->pr_WindowPtr = (APTR)(-1L); } /* Turn on system requestors for this process, after they have been * turned off by DisableRequestors(), above. */ void EnableRequestors(struct Process *proc, APTR oldWindowPtr) { proc->pr_WindowPtr = oldWindowPtr; }