home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 200-299 / ff284.lzh / FileTest / filetest.c < prev    next >
C/C++ Source or Header  |  1989-11-27  |  6KB  |  189 lines

  1. /****************************************
  2.   mytest.c
  3.  
  4.   By Stephen Vermeulen 1989
  5.  
  6.   Placed in the public domain, do with as
  7.   you please.
  8.  
  9.   This routine is used to recursively decend the file system tree from
  10.   a specified directory location, reading the files into memory
  11.   (if they will fit) as it goes.  I wrote this to try to isolate a
  12.   problem I was having with a GVP030 board when used with SETCPU's
  13.   FASTROM option and a SCSI hard disk interfaced with a 2090 card.
  14.  
  15.   Dave H:
  16.  
  17.   This program will walk the directory tree of a disk allocating
  18.   and freeing memory buffers and reading in each file as it goes.
  19.   By selecting the "mode" level you can specify which of these
  20.   operations will be done.  As well you can specify several
  21.   delays to be taken between the Open/Read/Close calls.  I tested
  22.   this in two modes:
  23.  
  24.     1) SETCPU CACHE BURST
  25.     2) SETCPU NOCACHE NOBURST FASTROM
  26.  
  27.   The first of these (caches on (both inst and data) and no fastrom)
  28.   worked fine in all tests, the second (nocaches, but fastrom is on)
  29.   only worked with modes 0, 1 and 2, but when mode 3 was used it would
  30.   hang (cli/mouse movement lock up, but NEVER a guru or task held) at
  31.   some point in the file tree.  By changing the first delay parameter
  32.   (del) you can change where in the file tree the hang occurs (I
  33.   tested values of 0, 10, 30, 40, 50 and 100) however the position of
  34.   the hang is not predictable for different delays (the hang occurred
  35.   at an earlier point with delay == 100 than with and other delay). By
  36.   changing the second delay parameter it is possible to get the system
  37.   to work (see below). When I included the "#ifdef TEST" lines it
  38.   appeared that the Read() call is where the lockup takes place.
  39.  
  40.      mytest c2: 3 0  5   hung
  41.      mytest c2: 3 0 25   hung
  42.      mytest c2: 3 5 25   worked sometimes, hung other times
  43.      mytest c2: 3 25 5   hung
  44.      mytest c2: 3 25 0   hung
  45.      mytest c2: 3 5  5   hung
  46.      mytest c2: 3 0  0   hung
  47.  
  48.   Perhaps the system is returning from the Open() call too soon and
  49.   the Read() then gets confused by an incorrectly/incompletely
  50.   opened file?  It also appears that the system is returning from the
  51.   Read() call before it completes since the scanning (files/sec)
  52.   is faser for the "3 25 5" case than the "3 5 25" case.
  53. *****************************************/
  54.  
  55. #include <stdio.h>
  56. #include <libraries/dos.h>
  57. #include <exec/memory.h>
  58. #include <workbench/workbench.h>
  59. #include <functions.h>
  60. #include <stdio.h>
  61.  
  62. long del, del2;
  63.  
  64. ScanDir(lock, dirname, mode)
  65. ULONG lock;
  66. char *dirname;
  67. int mode;
  68. {
  69.   ULONG tlock;
  70.   char tdir[256], t;
  71.   struct FileInfoBlock *fib;
  72.   ULONG in;
  73.   UBYTE *mem;
  74.   long size;
  75.  
  76.   fib = (struct FileInfoBlock *) AllocMem((long) sizeof(struct FileInfoBlock), 0L);
  77.   if (fib)
  78.   {
  79.     if (Examine(lock, fib))
  80.     {
  81.       while (ExNext(lock, fib))
  82.       {
  83.         strcpy(tdir, dirname);
  84.         if (strlen(tdir))
  85.         {
  86.           t = tdir[strlen(tdir) - 1];
  87.           if ((t != '/') && (t != ':')) strcat(tdir, "/");
  88.         }
  89.         strcat(tdir, fib->fib_FileName);
  90.         if (fib->fib_DirEntryType > 0)
  91.         {
  92.           tlock = (ULONG) Lock(tdir, ACCESS_READ);
  93.           ScanDir(tlock, tdir, mode);  /** it was a directory so recurse **/
  94.           UnLock(tlock);
  95.         }
  96.         else
  97.         {
  98.           if (mode > 0)
  99.           {
  100.             size = fib->fib_Size;
  101.             mem = (UBYTE *) AllocMem(size, MEMF_PUBLIC);
  102.             if (mem)
  103.             {
  104.               if (mode > 1)
  105.               {
  106.                 in = (ULONG) Open(tdir, MODE_OLDFILE);
  107.                 if (in)
  108.                 {
  109.                   printf("%s %ld\n", tdir, size);
  110.                   if (del2) Delay(del2);
  111.                   if (mode > 2)
  112.                   {
  113. #ifdef TEST
  114.                     putchar('-'); fflush(stdout); Delay(5L);
  115. #endif
  116.                     Read(in, mem, size);
  117. #ifdef TEST
  118.                     putchar('-'); fflush(stdout); Delay(5L);
  119. #endif
  120.                   }
  121.                   if (del) Delay(del);
  122.                   Close(in);
  123.                 }
  124.               }
  125.               else
  126.                 printf("mem only %s %ld\n", tdir, size);
  127.               FreeMem(mem, size);
  128.             }
  129.           }
  130.           else
  131.             printf("%s\n", tdir);
  132.         }
  133.       }
  134.     }
  135.     FreeMem(fib, (long) sizeof(struct FileInfoBlock));
  136.   }
  137. }
  138.  
  139. main(argc, argv)
  140. int argc;
  141. char *argv[];
  142. {
  143.   ULONG root;
  144.   struct FileInfoBlock *fib;
  145.   int mode;
  146.  
  147.   fib = (struct FileInfoBlock *) AllocMem((long) sizeof(struct FileInfoBlock), 0L);
  148.   if (fib)
  149.   {
  150.     if ((argc != 3) && (argc != 4) && (argc != 5))
  151.     {
  152.       puts("Syntax:  mytest directory mode [delay1 [delay2]] ");
  153.       puts("mode == 0 for directory scan only");
  154.       puts("     == 1 for directory scan plus mem alloc/free");
  155.       puts("     == 2 for dir scan plus alloc/open/close/free");
  156.       puts("     == 3 for dir scan plus alloc/open/read/close/free");
  157.       puts("if delay is specified (n/50 secs) the system will delay defore");
  158.       puts("closing the file.  Delay2 is the delay after opening the file");
  159.       puts("before a read operation will be attempted.");
  160.     }
  161.     else
  162.     {
  163.       mode = atoi(argv[2]);
  164.       if (argc == 4)
  165.       {
  166.         del = atoi(argv[3]);
  167.       }
  168.       else
  169.         del = 0;
  170.       if (argc == 5)
  171.       {
  172.         del2 = atoi(argv[4]);
  173.       }
  174.       else
  175.         del2 = 0;
  176.  
  177.       root = (ULONG) Lock(argv[1], ACCESS_READ);
  178.       if (Examine(root, fib))
  179.       {
  180.         if (fib->fib_DirEntryType > 0)
  181.           ScanDir(root, argv[1], mode);
  182.       }
  183.       UnLock(root);
  184.     }
  185.     FreeMem(fib, (long) sizeof(struct FileInfoBlock));
  186.   }
  187. }
  188.  
  189.