dosboot.resource: add small hint about boot device page
[AROS.git] / workbench / libs / datatypes / obtaindatatypea.c
blobc657f9ab3cc0739a8ea913ef8a9de192e22d2e5f
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include "datatypes_intern.h"
7 #include <proto/exec.h>
8 #include <proto/dos.h>
9 #include <proto/iffparse.h>
10 #include <proto/utility.h>
11 #include <utility/tagitem.h>
12 #include <dos/dos.h>
13 #include <datatypes/datatypesclass.h>
14 #include <libraries/iffparse.h>
16 #include <aros/debug.h>
18 /*****************************************************************************
20 NAME */
22 AROS_LH3(struct DataType *, ObtainDataTypeA,
24 /* SYNOPSIS */
25 AROS_LHA(ULONG , type, D0),
26 AROS_LHA(APTR , handle, A0),
27 AROS_LHA(struct TagItem *, attrs, A1),
29 /* LOCATION */
30 struct Library *, DataTypesBase, 6, DataTypes)
32 /* FUNCTION
34 Examine the data pointed to by 'handle'.
36 INPUTS
38 type -- type of 'handle'
39 handle -- handle to examine (if 'type' is DTST_FILE, 'handle' should be
40 a BPTR lock; if it's DTST_CLIPBOARD, 'handle' should be a
41 struct IFFHandle *).
42 attrs -- additional attributes (currently none defined).
44 RESULT
46 A pointer to a DataType or NULL if failure. IoErr() gives more information
47 in the latter case:
49 ERROR_NO_FREE_STORE -- Not enough memory available
50 ERROR_OBJECT_NOT_FOUND -- Unable to open the data type object
51 ERROR_NOT_IMPLEMENTED -- Unknown handle type
53 NOTES
55 EXAMPLE
57 BUGS
59 SEE ALSO
61 ReleaseDataType()
63 INTERNALS
65 HISTORY
67 *****************************************************************************/
69 AROS_LIBFUNC_INIT
71 struct CompoundDataType *cdt = NULL;
73 D(bug("datatypes.library/ObtainDataType - sem = %p\n", &(GPB(DataTypesBase)->dtb_DTList->dtl_Lock)));
74 ObtainSemaphoreShared(&(GPB(DataTypesBase)->dtb_DTList->dtl_Lock));
76 switch(type)
78 case DTST_FILE:
80 struct FileInfoBlock *fib;
82 D(bug("datatypes.library/ObtainDataType: SourceType = DTST_FILE\n"));
84 if((fib = AllocDosObject(DOS_FIB, TAG_DONE)) != NULL)
87 D(bug("datatypes.library/ObtainDataType: alloced DOS_FIB. Now calling ExamineLock\n"));
89 cdt = ExamineLock((BPTR)handle, fib, DataTypesBase);
91 D(bug("datatypes.library/ObtainDataType: DTST_FILE. ExamineLock call returned\n"));
93 FreeDosObject(DOS_FIB, fib);
95 break;
97 case DTST_CLIPBOARD:
99 struct ClipboardHandle *cbh;
100 UBYTE CheckArray[64];
102 D(bug("datatypes.library/ObtainDataType: SourceType = DTST_CLIPBOARD\n"));
104 cbh = (struct ClipboardHandle *)((struct IFFHandle *)handle)->iff_Stream;
106 /* cbh->cbh_Req.io_ClipID = 0; NONONONONO!!!! io_ClipID was set up by reads in OpenIFF!! */
107 cbh->cbh_Req.io_Error = 0;
108 cbh->cbh_Req.io_Offset = 0;
109 cbh->cbh_Req.io_Command = CMD_READ;
110 cbh->cbh_Req.io_Data = CheckArray;
111 cbh->cbh_Req.io_Length = sizeof(CheckArray);
113 if(DoIO((struct IORequest*)&cbh->cbh_Req))
115 SetIoErr(ERROR_OBJECT_NOT_FOUND);
117 else
119 cbh->cbh_Req.io_Error = 0;
120 cbh->cbh_Req.io_Offset = 0;
122 if(cbh->cbh_Req.io_Actual < 12)
123 SetIoErr(ERROR_OBJECT_NOT_FOUND);
124 else
126 struct DTHookContext dthc;
128 dthc.dthc_SysBase = (struct Library *)SysBase;
129 dthc.dthc_DOSBase = (struct Library *)DOSBase;
130 dthc.dthc_IFFParseBase = IFFParseBase;
131 dthc.dthc_UtilityBase = (struct Library *)UtilityBase;
132 dthc.dthc_Lock = BNULL;
133 dthc.dthc_FIB = NULL;
134 dthc.dthc_FileHandle = BNULL;
135 dthc.dthc_IFF = (struct IFFHandle *)handle;
136 dthc.dthc_Buffer = CheckArray;
137 dthc.dthc_BufferLength = cbh->cbh_Req.io_Actual;
139 D(bug("datatypes.library/ObtainDataType: DTST_CLIPBOARD: Calling ExamineData\n"));
141 cdt = ExamineData(DataTypesBase,
142 &dthc,
143 CheckArray,
144 (UWORD)cbh->cbh_Req.io_Actual,
148 D(bug("datatypes.library/ObtainDataType: DTST_CLIPBOARD: ExamineData call returned\n"));
153 break;
155 default:
156 SetIoErr(ERROR_NOT_IMPLEMENTED);
157 break;
160 if(cdt)
161 cdt->OpenCount++;
163 ReleaseSemaphore(&(GPB(DataTypesBase)->dtb_DTList->dtl_Lock));
165 if(IoErr() == ERROR_OBJECT_NOT_FOUND)
166 SetIoErr(DTERROR_COULDNT_OPEN);
168 D(bug("datatypes.library/ObtainDataType: Done. Returning %x\n", cdt));
170 return (struct DataType *)cdt;
172 AROS_LIBFUNC_EXIT
173 } /* ObtainDataTypeA */