home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / filesy~1 / mfs610s.zoo / fsck / io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-13  |  4.7 KB  |  185 lines

  1. /* The functions read_blocks(start,count,buff) and write_blocks(), read/write
  2.  * 'count' 1K blocks from disk starting at block 'start' into the buffer
  3.  * pointed to by 'buff' . The function init_device(name,rw) initialises the 
  4.  * device 'name' so that read_blocks() and write_blocks() use it. Since this
  5.  * is called once initially, any other machine dependent initialisation can be
  6.  * put here, if it returns non-zero then the operation failed. If 'rw' is not
  7.  * zero, write access is sought also for this device. The function set_size is
  8.  * used to tell the I/O routines the size of the filesystems being accessed,
  9.  * so any special arrangements can be made. If this function returns non-zero
  10.  * then the operation failed and the filesystem cannot be accessed.
  11.  */
  12.  
  13. #ifdef atarist
  14.  
  15. #include <stdio.h>
  16. #include <mintbind.h>
  17. #include "fs.h"
  18. #include "global.h"
  19. #include "proto.h"
  20.  
  21. int _device,_write_ok,shift;
  22.  
  23. void read_blocks(start,count,buff)
  24. long start;
  25. unsigned count;
  26. void *buff;
  27. {
  28.  
  29.     long ret;
  30.     ret=block_rwabs(0,buff,count,start,&hdinf);
  31.     if(ret) printf("Rwabs read returned %ld\n",ret);
  32. }
  33.  
  34. void write_blocks(start,count,buff)
  35. long start;
  36. unsigned count;
  37. void *buff;
  38. {
  39.     long ret;
  40. if(start==0){
  41.  printf("Illegal Write\n");
  42. return;
  43. }
  44.     if(!_write_ok)
  45.     {
  46.         printf("Internal error : Illegal write\n");
  47.         printf("Start %ld Count %d\n",(long)start,count);
  48.         return;
  49.     }
  50.     modified=1;
  51.     ret=block_rwabs(1,buff,count,start,&hdinf);
  52.     if(ret) printf("Rwabs write returned %ld\n",ret);
  53. }
  54.  
  55. /* Constants for fscntl */
  56.  
  57. #define MFS_BASE    0x100
  58. #define MFS_VERIFY    (MFS_BASE)    /* Return minixfs magic number */
  59. #define MFS_SYNC    (MFS_BASE|0x01)    /* Sync the filesystem */
  60. #define MFS_CINVALID    (MFS_BASE|0x02)    /* Invalidate cache entries */
  61. #define MFS_FINVALID    (MFS_BASE|0x03)    /* Invalidate Fileptrs */
  62. #define MFS_INFO    (MFS_BASE|0x04)    /* Get info about filesystem */
  63. #define MFS_USAGE    (MFS_BASE|0x05)    /* Get block allocation of a file */
  64. #define MFS_IMODE    (MFS_BASE|0x06)    /* Change all bits in an inode mode */
  65. #define MFS_GTRANS    (MFS_BASE|0x07) /* Get filename translation mode */ 
  66. #define MFS_STRANS    (MFS_BASE|0x08) /* Set filename translation mode */
  67. #define MFS_PHYS    (MFS_BASE|0x09) /* Get physical partition info */
  68. #define MFS_IADDR    (MFS_BASE|0x0a) /* Get start address of minixfs */
  69. #define MFS_UPDATE    (MFS_BASE|0x0b) /* Update daemon controls */
  70. #define MFS_MOUNT    (MFS_BASE|0x0c) /* Mount a filesystem */
  71. #define MFS_UMOUNT    (MFS_BASE|0x0d) /* Umount a filesystem */
  72.  
  73. #define MFS_MAGIC    0x18970431    /* Magic number from MFS_VERIFY */
  74.  
  75.  
  76. int init_device(name,rw)
  77. char *name;
  78. int rw;
  79. {
  80.     long err;
  81.     struct 
  82.     {
  83.         long start;
  84.         long finish;
  85.         char shadow;
  86.         char scsiz;
  87.     } pp;
  88.     _device=(name[0]-'A') & ~32;
  89.     if( (_device < 0) || (_device > 32) || name[1]!=':' )
  90.     {
  91.         fprintf(stderr,"Invalid drive name %s\n",name);
  92.         return 1;
  93.     }
  94.  
  95.     if( Dcntl(MFS_VERIFY,name,&err) || err!=MFS_MAGIC )
  96.     {
  97.         fprintf(stderr,"Not recognised Minixfs partition or Minixfs not running\n");
  98.         if(!ask("Continue?","Ignored")) return 1;
  99.     }
  100.  
  101.     if( !Dcntl(MFS_PHYS,name,&pp) && pp.start!=-1)
  102.     /* Is this a physical partition ? */
  103.     {
  104.         long tstack;
  105.         hdinf.start=pp.start;
  106.         hdinf.size=pp.finish-hdinf.start+1;
  107.         hdinf.scsiz=pp.scsiz;
  108.         hdinf.drive=_device;
  109.         hdinf.major = pp.shadow;
  110.         (void)Getbpb(_device);     /* Satisfy disk changes */
  111.         hdinf.rwmode = RW_PHYS;
  112.         tstack=Super(0l);
  113.         if(init_icd()==2)
  114.         {
  115.             Super(tstack);
  116.             fprintf(stderr,"Can't patch ICD bug\n");
  117.             return 1;
  118.         }
  119.         Super(tstack);
  120.  
  121.         if(hdinf.start > 0xfff0)
  122.         {
  123.             if(no_plrecno(hdinf.major)) return 1;
  124.             hdinf.rwmode |= RW_LRECNO;
  125.         }
  126.     }
  127.     else if( (err=get_hddinf(_device,&hdinf,0)) ) 
  128.     {
  129.         fprintf(stderr,"Drive %s %s\n",name,hdd_err[err]);
  130.         return 1;
  131.     }
  132.  
  133.     if(rw) _write_ok=1;
  134.  
  135.     Dcntl(MFS_UPDATE,name,1);    /* Suspend update */
  136.     /* Sync the filesytem and lock the device */
  137.     if( Dcntl(MFS_SYNC,name,0) || Dlock(1,_device) )
  138.     {
  139.         fprintf(stderr,"Couldn't sync or lock device %s.\n",name);
  140.         if(ask("Continue?","Ignored"))
  141.             fprintf(stderr,"Warning: reboot after running.\n");
  142.         else
  143.         {
  144.             close_device();
  145.             return 1;
  146.         }
  147.     }
  148.     return 0;
  149. }
  150.  
  151. void close_device()
  152. {
  153.     extern char *drvnam;
  154.     (void) Dlock(0,_device);    /* Unlock drive */
  155.     Dcntl(MFS_UPDATE,drvnam,2);        /* Restart update */
  156. }
  157.  
  158. int set_size(nblocks)
  159. long nblocks;
  160. {
  161.     long err,tsize;
  162.  
  163.     tsize=hdinf.size;
  164.     err = set_lrecno(&hdinf,nblocks);
  165.  
  166.     if(err)
  167.     {
  168.         fprintf(stderr,"set_size %s\n",hdd_err[err]);
  169.         return err;
  170.     }
  171.  
  172.     if( !tsize && no_size)
  173.     {
  174.         if( (err=get_size(hdinf.drive,&tsize)) ) 
  175.             fprintf(stderr,"get_size: warning %s\n",size_err[err]);
  176.         else if( tsize!=nblocks ) fprintf(stderr,"Warning filesystem "
  177.                  "size %ldK, Expected %ldK\n",nblocks,tsize);
  178.     }
  179.  
  180.     return 0;
  181.  
  182. }
  183.  
  184. #endif
  185.