Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rutgers!ames!ptsfa!hoptoad!academ!uhnix1!sugar!peter From: peter@sugar.UUCP (Peter DaSilva) Newsgroups: comp.sys.amiga Subject: Is a disk mounted or not? Here's how to find out! Message-ID: <144@sugar.UUCP> Date: Thu, 21-May-87 00:14:30 EDT Article-I.D.: sugar.144 Posted: Thu May 21 00:14:30 1987 Date-Received: Sun, 24-May-87 03:30:52 EDT Organization: Sugar Land UNIX - Houston, TX Lines: 213 Keywords: disk mounted startup sequence. #### 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 #include #include 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.

@$D3KD !GD4$\CP M $A*N0 $AF&$AZ 19.N0 #%183TAX ).N0 %N983T*Y 3"!Y M2"MH "+__"!M__P@* 8Y8 K0/_X(&W_^" H 3E@"M __1*K?_T9P JB!M M__0,J ( !&8 (HB;?_T2JD "&=^(&W_]" H "CE@"M __ @;?_P4JW_ M\! 02(!(P"M _^P,K0 !#_[&\(*WP 0_^PO+?_L+RW_\'(A(#D !, M3KD !B80?D !4T(@O $ZY )5D_O QR(2 Y 3$ZY 8F-"M_^Q! M^0 %1", @ 4KD !,(&W_]" 0Y8 K0/_T8 #_4B\Y 2$ZY 9B%A/ M3-\ #$Y=3G5D;W,N;&EB0!#86XG="!O<&5N(&1O * M83183R\M__Q.N0 $A183V#:0T]..C$V,"\U,"\S,C O,3 P+TUO=6YT960@ M=F]L=6UE("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. $(\X ,2.> @ @N 0!*6<02_H "$ZN_^)@!D*G M\U].103TYU9&]S M+FQI8G)A0 !1" M: $('D 4,7P 0 0(GD 4,WP 0 *('D ((#D (D*@ !%" M(\ 8('D 8(+Q-04Y80J=.N0 &:Q83R1 2JH K&