2 Copyright © 1995-2001, 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.1,
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
)
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 if (!AddSegment(name
, seglist
, SHArg(SYSTEM
)?CMD_SYSTEM
:0))
158 PrintFault(IoErr(), "Resident");
166 struct Segment
*curr
;
169 NEWLIST((struct List
*)&l
);
173 curr
= (struct Segment
*)BADDR(DOSBase
->dl_ResList
);
176 n
= NewSegNode(SysBase
, AROS_BSTR_ADDR(curr
->seg_Name
), curr
->seg_UC
);
180 SetIoErr(ERROR_NO_FREE_STORE
);
184 AddTail((struct List
*)&l
, (struct Node
*)n
);
185 curr
= (struct Segment
*)BADDR(curr
->seg_Next
);
191 PrintFault(IoErr(), "Resident");
195 PutStr("NAME USECOUNT\n\n");
196 while ((n
= (struct SegNode
*)RemHead((struct List
*)&l
)))
198 if (n
->data
[1] == CMD_SYSTEM
)
199 VPrintf("%-30s SYSTEM\n", n
->data
);
201 if (n
->data
[1] == CMD_INTERNAL
)
202 VPrintf("%-30s INTERNAL\n", n
->data
);
204 if (n
->data
[1] == CMD_DISABLED
)
205 VPrintf("%-30s DISABLED\n", n
->data
);
207 VPrintf("%-30s %-ld\n", n
->data
);
209 FreeVec((APTR
)n
->data
[0]);
220 static STRPTR
StrDup(struct ExecBase
*SysBase
, STRPTR str
)
222 size_t len
= strlen(str
)+1;
223 STRPTR ret
= (STRPTR
) AllocVec(len
, MEMF_ANY
);
227 CopyMem(str
, ret
, len
);
234 static struct SegNode
*NewSegNode(struct ExecBase
*SysBase
, STRPTR name
,
237 struct SegNode
*sn
= AllocVec(sizeof (struct SegNode
), MEMF_ANY
);
241 sn
->data
[0] = (IPTR
) StrDup(SysBase
, name
);