Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!apple!sun!swap!page From: page%swap@Sun.COM (Bob Page) Newsgroups: comp.sources.amiga Subject: v89i146: free - show available disk space v2 Message-ID: <105669@sun.Eng.Sun.COM> Date: 18 May 89 18:23:16 GMT Sender: news@sun.Eng.Sun.COM Lines: 363 Approved: page@sun.com Submitted-by: recondo!sirius@uunet.UU.NET (Michael Stilson) Posting-number: Volume 89, Issue 146 Archive-name: dos/fs/free2.1 Since version 1, Ported to Lattice (w/prototypes), made re-entrant/pure. Report the filesystem. [uuencoded executable included. ..bob] # This is a shell archive. # Remove anything above and including the cut line. # Then run the rest of the file through 'sh'. # Unpacked files will be owned by you and have default permissions. #----cut here-----cut here-----cut here-----cut here----# #!/bin/sh # shar: SHell ARchive # Run the following text through 'sh' to create: # free.c # makefile # free.uu # This is archive 1 of a 1-part kit. # This archive created: Thu May 18 11:15:31 1989 echo "extracting free.c" sed 's/^X//' << \SHAR_EOF > free.c X/* Free.c - (c) 1989 Mike 'Sirius' Stilson - Sirius Software X * Ver1.0 January 1989. Written, Tested, Debugged, Re-Tested, and Finished. X * Ver2.0 May 1989. Ported to Lattice 5.0.2, Made re-entrant/pure. Added X * Prototypes, and report the filesystem. X * Should work under Manx, remove the prototypes & use +l to compile. X * LMK Makefile provided for lattice. X * X * Display free/total bytes & blocks, name, and FileSys for a volume. X */ X X#include X#include X#include X#include X#include X#include X X/* Structure for all the variables we'll use */ Xstruct Variables { X struct InfoData *idata; X struct FileLock *lock; X BPTR mylock; X struct DeviceList *dev; X char name[80]; X char *temp; X ULONG usedbytes, X totalbytes, X freebytes, X bpb; X}; X X/* Macro to convert a BPTR to a C Pointer. Just for readability */ X#define BPTR_TO_C(cast, var) ((struct cast *)(BADDR((ULONG)var))) X X/* Function prototypes.. */ Xextern __stdargs int printf(char *,...); Xextern __stdargs int strlen(char *); Xextern __stdargs void strncpy(char *, char *, int); Xextern __stdargs void exit(long); X Xint main(int, char **av); Xchar *GetName(struct Variables *); Xvoid GetFree(struct Variables *); Xvoid Oops(struct Variables *, int); X Xmain(ac,av) Xint ac; char *av[]; X{ X X /* Declare a pointer to our variable structure */ X register struct Variables *Var; X X /* Allocate space for our variables */ X if(!(Var=(struct Variables *) X AllocMem(sizeof(struct Variables),MEMF_PUBLIC|MEMF_CLEAR))) { X printf("Cannot allocate space for variables.\n"); X Oops(Var,0); X } X X /* space for InfoData structure.. must be chip */ X if(!(Var->idata=(struct InfoData *) X AllocMem(sizeof(struct InfoData),MEMF_CLEAR|MEMF_CHIP))) { X printf("Unable to allocate space.\n"); X Oops(Var,1); X } X X /* Lock the drive */ X if((Var->mylock=Lock(av[1],ACCESS_READ))==NULL) { X printf("Attempt to lock %s failed.\n",av[1]); X Oops(Var,2); X } X X /* Fill the infodata structure */ X if(!(Info(Var->mylock,Var->idata))) { X printf("Unable to obtain info for device %s.\n",av[1]); X Oops(Var,3); X } X X /* Get the volume name. */ X printf("Volume Name: [1;4m%s[0m[%dC",GetName(Var),19-strlen(Var->name)); X X /* Get and display the free space for this volume */ X GetFree(Var); X X Oops(Var,3); X} X Xvoid Oops(Var,level) Xstruct Variables *Var; Xint level; X{ X switch(level) { X case 3: UnLock((BPTR)Var->mylock); X case 2: FreeMem(Var->idata,sizeof(struct InfoData)); X case 1: FreeMem(Var,sizeof(struct Variables)); X case 0: exit(0); X } X} X X X/* X * The devicelist is the only way I've managed to get the Volume name. X * InfoData->id_VolumeNode->ln_Name doesn't seem to work. X */ X Xchar *GetName(Var) Xstruct Variables *Var; X{ X X Forbid(); X X Var->lock = BPTR_TO_C(FileLock, Var->mylock); X Var->dev = BPTR_TO_C(DeviceList, Var->lock->fl_Volume); X Var->temp = (char *)BADDR(Var->dev->dl_Name); X strncpy(Var->name, &Var->temp[1], Var->temp[0]); X Var->name[Var->temp[0]] = NULL; X X Permit(); X X return(Var->name); X} X X Xstatic char *FileSystem[] = {"OFS", "FFS", "???"}; X Xvoid GetFree(Var) Xstruct Variables *Var; X{ X Var->bpb = Var->idata->id_BytesPerBlock; X Var->usedbytes = Var->bpb * Var->idata->id_NumBlocksUsed; X Var->totalbytes = Var->bpb * Var->idata->id_NumBlocks; X Var->freebytes = Var->totalbytes - Var->usedbytes; X X switch(Var->bpb) { X case 488: Var->bpb=0; X break; X case 512: Var->bpb=1; X break; X /* The only two DOS knows about for now.. */ X default: Var->bpb=2; X break; X } X X printf("FileSystem: %3s\n",FileSystem[Var->bpb]); X printf("Total bytes: %-7ld\t\tFree Bytes: %-7ld\n",Var->totalbytes,Var->freebytes); X printf("Total blocks: %-7ld\t\tFree Blocks: %-7ld\n\n",Var->idata->id_NumBlocks, X (Var->idata->id_NumBlocks - Var->idata->id_NumBlocksUsed)); X} X SHAR_EOF echo "extracting makefile" sed 's/^X//' << \SHAR_EOF > makefile XOBJS = Free.o XDEST = Free X XLC = lc XLC1 = lc1 XLC2 = lc2 XLCFLAGS = -ccfmsu -d0 -mas -r1 -v -w -O XLINK = blink XLIBS = lib:lcs.lib+lib:amiga.lib X X.c.o: X $(LC) $(LCFLAGS) $* X X$(DEST): $(OBJS) X $(LINK) lib:cres.o+$(OBJS) to $(DEST) LIB $(LIBS) SC SD ND VERBOSE MAP $(DEST).Map F H L O S X SHAR_EOF echo "extracting free.uu" sed 's/^X//' << \SHAR_EOF > free.uu X Xbegin 644 Free XM```#\P`````````#``````````(```9I`````````'<```/I```&:21()`!)5 XM^0`````L>``$2.?`X)G\`````"`\```#Y"(\``$``4ZN_SI*@&<``;0@0"1`' XM(D`@/````',@W%.`9OH@'&<.($G1W-70((HD25.`8/`H2=G\`````$S?!P,LM XM>``$*4X"!"E/`@Q"K`(()FX!%'``(CP``#``3J[^SBEK`)@"`$JK`*QG``!P, XM(`^0KP`$!H````"`*4`!T&$``4P@:P"LT``$(FP#U$ZNX XM_F).N@0$2JP""&<:(BP"$&<$3J[_W"QX``1.KO]\(FP""$ZN_H8@/````^0BO XM3)/\`````"QX``0N'RYL`@Q.KO\N(`=.=4S?!P-.=7!D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"P`<$C`+T``%"`!(B\`%$ZZ`@XR+`!P2,%.N@'D) XM+`!0AB`&5H`L``)&__PO!DZZ!4!83R9`(`MG$"\&+PM.NOT\+H=A`/\Z8`)PO XM`$SM#,#_Z$Y=3G4``````````'!A+P<^+P`(<``P!R\`3KK_$EA/+A].=0``\ XM2.<#$#XO`!!'[``D(`MG,@@K``(`$V8F""L``0`39QX@*P`$D*L`#"P`2D9GS XM$#\&+RL`##\K`!1.NO$N4$\F4V#*/P=.N@0N5$],WPC`3G5(YS<0+B\`'"9O_ XM`"`\+P`D2JP!_&<$3KH#B$)L`>0@!DC`(@0Y?``%`]`@!4S?".Q.=0``, XM+PB('+&P#U$ZN_]QP`"X?3G5(YS``)``F`4A"2$/$O XMP<;`P,'40TA"0D+0@DS?``Q.=4J`:@``'D2`2H%J```,1(%A```@1(%.=6$`_ XM`!A$@$2!3G5*@6H```Q$@6$```9$@$YU+P)(030!9@``(DA`2$%(0C0`9P``% XM!H3!,`)(0#0`A,$P`DA",@(D'TYU+P-V$`Q!`(!D```&X9E10PQ!"`!D```&P XMZ9E90PQ!(`!D```&Y9E50TI!:P``!N.94T,T`.:H2$)"0N:J2$.`P38`,`(TA XM`TA!Q,&0@F0```A30]"!9/YR`#(#2$/GN$A`P4$F'R0?3G5.5?^@2.W_KRE(`)1(>``\2'@`^G``+P`O`$AL! XM`+!(;`"<2&P`B$*G3KH!"$_O`"!3@&<$P"&-'`(`A@"#E\J XM``D#T'``+A].=0```````'!A2.P"&#HP! XM"`!*!6<8"`4``F82(`;!P4'L`A@O,`@"3KK\O%A/4T9@SB`'2,`O`$ZZZ(18- XM3TS?`.!.=0``2.<`,B9L`]@@"V<4)%,B2R`K``@L>``$3J[_+B9*8.B1R"E(; XM`]PI2`/83-],`$YU2.,`````/__````!``$````' XM``````````!T__\````$``0````````7J`````#__P````0`!````````!>R( XM```````@("`@("`@("`H*"@H*"`@("`@("`@("`@("`@("`@($@0$!`0$!`0@ XM$!`0$!`0$!"$A(2$A(2$A(2$$!`0$!`0$(&!@8&!@0$!`0$!`0$!`0$!`0$!L XM`0$!`0$!$!`0$!`0@H*"@H*"`@("`@("`@("`@("`@("`@("`@(0$!`0("`@Z XM("`@("`@("@H*"@H("`@("`@("`@("`@("`@("`@2!`0$!`0$!`0$!`0$!`00 XM$(2$A(2$A(2$A(00$!`0$!`0@8&!@8&!`0$!`0$!`0$!`0$!`0$!`0$!`0$02 XM$!`0$!""@H*"@H("`@("`@("`@("`@("`@("`@("`A`0$!`@`````@``````F XM``,````\````)````)@```/L````!@````````"\````J````(`````(````< X-!``````````````#\I@`1 X`` Xend Xsize 7168 SHAR_EOF echo "End of archive 1 (of 1)" # if you want to concatenate archives, remove anything after this line exit