Detabbed
[AROS.git] / rom / dos / dos_intern.h
blob9bd280cff8b045a0cb57122a26e04fa054783949
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Internal types and stuff for dos
6 Lang: English
7 */
8 #ifndef DOS_INTERN_H
9 #define DOS_INTERN_H
11 #include <aros/system.h>
12 #include <exec/io.h>
13 #include <dos/dos.h>
14 #include <dos/exall.h>
15 #include <dos/dosextens.h>
16 #include <dos/dosasl.h>
17 #include <dos/filehandler.h>
18 #include <utility/tagitem.h>
19 #include <proto/exec.h>
20 #include <proto/utility.h>
22 #include "fs_driver.h"
25 * These bases are historically placed in public portion of DOSBase.
26 * We won't change this.
28 #undef TimerBase
29 #define TimerBase (DOSBase->dl_TimeReq->tr_node.io_Device)
30 #undef UtilityBase
31 #define UtilityBase (DOSBase->dl_UtilityBase)
33 /* Needed for close() */
34 #define expunge() \
35 AROS_LC0(BPTR, expunge, struct DosLibrary *, DOSBase, 3, Dos)
37 #define RDAF_ALLOCATED_BY_READARGS (1L << 31)
39 /* BCPL compatibility: At least LONG alignment required */
41 struct IntDosBase
43 struct DosLibrary pub;
44 struct Library *debugBase;
45 struct RootNode rootNode __attribute__((aligned(4)));
46 struct ErrorString errors __attribute__((aligned(4)));
47 #ifdef __arm__
48 ULONG arm_Arch; /* ARM-specific info for ELF loader */
49 BOOL arm_VFP;
50 BOOL arm_VFP_v3;
51 #endif
54 #define IDosBase(base) ((struct IntDosBase *)base)
55 #define DebugBase IDosBase(DOSBase)->debugBase
57 struct DAList
59 STRPTR *ArgBuf;
60 UBYTE *StrBuf;
61 STRPTR *MultVec;
62 BOOL FreeRDA;
65 #ifndef EOF
66 #define EOF -1
67 #endif
68 #ifndef IOBUFSIZE
69 #define IOBUFSIZE 4096
70 #endif
72 struct vfp
74 BPTR file;
75 LONG count;
76 struct DosLibrary *DOSBase;
79 /* fh_Flags. The flags are AROS specific and therefore PRIVATE.. */
80 #define FHF_WRITE 0x80000000
81 #define FHF_BUF 1
82 #define FHF_APPEND 2
83 #define FHF_LINEBUF 4
84 #define FHF_NOBUF 8
85 #define FHF_OWNBUF 16
87 #define FPUTC(f,c) \
88 (((struct FileHandle *)BADDR(f))->fh_Flags&FHF_WRITE&& \
89 ((struct FileHandle *)BADDR(f))->fh_Pos<((struct FileHandle *)BADDR(f))->fh_End? \
90 *((struct FileHandle *)BADDR(f))->fh_Pos++=c,0:FPutC(f,c))
92 /* Softlink handling */
93 STRPTR ResolveSoftlink(BPTR cur, struct DevProc *dvp, CONST_STRPTR name, struct DosLibrary *DOSBase);
94 LONG RootDir(struct DevProc *dvp, struct DosLibrary *DOSBase);
96 /* Packet I/O */
97 struct DosPacket *allocdospacket(void);
98 void freedospacket(struct DosPacket *dp);
99 SIPTR dopacket(SIPTR *res2, struct MsgPort *port, LONG action, SIPTR arg1, SIPTR arg2, SIPTR arg3, SIPTR arg4, SIPTR arg5, SIPTR arg6, SIPTR arg7);
100 void internal_SendPkt(struct DosPacket *dp, struct MsgPort *port, struct MsgPort *replyport);
101 struct DosPacket *internal_WaitPkt(struct MsgPort *msgPort);
102 void internal_ReplyPkt(struct DosPacket *dp, struct MsgPort *replyPort, SIPTR res1, LONG res2);
104 #define dopacket5(base, res2, port, action, arg1, arg2, arg3, arg4, arg5) dopacket(res2, port, action, (SIPTR)(arg1), (SIPTR)(arg2), (SIPTR)(arg3), (SIPTR)(arg4), (SIPTR)(arg5), 0, 0)
105 #define dopacket4(base, res2, port, action, arg1, arg2, arg3, arg4) dopacket(res2, port, action, (SIPTR)(arg1), (SIPTR)(arg2), (SIPTR)(arg3), (SIPTR)(arg4), 0, 0, 0)
106 #define dopacket3(base, res2, port, action, arg1, arg2, arg3) dopacket(res2, port, action, (SIPTR)(arg1), (SIPTR)(arg2), (SIPTR)(arg3), 0, 0, 0, 0)
107 #define dopacket2(base, res2, port, action, arg1, arg2) dopacket(res2, port, action, (SIPTR)(arg1), (SIPTR)(arg2), 0, 0, 0, 0, 0)
108 #define dopacket1(base, res2, port, action, arg1) dopacket(res2, port, action, (SIPTR)(arg1), 0, 0, 0, 0, 0, 0)
109 #define dopacket0(base, res2, port, action) dopacket(res2, port, action, 0, 0, 0, 0, 0, 0, 0)
111 #ifdef __mc68000
112 extern void BCPL_Fixup(struct Process *me);
113 #else
114 #define BCPL_Fixup(p) do { } while (0)
115 #endif
117 ULONG CallEntry(STRPTR argptr, ULONG argsize, LONG_FUNC entry, struct Process *me);
119 struct MsgPort *RunHandler(struct DeviceNode *deviceNode, const char *path, struct DosLibrary *DOSBase);
120 BOOL namefrom_internal(struct DosLibrary *DOSBase, BPTR lock, STRPTR buffer, LONG length);
122 /* Platform-overridable boot sequence */
123 void __dos_Boot(struct DosLibrary *DOSBase, ULONG BootFlags, UBYTE Flags);
124 BOOL __dos_IsBootable(struct DosLibrary *DOSBase, BPTR Lock);
126 /* Cli dependent SetProgramName() for use in CreateNewProc() */
127 BOOL internal_SetProgramName(struct CommandLineInterface *cli,
128 CONST_STRPTR name, struct DosLibrary *DOSBase);
129 /* Duplicate a cli_CommandDir BPTR list */
130 BPTR internal_CopyPath(BPTR boldpath, struct DosLibrary * DOSBase);
133 /* Pattern matching function used by MatchPattern() and MatchPatternNoCase() */
134 BOOL patternMatch(CONST_STRPTR pat, CONST_STRPTR str, BOOL useCase,
135 struct DosLibrary *DOSBase);
137 /* Pattern parsing function used by ParsePattern() and ParsePatternNoCase() */
138 LONG patternParse(CONST_STRPTR Source, STRPTR Dest, LONG DestLength,
139 BOOL useCase, struct DosLibrary *DOSBase);
142 LONG InternalSeek
144 struct FileHandle *fh,
145 LONG position,
146 LONG mode,
147 struct DosLibrary *DOSBase
149 LONG InternalFlush( struct FileHandle *fh, struct DosLibrary *DOSBase );
152 /* match_misc.c */
154 struct AChain *Match_AllocAChain(LONG extrasize, struct DosLibrary *DOSBase);
155 void Match_FreeAChain(struct AChain *ac, struct DosLibrary *DOSBase);
156 LONG Match_BuildAChainList(CONST_STRPTR pattern, struct AnchorPath *ap,
157 struct AChain **retac, struct DosLibrary *DOSBase);
158 LONG Match_MakeResult(struct AnchorPath *ap, struct DosLibrary *DOSBase);
160 void addprocesstoroot(struct Process * , struct DosLibrary *);
161 void removefromrootnode(struct Process *, struct DosLibrary *);
163 struct marker
165 UBYTE type; /* 0: Split 1: MP_NOT */
166 CONST_STRPTR pat; /* Pointer into pattern */
167 CONST_STRPTR str; /* Pointer into string */
170 struct markerarray
172 struct markerarray *next;
173 struct markerarray *prev;
174 struct marker marker[128];
177 #define PUSH(t,p,s) \
179 if(macnt==128) \
181 if(macur->next==NULL) \
183 macur->next=AllocMem(sizeof(struct markerarray),MEMF_ANY); \
184 if(macur->next==NULL) \
185 ERROR(ERROR_NO_FREE_STORE); \
186 macur->next->prev=macur; \
188 macur=macur->next; \
189 macnt=0; \
191 macur->marker[macnt].type=(t); \
192 macur->marker[macnt].pat=(p); \
193 macur->marker[macnt].str=(s); \
194 macnt++; \
197 #define POP(t,p,s) \
199 macnt--; \
200 if(macnt<0) \
202 macnt=127; \
203 macur=macur->prev; \
204 if(macur==NULL) \
205 ERROR(0); \
207 (t)=macur->marker[macnt].type; \
208 (p)=macur->marker[macnt].pat; \
209 (s)=macur->marker[macnt].str; \
212 #define MP_ESCAPE 0x81 /* Before characters in [0x81;0x8a] */
213 #define MP_MULT 0x82 /* _#(_a) */
214 #define MP_MULT_END 0x83 /* #(a_)_ */
215 #define MP_NOT 0x84 /* _~(_a) */
216 #define MP_NOT_END 0x85 /* ~(a_)_ */
217 #define MP_OR 0x86 /* _(_a|b) */
218 #define MP_OR_NEXT 0x87 /* (a_|_b) */
219 #define MP_OR_END 0x88 /* (a|b_)_ */
220 #define MP_SINGLE 0x89 /* ? */
221 #define MP_ALL 0x8a /* #? or * */
222 #define MP_SET 0x8b /* _[_ad-g] */
223 #define MP_NOT_SET 0x8c /* _[~_ad-g] */
224 #define MP_DASH 0x8d /* [ad_-g_] */
225 #define MP_SET_END 0x8e /* [ad-g_]_ */
227 /* Whether MatchFirst/MatchNext/MatchEnd in case of the base
228 AChain should just take the currentdir lock pointer, or
229 make a real duplicate with DupLock() */
231 #define MATCHFUNCS_NO_DUPLOCK 0
233 #define __is_task(task) (((struct Task *)task)->tc_Node.ln_Type == NT_TASK)
234 #define __is_process(task) (((struct Task *)task)->tc_Node.ln_Type == NT_PROCESS)
236 struct seginfo
238 struct MinNode node;
239 APTR addr;
240 char name[32];
243 struct debug_segnode
245 struct MinNode node;
246 UBYTE name[200];
247 BPTR seglist;
248 IPTR start_address; // start address of loaded executable segment
249 struct MinList seginfos;
252 struct InternalExAllControl
254 struct ExAllControl eac;
255 /* Used for ExAll emulation. If non null, it means
256 ExAll emulation is being performed. */
257 struct FileInfoBlock *fib;
261 typedef struct FileHandle* FileHandlePtr;
263 void vbuf_free(FileHandlePtr fh);
264 APTR vbuf_alloc(FileHandlePtr fh, STRPTR buf, ULONG size);
265 BOOL vbuf_inject(BPTR fh, CONST_STRPTR argptr, ULONG argsize, struct DosLibrary *DOSBase);
267 LONG FWriteChars(BPTR file, CONST UBYTE* buffer, ULONG length, struct DosLibrary *DOSBase);
270 #ifdef AROS_FAST_BSTR
272 #define CMPBSTR(x, y) Stricmp(BADDR(x), BADDR(y))
273 #define CMPNICBSTR(x, y, n) Strnicmp(x, BADDR(y), n)
274 #define BSTR2C(s) ((STRPTR)BADDR(s))
275 #define FreeCSTR(s)
277 #else
279 BOOL CMPBSTR(BSTR, BSTR);
280 BOOL CMPNICBSTR(CONST_STRPTR, BSTR, UBYTE);
281 char *BSTR2C(BSTR);
283 #define FreeCSTR(s) FreeVec(s)
285 #endif
287 #ifdef AROS_FAST_BSTR
288 #define C2BSTR(x) ((char *)(x))
289 #define FREEC2BSTR(x) do { } while (0)
290 #define CMPCBSTR(a,b) strcmp(a,b)
291 #define CMPICBSTR(a,b) Stricmp(a,b)
292 #else
293 BSTR C2BSTR(CONST_STRPTR);
294 #define FREEC2BSTR(bstr) FreeVec(BADDR(bstr))
295 BOOL CMPCBSTR(CONST_STRPTR, BSTR);
296 BOOL CMPICBSTR(CONST_STRPTR, BSTR);
297 #endif
299 void fixfib(struct FileInfoBlock*);
301 struct PacketHelperStruct
303 BSTR name;
304 struct MsgPort *port;
305 BPTR lock;
306 struct DevProc *dp;
309 BOOL getpacketinfo(struct DosLibrary *DOSBase, CONST_STRPTR, struct PacketHelperStruct*);
310 BOOL getdevpacketinfo(struct DosLibrary *DOSBase, CONST_STRPTR devname, CONST_STRPTR name, struct PacketHelperStruct *phs);
311 void freepacketinfo(struct DosLibrary *DOSBase, struct PacketHelperStruct*);
313 #define ASSERT_VALID_FILELOCK(lock) do { \
314 struct FileLock *fl = BADDR(lock); \
315 if (fl && fl->fl_Access != SHARED_LOCK && fl->fl_Access != EXCLUSIVE_LOCK) { \
316 bug("%s() called with a bogus FileLock! Lock=%x FL=%x Access %d %s/%s/%d\n", __FUNCTION__, lock, fl, fl->fl_Access, __FILE__,__FUNCTION__,__LINE__); \
318 } while (0);
320 /* Shell utilities */
321 BPTR findseg_cli(BOOL isBoot, struct DosLibrary *DOSBase);
323 BPTR findseg_shell(BOOL isBoot, struct DosLibrary *DOSBase);
325 /* Helper for IN:, OUT:, ERR:, STDIN:, STDOUT:, STDERR:
327 BOOL pseudoLock(CONST_STRPTR name, LONG lockMode, BPTR *lock, LONG *ret, struct DosLibrary *DOSBase);
329 #endif /* DOS_INTERN_H */