home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / HD / SmartFileSystem / V1.58 / Sources / SetCache / setcache.c
Encoding:
C/C++ Source or Header  |  1999-01-24  |  2.2 KB  |  84 lines

  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>
  6.  
  7. #include "/fs/packets.h"
  8. #include "/fs/query.h"
  9.  
  10. static const char version[]={"\0$VER: SetCache 1.0 " __AMIGADATE__ "\r\n"};
  11.  
  12. LONG main() {
  13.   struct RDArgs *readarg;
  14.   UBYTE template[]="DEVICE/A,LINES/N,READAHEAD/N,NOCOPYBACK/S\n";
  15.  
  16.   struct {char *name;
  17.           ULONG *lines;
  18.           ULONG *readahead;
  19.           ULONG nocopyback;} arglist={NULL};
  20.  
  21.   if((DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",37))!=0) {
  22.     if((readarg=ReadArgs(template,(LONG *)&arglist,0))!=0) {
  23.       struct MsgPort *msgport;
  24.       struct DosList *dl;
  25.       UBYTE *devname=arglist.name;
  26.  
  27.       while(*devname!=0) {
  28.         if(*devname==':') {
  29.           *devname=0;
  30.           break;
  31.         }
  32.         devname++;
  33.       }
  34.  
  35.       dl=LockDosList(LDF_DEVICES|LDF_READ);
  36.       if((dl=FindDosEntry(dl,arglist.name,LDF_DEVICES))!=0) {
  37.         ULONG copyback=1;
  38.         LONG errorcode;
  39.  
  40.         msgport=dl->dol_Task;
  41.         UnLockDosList(LDF_DEVICES|LDF_READ);
  42.  
  43.         if(arglist.lines!=0 && arglist.readahead!=0) {
  44.           if(arglist.nocopyback!=0) {
  45.             copyback=0;
  46.           }
  47.  
  48.           if((errorcode=DoPkt(msgport,ACTION_SET_CACHE,*arglist.lines,*arglist.readahead,copyback,0,0))==DOSFALSE) {
  49.             PrintFault(IoErr(),"error while setting new cache size");
  50.           }
  51.         }
  52.  
  53.         {
  54.           struct TagItem tags[]={ASQ_CACHE_LINES, 0,
  55.                                  ASQ_CACHE_READAHEADSIZE, 0,
  56.                                  ASQ_CACHE_MODE, 0};
  57.  
  58.           if((errorcode=DoPkt(msgport, ACTION_SFS_QUERY, (LONG)&tags, 0, 0, 0, 0))!=DOSFALSE) {
  59.             VPrintf("Current cache settings: %ld lines,", &tags[0].ti_Data);
  60.             VPrintf(" %ld bytes readahead, ", &tags[1].ti_Data);
  61.             if(tags[2].ti_Data==0) {
  62.               PutStr("no copyback.\n");
  63.             }
  64.             else {
  65.               PutStr("copyback.\n");
  66.             }
  67.           }
  68.         }
  69.       }
  70.       else {
  71.         VPrintf("Couldn't find device '%s:'.\n",&arglist.name);
  72.         UnLockDosList(LDF_DEVICES|LDF_READ);
  73.       }
  74.  
  75.       FreeArgs(readarg);
  76.     }
  77.     else {
  78.       PutStr("Wrong arguments!\n");
  79.     }
  80.     CloseLibrary((struct Library *)DOSBase);
  81.   }
  82.   return(0);
  83. }
  84.