home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 February / PCWorld_2002-02_cd.bin / Software / Vyzkuste / ranish / SOURCES.ZIP / PART.C < prev    next >
Text File  |  1998-11-19  |  55KB  |  1,840 lines

  1. #define _PART_C
  2.  
  3. #include "part.h"
  4.  
  5.  
  6. int num_disks;
  7.  
  8.  
  9. void main(int argc, char **argv)
  10. {
  11.  int i;
  12.  hd=0x80;
  13.  
  14.  set_messages();
  15.  
  16.  get_base_dir(argv[0]);
  17.  
  18.  argc--;
  19.  argv++;
  20.  
  21.  while( argc!=0 && (argv[0][0]=='-' || argv[0][0]=='/') )
  22.     {
  23.      if( argv[0][1]=='D' || argv[0][1]=='d' && argc>1 )
  24.        {
  25.         i=atoi(argv[1]);
  26.         if( i<1 || i>16 ) usage();
  27.         hd+=i-1;
  28.         argc-=2;
  29.         argv+=2;
  30.        }
  31.      if( argv[0][1]=='Q' || argv[0][1]=='q' )
  32.        {
  33.         quiet=1;
  34.         argc--;
  35.         argv++;
  36.        }
  37.      else break;
  38.     }
  39.  
  40.  conio_init();
  41.  diskio_init();
  42.  
  43.  if( detected_os==SYS_WIN_NT )
  44.    {
  45.     fprintf(stderr,"This program will not run under Windows NT.\n"
  46.                    "Run it under DOS or Windows 95/98\n"
  47.                    "For more help visit http://www.intercom.com/~ranish\n");
  48.     exit(1);
  49.    }
  50.  
  51.  if( argc==0 )
  52.    {
  53.     interactive=1;
  54.     start_gui();
  55.    }
  56.  else
  57.    {
  58.     interactive=0;
  59.     command_line(argc,argv);
  60.    }
  61.  
  62.  diskio_exit();
  63.  conio_exit();
  64.  exit(0);
  65. }/* main */
  66.  
  67.  
  68. void start_gui(void)
  69. {
  70.  static struct part_long pseudo_part;
  71.  struct part_long *p=&pseudo_part;
  72.  
  73.  show_mouse();
  74.  move_mouse(80,25);
  75.  
  76.  while(1)
  77.     {
  78.      border_window( BORDER_COLOR, 1, 1, 80, 25, MAIN_BORDER );
  79.      write_string( TITLE_COLOR, 4, 2, PROGRAM_TITLE );
  80.      border_window( BORDER_COLOR, 2, 3, 78,  2, HRZN_BORDER );
  81.  
  82.      write_string(HEADER_COLOR,4,4, HEADER_GET );
  83.      write_int(TABLE_COLOR,14,4,2, hd-0x80+1 );
  84.  
  85.      if( (num_disks=get_disk_info(hd,&dinfo,buf))==-1 )
  86.        {
  87.         show_error(ERROR_DISK_INFO);
  88.         if( hd!=0x80 ) { hd=0x80; continue; }
  89.         break;
  90.        }
  91.  
  92.      p->level=0;
  93.      p->empty=0;
  94.      p->valid=1;
  95.      p->inh_changed=0;
  96.      p->inh_invalid=0;
  97.      p->inconsist_err=0;
  98.      p->boot_record_err=0;
  99.  
  100.      p->container=0;
  101.      p->container_base=0;
  102.         
  103.      p->start_cyl=0;     p->end_cyl=dinfo.num_cyls-1;
  104.      p->start_head=0;    p->end_head=dinfo.num_heads-1;
  105.      p->start_sect=1;    p->end_sect=dinfo.num_sects;
  106.            
  107.      p->rel_sect=0;
  108.      p->num_sect=dinfo.total_sects;
  109.  
  110.      select_target=0;
  111.      
  112.      setup_mbr(p);
  113.      
  114.      if( select_target==0 ) break;
  115.      
  116.      hd=(hd-0x80+1)%num_disks+0x80;
  117.     }
  118.  
  119.  clear_window( White+BakBlack, 1, 1, 80, 25 );
  120.  move_cursor(1,1);
  121.  hide_mouse();
  122. }/* start_gui */
  123.  
  124.  
  125. int setup_mbr(struct part_long *p)
  126. {
  127.  int i, j, n, top, row, field, scr_rows, num_rows;
  128.  int old_top, old_row, old_field, preview_mode, mx, my, pressed;
  129.  int valid, hint_y, view, ext_fix;
  130.  int force_redraw_header, force_redraw_menu, force_redraw_table;
  131.  int force_initialize, force_recalculate, force_adv_adjust;
  132.  int force_edit_menu, act_menu_sav=0, force_special_copy=1;
  133.  unsigned long *edit_target, edit_limit, empty_start;
  134.  char *hint=0, *mesg=0, *warn=0, *help=0, *data, *data_orig;
  135.  
  136.  int data_size;
  137.  struct mbr  *mbr;
  138.  struct adv  *adv;
  139.  struct part_long *part, *q;
  140.  
  141.  
  142.  static struct field_desc
  143.      {
  144.       unsigned long edit_limit;
  145.       int pos;
  146.       int len;
  147.      }*fd,
  148.  fd_chs[8]={ {0,4,8},{0,13,23}, {1023,37,4}, {255,42,4}, {63,47,4},
  149.                                 {1023,53,4}, {255,58,4}, {63,63,4} },
  150.  fd_lba[4]={ {0,4,8},{0,13,23}, {16777215,36,9},{16777215,46,10} };
  151.  
  152.  
  153.  view      = (p->level==0) ? VIEW_MBR : VIEW_EMBR ;
  154.  num_rows  = (p->level==0) ? MAX_PART_ROWS : 4 ;
  155.  data_size = (p->level==0) ? SECT_SIZE+ADV_DATA_SIZE : SECT_SIZE;
  156.  
  157.  if( (data=malloc(2*data_size))==0 )
  158.    { show_error(ERROR_MALLOC); return FAILED; }
  159.  if( (part=malloc(sizeof(struct part_long)*num_rows))==0 )
  160.    { show_error(ERROR_MALLOC); free(data); return FAILED; }
  161.  
  162.  memset( data, 0, 2*data_size );
  163.  
  164.  data_orig=data+data_size;
  165.  
  166.  mbr=(struct mbr*)(data);
  167.  adv=(struct adv*)(data+SECT_SIZE);
  168.  
  169.  if( disk_read_rel(p,0,mbr,1)==-1 )
  170.    {
  171.     show_error(ERROR_READ_MBR);
  172.     free(data);
  173.     free(part);
  174.     return FAILED;
  175.    }
  176.  
  177.  if( p->level==0 && ( mbr->x.adv.adv_mbr_magic==ADV_MBR_MAGIC ||
  178.         strcmp(mbr->x.adv_old.signature, ADV_DATA_SIGNATURE)==0 ) )
  179.    {
  180.     if( disk_read_rel( p, mbr->x.adv.rel_sect, adv, ADV_DATA_SECT )==-1 )
  181.       {
  182.        show_error(ERROR_READ_ADV);
  183.       }
  184.     if( strcmp(adv->signature,ADV_DATA_SIGNATURE)==0 )
  185.       {
  186.        view=VIEW_ADV;
  187.        act_menu_sav=mbr->x.adv.act_menu;
  188.       }
  189.     else
  190.       show_error(ERROR_ADV_BAD);
  191.    }
  192.  
  193.  if( mbr->x.new.bm_sign==BM_238_SIGN )
  194.    {
  195.     show_error("Partition Manager v2.38 or later was found. Please, use a newer version.");
  196.    }
  197.  
  198.  memmove( data_orig, data, data_size );
  199.  
  200.  top=0;
  201.  row=0;
  202.  field=0;
  203.  
  204.  pressed=0; 
  205.  preview_mode=0;
  206.  force_edit_menu=0;
  207.  force_initialize=1;
  208.  force_adv_adjust=0;
  209.  force_recalculate=0;
  210.  
  211.  if( p->level==0 && dinfo.num_cyls==dinfo.bios_num_cyls+1 )
  212.    {
  213.     sprintf(tmp3,MESG_BIOS_CYL,dinfo.bios_num_cyls);
  214.     mesg=tmp3;
  215.    }
  216.  
  217.  if( view==VIEW_ADV )
  218.    {
  219.     unsigned long *lp=(unsigned long*)mbr;
  220.     if( *lp!=0xD88EC033L )
  221.       show_error("Advanced Boot Manager code not found in MBR. Use F2 to reinstall the code.");
  222.    }
  223.  
  224.  while(1)
  225.     {
  226.      help=0;
  227.      
  228.      if( top!=old_top || row!=old_row || field!=old_field )
  229.        {
  230.         old_top=top;
  231.         old_row=row;
  232.         old_field=field;
  233.         force_redraw_table=1;
  234.        }
  235.      
  236.      if( force_initialize==1 )
  237.        {
  238.         if( view==VIEW_ADV )
  239.           {
  240.            if( adv->version>ADV_DATA_VERSION )
  241.              {
  242.               show_error(ERROR_ADV_VER);
  243.              }
  244.            if( adv->version<ADV_DATA_VERSION )
  245.              {
  246.               convert_adv_data(adv);
  247.               force_special_copy=1;
  248.              }
  249.  
  250.            hint_y=18;
  251.            scr_rows=8;
  252.            num_rows=MAX_PART_ROWS;
  253.            data_size=SECT_SIZE+ADV_DATA_SIZE;
  254.            unpack_adv_part_tab(adv->part, part, num_rows, p );
  255.           }
  256.         else
  257.           {
  258.            top=0;
  259.            hint_y=14;
  260.            num_rows=4;
  261.            scr_rows=4;
  262.            if( row>=4 ) row=0;
  263.            data_size=SECT_SIZE;
  264.            unpack_part_tab( mbr->part_rec, part, num_rows, p );
  265.           }
  266.  
  267.         valid=validate_table(part,num_rows,p);
  268.  
  269.         force_redraw_header=1;
  270.         force_redraw_table=1;
  271.         force_redraw_menu=1;
  272.         force_adv_adjust=1;
  273.         force_initialize=0;
  274.        }
  275.  
  276.      if( force_redraw_menu==1 )
  277.        {
  278.         redraw_menu(view);
  279.         force_redraw_menu=0;
  280.        }
  281.  
  282.      if( force_redraw_header==1 )
  283.        {
  284.         redraw_header(view,mode,p);
  285.         force_redraw_header=0;
  286.         force_redraw_table=1;
  287.        }
  288.  
  289.      if( force_recalculate==1 )
  290.        {
  291.         recalculate_part(&part[row],mode);
  292.         valid=validate_table(part,num_rows,p);
  293.         
  294.         force_redraw_table=1;
  295.         force_adv_adjust=1;
  296.         force_recalculate=0;
  297.        }
  298.      
  299.      if( view==VIEW_ADV && force_adv_adjust==1 )
  300.        {
  301.         struct part_long tmp;
  302.         int cur_row_was_unused;
  303.         
  304.         cur_row_was_unused = (part[row].os_id==0) ? 1 : 0;
  305.         
  306.         for( i=0 ; i<num_rows ; i++ )
  307.          if( part[i].os_id==OS_ADV ||
  308.              part[i].os_id==0 && i==num_rows-1 )
  309.            {
  310.             if( part[i].os_id==OS_ADV && part[i].num_sect>=ADV_NUM_SECTS ) break;
  311.             part[i].os_id=OS_ADV;
  312.             part[i].num_sect=ADV_NUM_SECTS;
  313.             determine_os_num(&part[i]);
  314.             recalculate_part(&part[i],MODE_LBA);
  315.             break;
  316.            }
  317.         
  318.         while(1)            /* Bubble sort all USED rows */
  319.            {
  320.             n=0;
  321.             for( i=0 ; i<num_rows-1 ; i++ )
  322.              if( part[i+1].os_id!=0 )
  323.                if( part[i].rel_sect>part[i+1].rel_sect )
  324.                  {
  325.                   tmp=part[i]; part[i]=part[i+1]; part[i+1]=tmp;
  326.                        if( row==i ) row++;
  327.                   else if( row==i+1 ) row--;
  328.                   n=1;
  329.                  } 
  330.                else if( part[i].os_id==0 )
  331.                  {
  332.                   tmp=part[i]; part[i]=part[i+1]; part[i+1]=tmp;
  333.                   if( row==i+1 ) row--;
  334.                   n=1;
  335.                  }
  336.             if( n==0 ) break;
  337.            }
  338.         
  339.         while( row>0 && part[row-1].os_id==0 ) row--;
  340.  
  341.         empty_start=1;                    /* fill unused space */
  342.         for( i=0 ; i<num_rows && part[i].os_id!=0 ; i++ )
  343.          if( part[i].rel_sect>empty_start )     /* add empty partition */
  344.            {
  345.             tmp=part[num_rows-1];
  346.             if( tmp.os_id!=0 )
  347.               { warn=ERROR_NO_UNUSED; break; }
  348.             for( j=num_rows-1 ; j>i ; j-- ) part[j]=part[j-1];
  349.             part[i]=tmp;
  350.             part[i].rel_sect=empty_start;
  351.             part[i].num_sect=part[i+1].rel_sect-empty_start;
  352.             recalculate_part(&part[i],MODE_LBA);
  353.             empty_start=part[i+1].rel_sect;
  354.             if( row>i || row==i && !cur_row_was_unused ) row++;
  355.            }
  356.          else empty_start=max(empty_start,part[i].rel_sect+part[i].num_sect);
  357.         
  358.         if( empty_start<p->num_sect && i!=num_rows )
  359.           {
  360.            part[i].rel_sect=empty_start;
  361.            part[i].num_sect=p->num_sect-empty_start;
  362.            recalculate_part(&part[i],MODE_LBA);
  363.            i++;
  364.           }
  365.  
  366.         for( ; i<num_rows ; i++ )
  367.          if( part[i].os_id==0 )
  368.            {
  369.             part[i].rel_sect=0;
  370.             part[i].num_sect=0;
  371.             recalculate_part(&part[i],MODE_LBA);
  372.            }
  373.         
  374.         valid=validate_table(part,num_rows,p);
  375.         
  376.         for( i=0 ; i<num_rows ; i++ )
  377.          if( part[i].os_id==OS_ADV )
  378.            {
  379.             if( part[i].num_sect<ADV_NUM_SECTS )
  380.               {
  381.                part[i].mbr_err=1;
  382.                part[i].valid=0;
  383.                valid=0;
  384.               }
  385.             break;
  386.            }
  387.  
  388.         if( row<top || row>=top+scr_rows ) top=row;
  389.         if( top+scr_rows>num_rows ) top=num_rows-scr_rows;
  390.         
  391.         old_top=top;
  392.         old_row=row;
  393.  
  394.         force_adv_adjust=0;
  395.        }
  396.       
  397.      if( force_redraw_table==1 )
  398.        {
  399.         for( i=0 ; i<scr_rows ; i++ )
  400.           {
  401.            sprintf_partrec(tmp, &part[top+i], top+i+1, view );  tmp[76]=0;
  402.            if( part[top+i].empty || part[top+i].valid )
  403.              {
  404.               if( part[top+i].os_id!=0 ) 
  405.                  write_string(TABLE_COLOR,3,i+9,tmp);
  406.               else
  407.                  write_string(HEADER_COLOR,3,i+9,tmp);
  408.              }
  409.            else
  410.               write_string(INVAL_COLOR,3,i+9,tmp);
  411.           }
  412.           
  413.         if( top>0 )
  414.           {
  415.            int color=HINT_COLOR;
  416.            for( i=0 ; i<top ; i++ )
  417.             if( !part[i].empty && !part[i].valid ) color=INVAL_COLOR;
  418.            write_string( color, 73, 8, "more ");
  419.           }
  420.         else write_string( HINT_COLOR, 73, 8, "      ");
  421.  
  422.         if( top+scr_rows<num_rows )
  423.           {
  424.            int color=HINT_COLOR;
  425.            for( i=top+scr_rows ; i<num_rows ; i++ )
  426.             if( !part[i].empty && !part[i].valid ) color=INVAL_COLOR;
  427.            write_string( color, 73, hint_y-1, "more ");
  428.           }
  429.         else write_string( HINT_COLOR, 73, hint_y-1, "      ");
  430.  
  431.         write_string(INVAL_COLOR,64,hint_y+1,"              ");
  432.         write_string(INVAL_COLOR,67,hint_y+2,"           ");
  433.         write_string(INVAL_COLOR,70,hint_y+3,"        ");
  434.         write_string(INVAL_COLOR,73,hint_y+4,"     ");
  435.  
  436.         if( part[row].empty==0 )
  437.           {
  438.            if( part[row].inconsist_err ) write_string(INVAL_COLOR,64,hint_y+1,ERR_INCONS);
  439.            else if( part[row].boot_record_err ) write_string(INVAL_COLOR,64,hint_y+1,ERR_BOOTREC);
  440.            if( part[row].overlap_err )   write_string(INVAL_COLOR,67,hint_y+2,ERR_OVERLAP);
  441.            if( part[row].range_err )     write_string(INVAL_COLOR,70,hint_y+3,ERR_RANGE);
  442.            if( part[row].mbr_err )       write_string(INVAL_COLOR,73,hint_y+4,ERR_MBR);
  443.           }
  444.         
  445.         force_redraw_table=0;
  446.        }
  447.      
  448.      if( view==VIEW_ADV )
  449.        pack_adv_part_tab( part, adv->part, num_rows );
  450.      else
  451.        pack_part_tab( part, mbr->part_rec, num_rows );
  452.  
  453.      if( force_special_copy==1 )
  454.        {
  455.         memmove(data_orig, data, data_size);
  456.         force_special_copy=0;
  457.        }
  458.  
  459.      p->changed = ( memcmp(data, data_orig, data_size)==0 ) ? 0 : 1;
  460.  
  461.      if( p->changed==0 ) write_string(         HINT_COLOR, 15, 24,"F2");
  462.      if( p->changed==1 ) write_string( Blink + HINT_COLOR, 15, 24,"F2");
  463.  
  464.      if( field==0 )                        /* Active: Yes/No */
  465.        {
  466.         if( view==VIEW_ADV )
  467.           {
  468.            write_string(ACTIVE_COLOR,6,row-top+9,(part[row].active)?" Menu ":"  No  ");
  469.            move_cursor((part[row].active)?7:8,row-top+9);
  470.            hint=HINT_ADV;
  471.           }
  472.         else
  473.           {
  474.            write_string(ACTIVE_COLOR,7,row-top+9,(part[row].active)?" Yes ":" No  ");
  475.            move_cursor(8,row-top+9);
  476.            hint=HINT_INS;
  477.           }
  478.        }
  479.      else if( field==1 )                /* Partition Type */
  480.        {
  481.         write_string(ACTIVE_COLOR,13,row-top+9, sprintf_os_name(tmp,&part[row]) );
  482.         move_cursor(13,row-top+9);
  483.         hint = (view==VIEW_ADV) ? HINT_ADV : HINT_INS;
  484.        }
  485.      else if( mode==MODE_CHS && field==2 ) edit_target=&part[row].start_cyl;
  486.      else if( mode==MODE_CHS && field==3 ) edit_target=&part[row].start_head;
  487.      else if( mode==MODE_CHS && field==4 ) edit_target=&part[row].start_sect;
  488.      else if( mode==MODE_CHS && field==5 ) edit_target=&part[row].end_cyl;
  489.      else if( mode==MODE_CHS && field==6 ) edit_target=&part[row].end_head;
  490.      else if( mode==MODE_CHS && field==7 ) edit_target=&part[row].end_sect;
  491.      else if( mode==MODE_LBA && field==2 ) edit_target=&part[row].rel_sect;
  492.      else if( mode==MODE_LBA && field==3 ) edit_target=&part[row].num_sect;
  493.  
  494.      ext_fix=(p->level>1 && part[row].os_id==OS_EXT);
  495.  
  496.      if( field>1 )
  497.        {
  498.         fd = ( mode==MODE_CHS ) ? &fd_chs[field] : &fd_lba[field];
  499.         edit_limit = fd->edit_limit;
  500.         write_int( ACTIVE_COLOR, fd->pos, row-top+9, fd->len, *edit_target );
  501.         move_cursor( fd->pos+fd->len-1, row-top+9 );
  502.         
  503.         if( mode==MODE_CHS )
  504.           sprintf(tmp, HINT_CHS, ext_fix ? p->end_cyl+1 : part[row].container->start_cyl, part[row].container->end_cyl, dinfo.num_heads-1, dinfo.num_sects );
  505.         else
  506.           sprintf(tmp, HINT_LBA, ext_fix ? p->rel_sect+p->num_sect : 1, part[row].container->num_sect-1, part[row].container->num_sect-1 - (ext_fix ? p->rel_sect+p->num_sect-1 : 0));
  507.  
  508.         hint=tmp;
  509.        }
  510.  
  511.      clear_window(BORDER_COLOR,2,hint_y,78,1);
  512.      
  513.           if( warn!=0 )  write_string(WARN_COLOR,7,hint_y,warn);
  514.      else if( mesg!=0 )  write_string(MESG_COLOR,7,hint_y,mesg);
  515.      else if( hint!=0 )  write_string(HINT_COLOR,7,hint_y,hint);
  516.  
  517.      if( view==VIEW_EMBR ) help="#extended";
  518.      if( !valid ) help="#conflict";
  519.      
  520.      for( i=0 ; i<num_rows ; i++ )
  521.         {
  522.          part[i].inh_changed = ( p->changed || p->inh_changed ) ? 1 : 0;
  523.          part[i].inh_invalid = ( !part[i].valid || p->inh_invalid ) ? 1 : 0;
  524.         }
  525.                                                    
  526.  
  527.      if( force_edit_menu==1 )
  528.        {
  529.         edit_boot_menu(adv,0,1);
  530.         force_initialize=1;
  531.         force_edit_menu=0;
  532.         continue;
  533.        }
  534.  
  535.      mx=0;
  536.      my=0;
  537.  
  538.      while(1)
  539.         {
  540.          get_event( &ev, EV_KEY | EV_MOUSE );
  541.  
  542.          if( ev.ev_type & EV_KEY ) break;
  543.          if( ev.ev_type & EV_MOUSE )
  544.            {
  545. /*
  546.             sprintf(tmp,"y=%2d  x=%2d",ev.y, ev.x);
  547.             write_string(BrCyan+BakBlue,68,23,tmp);
  548. */
  549.             if( pressed==0 && ev.left==1 ){ pressed=1; mx=ev.x; my=ev.y; break;}
  550.             if( pressed==1 && ev.left==0 ){ pressed=0; }
  551.            }
  552.         }/* while - get event */
  553.  
  554.      #define CLICK(y,x1,x2)          ((mx)>=(x1)&&(mx)<=(x2)&&(my)==(y))
  555.  
  556.      if( hint==HINT_INS || hint==HINT_ADV )
  557.        {
  558.         if( CLICK(hint_y,7,30) )  ev.key=0x20;    /* Space */
  559.         if( CLICK(hint_y,32,57) ) ev.scan=0x5200; /* Ins */
  560.         if( CLICK(hint_y,59,74) ) ev.key=0x0D;    /* Enter */
  561.        }
  562.  
  563.      hint=mesg=warn=0;
  564.      
  565.      if( ev.scan==0x6700 )        /* Ctrl-F10 - Unconditional Exit */
  566.        {
  567.         exit(1);
  568.        }
  569.  
  570.  
  571.      if( preview_mode==1 && (ev.key==27 || CLICK(24,68,77)) )
  572.        {
  573.         view=VIEW_ADV;
  574.         preview_mode=0;
  575.         force_initialize=1;
  576.         continue;
  577.        }
  578.      
  579.      if( ev.key==27 || CLICK(24,68,77) )          /* ESC - Quit */
  580.        {
  581.         if( p->changed==0 ) break;
  582.         mesg=MESG_NOT_SAVED;
  583.         continue;
  584.        }
  585.  
  586.      if( CLICK(2,3,78) )
  587.        {
  588.         html_view("#contact");
  589.         continue;
  590.        }
  591.  
  592.      if( (ev.ev_type & (EV_MOUSE | EV_TIMER)) && my>=9 && my<9+scr_rows )
  593.        {
  594.         int n = (mode==MODE_CHS) ? 8 : 4;
  595.  
  596.         fd = (mode==MODE_CHS) ? fd_chs : fd_lba;
  597.  
  598.         for( i=0 ; i<n ; i++ )
  599.          if( mx>=fd[i].pos && mx<fd[i].pos+fd[i].len )
  600.            {
  601.             row=my-9+top;
  602.             field=i;
  603.             break;
  604.            }
  605.         continue;
  606.        }
  607.  
  608.      if( !valid && ( CLICK(hint_y+1,64,77) || CLICK(hint_y+2,66,77) ||
  609.                      CLICK(hint_y+3,68,77) || CLICK(hint_y+4,70,77)  ) )
  610.         {
  611.         html_view("#conflict");
  612.         continue;
  613.         }
  614.  
  615.      if( view==VIEW_EMBR && (ev.scan==0x49E0 || ev.scan==0x4900) )/* PgUp */
  616.        {
  617.         if( p->changed==0 ) break;
  618.         continue;
  619.        }
  620.  
  621.      if( view!=VIEW_ADV && (ev.scan==0x51E0 || ev.scan==0x5100) )/* PgDn */
  622.        {
  623.         for( i=0 ; i<num_rows ; i++ )
  624.          if( part[i].os_id==OS_EXT ) break;
  625.         
  626.         if( i!=num_rows )
  627.           {
  628.            os_desc[part[i].os_num].setup(&part[i]);
  629.            force_redraw_header=1;
  630.            force_redraw_table=1;
  631.            force_redraw_menu=1;
  632.           }
  633.         continue;
  634.        }
  635.  
  636.      if( (field==0 || field==1) && ev.key==0x0D )    /* Enter - Setup */
  637.        {
  638.         if( part[row].empty ) continue;
  639.         if( part[row].os_id==0 ) continue;
  640.  
  641.         if( part[row].os_id==OS_ADV )
  642.           {
  643.            edit_boot_menu(adv,row,1);
  644.           }
  645.         else
  646.           {
  647.            if( os_desc[part[row].os_num].setup==0 )
  648.              { show_error(ERROR_NO_SETUP); continue; }
  649.  
  650.            os_desc[part[row].os_num].setup(&part[row]);
  651.           }
  652.  
  653.         force_redraw_header=1;
  654.         force_redraw_table=1;
  655.         force_redraw_menu=1;
  656.         continue;
  657.        }
  658.  
  659.      if( ev.scan==0x0F09 )                 /* Tab */
  660.        {
  661.              if( field==0 || field==1 ) field=2;
  662.         else if( mode==MODE_CHS && field<5 ) field=5;
  663.         else if( mode==MODE_LBA && field<3 ) field=3;
  664.         else field=0;
  665.         continue;
  666.        }
  667.  
  668.      if( field>1 && ev.key==0x0D )            /* Enter - MoveOn */
  669.        {
  670.              if( mode==MODE_CHS && field<5 ) field=5;
  671.         else if( mode==MODE_LBA && field<3 ) field=3;
  672.         else field=0;
  673.         continue;
  674.        }
  675.  
  676.      if( ev.scan==0x4BE0 || ev.scan==0x4B00 )     /* left */
  677.        {
  678.         if( field>0 ) field--;
  679.         continue;
  680.        }
  681.  
  682.      if( ev.scan==0x4DE0 || ev.scan==0x4D00 )     /* right */
  683.        {
  684.         if( mode==MODE_CHS && field<7 ) field++;
  685.         if( mode==MODE_LBA && field<3 ) field++;
  686.         continue;
  687.        }
  688.  
  689.      if( ev.scan==0x50E0 || ev.scan==0x5000 )    /* down */
  690.        {
  691.         if( row<num_rows-1 ) row++;
  692.         if( top+scr_rows<=row ) top++;
  693.         continue;
  694.        }
  695.  
  696.      if( ev.scan==0x48E0 || ev.scan==0x4800 )     /* up */
  697.        {
  698.         if( row>0 ) row--;
  699.         if( top>row ) top--;
  700.         continue;
  701.        }
  702.  
  703.      if( ev.scan==0x4FE0 || ev.scan==0x4F00  )     /* End */
  704.        {
  705.         row=num_rows-1;
  706.         top=row+1-scr_rows;
  707.         continue;
  708.        }
  709.  
  710.      if( ev.scan==0x47E0 || ev.scan==0x4700  )    /* Home */
  711.        {
  712.         row=0;
  713.         top=0;
  714.         continue;
  715.        }
  716.  
  717.      if( view==VIEW_ADV &&
  718.         (ev.scan==0x49E0 || ev.scan==0x4900 || CLICK(8,73,78)) )/* PgUp */
  719.        {
  720.         row = (row>=scr_rows) ? row-scr_rows : 0;
  721.         top = (top>=scr_rows) ? top-scr_rows : 0;
  722.         continue;
  723.        }
  724.  
  725.      if( view==VIEW_ADV &&
  726.         (ev.scan==0x51E0 || ev.scan==0x5100 || CLICK(hint_y-1,73,78)) )/* PgDn */
  727.        {
  728.         row = (row<num_rows-scr_rows) ? row+scr_rows : num_rows-1;
  729.         top = (top<num_rows-2*scr_rows) ? top+scr_rows : num_rows-scr_rows;
  730.         continue;
  731.        }
  732.  
  733.      if( ev.scan==0x3B00 || CLICK(24,4,12) )              /* F1 - Help */
  734.        {
  735.         html_view(help);
  736.         continue;
  737.        }
  738.  
  739.      if( ev.scan==0x3E00 || CLICK(24,45,53) )        /* F4 - Mode */
  740.        {
  741.         if( mode==MODE_CHS )
  742.           {
  743.            mode=MODE_LBA;
  744.            if( field==2 || field==3 || field==4 ) field=2;
  745.            if( field==5 || field==6 || field==7 ) field=3;
  746.           }
  747.         else
  748.           {
  749.            mode=MODE_CHS;
  750.            if( field==2 ) field=2;
  751.            if( field==3 ) field=5;
  752.           }
  753.         force_redraw_header=1;
  754.         continue;
  755.        }
  756.  
  757.      if( ev.key=='F' || ev.key=='f' || CLICK(20,11,38) )    /* Format */
  758.        {
  759.         int fstatus;
  760.  
  761. #define NUM_ARGS  10
  762.  
  763.         char *argv[NUM_ARGS];
  764.         
  765.         if(  part[row].empty ) continue;
  766.  
  767.         if( os_desc[part[row].os_num].format==0 )
  768.           { show_error(ERROR_NO_FORMAT); continue; }
  769.  
  770.         if( part[row].inh_invalid )
  771.           { show_error(ERROR_FIX_FIRST); continue; }
  772.  
  773.         if( part[row].inh_changed ) { mesg=MESG_NOT_SAVED; continue; }
  774.  
  775.         sprintf(tmp2,"#0x%04X",part[row].os_id);
  776.  
  777.         if( enter_string(4,hint_y,PROMPT_FORMAT,sizeof(tmp),tmp,tmp2)==0 ) continue;
  778.         
  779.         parse_arg(tmp,argv,NUM_ARGS);
  780.         
  781.         fstatus=os_desc[part[row].os_num].format(&part[row],argv);
  782.  
  783.              if( fstatus==OK )     mesg=MESG_FORMAT_OK;
  784.         else if( fstatus==CANCEL ) mesg=WARN_FORMAT_CANCEL;
  785.         else if( fstatus==FAILED ) show_error(ERROR_FORMAT_FAILED);
  786.  
  787.         force_redraw_header=1;
  788.         force_redraw_table=1;
  789.         force_redraw_menu=1;
  790.         continue;
  791.        }
  792.  
  793.      if( ev.key=='V' || ev.key=='v' || CLICK(21,11,38) )    /* Verify */
  794.        {
  795.         int fstatus;
  796.         
  797.         if(  part[row].empty ) continue;
  798.  
  799.         if( part[row].valid==0 )
  800.           { show_error(ERROR_FIX_FIRST); continue; }
  801.  
  802.         fstatus=generic_verify(&part[row],0,0);
  803.  
  804.              if( fstatus==OK )     mesg=MESG_VERIFY_OK;
  805.         else if( fstatus==CANCEL ) mesg=WARN_VERIFY_CANCEL;
  806.         else if( fstatus==FAILED ) show_error(ERROR_VERIFY_FAILED);
  807.  
  808.         force_redraw_header=1;
  809.         force_redraw_table=1;
  810.         force_redraw_menu=1;
  811.         continue;
  812.        }
  813.  
  814.      if( preview_mode==1 )
  815.        {
  816.         mesg=HINT_RETURN;
  817.         continue;
  818.        }
  819.      
  820.      if( view==VIEW_ADV && (ev.key=='P' || ev.key=='p' || CLICK(22,11,38)) )
  821.        {
  822.         preview_mode=1;
  823.         view=VIEW_MBR;
  824.         force_initialize=1;
  825.         mesg=HINT_RETURN;
  826.         continue;
  827.        }
  828.  
  829.      
  830.      if( view!=VIEW_ADV && (ev.key=='Y' || ev.key=='y' ||
  831.                             ev.key==' ' && part[row].active==0 ) )
  832.        {
  833.         for( i=0 ; i<num_rows ; i++ )
  834.            part[i].active=0;
  835.         part[row].active=1;
  836.         force_redraw_table=1;
  837.         continue;
  838.        }
  839.  
  840.      if( view!=VIEW_ADV && (ev.key=='N' || ev.key=='n' ||
  841.                             ev.key==' ' && part[row].active==1 ) )
  842.        {
  843.         part[row].active=0;
  844.         force_redraw_table=1;
  845.         continue;
  846.        }
  847.  
  848.      if( view==VIEW_ADV && ev.key==' ' )        /* Edit Boot Menu */
  849.        {
  850.         edit_boot_menu(adv,row,0);
  851.         force_initialize=1;
  852.         continue;
  853.        }
  854.  
  855.      if( ev.scan==0x52E0 || ev.scan==0x5200 )             /* Insert */
  856.        {
  857.         int prev_os_id=part[row].os_id;
  858.            
  859.         if( view==VIEW_ADV && part[row].os_id==OS_ADV ) continue;
  860.         
  861.         if( view==VIEW_EMBR && row==1 && part[row].os_id==0 )
  862.           {
  863.            part[row].os_id=OS_EXT;
  864.            determine_os_num(&part[row]);
  865.           }
  866.  
  867.         select_system_type(&part[row]);
  868.  
  869.         if( part[row].level>2 && part[row].os_id==OS_EXT )
  870.            part[row].container = p->container;
  871.         else
  872.            part[row].container = p;
  873.         part[row].container_base = QUICK_BASE(part[row].container);
  874.  
  875.         if( view==VIEW_MBR && row==0 && part[0].empty && part[0].os_id!=0
  876.                                      && part[1].empty
  877.                                      && part[2].empty
  878.                                      && part[3].empty ) part[0].active=1;
  879.  
  880.         if( part[row].empty && part[row].os_num!=0 )
  881.           {
  882.            if( mode==MODE_CHS )
  883.              {
  884.               unsigned long start_head, start_cyl, end_cyl;
  885.  
  886.               start_cyl  = p->start_cyl;
  887.               end_cyl    = part[row].container->end_cyl;
  888.  
  889.               start_head = ( row==0 ) ? 1 : 0;
  890.               
  891.               if( row>0 && !part[row-1].empty )
  892.                 {
  893.                  start_cyl=part[row-1].end_cyl+1;
  894.                 }
  895.               
  896.  
  897.               if( part[row].level>2 && part[row].os_id==OS_EXT )
  898.                 {
  899.                  start_cyl=p->end_cyl+1;
  900.                 }
  901.               else if( row<3 && !part[row+1].empty )
  902.                {
  903.                 end_cyl = part[row+1].start_cyl-1;
  904.                }
  905.  
  906.               part[row].start_cyl  = start_cyl;
  907.               part[row].start_head = start_head;
  908.               part[row].start_sect = 1;
  909.               part[row].end_cyl    = end_cyl;
  910.               part[row].end_head   = dinfo.num_heads-1;
  911.               part[row].end_sect   = dinfo.num_sects;
  912.              }
  913.            else
  914.              {
  915.               if( row>0 && !part[row-1].empty )
  916.                 part[row].rel_sect = part[row-1].rel_sect+part[row-1].num_sect;
  917.               else
  918.                 part[row].rel_sect = dinfo.num_sects;
  919.               
  920.               if( row<3 && !part[row+1].empty )
  921.                 part[row].num_sect = part[row+1].rel_sect-part[row].rel_sect;
  922.               else
  923.                 part[row].num_sect = part[row].container->num_sect -
  924.                                                           part[row].rel_sect; 
  925.  
  926.               if( part[row].level>2 && part[row].os_id==OS_EXT )
  927.                 {
  928.                  part[row].rel_sect = p->rel_sect+p->num_sect;
  929.                  part[row].num_sect = part[row].container->num_sect -
  930.                                                           part[row].rel_sect; 
  931.                 }
  932.              }
  933.            field=2;
  934.            force_recalculate=1;
  935.           }
  936.         
  937.         if( prev_os_id==0 && part[row].os_num!=0 )
  938.           {
  939.            field=2;
  940.           }
  941.  
  942.         force_redraw_header=1;
  943.         force_redraw_table=1;
  944.         force_redraw_menu=1;
  945.         continue;
  946.        }/* insert */
  947.  
  948.  
  949.      if( field<2 )
  950.        {
  951.         /* do nothing -> threfore else will be only for field>=2 (long ints) */
  952.        }
  953.      else if( ev.key == 8 || ev.scan==0x53E0 || ev.scan==0x5300 )/* BkSp/Del */
  954.        {
  955.         *edit_target/=10;
  956.         force_recalculate=1;
  957.         continue;
  958.        }
  959.      else if( ev.key>='0' && ev.key<='9' )
  960.        {
  961.         int x=ev.key-'0';
  962.         
  963.         if( edit_limit>x && (edit_limit-x)/10>=*edit_target )
  964.           {
  965.            *edit_target = *edit_target*10 + x;
  966.            force_recalculate=1;
  967.           }
  968.         
  969.         continue;
  970.        }
  971.      else if( mode==MODE_CHS && ev.key=='+' )
  972.        {
  973.         if( *edit_target<edit_limit )
  974.           {
  975.            (*edit_target)++;
  976.            force_recalculate=1;
  977.           }
  978.         continue;
  979.        }
  980.      else if( mode==MODE_CHS && ev.key=='-' )
  981.        {
  982.         if( *edit_target>0 )
  983.           {
  984.            (*edit_target)--;
  985.            force_recalculate=1;
  986.           }
  987.         continue;
  988.        }
  989.      else if( mode==MODE_LBA && ev.key=='+' )
  990.        {
  991.         unsigned long x=*edit_target-*edit_target%dinfo.sect_per_track;
  992.  
  993.         if( edit_limit>dinfo.sect_per_track && edit_limit-dinfo.sect_per_track>x )
  994.           {
  995.            *edit_target=x+dinfo.sect_per_track;
  996.            force_recalculate=1;
  997.           }
  998.  
  999.         continue;
  1000.        }
  1001.      else if( mode==MODE_LBA && ev.key=='-' )
  1002.        {
  1003.         if( *edit_target>0 )
  1004.           {
  1005.            (*edit_target)--;
  1006.            *edit_target-=*edit_target%dinfo.sect_per_track;
  1007.            force_recalculate=1;
  1008.           }
  1009.         continue;
  1010.        }
  1011.  
  1012.  
  1013.      if( ev.scan==0x53E0 || ev.scan==0x5300 )     /* Delete */
  1014.        {
  1015.         if( view==VIEW_ADV && part[row].os_id==OS_ADV ) continue;
  1016.         part[row].empty=1;
  1017.         part[row].valid=0;
  1018.         part[row].os_id=0;
  1019.         part[row].os_num=0;
  1020.         part[row].active=0;
  1021.         part[row].orig_row=0;
  1022.         part[row].start_cyl=0;   part[row].end_cyl=0;
  1023.         part[row].start_head=0;  part[row].end_head=0;
  1024.         part[row].start_sect=0;  part[row].end_sect=0;
  1025.         part[row].rel_sect=0;
  1026.         part[row].num_sect=0;
  1027.         force_recalculate=1;
  1028.         force_redraw_table=1;
  1029.         continue;
  1030.        }
  1031.  
  1032.      if( ev.scan==0x3C00 || CLICK(24,15,31) )               /* F2 - Save */
  1033.        {
  1034.         if( view==VIEW_ADV )
  1035.           {
  1036.            if( !valid )
  1037.              { show_error(ERROR_FIX_FIRST); continue; }
  1038.  
  1039.            if( !prepare_adv_mbr_for_save(part,mbr,adv) )
  1040.              { show_error(ERROR_NO_ADV); continue; }
  1041.            
  1042.            mbr->x.adv.act_menu=act_menu_sav;
  1043.           }
  1044.         else if( p->inh_invalid || p->inh_changed )
  1045.           { show_error(ERROR_INH_INVAL); continue; }
  1046.  
  1047.         disk_lock(dinfo.disk);
  1048.         
  1049.         mbr->magic_num=MBR_MAGIC_NUM;
  1050.  
  1051.         if( view==VIEW_ADV && 
  1052.             (disk_write_rel(p,mbr->x.adv.rel_sect,adv,ADV_DATA_SECT)==-1 ||
  1053.              disk_write_rel(p,mbr->x.adv.rel_sect+ADV_DATA_SECT,
  1054.                                           ADV_MANAGER,ADV_CODE_SECT)==-1 ) )
  1055.           {
  1056.            warn=ERROR_SAVE_ADV;
  1057.           }
  1058.         else if( disk_write_rel(p,0,mbr,1)==-1 )
  1059.           {
  1060.            warn=ERROR_SAVE_MBR;
  1061.           }
  1062.         else
  1063.           {
  1064.            mesg=MESG_MBR_SAVED;
  1065.            memmove(data_orig, data, data_size);
  1066.           }
  1067.  
  1068.         disk_unlock(dinfo.disk);
  1069.         force_recalculate=1;
  1070.         force_adv_adjust=1;
  1071.         force_special_copy=1;
  1072.         continue;
  1073.        }
  1074.  
  1075.      if( ev.scan==0x3D00 || CLICK(24,34,42) )                      /* F3 - Undo */
  1076.        {
  1077.         memmove(data, data_orig, data_size);
  1078.         if( view==VIEW_MBR && ( mbr->x.adv.adv_mbr_magic==ADV_MBR_MAGIC ||
  1079.             strcmp(mbr->x.adv_old.signature, ADV_DATA_SIGNATURE)==0 ) )
  1080.           {
  1081.            memmove(data, data_orig, SECT_SIZE+ADV_DATA_SIZE);
  1082.            view=VIEW_ADV;
  1083.           }
  1084.         else if( view==VIEW_ADV && mbr->x.adv.adv_mbr_magic!=ADV_MBR_MAGIC &&
  1085.                  strcmp(mbr->x.adv_old.signature, ADV_DATA_SIGNATURE)!=0 )
  1086.           {
  1087.            view=VIEW_MBR;
  1088.           }
  1089.           
  1090.         if( view==VIEW_ADV &&
  1091.             strcmp(adv->signature, ADV_DATA_SIGNATURE)!=0 )
  1092.           {
  1093.            view=VIEW_MBR;
  1094.           }
  1095.  
  1096.         force_initialize=1;
  1097.         continue;
  1098.        }
  1099.  
  1100.  
  1101.      if( p->level==0 && (ev.scan==0x3F00 || CLICK(24,56,64) ) )    /* F5 - Disk */
  1102.        {
  1103.         if( p->changed ) { mesg=MESG_NOT_SAVED; continue; }
  1104.         select_target=1;
  1105.         break;
  1106.        }
  1107.  
  1108.      if( view!=VIEW_ADV && (ev.key=='H' || ev.key=='h' || CLICK(19,11,38)) )
  1109.        {                            /* Hide */
  1110.         if( part[row].os_id==0x0100 ||
  1111.             part[row].os_id==0x0400 || 
  1112.             part[row].os_id==0x0600 || 
  1113.             part[row].os_id==0x0700 || 
  1114.             part[row].os_id==0x0B00 ) part[row].os_id+=0x1000;
  1115.         else
  1116.         if( part[row].os_id==0x1100 ||
  1117.             part[row].os_id==0x1400 || 
  1118.             part[row].os_id==0x1600 || 
  1119.             part[row].os_id==0x1700 || 
  1120.             part[row].os_id==0x1B00 ) part[row].os_id-=0x1000;
  1121.         else
  1122.             part[row].os_id=OS_HIDDEN;
  1123.         determine_os_num(&part[row]);
  1124.         force_redraw_table=1;
  1125.         continue;
  1126.        }
  1127.  
  1128.      if( view==VIEW_MBR && (ev.key=='U' || ev.key=='u' || CLICK(17,11,61)) )
  1129.        {                            /* Uninstall */
  1130.         memmove( mbr, STD_IPL, sizeof(mbr->x.std.code) );
  1131.         mesg=MESG_UNINSTALL;
  1132.         continue;
  1133.        }
  1134.  
  1135.  
  1136.      if( view==VIEW_ADV && (ev.key=='U' || ev.key=='u' || CLICK(22,42,68)) )
  1137.        {                        /* Uninstall Advanced */
  1138.         int n, x;
  1139.  
  1140.         unpack_adv_part_tab(adv->part, part, MAX_PART_ROWS, p );
  1141.         force_initialize=1;
  1142.  
  1143.         for( i=0, n=0 ; i<MAX_PART_ROWS ; i++ )
  1144.          if( part[i].os_id!=0 && part[i].os_id!=OS_ADV ) n++;
  1145.             
  1146.         if( n>4 )
  1147.           { show_error(ERROR_GR_FOUR); continue; }
  1148.  
  1149.         for( i=0, n=0, x=dinfo.disk ; i<MAX_PART_ROWS ; i++ )
  1150.          if( part[i].os_id!=0 && part[i].os_id!=OS_ADV )
  1151.            {
  1152.             if( i==n ) { n++; continue; }
  1153.             if( part[i].active ) { part[i].active=x; x=0; }
  1154.             part[n++]=part[i];
  1155.            }
  1156.         
  1157.         if( x!=0 && n!=0 && part[0].os_id!=0 ) part[0].active=x;
  1158.         
  1159.         if( n<4 ) memset(part+n,0,(4-n)*sizeof(struct part_long));
  1160.  
  1161.         for( x=0 ; x<n ; x++ )
  1162.           for( i=0 ; i<4 ; i++ )
  1163.            if( part[i].os_id!=0 && part[i].orig_row!=0 && part[i].orig_row!=i )
  1164.              {
  1165.               int r=part[i].orig_row-1;
  1166.               part[4]=part[r];
  1167.               part[r]=part[i];
  1168.               part[i]=part[4];
  1169.              }
  1170.  
  1171.         pack_part_tab(part,mbr->part_rec,4);
  1172.  
  1173.         
  1174.         if( mbr->x.adv.adv_mbr_magic==ADV_MBR_MAGIC ||
  1175.             strcmp(mbr->x.adv_old.signature, ADV_DATA_SIGNATURE)==0 )
  1176.           {
  1177.            memset(  mbr, 0, 0x1BE );
  1178.            memmove( mbr, STD_IPL, sizeof(mbr->x.std.code) );
  1179.           }
  1180.  
  1181.         mesg=MESG_UNINSTALL;
  1182.         force_initialize=1;
  1183.         view=VIEW_MBR;
  1184.         continue;
  1185.        }
  1186.  
  1187.  
  1188.      if( view==VIEW_EMBR && (ev.key=='I' || ev.key=='i' || CLICK(16,11,60)) )
  1189.        {                 /* Install dummy boot rec into EMBR */
  1190.         memmove(mbr->x.std.code, EMP_IPL, EMP_SIZE );
  1191.         strncpy(mbr->x.std.code + EMP_SIZE, MESG_EXT_NONBOOT,
  1192.                                  sizeof(mbr->x.std.code)-EMP_SIZE);
  1193.         mesg=MESG_INSTALL;
  1194.        }
  1195.      else if( view==VIEW_EMBR && (ev.key=='R' || ev.key=='r' || CLICK(17,11,60)) )
  1196.        {                /* Read how to make ext bootable */
  1197.         html_view("#make_primary");
  1198.        }
  1199.      else if( view==VIEW_MBR && (ev.key=='A' || ev.key=='a' || CLICK(16,49,61)))
  1200.        {                        /* Install Advanced */
  1201.         int m;
  1202.         struct adv_part_rec tmp_part_rec;
  1203.  
  1204.         if( !valid )
  1205.           { show_error(ERROR_FIX_FIRST); continue; }
  1206.         
  1207.         memset(adv,0,ADV_DATA_SIZE);
  1208.         
  1209.         strcpy(adv->signature,ADV_DATA_SIGNATURE);
  1210.         adv->version=ADV_DATA_VERSION;
  1211.         strncpy(adv->adv_title,MANAGER_TITLE,sizeof(adv->adv_title));
  1212.         
  1213.         m=0;
  1214.         
  1215.         if( dinfo.disk==0x80 )
  1216.           {
  1217.            adv->menu[m].boot_type =  MENU_BOOT_FLOPPY;
  1218.            sprintf( adv->menu[m].name, "Boot from floppy");
  1219.            m++;
  1220.           }
  1221.  
  1222.         for( i=0, n=0 ; i<4 ; i++ )    /* copying all non-empty partitions */
  1223.          if( part[i].os_id!=0 )
  1224.            {
  1225.             if(  part[i].os_id==0x1100 ||     /* FAT-12     */
  1226.                  part[i].os_id==0x1400 ||     /* FAT-16     */
  1227.                  part[i].os_id==0x1600 ||     /* FAT-16 BIG */
  1228.                  part[i].os_id==0x1700 ||     /* NTFS       */
  1229.                  part[i].os_id==0x1B00 ||     /* FAT-32     */
  1230.                  part[i].os_id==0x1C00  )     /* FAT-32 LBA */
  1231.                {
  1232.                 part[i].os_id-=0x1000; /* Unhiding hidden partitions */
  1233.                 determine_os_num( &part[i] );
  1234.                }
  1235.  
  1236.             adv->part[n].os_id=part[i].os_id;
  1237.             adv->part[n].orig_row=i+1;
  1238.             adv->part[n].rel_sect=part[i].rel_sect;
  1239.             adv->part[n].num_sect=part[i].num_sect;
  1240.             adv->part[n].tag = n+1;
  1241.             if( adv->menu[0].x.part.tag==0 && 
  1242.                 (part[i].os_id==0x0100 ||     /* FAT-12     */
  1243.                  part[i].os_id==0x0400 ||     /* FAT-16     */
  1244.                  part[i].os_id==0x0600 ||     /* FAT-16 BIG */
  1245.                  part[i].os_id==0x0700 ||     /* NTFS       */
  1246.                  part[i].os_id==0x0B00 ||     /* FAT-32     */
  1247.                  part[i].os_id==0x0C00 ) )    /* FAT-32 LBA */
  1248.               {
  1249.                adv->menu[0].x.part.tag=n+1;
  1250.               }
  1251.             if( i>0 && (part[i-1].os_id==0x8100 || /* Linix */
  1252.                         part[i-1].os_id==0x8300) /* Linix ext2fs */
  1253.                     && (part[i].os_id>>8)==0x82 /* Linix swap */ )
  1254.               {
  1255.                adv->part[n].os_id=0x8201; /* Linux Swap */
  1256.                adv->part[n].tag=0;
  1257.                adv->menu[m-1].x.part.show = SHOW_NEXT;
  1258.               }
  1259.             else if( part[i].os_id!=OS_EXT && /* Extended DOS */
  1260.                      part[i].os_id!=0x0A00 )  /* OS/2 Boot Manager */
  1261.               {
  1262.                adv->menu[m].boot_type = MENU_BOOT_PART;
  1263.                adv->menu[m].x.part.tag = n+1;
  1264.                sprintf_os_name( adv->menu[m].name, &part[i] );
  1265.                m++;
  1266.                if( !part[i].empty && part[i].valid && 
  1267.                    (part[i].os_id==0x0600  /* FAT-16 */  ||
  1268.                     part[i].os_id==0x0B00  /* FAT-32 */  ||
  1269.                     part[i].os_id==0x0C00  /* FAT-32 LBA */ ) )
  1270.                  {
  1271.                   if( disk_read_rel(&part[i],0,tmp,1)!=-1 )
  1272.                     {
  1273.                      if( memcmp(tmp+3,"MSWIN",5)==0 )
  1274.                        {
  1275.                         sprintf( adv->menu[m-1].name, "Windows 95");
  1276.                         sprintf( adv->menu[m].name,   "Windows 95 / Menu      (F8)");
  1277.                         sprintf( adv->menu[m+1].name, "Windows 95 / Safe mode (F5)");
  1278.                         sprintf( adv->menu[m+2].name, "Windows 95 / Command Prompt");
  1279.                         adv->menu[m].boot_type = MENU_BOOT_PART;
  1280.                         adv->menu[m].x.part.tag = n+1;
  1281.                         adv->menu[m].x.part.num_keys=1;
  1282.                         adv->menu[m].x.part.keys[0]=0x4200; /* F8    */
  1283.                         m++;
  1284.                         adv->menu[m].boot_type = MENU_BOOT_PART;
  1285.                         adv->menu[m].x.part.tag = n+1;
  1286.                         adv->menu[m].x.part.num_keys=1;
  1287.                         adv->menu[m].x.part.keys[0]=0x3F00; /* F5    */
  1288.                         m++;
  1289.                         adv->menu[m].boot_type = MENU_BOOT_PART;
  1290.                         adv->menu[m].x.part.tag = n+1;
  1291.                         adv->menu[m].x.part.num_keys=3;
  1292.                         adv->menu[m].x.part.keys[0]=0x4200; /* F8    */
  1293.                         adv->menu[m].x.part.keys[1]=0x0736; /* 6     */
  1294.                         adv->menu[m].x.part.keys[2]=0x1C0D; /* Enter */
  1295.                         m++;
  1296.                        }
  1297.                     }
  1298.                  }
  1299.               }
  1300.             n++;
  1301.            }
  1302.         
  1303.         
  1304.         for( i=0 ; i<n-1 ; i++ )        /* sorting them by rel_sect */
  1305.           for( j=i+1 ; j<n ; j++ )
  1306.            if( adv->part[j].rel_sect < adv->part[i].rel_sect )
  1307.              {
  1308.               tmp_part_rec=adv->part[i];
  1309.               adv->part[i]=adv->part[j];
  1310.               adv->part[j]=tmp_part_rec;
  1311.              }
  1312.         
  1313.         if( num_disks>dinfo.disk-0x80+1 )
  1314.           {
  1315.            adv->menu[m].boot_type =  MENU_BOOT_NEXT_HD;
  1316.            adv->menu[m].x.part.tag = 0;
  1317.            sprintf( adv->menu[m].name, "Boot from the next Hard Disk");
  1318.            m++;
  1319.           }
  1320.  
  1321.         if( n>1 && adv->part[n-1].os_id==OS_EXT )
  1322.           for( i=0 ; i<m ; i++ )
  1323.            if( adv->menu[i].x.part.show == SHOW_NONE )
  1324.              {
  1325.               if( adv->menu[i].boot_type == MENU_BOOT_PART )
  1326.                   adv->menu[i].x.part.show=SHOW_LAST;
  1327.               else
  1328.                   adv->menu[i].x.part.tag=n-1+1;
  1329.              }
  1330.  
  1331.         empty_start=1;
  1332.         for( i=0 ; i<n ; i++ )
  1333.          if( empty_start+ADV_NUM_SECTS > adv->part[i].rel_sect )
  1334.            {
  1335.             empty_start=adv->part[i].rel_sect+adv->part[i].num_sect;
  1336.            }
  1337.          else break;
  1338.         
  1339.         if( empty_start+ADV_NUM_SECTS > dinfo.total_sects )
  1340.           {
  1341.            show_error(ERROR_ADV_NOSPACE);
  1342.            continue;
  1343.           }
  1344.  
  1345.         for( j=n-1 ; j>=i ; j-- )  adv->part[j+1]=adv->part[j];
  1346.         
  1347.         adv->part[i].os_id=OS_ADV;
  1348.         adv->part[i].tag=0;
  1349.         
  1350.         if( empty_start==1 && (n==0 ||
  1351.                                (adv->part[1].rel_sect>=dinfo.num_sects &&
  1352.                                 ADV_NUM_SECTS<=dinfo.num_sects-7) ) )
  1353.           {
  1354.            adv->part[i].rel_sect=7;
  1355.            adv->part[i].num_sect=dinfo.num_sects-7;
  1356.           }
  1357.         else
  1358.           {
  1359.            adv->part[i].rel_sect=empty_start;
  1360.            adv->part[i].num_sect=ADV_NUM_SECTS;
  1361.           }
  1362.         
  1363.         adv->options |= ADV_OPT_VIR_CHECK;
  1364.  
  1365.         if( n!=0 ) force_edit_menu=1;
  1366.         force_initialize=1;
  1367.         view=VIEW_ADV;
  1368.        }
  1369.      else if( view==VIEW_MBR && (ev.key=='I' || ev.key=='i' || CLICK(16,11,47)))
  1370.        {                        /* Install IPL */
  1371.         if( memcmp(mbr,IPL,0x180)==0 )
  1372.            memmove(mbr,IPL,sizeof(mbr->x.ipl.code));
  1373.         else
  1374.           {
  1375.            memmove(mbr,IPL,sizeof(mbr->x.ipl));
  1376.            mesg=MESG_INSTALL;
  1377.           }
  1378.         setup_ipl(mbr);
  1379.         force_redraw_header=1;
  1380.         force_redraw_table=1;
  1381.         force_redraw_menu=1;
  1382.        }
  1383.      else if( ev.key=='S' || ev.key=='s' || CLICK(20,42,64) )    /* Save */
  1384.        {
  1385.         if( enter_string(20,10,PROMPT_FILE,sizeof(file_name),file_name,0) == 0 )
  1386.            continue;
  1387.         if( view!=VIEW_ADV && save_to_file(file_name,mbr,SECT_SIZE)==-1 ||
  1388.             view==VIEW_ADV && save_to_file(file_name,adv,ADV_DATA_SIZE)==-1 )
  1389.           warn=ERROR_SAVE_FILE;
  1390.         else
  1391.           mesg=MESG_FILE_SAVED;
  1392.        }
  1393.      else if( ev.key=='L' || ev.key=='l' || CLICK(21,42,66) )    /* Load */
  1394.        {
  1395.         char *zz;
  1396.         if( enter_string(20,10,PROMPT_FILE,sizeof(file_name),file_name,0) == 0 )
  1397.            continue;
  1398.         if( (zz=malloc(ADV_DATA_SIZE))==0 ) { show_error(ERROR_MALLOC); continue; }
  1399.         if( view!=VIEW_ADV && load_from_file(file_name,zz,SECT_SIZE)==-1 ||
  1400.             view==VIEW_ADV && load_from_file(file_name,zz,ADV_DATA_SIZE)==-1 )
  1401.            {
  1402.             warn=ERROR_LOAD_FILE;
  1403.             if( view==VIEW_ADV && load_from_file(file_name,zz,SECT_SIZE)!=-1 )
  1404.               warn="Warning! Specified file is not Advanced Boot Manager partition table";
  1405.            }
  1406.         else
  1407.           {
  1408.            if( view==VIEW_ADV && strcmp(zz,ADV_DATA_SIGNATURE)!=0 )
  1409.              {
  1410.               show_error(ERROR_ADV_BAD);
  1411.              }
  1412.            else 
  1413.              {
  1414.               mesg=MESG_FILE_LOADD;
  1415.               if( view==VIEW_MBR && strcmp(zz, ADV_DATA_SIGNATURE)==0 )
  1416.                 {
  1417.                  load_from_file(file_name,zz,ADV_DATA_SIZE);
  1418.                  view=VIEW_ADV;
  1419.                 }
  1420.               if( view!=VIEW_ADV ) memmove(mbr,zz,SECT_SIZE);
  1421.                               else memmove(adv,zz,ADV_DATA_SIZE);
  1422.               force_initialize=1;
  1423.              }
  1424.           }
  1425.         free(zz);
  1426.        }
  1427.      else if( view!=VIEW_ADV &&             /* Load IPL Code */
  1428.              (ev.key=='C' || ev.key=='c' || CLICK(19,42,61) ) )
  1429.        {
  1430.         char *zz;
  1431.         if( enter_string(20,10,PROMPT_FILE,sizeof(file_name),file_name,0) == 0 )
  1432.            continue;
  1433.         if( (zz=malloc(SECT_SIZE))==0 ) { show_error(ERROR_MALLOC); continue; }
  1434.         if( load_from_file(file_name,zz,SECT_SIZE)==-1 )
  1435.           warn=ERROR_LOAD_FILE;
  1436.         else
  1437.           {
  1438.            memmove(mbr, zz, sizeof(mbr->x.std.code) );
  1439.            mesg=MESG_INSTALL;
  1440.           }
  1441.         free(zz);
  1442.        }
  1443.  
  1444.     }/* while(1) */
  1445.  
  1446.  free(part);
  1447.  free(data);
  1448.  
  1449.  return 0;
  1450. }/* setup_mbr */
  1451.  
  1452.  
  1453.  
  1454. void command_line(int argc, char **argv)
  1455. {
  1456.  char ch, *data;
  1457.  struct mbr *mbr;
  1458.  struct adv *adv;
  1459.  struct part_long *p, *part;
  1460.  int i, x, view, valid, num_rows;
  1461.  
  1462.  if( argv[0][0]=='-' || argv[0][0]=='/' ) argv[0]++;
  1463.                                      else usage();
  1464.  
  1465.  if( strcmpi(argv[0],"Reboot")==0 )  reboot();
  1466.  
  1467.  for( i=0 ; (ch="IiPpCcAaVvFfSsLlHh"[i])!=0 ; i++ )
  1468.    if( argv[0][0]==ch ) break;
  1469.  
  1470.  if( ch==0 )
  1471.    {
  1472.     usage();
  1473.     return;
  1474.    }
  1475.  
  1476.  if( argv[0][0]=='I' || argv[0][0]=='i' )    /* Print IDE information */
  1477.    {
  1478.     flush_caches();
  1479.     print_ide_info();
  1480.     return;
  1481.    }
  1482.  
  1483.  if( get_disk_info(hd,&dinfo,buf)==-1 )  cmd_error(ERROR_DISK_INFO);
  1484.  
  1485.  if( (data=malloc(SECT_SIZE+ADV_DATA_SIZE))==0 )
  1486.    { cmd_error(ERROR_MALLOC); return; }
  1487.  if( (p=malloc(sizeof(struct part_long)*(MAX_PART_ROWS+1)))==0 )
  1488.    { cmd_error(ERROR_MALLOC); free(data); return; }
  1489.  
  1490.  mbr=(struct mbr*)(data);
  1491.  adv=(struct adv*)(data+SECT_SIZE);
  1492.  part=p+1;
  1493.  
  1494.  p->level=0;
  1495.  p->empty=0;
  1496.  p->valid=1;
  1497.  p->inh_changed=0;
  1498.  p->inh_invalid=0;
  1499.  p->inconsist_err=0;
  1500.  p->boot_record_err=0;
  1501.  
  1502.  p->container=0;
  1503.  p->container_base=0;
  1504.        
  1505.  p->start_cyl=0;     p->end_cyl=dinfo.num_cyls-1;
  1506.  p->start_head=0;    p->end_head=dinfo.num_heads-1;
  1507.  p->start_sect=1;    p->end_sect=dinfo.num_sects;
  1508.            
  1509.  p->rel_sect=0;
  1510.  p->num_sect=dinfo.total_sects;
  1511.  
  1512.  
  1513.  if( argv[0][0]=='L' || argv[0][0]=='l' )        /* Load */
  1514.    {
  1515.     if( argc<2 ) usage();
  1516.  
  1517.     if( load_from_file(argv[1],mbr,SECT_SIZE)==-1 ) cmd_error(ERROR_LOAD_FILE);
  1518.     if( strcmp((char*)mbr, ADV_DATA_SIGNATURE)!=0 )
  1519.       {
  1520.        num_rows=4;
  1521.        unpack_part_tab( mbr->part_rec, part, num_rows, p );
  1522.       }
  1523.     else
  1524.       {
  1525.        if( load_from_file(argv[1],adv,ADV_DATA_SIZE)==-1 ) cmd_error(ERROR_LOAD_FILE);
  1526.        if( adv->version>ADV_DATA_VERSION ) cmd_error(ERROR_ADV_VER);
  1527.        if( adv->version<ADV_DATA_VERSION ) convert_adv_data(adv);
  1528.        num_rows=MAX_PART_ROWS;
  1529.        unpack_adv_part_tab(adv->part, part, num_rows, p );
  1530.        view=VIEW_ADV;
  1531.       }
  1532.  
  1533.     valid=validate_table(part,num_rows,p);
  1534.  
  1535.     if( !valid ) cmd_error(ERROR_FIX_FIRST);
  1536.     
  1537.     if( view==VIEW_ADV )
  1538.       {
  1539.        if( !prepare_adv_mbr_for_save(part,mbr,adv) )
  1540.           cmd_error(ERROR_NO_ADV);
  1541.       }
  1542.  
  1543.     disk_lock(dinfo.disk);
  1544.        
  1545.     mbr->magic_num=MBR_MAGIC_NUM;
  1546.  
  1547.     if( view==VIEW_ADV && 
  1548.         (disk_write_rel(p,mbr->x.adv.rel_sect,adv,ADV_DATA_SECT)==-1 ||
  1549.          disk_write_rel(p,mbr->x.adv.rel_sect+ADV_DATA_SECT,
  1550.                                        ADV_MANAGER,ADV_CODE_SECT)==-1 ) )
  1551.       {
  1552.        disk_unlock(dinfo.disk);
  1553.        cmd_error(ERROR_SAVE_ADV);
  1554.       }
  1555.  
  1556.     if( disk_write_rel(p,0,mbr,1)==-1 )
  1557.       {
  1558.        disk_unlock(dinfo.disk);
  1559.        cmd_error(ERROR_SAVE_MBR);
  1560.       }
  1561.  
  1562.     disk_unlock(dinfo.disk);
  1563.     printf("%s\n",MESG_MBR_SAVED2);
  1564.     return;
  1565.    }/* load */
  1566.  
  1567.  
  1568.  if( disk_read_rel(p,0,mbr,1)==-1 ) cmd_error(ERROR_READ_MBR);
  1569.  
  1570.  view=VIEW_MBR;
  1571.  
  1572.  if(  mbr->x.adv.adv_mbr_magic==ADV_MBR_MAGIC ||
  1573.       strcmp(mbr->x.adv_old.signature, ADV_DATA_SIGNATURE)==0 )
  1574.    {
  1575.     if( disk_read_rel( p, mbr->x.adv.rel_sect, adv, ADV_DATA_SECT )==-1 )
  1576.       {
  1577.        fprintf(stderr,"Warning: %s\n\n",ERROR_READ_ADV);
  1578.       }
  1579.     else if( strcmp(adv->signature,ADV_DATA_SIGNATURE)!=0 )
  1580.       {
  1581.        fprintf(stderr,"Warning: %s\n\n",ERROR_ADV_BAD);
  1582.       }
  1583.     else
  1584.       {
  1585.        view=VIEW_ADV;
  1586.       }
  1587.    }
  1588.  
  1589.  if( view==VIEW_ADV )
  1590.    {
  1591.     if( adv->version>ADV_DATA_VERSION )
  1592.       {
  1593.        fprintf(stderr,"Warning: %s\n\n",ERROR_ADV_VER);
  1594.       }
  1595.     if( adv->version<ADV_DATA_VERSION ) convert_adv_data(adv);
  1596.     num_rows=MAX_PART_ROWS;
  1597.     unpack_adv_part_tab(adv->part, part, num_rows, p );
  1598.    }
  1599.  else
  1600.    {
  1601.     num_rows=4;
  1602.     unpack_part_tab( mbr->part_rec, part, num_rows, p );
  1603.    }
  1604.  
  1605.  valid=validate_table(part,num_rows,p);
  1606.  
  1607.  if( argv[0][0]=='P' || argv[0][0]=='p' )    /* Print partition table */
  1608.    {
  1609.     int rec_opt=( argc>1 && (argv[1][0]=='-' || argv[1][0]=='/') 
  1610.                          && (argv[1][1]=='R' || argv[1][1]=='r') )?1:0;
  1611.     if( rec_opt )
  1612.       {
  1613.        printf("  %s\n\n", PROGRAM_TITLE );
  1614.        if( view==VIEW_ADV )
  1615.          {
  1616.           print_adv_menu(adv);
  1617.           printf("\n-------------------------------------------------------------------------------\n\n");
  1618.          }
  1619.       }
  1620.        
  1621.  
  1622.     printf(HEADER_CMD, dinfo.disk-127, dinfo.total_sects/2048, dinfo.num_cyls,
  1623.        dinfo.num_heads, dinfo.num_sects, sprintf_long(tmp,dinfo.total_sects) );
  1624.     
  1625.     printf("Valid%s\n |   %s\n\n", HEADER_CHS2, HEADER_CHS3 );
  1626.  
  1627.     for( i=0 ; i<num_rows ; i++ )
  1628.        {
  1629.         if( num_rows>4 && part[i].empty )continue; 
  1630.         sprintf_partrec(tmp, &part[i], i+1, view );  tmp[75]=0;
  1631.         printf("%s %s\n", part[i].empty?"   ":(part[i].valid?"OK ":" X "),tmp);
  1632.        }
  1633.  
  1634.     printf("\n");
  1635.  
  1636.     if( rec_opt )
  1637.       {
  1638.        print_part_details(part,num_rows);
  1639.        
  1640.        for( i=0 ; i<num_rows ; i++ )
  1641.         if(!part[i].empty && part[i].valid && part[i].os_id!=0
  1642.                                            && part[i].os_id!=OS_ADV )
  1643.           {
  1644.            printf("\n\n-------------------------------------------------------------------------------\n\n"
  1645.                   "%s  [  %luM = %s sectors  at  CHS=(%lu,%lu,%lu)  ]\n\n",
  1646.                   sprintf_os_name(tmp,&part[i]),
  1647.                   part[i].num_sect/2048, sprintf_long(tmp2,part[i].num_sect),
  1648.                   part[i].start_cyl, part[i].start_head, part[i].start_sect );
  1649.  
  1650.            if( os_desc[part[i].os_num].print!=0 )
  1651.                os_desc[part[i].os_num].print(&part[i]);
  1652.            else print_unknown(&part[i]);
  1653.           }
  1654.       }
  1655.     else /* Print logical drives */
  1656.       {
  1657.        int level=0;
  1658.        int num=num_rows+1;
  1659.        while(1)
  1660.           {
  1661.            if( level>32 ) cmd_error("Recursion is too deep.");
  1662.  
  1663.            for( i=0 ; i<num_rows ; i++ )
  1664.             if( part[i].os_id==OS_EXT ) break;
  1665.  
  1666.            if( i==num_rows ) break;
  1667.  
  1668.            if( level==0 ) printf(MESG_LOGICAL);
  1669.  
  1670.            if( disk_read_rel(&part[i],0,mbr,1)==-1 ) cmd_error(ERROR_READ_MBR);
  1671.            p=&part[MAX_PART_ROWS-1];
  1672.            *p=part[i];
  1673.            num_rows=4;
  1674.            unpack_part_tab( mbr->part_rec, part, num_rows, p );
  1675.            valid=validate_table(part,num_rows,p);
  1676.            for( i=0 ; i<num_rows ; i++ )
  1677.             if( part[i].os_id!=0 && part[i].os_id!=OS_EXT )
  1678.               {
  1679.                sprintf_partrec(tmp, &part[i], num++, view );  tmp[75]=0;
  1680.                printf("%s %s\n", part[i].empty?"   ":(part[i].valid?"OK ":" X "),tmp);
  1681.               }
  1682.            level++;
  1683.           }
  1684.       }/* print logical */
  1685.  
  1686.     return;
  1687.    }/* print */
  1688.  
  1689.  if( argv[0][0]=='S' || argv[0][0]=='s' )        /* Save */
  1690.    {
  1691.     if( argc<2 ) usage();
  1692.     if( view!=VIEW_ADV )
  1693.       {
  1694.        if( save_to_file(argv[1],mbr,SECT_SIZE)==-1 )
  1695.            cmd_error(ERROR_SAVE_FILE);
  1696.       }
  1697.     else
  1698.       {
  1699.        if( save_to_file(argv[1],adv,ADV_DATA_SIZE)==-1 )
  1700.            cmd_error(ERROR_SAVE_FILE);
  1701.       }
  1702.     printf("%s\n",MESG_FILE_SAVED);
  1703.     if( !valid )
  1704.        fprintf(stderr,"Warning: %s\n",WARN_INVALID);
  1705.     return;
  1706.    }/* save */
  1707.  
  1708.  if( argv[0][0]=='C' || argv[0][0]=='c' )        /* Compare */
  1709.    {
  1710.     if( argc<2 ) usage();
  1711.     if( view!=VIEW_ADV )
  1712.       {
  1713.        if( load_from_file(argv[1],tmp,SECT_SIZE)==-1 || 
  1714.            memcmp(mbr,tmp,SECT_SIZE)!=0 )
  1715.            cmd_error(MESG_DIFFERENT);
  1716.       }
  1717.     else
  1718.       {
  1719.        if( load_from_file(argv[1],tmp,ADV_DATA_SIZE)==-1 ||
  1720.            memcmp(adv,tmp,ADV_DATA_SIZE)!=0 )
  1721.            cmd_error(MESG_DIFFERENT);
  1722.       }
  1723.     if( !valid )
  1724.        fprintf(stderr,"Warning: %s\n",WARN_INVALID);
  1725.     printf("%s\n",MESG_NO_DIFFERENCES);
  1726.     return;
  1727.    }/* save */
  1728.  
  1729.  if( !valid ) cmd_error(ERROR_FIX_FIRST);
  1730.  
  1731.  if( argv[0][0]=='A' || argv[0][0]=='a' )            /* Activate */
  1732.    {
  1733.     int x;
  1734.  
  1735.     if( view==VIEW_ADV ) return;
  1736.     if( argc<2 ) usage();
  1737.     i=atoi(argv[1])-1;
  1738.     if( i<0 || i>3 ) usage();
  1739.  
  1740.     for( x=0 ; x<4 ; x++ )
  1741.        part[x].active=0;
  1742.     part[i].active=1;
  1743.  
  1744.     pack_part_tab( part, mbr->part_rec, 4 );
  1745.  
  1746.     disk_lock(hd);
  1747.      
  1748.     if( disk_write_rel(p,0,mbr,1)==-1 )
  1749.       {
  1750.        disk_unlock(hd);
  1751.        cmd_error(ERROR_SAVE_MBR);
  1752.       }
  1753.  
  1754.     printf("%s\n",MESG_MBR_SAVED);
  1755.  
  1756.     disk_unlock(hd);
  1757.     return;
  1758.    }/* activate */
  1759.  
  1760.  if( argv[0][0]=='H' || argv[0][0]=='h' )            /* Hide */
  1761.    {
  1762.     int x;
  1763.  
  1764.     if( view==VIEW_ADV ) return;
  1765.     if( argc<2 ) usage();
  1766.     i=atoi(argv[1])-1;
  1767.     if( i<0 || i>3 ) usage();
  1768.  
  1769.     if( part[i].os_id==0x0100 ||
  1770.         part[i].os_id==0x0400 ||
  1771.         part[i].os_id==0x0600 || 
  1772.         part[i].os_id==0x0700 || 
  1773.         part[i].os_id==0x0B00 ) part[i].os_id+=0x1000;
  1774.     else
  1775.     if( part[i].os_id==0x1100 ||
  1776.         part[i].os_id==0x1400 || 
  1777.         part[i].os_id==0x1600 || 
  1778.         part[i].os_id==0x1700 || 
  1779.         part[i].os_id==0x1B00 ) part[i].os_id-=0x1000;
  1780.     else
  1781.       {
  1782.        fprintf(stderr,
  1783.          "I will not hide partition which I couldn't unhide later\n");
  1784.        return;
  1785.       }
  1786.  
  1787.     pack_part_tab( part, mbr->part_rec, 4 );
  1788.  
  1789.     disk_lock(hd);
  1790.      
  1791.     if( disk_write_rel(p,0,mbr,1)==-1 )
  1792.       {
  1793.        disk_unlock(hd);
  1794.        cmd_error(ERROR_SAVE_MBR);
  1795.       }
  1796.  
  1797.     printf("%s\n",MESG_MBR_SAVED);
  1798.  
  1799.     disk_unlock(hd);
  1800.     return;
  1801.    }/* hide */
  1802.  
  1803.  if( argv[0][0]=='F' || argv[0][0]=='f' )            /* Format */
  1804.    {
  1805.     if( argc<2 ) usage();
  1806.     i=atoi(argv[1])-1;
  1807.     if( i<0 || i>=num_rows ) usage();
  1808.         
  1809.     if( part[i].empty ) cmd_error(ERROR_FORMAT_EMPTY);
  1810.  
  1811.     if( os_desc[part[i].os_num].format==0 ) cmd_error(ERROR_NO_FORMAT);
  1812.  
  1813.     x=os_desc[part[i].os_num].format(&part[i],argv+2);
  1814.          if( x==FAILED ) cmd_error(ERROR_FORMAT_FAILED);
  1815.     else if( x==CANCEL ) cmd_error(WARN_FORMAT_CANCEL);
  1816.     else printf("\n%s\n",MESG_FORMAT_OK);
  1817.  
  1818.     return;
  1819.    }
  1820.  
  1821.  if( argv[0][0]=='V' || argv[0][0]=='v' )            /* Verify */
  1822.    {
  1823.     if( argc<2 ) usage();
  1824.     i=atoi(argv[1])-1;
  1825.     if( i<0 || i>=num_rows ) usage();
  1826.         
  1827.     if( part[i].empty ) cmd_error(ERROR_FORMAT_EMPTY);
  1828.  
  1829.     x=generic_verify(&part[i],0,0);
  1830.          if( x==FAILED ) cmd_error(ERROR_VERIFY_FAILED);
  1831.     else if( x==CANCEL ) cmd_error(WARN_VERIFY_CANCEL);
  1832.     else printf("\n%s\n",MESG_VERIFY_OK);
  1833.  
  1834.     return;
  1835.    }
  1836.  
  1837. }/* command_line */
  1838.  
  1839.  
  1840.