CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
花落谁家,你作主! 盛大widget设计大赛英雄榜
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  Linux/Unix社区 >  系统维护与使用区

用程序实现格式化磁盘怎么实现?

楼主mozhanshi(魔战士)2002-05-15 14:27:00 在 Linux/Unix社区 / 系统维护与使用区 提问

如何编程实现对软盘的格式化?听说在用中断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

相关问题

  • 在delphi中实现磁盘格式化有哪几钟方法??
  • 磁盘格式化问题?
  • 汇编里怎么实现磁盘的管理!特别是对磁道的管理,如格式化等!
  • 关于格式化磁盘的问题
  • 再论磁盘格式化问题
  • 我想在windows2000下不能格式化我的移动磁盘并给我提示,而在windows98下要调动我的格式化程序,我该怎么做?急....
  • VC中格式化磁盘的问题,人多可以加分……
  • 有谁知道格式化磁盘的api函数?谢谢!!!
  • 格式化磁盘要用什么API??请高手赐教!
  • 怎么才能格式化指定的磁盘

关键词

  • 格式化
  • bpb
  • partnarr
  • partn
  • Αて
  • old
  • comm
  • 絋﹚
  • extstart
  • ptr

得分解答快速导航

  • 帖主:mozhanshi
  • BuZhang_AP97091

相关链接

  • CSDN Blog
  • 技术文档
  • 代码下载
  • 第二书店
  • 读书频道

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo