2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
8 #include <aros/config.h>
9 #include <exec/execbase.h>
10 #include <exec/devices.h>
12 #include <exec/errors.h>
13 #include <aros/libcall.h>
14 #include <exec/libraries.h>
15 #include <proto/exec.h>
17 #ifndef DEBUG_SetFunction
18 # define DEBUG_SetFunction 0
24 #include <aros/debug.h>
27 char *const timername
= "timer.device";
28 char *const inputname
= "input.device";
30 /*****************************************************************************
34 AROS_LH4(BYTE
, OpenDevice
,
37 AROS_LHA(CONST_STRPTR
, devName
, A0
),
38 AROS_LHA(ULONG
, unitNumber
, D0
),
39 AROS_LHA(struct IORequest
*, iORequest
, A1
),
40 AROS_LHA(ULONG
, flags
, D1
),
43 struct ExecBase
*, SysBase
, 74, Exec
)
46 Tries to open a device and fill the iORequest structure. An error
47 is returned if this fails, 0 if all went well.
49 If the device doesn't exist in the current system device list, then
50 first the system ROMtag module list, then if the DOS is running,
51 then the DEVS: directory will be tried.
54 devName - Pointer to the devices's name.
55 unitNumber - The unit number. Most often 0.
56 iORequest - Pointer do device specific information.
57 Will be filled out by the device.
58 Must lie in public (or at least shared) memory.
59 flags - Some flags to give to the device.
62 Error code or 0 if all went well. The same value can be found
63 in the io_Error field.
76 *****************************************************************************/
80 struct Device
*device
;
81 BYTE ret
=IOERR_OPENFAIL
;
83 D(bug("OpenDevice $%lx $%lx $%lx %ld (\"%s\") by \"%s\"\n", devName
, unitNumber
, iORequest
,
84 flags
, (devName
> (STRPTR
)1) ? devName
: (UBYTE
*)"(null)", SysBase
->ThisTask
->tc_Node
.ln_Name
));
86 /* Arbitrate for the device list */
90 Kludge for compatibility with V40 kickstart. DO NOT depend on this!
91 See TaggedOpenLibrary() for more info.
93 if (devName
== (STRPTR
)0) devName
= timername
;
94 else if(devName
== (STRPTR
)1) devName
= inputname
;
96 /* Look for the device in our list */
97 device
=(struct Device
*)FindName(&SysBase
->DeviceList
,devName
);
99 /* Something found ? */
103 iORequest
->io_Error
=0;
104 iORequest
->io_Device
=device
;
105 iORequest
->io_Unit
= NULL
;
107 /* Call Open vector. */
108 AROS_LVO_CALL3NR(void,
109 AROS_LCA(struct IORequest
*,iORequest
,A1
),
110 AROS_LCA(ULONG
,unitNumber
,D0
),
111 AROS_LCA(ULONG
,flags
,D1
),
112 struct Device
*, device
, 1, dev
115 /* Check for error */
116 ret
=iORequest
->io_Error
;
118 /* Mark request as non-open */
119 iORequest
->io_Device
=NULL
;
123 * We cannot handle loading devices from disk. But thankfully this is
124 * taken care of by dos.library (well lddemon really). It replaces
125 * this function with one of its own via the SetFunction() call.