Added useful custom dimensions to some top-level drawers that lacked them.
[AROS.git] / rom / exec / opendevice.c
blob98d982e23bc266cb409df22c1c87fff2eafffb8f
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Open a device.
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <exec/execbase.h>
11 #include <exec/devices.h>
12 #include <exec/io.h>
13 #include <exec/errors.h>
14 #include <aros/libcall.h>
15 #include <exec/libraries.h>
16 #include <proto/exec.h>
18 /*****************************************************************************
20 NAME */
22 AROS_LH4(LONG, OpenDevice,
24 /* SYNOPSIS */
25 AROS_LHA(CONST_STRPTR, devName, A0),
26 AROS_LHA(IPTR, unitNumber, D0),
27 AROS_LHA(struct IORequest *, iORequest, A1),
28 AROS_LHA(ULONG, flags, D1),
30 /* LOCATION */
31 struct ExecBase *, SysBase, 74, Exec)
33 /* FUNCTION
34 Tries to open a device and fill the iORequest structure. An error
35 is returned if this fails, 0 if all went well.
37 If the device doesn't exist in the current system device list, then
38 first the system ROMtag module list, then if the DOS is running,
39 then the DEVS: directory will be tried.
41 INPUTS
42 devName - Pointer to the devices's name.
43 unitNumber - The unit number. Most often 0. In some special cases this can be
44 a pointer to something (device-dependent).
45 iORequest - Pointer to device specific information.
46 Will be filled out by the device.
47 Must lie in public (or at least shared) memory.
48 flags - Some flags to give to the device.
50 RESULT
51 Error code or 0 if all went well. The same value can be found
52 in the io_Error field.
54 NOTES
55 Return type is internally extended to LONG in all existing official ROMs
56 (EXT.W D0 + EXT.L D0) DoIO() and WaitIO() do the same.
57 Many programs assume LONG return code, even some WB utilities.
59 EXAMPLE
61 BUGS
63 SEE ALSO
64 OpenDevice()
66 INTERNALS
68 *****************************************************************************/
70 AROS_LIBFUNC_INIT
73 * Kludge for compatibility with V40 kickstart. DO NOT depend on this!
74 * See TaggedOpenLibrary() for more info.
76 switch ((IPTR)devName)
78 case 0:
79 devName = "timer.device";
80 break;
82 case 1:
83 devName = "input.device";
84 break;
87 D(bug("[exec] OpenDevice(\"%s\", %ld, 0x%p, %d) by \"%s\"\n", devName, unitNumber, iORequest,
88 flags, GET_THIS_TASK->tc_Node.ln_Name));
90 /* Arbitrate for the device list */
91 Forbid();
93 /* Look for the device in our list */
94 iORequest->io_Unit = NULL;
95 iORequest->io_Device = (struct Device *)FindName(&SysBase->DeviceList, devName);
96 D(bug("[OpenDevice] Found resident 0x%p\n", iORequest->io_Device));
98 /* Something found ? */
99 if (iORequest->io_Device)
101 iORequest->io_Error = 0;
103 /* Call Open vector. */
104 AROS_LVO_CALL3NR(void,
105 AROS_LCA(struct IORequest *,iORequest,A1),
106 AROS_LCA(IPTR, unitNumber,D0),
107 AROS_LCA(ULONG,flags,D1),
108 struct Device *, iORequest->io_Device, 1, dev);
110 /* Check for error */
111 if (iORequest->io_Error)
112 /* Mark request as non-open */
113 iORequest->io_Device=NULL;
115 else
116 iORequest->io_Error = IOERR_OPENFAIL;
119 * We cannot handle loading devices from disk. But thankfully this is
120 * taken care of by dos.library (well lddemon really). It replaces
121 * this function with one of its own via the SetFunction() call.
124 /* All done. */
125 Permit();
127 D(bug("[OpenDevice] Returning device 0x%p, unit 0x%p, error %d\n", iORequest->io_Device, iORequest->io_Unit, iORequest->io_Error));
129 return iORequest->io_Error;
131 AROS_LIBFUNC_EXIT
132 } /* OpenDevice */