https://aminet.net/package/misc/fish/fish-0066 – free.c
#include <protos/dos.h> BPTR lock; struct InfoData info; long bytes; // max 4 GB, might need more space, a 48 bit number might be best disk = Lock(device, ACCESS_READ); Info(disk, &info); bytes = (info.id_NumBlocks - info.id_NumBlocksUsed) * info->id_BytesPerBlock; UnLock(disk);
I've used this for seeding a random number generator.
#include <devices/timer.h> #include <clib/timer_protos.h> struct Library *TimerBase; struct MsgPort *TimerMP; struct timerequest *TimerIO; int main(void) { long randomSeed = 0; struct timeval currentSystemTime; if (TimerMP = CreatePort(NULL, NULL)) { if (TimerIO = (struct timerequest *)CreateExtIO(TimerMP, sizeof(struct timerequest))) { if (!(OpenDevice( TIMERNAME, UNIT_MICROHZ, (struct IORequest *)TimerIO, 0 ))) { TimerBase = (struct Library *)TimerIO->tr_node.io_Device; GetSysTime(¤tSystemTime); randomSeed = currentSystemTime.tv_micro; CloseDevice(TimerIO); } DeleteExtIO(TimerIO); } DeletePort(TimerMP); } }
#include <clib/alib_protos.h> long semiRandom = FastRand(someSeed); // i actually needed to change the seed in my program a bunch of times...