home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff236.lzh / DiskHandler / main.c < prev    next >
C/C++ Source or Header  |  1989-08-09  |  10KB  |  243 lines

  1. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  2. /* |_o_o|\\ Copyright (c) 1988 The Software Distillery.  All Rights Reserved */
  3. /* |. o.| || This program may not be distributed without the permission of   */
  4. /* | .  | || the authors:                             BBS: (919) 481-6436    */
  5. /* | o  | ||   John Toebes     John Mainwaring    Jim Cooper                 */
  6. /* |  . |//    Bruce Drake     Gordon Keener      Dave Baker                 */
  7. /* ======                                                                    */
  8. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  9.  
  10. #include "handler.h"
  11.  
  12. /******************************************************************************/
  13. /******************************************************************************/
  14. /********************* Dispatch table to handle all packets *******************/
  15. /******************************************************************************/
  16. /******************************************************************************/
  17. #define BP1 1
  18. #define BP2 2
  19. #define BP3 4
  20. #define BP4 8
  21.  
  22. typedef void (*ifuncp)(GLOBAL, struct DosPacket *);
  23. struct LookupTable
  24.    {
  25.    ifuncp subr;
  26.    int flags;
  27.    };
  28.  
  29. #define LO_FIRST 0
  30. #define LO_LAST  34
  31. struct LookupTable lowork[LO_LAST+1] = {
  32.    { NULL,              0  | 0  | 0  | 0   }, /*  0 - ACTION_NIL            */
  33.    { NULL,              0  | 0  | 0  | 0   }, /*  1 - Unknown               */
  34.    { NULL,              BP1| BP2| BP3| 0   }, /*  2 - ACTION_GET_BLOCK      */
  35.    { NULL,              0  | BP2| BP3| 0   }, /*  3 - Unknown               */
  36.    { NULL,              BP1| BP2| BP3| 0   }, /*  4 - ACTION_SET_MAP        */
  37.    { ActDie,            0  | 0  | 0  | 0   }, /*  5 - ACTION_DIE            */
  38.    { NULL,              0  | 0  | 0  | 0   }, /*  6 - ACTION_EVENT          */
  39.    { ActCurentVol,      BP1| 0  | 0  | 0   }, /*  7 - ACTION_CURRENT_VOLUME */
  40.    { ActLock,           BP1| BP2| 0  | 0   }, /*  8 - ACTION_LOCATE_OBJECT  */
  41.    { ActRenameDisk,     BP1| BP2| 0  | 0   }, /*  9 - ACTION_RENAME_DISK    */
  42.    { NULL,              0  | 0  | 0  | 0   }, /* 10 - Unknown               */
  43.    { NULL,              0  | 0  | 0  | 0   }, /* 11 - Unknown               */
  44.    { NULL,              0  | 0  | 0  | 0   }, /* 12 - Unknown               */
  45.    { NULL,              0  | 0  | 0  | 0   }, /* 13 - Unknown               */
  46.    { NULL,              0  | 0  | 0  | 0   }, /* 14 - Unknown               */
  47.    { ActUnLock,         BP1| 0  | 0  | 0   }, /* 15 - ACTION_FREE_LOCK      */
  48.    { ActDelete,         BP1| BP2| 0  | 0   }, /* 16 - ACTION_DELETE_OBJECT  */
  49.    { ActRename,         BP1| BP2| BP3| BP4 }, /* 17 - ACTION_RENAME_OBJECT  */
  50.    { NULL,              0  | 0  | 0  | 0   }, /* 18 - ACTION_MORE_CACHE     */
  51.    { ActDupLock,        BP1| 0  | 0  | 0   }, /* 19 - ACTION_COPY_DIR       */
  52.    { NULL,              0  | 0  | 0  | 0   }, /* 20 - ACTION_WAIT_CHAR      */
  53.    { ActSetProtection,  0  | BP2| BP3| 0   }, /* 21 - ACTION_SET_PROTECT    */
  54.    { ActCreateDir,      BP1| BP2| 0  | 0   }, /* 22 - ACTION_CREATE_DIR     */
  55.    { ActExamine,        BP1| BP2| 0  | 0   }, /* 23 - ACTION_EXAMINE_OBJECT */
  56.    { ActExNext,         BP1| BP2| 0  | 0   }, /* 24 - ACTION_EXAMINE_NEXT   */
  57.    { ActDiskInfo,       BP1| 0  | 0  | 0   }, /* 25 - ACTION_DISK_INFO      */
  58.    { ActInfo,           BP1| BP2| 0  | 0   }, /* 26 - ACTION_INFO           */
  59.    { ActFlush,          0  | 0  | 0  | 0   }, /* 27 - ACTION_FLUSH          */
  60.    { ActSetComment,     0  | BP2| BP3| BP4 }, /* 28 - ACTION_SET_COMMENT    */
  61.    { ActParent,         BP1| 0  | 0  | 0   }, /* 29 - ACTION_PARENT         */
  62.    { ActTimer,          BP1| 0  | 0  | 0   }, /* 30 - ACTION_TIMER          */
  63.    { ActInhibit,        0  | 0  | 0  | 0   }, /* 31 - ACTION_INHIBIT        */
  64.    { NULL,              BP1| 0  | 0  | 0   }, /* 32 - ACTION_DISK_TYPE      */
  65.    { NULL,              0  | 0  | 0  | 0   }, /* 33 - ACTION_DISK_CHANGE    */
  66.    { NULL,              0  | 0  | 0  | 0   }  /* 34 - ACTION_SET_FILE_DATE  */
  67.       };
  68.  
  69. #define HI_FIRST 1004
  70. #define HI_LAST  1008
  71. struct LookupTable hiwork[5] = {
  72.    { ActFindwrite,      BP1| BP2| BP3| 0   }, /* ACTION_FIND_WRITE  - 1004 */
  73.    { ActFindin,         BP1| BP2| BP3| 0   }, /* ACTION_FIND_INPUT  - 1005 */
  74.    { ActFindout,        BP1| BP2| BP3| 0   }, /* ACTION_FIND_OUTPUT - 1006 */
  75.    { ActEnd,            0  | 0  | 0  | 0   }, /* ACTION_END         - 1007 */
  76.    { ActSeek,           0  | 0  | 0  | 0   }  /* ACTION_SEEK        - 1008 */
  77.    };
  78.  
  79. struct DosLibrary *DOSBase;
  80.  
  81. void __saveds handler()
  82. {
  83.    struct DosPacket   *mypkt;      /* a pointer to the dos packet sent       */
  84.    int                action;
  85.    ifuncp             subr;
  86.    int                flags;
  87.    struct global      global;
  88.  
  89.    DOSBase = (struct DosLibrary *)OpenLibrary(DOSNAME,0);
  90.  
  91.    /* Initialize our global data structure */
  92.    memset((char *)&global, 0, sizeof(struct global));
  93.    global.self   = (struct Process *) FindTask(0L);  /* find myself        */
  94.    global.run    = 1;
  95.    global.port   = &(global.self->pr_MsgPort);
  96.                  /* install our taskid ...   */
  97.  
  98.  
  99.    /* Initialize the intuitext structures for the requesters we might have   */
  100.    /* to display                                                             */
  101.    /* Because we have no scruples we can cheat and do this with a couple of  */
  102.    /* long word assignments.  We leave the acual C code commented out here   */
  103.    /* so that if this structure ever changed we will still be able to work   */
  104. #if 0
  105.    global.line1.FrontPen = global.line1.BackPen = -1;
  106.    global.line1.DrawMode = JAM1;
  107.    global.line1.LeftEdge = global.line1.TopEdge = 4;
  108.    global.line2 = global.line1;
  109.    global.line3 = global.line1;
  110.    global.retrytxt = global.line1;
  111.    global.canceltxt = global.line1;
  112. #else
  113.    *(long *)&global.line1.FrontPen     = 0x00010000L | (JAM1<<8);
  114.    *(long *)&global.line1.LeftEdge     = 0x00040004L;  /* 4,4  */
  115.    *(long *)&global.line2.FrontPen     = 0x00010000L | (JAM1<<8);
  116.    *(long *)&global.line2.LeftEdge     = 0x0004000EL;  /* 4,14 */
  117.    *(long *)&global.line3.FrontPen     = 0x00010000L | (JAM1<<8);
  118.    *(long *)&global.line3.LeftEdge     = 0x00040018L;  /* 4,24 */
  119.    *(long *)&global.retrytxt.FrontPen  = 0x00010000L | (JAM1<<8);
  120.    *(long *)&global.retrytxt.LeftEdge  = 0x00040004L;
  121.    *(long *)&global.canceltxt.FrontPen = 0x00010000L | (JAM1<<8);
  122.    *(long *)&global.canceltxt.LeftEdge = 0x00040004L;
  123. #endif
  124.    global.retrytxt.IText = "Retry";
  125.    global.canceltxt.IText = "Cancel";
  126.  
  127.    /* since we were started as a non-BCPL module we get sent the parameter   */
  128.    /* packet (ie. parameter packet not in D1) */
  129.  
  130.    mypkt = taskwait(&global);  /* wait for parameter packet */
  131.  
  132. #ifdef DEBUG
  133.    initdebug();
  134. #endif
  135.  
  136.    global.devname  = (((char *)BADDR(mypkt->dp_Arg1))+1);  /* BSTR name passed to handler */
  137. #if 0
  138.    global.extra    = mypkt->dp_Arg2;          /* Extra Info passed           */
  139. #endif
  140.  
  141.    /* get pointer to our device node */
  142.    global.node = (struct DeviceNode *) BADDR(mypkt->dp_Arg3); /* ptr to device node */
  143.    global.node->dn_Task = global.port;
  144.  
  145.    InitDevice(&global);
  146.  
  147.    /* Now mount the disk */
  148.    Mount(&global);
  149.  
  150.    OpenTimer(&global);
  151.  
  152.    mypkt->dp_Res1 = DOS_TRUE;
  153.    retpkt(&global, mypkt);
  154.  
  155.    PostTimerReq(&global);
  156.  
  157.    while(global.run)   /* start of the real work */
  158.       {
  159.       mypkt = taskwait(&global);  /* wait for a packet */
  160.  
  161.       action = mypkt->dp_Type;
  162.  
  163.       BUG(("Execute: action #%ld\n", action));
  164.  
  165.       switch (action)
  166.          {
  167.          case ACTION_READ:
  168.             subr = ActRead;
  169.             flags = 0;
  170.             break;
  171.          case ACTION_WRITE:
  172.             subr = ActWrite;
  173.             flags = 0;
  174.             break;
  175.  
  176.          case ACTION_SET_RAW_MODE:
  177.             subr = NULL;
  178.             flags = 0;
  179.             break;
  180.  
  181.          case ACTION_FIND_WRITE:  /* 1004 */
  182.          case ACTION_FIND_INPUT:  /* 1005 */
  183.          case ACTION_FIND_OUTPUT: /* 1006 */
  184.          case ACTION_END:         /* 1007 */
  185.          case ACTION_SEEK:        /* 1008 */
  186.             subr = hiwork[action-HI_FIRST].subr;
  187.             flags = hiwork[action-HI_FIRST].flags;
  188.             break;
  189.  
  190.          default:            
  191.             if ((action >= LO_FIRST) && (action <= LO_LAST))
  192.                {
  193.                subr = lowork[action-LO_FIRST].subr;
  194.                flags = lowork[action-LO_FIRST].flags;
  195.                }
  196.             else
  197.                subr = NULL;
  198.          }
  199.  
  200.       mypkt->dp_Res1 = DOS_FALSE;
  201.       mypkt->dp_Res2 = ERROR_ACTION_NOT_KNOWN;
  202.  
  203.       if (subr != NULL)
  204.          {
  205.          global.reply = 1;
  206.          if (flags & BP1)
  207.             mypkt->dp_Arg1 <<= 2;
  208.          if (flags & BP2)
  209.             mypkt->dp_Arg2 <<= 2;
  210.          if (flags & BP3)
  211.             mypkt->dp_Arg3 <<= 2;
  212.          if (flags & BP4)
  213.             mypkt->dp_Arg4 <<= 2;
  214.  
  215.          if (global.changedisk)
  216.             Mount(&global);
  217.  
  218.          (*subr)(&global, mypkt);
  219.  
  220.          if (global.changedisk)
  221.             Mount(&global);
  222.          }
  223.       else
  224.          {
  225.          BUG(("Unknown packet type %ld\n",mypkt->dp_Type));
  226.          }
  227.  
  228.       /* Now return the packet to them */
  229.       if (global.reply)
  230.          retpkt(&global, mypkt);
  231.   
  232.       BUG(("-----\n"));
  233.       }
  234.  
  235.    /* do our final cleanup */
  236.    global.node->dn_Task = FALSE; /* zero the taskid field of device node */
  237.    global.node->dn_SegList = 0;  /* make us be gone */
  238.  
  239.    DisMount(&global);
  240.    TermDevice(&global);
  241.    FreeBlkBuffs(&global);
  242. }
  243.