用程序实现格式化磁盘怎么实现?
如何编程实现对软盘的格式化?听说在用中断13H时,需要向磁头写一个数据表才能实现格式化。如果有人知道,请把详细方法告诉我,谢谢!
问题点数:100、回复次数:8Top
1 楼liglow(不是激励)回复于 2002-05-15 22:34:01 得分 0
不能直接调用format /y吗?Top
2 楼ytweiwei(又穷又丑农村户口!!!!)回复于 2002-05-16 08:53:08 得分 0
system("format c:");Top
3 楼mrzho(mrzhou)回复于 2002-05-16 10:11:19 得分 0
如果你想完全控制整个格式化过程,你可以调用INT13的格式化功能。Top
4 楼cutelocust(涉水而来)回复于 2002-05-16 13:03:28 得分 0
windows kernel32.dll 调用他Top
5 楼mozhanshi(魔战士)回复于 2002-05-16 14:15:19 得分 0
INT13H的格式化功能需要向所格式化的磁头写一个数据表来通知它如何格式化,我不知道数据表的内容。并且我需要控制整个格式化过程。谢谢高手帮我解决问题!
E-mail:mozhanshi@sina.comTop
6 楼BuZhang_AP97091(Email:gold_ap97091@163.com,Q45324223)回复于 2002-05-24 17:32:42 得分 0
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "bootmgr.h"
#include "common.h"
#include "global.h"
/*========================== е 硉 Α て 祘 Α ========================*/
#ifdef QKFORMAT
sword quick_format (PARTN *PartnArr, sword ndx)
{
byte buff[512];
PARTN *ptr;
sword key;
if ( isUpdatePartn() ) /** だ澄Τ笆ゼ纗 **/
return( 2 );
ptr = &PartnArr[ndx];
#if ( DISPLAY == CHINESE )
if ( !YN_box(IMMEDIATE_BOX, "眤 絋 ﹚ 璶 秈 ︽ Α て ") )
return( 1 );
#else
if ( !YN_box(IMMEDIATE_BOX, "Are you sure to quick format ?") )
return( 1 );
#endif
if ( (lba_ReadWDK(GetStart(ptr), 1, buff) == 0) && \
(*(word *)&buff[0x1fe] == 0xaa55) )
{
#if ( DISPLAY == CHINESE )
key = msg_box(" 繧",
" だ 澄 Ν Τ ミ 郎 ╰ 参 \nご 絋 ﹚ 璶 秈 ︽ Α て ",
"(Y)絋﹚ (N)", FALSE);
#else
key = msg_box("danger",
"Found file system exist !\nAre you sure to continue ?",
"(Y)es or (N)o", FALSE);
#endif
if ( toupper(key) != 'Y' )
return( 1 );
} /* end if */
#if 0
if ( auto_modify_id(ptr) == 0 && /** Modify System ID **/
(!isAllowSavePartn() || write_partn(PartnArr, 0, 0)) )
{
return( -1 );
}
#endif
CreateBPB(PartnArr, ndx, buff); /** ミ BPB **/
if ( Format(ptr, buff) )
return( -2 ); /**╰参合跋ずΤ穕胊合跋 **/
return( 0 );
} /* end quick_format */
#endif /* QKFORMAT */
/*============================= Modify System ID ============================*/
sword auto_modify_id (PARTN *ptr)
{
sword old_id = ptr->old_id;
dword Size;
Size = get_nsector(ptr) / 2048L; /** Unit: MB **/
if ( Size < 16 )
ptr->old_id = 1;
else if ( Size < 32 )
ptr->old_id = 4;
else if ( Size < 512 )
ptr->old_id = 6;
else if ( Size >= 2048 )
ptr->old_id = 0xb;
else if ( ptr->old_id != 6 && ptr->old_id != 0xb && ptr->old_id != 0xe )
ptr->old_id = ( g_Info.FD.use_fat32 ) ? 0xb : 6;
if ( (ptr->no < 5) && (ptr->end > 1023) )
ptr->old_id = (ptr->old_id == 0xb || ptr->old_id == 0xc) ? 0xc : 0xe;
if ( ptr->id != HIDDEN )
ptr->id = ptr->old_id;
return( old_id == ptr->old_id );
} /* end auto_modify_id */
/*====================== ミ FAT 12 or 16 or 32 BPB ========================*/
void CreateBPB (PARTN *PartnArr, sword ndx, void *buffer)
{
dword ExtStart, Total, Size, Temp;
byte FAR *codePTR;
byte *bootStrap;
PARTN *ptr;
DOSBPB *bpb;
sword i;
randomize();
ptr = PartnArr + ndx;
memset(buffer, 0, 512);
bpb = (DOSBPB *)buffer;
ExtStart = 0;
if ( ptr->no > 4 )
{
i = find_ext(PartnArr); /** т碝耎だ澄 **/
ExtStart = GetStart(PartnArr + i);
}
Total = get_nsector(ptr); /** だ澄合跋羆计 **/
cpymem(bpb->Comm.OEM, "DOS_BOOT", 8); /** OEM 紅坝セ **/
bpb->Comm.bytePerSect = 512; /** –合跋 Byte 计 **/
bpb->Comm.nFAT = 2; /** FAT 计 **/
bpb->Comm.m_descriptor = 0xf8; /** 祑盒 0xf8 **/
bpb->Comm.sectPerTrack = (word)g_Info.wdk->geo.maxSect; /** –瓂Τぶ合跋 **/
bpb->Comm.nHead = (word)g_Info.wdk->geo.maxHead + 1; /** –合琖Τぶ **/
bpb->Comm.tSector4 = Total; /** だ澄合跋羆计 **/
bpb->Comm.nHiddSect = GetStart(ptr) - ExtStart; /** 留旅合跋计 **/
bpb->Comm.MagicNum = 0xaa55; /** Magic Number **/
Size = Total / 2048; /** 传衡Θ MB **/
/*----------------------+
| FAT 32 |
+----------------------*/
if ( ptr->old_id == 0xb || ptr->old_id == 0xc )
{
bpb->Comm.nBootSect = 32; /** 玂痙合跋计 **/
bpb->FAT32.rootClust = 2; /** ヘ魁ノぇ合罫 **/
bpb->FAT32.fsInfoSect = 1; /** 郎╰参戈癟合跋 **/
bpb->FAT32.bakBootSect = 6; /** 币笆合跋合跋计 **/
bpb->FAT32.firstHD = 0x80; /** 材场祑盒腹 **/
bpb->FAT32.signature = 0x29; /** 疭紉絏 **/
bpb->FAT32.serNoLow = random(0xffff) + 1;
bpb->FAT32.serNoHigh = random(0xffff) + 1;
cpymem(bpb->FAT32.label, "NO NAME ", 11); /** Label **/
cpymem(bpb->FAT32.fsType, "FAT32 ", 8); /** 郎╰参 **/
/*----------------------------------+
| – Cluster 合跋计 |
+----------------------------------*/
bpb->Comm.sectPerClust = ( Size < 259L ) ? 1 :
( Size < 8192L ) ? 8 :
( Size < 16384L ) ? 16 :
( Size < 32768L ) ? 32 : 64;
/*-----------------------------------------------------------+
| FAT 合跋计 |
| FAT 合跋计 = (羆合跋计 - 玂痙合跋计 - ヘ魁ノ合跋计) |
| / ( 2 + 合罫ぇ合跋计 * 512 / 4 ) |
+-----------------------------------------------------------*/
Temp = Total - bpb->Comm.nBootSect - bpb->Comm.sectPerClust;
Temp /= ( 2 + bpb->Comm.sectPerClust * 128L ); /** 128 = 512 / 4 **/
bpb->FAT32.sectPerFAT = Temp + 1; /** FAT 合跋计 **/
bootStrap = bpb->FAT32.bootStrap; /** 币笆祘Α絏熬簿竚 **/
}Top
7 楼BuZhang_AP97091(Email:gold_ap97091@163.com,Q45324223)回复于 2002-05-24 17:33:51 得分 100
/*---------------------+
| FAT 12 or 16 |
+---------------------*/
else
{
bpb->Comm.nBootSect = 1; /** FAT 玡合跋计 **/
bpb->FAT1x.nFdbRoot = 512; /** ヘ魁兜计 **/
bpb->FAT1x.firstHD = 0x80; /** 材场祑盒腹 **/
bpb->FAT1x.signature = 0x29; /** 疭紉絏 **/
bpb->FAT1x.serNoLow = random(0xffff) + 1;
bpb->FAT1x.serNoHigh = random(0xffff) + 1;
cpymem(bpb->FAT1x.label, "NO NAME ", 11); /** Label **/
cpymem(bpb->FAT1x.fsType, "FAT16 ", 8); /** 郎╰参 **/
if ( ptr->old_id == 1 )
{
bpb->FAT1x.fsType[4] = '2';
bpb->Comm.sectPerClust = 8; /** FAT12 **/
}
else
{
/*----------------------------------+
| – Cluster 合跋计 |
+----------------------------------*/
bpb->Comm.sectPerClust = ( Size <= 32 ) ? 1 : /** FAT16 **/
( Size <= 64 ) ? 2 :
( Size <= 127 ) ? 4 :
( Size <= 255 ) ? 8 :
( Size <= 511 ) ? 16 :
( Size <= 1023 ) ? 32 : 64;
} /* end if */
/*-----------------------------------------------------------+
| FAT 合跋计 |
| FAT 合跋计 = (羆合跋计 - 玂痙合跋计 - ヘ魁ノ合跋计) |
| / ( 2 + 合罫ぇ合跋计 * 512 / (FAT12:1.5, FAT16:2) ) |
+-----------------------------------------------------------*/
Temp = Total - bpb->Comm.nBootSect - bpb->FAT1x.nFdbRoot / 16L;
Temp /= bpb->Comm.sectPerClust;
if ( ptr->old_id == 1 )
Temp = Temp * 2L / 3L;
else
Temp *= 2L;
Temp /= 512L;
bpb->FAT1x.sectPerFAT = (word)Temp + 1; /** FAT 合跋计 **/
bootStrap = bpb->FAT1x.bootStrap; /** 币笆祘Α絏熬簿竚 **/
} /* end if */
codePTR = (byte FAR *)BOOT_HEAD;
while ( codePTR != (byte FAR *)BOOT_END ) /** 恶币笆祘Α絏 **/
*bootStrap++ = *codePTR++;
/*--------------------------------------+
| Modify SI context at BootSect.asm |
| and fill JUMP instruction to buffer |
+--------------------------------------*/
bpb->Comm.NOP = 0x90; /** NOP **/
bpb->Comm.jumpCode = 0xeb;
if ( ptr->old_id == 0xb || ptr->old_id == 0xc )
{ /** JMP 58h 单 BPB **/
bpb->Comm.jumpOffset = 512 - sizeof(bpb->FAT32.bootStrap) - 4;
bpb->FAT32.bootStrap[ (word)BOOT_DATA - (word)BOOT_HEAD + 1 ] += 0x5a;
}
else
{ /** JMP 3Ch 单 BPB **/
bpb->Comm.jumpOffset = 512 - sizeof(bpb->FAT1x.bootStrap) - 4;
bpb->FAT1x.bootStrap[ (word)BOOT_DATA - (word)BOOT_HEAD + 1 ] += 0x3e;
}
} /* end CreateBPB */
/*============================= 秈 ︽ Α て ==============================*/
sword Format (PARTN *ptr, void *bootSect)
{
dword Sys_Sector, NowSect, Start, Total;
byte Temp[512];
FS_SECT *fsSect;
byte isFAT32;
DOSBPB *bpb;
sword ratio, i;
bpb = (DOSBPB *)bootSect;
isFAT32 = ( (ptr->old_id == 0xb) || (ptr->old_id == 0xc) );
NowSect = GetStart(ptr); /** 眔币﹍合跋 **/
Total = get_nsector(ptr); /** だ澄合跋羆计 **/
if ( isFAT32 ) /** 璸衡郎╰参ノぶ合跋 **/
Sys_Sector = bpb->FAT32.sectPerFAT * bpb->Comm.nFAT +
bpb->Comm.nBootSect + bpb->Comm.sectPerClust;
else
Sys_Sector = bpb->FAT1x.sectPerFAT * bpb->Comm.nFAT +
bpb->Comm.nBootSect + (bpb->FAT1x.nFdbRoot >> 4);
#if ( DISPLAY == CHINESE )
show_msg("タ 秈 ︽ Α て Ч Θ ");
#else
show_msg("It's formatting, completed ");
#endif
/*-----------------------------*/
/* ╰ 参 合 跋 恶 */
/*-----------------------------*/
for ( Start = 0 ; Start < Sys_Sector ; Start += 10 )
{
i = ( (Sys_Sector - Start) < 10 ) ? (sword)(Sys_Sector - Start) : 10;
if ( fill_sector(g_Info.wdk, NowSect + Start, i, 0) )
{
return( -1 );
}
ratio = (sword)(Start * 100 / Sys_Sector);
c_printf("%3d%%\b\b\b\b", ratio); /** 陪ボЧΘ瞯 **/
}
show_msg(NULL);
/*----------------------------------+
| 材币笆合跋 |
+----------------------------------*/
if ( lba_WriteWDK(NowSect, 1, bpb) )
return( -1 );
memset(Temp, 0, 512);
if ( isFAT32 )
{
/*------------------------------------------+
| FAT32 材币笆合跋 |
+------------------------------------------*/
if ( lba_WriteWDK(NowSect + bpb->FAT32.bakBootSect, 1, bpb) )
return( -1 );
fsSect = (FS_SECT *)Temp;
fsSect->title = 0x41615252L;
fsSect->signature = 0x61417272L;
fsSect->next_free_clus = 0x00000002L;
fsSect->magicNum = 0xaa55;
/*----------------------------------------------------+
| FAT32 郎 ╰ 参 合 跋 戈 癟 |
+----------------------------------------------------*/
fsSect->free_clust_cnt = (Total - Sys_Sector) /
(dword)bpb->Comm.sectPerClust;
if ( lba_WriteWDK(NowSect + 1, 1, fsSect) ||
lba_WriteWDK(NowSect + bpb->FAT32.bakBootSect + 1, 1, fsSect) )
{
return( -1 );
}
memset(Temp, 0, 512); /** ミ FAT ㄏノぇ既丁 **/
*(dword *)&Temp[4] = 0x0fffffffL;
*(dword *)&Temp[8] = 0x0fffffffL;
Temp[3] = 0x0f; /** 砞﹚ FAT 繷 **/
}
else
{
if ( ptr->old_id != 1 ) /** 砞﹚ FAT 繷 **/
Temp[3] = 0xff;
}
*(word *)&Temp[1] = 0xffff; /** 砞﹚ FAT 繷 **/
Temp[0] = bpb->Comm.m_descriptor; /** 砞称磞瓃じ **/
/*-----------------------------+
| ミ ㄢ FAT |
+-----------------------------*/
NowSect += bpb->Comm.nBootSect;
for ( i = 0 ; i < bpb->Comm.nFAT ; i++ )
{
if ( lba_WriteWDK(NowSect, 1, Temp) )
return( -1 );
/*-------------- 璸 衡 材 FAT ぇ 熬 簿 秖 ---------------*/
NowSect += ((isFAT32) ? bpb->FAT32.sectPerFAT : bpb->FAT1x.sectPerFAT);
}
return( 0 );
} /* end Format */
Top
8 楼BuZhang_AP97091(Email:gold_ap97091@163.com,Q45324223)回复于 2002-05-24 17:41:11 得分 0
还有头文件,本来是想贴在这让大家共享的。但很长,很难贴上。请留个Email。我发给你。
最好给我发Email:ap97091class@163.comTop




