peter@sugar.UUCP (Peter DaSilva) (05/21/87)
#### SHAR-TYPE ARCHIVE. CUT WHEREVER YOU LIKE #### # # Includes: read.me, mounted.c, mounted.uue # cat > read.me << 'EOF' MOUNTED is a quick little program I wrote to tell if a disk is mounted or not. It's intended to be used in startup-sequences to conditionally execute programs from df1. For example, mine includes: mounted playit if not warn run playit:play playit:bachfugue.smus playit: endif So if I start up with the disk "playit" in df1: it plays a bach fugue during loading. This program illustrates how to deal with BPTRs in a well behaved way, and how to get hold of the device list. It's full of magic numbers and inefficient code, and including stdio bloats it up to 8K. A little tidying up can probably get it down quite a bit. But it fits nicely in *my* c: directory and I'm arrogant enough to think I have better things to do. It's a good idea to have the AmigaDOS manual open to pages 266-269 while you're checking out the code. It's written for Aztec V3.40a with the +P option set, so it should run just fine with Lattice. -- Peter da Silva. -- Author of the fantastic screen hack "Workbench Lander". -- Not to mention ROT and Smart-TTY. -- And incredibly modest guy. EOF cat > mounted.c << 'EOF' /* MOUNTED -- is a disk mounted? * * Copyright 1987 by Peter da Silva. * * This code may be freely distributed provided this notice is * retained. It may be hacked, munged, and incorporated in commercial * software if you want, so long as you credit me for it. */ #include <stdio.h> #include <ctype.h> #include <libraries/dosextens.h> struct DosLibrary *DosLibrary; /* hack BPTRS */ #define toAPTR(b) ((b)<<2) #define toBPTR(a) ((a)>>2) #define VOLUMES 16 /* If you have more than 16 drives, tough luck :-> */ char volumes[VOLUMES][33]; int nvols; main(ac, av) int ac; char **av; { GetVolumes(); if(ac==0) wbmain(); /* I think this should work with Lattice */ else if(ac==1) dumpvols(); else if(ac==2 && av[1][0] != '?') exit(mounted(av[1])?0:5); /* Code 5 is warn */ else { /* should loop & return success only if all work. */ printf("MOUNTED Copyright (c) 1987 by Peter da Silva.\n"); printf("Usage: mounted [volumename]\n"); printf("Returns error code 5 is volume is not mounted.\n"); exit(10); /* code 10 is error. maybe Should be 20 (fatal). */ } exit(0); } GetVolumes() /* who'se out there */ { struct RootNode *root; struct DosInfo *info; struct DeviceList *list; DosLibrary = OpenLibrary("dos.library", 0); if(!DosLibrary) { printf("Can't open dos.library\n"); exit(2); } nvols = 0; /* The following 3 lines caused me some worry, but they worked first time. Thank you C=Amiga. */ root = DosLibrary -> dl_Root; info = toAPTR(root->rn_Info); list = toAPTR(info->di_DevInfo); while(list) { if(list->dl_Type == DLT_VOLUME && /* is it a device? */ list->dl_Task != 0) { /* Ignore unmounted devices */ char *ptr; int count; ptr = toAPTR((BPTR)list->dl_Name); count = *ptr++; if(count > 16) /* Should be a CONSTANT */ count = 16; strncpy(volumes[nvols], ptr, count); volumes[nvols][count] = 0; nvols++; } list = toAPTR(list->dl_Next); } CloseLibrary(DosLibrary); } wbmain(dummy) /* if run from workbench, just list mounted volumes */ { FILE *fp; if(!(fp = fopen("CON:160/50/320/100/Mounted volumes."))) return; fdumpvols(fp); sleep(10); fclose(fp); } sleep(n) /* This should have been provided by Aztec, for god's sake. */ { Delay(50*n); } dumpvols() { fdumpvols(stdout); } fdumpvols(fp) FILE *fp; { int i; for(i = 0; i < nvols; i++) printf("%s\n", volumes[i]); } mounted(name) /* The biggee */ char *name; { int i; for(i = 0; i < nvols; i++) if(streq(volumes[i], name)) return 1; return 0; } streq(s1, s2) char *s1, *s2; { normalise(s1); normalise(s2); return strcmp(s1, s2)==0; } normalise(s) char *s; { int i; for(i = 0; s[i]; i++) if(isupper(s[i])) s[i] = tolower(s[i]); else if(s[i]==':') { s[i] = 0; break; } } EOF cat > mounted.uue << 'EOF' begin 664 mounted M #\P # ( :5 I@ )D /I &E4[Z!5Q. M50 2.<P $ZZ 1A*K0 (9@9.N@)B8'P,K0 $ "&8&3KH"W&!L#*T " M AF,B!M PB: $#!$ /V<D(&T #"\H 1.N@,<6$]*@&<$< !@ G %+P!. MN0 %N983V P2'H 0$ZY ,5%A/2'H 8TZY ,5%A/2'H =$ZY ,5%A/ M2'@ "DZY 6YEA/0J=.N0 %N983TS? Q.74YU34]53E1%1"!#;W!Y<FEG M:'0@*&,I(#$Y.#<@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983R(M__P@ M;0 ($8 8 & >("W__"!M @,, Z" !F#B M__P@;0 (0C ( & 24JW__" M M__P@;0 (2C ( &:*3-\ #$Y=3G5P ! O >P/ !@8PJP/ !Z8@20/ @3G5P M ! O >P/ ! 8PJP/ !:8@30/ @3G5.50 2.<P($ZY 3G"1 2H!F"G M3-\$#$Y=3G4O"B\M PO+0 (809/[P ,8.9.50 2.<X("\M !!.N0 $A18 M3T'Y "1(2A)F%"/\ !0 1P $S?!!Q.74YU+RT #"\*3KD M* M4$]*@&<$4(I@TB\J 0O+0 (3KD F:4$\H +"\_____V8$< !@Q"!M ! 1 M1 @;0 0$7P 0 ,("T $&"L87Q#^0 IA%^0 "UR68.,CP F&L(= B MPE')__PCSP @L> $(\X ,2.> @ @N 0!*6<02_H "$ZN_^)@!D*G M\U].<T/Z "1.KOYH(\ 09@PN/ #@ =.KO^48 9.N0 !>103TYU9&]S M+FQI8G)A<GD 2?D '_^3G5.50 2.<P($AY $ # Y "E,'\ 8O $ZY M 9G%!/(\ 49AA"ITAY $ $ZY 9;E!/+GD (3G4@>0 !1" M: $('D 4,7P 0 0(GD 4,WP 0 *('D ((#D (D*@ !%" M(\ 8('D 8(+Q-04Y80J=.N0 &:Q83R1 2JH K&<X+RT #"\M @O M"DZY '<$_O PC_ $ <('D 4 &B $('D 4 &B * *8%A(:@!<3KD PC end EOF