⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 srpd.cpp

📁 该软件是一个纯中文的DOS硬盘分区管理程序,它除了居有分区管理外还有MBR、DBR备份/恢复功能。
💻 CPP
📖 第 1 页 / 共 4 页
字号:
#include"dos.h"
#include"math.h"
#include"conio.h"
#include"string.h"
#include"stdio.h"
#include"stdlib.h"
#include"process.h"
#include"function.cpp"
typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;
DWORD M_SECTORS=0,LM_SECTORS=0,LM_SSECTORS=0,LL_SECTORS=0,LL_SSECTORS=0,E_SECTORS=0,SECTORS=0,HEADS=255,T_SECTS=63;
BYTE PNO_M=0,PNO_L=0,P_TOTAL=0,SELECT=0,EXT=0,CHANGE=0;
BYTE HDD=0x80,HDD_COUNT=0,DBR=0;/*DBR存贮已存DBR的个数*/
struct DPT       /*DPT结构*/
{
  BYTE bflag;    /*引导标志,80H为活动分区*/
  BYTE head;     /*起始磁头*/
  BYTE sector;   /*起始扇区*/
  BYTE cylinder; /*起始柱面*/
  BYTE pflag;    /*分区类型标志*/
  BYTE ehead;    /*结束磁头*/
  BYTE esector;  /*结束扇区*/
  BYTE ecylinder;/*结束柱面*/
  DWORD ssectors;/*起始扇区号*/
  DWORD sectors; /*扇区数*/
  BYTE flag;     /*分区类型标志(主、扩展、逻辑)*/
  DWORD s_position;/*用来保存扇区的起始位置*/
}dpt[24];
struct EXT_13
{
  BYTE len; /*package的大小*/
  BYTE reserved; /*保留字节*/
  WORD nob; /*package的个数*/
  WORD bufoff; /*数据缓冲区偏移量*/
  WORD bufseg;/*数据缓冲区段地址*/
  DWORD s_low; /*扇区起始地址低位*/
  DWORD s_high; /*扇区起始地址高位*/
};
struct D_EXT_13/*检测硬盘是否支持扩展INT13*/
{
  WORD size;
  WORD inforflags;
  DWORD heads;
  DWORD cylins;
  DWORD sects;
  DWORD s_low;
  DWORD s_high;
  BYTE bps;
};
struct DBR
{
  char name[6];/*名称*/
  char pflag;/*分区类型*/
  DWORD size;/*分区大小*/
  DWORD position;/*分区位置*/
  char reserve;/*保留扇区数*/
}dbr[24];
char *menu1[]={"(M)  分区管理","(D)  高    级","(A)  关    于","(X)  退    出"};
char *sub_menu1[]={"(M)  MBR管理","(D)  DBR管理","(P)  DPT管理","(X)  返   回"};
char *sub_menu2[]={"(B)  备份MBR","(R)  恢复MBR","(F)  重写MBR","(X)  返   回"};
char *sub_menu3[]={"(B)  备份DPT","(R)  恢复DPT","(X)  返   回"};
char *cp_notice[]={"[P]  主分区","[E]  扩展分区"};
void notice(char *);
int detect_ext13(BYTE hdd)/*检测硬盘是否支持扩展INT 13*/
{
  REGS regs;
  SREGS sregs;
  regs.h.ah=0x41;
  regs.h.dl=hdd;
  regs.x.bx=0x55aa;
  int86x(0x13,&regs,&regs,&sregs);
  if(regs.x.bx==0xaa55)
    return 1;
  else
    return 0;
}
BYTE detect_hdd(BYTE hdd)/*获取硬盘参数信息*/
{
  union REGS regs;
  struct SREGS sregs;
  D_EXT_13 packet;
  regs.h.ah=0x48;
  regs.h.dl=hdd;
  sregs.ds=FP_SEG(&packet);
  regs.x.si=FP_OFF(&packet);
  int86x(0x13,&regs,&regs,&sregs);
  SECTORS=packet.s_low;
  if(regs.h.ah==0)
  {
    SECTORS=packet.s_low;
    return 1;
  }
  else
    return 0;
}
int read_sector(BYTE cmd,BYTE hdd,DWORD sector,char *buffer)/*以LBA方式读写硬盘*/
{
  union REGS regs;
  struct SREGS sregs;
  EXT_13 packet;
  packet.len=sizeof(packet);
  packet.reserved=0;
  packet.nob=1;
  packet.bufoff=FP_OFF(buffer);
  packet.bufseg=FP_SEG(buffer);
  packet.s_low=sector;
  regs.h.ah=cmd;
  regs.h.dl=hdd;
  regs.h.al=0;
  sregs.ds=FP_SEG(&packet);
  regs.x.si=FP_OFF(&packet);
  int86x(0x13,&regs,&regs,&sregs);
  if(regs.h.ah==0)
  {
    return 1;
  }
  else
    return 0;
}
char a[512]="";
int read_dpt(BYTE hdd)/*读取分硬盘分区表*/
{
  BYTE buff[512]="";
  BYTE ebuff[512]="";
  DWORD t=0;
  int i,j;
  P_TOTAL=0;
  PNO_M=0;
  PNO_L=0;
  EXT=0;
  LL_SECTORS=LL_SSECTORS=LM_SECTORS=LM_SSECTORS=0;
  for(i=0;i<24;i++)
  {
    dpt[i].bflag=dpt[i].head=dpt[i].sector=dpt[i].cylinder=dpt[i].pflag=dpt[i].ehead=dpt[i].ecylinder=dpt[i].flag=0;
    dpt[i].ssectors=dpt[i].sectors=dpt[i].s_position=0;
  }
  if(read_sector(0x42,hdd,0,buff))
  {
    for(i=446;i<=494&&buff[i+4]!=0;i+=16)
    {
      if(i==446&&buff[i+4]==0x0)
      {
	dpt[P_TOTAL].ssectors=0;
	dpt[P_TOTAL].sectors=SECTORS;
	dpt[P_TOTAL].pflag=0x0;
	dpt[P_TOTAL].s_position=0;
	P_TOTAL++;
	return 1;
      }
      t=DWORD(buff[i+8]);
      t=DWORD(buff[i+9])*0x100+t;
      t=DWORD(buff[i+10])*0x10000+t;
      t=DWORD(buff[i+11])*0x1000000+t;
      dpt[P_TOTAL].ssectors=t;
      dpt[P_TOTAL].s_position=t;
      t=DWORD(buff[i+12]);
      t=DWORD(buff[i+13])*0x100+t;
      t=DWORD(buff[i+14])*0x10000+t;
      t=DWORD(buff[i+15])*0x1000000+t;
      dpt[P_TOTAL].sectors=t;
      if(i==446&&dpt[P_TOTAL].ssectors>pow(2,14))
      {
	dpt[P_TOTAL+1].ssectors=dpt[P_TOTAL].ssectors;
	dpt[P_TOTAL+1].sectors=dpt[P_TOTAL].sectors;
	dpt[P_TOTAL+1].s_position=dpt[P_TOTAL+1].ssectors;
	dpt[P_TOTAL].ssectors=0x0;
	dpt[P_TOTAL].sectors=dpt[P_TOTAL+1].ssectors;
	dpt[P_TOTAL].pflag=0x0;
	dpt[P_TOTAL].flag=0x0;
	dpt[P_TOTAL].s_position=dpt[P_TOTAL].ssectors;
	P_TOTAL++;
      }
      if(dpt[P_TOTAL].ssectors>dpt[P_TOTAL-1].ssectors+dpt[P_TOTAL-1].sectors+pow(2,14))
      {
	dpt[P_TOTAL+1].ssectors=dpt[P_TOTAL].ssectors;
	dpt[P_TOTAL+1].sectors=dpt[P_TOTAL].sectors;
	dpt[P_TOTAL].ssectors=dpt[P_TOTAL-1].ssectors+dpt[P_TOTAL-1].sectors;
	dpt[P_TOTAL].sectors=dpt[P_TOTAL+1].ssectors-dpt[P_TOTAL].ssectors;
	dpt[P_TOTAL].pflag=0x0;
	dpt[P_TOTAL].flag=0x0;
	dpt[P_TOTAL].s_position=dpt[P_TOTAL].ssectors;
	dpt[P_TOTAL+1].s_position=dpt[P_TOTAL+1].ssectors;
	P_TOTAL++;
      }
      dpt[P_TOTAL].bflag=buff[i];
      dpt[P_TOTAL].head=buff[i+1];
      dpt[P_TOTAL].sector=buff[i+2];
      dpt[P_TOTAL].cylinder=(buff[i+3]);
      dpt[P_TOTAL].pflag=buff[i+4];
      dpt[P_TOTAL].ehead=buff[i+5];
      dpt[P_TOTAL].esector=buff[i+6];
      dpt[P_TOTAL].ecylinder=(buff[i+7]);
      LM_SSECTORS=dpt[P_TOTAL].ssectors;
      LM_SECTORS=dpt[P_TOTAL].sectors;
      P_TOTAL++;
      PNO_M++;
      if(buff[i+4]==0x0f)
      {
	dpt[P_TOTAL-1].flag='E';
	EXT=1;
	E_SECTORS=t;
	M_SECTORS=dpt[P_TOTAL-1].ssectors;
	t=M_SECTORS;
	dpt[P_TOTAL].s_position=dpt[P_TOTAL-1].ssectors;
	for(;P_TOTAL<25;)
	{
	  if(read_sector(0x42,hdd,t,ebuff))
	  {
	    if(ebuff[510]!=0x55&&ebuff[511]!=0xaa&&dpt[P_TOTAL-1].flag=='E')
	    {
	      dpt[P_TOTAL].pflag=0x05;
	      dpt[P_TOTAL].flag=0;
	      dpt[P_TOTAL].s_position=M_SECTORS;
	      dpt[P_TOTAL].ssectors=M_SECTORS;
	      dpt[P_TOTAL].sectors=E_SECTORS;
	      LL_SECTORS=E_SECTORS;
	      P_TOTAL++;
	      break;
	    }
	    j=446;
	    t=DWORD(ebuff[j+8]);
	    t=DWORD(ebuff[j+9])*0x100+t;
	    t=DWORD(ebuff[j+10])*0x10000+t;
	    t=DWORD(ebuff[j+11])*0x1000000+t;
	    LL_SSECTORS=t;
	    dpt[P_TOTAL].ssectors=t;
	    if(ebuff[j+4]==0x05)
	    {
	      if(dpt[P_TOTAL-1].flag=='E')
	      {
		dpt[P_TOTAL].sectors=t+M_SECTORS-dpt[P_TOTAL-1].ssectors;
		dpt[P_TOTAL].ssectors=dpt[P_TOTAL-1].ssectors;
		dpt[P_TOTAL].s_position=M_SECTORS;
	      }
	      else
	      {
		dpt[P_TOTAL].sectors=t-dpt[P_TOTAL-1].ssectors-dpt[P_TOTAL-1].sectors;
		dpt[P_TOTAL].ssectors=dpt[P_TOTAL-1].ssectors+dpt[P_TOTAL-1].sectors;
		dpt[P_TOTAL].s_position=t+M_SECTORS;
	      }
	      dpt[P_TOTAL].flag=0x0;
	      dpt[P_TOTAL].pflag=0x05;
	      P_TOTAL++;
	      t=t+M_SECTORS;
	      dpt[P_TOTAL].s_position=t;
	      continue;
	    }
	    else if(ebuff[j+4]==0)
	    {
	      dpt[P_TOTAL].pflag=0x05;
	      dpt[P_TOTAL].flag=0;
	      dpt[P_TOTAL].s_position=M_SECTORS;
	      dpt[P_TOTAL].ssectors=M_SECTORS;
	      dpt[P_TOTAL].sectors=E_SECTORS;
	      LL_SECTORS=E_SECTORS;
	      P_TOTAL++;
	      break;
	    }
	    else
	    {
	      dpt[P_TOTAL].bflag=ebuff[j];
	      dpt[P_TOTAL].head=ebuff[j+1];
	      dpt[P_TOTAL].sector=ebuff[j+2];
	      dpt[P_TOTAL].cylinder=ebuff[j+3];
	      dpt[P_TOTAL].pflag=ebuff[j+4];
	      dpt[P_TOTAL].ehead=ebuff[j+5];
	      dpt[P_TOTAL].esector=ebuff[j+6];
	      dpt[P_TOTAL].ecylinder=ebuff[j+7];
	      t=DWORD(ebuff[j+12]);
	      t=DWORD(ebuff[j+13])*0x100+t;
	      t=DWORD(ebuff[j+14])*0x10000+t;
	      t=DWORD(ebuff[j+15])*0x1000000+t;
	      dpt[P_TOTAL].sectors=t;
	      LL_SECTORS=t;
	      dpt[P_TOTAL].flag='L';
	      P_TOTAL++;
	      PNO_L++;
	      j+=16;
	      if(ebuff[j+4]==0x05)
	      {
		t=DWORD(ebuff[j+8]);
		t=DWORD(ebuff[j+9])*0x100+t;
		t=DWORD(ebuff[j+10])*0x10000+t;
		t=DWORD(ebuff[j+11])*0x1000000+t;
		if(t>dpt[P_TOTAL-1].s_position-M_SECTORS+dpt[P_TOTAL-1].sectors+0x3f)
		{
		  dpt[P_TOTAL].ssectors=(dpt[P_TOTAL-1].s_position+dpt[P_TOTAL-1].sectors+0x3f-M_SECTORS);
		  dpt[P_TOTAL].sectors=t-dpt[P_TOTAL].ssectors;
		  dpt[P_TOTAL].s_position=dpt[P_TOTAL].ssectors+M_SECTORS;
		  dpt[P_TOTAL].flag=0x0;
		  dpt[P_TOTAL].pflag=0x05;
		  P_TOTAL++;
		}
		t=M_SECTORS+t;
		dpt[P_TOTAL].s_position=t;
	      }
	      else
		break;
	    }
	  }
	  else
	    return 0;
	}
	if(E_SECTORS-dpt[P_TOTAL-1].s_position+M_SECTORS-dpt[P_TOTAL-1].sectors>pow(2,14)&&E_SECTORS-dpt[P_TOTAL-1].ssectors-dpt[P_TOTAL-1].sectors<SECTORS)
	{
	  dpt[P_TOTAL].ssectors=dpt[P_TOTAL-1].s_position-M_SECTORS+dpt[P_TOTAL-1].sectors+0x3f;
	  dpt[P_TOTAL].sectors=E_SECTORS-dpt[P_TOTAL].ssectors;
	  dpt[P_TOTAL].s_position=dpt[P_TOTAL].ssectors+M_SECTORS;
	  dpt[P_TOTAL].flag=0x0;
	  dpt[P_TOTAL].pflag=0x5;
	  P_TOTAL++;
	}
      }
      else
      {
	dpt[P_TOTAL-1].flag='P';
      }
    }
    if(SECTORS-LM_SECTORS-LM_SSECTORS>pow(2,14))
    {
      dpt[P_TOTAL].ssectors=LM_SECTORS+LM_SSECTORS;
      dpt[P_TOTAL].sectors=SECTORS-LM_SECTORS-LM_SSECTORS;
      dpt[P_TOTAL].flag=0x0;
      dpt[P_TOTAL].pflag=0x0;
      dpt[P_TOTAL].s_position=LM_SECTORS+LM_SSECTORS;
      P_TOTAL++;
    }
    return 1;
  }
  else
    return 0;
}
int answer(char *s)
{
  union inkey
  {
    char ch[2];
    int i;
  }c;
  int i,x;
  x=(80-strlen(s))/2;
  goto_xy(x,10);
  textbackground(3);
  window(x,10,x+strlen(s),13);
  clrscr();
  textcolor(14);
  cprintf(s);
  goto_xy(42,12);
  cprintf("否(NO)");
  textbackground(1);
  textcolor(15);
  goto_xy(30,12);
  cprintf("是(YES)");
  i=1;
  do
  {
    while(!bioskey(1));
    c.i=bioskey(0);
    if(c.ch[0])
    {
      switch(c.ch[0])
      {
	case 'Y':
	case 'y':
		 window(1,1,80,25);
		 return 1;
	case 'N':
	case 'n':
		 window(1,1,80,25);
		 return 0;
	case 13:
	case ' ':
		window(1,1,80,25);
		return i;
	case 27:
		window(1,1,80,25);
		return -1;
      }
    }
    else
    {
      switch(c.ch[1])
      {
	case 75:
	case 77:
		if(i==0)
		  i=1;
		else
		  i=0;
		break;
	default:
		sound(1500);
		delay(10);
		nosound();
      }
    }
    if(i==1)
    {
      textbackground(3);
      textcolor(14);
      goto_xy(42,12);
      cprintf("否(NO)");
      textbackground(1);
      textcolor(15);
      goto_xy(30,12);
      cprintf("是(YES)");
    }
    else
    {
      textbackground(3);
      textcolor(14);
      goto_xy(30,12);
      cprintf("是(YES)");
      textbackground(1);
      textcolor(15);
      goto_xy(42,12);
      cprintf("否(NO)");
    }
  }while(1);
}
int active_p(BYTE hdd,BYTE p_no,DWORD position)/*设置活动,读写错误返回0,成功返回1,不是主分区返回2*/
{
  DWORD t=0;
  BYTE buff[512]="";
  int i;
  if(dpt[p_no-1].flag=='P')
    if(read_sector(0x42,hdd,0,buff))
    {
      for(i=446;i<500;i+=16)
	buff[i]=0;
      for(i=446;i<=494;i+=16)
      {
	t=DWORD(buff[i+8]);
	t=DWORD(buff[i+9])*0x100+t;
	t=DWORD(buff[i+10])*0x10000+t;
	t=DWORD(buff[i+11])*0x1000000+t;
	if(t==position)
	{
	  if(buff[i+4]!=0x0&&buff[i+4]!=0x0f)
	  {
	    buff[i]=0x80;
	    if(read_sector(0x43,hdd,0,buff))
	    {
	      CHANGE=1;
	      return 1;
	    }
	    else
	      return 0;
	  }
	  else
	    return 0;
	}
      }
    }
    else
      return 0;
  else
    return 2;
}
int delete_p(BYTE hdd,BYTE p_no)/*返回1表示成功,0表示失败,2表示扩展分区中还有逻辑分区 */
{
  BYTE buff[512]="",buff1[512]="";
  DWORD t;
  int i,j;
  if(dpt[p_no-1].flag=='L')
  {
    if(dpt[p_no-2].flag==0x0)
    {
      if(read_sector(0x42,hdd,dpt[p_no-1].s_position,buff))
      {
	if(read_sector(0x42,hdd,dpt[p_no-3].s_position,buff1))
	{
	  if(dpt[p_no-3].flag=='E')
	  {
	    for(i=446;i<462;i++)
	      buff1[i]=buff[i+16];
	    for(;i<478;i++)
	      buff1[i]=0;
	    if(read_sector(0x43,hdd,dpt[p_no-3].s_position,buff1))
	    {
	      CHANGE=1;
	      return 1;
	    }
	    else
	      return 0;
	  }
	  else
	  {
	    for(i=462;i<478;i++)
	      buff1[i]=buff[i];
	    if(read_sector(0x43,hdd,dpt[p_no-3].s_position,buff1))
	    {
	      CHANGE=1;
	      return 1;
	    }
	    else
	      return 0;
	  }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -