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(%p) with cli = %p\n", process
, cli
));
40 ci
= (struct CLIInfo
*)AllocVec(sizeof(struct CLIInfo
), MEMF_PUBLIC
);
45 ObtainSemaphore(&root
->rn_RootLock
);
47 D(bug("[addprocesstoroot] Adding to CliList\n"));
48 /* Set the node's name to the process' name so we may use FindName()
49 on the rn_CliList to locate a specific command */
51 /* This is kind of hacky but doing it another way will be more
52 troublesome; we rely here that even BSTR:s have a trailing 0. */
54 ci
->ci_Process
= process
;
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 D(bug("[addprocesstoroot] Adding to TaskArray\n"));
61 taskarray
= BADDR(root
->rn_TaskArray
);
65 ** Check out the taskarray for an empty slot
73 taskarray
[i
] = (IPTR
)&process
->pr_MsgPort
;
74 process
->pr_TaskNum
= i
;
82 ** it seems like a new taskarray is needed
84 newtaskarray
= AllocMem(sizeof(IPTR
) + (size
+ 1)*sizeof(APTR
), MEMF_ANY
);
86 newtaskarray
[0] = size
+ 1;
91 newtaskarray
[i
] = taskarray
[i
];
95 newtaskarray
[size
+ 1] = (IPTR
)&process
->pr_MsgPort
;
96 process
->pr_TaskNum
= size
+ 1;
98 root
->rn_TaskArray
= MKBADDR(newtaskarray
);
100 FreeMem(taskarray
, sizeof(IPTR
) + size
*sizeof(APTR
));
103 D(bug("Returning from addprocesstoroot() (%d)\n", process
->pr_TaskNum
));
104 ReleaseSemaphore(&root
->rn_RootLock
);
108 void removefromrootnode(struct Process
*process
, struct DosLibrary
*DOSBase
)
111 struct CLIInfo
*ci
, *tmp
;
113 struct RootNode
*root
= DOSBase
->dl_Root
;
115 D(bug("[removefromrootnode] %p, TaskNum %d\n", process
, process
->pr_TaskNum
));
117 if (!__is_process(process
) || process
->pr_CLI
== BNULL
)
119 D(bug("[removefromrootnode] Strange. Doesn't seem be a CLI...\n"));
123 ObtainSemaphore(&root
->rn_RootLock
);
125 ForeachNodeSafe(&root
->rn_CliList
, ci
, tmp
) {
126 if (ci
->ci_Process
== process
) {
127 D(bug("[removefromrootnode] Removing from CLIList\n"));
128 Remove((struct Node
*)ci
);
133 D(bug("[removefromrootnode] Removing from TaskArray\n"));
134 taskarray
= BADDR(root
->rn_TaskArray
);
135 taskarray
[process
->pr_TaskNum
] = 0;
137 ReleaseSemaphore(&root
->rn_RootLock
);