date and time created 86/01/12 18:04:59 by sam
authorSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 13 Jan 1986 10:04:59 +0000 (02:04 -0800)
committerSam Leffler <sam@ucbvax.Berkeley.EDU>
Mon, 13 Jan 1986 10:04:59 +0000 (02:04 -0800)
SCCS-vsn: sys/tahoe/stand/fastcopy.c 1.1
SCCS-vsn: sys/tahoe/stand/ls.c 1.1

usr/src/sys/tahoe/stand/fastcopy.c [new file with mode: 0644]
usr/src/sys/tahoe/stand/ls.c [new file with mode: 0644]

diff --git a/usr/src/sys/tahoe/stand/fastcopy.c b/usr/src/sys/tahoe/stand/fastcopy.c
new file mode 100644 (file)
index 0000000..2916844
--- /dev/null
@@ -0,0 +1,92 @@
+/*     fastcopy.c      1.1     86/01/12        */
+/*     fastcopy.c */
+
+#define        BSIZE   1024
+#define FACTOR 32      /* 32k bytes in one i/o */
+
+char   buffer[BSIZE * FACTOR];
+
+main()
+{
+       char            in_dev[50];
+       char            out_dev[50];
+       char            blocks[50];
+       register int    input;
+       register int    output;
+       register int    count;
+       register int    firstread = 1;
+       register int    blk_siz = BSIZE * FACTOR;
+       register int    blk_num = 0;
+       register int    read_count = 0;
+       register int    write_count = 0;
+       register int    transfers = 0;
+
+       in_dev[0] = 0;
+       out_dev[0] = 0;
+       blocks[0] = 0;
+       for(;;) {
+               /* get input and output devices */
+               printf("Source device : ");
+               gets(in_dev);
+               if((input = open(in_dev, 0)) > 0)
+                       break;
+               printf("Cannot open input file '%s'\n", in_dev);
+       }
+
+       for(;;) {
+               printf("Copy to device : ");
+               gets(out_dev);
+               if((output = open(out_dev, 1)) > 0)
+                       break;
+               printf("Cannot open output file '%s'\n", out_dev);
+       }
+
+       for(;;) {
+               printf("Number of blocks : ");
+               gets(blocks);
+               count = number(blocks);
+               if(count > 0)
+                       break;
+       }
+       printf("\nCopy %d blocks from %s to %s\n", count, in_dev, out_dev);
+       do {    
+               if ((transfers > 0) && !(transfers % 25))
+                       printf("%d blocks\n", blk_num);
+               transfers++;
+               read_count = read(input, buffer,
+                   ((count*BSIZE) > blk_siz) ? blk_siz : count*BSIZE);
+               if (firstread) {
+                       if (read_count != blk_siz) {
+                               blk_siz = read_count;
+                       }
+                       firstread = 0;
+                       printf("Block size from input = %d bytes\n", blk_siz);
+               }
+               if (read_count > 0) {
+                       if (read_count != blk_siz)
+                               printf("Short read!  Block %d: %d read, %d bytes requested\n", blk_num, read_count, blk_siz);
+                       write_count = write(output, buffer, read_count);
+                       if (write_count != read_count)
+                               printf("Short write!  Block %d: %d bytes written of %d bytes possible\n", blk_num, write_count, read_count);
+                       count -= read_count / BSIZE;
+                       blk_num += read_count / BSIZE;
+               }
+       } while((read_count > 0) && (write_count > 0) && (count > 0));
+       printf ("Total of %d blocks copied\n", blk_num);
+       close(input);
+       close(output);
+}
+
+int number (response)
+char *response;
+{
+       int     total;
+       
+       total = 0;
+       while (*response == ' ' || *response == '\t') response++;
+       while (*response >= '0' && *response <= '9') {
+               total = total * 10 + (*response - '0');
+               response++;
+       }
+       return (total);
+}
diff --git a/usr/src/sys/tahoe/stand/ls.c b/usr/src/sys/tahoe/stand/ls.c
new file mode 100644 (file)
index 0000000..59e049d
--- /dev/null
@@ -0,0 +1,83 @@
+/*     ls.c    1.1     86/01/12        */
+/*     ls.c    6.1     83/07/29        */
+
+#include "param.h"
+#include "inode.h"
+#include "dir.h"
+#include "fs.h"
+
+#include "saio.h"
+
+char line[100];
+
+main()
+{
+       int io;
+       register char   *ptr;
+       struct inode    *ip;
+
+       for(;;) {
+               line[0] = 0;
+               printf("\n\nls: ");
+               gets(line);
+               /* scan to end of line */
+               for(ptr=line; *ptr; ptr++)
+                       ;
+               /* check to see if a file was specified */
+               if(ptr == line) {
+                       printf("usage: dev(unit,0)/directory\n");
+                       continue;
+               }
+               /* do one correction first so the raw dev is not opened */
+               if(*(--ptr) == ')') {
+                       *(++ptr) = '/';
+                       *(++ptr) = '.';
+                       *(++ptr) = (char)0;
+               }
+               if(*ptr == '/') {
+                       *(++ptr) = '.';
+                       *(++ptr) = (char)0;
+               }
+               if((io = open(line, 0)) >= 0)
+                       break;
+       }
+       if((io >= NFILES+3) || (io < 3))
+               _stop("open returned corrupt file index!");
+       ip = &iob[io-3].i_ino;
+       if ((ip->i_mode & IFMT) != IFDIR) {
+               printf("%s is not a directory!\n", line);
+               _stop("");
+       }
+       if (ip->i_size == 0) {
+               printf("%s is a zero length directory!\n", line);
+               _stop("");
+       }
+       
+       ls(io);
+}
+
+ls(io)
+register io;
+{
+
+       register int    i, size;
+       register char   *dp;
+       static char     dirbuf[DIRBLKSIZ];
+
+       printf ("\nInode -> Name\n");
+       while ((size = read(io, dirbuf, DIRBLKSIZ)) == DIRBLKSIZ) {
+               for(dp = dirbuf; (dp < (dirbuf + size)) &&
+                   (dp + ((struct direct *)dp)->d_reclen) < (dirbuf + size);
+                   dp += ((struct direct *)dp)->d_reclen) {
+                       if(((struct direct *)dp)->d_ino == 0)
+                               continue;
+                       if(((struct direct *)dp)->d_reclen > 
+                           DIRSIZ(((struct direct *)dp)))
+                               continue;
+                       if(((struct direct *)dp)->d_namlen > MAXNAMLEN+1)
+                               _stop("Corrupt file name length!  Run fsck soon!\n");
+                       printf("%s -> %d\n", ((struct direct *)dp)->d_name,
+                           ((struct direct *)dp)->d_ino);
+               }
+       }
+}