home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 274.lha / DiskHandler / device.c < prev    next >
C/C++ Source or Header  |  1989-07-25  |  7KB  |  200 lines

  1. /* Device.c - Device support routines */
  2.  
  3. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  4. /* |_o_o|\\ Copyright (c) 1987 The Software Distillery.  All Rights Reserved */
  5. /* |. o.| || This program may not be distributed without the permission of   */
  6. /* | .  | || the author.                                           BBS:      */
  7. /* | o  | ||   John Toebes    Dave Baker                     (919)-471-6436  */
  8. /* |  . |//                                                                  */
  9. /* ======                                                                    */
  10. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  11.  
  12. #include "handler.h"
  13. #include <devices/trackdisk.h>
  14.  
  15. typedef struct FileSysStartupMsg *FSSM;
  16.  
  17. int GetDevice (global, myfssmsg)
  18. GLOBAL global;    
  19. FSSM myfssmsg;
  20. {
  21. FSSM  fssmsg;
  22. ULONG *tmpdskenv;
  23. int   devnum;
  24. char  *defaultdev = TD_NAME;
  25.  
  26.    BUG(("devname:%s\n",global->devname));
  27.    BUG(("Global->node = %08lx Global->node->dn_Startup = %08lx\n",global->node, BADDR(global->node->dn_Startup)));
  28.  
  29.    /* Did they give us any information in the device list ? */
  30.    if (((fssmsg = (FSSM)BADDR(global->node->dn_Startup)) == NULL) ||
  31.         (fssmsg->fssm_Device == NULL))
  32.       {
  33.       /* No information about what we are mounting.  Figure out what it is */
  34.       /* we want by guessing from a default naming convention              */
  35.  
  36.       /* Make sure we have a 4 character name followed by a : only */
  37.       if (global->devname[4] != ':')
  38.          {
  39.          BUG(("Name is not the right length\n"));
  40.          return(NULL);
  41.          }
  42.  
  43.       devnum = global->devname[3] - '0';
  44.       if ((devnum < 0) || (devnum > 3))
  45.          {
  46.          BUG(("Device number %ld out of range\n", devnum));
  47.          return(NULL);
  48.          }
  49.  
  50.       /* Initialize the device information */
  51.       global->unitnum = myfssmsg->fssm_Unit = devnum;
  52.  
  53.       /* what trackdisk.device looks like */
  54.       myfssmsg->fssm_Device          = (ULONG)defaultdev;
  55.       myfssmsg->fssm_Flags           = 0;
  56.       global->dskenv.de_sizeblock    = 128;
  57.       global->dskenv.de_blkspertrk   = 11;
  58.       global->dskenv.de_reservedblks = 2;
  59.       global->dskenv.de_numblks      = 1760;
  60.       global->dskenv.de_lowcyl       = 0;
  61.       global->dskenv.de_uppercyl     = 79;
  62.       global->dskenv.de_numbufs      = 5;
  63.       global->dskenv.de_membuftype   = (MEMF_CHIP|MEMF_CLEAR);
  64.  
  65.       BUG(("GetDevice-fssm_Device:%s\n", myfssmsg->fssm_Device));
  66.       BUG(("GetDevice-fssm_Unit:%ld\n",   myfssmsg->fssm_Unit)); 
  67.       BUG(("GetDevice-fssm_Flags:%lx\n", myfssmsg->fssm_Flags));
  68.       }
  69.  
  70.    else
  71.       {
  72.       /* They gave us all the device information in the mountlist */
  73.       myfssmsg->fssm_Device  = (ULONG)BADDR(fssmsg->fssm_Device);
  74.       global->unitnum        =
  75.       myfssmsg->fssm_Unit    = fssmsg->fssm_Unit;
  76.       myfssmsg->fssm_Flags   = (ULONG)BADDR(fssmsg->fssm_Flags);
  77.   
  78.       BUG(("fssm:%lx\n", fssmsg));
  79.       BUG(("fssm_Device:%s\n",    fssmsg->fssm_Device));
  80.       BUG(("fssm_Unit:%ld\n",      fssmsg->fssm_Unit)); 
  81.       BUG(("fssm_Flags:%lx\n",    fssmsg->fssm_Flags));
  82.       BUG(("fssm_Environ:%lx\n",  fssmsg->fssm_Environ));
  83.   
  84.       tmpdskenv = (ULONG *)BADDR(fssmsg->fssm_Environ);
  85.  
  86.       BUG(("dskenv tablesize:%lx\n",    tmpdskenv[DE_TABLESIZE]   ));
  87.       BUG(("dskenv sizeblock:%lx\n",    tmpdskenv[DE_SIZEBLOCK]   ));
  88.       BUG(("dskenv secorg:%lx\n",       tmpdskenv[DE_SECORG]      ));
  89.       BUG(("dskenv numheads:%lx\n",     tmpdskenv[DE_NUMHEADS]    ));
  90.       BUG(("dskenv secsperblk:%lx\n",   tmpdskenv[DE_SECSPERBLK]  ));
  91.       BUG(("dskenv blkspertrack:%lx\n", tmpdskenv[DE_BLKSPERTRACK]));
  92.       BUG(("dskenv reservedblks:%lx\n", tmpdskenv[DE_RESERVEDBLKS]));
  93.       BUG(("dskenv prefac:%lx\n",       tmpdskenv[DE_PREFAC]      ));
  94.       BUG(("dskenv interleave:%lx\n",   tmpdskenv[DE_INTERLEAVE]  ));
  95.       BUG(("dskenv lowcyl:%lx\n",       tmpdskenv[DE_LOWCYL]      ));
  96.       BUG(("dskenv uppercyl:%lx\n",     tmpdskenv[DE_UPPERCYL]    ));
  97.       BUG(("dskenv numbuffers:%lx\n",   tmpdskenv[DE_NUMBUFFERS]  ));
  98.       BUG(("dskenv membuftype:%lx\n",   tmpdskenv[DE_MEMBUFTYPE]  ));
  99.    
  100.       global->dskenv.de_sizeblock    = tmpdskenv[DE_SIZEBLOCK];
  101.       global->dskenv.de_blkspertrk   =  tmpdskenv[DE_BLKSPERTRACK];
  102.       global->dskenv.de_reservedblks = tmpdskenv[DE_RESERVEDBLKS];
  103.       global->dskenv.de_numblks      =
  104.           ((((tmpdskenv[DE_UPPERCYL]-tmpdskenv[DE_LOWCYL])+1)*
  105.              (tmpdskenv[DE_BLKSPERTRACK]))*(tmpdskenv[DE_NUMHEADS]));
  106.  
  107.       global->dskenv.de_lowcyl       = tmpdskenv[DE_LOWCYL];
  108.       global->dskenv.de_uppercyl     = tmpdskenv[DE_UPPERCYL];
  109.       global->dskenv.de_numbufs      = tmpdskenv[DE_NUMBUFFERS];
  110.       global->dskenv.de_membuftype   = tmpdskenv[DE_MEMBUFTYPE];
  111.    
  112.       }
  113.  
  114.    /* Figure out where the root block is supposed to be */
  115.    global->Root = (global->dskenv.de_numblks / 2);
  116.    return(-1);
  117. }
  118.  
  119.  
  120.  
  121. int InitDevice(global)
  122. GLOBAL global;
  123. {
  124.    struct FileSysStartupMsg myfssmsg;
  125.   
  126.    BUG(("InitDevice:\n"));
  127.  
  128.    if (GetDevice(global,&myfssmsg) == NULL)
  129.       {
  130.       BUG(("GetDevice Failed \n"));
  131.       return(0);
  132.       }
  133.  
  134.    if ((global->devport = (struct MsgPort *)CreatePort("dskport",0))==NULL)
  135.       {
  136.       BUG(("CreatePort Failed\n"));
  137.       return(0);        /* error in createport */
  138.       }  
  139.  
  140.    BUG(("fssm_Device:%s\n", myfssmsg.fssm_Device));
  141.    BUG(("fssm_Unit:%ld\n",   myfssmsg.fssm_Unit)); 
  142.    BUG(("fssm_Flags:%lx\n", myfssmsg.fssm_Flags));
  143.  
  144.    BUG(("CreateExtIO\n"));
  145.  
  146.    /* make an io request block for communicating with the disk */
  147.    if ((global->devreq = (struct IOExtTD *)
  148.              CreateExtIO(global->devport, sizeof(struct IOExtTD)))==NULL)
  149.       {
  150.       BUG(("CreateExtIO Failed\n"));
  151.       DeletePort(global->devport);
  152.       return(0);
  153.       }
  154.  
  155.    BUG(("OpenDevice\n"));
  156.    /* open the device for access note using FileSysStartupMsg struct */ 
  157.    /* however fields have been converted to C pointers by GetDevice  */
  158.    if ((OpenDevice((char *)myfssmsg.fssm_Device, myfssmsg.fssm_Unit,
  159.                   (struct IORequest *)(global->devreq), 
  160.                   myfssmsg.fssm_Flags)) != NULL)
  161.       {
  162.       BUG(("OpenDevice Failed\n"));
  163.       return(0);
  164.       }
  165.  
  166.  
  167.    BUG(("AddDskChngInt\n"));
  168.    /* add the disk change interrupt trash */
  169.    if (AddDskChngInt(global) == NULL)
  170.       {
  171.       BUG(("AddDskChngInt Failed\n")); 
  172.       }
  173.  
  174.    BUG(("AllocBlkBuffs\n"));
  175.    /* allocate the block buffers */
  176.    if ((AllocBlkBuffs(global,global->dskenv.de_numbufs) == NULL))
  177.       {
  178.       BUG(("AllocBlkBuffs Failed\n"));
  179.       return(0);
  180.       }
  181.  
  182.    BUG(("DiskChange\n"));
  183.    /* now get the disk change value */
  184.    global->devreq->iotd_Req.io_Command = TD_CHANGENUM;
  185.    DoIO((struct IORequest *)global->devreq);
  186.    global->DiskChange = global->devreq->iotd_Req.io_Actual;
  187.  
  188.    return(1);  /* successful completion */
  189. }
  190.  
  191.  
  192.  
  193. int TermDevice(global)
  194. GLOBAL global;
  195. {
  196.    return(1);
  197. }
  198.  
  199.  
  200.