home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 13 / MA_Cover_13.bin / source / c / stefanb_src / private_projects / yath / remdev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-06  |  1.8 KB  |  80 lines

  1. /*
  2.  * RemDev.c   V0.02 (beta)
  3.  *
  4.  * "UnMount" a DOS device. USE WITH CARE!!!
  5.  *
  6.  * (c) 1991 by Stefan Becker
  7.  *
  8.  */
  9.  
  10. #include <dos/dos.h>
  11. #include <dos/filehandler.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include <string.h>
  15. #include <clib/exec_protos.h>
  16. #include <clib/dos_protos.h>
  17.  
  18. #define FreeDosMem(aptr) FreeMem((ULONG *) (aptr)-1, *((ULONG *) (aptr)-1))
  19.  
  20. char ident[]="$VER: remdev 0.02 (07.04.1991)";
  21.  
  22. void main(int argc, char *argv[])
  23. {
  24.  char *s;
  25.  struct MsgPort *devpr;
  26.  
  27.  if (argc<2)
  28.   {
  29.    printf("Usage: %s <name>\n",argv[0]);
  30.    exit(20);
  31.   }
  32.  
  33.  /* Copy name string */
  34.  if (s=strdup(argv[1]))
  35.   {
  36.    /* Remove trailing ':' */
  37.    s[strlen(s)-1]='\0';
  38.  
  39.    /* Find device handler process */
  40.    if (devpr=DeviceProc(argv[1]))
  41.  
  42.     /* Send shutdown packet to handler process */
  43.     if (DoPkt(devpr,ACTION_DIE,0,0,0,0,0)==DOSTRUE)
  44.      {
  45.       /* Handler process has stopped. Remove device node */
  46.       struct DosList *dol1,*dol2;
  47.  
  48.       dol1=LockDosList(LDF_DEVICES|LDF_WRITE);
  49.  
  50.       if (dol2=FindDosEntry(dol1,s,LDF_DEVICES)) RemDosEntry(dol2);
  51.  
  52.       UnLockDosList(LDF_DEVICES|LDF_WRITE);
  53.  
  54.       if (dol2)
  55.        {
  56.         /* Free memory associated with the device node */
  57.         struct FileSysStartupMsg *fssm=BADDR(dol2->
  58.                                              dol_misc.dol_handler.dol_Startup);
  59.  
  60.         FreeDosMem(BADDR(fssm->fssm_Device));
  61.         FreeDosMem(BADDR(fssm->fssm_Environ));
  62.         FreeDosMem(fssm);
  63.         FreeDosMem(BADDR(dol2->dol_misc.dol_handler.dol_Handler));
  64.  
  65.         /* Unload handler code */
  66.         UnLoadSeg(dol2->dol_misc.dol_handler.dol_SegList);
  67.  
  68.         FreeDosEntry(dol2);
  69.         printf("Device '%s' removed!\n",argv[1]);
  70.        }
  71.      }
  72.     else printf("Handler of device '%s' wouldn't die!\n",argv[1]);
  73.    else printf("Device '%s' not found!\n",argv[1]);
  74.  
  75.    free(s);
  76.   }
  77.  
  78.  exit(0);
  79. }
  80.