home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / boot / i386 / root / usr / share / YaST2 / include / partitioning / auto_part_create.ycp next >
Text File  |  2006-11-29  |  4KB  |  149 lines

  1. /**
  2.  * Module:        auto_part_create.ycp
  3.  *
  4.  * Authors:        Andreas Schwab (schwab@suse.de)
  5.  *            Klaus KΣmpf (kkaempf@suse.de)
  6.  *
  7.  * Purpose:        This module creates the neccessary partitions
  8.  *            in the targetMap
  9.  *
  10.  * $Id: auto_part_create.ycp 33627 2006-10-24 10:39:14Z fehr $
  11.  *
  12.  * used globals
  13.  *
  14.  * defined functions
  15.  */
  16. {
  17.     textdomain "storage";
  18.  
  19.     import "Storage";
  20.     import "Partitions";
  21.     import "ProductFeatures";
  22.  
  23. include "partitioning/do_proposal_flexible.ycp";
  24.  
  25. boolean create_partitions( map<string,map> tgmap, map disk, list<map> partitions )
  26.     {
  27.     y2milestone( "create_partitions disk:%1",
  28.                  haskey(disk,"partitions")?remove(disk,"partitions"):disk );
  29.     y2milestone( "create_partitions partitions %1", partitions );
  30.     boolean ret = false;
  31.     boolean has_flex = has_flex_proposal();
  32.     string vm = Storage::ProposalVM();
  33.     y2milestone( "create_partitions flex %1 vm %2", has_flex, vm );
  34.     disk["partitions"] = partitions;
  35.     map keep = find( map p, partitions, 
  36.              ``(!p["delete"]:false&&p["type"]:`unknown!=`free));
  37.     if( size(vm)==0 )
  38.     {
  39.     if( has_flex )
  40.         {
  41.         map flex = do_flexible_disk( disk );
  42.         if( flex["ok"]:false )
  43.         partitions = flex["disk","partitions"]:[];
  44.         }
  45.     else
  46.         {
  47.         integer num_del_exist = size(filter(map p, partitions,
  48.                         ``(p["type"]:`unknown!=`free&&
  49.                            p["delete"]:false)));
  50.         integer num_del_free = size(filter(map p, partitions,
  51.                         ``(p["type"]:`unknown==`free&&
  52.                            p["delete"]:false)));
  53.         map r = can_swap_reuse( disk["device"]:"", partitions, tgmap );
  54.         if( haskey( r, "partitions" ))
  55.         partitions = r["partitions"]:[];
  56.         else if( haskey( r, "targets" ))
  57.         tgmap = r["targets"]:$[];
  58.  
  59.         y2milestone( "create_partitions num_del_exist %1 num_del_free %2 swap_reuse %3", 
  60.              num_del_exist, num_del_free, size(r)>0 );
  61.         y2milestone( "create_partitions keep %1", keep );
  62.         if( keep!=nil && size(r)>0 && num_del_exist==1 && num_del_free==0 )
  63.         {
  64.         y2milestone( "create_partitions single special" );
  65.         boolean first = true;
  66.         partitions = maplist( map p, partitions, 
  67.                       ``{
  68.                       if( p["delete"]:false && first )
  69.                       {
  70.                       p = remove( p, "delete" );
  71.                       first = false;
  72.                       p["format"] = true;
  73.                       p["used_fs"] = Partitions::DefaultFs();
  74.                       p["mount"] = "/";
  75.                       y2milestone( "create_partitions single p %1", p );
  76.                       }
  77.                       return( p );
  78.                       });
  79.         }
  80.         else
  81.         {
  82.         partitions = get_proposal( size(r)>0, disk );
  83.         }
  84.         }
  85.     y2milestone( "create_partitions %1", partitions );
  86.     }
  87.     else
  88.     {
  89.     map id_save = $[];
  90.     disk["partitions"] = maplist( map p, disk["partitions"]:[],
  91.         ``{
  92.         if( !p["delete"]:false && 
  93.             p["type"]:`unknown!=`free && p["type"]:`unknown!=`extended )
  94.         {
  95.         id_save[p["device"]:""] = p["fsid"]:0;
  96.         p["fsid"] = Partitions::fsid_hibernation;
  97.         }
  98.         return( p );
  99.         });
  100.     y2milestone( "create_partitions id_save %1", id_save );
  101.     y2milestone( "create_partitions ps %1", disk["partitions"]:[] );
  102.     map r = get_proposal_vm( tgmap, vm, disk );
  103.     ret = r["ok"]:false;
  104.     if( ret )
  105.         {
  106.         string ddev = disk["device"]:"";
  107.         tgmap = r["target"]:$[];
  108.         tgmap[ddev,"partitions"] = maplist( map p, tgmap[ddev,"partitions"]:[],
  109.         ``{
  110.         if( haskey( id_save, p["device"]:"" ))
  111.             p["fsid"] = id_save[p["device"]:""]:0;
  112.         return( p );
  113.         });
  114.         y2milestone( "create_partitions ps %1", tgmap[ddev,"partitions"]:[] );
  115.         }
  116.     }
  117.     keep = find( map p, partitions, 
  118.          ``(!p["delete"]:false&&!p["create"]:false));
  119.     partitions = filter( map p, partitions, ``(p["type"]:`unknown!=`free));
  120.     y2milestone( "create_partitions keep %1", keep );
  121.     Storage::SetWholeDisk( keep == nil );
  122.     if( size(vm)==0 )
  123.     {
  124.     partitions = maplist( map p, partitions,
  125.         ``{
  126.         if( size(p["mount"]:"")>0 && !p["delete"]:false )
  127.         p["fstopt"] = FileSystems::DefaultFstabOptions( p );
  128.         if( p["format"]:false && !p["delete"]:false )
  129.         p["fs_options"] = FileSystems::DefaultFormatOptions( p );
  130.         return( p );
  131.         });
  132.     ret = size(partitions)>0;
  133.     if( ret )
  134.         {
  135.         tgmap[disk["device"]:"","partitions"] = partitions;
  136.         tgmap = Storage::SpecialBootHandling(tgmap);
  137.         }
  138.     }
  139.     if( ret )
  140.     {
  141.     Storage::SetTargetMap( tgmap );
  142.     Storage::AddMountPointsForWin(tgmap);
  143.     }
  144.     y2milestone( "create_partitions ret %1", ret );
  145.     return( ret );
  146.     }; // create_partitions
  147.  
  148. }
  149.