2 #include <dos/dosextens.h>
4 #include <proto/exec.h>
5 #include <utility/tagitem.h>
7 #include "../FS/packets.h"
8 #include "../FS/query.h"
10 const char version
[]="\0$VER: SetCache 1.2 (" ADATE
")\r\n";
14 struct RDArgs
*readarg
;
15 UBYTE
template[]="DEVICE/A,LINES/N,READAHEAD/N,NOCOPYBACK/S\n";
20 IPTR nocopyback
;} arglist
={NULL
};
22 if((DOSBase
=(struct DosLibrary
*)OpenLibrary("dos.library",37))!=0) {
23 if((readarg
=ReadArgs(template,(IPTR
*)&arglist
,0))!=0) {
24 struct MsgPort
*msgport
;
26 UBYTE
*devname
=arglist
.name
;
36 dl
=LockDosList(LDF_DEVICES
|LDF_READ
);
37 if((dl
=FindDosEntry(dl
,arglist
.name
,LDF_DEVICES
))!=0) {
41 UnLockDosList(LDF_DEVICES
|LDF_READ
);
43 if(arglist
.lines
!=0 || arglist
.readahead
!=0 || arglist
.nocopyback
!=0) {
44 struct TagItem tags
[]={
45 {ASQ_CACHE_LINES
, 0},
46 {ASQ_CACHE_READAHEADSIZE
, 0},
51 if((errorcode
=DoPkt(msgport
, ACTION_SFS_QUERY
, (SIPTR
)&tags
, 0, 0, 0, 0))!=DOSFALSE
) {
52 ULONG lines
,readahead
;
54 lines
=tags
[0].ti_Data
;
55 readahead
=tags
[1].ti_Data
;
57 if(arglist
.nocopyback
!=0) {
61 if(arglist
.lines
!=0) {
65 if(arglist
.readahead
!=0) {
66 readahead
=*arglist
.readahead
;
69 Printf("Setting cache to %ld lines ", lines
);
70 Printf("of %ld bytes and copyback mode ", readahead
);
75 PutStr("disabled.\n");
78 if((errorcode
=DoPkt(msgport
,ACTION_SET_CACHE
, lines
, readahead
, copyback
, 0, 0))==DOSFALSE
) {
79 PrintFault(IoErr(),"error while setting new cache size");
83 PrintFault(IoErr(),"error while reading old cache settings");
88 struct TagItem tags
[]={
89 {ASQ_CACHE_LINES
, 0},
90 {ASQ_CACHE_READAHEADSIZE
, 0},
94 if((errorcode
=DoPkt(msgport
, ACTION_SFS_QUERY
, (SIPTR
)&tags
, 0, 0, 0, 0))!=DOSFALSE
) {
95 Printf("Current cache settings: %ld lines,", (ULONG
)tags
[0].ti_Data
);
96 Printf(" %ld bytes readahead, ", (ULONG
)tags
[1].ti_Data
);
97 if(tags
[2].ti_Data
==0) {
98 PutStr("no copyback.\n");
101 PutStr("copyback.\n");
107 Printf("Couldn't find device '%s:'.\n",arglist
.name
);
108 UnLockDosList(LDF_DEVICES
|LDF_READ
);
114 PutStr("Wrong arguments!\n");
116 CloseLibrary((struct Library
*)DOSBase
);