TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: All
from: Frank Adam
date: 1996-10-19 12:19:02
subject: [5/6] Fat

>>> Part 5 of 6...

 {
  printf("\nOnly one FAT on this drive .");
  return 0;
  }

 startsector = ((fatnum -1) * dpb.SecPerFat) + 1;
 endsector = (dpb.SecPerFat * fatnum) + 1;
 fat = (UCHAR*)calloc(dpb.Bpersec,sizeof(UCHAR));
  if(NULL == fat) {printf("\nNot enough memory");return 0;}

 if(mode == FATSAVE)
 {
  sprintf(fname,"fat%c.dat\0",dpb.Driveno + 'A');
   out = fopen(fname,"wb");
   if(out == NULL) {perror("\nError opening file");return 0;}
  }
 printf("\n");

 for(i = startsector ;i < endsector;i++)
 {
  if (AbsRead(dpb.Driveno,i,1 , fat) != 1)
  {perror("\nDisk read error"); return 0;}

 if(mode == FATSAVE || PrintFlag == 1)
  {
   printf("\rSector %02d Read OK....",i);
   if(!PrintFlag)
    for(j = 0; j < dpb.Bpersec;j++) p += fwrite(&fat[j],1,1,out);

    printf("Written %03d sectors OK",i,p);
    p = 0;
    }

  if(mode == FATSHOW) ShowSector(i,fat);
 }
 free(fat);
 if(mode == FATSAVE )
 {
  fclose(out);
  printf("\nFat saved OK to %s.",fname);
  }
 else
  printf("\nEnd. Press any key to exit...");

 while(!GetKey());
 return 1; /* phew */
 }

void ShowMedia( void ) /* just a bit of show off :o) */
{
 printf("\nDrive %c media type = ",toupper(dpb.Driveno + 'A'));
 switch((int)dpb.MediaId)
 {
  case 0xfff0 : if(dpb.SecPerFat > 4 && dpb.SecPerFat < 10)
     printf("Probably 1.44M 3.5 floppy");
       else printf("Unrecognized device");
     break;
  case 0xfff8 : printf("Hard drive");break;
  case 0xfff9 : printf("DS 1.2M 5.25 floppy");break;
  case 0xfffa : printf("HP ROM device");break;
  case 0xfffc : printf("SS 9S/T 180K floppy");break;
  case 0xfffd : printf("DS 9S/T 360K floppy");break;
  case 0xfffe : printf("SS 8S/T 160K floppy");break;
  case 0xffff : printf("DS 8S/T 320K floppy");break;
  default   : printf("Unrecognized device");break;
  }
 printf("\nSectors per fat  = %d",dpb.SecPerFat);
 printf("\nBytes per sector = %d",dpb.Bpersec);
 printf("\nNumber of fats   = %d",dpb.NumFats);
 printf("\nFat System       = ");
 printf(dpb.MaxClust > 0xffb ? "16 Bit" : "12 Bit");
if((unsigned) dpb.MediaId == 0xfff8)
 printf("\nAvailable Space  = %ld bytes",
    (long) (dpb.FreeClus << dpb.Shft) * (long)dpb.Bpersec);
 }

/* Note: i found, a 1.4M can return 0xfff9 if disk/x-copied from a 1.2M */

int AbsRead(int AbsRdrive,DWORD sector,WORD numsecs,UCHAR *buf)
{
 union REGS inregs,outregs;
 struct SREGS sregs;
 drp.sector = sector;
 drp.numsectors = numsecs;
 drp.transferto = (DWORD)buf;
 inregs.h.al = AbsRdrive;
 inregs.x.cx = 0xffff;
 inregs.x.bx = FP_OFF(&drp);
 sregs.ds = FP_SEG(&drp);
 int86x(0x25,&inregs,&outregs,&sregs);
 if(outregs.x.cflag) return 0;
 return 1;
 }

/*
** !!! to newbies and not so sures, DO NOT muck around with

 >>> Continued to next message...
___ Blue Wave/DOS v2.21

---
* Origin: Melbourne PC User Group BBS (3:632/309)
SEEN-BY: 633/267 270
@PATH: 632/309 107 635/503 50/99 635/728 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.