2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Miscellaneous functions for dealing with DOS rootnode.
9 #include <aros/debug.h>
11 #include <exec/lists.h>
12 #include <exec/types.h>
13 #include <exec/memory.h>
14 #include <proto/exec.h>
15 #include <dos/dosextens.h>
16 #include "dos_intern.h"
19 /* Add a CLI process to the RootNode structure. This is used by commands
20 as C:Status and functions like dos.library/MaxCli() */
21 void addprocesstoroot(struct Process
*process
, struct DosLibrary
*DOSBase
)
28 struct CommandLineInterface
*cli
=
29 (struct CommandLineInterface
*)BADDR(process
->pr_CLI
);
31 struct RootNode
*root
= DOSBase
->dl_Root
;
35 D(bug("Calling addprocesstoroot() with cli = %p\n", cli
));
40 ci
= (struct CLIInfo
*)AllocVec(sizeof(struct CLIInfo
), MEMF_PUBLIC
);
45 ci
->ci_Process
= process
;
47 ObtainSemaphore(&root
->rn_RootLock
);
49 /* Set the node's name to the process' name so we may use FindName()
50 on the rn_CliList to locate a specific command */
52 /* This is kind of hacky but doing it another way will be more
53 troublesome; we rely here that even BSTR:s have a trailing 0. */
55 ci
->ci_Node
.ln_Name
= AROS_BSTR_ADDR(cli
->cli_CommandName
);
57 /* Can't use AddTail() here as it complains about the list pointer */
58 ADDTAIL((struct List
*)&root
->rn_CliList
, (struct Node
*)ci
);
60 taskarray
= BADDR(root
->rn_TaskArray
);
64 ** Check out the taskarray for an empty slot
72 taskarray
[i
] = (ULONG
)&process
->pr_MsgPort
;
73 process
->pr_TaskNum
= i
;
75 ReleaseSemaphore(&root
->rn_RootLock
);
77 D(bug("Returning from addprocesstoroot() -- 1\n"));
86 ** it seems like a new taskarray is needed
88 newtaskarray
= AllocMem(sizeof(ULONG
) + (size
+ 1)*sizeof(APTR
), MEMF_ANY
);
90 newtaskarray
[0] = size
+ 1;
95 newtaskarray
[i
] = taskarray
[i
];
99 newtaskarray
[size
+ 1] = (ULONG
)&process
->pr_MsgPort
;
100 process
->pr_TaskNum
= size
+ 1;
102 root
->rn_TaskArray
= MKBADDR(newtaskarray
);
104 FreeMem(taskarray
, sizeof(ULONG
) + size
*sizeof(APTR
));
106 ReleaseSemaphore(&root
->rn_RootLock
);
110 void removefromrootnode(struct Process
*process
, struct DosLibrary
*DOSBase
)
117 struct CLIInfo
*cliNode
;
118 struct RootNode
*root
= DOSBase
->dl_Root
;
120 if (!__is_process(process
) || process
->pr_CLI
== NULL
)
125 ObtainSemaphore(&root
->rn_RootLock
);
127 /* Remove node from CliList */
128 ForeachNodeSafe(&root
->rn_CliList
, cliNode
, temp
)
130 if (cliNode
->ci_Process
== process
)
132 Remove((struct Node
*)cliNode
);
138 taskarray
= BADDR(root
->rn_TaskArray
);
145 if (taskarray
[i
] == (ULONG
)&process
->pr_MsgPort
)
154 ReleaseSemaphore(&root
->rn_RootLock
);