用C 语 言 的DOS 功 能 调 用 函 数dosx() 可 以 方 便 地 取 或 置 磁 盘ID 号, 用Turbo C 2.0 写 的 源 程 序 如 下:
#include
#include
#include
#include
main()
{int i,j;
union REGS regs; struct SREGS sregs;
unsigned char ch,tp[8],id[6];
clrscr();
printf(“\n\nPlease select one operation!");
printf(“\n 0--Get disk ID
1--Set disk ID\n");
ch=getch();
if(ch==27) return 0;
printf(“\nPlease select one disk to operate.");
printf(“\n 0--Current disk
1--disk A 2--disk B 3--disk
C ...\n");
j=getch()-48;
if(ch==49)
{printf(“\nPlease enter eight
HEX numerals(such as 1f23e35b):");
/*下面这一段程序是将输入的字符串转化成相应的
十六进制数(四字节)*/
scanf(“%s",tp);
for(i=0;i<8;i++)
if(isalpha(tp[i]))
{ tp[i]=tolower(tp[i]);
tp[i]=tp[i]-87;
}
else tp[i]=tp[i]-48;
id[5]=tp[0]*16+tp[1]; id[4]=tp[2]*16+tp[3];
id[3]=tp[4]*16+tp[5]; id[2]=tp[6]*16+tp[7];
/*-------------*/
regs.h.ah=0x69; regs.h.al=0x01;
regs.h.bl=j;
regs.x.dx=FP_OFF(id);
sregs.ds=FP_SEG(id);
intdosx(&regs,&regs,&sregs);
if(regs.x.cflag==0)
printf(“This operation is successful!");
}
else
{regs.h.ah=0x69;
regs.h.al=0x00;
regs.h.bl=j;
regs.x.dx=FP_OFF(id);
sregs.ds=FP_SEG(id);
intdosx(&regs,&regs,&sregs);
if(regs.x.cflag==0)
{printf(“\nThis disk ID is ");
printf(“%x%x-%x%x\n",
id[5],id[4],id[3],id[2]);
}
else printf(“\nTo get ID is failure.\n");
}
return 0;
}