Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ulowell!page From: page@swan.ulowell.edu (Bob Page) Newsgroups: comp.sources.amiga Subject: v89i047: free - print disk free space Message-ID: <12222@swan.ulowell.edu> Date: 15 Mar 89 15:42:13 GMT Organization: University of Lowell, Computer Science Dept. Lines: 308 Approved: page@swan.ulowell.edu Submitted-by: well!sirius (Mike Stilson) Posting-number: Volume 89, Issue 47 Archive-name: dos/fs/free.1 [Shows how much free space is left on your disk/s, like info. uuencoded executable enclosed. ..Bob] # This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. #----cut here-----cut here-----cut here-----cut here----# #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # readme # makefile # Free.c # Free.uu # This archive created: Wed Mar 15 10:39:03 1989 cat << \SHAR_EOF > readme Free (c) 1989 Mike 'Sirius' Stilson - Sirius Software Purpose of this program: I needed to know how much space was left on my disks. I wanted it in terms of Bytes, not blocks. And telling me x% free (ala Info) didn't help much. Usage: Free [Devices] If no argument is given, free gives info about the volume containing the current directory. The output is of the format: Volume Name: Bytes Per Block: Total bytes: Free Bytes: Total blocks: Free Blocks: Free can handle a list of devices. (Sorry.. no wildcards yet.) such as: Free Dh1: Dh2: Df0: Hope you enjoy it, and let me know of any problems. This compiles under Manx 3.6a Makefile is included. Mike 'Sirius' Stilson - Sirius Software uucp: sirius@well.UUCP or: ...portal!cup.portal.com!sirius SHAR_EOF cat << \SHAR_EOF > makefile CFLAGS= LFLAGS= all: Free.o ln $(LFLAGS) Free.o -lc SHAR_EOF cat << \SHAR_EOF > Free.c /* Free.c - (c) 1989 Mike 'Sirius' Stilson - Sirius Software * Ver1.0 January 1989. Written, Tested, Debugged, Re-Tested, and Finished. * * Display free/total bytes for a volume. * * Notice: * The author makes no claims or guarantees of the suitability of this * program for any given application, and I assume no responsibility or * liability for damages incurred through its usage. * * Feel free to steal any or all of this code and make millions of dollars * from its sale and commercial use, but please.. Give credit where credit is * due. * * Any similarity of this program, living, dead, deleted, or undead is purely * coincidental and unintentional. * */ #include #include #include #include #include struct InfoData *idata = NULL; struct FileLock *mylock = NULL; _wb_parse() {} /* We don't run from the wb.. */ main(ac,av) int ac; char **av; { char *GetName(); if(!(idata=(struct InfoData *) AllocMem((long)sizeof(struct InfoData),(long)MEMF_CHIP|MEMF_CLEAR))) { puts("Not enough memory.\n"); exit(20); } if(ac==1) goto once; while(--ac > 0) { once: if(!(mylock=Lock(*++av,ACCESS_READ))) { printf("Attempt to lock %s failed.\n",*av); FreeMem(idata,(long)sizeof(struct InfoData)); exit(20); } if(!(Info(mylock,idata))) { printf(Output(),"Unable to obtain info for device %s.\n",*av); FreeMem(idata,(long)sizeof(struct InfoData)); UnLock(mylock); exit(20); } printf("Volume Name: \2334;31;40m%s\2330;0;0m\t",GetName(mylock)); GetFree(); UnLock(mylock); } FreeMem(idata,(long)sizeof(struct InfoData)); exit(0); } /* Macro to convert a BPTR to a CString. Just for readability */ #define BPTR_TO_C(cast, var) ((struct cast *)(BADDR((ULONG)var))) char * GetName(lock) struct FileLock *lock; { struct DeviceList *dl=NULL; register char *p=NULL; register char buf[80]; Forbid(); /* Since the InfoData structure points to a NULL BSTR all the time, this is the only way I can think to get the volume name */ lock = BPTR_TO_C(FileLock, lock); dl = BPTR_TO_C(DeviceList, lock->fl_Volume); p = (char *)BADDR(dl->dl_Name); movmem(p+1, buf, p[0]); buf[p[0]] = '\0'; Permit(); return(buf); } GetFree() { register ULONG usedbytes=0, totalbytes=0, freebytes=0, bpb=0; bpb=idata->id_BytesPerBlock; usedbytes=bpb * idata->id_NumBlocksUsed; totalbytes=bpb * idata->id_NumBlocks; freebytes=totalbytes-usedbytes; printf("Bytes per block: %-7ld\n",bpb); printf("Total bytes: %-7ld\t\tFree Bytes: %-7ld\n",totalbytes,freebytes); printf("Total blocks: %-7ld\t\tFree Blocks: %-7ld\n\n",idata->id_NumBlocks, (idata->id_NumBlocks - idata->id_NumBlocksUsed)); } SHAR_EOF cat << \SHAR_EOF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G4H'TY=3G5.50``, M2.<.(#@M``@P!,'\``8D0-7L@G)*1&T*N&R"5FP$2I)F$#E\``*"E'#_3-\$( M<$Y=3G4(*@`'``1F""\23KH`"EA/0I)P`&#B(B\`!"QL@FY.[O_<(B\`!"QLJ M@FY.[O^"(B\`!"QL@FY.[O^X3.\`!@`$+&R";D[N_XXL;()N3N[_RBQL@FY.V M[O]\(B\`!"QL@FY.[O\H3OH``DSO``8`!"QL@FY.[O^L3.\`!@`$+&R";D[NP M_^).^@`"+&R";D[N_\1.^@`"(B\`!"QL@FY.[O^F3.\`#@`$+&R";D[N_]!(B MYP$$3.\@@``,+&R":DZN_Y1,WR"`3G4B;P`$+&R":D[N_F).^@`"3.\``P`$U M+&R":D[N_SHB;P`$+&R":D[N_MI.^@`"+&R":D[N_WQ.^@`"(F\`!"`O``@L- M;()J3N[_+B!O``0L;()J3N[^C"QL@FI.[O]V(F\`!"QL@FI.[OZ&3.\``P`$N M+&R":D[N_LX@;P`$+&R":D[N_H```````^P````!`````0```\8````````#: M\@```^H```"8```````````P,3(S-#4V-S@Y86)C9&5F````("`@("`@("`@Y M,#`P,#`@("`@("`@("`@("`@("`@(""00$!`0$!`0$!`0$!`0$!`#`P,#`P,( M#`P,#$!`0$!`0$`)"0D)"0D!`0$!`0$!`0$!`0$!`0$!`0$!`4!`0$!`0`H*. M"@H*"@("`@("`@("`@("`@("`@("`@("0$!`0"```````````````````0``Q M```!``````````````````````$!`````0`````````````````````!`@``' M``$`````````````````````````````````````````````````````````! M````````````````````````````````````````````````````````````` M````````````````````````````````````````````````````````````` M````````````````````````````````````````````````````````````` M````````````````````````````````````````````````````````````` M````````````````````````````````````````````````````````````` M````````````````````````````````````````````````````````````` M````````````````````````````````````````````````````````````` M````````````````````````````%`````````````````/R```#ZP````$`X #``/RU `` end size 5628 SHAR_EOF # End of shell archive exit 0 -- Bob Page, U of Lowell CS Dept. page@swan.ulowell.edu ulowell!page Have five nice days.