Added kernel module for starting the usb stack at boot time. It's not activated thoug...
[cake.git] / rom / dos / rootnode.c
blobe00842b5aa8e7bfdb81256c6986a2d795cce783d
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Miscellaneous functions for dealing with DOS rootnode.
6 Lang:
7 */
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)
23 ULONG *taskarray;
24 ULONG *newtaskarray;
25 ULONG size;
26 ULONG i;
28 struct CommandLineInterface *cli =
29 (struct CommandLineInterface *)BADDR(process->pr_CLI);
31 struct RootNode *root = DOSBase->dl_Root;
33 struct CLIInfo *ci;
35 D(bug("Calling addprocesstoroot() with cli = %p\n", cli));
37 if(cli == NULL)
38 return;
40 ci = (struct CLIInfo *)AllocVec(sizeof(struct CLIInfo), MEMF_PUBLIC);
42 if(ci == NULL)
43 return;
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);
61 size = taskarray[0];
64 ** Check out the taskarray for an empty slot
66 i = 1;
68 while(i <= size)
70 if(0 == taskarray[i])
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"));
79 return;
82 i++;
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;
91 i = 1;
93 while(i <= size)
95 newtaskarray[i] = taskarray[i];
96 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)
112 ULONG size;
113 ULONG *taskarray;
114 ULONG i;
116 struct Node *temp;
117 struct CLIInfo *cliNode;
118 struct RootNode *root = DOSBase->dl_Root;
120 if (!__is_process(process) || process->pr_CLI == NULL)
122 return;
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);
133 FreeVec(cliNode);
134 break;
138 taskarray = BADDR(root->rn_TaskArray);
139 size = taskarray[0];
141 i = 1;
143 while (i <= size)
145 if (taskarray[i] == (ULONG)&process->pr_MsgPort)
147 taskarray[i] = 0;
148 break;
151 i++;
154 ReleaseSemaphore(&root->rn_RootLock);