Documented GVF_SAVE_VAR alongside other flags, and removed a query/doubt
[AROS.git] / rom / filesys / SFS / SetCache / SetCache.c
blobb715b7b54cd833e236ce50a8759814588cac3e7d
1 #include <dos/dos.h>
2 #include <dos/dosextens.h>
3 #include <proto/dos.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";
12 int main()
14 struct RDArgs *readarg;
15 UBYTE template[]="DEVICE/A,LINES/N,READAHEAD/N,NOCOPYBACK/S\n";
17 struct {char *name;
18 ULONG *lines;
19 ULONG *readahead;
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;
25 struct DosList *dl;
26 UBYTE *devname=arglist.name;
28 while(*devname!=0) {
29 if(*devname==':') {
30 *devname=0;
31 break;
33 devname++;
36 dl=LockDosList(LDF_DEVICES|LDF_READ);
37 if((dl=FindDosEntry(dl,arglist.name,LDF_DEVICES))!=0) {
38 ULONG copyback=1;
39 LONG errorcode;
40 msgport=dl->dol_Task;
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},
47 {ASQ_CACHE_MODE , 0},
48 {TAG_END , 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) {
58 copyback=0;
61 if(arglist.lines!=0) {
62 lines=*arglist.lines;
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);
71 if(copyback!=0) {
72 PutStr("enabled.\n");
74 else {
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");
82 else {
83 PrintFault(IoErr(),"error while reading old cache settings");
88 struct TagItem tags[]={
89 {ASQ_CACHE_LINES , 0},
90 {ASQ_CACHE_READAHEADSIZE, 0},
91 {ASQ_CACHE_MODE , 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");
100 else {
101 PutStr("copyback.\n");
106 else {
107 Printf("Couldn't find device '%s:'.\n",arglist.name);
108 UnLockDosList(LDF_DEVICES|LDF_READ);
111 FreeArgs(readarg);
113 else {
114 PutStr("Wrong arguments!\n");
116 CloseLibrary((struct Library *)DOSBase);
118 return(0);