2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
5 Desc: Internal types and stuff for dos
11 #include <aros/system.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.
29 #define TimerBase (DOSBase->dl_TimeReq->tr_node.io_Device)
31 #define UtilityBase (DOSBase->dl_UtilityBase)
33 /* Needed for close() */
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 */
43 struct DosLibrary pub
;
44 struct Library
*debugBase
;
45 struct RootNode rootNode
__attribute__((aligned(4)));
46 struct ErrorString errors
__attribute__((aligned(4)));
48 ULONG arm_Arch
; /* ARM-specific info for ELF loader */
54 #define IDosBase(base) ((struct IntDosBase *)base)
55 #define DebugBase IDosBase(DOSBase)->debugBase
69 #define IOBUFSIZE 4096
76 struct DosLibrary
*DOSBase
;
79 /* fh_Flags. The flags are AROS specific and therefore PRIVATE.. */
80 #define FHF_WRITE 0x80000000
81 #define FHF_BUF 0x00000001
82 #define FHF_APPEND 0x00000002
83 #define FHF_LINEBUF 0x00000004
84 #define FHF_NOBUF 0x00000008
85 #define FHF_OWNBUF 0x00000010
86 #define FHF_FLUSHING 0x00000020
89 (((struct FileHandle *)BADDR(f))->fh_Flags&FHF_WRITE&& \
90 ((struct FileHandle *)BADDR(f))->fh_Pos<((struct FileHandle *)BADDR(f))->fh_End? \
91 *((struct FileHandle *)BADDR(f))->fh_Pos++=c,0:FPutC(f,c))
93 #define DOS_FH_MAGIC AROS_MAKE_ID('F','h','n','d')
94 #define ISFILEHANDLE(f) \
95 ((((struct FileHandle *)BADDR(f))->fh_Func2) == DOS_FH_MAGIC)
97 /* Softlink handling */
98 STRPTR
ResolveSoftlink(BPTR cur
, struct DevProc
*dvp
, CONST_STRPTR name
, struct DosLibrary
*DOSBase
);
99 LONG
RootDir(struct DevProc
*dvp
, struct DosLibrary
*DOSBase
);
102 struct DosPacket
*allocdospacket(void);
103 void freedospacket(struct DosPacket
*dp
);
104 SIPTR
dopacket(SIPTR
*res2
, struct MsgPort
*port
, LONG action
, SIPTR arg1
, SIPTR arg2
, SIPTR arg3
, SIPTR arg4
, SIPTR arg5
, SIPTR arg6
, SIPTR arg7
);
105 void internal_SendPkt(struct DosPacket
*dp
, struct MsgPort
*port
, struct MsgPort
*replyport
);
106 struct DosPacket
*internal_WaitPkt(struct MsgPort
*msgPort
);
107 void internal_ReplyPkt(struct DosPacket
*dp
, struct MsgPort
*replyPort
, SIPTR res1
, LONG res2
);
108 SIPTR
handleNIL(LONG action
, SIPTR arg1
, SIPTR arg2
, SIPTR arg3
);
110 #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)
111 #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)
112 #define dopacket3(base, res2, port, action, arg1, arg2, arg3) dopacket(res2, port, action, (SIPTR)(arg1), (SIPTR)(arg2), (SIPTR)(arg3), 0, 0, 0, 0)
113 #define dopacket2(base, res2, port, action, arg1, arg2) dopacket(res2, port, action, (SIPTR)(arg1), (SIPTR)(arg2), 0, 0, 0, 0, 0)
114 #define dopacket1(base, res2, port, action, arg1) dopacket(res2, port, action, (SIPTR)(arg1), 0, 0, 0, 0, 0, 0)
115 #define dopacket0(base, res2, port, action) dopacket(res2, port, action, 0, 0, 0, 0, 0, 0, 0)
118 extern void BCPL_Fixup(struct Process
*me
);
120 #define BCPL_Fixup(p) do { } while (0)
123 ULONG
CallEntry(STRPTR argptr
, ULONG argsize
, LONG_FUNC entry
, struct Process
*me
);
125 struct MsgPort
*RunHandler(struct DeviceNode
*deviceNode
, const char *path
, struct DosLibrary
*DOSBase
);
126 BOOL
namefrom_internal(struct DosLibrary
*DOSBase
, BPTR lock
, STRPTR buffer
, LONG length
);
128 /* Platform-overridable boot sequence */
129 void __dos_Boot(struct DosLibrary
*DOSBase
, ULONG BootFlags
, UBYTE Flags
);
130 BOOL
__dos_IsBootable(struct DosLibrary
*DOSBase
, BPTR Lock
);
132 /* Cli dependent SetProgramName() for use in CreateNewProc() */
133 BOOL
internal_SetProgramName(struct CommandLineInterface
*cli
,
134 CONST_STRPTR name
, struct DosLibrary
*DOSBase
);
135 /* Duplicate a cli_CommandDir BPTR list */
136 BPTR
internal_CopyPath(BPTR boldpath
, struct DosLibrary
* DOSBase
);
139 /* Pattern matching function used by MatchPattern() and MatchPatternNoCase() */
140 BOOL
patternMatch(CONST_STRPTR pat
, CONST_STRPTR str
, BOOL useCase
,
141 struct DosLibrary
*DOSBase
);
143 /* Pattern parsing function used by ParsePattern() and ParsePatternNoCase() */
144 LONG
patternParse(CONST_STRPTR Source
, STRPTR Dest
, LONG DestLength
,
145 BOOL useCase
, struct DosLibrary
*DOSBase
);
150 struct FileHandle
*fh
,
153 struct DosLibrary
*DOSBase
155 LONG
InternalFlush( struct FileHandle
*fh
, struct DosLibrary
*DOSBase
);
160 struct AChain
*Match_AllocAChain(LONG extrasize
, struct DosLibrary
*DOSBase
);
161 void Match_FreeAChain(struct AChain
*ac
, struct DosLibrary
*DOSBase
);
162 LONG
Match_BuildAChainList(CONST_STRPTR pattern
, struct AnchorPath
*ap
,
163 struct AChain
**retac
, struct DosLibrary
*DOSBase
);
164 LONG
Match_MakeResult(struct AnchorPath
*ap
, struct DosLibrary
*DOSBase
);
166 void addprocesstoroot(struct Process
* , struct DosLibrary
*);
167 void removefromrootnode(struct Process
*, struct DosLibrary
*);
171 UBYTE type
; /* 0: Split 1: MP_NOT */
172 CONST_STRPTR pat
; /* Pointer into pattern */
173 CONST_STRPTR str
; /* Pointer into string */
178 struct markerarray
*next
;
179 struct markerarray
*prev
;
180 struct marker marker
[128];
183 #define PUSH(t,p,s) \
187 if(macur->next==NULL) \
189 macur->next=AllocMem(sizeof(struct markerarray),MEMF_ANY); \
190 if(macur->next==NULL) \
191 ERROR(ERROR_NO_FREE_STORE); \
192 macur->next->prev=macur; \
197 macur->marker[macnt].type=(t); \
198 macur->marker[macnt].pat=(p); \
199 macur->marker[macnt].str=(s); \
213 (t)=macur->marker[macnt].type; \
214 (p)=macur->marker[macnt].pat; \
215 (s)=macur->marker[macnt].str; \
218 #define MP_ESCAPE 0x81 /* Before characters in [0x81;0x8a] */
219 #define MP_MULT 0x82 /* _#(_a) */
220 #define MP_MULT_END 0x83 /* #(a_)_ */
221 #define MP_NOT 0x84 /* _~(_a) */
222 #define MP_NOT_END 0x85 /* ~(a_)_ */
223 #define MP_OR 0x86 /* _(_a|b) */
224 #define MP_OR_NEXT 0x87 /* (a_|_b) */
225 #define MP_OR_END 0x88 /* (a|b_)_ */
226 #define MP_SINGLE 0x89 /* ? */
227 #define MP_ALL 0x8a /* #? or * */
228 #define MP_SET 0x8b /* _[_ad-g] */
229 #define MP_NOT_SET 0x8c /* _[~_ad-g] */
230 #define MP_DASH 0x8d /* [ad_-g_] */
231 #define MP_SET_END 0x8e /* [ad-g_]_ */
233 /* Whether MatchFirst/MatchNext/MatchEnd in case of the base
234 AChain should just take the currentdir lock pointer, or
235 make a real duplicate with DupLock() */
237 #define MATCHFUNCS_NO_DUPLOCK 0
239 #define __is_task(task) (((struct Task *)task)->tc_Node.ln_Type == NT_TASK)
240 #define __is_process(task) (((struct Task *)task)->tc_Node.ln_Type == NT_PROCESS)
254 IPTR start_address
; // start address of loaded executable segment
255 struct MinList seginfos
;
258 struct InternalExAllControl
260 struct ExAllControl eac
;
261 /* Used for ExAll emulation. If non null, it means
262 ExAll emulation is being performed. */
263 struct FileInfoBlock
*fib
;
267 typedef struct FileHandle
* FileHandlePtr
;
269 void vbuf_free(FileHandlePtr fh
);
270 APTR
vbuf_alloc(FileHandlePtr fh
, STRPTR buf
, ULONG size
);
271 BOOL
vbuf_inject(BPTR fh
, CONST_STRPTR argptr
, ULONG argsize
, struct DosLibrary
*DOSBase
);
272 LONG
vbuf_fetch(BPTR file
, UBYTE
* buffer
, ULONG fetchsize
, struct DosLibrary
*DOSBase
);
274 LONG
FWriteChars(BPTR file
, CONST UBYTE
* buffer
, ULONG length
, struct DosLibrary
*DOSBase
);
277 #ifdef AROS_FAST_BSTR
279 #define CMPBSTR(x, y) Stricmp(BADDR(x), BADDR(y))
280 #define CMPNICBSTR(x, y, n) Strnicmp(x, BADDR(y), n)
281 #define BSTR2C(s) ((STRPTR)BADDR(s))
286 BOOL
CMPBSTR(BSTR
, BSTR
);
287 BOOL
CMPNICBSTR(CONST_STRPTR
, BSTR
, UBYTE
);
290 #define FreeCSTR(s) FreeVec(s)
294 #ifdef AROS_FAST_BSTR
295 #define C2BSTR(x) ((char *)(x))
296 #define FREEC2BSTR(x) do { } while (0)
297 #define CMPCBSTR(a,b) strcmp(a,b)
298 #define CMPICBSTR(a,b) Stricmp(a,b)
300 BSTR
C2BSTR(CONST_STRPTR
);
301 #define FREEC2BSTR(bstr) FreeVec(BADDR(bstr))
302 BOOL
CMPCBSTR(CONST_STRPTR
, BSTR
);
303 BOOL
CMPICBSTR(CONST_STRPTR
, BSTR
);
306 void fixfib(struct FileInfoBlock
*);
308 struct PacketHelperStruct
311 struct MsgPort
*port
;
316 BOOL
getpacketinfo(struct DosLibrary
*DOSBase
, CONST_STRPTR
, struct PacketHelperStruct
*);
317 BOOL
getdevpacketinfo(struct DosLibrary
*DOSBase
, CONST_STRPTR devname
, CONST_STRPTR name
, struct PacketHelperStruct
*phs
);
318 void freepacketinfo(struct DosLibrary
*DOSBase
, struct PacketHelperStruct
*);
320 #define ASSERT_VALID_FILELOCK(lock) do { \
321 struct FileLock *fl = BADDR(lock); \
322 if (fl && fl->fl_Access != SHARED_LOCK && fl->fl_Access != EXCLUSIVE_LOCK) { \
323 bug("%s() bogus FileLock! '%s' %x %d %s/%s/%d\n", \
324 __FUNCTION__, FindTask(NULL)->tc_Node.ln_Name, fl, fl->fl_Access, __FILE__,__FUNCTION__,__LINE__); \
328 /* Shell utilities */
329 BPTR
findseg_cli(BOOL isBoot
, struct DosLibrary
*DOSBase
);
331 BPTR
findseg_shell(BOOL isBoot
, struct DosLibrary
*DOSBase
);
333 /* Helper for IN:, OUT:, ERR:, STDIN:, STDOUT:, STDERR:
335 BOOL
pseudoLock(CONST_STRPTR name
, LONG lockMode
, BPTR
*lock
, LONG
*ret
, struct DosLibrary
*DOSBase
);
337 #endif /* DOS_INTERN_H */