home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / misc / emu / AROSdev.lha / AROS / rom / exec / opendevice.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-09  |  3.2 KB  |  135 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: opendevice.c,v 1.8 1997/01/07 12:29:08 digulla Exp $
  4.     $Log: opendevice.c,v $
  5.     Revision 1.8  1997/01/07 12:29:08  digulla
  6.     Removed AROS_LVO_CALL*NR() macros
  7.  
  8.     Revision 1.7  1997/01/01 03:46:13  ldp
  9.     Committed Amiga native (support) code
  10.  
  11.     Changed clib to proto
  12.  
  13.     Revision 1.6  1996/12/10 13:51:49  aros
  14.     Moved all #include's in the first column so makedepend can see it.
  15.  
  16.     Revision 1.5  1996/10/24 15:50:53  aros
  17.     Use the official AROS macros over the __AROS versions.
  18.  
  19.     Revision 1.4  1996/08/13 13:56:05  digulla
  20.     Replaced AROS_LA by AROS_LHA
  21.     Replaced some AROS_LH*I by AROS_LH*
  22.     Sorted and added includes
  23.  
  24.     Revision 1.3  1996/08/01 17:41:15  digulla
  25.     Added standard header for all files
  26.  
  27.     Desc:
  28.     Lang: english
  29. */
  30. #include <exec/execbase.h>
  31. #include <exec/devices.h>
  32. #include <exec/io.h>
  33. #include <exec/errors.h>
  34. #include <aros/libcall.h>
  35. #include <exec/libraries.h>
  36. #include <proto/exec.h>
  37.  
  38. /*****************************************************************************
  39.  
  40.     NAME */
  41.  
  42.     AROS_LH4(BYTE, OpenDevice,
  43.  
  44. /*  SYNOPSIS */
  45.     AROS_LHA(STRPTR,             devName,    A0),
  46.     AROS_LHA(ULONG,              unitNumber, D0),
  47.     AROS_LHA(struct IORequest *, iORequest,  A1),
  48.     AROS_LHA(ULONG,              flags,      D1),
  49.  
  50. /*  LOCATION */
  51.     struct ExecBase *, SysBase, 74, Exec)
  52.  
  53. /*  FUNCTION
  54.     Tries to open a device and fill the iORequest structure.
  55.     And error is returned if this fails, 0 if all went well.
  56.  
  57.     INPUTS
  58.     devName    - Pointer to the devices's name.
  59.     unitNumber - The unit number. Most often 0.
  60.     iORequest  - Pointer do device specific information.
  61.              Will be filled out by the device.
  62.              Must lie in public (or at least shared) memory.
  63.     flags       - Some flags to give to the device.
  64.  
  65.     RESULT
  66.     Error code or 0 if all went well. The same value can be found
  67.     in the io_Error field.
  68.  
  69.     NOTES
  70.  
  71.     EXAMPLE
  72.  
  73.     BUGS
  74.  
  75.     SEE ALSO
  76.     CloseDevice()
  77.  
  78.     INTERNALS
  79.  
  80.     HISTORY
  81.  
  82. *****************************************************************************/
  83. {
  84.     AROS_LIBFUNC_INIT
  85.  
  86.     AROS_LIBBASE_EXT_DECL(struct ExecBase *,SysBase)
  87.     struct Device *device;
  88.     BYTE ret=IOERR_OPENFAIL;
  89.  
  90.     /* Arbitrate for the device list */
  91.     Forbid();
  92.  
  93.     /* Look for the device in our list */
  94.     device=(struct Device *)FindName(&SysBase->DeviceList,devName);
  95.  
  96.     /* Something found ? */
  97.     if(device!=NULL)
  98.     {
  99.     /* Init iorequest */
  100.     iORequest->io_Error=0;
  101.     iORequest->io_Device=device;
  102.     iORequest->io_Flags=flags;
  103.     iORequest->io_Message.mn_Node.ln_Type=NT_REPLYMSG;
  104.  
  105.     /* Call Open vector. */
  106.     AROS_LVO_CALL3(void,
  107.         AROS_LCA(struct IORequest *,iORequest,A1),
  108.         AROS_LCA(ULONG,unitNumber,D0),
  109.         AROS_LCA(ULONG,flags,D1),
  110.         struct Device, device, 1,
  111.     );
  112.  
  113.     /* Check for error */
  114.     ret=iORequest->io_Error;
  115.     if(ret)
  116.         /* Mark request as non-open */
  117.         iORequest->io_Device=NULL;
  118.     }
  119.     /*
  120.     else
  121.     {
  122.     Under normal circumstances you'd expect the device loading here -
  123.     but this is only exec which doesn't know anything about the
  124.     filesystem level. Therefore dos.library has to SetFunction() this vector
  125.     for the additional functionality.
  126.     }
  127.     */
  128.  
  129.     /* All done. */
  130.     Permit();
  131.     return ret;
  132.     AROS_LIBFUNC_EXIT
  133. } /* OpenDevice */
  134.  
  135.