home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / diskutil / tapebios / restore.c < prev    next >
C/C++ Source or Header  |  1993-08-06  |  3KB  |  143 lines

  1. /* Restore a partition from tape             */
  2. /* This program is part of the TapeBIOS distribution    */
  3. /* Written by Alan Hourihane 1992            */
  4. /* Needs TapeBIOS driver loaded                */
  5.  
  6. #include <osbind.h>
  7. #include <stdio.h>
  8. #include "tapebind.h"
  9.  
  10. extern long get_cookie();
  11. extern int atoi();
  12. extern int strcmp();
  13. extern void strncpy();
  14. extern void exit();
  15. extern int strlen();
  16. extern char toupper();
  17.  
  18. #define DMAMAX        (long)(64*1024)        /* 64Kbyte buffer */
  19. #define DUMPNAME    20
  20. #define NUMLEN        10
  21. #define WABS        1
  22. #define IDPOS        64
  23.  
  24. typedef struct {
  25.     short    recsiz;
  26.     short    clsiz;
  27.     short    clsizb;
  28.     short    rdlen;
  29.     short    fsiz;
  30.     short    fatrec;
  31.     short    datrec;
  32.     short    numcl;
  33.     short    bflags;
  34. } bpb;
  35.  
  36. int
  37. main(argc, argv)
  38. int argc;
  39. char *argv[];
  40. {
  41.     int spacing;
  42.     long maxspace;
  43.     char drive;
  44.     char sname[DUMPNAME];
  45.     char *name;
  46.     long numsectors;
  47.     int sectorsize;
  48.     char buffer[512];
  49.     char *obuf;
  50.     int status;
  51.     int s,n;
  52.     int nscts;
  53.     int drivelist;
  54.  
  55.     printf("Restore Disk Drives from Tape. Copyright 1992, A. Hourihane.\r\n");
  56.     
  57.     if (argc == 1) {
  58.         printf("Usage: %s [destination drives] [dumpname_a] [dumpname_b] [etc..]\r\n",argv[0]);
  59.         printf("e.g.   %s fg boot apps\r\n",argv[0]);
  60.         exit(1);
  61.     }
  62.  
  63.     if (!get_cookie("TAPE")) {
  64.         printf("TapeBIOS is not installed.\r\n");
  65.         exit(1);
  66.     }
  67.     
  68.     status = Tload(0L);
  69.     status = Trewind();
  70.  
  71.     for (drivelist=0;drivelist<strlen(argv[1]);drivelist++) {
  72.     strncpy(sname,argv[2+drivelist],DUMPNAME);
  73.     for (;;) {
  74.         status = Tread(buffer,1);
  75.         if (status != 0) {
  76.             fprintf(stderr, "Error reading header block from tape\r\n");
  77.             status = Trewind();
  78.             status = Tunload(0L);
  79.             exit(4);
  80.         }
  81.         if (strcmp("DUMPFORMAT",&buffer[IDPOS])) {
  82.             printf("Tape not in DUMP format");
  83.             status = Trewind();
  84.             status = Tunload(0L);
  85.             exit(1);
  86.         }
  87.         
  88.         drive = toupper(argv[1][drivelist])-'A';
  89.         sectorsize = atoi(&buffer[1]);
  90.         numsectors = atoi(&buffer[1+NUMLEN]);
  91.         name = &buffer[1+NUMLEN*2];
  92.         if (strcmp(name,sname)==0) break;
  93.         for (spacing=1;spacing<=(sectorsize/512);spacing++)
  94.             status = Tspace(numsectors);
  95.     }
  96.  
  97.     maxspace = Malloc(-1L);
  98.     if (maxspace < DMAMAX) {
  99.         fprintf(stderr, "Not enough memory for buffer allocation.");
  100.         exit(3);
  101.     }
  102.      maxspace = DMAMAX;
  103.     obuf=(char*)Malloc(maxspace);
  104.     if (!obuf) {
  105.         fprintf(stderr, "Cannot malloc buffer\r\n");
  106.         exit(3);
  107.     }
  108.     if ((long)obuf&1) obuf++;    /* Word align it */
  109.     nscts = maxspace/sectorsize;
  110.  
  111.     printf("Restoring: Source drive: %c, Sector size: %d bytes, Drive size = %.1fK\r\n",buffer[0],sectorsize,(float)numsectors*(float)sectorsize/1024);
  112.     printf("       Destination drive: %c, Dump name: %s\r\n",drive+'A',name);
  113.  
  114.  
  115.     s = 0;
  116.     do {
  117.         n = (numsectors>nscts ? nscts : numsectors);
  118.         status = Tread(obuf,n*(sectorsize/512));
  119.         printf("Restoring: %dK\r", (s*sectorsize/1024));
  120.         if (status != 0) {
  121.             fprintf(stderr, "\nError reading from tape.\r\n\r\n");
  122.             status = Trewind();
  123.             status = Tunload(0L);
  124.             exit(4);
  125.         }
  126.         status = Rwabs(WABS, &obuf[0], n, s, (int)drive);
  127.         if (status < 0) {
  128.             fprintf(stderr, "\nError %d writing to drive\r\n\r\n",status);
  129.             status = Trewind();
  130.             status = Tunload(0L);
  131.             exit(4);
  132.         }
  133.         s+=n;
  134.         numsectors-=n;
  135.     } while(numsectors>0);
  136.  
  137.     }
  138.     printf("\r\n");
  139.     status = Trewind();
  140.     status = Tunload(0L);
  141.     return 0;
  142. }
  143.