2 Copyright © 2004-2013, The AROS Development Team. All rights reserved.
3 This file is part of the LoadResource program, which is distributed under
4 the terms of version 2 of the GNU General Public License.
7 + Implement LOCK and UNLOCK options. Argument template should then be
8 changed to "NAME/M,LOCK/S,UNLOCK/S"; if the user doesn't provide NAME,
9 then all currently locked resources shall be listed.
10 + Implement support for loading devices, fonts and catalogs.
14 #include <proto/exec.h>
15 #include <proto/dos.h>
21 #if defined(__AROSPLATFORM_SMP__)
22 #include <aros/types/spinlock_s.h>
23 #include <proto/execlock.h>
24 #include <resources/execlock.h>
33 #define TEMPLATE "NAME/M/A"
34 #define ERROR_HEADER "LoadResource"
36 BOOL
process(CONST_STRPTR name
);
37 BOOL
dev_process(CONST_STRPTR name
);
42 struct RDArgs
*rdargs
= NULL
;
43 IPTR args
[ARG_COUNT
] = { 0 };
45 if ((rdargs
= ReadArgs(TEMPLATE
, args
, NULL
)) != NULL
)
47 if (args
[ARG_NAME
] != 0)
49 CONST_STRPTR
*names
= (CONST_STRPTR
*) args
[ARG_NAME
],
52 while ((name
= *names
++) != NULL
)
55 int len
= strlen(name
);
57 if ((len
> 7) && (!strcmp(&name
[len
-7], ".device")))
58 res
= dev_process(name
);
70 // FIXME: List currently locked resources.
77 PrintFault(IoErr(), ERROR_HEADER
);
84 BOOL
process(CONST_STRPTR name
)
86 struct Library
*lb
= OpenLibrary(name
, 0L);
95 PutStr(ERROR_HEADER
": ");
96 Printf(_(MSG_ERROR_OPEN_LIBRARY
), name
);
102 BOOL
dev_process(CONST_STRPTR name
)
104 struct IORequest req
;
106 memset(&req
, 0, sizeof(req
));
107 req
.io_Message
.mn_Length
= sizeof(req
);
108 #if defined(__AROSPLATFORM_SMP__)
109 void *ExecLockBase
= OpenResource("execlock.resource");
112 if (!OpenDevice(name
, 0, &req
, 0))
119 #if defined(__AROSPLATFORM_SMP__)
121 ObtainSystemLock(&SysBase
->DeviceList
, SPINLOCK_MODE_READ
, LOCKF_FORBID
);
127 /* There can different errors, but if the device was loaded, it's OK */
128 if (FindName(&SysBase
->DeviceList
, name
))
131 #if defined(__AROSPLATFORM_SMP__)
133 ReleaseSystemLock(&SysBase
->DeviceList
, LOCKF_FORBID
);
141 PutStr(ERROR_HEADER
": ");
142 Printf(_(MSG_ERROR_OPEN_DEVICE
), name
);