Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » Data File StructureRSS Feeds

Program of disk editor

Posted By: Easy Tutor     Category: C++ Programming     Views: 3302

Write a program that can perform below operations.

1) Display floppy drive info
2) Display Hard disk info
3) Edit floppy sector
4) Edit hard disk sector
5) File mode
6) Save to file
7) Write from file
8) Help
9) Disclaimer

Code for Program of disk editor in C++ Programming

#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <dir.h>
#include <bios.h>
#include <ctype.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>

#define Esc 0x11B
#define Right 0x4D00
#define Left 0x4B00
#define Up 0x04800
#define Down 0x5000
#define Pgdwn 0x5100
#define Pgup 0x4900

#define F1 0x3B00
#define F2 0x3C00
#define F3 0x3d00
#define F4 0x3e00
#define F5 0x3f00
#define F6 0x4000
#define F7 0x4100

struct boot
   {
   unsigned char code[3] ;
   unsigned char system_id[8] ;
   int bytes_per_sec ;
   char sec_per_clus ;
   int res_sec ;
   char fat_copies ;
   int root_dir_entry ;
   unsigned int no_sects ;
   unsigned char format_id ;
   int sec_per_fat ;
   int sec_per_trk ;
   int no_sides ;
   int no_sp_res_sect ;
   unsigned char rest_code[482] ;
    } ;
struct boot b ;

struct ffblk ffblk;
unsigned char buff[512],temp[512];
char fl[512][14];
int drive,head,track,sector,lsect,maxc,i,i5=0,i6=0,x,y,a,indicator,of=0,ftp=1;
FILE *fp1;
FILE *fs;
staticint x1=2;

void update(int i);
void filemode();
void dispfl(char *fl);
void help();
void part();
void disclam();
void chdr(char a);
char *getascii (unsigned int in_data [], int off_start, int off_end);

void lay()
 {
  int p,q;
gotoxy(1,1);
textcolor(15);
cprintf("                          Disk Editor(version 2.0)                             ");
for(q=2;q<=24;q++)
{gotoxy(1,q);
cprintf("%c",186);
gotoxy(80,q);
cprintf("%c",186);
}
for(p=2;p<80;p++)
{
gotoxy(p,24);
cprintf("%c",205);}
gotoxy(80,24);
cprintf("%c",188);
gotoxy(1,24);
cprintf("%c",200);
for(p=2;p<25;p++)
{gotoxy(p,1);
cprintf("%c",205);}
for(p=53;p<80;p++)
{gotoxy(p,1);
cprintf("%c",205);}
gotoxy(1,1);
cprintf("%c",201);
gotoxy(80,1);
cprintf("%c",187);
     }



void hdinfo ()
{
  unsigned int dd [256]; /* DiskData */
  unsigned int dd_off;   /* DiskData offset */
  unsigned int loop=0;     /* Loop variable */int num_drv;           /* Number of Hard disks */
  union REGS registers;  /* Used for Interrupt for BIOS data */
  unsigned int bios_cyl [2], bios_head [2], bios_sec [2];  /* Cylinders, Heads, Sectors *//* Get IDE Drive info */while (inp (0x1F7) != 0x50)
    ;/* Wait for controller not busy */
      outp (0x1F6, 0xA0 ); /* Get first drive */
      outp (0x1F7, 0xEC);

      /* Get drive info data */while (inp (0x1F7) != 0x58)
    ;  /* Wait for data ready */for (dd_off = 0; dd_off != 256; dd_off++) /* Read "sector" */
    dd [dd_off] = inpw (0x1F0);
     /* Get BIOS drive info */
      registers.h.ah = 0x8;            /* Get drive info */
      registers.h.dl = 0x80 ;    /* Drive is 80H for Disk 0, 81H for Disk 1 */
      int86 (0x13, &registers, &registers);
      if (! registers.x.cflag)   /* All OK if carry not set */
    {
      bios_head [loop] = registers.h.dh + 1; /* Heads are from 0 */
      bios_sec [loop] = registers.h.cl & 0x3F; /* sec is bits 5 - 0 */
      bios_cyl [loop] = ((registers.h.cl & 0xC0) << 2) + registers.h.ch + 2; /* +1 because starts from 0 and +1 for FDISK leaving one out */
    }
      gotoxy(2,2);
      printf ( "  DRIVE %d:\n", loop);
      gotoxy(2,3);
      printf ( "  Model Number______________________: %s\n", getascii (dd, 27, 46));
      gotoxy(2,4);
      printf ( "  Serial Number_____________________: %s\n", getascii (dd, 10, 19));
      gotoxy(2,5);
      printf ( "  Controller Revision Number________: %s\n\n", getascii (dd, 23, 26));
      gotoxy(2,7);
      printf ( "  Able to do Double Word Transfer___: %6s\n", (dd [48] == 0 ? "No" : "Yes"));
      gotoxy(2,8);
      printf ( "  Controller type___________________:   %04X\n", dd [20]);
      gotoxy(2,9);
      printf ( "  Controller buffer size (bytes)____: %6u\n", dd [21] * 512);
      gotoxy(2,10);
      printf ( "  Number of ECC bytes transferred___: %6u\n", dd [22]);
      gotoxy(2,11);
      printf ( "  Number of sectors per interrupt___: %6u\n\n", dd [47]);
      gotoxy(2,13);
      printf ( "  Hard Disk Reports\n");
      gotoxy(2,14);
      printf ( "  Number of Cylinders (Fixed)_______: %6u\n", dd [1]);
      gotoxy(2,15);
      printf ( "  Number of Heads___________________: %6u\n", dd [3]);
      gotoxy(2,16);
      printf ( "  Number of Sectors per Track_______: %6u\n\n", dd [6]);
      gotoxy(2,18);
      printf ( "  BIOS Reports\n");
      gotoxy(2,19);
      printf ( "  Number of Cylinders_______________: %6u\n", bios_cyl [loop]);
      gotoxy(2,20);
      printf ( "  Number of Heads___________________: %6u\n", bios_head [loop]);
      gotoxy(2,21);
      printf ( "  Number of Sectors per Track_______: %6u\n\n", bios_sec [loop]);
      gotoxy(49,23);
      printf ( "press a key to continue....");
      getch ();
    part();
    }

char *getascii (unsigned int in_data [], int off_start, int off_end)
{
  staticchar ret_val [255];
  int loop, loop1;

  for (loop = off_start, loop1 = 0; loop <= off_end; loop++)
    {
      ret_val [loop1++] = (char) (in_data [loop] / 256);  /* Get High byte */
      ret_val [loop1++] = (char) (in_data [loop] % 256);  /* Get Low byte */
    }
  ret_val [loop1] = '\0';  /* Make sure it ends in a NULL character */return (ret_val);
}

void part()
{
struct partition
{
unsigned char bootable ;   unsigned char start_side ;
unsigned int start_sec_cyl ;   unsigned char parttype ;
unsigned char end_side ;   unsigned int end_sec_cyl ;
unsigned long part_beg ;   unsigned long plen ;
} ;

struct part
{
unsigned char master_boot[446] ;
struct partition pt[4] ;
int lasttwo ;
} ;

struct part p ;
int p1,q;
unsigned int s_sec, s_trk, e_sec, e_trk, i, t1, t2 ;
char type[20], boot[5] ;
clrscr();
biosdisk ( 2, 0x80, 0, 0, 1, 1, &p ) ;
printf("\n  Part.   Boot     Startlocation       EndLocation    Relative sec   Number of");
printf("\n  Type    Side   Cyl  Sector  Side     Cyl   Sector  begin   end     Sectors\n");

for ( i = 0 ; i <= 3 ; i++ )
{
if ( p.pt[i].bootable == 0x80 )
strcpy ( boot, "Yes" ) ;
else
strcpy ( boot, "No" ) ;

switch ( p.pt[i].parttype )
{
case 0 :
    strcpy ( type, "Unused" ) ;
    break ;
case 1 :
    strcpy ( type, "12-Bit" ) ;
    break ;
case 2 :
    strcpy ( type, "Xenix" ) ;
    break ;
case 4 :
    strcpy ( type, "16-Bit" ) ;
    break ;
case 5 :
    strcpy ( type, "Extended" ) ;
    break ;
case 6 :
    strcpy ( type, "Huge" ) ;
    break ;
default :
     strcpy ( type, "Unknown" ) ;
     break ;
}

s_sec = ( p.pt[i].start_sec_cyl & 0x3f )  ;
t1    = ( p.pt[i].start_sec_cyl & 0xff00 ) >> 8 ;
t2    = ( p.pt[i].start_sec_cyl & 0x00c0 ) << 2 ;
s_trk = t1 | t2 ;
e_sec = ( p.pt[i].end_sec_cyl & 0x3f )  ;
t1    = ( p.pt[i].end_sec_cyl & 0xff00 ) >> 8 ;
t2    = ( p.pt[i].end_sec_cyl & 0x00c0 ) << 2 ;
e_trk = t1 | t2 ;
printf ( "\n %6s  %3s", type, boot ) ;
printf ( "      %d %6d     %d", p.pt[i].start_side, s_trk,s_sec ) ;
printf ( "   %7d%6u %8u ", p.pt[i].end_side,  e_trk, e_sec ) ;
printf ( "%8lu%10lu", p.pt[i].part_beg,  p.pt[i].plen ) ;
}
lay();
for(p1=2;p1<80;p1++)
{
gotoxy(p1,4);
printf("%c",205);
gotoxy(p1,9);
printf("%c",205);
}
for(q=2;q<9;q++)
{
gotoxy(9,q);
printf("%c",179);
gotoxy(16,q);
printf("%c",179);
gotoxy(37,q);
printf("%c",179);
gotoxy(53,q);
printf("%c",179);
gotoxy(68,q);
printf("%c",179);
}
for(q=5;q<9;q++)
{ gotoxy(22,q);
printf("%c",179);
gotoxy(29,q);
printf("%c",179);
gotoxy(45,q);
printf("%c",179);
gotoxy(59,q);
printf("%c",179);
}
gotoxy(37,9);
printf("%c",207);
gotoxy(29,9);
printf("%c",207);
gotoxy(22,9);
printf("%c",207);
gotoxy(16,9);
printf("%c",207);
gotoxy(9,9);
printf("%c",207);
gotoxy(45,9);
printf("%c",207);
gotoxy(53,9);
printf("%c",207);
gotoxy(59,9);
printf("%c",207);
gotoxy(68,9);
printf("%c",207);

gotoxy(37,4);
printf("%c",216);
gotoxy(29,4);
printf("%c",209);
gotoxy(22,4);
printf("%c",209);
gotoxy(16,4);
printf("%c",216);
gotoxy(9,4);
printf("%c",216);
gotoxy(45,4);
printf("%c",209);
gotoxy(53,4);
printf("%c",216);
gotoxy(59,4);
printf("%c",209);
gotoxy(68,4);
printf("%c",216);
gotoxy(25,12);
printf("Press any key to continue....");
getch();
}


display(int i4)
{
  int r,c,a,i=0,p,q;
  unsigned char ch;
    textbackground(4);
    clrscr();
   textcolor(11);
   if(drive==0)
   cprintf("Relative sector displayed is %06d",lsect);
   elseif(drive==0x80)
   cprintf("Head:%03d, Track:%06d, Sector:%08d",head,track,sector);
   elseif(drive==405)
   { if(i6==0)
   {gotoxy(1,1);
   cprintf("File=%s",fl[i4]);
   fread(buff,512,1,fs);}
   gotoxy(1,1);
   cprintf("File=%s",fl[i4]);
      }
   textcolor(14);
   printf("\n");
   gotoxy(21,2);
   cprintf("Hex codes");
   textcolor(11);
  for(q=2;q<20;q++)
   {
    gotoxy(q,2);
    cprintf("%c",205);
      }
  for(q=31;q<=54;q++)
   {
    gotoxy(q,2);
    cprintf("%c",205);}
    gotoxy(1,2);
    cprintf("%c",201);
  for(q=3;q<=24;q++)
   {
    gotoxy(1,q);
    cprintf("%c",186);
      }
  for(q=3;q<=24;q++)
   {
    gotoxy(55,q);
    cprintf("%c",186);
     }
  gotoxy(55,2);
  cprintf("%c",203);
   for(q=56;q<61;q++)
     {
      gotoxy(q,2);
      cprintf("%c",205);
     }
   textcolor(14);
   cprintf(" Ascii values ");
   textcolor(11);
      for(q=75;q<=80;q++)
    {
     gotoxy(q,2);
     cprintf("%c",205);
        }
    for(r=3;r<=24;r++)
      {
       for(c=2;c<=55;c+=2)
    {
     ch=buff[i];
     gotoxy(c,r);
     textcolor(15);
     cprintf("%02x",ch);
     gotoxy(57+(i%24),r);
      if(ch==7||ch==8||ch==13||ch==10)
        printf(" ");
      else
        {
          cprintf("%c",ch);
           }
      i++;
       if(i%4==0)
         c++;
       if(i==512)
         {
          maxc=c+1;
          break;
        }
          }
        }
    textcolor(11);
    printf("\n");
    if(drive==0)
    {cprintf("F1-Restore;F2-Save changes,F5-Jump to sec,Pgdwn-Next sec,Pgup-Prev sec,Esc-Exit");
    gotoxy(52,1);
    cprintf("F3-Edit hex,F4-Edit ascii ");}
    elseif(drive==0x80)
    {
    cprintf("F1-Restore,F2-Save,F3-Edit hex,F4-Edit ascii,F5-Head,F6-Track,F7-Sector");
    gotoxy(41,1);
    cprintf("Pg up-Prev sec,Pg down-Next sec,Esc-Exit");}
    elseif(drive==405)
    {
    cprintf("F2-Save,F3-Edit hex,F4-Edit ascii");
    gotoxy(38,1);
    cprintf("Pg up-Prev Page,Pg down-Next page,Esc-Exit");}
    return 0 ;
       }

void fp()
{
int a;
clrscr();
lay();
a=absread(0,1,0,&b);
  if(a==-1)
   {
    clrscr();
    perror("Disk Read/Write error:");
    getch();
    }
gotoxy(6,4);
cprintf("System id: %s", b.system_id);
gotoxy(6,7);
cprintf("Bytes per sector : %d", b.bytes_per_sec ) ;
gotoxy(6,10);
cprintf("Sectors per cluster : %d", b.sec_per_clus ) ;
gotoxy(6,13);
cprintf("Reserved sectors : %d", b.res_sec ) ;
gotoxy(6,16);
cprintf("FAT copies : %d", b.fat_copies ) ;
gotoxy(6,19);
cprintf("Root directory entries : %d", b.root_dir_entry ) ;
gotoxy(44,4);
cprintf("No. of sectors on disk : %u", b.no_sects ) ;
gotoxy(44,7);
cprintf("Format id : %X", b.format_id ) ;
gotoxy(44,10);
cprintf("Sectors per FAT : %d", b.sec_per_fat ) ;
gotoxy(44,13);
cprintf("Sectors per track : %d", b.sec_per_trk ) ;
gotoxy(44,16);
cprintf("No. of sides : %d", b.no_sides ) ;
gotoxy(44,19);
cprintf("No. of reserved sectors : %d", b.no_sp_res_sect ) ;
gotoxy(48,22);
printf("Press any key to continue....");
getch();
     }


void options()
{ char ch;  int dr;char name[20];
  textbackground(4);
  clrscr();
  while(ch!=27)
  {clrscr();
  lay();
  _setcursortype(0);
  gotoxy(28,4);
  cprintf("F : Floppy drive info");
  gotoxy(28,6);
  cprintf("M : Harddisk info");
  gotoxy(28,8);
  cprintf("A : Edit Floppy  sector");
  gotoxy(28,10);
  cprintf("C : Edit Harddisk  sector");
  gotoxy(28,12);
  cprintf("F2 : File mode");
  gotoxy(28,14);
  cprintf("T : Save to file");
  gotoxy(28,16);
  cprintf("W : Write from file");
  gotoxy(28,18);
  cprintf("F1 : Help");
  gotoxy(28,20);
  cprintf("D : Disclamier");
  gotoxy(28,22);
  cprintf("Esc : Exit");
  textcolor(15);
     ch=getch();
    _setcursortype(2);
    switch(ch)
    {
    case'F':
    case'f':clrscr();
         lay();
         gotoxy(2,2);
        printf("Please insert a floppy disk in drive and press any key....");
        getch();
        clrscr();
        fp();
        break;
    case'M':
    case'm':clrscr();
         lay();
         gotoxy(2,2);
         printf("This option is not compatible with all the drivers.If your screen goes blank");
         gotoxy(2,3);
         printf("then press ctrl+pause to exit.press any key to continue....");
         getch();
         clrscr();
         lay();
         hdinfo();
         break;
    case'A':
    case'a':clrscr();
         lay();
         gotoxy(4,4);
         cprintf("Enter logical sector you wish to edit:");
         scanf("%d",&lsect);
         drive=0;
         a=absread(drive,1,lsect,buff);
          if(a==-1)
        {
         perror("Disk Read/Write error:");
         getch();
         break;
           }
        display(0);
        edit();
        break;
   case'C':
   case'c':  clrscr();
          lay();
          drive=0x80;
          gotoxy(4,4);
          cprintf("Enter the head:");
          scanf("%d",&head);
          gotoxy(4,6);
          cprintf("Enter the track:");
          scanf("%d",&track);
          gotoxy(4,8);
          cprintf("Enter the sector:");
          scanf("%d",&sector);
          biosdisk(2,0x80,head,track,sector,1,buff);
          display(0);
          edit();
          break;

   case'T':
   case't':clrscr();
        lay();
        chdir("c:\\windows\\desktop");
        gotoxy(2,2);
        cprintf("Enter the file name with extension:");
        scanf("%s",name);
          fp1=fopen(name,"wb+");
         if(fp1==NULL)
         perror("can't open file!!!");
         else
         {
         gotoxy(2,3);
         cprintf("Select Drive");
         gotoxy(2,4);
         cprintf("1)Harddisk");
         gotoxy(2,5);
         cprintf("2)Floppy disk");
         gotoxy(2,6);
         printf("ur choice:");
         dr=getche();
         dr=dr-48;
          while(dr!=1&&dr!=2)
          {gotoxy(2,4);
          cprintf("Please enter a valid choice!!!");
          dr=getche();
         dr=dr-48;}
          switch(dr)
             {
         case 1:clrscr();
            lay();
            gotoxy(12,2);
            cprintf("write the hard disk sector to file!!!");
            gotoxy(2,4);
            cprintf("enter the head:");
            scanf("%d",&head);
            gotoxy(2,6);
            cprintf("enter the track:");
            scanf("%d",&track);
            gotoxy(2,8);
            cprintf("enter the sector:");
            scanf("%d",&sector);
            biosdisk(2,0x80,head,track,sector,1,buff);
            fwrite(&buff,sizeof(buff),1,fp1);
            fclose(fp1);
            gotoxy(2,10);
            cprintf("the sector is stored to the file \"c:\\windows\\desktop\\%s\"",name);
            getch();
            break;
          case 2:clrscr();
            lay();
            gotoxy(12,2);
            cprintf("write the floppy disk sector to file!!!");
            gotoxy(2,4);
            cprintf("enter logical sector:");
            scanf("%d",&lsect);
            gotoxy(2,6);
            cprintf("writing....");
            a=absread(drive,1,lsect,buff);
             if(a==-1)
              {
               perror("Disk Read/Write error:");
               getch();
               break;
               }
              fwrite(&buff,sizeof(buff),1,fp1);
            fclose(fp1);
            gotoxy(2,8);
            cprintf("the sector is stored to the file \"c:\\windows\\desktop\\%s\"",name);
            getch();
            }
            }/*else*/break;
   case'W':
   case'w': clrscr();
        lay();
        chdir("c:\\windows\\desktop");
          gotoxy(2,2);
          cprintf("enter the file name with extension:");
          scanf("%s",name);
          fp1=fopen(name,"rb+");
         if(fp1==NULL)
         {perror("can't open file!!!");
         getch();
         break;
         }
         else
         {
         gotoxy(2,3);
         cprintf("enter the drive");
         gotoxy(2,4);
         cprintf("1)for harddisk");
         gotoxy(2,5);
         cprintf("2)for floppy disk");
         gotoxy(2,6);
         printf("ur choice:");
         dr=getche();
         dr=dr-48;
          while(dr!=1&&dr!=2)
          {gotoxy(2,8);
          printf("please enter a valid choice!!!");
          dr=getche();
         dr=dr-48;
          }
         switch(dr)
         {
         case 1:clrscr();
            lay();
            gotoxy(12,2);
            cprintf("write to hard disk **from** file!!!");
            gotoxy(2,4);
            cprintf("enter the head:");
            scanf("%d",&head);
            gotoxy(2,6);
            cprintf("enter the track:");
            scanf("%d",&track);
            gotoxy(2,8);
            cprintf("enter the sector:");
            scanf("%d",&sector);
            fread(&buff,512,1,fp1);
            biosdisk(3,0x80,head,track,sector,1,buff);
            fclose(fp1);
            gotoxy(2,10);
            cprintf("successfully write to the disk!!!");
            getch();
            break;
          case 2:clrscr();
            lay();
            gotoxy(12,2);
            cprintf("write to floppy disk sector **from** file!!!");
            gotoxy(2,4);
            cprintf("enter logical sector:");
            scanf("%d",&lsect);
            fread(&buff,512,1,fp1);
            gotoxy(2,6);
            cprintf("writing...." );
            a=abswrite(drive,1,lsect,buff);
             if(a==-1)
              {
               perror("Disk Read/Write error:");
               getch();
               break;
               }
            fclose(fp1);
            gotoxy(2,8);
            cprintf("successfully write to the disk!!!");
            getch();
            }
            }/*else*/break;
   case 27: textbackground(0);
        clrscr();
        gotoxy(2,2);
        printf("thanks for using this!!!");
        gotoxy(13,3);
        printf("-hardik shah");
        chdr('c');
        exit(1);
        break;
   case 59:clrscr();
       help();
       getch();
       break;
   case 60:clrscr();
       filemode();
       break;
   case'd':
   case'D':clrscr();
        disclam();
        lay();
        getch();
        break;
        }
        }
    }

 edit()
 {
  int ch,ch1,j,flg=0;
  x=2;
  y=3;
  indicator=1;
  i=0;

    for(j=0;j<=511;j++)
      temp[j]=buff[j];
    while(1)
     {
      gotoxy(x,y);
      ch=bioskey(0);
      ch1=toupper(ch);
     if(ch1>='0'&&ch1<='9'||ch1>='A'&&ch1<='F')
       {
    putch(toupper(ch));
    indicator=!(indicator);
    x++;
    if(((x-1)%9==0)&&(x>=9))
    x++;
    if(indicator==0)
     {
      gotoxy(x,y);
     printf(" ");
        }
      ch1=ch1-48;
      if(ch1>9)
      ch1=ch1-7;
      if(indicator==0)
    {
     ch1=ch1<<4;
    temp[i]=temp[i]&0x0f;
     flg=1;
       }
       else
    {
    flg=0;
    temp[i]=temp[i]&0xf0;
        }
       temp[i]=temp[i]|ch1;
       if(x>=19&&y==24)
       flg=0;
       gotoxy((57+(i%24)),y);
       printf("%c",temp[i]);
     if(flg==0)
       i++;
    nosound();
      update(0);
      }
      else
       {
       switch(ch)
    {
      case Right:
            if((x==8)||(x==17)||(x==26)||(x==35)||(x==44))
               x++;
            update(1);
            break;

      case Left:
            if(((x-2)%9==0)&&(x>=9))
              x--;
            update(2);
            break;

      case Down:
            update(3);
            break;

      case Up:
            update(4);
            break;

      case F1:  x=2;
            y=3;
            i=0;
            display(0);
            break;

      case F2:i=0;
          gotoxy(52,1);
          printf("               saving....");
          for(j=0;j<=511;j++)
            buff[j]=temp[j];
          if(drive==0)
          {a=abswrite(drive,1,lsect,temp);
           if(a==-1)
             {
             clrscr();
             perror("Disk Read/Write error:");
             getch();
            }
            clrscr();
            a=absread(drive,1,lsect,buff);
            if(a==-1)
             {
              clrscr();
              perror("Disk Read/Write error:");
              getch();
            } }
             elseif(drive==0x80)
             {biosdisk(3,drive,head,track,sector,1,buff);
             clrscr();
            biosdisk(4,drive,head,track,sector,1,buff);
            }
            elseif(drive==405)
            {fseek(fs,-512,1);
             fwrite(buff,512,1,fs);
              fseek(fs,-512,1);
              i6=0;
               display(i5);
               edit();
               break;
               }
            display(0);
            edit();
            break;

      case F5:
          if(drive==0)
          {i=0;
          gotoxy(1,25);
          textcolor(2);
          cprintf("                  enter the sector you wish to modify:                         ");
          gotoxy(55,25);
          scanf("%d",&lsect);
          textcolor(15);
          a=absread(drive,1,lsect,buff);
          if(a==-1)
           {
            clrscr();
            perror("Disk Read/Write error:");
            getch();
              }
          }
          elseif(drive==0x80)
          {i=0;
          gotoxy(6,1);
          textcolor(2);
          printf("   ");
          gotoxy(6,1);
          scanf("%d",&head);
          textcolor(15);
          biosdisk(2,drive,head,track,sector,1,buff);
          }
          display(0);
          edit();

          break;

      case Pgup:
            if(drive==0)
            {i=0;
            lsect--;
            if(lsect<0)
              lsect=0;
            a=absread(drive,1,lsect,buff);
            if(a==-1)
             {
               clrscr();
               perror("Disk Read/Write error:");
               getch();
            }
             else
               display(0);
                }
            elseif(drive==0x80)
            {i=0;
            sector--;
            if(sector<1)
              sector=1;
            biosdisk(2,drive,head,track,sector,1,buff);
            display(0);}
            elseif(drive==405)
            {if(ftp>1)
            {ftp--;
            if(ftp<=-1)
            ftp=0;
            if(ftp==0)
            {i6=0;
            fseek(fs,-512,1);
            display(i5);}
            elseif(ftp>0)
            {
            i6=0;
            fseek(fs,-512,1);
            fseek(fs,-512,1);
            display(i5);
            } }
             else
             {i6=1;
             display(i5);}
                 }

             edit();
            break;

      case Pgdwn:
             if(drive==0)
             {i=0;
             lsect++;
             a=absread(drive,1,lsect,buff);
             if(a==-1)
              {
               clrscr();
               perror("Disk Read/Write error:");
               getch(); }
              else
               display(0);     }
              elseif(drive==0x80)
              {
              i=0;
             sector++;
             biosdisk(2,drive,head,track,sector,1,buff);
              display(0);
              }
               elseif(drive==405)
              {ftp++;
               i6=0;
              clrscr();
              if((ch=fread(buff,512,1,fs))!=0)
             {
             fseek(fs,-512,1);
              display(i5);
              }
              else
              {fseek(fs,-512,1);
              i6=1;
              display(i5);}
             }
              edit();
              break;

      case F4:
          i=0;
          edascii();
          break;

      case F6:
          if(drive==0x80)
          {i=0;
          gotoxy(17,1);
          textcolor(2);
          printf("      ");
          gotoxy(17,1);
          scanf("%d",&track);
          textcolor(15);
          biosdisk(2,drive,head,track,sector,1,buff);
          display(0);
          edit();
          }
          break;

      case F7:
          if(drive==0x80)
          {i=0;
          gotoxy(32,1);
          textcolor(2);
          printf("        ");
          gotoxy(32,1);
          scanf("%d",&sector);
          textcolor(15);
          biosdisk(2,drive,head,track,sector,1,buff);
          display(0);
          edit();
          }
          break;


      case Esc:if(drive==405)
           fclose(fs);
           options();
           break;
            }
          }
           }
        }
 void update(int i1)
   {
   if(x==2&&y==3)
   i=0;
   if(i1==0)
     if(x>=55)
      {
       x=2;
       y++;
        }
    if(y==24&&x>=maxc+1)
         {
          y=24;
          x=17;
          i=511;
        }
    /*right*/if(i1==1)
       {
          if((y<=23)||(y==24&&x<18))
          i++;
           x+=2;
       if(x>=55)
          {
           x=2;
           y++;
         }
        if(y==24&&x>=maxc+1)
         {
          y=24;
          x=17;
          i=511;
        }
           }
      else/*left*/if(i1==2)
      {
        i--;
        x-=2;
     if(x<2)
     {
     x=55;
     y--;
       }
    if(y<3)
     {
     i=0;
     y=3;
     x=2;
      }
        }
       else/*down*/if(i1==3)
       {   indicator=1;
       if((y<24&&x<=18)||(y<23&&x>18))
    i+=24;
    y++;
    if(y>=24)
    y=24;
    if(y>=23&&x>18)
    y=23;
      }
     else/*up*/if(i1==4)
     {indicator=0;
     if(y>3)
     i-=24;
     y--;
       if(y<3)
       y=3;
       }
      if(x==2&&y==3)
      i=0;
      }
   edascii()
  {
   int ch,ch1,j,x2,fkey=0;

   x=57,y=3;
   gotoxy(57,3);
     for(j=0;j<=511;j++)
       temp[j]=buff[j];
     while(1)
      {
       gotoxy(x,y);
       ch=getch();
       if(ch==27)
       {
       options();}
       elseif(ch==0)
      {fkey=1;
       ch=getch();
      }
      else
      fkey=0;
      if(fkey!=1)
      {
       putch(ch);
        x++;
        temp[i]=ch;
        if(x1==10||x1==19||x1==28||x1==37||x1==46)
          x1++;
        if(x1>=54)
          x1=2;
        gotoxy(x1,y);
        printf("%02x",temp[i]);
        if((y==24&&x<64)||(y<=23))
         i++;
         x1+=2;
        upascii(0);
           }
       else
      {
       switch(ch)
      {
       case 77:
              x1+=2;
              if(x1==10||x1==19||x1==28||x1==37||x1==46)
              x1++;
              if(x1>=54)
              x1=2;
              upascii(1);
              break;

       case 75:
              x1-=2;
              if(x1==10||x1==19||x1==28||x1==37||x1==46)
             x1--;
              if(x1>=54||x1<=2)
             x1=2;
              upascii(2);
              break;

       case 80:
             upascii(3);
             break;

       case 72:
            upascii(4);
            break;


       case 59:
           i=0;
           x1=2;
           x=57;
           y=3;
           display(0);
           break;
       case 60:
          i=0;
          gotoxy(52,1);
          printf("               saving....");
          for(j=0;j<=511;j++)
            buff[j]=temp[j];
          if(drive!=0x80)
          {a=abswrite(drive,1,lsect,temp);
           if(a==-1)
             {
             clrscr();
             perror("Disk Read/Write error:");
             getch();
            }
            clrscr();
            a=absread(drive,1,lsect,buff);
            if(a==-1)
             {
              clrscr();
              perror("Disk Read/Write error:");
              getch();
            } }
             else
             {biosdisk(3,drive,head,track,sector,1,buff);
              clrscr();
              biosdisk(4,drive,head,track,sector,1,buff);
            }
            display(0);
            edascii();
            break;

      case 63:
          i=0;
          gotoxy(1,25);
          textcolor(2);
          if(drive!=0x80)
          {cprintf("                  enter the sector you wish to modify:                         ");
          gotoxy(55,25);
          scanf("%d",&lsect);
          textcolor(15);
          a=absread(drive,1,lsect,buff);
          if(a==-1)
           {
            clrscr();
            perror("Disk Read/Write error:");
            getch();
              }
            }
          else
          {i=0;
          gotoxy(6,1);
          textcolor(2);
          printf("   ");
          gotoxy(6,1);
          scanf("%d",&head);
          textcolor(15);
          biosdisk(2,drive,head,track,sector,1,buff);
          }
          display(0);
          edascii();
          break;
      case 61:
          edit();
          break;
      case 73:
            i=0;
            if(drive!=0x80)
            {
            lsect--;
            if(lsect<0)
              lsect=0;
            a=absread(drive,1,lsect,buff);
            if(a==-1)
             {
               clrscr();
               perror("Disk Read/Write error:");
               getch();
             }}
            else
            {
            sector--;
            if(sector<1)
              sector=1;
            biosdisk(2,drive,head,track,sector,1,buff);
            }
            display(0);
            edascii();
            break;

      case 81:
             i=0;
             if(drive!=0x80)
             {
             lsect++;
             a=absread(drive,1,lsect,buff);
             if(a==-1)
              {
               clrscr();
               perror("Disk Read/Write error:");
               getch();
             }}
              else
              {
              sector++;
             biosdisk(2,drive,head,track,sector,1,buff);
              }
              display(0);
              edascii();
              break;

      case 62:
          i=0;
          x1=2;
          edascii();
          break;

      case 64:
          if(drive==0x80)
          {i=0;
          gotoxy(17,1);
          textcolor(2);
          printf("      ");
          gotoxy(17,1);
          scanf("%d",&track);
          textcolor(15);
          biosdisk(2,drive,head,track,sector,1,buff);
          display(0);
          edit();
          }
          break;

      case 65:
          if(drive==0x80)
          {i=0;
          gotoxy(32,1);
          textcolor(2);
          printf("        ");
          gotoxy(32,1);
          scanf("%d",&sector);
          textcolor(15);
          biosdisk(2,drive,head,track,sector,1,buff);
          display(0);
          edit();
          }
          break;
             }
           }
        }
        }


upascii(int i1)
   {
     if(x>=64&&y==24)
     x=64;
     if((x==64)&&(y==24))
     x1=17;

     if(i1==0)
     {
     if(x>=81)
     {x=57;
     y++; }
     }
     else/* right */if(i1==1)
     {
     if((y==24&&x<64)||(y<=23))
       i++;
       x++;
       if(x>=81)
       {
       x=57;
       y++;
        }
       if(y>24)
       y=24;
       if(x>64&&y==23)
       y=23;
       if(x>=64&&y==24)
       x=64;
       }
      else/* left */if(i1==2)
      { if(x>57&&y>=3)
        i--;
        x--;
       if(x<=56)
         { i--;
           x=80;
           y--;
       if(y<3)
         {
          y=3;
          x=57;
        }
         }
        if(x==57&&y==3)
        i=0;
        if((x<=57)&&(y<=3))
         {
           x=57;
           y=3;
        }
         }
     else/* down */if(i1==3)
      { if((y==23&&x<65)||(y<23))
    i+=24;
    y++;
    if(y>=23&&x>=65)
        y=23;
    if((y>24))
      y=24;
       }
     else/* up */if(i1==4)
       {if(y>3)
    i-=24;
    y--;
    if(x==57&&y==3)
    i=0;
    if(y<3)
      y=3;
     }
     return;
       }

 void chdr(char a)
{    int chdr;
switch(a)
{
  case'A':
  case'a':chdr=_chdrive(1);
      break;

  case'B':
  case'b':chdr=_chdrive(2);
      break;

  case'C':
  case'c':chdr=_chdrive(3);
      break;

  case'D':
  case'd':chdr=_chdrive(4);
      break;

  case'E':
  case'e':chdr=_chdrive(5);
      break;

  case'F':
  case'f':chdr=_chdrive(6);
      break;

  case'G':
  case'g':chdr=_chdrive(7);
      break;
  case'H':
  case'h':chdr=_chdrive(8);
      break;
  case'I':
  case'i':chdr=_chdrive(9);
      break;
  case'J':
  case'j':chdr=_chdrive(10);
      break;
      }
       if(chdr!=0)
       {clrscr();
       printf("An Unexpected ERROR Occured!!!\n Please Restart The Application.....");
       exit(1);}
      }

 void filemode()
 {char buffer[MAXPATH],ch2,t1[4],tm[3]={'a','m'};
  int y2=3,i2=0,y3=4,i3=0,len,done,max=0;
  unsigned int hr,min,sec,yr,mon,day;
   clrscr();
 lay();
 getcwd(buffer, MAXPATH);
_setcursortype(0);
gotoxy(2,2);
cprintf("Current dir %s\n", buffer);
done = findfirst("*.*",&ffblk,FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_LABEL|FA_DIREC|FA_ARCH);
       while (1)
       {if(done==0)
    {
    gotoxy(36,2);
    printf("Time");
    gotoxy(47,2);
    printf("Date");
    gotoxy(57,2);
       printf("Size(in bytes)");
       gotoxy(3,y2);
      printf("  %s", ffblk.ff_name);
      if(ffblk.ff_attrib==FA_HIDDEN)
       {gotoxy(22,y2);
       printf(" hidden"); }
      if(ffblk.ff_attrib==FA_RDONLY)
      {gotoxy(22,y2);
      printf(" read only"); }
      if(ffblk.ff_attrib==FA_SYSTEM)
      {gotoxy(22,y2);
      printf(" system");}
      if(ffblk.ff_attrib==FA_LABEL)
      {gotoxy(22,y2);
      printf(" vol");}
      if(ffblk.ff_attrib==FA_DIREC)
      {gotoxy(22,y2);
      printf(" dir");}
      if(ffblk.ff_attrib==FA_ARCH)
      {gotoxy(22,y2);
      printf(" archive");}
      /* for time */
      hr=ffblk.ff_ftime>>11;
      if(hr>12)
      {tm[0]='p';
      hr=hr-12; }
      min=(ffblk.ff_ftime<<5)>>10;
      sec= ((ffblk.ff_ftime<<11)>>11)*2;
      gotoxy(33,y2);
      printf("%02u:%02u:%02u%s",hr,min,sec,tm);
       /* for date */
      gotoxy(45,y2);
      yr=1980+(ffblk.ff_fdate>>9);
      mon=(ffblk.ff_fdate<<7)>>12;
      day=(ffblk.ff_fdate<<11)>>11;
      printf("%02u\-%02u\-%04u",day,mon,yr);
      gotoxy(57,y2);
      printf("%lu",ffblk.ff_fsize);
      printf("\n");
      len=strlen(ffblk.ff_name);
      strcpy(fl[i2],ffblk.ff_name);
      fl[i2][len+1]='\0';
      y2++;
       i2++;
       max++; }
       if((y2==24)||done)
    {gotoxy(4,3);
   printf("%c",16);
    gotoxy(5,25);
    printf("F1-Change directory");
    gotoxy(30,25);
    printf("F2-change drive");
    gotoxy(51,25);
    printf("Esc-Main menu");
    y2=3;
   while(1)
    {
     ch2=getch();
       switch(ch2)
     {
   case 80: if(!done)
         {
        if(y3!=25)
        {
        y3++;
        i3++;
        i5=i3;
        gotoxy(4,y3-2);
        printf(" ");
        gotoxy(4,y3-1);
        printf("%c",16);
        } }
        else
        {if(i3<max-1)
         {y3++;
        i3++;
        i5=i3;
        gotoxy(4,y3-2);
        printf(" ");
        gotoxy(4,y3-1);
        printf("%c",16);
        } }

         break;
   case 72:                 /*up */if(y3>=5)
       {
       gotoxy(4,y3-1);
       printf(" ");
       gotoxy(4,y3-2);
       printf("%c",16);
       y3--;
       i3--;
       i5=i3;
       }
       break;
   case 59:gotoxy(2,2);
       _setcursortype(2);
       printf("enter the directory:                    ");
       gotoxy(22,2);
       scanf("%s",buffer);
       _setcursortype(0);
       if(buffer[1]==':')
       chdr(buffer[0]);
       chdir(buffer);
       filemode();
       return;
   case 60: gotoxy(2,2);
        printf("                                         ");
        gotoxy(2,2);
       _setcursortype(2);
       printf("Enter Drive:");
       scanf("%s",t1);
       chdr(t1[0]);
       filemode();
       return;
   case 13:clrscr();
       drive =405;
      _setcursortype(2);
       ftp=1;
       findfirst(fl[i3],&ffblk,FA_RDONLY|FA_HIDDEN|FA_SYSTEM|FA_LABEL|FA_DIREC|FA_ARCH);
       if(ffblk.ff_attrib==FA_DIREC)
       {chdir(fl[i3]);
       filemode();
       return;
       }
       else
       {fs=fopen(fl[i3],"rb+");
       display(i3);
        edit(); }
        break;
   case 27:
       return;
      }
       if(y3==25)
       {clrscr();
       lay();
       y3=4;
       break;
       }
       } /* while*/

    }/*if*/
      done = findnext(&ffblk);
   }
       }

  void help()
   {
  printf("\n");
  printf("\n");
  textcolor(10);
  cprintf("  Disk Editor is a utility to see,modify disk sectors.you can edit any");
  printf("\n");
  cprintf("  sector on your disk drive.");
  printf("\n");
  printf("\n");
  textcolor(11);
  cprintf("                -:Varius commands are as bellow:-");
  printf("\n");
  printf("\n");
  textcolor(14);
  cprintf("  F1 - It is use to restore the disk sector.it means this command re-read");
  printf("\n");
  cprintf("     the sector and then display the contains of the sector again on the screen");
  printf("\n");
  printf("\n");
  cprintf("  F2 - It is use to save the changes made by you.");
  printf("\n");
  printf("\n");
  cprintf("  F3 - If you want to edit sectors in Hex mode then press this key.");
  printf("\n");
  printf("\n");
  cprintf("  F4 - If you want to edit the sectors in ascii mode then use this key.");
  printf("\n");
  printf("\n");
  cprintf("  F5 - By using this you can direct jump to any sector");
  printf("\n");
  printf("\n");
  cprintf("  Page Up - Go to previous sector.");
  printf("\n");
  printf("\n");
  cprintf("  Page Down - Go to next sector");
  printf("\n");
  printf("\n");
  cprintf("  Esc - Exit from Disk Editor");
   printf("\n                                               Press any key to Exit....");
    textcolor(14);


    lay();
    }

void disclam()
   { int p;
   gotoxy(2,3);
   printf(" Disclamier:-");
   for(p=3;p<13;p++)
   {
   gotoxy(p,4);
   printf("%c",205);}
   gotoxy(2,5);
   printf(" This software is provided on \"AS-IS\" basis.As this software is direct access-");
   gotoxy(2,6);
   printf(" es the disk drives, I am not responsible for any damage caused to you or your");
   gotoxy(2,7);
   printf(" computer's hardware or software through proper or inproper use  of this soft-");
   gotoxy(2,8);
   printf(" ware.Please do not change any critical sectors on your drive otherwise you ");
   gotoxy(2,9);
   printf(" can damage your computer.");
    }

void main()
 {
   clrscr();
   textcolor(11);
   options();
      }
  
Share: 


Didn't find what you were looking for? Find more on Program of disk editor Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program of disk editor is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!