/*      DISMOUNT command

        Syntax:
            DISMOUNT <device>

        DISMOUNTs the given device if it
        is not busy.
*/


SECTION "DISMOUNT"


GET "LIBHDR"


GET "CLIHDR"


GET "MANHDR"


LET start() BE
$( LET id = 0
   LET prefix = VEC 30/bytesperword
   LET argv = VEC 50
   LET res = rdargs("DEVICE/A", argv, 50)
   UNLESS res=0 DO res := split(prefix, ':', argv!0, 1)

   IF res=0 | devicename(prefix)=0 DO
   $( writef("%s failed - argument should refer to a dismountable device*n",
             cli.commandname)
      stop(20)
   $)
   IF !devicename(prefix)=0 THEN
   $( writef("%s failed - device not mounted*n", cli.commandname)
      stop(20)
   $)

   TEST sendpkt(-1, !devicename(prefix), action.die)=0
   THEN writef("Dismount of %S: failed - device in use*N", prefix)
   ELSE !devicename(prefix) := 0
$)