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

📄 s_fat16.c

📁 独立 WIN98下磁盘分区程序(C语言+汇编) 界面功能类似FDISK 但独立编译
💻 C
📖 第 1 页 / 共 2 页
字号:
int print_fat(struct part_long *p )
{
 int i;
 struct boot_ms_dos *b=(struct boot_ms_dos*)tmp;
 char tmp1[20], tmp2[20];
 
 if( disk_read_rel(p,0,b,1)==-1 )
   {
    fprintf(stderr,"Error reading boot sector.\n");
    return FAILED;
   }

 printf("\n              DOS Boot Sector Data              Expected Value\n\n");
 printf("                        System id:  %-.8s\n", b->sys_id );
 printf("                      Sector size:  %-3d         512\n", b->sect_size );
 printf("              Sectors per cluster:  %d\n", b->clust_size );
 printf("Reserved sectors at the beginning:  %d\n", b->res_sects );
 printf("             Number of FAT copies:  %d\n", b->num_fats );
 printf("           Root directory entries:  %d\n", b->root_entr );
 printf("            Total sectors on disk:  %-5u       %u\n", b->total_sect, (b->total_sect==0 || p->num_sect>65535L)?0:p->num_sect );
 printf("            Media descriptor byte:  %02Xh         F8h\n", b->media_desc );
 printf("                  Sectors per FAT:  %d\n", b->fat_size );
 printf("                 Sectors per side:  %-2d          %d\n", b->num_sects, dinfo.num_sects );
 printf("                  Number of sides:  %-3d         %d\n", b->num_sides, dinfo.num_heads );
 printf("Hidden sectors prior to partition:  %-10s  %-10s\n", sprintf_long(tmp1,b->hid_sects), sprintf_long(tmp2,p->rel_sect) );
 printf("      Big total number of sectors:  %-10s  %-10s\n", b->big_total==0?"0":sprintf_long(tmp1,b->big_total), (b->total_sect==0 || p->num_sect>65535L)?sprintf_long(tmp2,p->num_sect):"0" );
 printf("                     Drive number:  %-3d         %d\n", b->drive_num, dinfo.disk );
 printf("   Extended boot record signature:  %02Xh\n", b->ext_signat );
 printf("             Volume serial number:  %08lX\n", b->serial_num );
 printf("                     Volume label:  %-.11s\n", b->label );
 printf("                 File system type:  %-.8s    %s\n", b->fs_id, (b->clust_size==0)?("?"):(p->num_sect/b->clust_size<4096?"FAT12":"FAT16") );
 printf("         Boot sector magic number:  0%04Xh      0AA55h\n", b->magic_num );
 return 0;
}/* print_fat */


#define StX  5
#define StY  5
#define StW  66
#define StH  14

#define StX2 (StX+30)
#define StX3 (StX+69)

#define TEXT_COLOR (BrCyan+BakBlue)
#define DATA_COLOR (BrWhite+BakBlue)
#define EDIT_COLOR (BrWhite+BakBlack)

int setup_fat(struct part_long *p)
{
 struct event ev;
 int i, v, syst, act, pos, fatsz;
 char *tmp, *tmp1, *tmp2;
 unsigned long n, l, lc, max_clust, min_clust, min_num_sect, max_num_sect;
 struct boot_ms_dos *b, *b_orig, *fat_boot_code=(struct boot_ms_dos*)FAT_BOOT;

 if( (tmp=malloc(3*SECT_SIZE))==0 )
   {
    show_error(ERROR_MALLOC);
    return FAILED;
   }

 tmp1=tmp+100;
/* tmp2=tmp+120; */
 b=(struct boot_ms_dos*)(tmp+SECT_SIZE);
 b_orig=b+1;
 
 if( disk_read_rel(p,0,b,1)==-1 )
   {
    show_error("Error reading boot sector");
    free(tmp);
    return FAILED;
   }

 memmove(b_orig,b,SECT_SIZE);
 
 clear_window(TEXT_COLOR,2,5,78,19);
 write_string( HINT_COLOR, 45, 24,"         ESC");
 write_string( MENU_COLOR, 57, 24," - Return to MBR view");

 write_string( HINT_COLOR, 64, 13,"F5");
 write_string( MENU_COLOR, 66, 13," - SetExpVal");
 write_string( HINT_COLOR, 64, 14,"F6");
 write_string( MENU_COLOR, 66, 14," - FixBoot2G");

 syst=0;
 if( strncmp(b->fs_id,"FAT12",5)==0 ) syst=12;
 if( strncmp(b->fs_id,"FAT16",5)==0 ) syst=16;

 max_clust =  (syst==0)?(0):( (long)SECT_SIZE*8*b->fat_size/syst - 2 );

 write_string( TEXT_COLOR, StX, StY+ 1,"                  System id:");
 write_string( TEXT_COLOR, StX, StY+ 2,"           File system type:                             Media desc:");
 write_string( TEXT_COLOR, StX, StY+ 3,"        Sectors per cluster:                            Sector size:");
 write_string( TEXT_COLOR, StX, StY+ 4,"            Sectors per FAT:                             FAT copies:");
 write_string( TEXT_COLOR, StX, StY+ 5,"     Root directory entries:                               Ext sign:");
 write_string( TEXT_COLOR, StX, StY+ 6,"       Volume serial number:                                  Magic:");
 write_string( TEXT_COLOR, StX, StY+ 7,"               Volume label:               Expected Value");
 write_string( TEXT_COLOR, StX, StY+ 8,"               Drive number:");
 write_string( TEXT_COLOR, StX, StY+ 9,"            Number of sides:");
 write_string( TEXT_COLOR, StX, StY+10,"           Sectors per side:");
 write_string( TEXT_COLOR, StX, StY+11," Sectors prior to partition:               123456789");
 write_string( TEXT_COLOR, StX, StY+12,"    Total number of sectors:               12345");
 write_string( TEXT_COLOR, StX, StY+13,"Big total number of sectors:               123456789");
 write_string( TEXT_COLOR, StX, StY+15,"     Minimum partition size:");
 write_string( TEXT_COLOR, StX, StY+16,"     Current partition size:");
 write_string( TEXT_COLOR, StX, StY+17,"     Maximum partition size:");

 sprintf(tmp,"%-.8s", b->sys_id );
 write_string( DATA_COLOR, StX2, StY+1, tmp );

 sprintf(tmp,"%-.8s", b->fs_id );
 write_string( DATA_COLOR, StX2, StY+2, tmp );

 sprintf(tmp,"%Xh", b->media_desc );
 write_string( DATA_COLOR, StX3, StY+2, tmp );

 sprintf(tmp,"%-3u %s bytes/cluster", b->clust_size, sprintf_long(tmp1,(unsigned long)b->clust_size*SECT_SIZE) );
 write_string( DATA_COLOR, StX2, StY+3, tmp );

 sprintf(tmp,"%d", b->sect_size );
 write_string( DATA_COLOR, StX3, StY+3, tmp );

 sprintf(tmp,"%-3d %s max clusters", b->fat_size, sprintf_long(tmp1,max_clust) );
 write_string( DATA_COLOR, StX2, StY+4, tmp );

 sprintf(tmp,"%d", b->num_fats );
 write_string( DATA_COLOR, StX3, StY+4, tmp );

 sprintf(tmp,"%d", b->root_entr );
 write_string( DATA_COLOR, StX2, StY+5, tmp );

 sprintf(tmp,"%Xh", b->ext_signat );
 write_string( DATA_COLOR, StX3, StY+5, tmp );

 sprintf(tmp,"%08lX", b->serial_num );
 write_string( DATA_COLOR, StX2, StY+6, tmp );


 sprintf(tmp," %u", dinfo.disk );
 write_string( DATA_COLOR, StX2+12, StY+ 8, tmp );

 sprintf(tmp," %u", dinfo.num_heads );
 write_string( DATA_COLOR, StX2+12, StY+ 9, tmp );

 sprintf(tmp," %u", dinfo.num_sects );
 write_string( DATA_COLOR, StX2+12, StY+10, tmp );

 sprintf(tmp," %-9lu", p->rel_sect );
 write_string( DATA_COLOR, StX2+12, StY+11, tmp );

 sprintf(tmp," %-5u", (p->num_sect>65535L)?0:p->num_sect );
 write_string( DATA_COLOR, StX2+12, StY+12, tmp );

 sprintf(tmp," %-9lu",(p->num_sect>65535L)?p->num_sect:0 );
 write_string( DATA_COLOR, StX2+12, StY+13, tmp );


 write_string( HINT_COLOR, StX2, StY+16, "Reading FAT... " );
 move_cursor( StX2+14, StY+16 );
 
 fatsz=min(256,b->fat_size);
 l=lc=0;
 for( n=b->res_sects ; n<b->res_sects+fatsz ; n++ )
  if( disk_read_rel(p,n,tmp,1)==-1 )
    {
     show_error("Error reading FAT table");
     break;
    }
  else
   for( i=0 ; i<SECT_SIZE ; i++, l++ )
    if( tmp[i]!=0 ) lc=l;

 min_clust = (syst==0)?(0):( lc*8/syst + (lc*8%syst==0?0:1) - 2);

 n = b->res_sects + b->num_fats*b->fat_size + b->root_entr*32/SECT_SIZE;

 min_num_sect =  n+min_clust*b->clust_size;
 max_num_sect =  n+max_clust*b->clust_size;

 sprintf(tmp,"%ld sectors = %s kbytes", min_num_sect, sprintf_long(tmp1,(min_num_sect)/2) );
 write_string( DATA_COLOR, StX2, StY+15, tmp );

 sprintf(tmp,"%ld sectors = %s kbytes", max_num_sect, sprintf_long(tmp1,(max_num_sect)/2) );
 write_string( DATA_COLOR, StX2, StY+17, tmp );

     n = b->total_sect!=0 ? b->total_sect : b->big_total;
     sprintf(tmp,"%ld sectors = %s kbytes", n, sprintf_long(tmp1,n/2) );
     write_string( DATA_COLOR, StX2, StY+16, tmp );

 pos=0;
 act=0;

 while(1)
    {
     for( i=0 ; i<11 ; i++ ) tmp[i]=(b->label[i]==0)?' ':b->label[i];
     tmp[i]=0;
     write_string( DATA_COLOR, StX2, StY+ 7, tmp );
     sprintf(tmp,"%-5d",b->drive_num);
     write_string( (b->drive_num==dinfo.disk)?DATA_COLOR:INVAL_COLOR, StX2, StY+ 8, tmp );
     sprintf(tmp,"%-5d",b->num_sides);
     write_string( (b->num_sides==dinfo.num_heads)?DATA_COLOR:INVAL_COLOR, StX2, StY+ 9, tmp );
     sprintf(tmp,"%-5d",b->num_sects);
     write_string( (b->num_sects==dinfo.num_sects)?DATA_COLOR:INVAL_COLOR, StX2, StY+10, tmp );
     sprintf(tmp,"%-9lu",b->hid_sects);
     write_string( (b->hid_sects==p->rel_sect)?DATA_COLOR:INVAL_COLOR, StX2, StY+11, tmp );
     sprintf(tmp,"%-6u",b->total_sect);
     write_string( (b->total_sect==0||b->total_sect==p->num_sect)?DATA_COLOR:INVAL_COLOR, StX2, StY+12, tmp );
     sprintf(tmp,"%-9lu",b->big_total);
     write_string( (b->big_total==0||b->big_total==p->num_sect)?DATA_COLOR:INVAL_COLOR, StX2, StY+13, tmp );
     sprintf(tmp,"%04X", b->magic_num );
     write_string( (b->magic_num==MBR_MAGIC_NUM)?DATA_COLOR:INVAL_COLOR, StX3, StY+6, tmp );

     p->changed = ( memcmp(b, b_orig, SECT_SIZE)==0 ) ? 0 : 1;
     if( p->changed==0 ) write_string(         HINT_COLOR, 15, 24,"F2");
     if( p->changed==1 ) write_string( Blink + HINT_COLOR, 15, 24,"F2");

     if( act==0 )
       {
        memmove(tmp,b->label,11);
        tmp[11]=0;
        for( i=10 ; i>=0 && tmp[i]==' ' ; i-- ) tmp[i]=0;
        memmove(tmp1,tmp,12);
        edit_str_field(&ev,0,EDIT_COLOR, StX2, StY+7, 12, tmp, &pos );
        if( memcmp(tmp,tmp1,12)!=0 )
          {
           for( i=0 ; tmp[i]!=0 && i<11 ; i++ ) b->label[i]=tmp[i];
           for( ; i<11 ; i++ ) b->label[i]=' ';
          }
       }

     if( act==1 )
       {
        n=b->drive_num;
        edit_int_field(&ev,0,EDIT_COLOR, StX2, StY+ 8, -5, &n, 255L );
        b->drive_num=n;
       }

     if( act==2 )
       {
        n=b->num_sides;
        edit_int_field(&ev,0,EDIT_COLOR, StX2, StY+ 9, -5, &n, 255L );
        b->num_sides=n;
       }

     if( act==3 )
       {
        n=b->num_sects;
        edit_int_field(&ev,0,EDIT_COLOR, StX2, StY+10, -5, &n, 63L );
        b->num_sects=n;
       }

     if( act==4 )
        edit_int_field(&ev,0,EDIT_COLOR, StX2, StY+11, -9,
                                                &b->hid_sects, 999999999L);
     if( act==5 )
       {
        n=b->total_sect;
        edit_int_field(&ev,0,EDIT_COLOR, StX2, StY+12, -6, &n, 65535L );
        b->total_sect=n;
       }

     if( act==6 )
        edit_int_field(&ev,0,EDIT_COLOR, StX2, StY+13, -9,
                                                &b->big_total, 999999999L);
/*   get_event(&ev,EV_KEY); */

     n = b->total_sect!=0 ? b->total_sect : b->big_total;
     sprintf(tmp,"%ld sectors = %s kbytes", n, sprintf_long(tmp1,n/2) );
     clear_window(DATA_COLOR, StX2, StY+16, 78-StX2, 1 );
     write_string( (n>=min_num_sect && n<=max_num_sect)?DATA_COLOR:INVAL_COLOR, StX2, StY+16, tmp );

     p->changed = ( memcmp(b, b_orig, SECT_SIZE)==0 ) ? 0 : 1;
     if( p->changed==0 ) write_string(         HINT_COLOR, 15, 24,"F2");
     if( p->changed==1 ) write_string( Blink + HINT_COLOR, 15, 24,"F2");

     if( ev.key==27 )				 /* ESC */
       {
        if( p->changed ) continue;
        break;
       }
     if( ev.key==13 || ev.key==9 )		/* Enter or Tab */
       {
        act=(act+1)%7;
       }
     else if( ev.scan==0x3B00 )				/* F1 - Help */
       {
        sprintf(tmp,"#setup_fat");
        html_view(tmp);
       }
     else if( ev.scan==0x50E0 || ev.scan==0x5000 )	/* down */
       {
        if( act<6 ) act++;
       }
     else if( ev.scan==0x48E0 || ev.scan==0x4800 )	/* up */
       {
        if( act>0 ) act--;
       }
     else if( ev.scan==0x3C00  )	           	/* F2 - Save */
       {
        if( p->inh_invalid || p->inh_changed )
          { show_error(ERROR_INH_INVAL); continue; }

        flush_caches();

        disk_lock(dinfo.disk);
        
        if( disk_write_rel(p,0,b,1)==-1 )
          {
           show_error("Error saving boot sector");
          }
        else
          {
           memmove(b_orig, b, SECT_SIZE);
          }

        disk_unlock(dinfo.disk);
       }
     else if( ev.scan==0x3D00  )	           	/* F3 - Undo */
       {
        memmove( b, b_orig, SECT_SIZE );
       }
     else if( ev.scan==0x3F00  )			/* F5 - Set */
       {
        b->drive_num=dinfo.disk;
        b->num_sides=dinfo.num_heads;
        b->num_sects=dinfo.num_sects;
        b->hid_sects=p->rel_sect;
        b->total_sect=(p->num_sect<65536L)?p->num_sect:0;
        b->big_total =(p->num_sect<65536L)?0:p->num_sect;
        b->magic_num=MBR_MAGIC_NUM;
       }
     else if( ev.scan==0x4000  )			/* F6 - Code */
       {
        memmove(b->xcode, fat_boot_code->xcode, sizeof(b->xcode) );
       }

    }/* while(1) */

 free(tmp);
 return OK;
}/* setup_fat */

⌨️ 快捷键说明

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