home *** CD-ROM | disk | FTP | other *** search
/ No Fragments Archive 12: Textmags & Docs / nf_archive_12.iso / MAGS / SOURCES / ATARI_SRC.ZIP / atari source / AHDI / TTFHDX / ASSIST.C < prev    next >
Encoding:
C/C++ Source or Header  |  2001-02-09  |  2.2 KB  |  92 lines

  1. /* assist.c */
  2. /* 
  3.  * 14-Sep-1989    ml.    Use Rwabs() instead of hread() and hwrite().
  4.  *            Will handle both SCSI and ACSI drives.
  5.  */
  6.  
  7. #include <osbind.h>
  8. #include <obdefs.h>
  9. #include "fhdx.h"
  10. #include "define.h"
  11. #include "part.h"
  12. #include "bsl.h"
  13. #include "addr.h"
  14. #include "lrwabs.h"
  15.  
  16.  
  17. #define    MBUFSIZ        32        /* #blocks in read buffer */
  18.  
  19. extern SECTOR *badbuf;
  20.  
  21.  
  22. /* 
  23.  * Critical Error Handler:
  24.  *    Always return -1L
  25.  *
  26.  */
  27. long
  28. crerr()
  29. {
  30.     return -1L;
  31. }
  32.  
  33.  
  34. /*
  35.  * Fixup bad sector entries in the FATs;
  36.  */
  37. fixbadcls(ldev, fat0, fatsiz, data, nbad, sratio)
  38. int ldev;        /* logical device */
  39. SECTOR fat0, data;    /* log starting sector of FAT0 and data */
  40. WORD fatsiz;        /* FAT size in # log sectors */
  41. int nbad;        /* # bad sectors */
  42. WORD sratio;        /* log sector size : phys sector size */
  43. {
  44.     long clno, numcl;
  45.     int i, pdev;
  46.     WORD *buf;
  47.     SECTOR fat1;    /* physical starting sector# of 2nd FAT */
  48.     SECTOR pstart;    /* physical starting sector# of partition */
  49.     SECTOR pdata;    /* physical starting sector# of data */
  50.     extern SECTOR logstart();
  51.     extern LOGMAP logmap[];
  52.     int ret;
  53.     
  54.     if((buf = (WORD *)Malloc((long)(fatsiz*sratio) << 9)) <= 0)
  55.         return err(nomemory);
  56.         
  57.     pdev = ldev;
  58.     fat0 *= sratio;    /* FAT0 starting sector # (in # phys sector) */
  59.     fatsiz *= sratio;    /* FAT size in # phys sector */
  60.     
  61.     /* find phys dev # and FAT0 phys starting sector # */
  62.     log2phys(&pdev, &fat0);
  63.     pstart = logstart(ldev);
  64.     pdata = (data * sratio) + pstart;
  65.     numcl = ((logmap[ldev-'C'].lm_siz / sratio) - data) >> 1;
  66.             
  67.     ret = OK;    /* Assume everything is going to be OK */
  68.     
  69.     if (Lrwabs(PHYSREAD, buf, fatsiz, fat0, pdev+2) != 0) {
  70.         ret = err(fatread);
  71.         goto fixend;
  72.     }
  73.  
  74.     for (i = 0; i < nbad; ++i) {
  75.         if ((clno = ((*(badbuf+i)-pdata)/sratio)>>1) >= numcl)
  76.             continue;
  77.     *(buf+clno+2) = 0xf7ff;        /* 0xfff0 in 8086-land */
  78.     }
  79.  
  80.     /* find phys starting sector # of FAT1 */
  81.     fat1 = fat0 + fatsiz;
  82.     
  83.     if (Lrwabs(PHYSWRT, buf, fatsiz, fat0, pdev+2) != 0 ||
  84.         Lrwabs(PHYSWRT, buf, fatsiz, fat1, pdev+2) != 0) {
  85.         ret = err(fatwrite);
  86.     }
  87.     
  88. fixend:
  89.     Mfree((long)buf);
  90.     return ret;
  91. }
  92.