发信人: zelor(东村遗少张作乐)
整理人: yangcs(2002-09-19 10:57:51), 站内信件
|
/********************************************************
* ZDISK.H: *
* This head file is defined something about disk *
* r/w in DOS/EINT13H. U can use it freely and at ur *
* own risk. *
* *
* Author: zelor<[email protected]> *
* *
* *
* version: *
* 0.0.1 *
* *
********************************************************/
#ifndef __ZELOR_DISK_H__
#define __ZELOR_DISK_H__
#include <bios.h>
#include <dos.h>
#define ZD_READ 0x42
#define ZD_WRITE 0x43
#define ZD_VERIFY 0x44
#define ZD_POSIT 0x47
#define ZD_GETDPP 0x48
#define MAX_DRV 4 /*最大磁盘数*/
/* a common sector size. */
#define SECTOR_SIZE 512
/*-------------------------------------
a flag array for whether support
E-INT13H
value:
0: yet not test
1: is support e-int13h
-1:is NOT support
-------------------------------------*/
int g_sup_e_int13h[MAX_DRV] = 0;
/* a common sector size. */
typedef unsigned char Z_SECTOR[SECTOR_SIZE];
struct tag_hsc {
unsigned char n_head;
unsigned n_sec:6;
unsigned n_cyl:10;
};
typedef union z_hsc {
unsigned char chartype[3];
struct tag_hsc hsctype;
} HSC;
struct tag_PAT {
unsigned char fboot; /* 可引导标志 */
HSC begin_hsc;
unsigned char id;
HSC end_hsc;
unsigned long hi_sec_num;
unsigned long total_sec;
};
typedef struct tag_MBR {
unsigned char BP[0x1be];
struct tag_PAT PAT[4];
unsigned char fenable[2];
} MBR;
typedef struct tag_disk_info {
unsigned long n_head;
unsigned long n_cyl;
unsigned long n_sec;
} DISKINFO;
/*
* disk address packet struct
*/
typedef struct tag_DAP {
unsigned char size = 16; /* 数据包尺寸(现恒为16)*/
unsigned char resv = 0; /* 保留==0 */
unsigned short n_blk; /* 要传输的数据块个数(以扇区为单位) */
unsigned long buf_addr; /* 传输缓冲地址(segment:offset)*/
unsigned long n_sec[2]; /* 磁盘起始绝对块地址 */
} DAP;
/*
* Drive Parameters Packet
*/
typedef struct tag_DPP {
unsigned short inf_size = 26; /* 数据包尺寸 (26 字节) */
unsigned short flags; /* 信息标志 */
unsigned long n_cyl; /* 磁盘柱面数 */
unsigned long n_head; /* 磁盘磁头数 */
unsigned long sec_per_track; /* 每磁道扇区数 */
unsigned long n_sec[2]; /* 磁盘总扇区数 */
unsigned short sec_size; /* 扇区尺寸 (以字节为单位) */
} DPP;
struct itemFAT16;
struct itemFAT32;
typedef struct tag_fat16_dbr {
unsigned char head[0x0b];
struct tag_fat16_bpb {
unsigned short int byte_per_sec;
unsigned char sec_per_clu;
unsigned short int resv_sec;
unsigned char nfat;
unsigned short int fdt_item;
unsigned short int nsec;
unsigned char media;
unsigned short int sec_per_fat;
unsigned short int sec_per_trac;
unsigned short int nhead;
unsigned long int hide_sec;
} fat16_bpb;
unsigned long nsec;
unsigned char drive_num;
unsigned char resv;
unsigned char exp_flag;
unsigned long vol_num;
unsigned char vol_name[14];
unsigned char fs_type[5];
unsigned char code[0x01C0];
unsigned char invl_flag[2] = {0x55,0xaa};
} FAT16_DBR;
typedef struct tag_fat32_dbr {
unsigned char head[0x0b];
struct tag_fat32_bpb {
unsigned short int byte_per_sec;
unsigned char sec_per_clu;
unsigned short int resv_sec;
unsigned char nfat;
unsigned char unused1[4];
unsigned char media;
unsigned short int sec_per_fat;
unsigned short int sec_per_trac;
unsigned short int nhead;
unsigned long hide_sec;
unsigned long big_total_sec;
unsigned long big_sec_per_fat;
unsigned char fat_flag;
unsigned char fs_v_major;
unsigned char fs_v_minor;
unsigned char unknow;
unsigned long root_cluster;
unsigned short int fs_sec;
unsigned short int bk_boot_sec;
unsigned char some_resv[12];
unsigned char drive_num;
unsigned char unused2;
unsigned char ebrs; //0x29
unsigned long vol_num;
unsigned char vol_lable[11];
unsigned char fs[8];
} fat32_bpb;
unsigned char code[418];
unsigned long sig;
} FAT32_DBR;
/* save LBA mode disk info and physical disk info.*/
DISKINFO g_LBA_DI = {0, 0, 0}, g_PHY_DI = {0, 0, 0};
/*
* Access a sector(read & write)
*
* parameter
* drv_num: physical driver number.
* sec_num: physical absolute sector number.
* mode: access mode.
* buf: buffer address.
*
* return
* 0: access sucessed.
* 1: access failed.
*/
int acs_sec(unsigned char mode, unsigned char drv_num, unsigned long sec_num, DAP * tdap)
/*
* line-search MBR -- from current MBR to next MBR
*
* pcur: a point to the current MBR.
* pnext: a point to the next MBR.
*/
int lnsrch_mbr(MBR * pcur, MBR * pnext);
/*
* get LBA mode disk information.
*
*/
int get_diskinfo(DISKINFO * pdi);
/*
* get the physical disk information, use EINT13 -47h.
*/
int get_phy_diskinfo(DISKINFO *pdi);
/*
* exchange number of h-s-c type and physical number type.
*/
unsigned long di2phn(DISKINFO * pdi);
void phn2di(unsigned long phn, DISKINFO * pdi);
/*
* judge whether support e-int13h
* return: 1 support 0 not support
*/
int is_sup_e13(unsigned int drv_num);
#endif
---- 生活,就是理想加泡面。
——张作乐,送你一束玫瑰 |
|