home *** CD-ROM | disk | FTP | other *** search
- /* finish v1.2 - program to wait till all activity on a selected
- disk drive is finished
- by Mark Wolfskehl
- type finish.doc for instructions */
- #include <exec/types.h>
- #include <exec/nodes.h>
- #include <exec/lists.h>
- #include <exec/ports.h>
- #include <devices/trackdisk.h>
-
- int val ( string )
- char string[];
- {
- int value , place , endflag;
- char chr;
- value = 0;
- place = 0;
- endflag = 1;
- chr = string[0];
- while ( ( chr != '\0' ) && endflag )
- {
- chr = string[place];
- if ( ( chr < '0' ) || ( chr > '9' ) )
- endflag = 0;
- else value = value * 10 + (chr - '0');
- ++place;
- }
- return ( value );
- }
-
- int finish ( drive )
- int drive;
- {
- SHORT error;
- struct MsgPort *diskport;
- struct IOExtTD *diskreq;
- struct MsgPort *CreatePort();
- struct IORequest *CreateExtIO();
- int counter;
- if ( drive < 0 || drive > 2 ) return ( 100 );
- diskport = CreatePort ( 0,0 );
- if ( diskport == 0 ) return ( 100 ); /* error - terminate */
- diskreq = (struct IOExtTD *) CreateExtIO ( diskport ,
- sizeof ( struct IOExtTD ) );
- if ( diskreq == 0 )
- {
- DeletePort ( diskport );
- return ( 100 ); /* error - terminate */
- }
-
- error = OpenDevice ( TD_NAME , drive , diskreq , 0 ); /* Open drive */
- if ( error ) /* error - terminate */
- {
- DeleteExtIO ( diskreq , sizeof ( struct IOExtTD ) );
- DeletePort ( diskreq );
- return ( 100 );
- }
- counter = 0;
- diskreq->iotd_Req.io_Command = TD_CHANGESTATE;
- DoIO ( diskreq );
- if ( !diskreq->iotd_Req.io_Actual ) /* Perform only if disk in drive */
- {
- do
- {
- diskreq->iotd_Req.io_Length = 0; /* turn off disk motor */
- diskreq->iotd_Req.io_Command = ETD_MOTOR;
- DoIO ( diskreq ) ;
- ++counter;
- }
- while ( ( counter <= 375 ) ); /* wait 375 times to make
- sure disk has stopped */
- }
- CloseDevice ( diskreq );
- DeleteExtIO ( diskreq , sizeof ( struct IOExtTD ) );
- DeletePort ( diskport );
- return ( (int)error );
- }
-
- void main ( argc , argv )
- int argc;
- char *argv[];
- {
- int error;
- if ( argc < 2 )
- {
- error = finish ( 0 ); /* Default to DF0: */
- if ( error ) printf ( "Error\n" );
- exit ( error );
- }
- if ( !strcmp ( argv[1] , "?" ) ) /* Print the usage? */
- {
- printf ( "Finish v1.2 by Mark Wolfskehl\n" );
- printf ( "Usage: finish <drive #>\n<drive #> is 0, 1 or 2.\n" );
- exit ( 0 );
- }
- error = finish ( val ( argv[1] ) );
- if ( error ) printf ( "Error\n");
- exit ( error );
- }
-
-
-