2 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
5 Desc: Resident CLI command
10 #include <proto/dos.h>
11 #include <dos/dosextens.h>
13 #include <exec/lists.h>
14 #include <exec/nodes.h>
15 #include <exec/memory.h>
19 #include <aros/shcommands.h>
27 static struct SegNode
*NewSegNode(struct ExecBase
*SysBase
, STRPTR name
, LONG uc
);
29 AROS_SH7(Resident
, 41.2,
30 AROS_SHA(STRPTR
, ,NAME
, ,NULL
),
31 AROS_SHA(STRPTR
, ,FILE, ,NULL
),
32 AROS_SHA(BOOL
, ,REMOVE
,/S
,FALSE
),
33 AROS_SHA(BOOL
, ,ADD
,/S
,FALSE
),
34 AROS_SHA(BOOL
, ,REPLACE
,/S
,FALSE
),
35 AROS_SHA(BOOL
,PURE
=,FORCE
,/S
,FALSE
),
36 AROS_SHA(BOOL
, ,SYSTEM
,/S
,FALSE
))
41 if (SHArg(FILE) || SHArg(NAME
))
45 struct FileInfoBlock
*fib
;
54 name
= FilePart(SHArg(NAME
));
61 struct Segment
*found
;
64 found
= FindSegment(name
, NULL
, TRUE
);
68 SetIoErr(ERROR_OBJECT_NOT_FOUND
);
71 if (!RemSegment(found
))
73 if (found
->seg_UC
== CMD_INTERNAL
)
74 found
->seg_UC
= CMD_DISABLED
;
76 SetIoErr(ERROR_OBJECT_IN_USE
);
81 PrintFault(IoErr(), SHArg(NAME
));
90 struct Segment
*found
;
93 found
= FindSegment(name
, NULL
, TRUE
);
94 if (found
&& found
->seg_UC
== CMD_DISABLED
)
96 found
->seg_UC
= CMD_INTERNAL
;
103 if (!SHArg(ADD
)) SHArg(REPLACE
) = TRUE
;
105 if (!SHArg(FORCE
) && (fib
= (struct FileInfoBlock
*)AllocDosObject(DOS_FIB
, NULL
)))
109 if ((lock
= Lock(file
, SHARED_LOCK
)))
111 if (Examine(lock
, fib
))
113 if ((fib
->fib_Protection
& FIBF_PURE
) == 0)
114 SetIoErr(ERROR_OBJECT_WRONG_TYPE
);
120 FreeDosObject(DOS_FIB
, fib
);
123 if (IoErr() || !(seglist
= LoadSeg(file
)))
125 PrintFault(IoErr(), file
);
131 struct Segment
*found
;
134 found
= FindSegment(name
, NULL
, FALSE
);
138 if (found
->seg_UC
!= 0)
141 PrintFault(ERROR_OBJECT_IN_USE
, file
);
146 UnLoadSeg(found
->seg_Seg
);
147 found
->seg_Seg
= seglist
;
155 /* WB1.x backwards compatibility hack, do not allow
156 * override of built-in resident or to add l:shell-seg (CLI) */
157 if (!stricmp(name
, "resident") || !stricmp(name
, "cli")) {
158 SetIoErr(ERROR_OBJECT_WRONG_TYPE
);
160 return 1; /* yes, return code = 1 in this special case */
163 if (!AddSegment(name
, seglist
, SHArg(SYSTEM
)?CMD_SYSTEM
:0))
166 PrintFault(IoErr(), "Resident");
174 struct Segment
*curr
;
176 struct DosInfo
*dinf
= BADDR(DOSBase
->dl_Root
->rn_Info
);
177 BOOL isbreak
= FALSE
;
179 NEWLIST((struct List
*)&l
);
183 curr
= (struct Segment
*)BADDR(dinf
->di_ResList
);
186 n
= NewSegNode(SysBase
, AROS_BSTR_ADDR(MKBADDR(&curr
->seg_Name
[0])), curr
->seg_UC
);
190 SetIoErr(ERROR_NO_FREE_STORE
);
194 AddTail((struct List
*)&l
, (struct Node
*)n
);
195 curr
= (struct Segment
*)BADDR(curr
->seg_Next
);
201 PrintFault(IoErr(), "Resident");
205 PutStr("NAME USECOUNT\n\n");
206 while ((n
= (struct SegNode
*)RemHead((struct List
*)&l
)))
208 if (SetSignal(0L, SIGBREAKF_CTRL_C
) & SIGBREAKF_CTRL_C
)
211 if (n
->data
[1] == CMD_SYSTEM
)
212 VPrintf("%-30s SYSTEM\n", n
->data
);
214 if (n
->data
[1] == CMD_INTERNAL
)
215 VPrintf("%-30s INTERNAL\n", n
->data
);
217 if (n
->data
[1] == CMD_DISABLED
)
218 VPrintf("%-30s DISABLED\n", n
->data
);
220 VPrintf("%-30s %-ld\n", n
->data
);
222 FreeVec((APTR
)n
->data
[0]);
226 SetIoErr(ERROR_BREAK
);
227 PrintFault(IoErr(), "Resident");
237 static STRPTR
StrDup(struct ExecBase
*SysBase
, STRPTR str
)
239 size_t len
= strlen(str
)+1;
240 STRPTR ret
= (STRPTR
) AllocVec(len
, MEMF_ANY
);
244 CopyMem(str
, ret
, len
);
251 static struct SegNode
*NewSegNode(struct ExecBase
*SysBase
, STRPTR name
,
254 struct SegNode
*sn
= AllocVec(sizeof (struct SegNode
), MEMF_ANY
);
258 sn
->data
[0] = (IPTR
) StrDup(SysBase
, name
);