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

📄 extdrvpa.c

📁 用扩展13中断获取硬盘参数,获取硬盘参数的纯C语言程序.
💻 C
字号:
/* 用扩展13中断获取硬盘参数 */
/* #include "zlib.h" */
#include <dos.h>
#include <stdio.h>
/* #include "zlib.h" */
/*
#define  BYTE unsigned char /*定义字节数据类型名

#define  unsigned short unsigned short /*定义字数据类型名

#define  Dunsigned short unsigned long /*定义双字数据类型名
*/

int extInt13DriveParameter(unsigned int driveNum,
						/*   unsigned long *maxCylinder,
						   unsigned long *maxHead,
						   unsigned long *maxSector,  */
						   unsigned long *totalSector)
{

	/*
	unsigned long cylinder=0;
	unsigned long head=0;
	unsigned long sector=0;
	unsigned long totalSectorVar=0;
	*/
	union REGS regs;
    struct SREGS sregs;
	
    struct {
		
		unsigned short size; /*地址包大小*/
		
		unsigned short inforflags; /*信息标志*/
		
		unsigned long cylns; /*物理柱面数*/

		unsigned long heads; /*物理磁头数*/
		
		unsigned long sects; /*物理每柱扇区数*/
		
		unsigned long tslow; /*扇区总数低位*/
		
		unsigned long tshi; /*扇区总数高位*/
		
		unsigned short  bps; /*每扇区字节数*/
		
    } package; /*LBA地址包定义*/
	
    regs.h.ah=0x48;
	
    regs.h.dl=(unsigned char)driveNum;
	
    sregs.ds=FP_SEG(&package); /*获得package的段地址*/
	
    regs.x.si=FP_OFF(&package); /*获得package的偏移量*/
	
    int86x(0x13,&regs,&regs,&sregs); /*调用中断*/
	
    if(regs.h.ah!=0) return regs.h.ah;
	/*
	printf("Cylinders=%lu Heads=%lu Sectors=%lu\nTotal sectors=%lu (%lu.3f GB)\n",cylinder,head,sector,totalSectorVar,totalSectorVar*512);
	*/
	printf("Cylinders=%lu Heads=%lu Sectors=%lu\nTotal sectors=%lu (%lu MB)\n\n",
		package.cylns,package.heads,package.sects,package.tslow,package.tslow/2/1024);
	/*
	printf("Cylinders=%lu Heads=%lu Sectors=%lu\nTotal sectors=%lu (%lu.3f GB)\n",*maxCylinder,*maxHead,*maxSector,*totalSector,(*totalSector)*512);
	*/
	*totalSector=package.tslow;

	return 0;
}

⌨️ 快捷键说明

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