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 / modules / Partitions.ycp < prev    next >
Encoding:
Text File  |  2006-11-29  |  22.1 KB  |  809 lines

  1. /**
  2.  * Module:         Partitions.ycp
  3.  *
  4.  * Authors:        Thomas Fehr (fehr@suse.de)
  5.  *
  6.  * Purpose:         Provides information about partitions
  7.  *
  8.  * $Id: Partitions.ycp 33469 2006-10-17 11:51:13Z fehr $
  9.  */
  10. {
  11.     module "Partitions";
  12.  
  13.     textdomain "storage";
  14.  
  15.     import "Arch";
  16.     import "Mode";
  17.     import "Stage";
  18.     import "AsciiFile";
  19.  
  20.     // The filesystem ids for the partitions
  21.     global integer fsid_empty    = 0;
  22.     global integer fsid_native   = 131;
  23.     global integer fsid_swap     = 130;
  24.     global integer fsid_lvm      = 142;
  25.     global integer fsid_raid     = 253;
  26.     global integer fsid_hibernation = 160;
  27.     global integer fsid_extended = 5;
  28.     global integer fsid_extended_win = 15;
  29.     global integer fsid_fat16    = 6;
  30.     global integer fsid_fat32    = 12;
  31.     global integer fsid_prep_chrp_boot = 0x41;
  32.     global integer fsid_mac_hidden = 0x101;
  33.     global integer fsid_mac_hfs = 0x102;
  34.     global integer fsid_mac_ufs = 0x106;
  35.     global integer fsid_gpt_boot = 0x103;
  36.     global integer fsid_gpt_service = 0x104;
  37.     global integer fsid_gpt_msftres = 0x105;
  38.     global integer fsid_freebsd = 0xa5;
  39.     global integer fsid_openbsd = 0xa6;
  40.     global integer fsid_beos = 0xeb;
  41.     global integer fsid_solaris = 0xbf;
  42.     global integer fsid_root = fsid_native;
  43.            integer fsid_boot = 0;
  44.            integer boot_cyl = 0;
  45.            string boot_mount_point = "";
  46.  
  47.     global boolean no_fsid_menu = Arch::s390 ();
  48.  
  49.     global string  raid_name = "MD Raid";
  50.     global string  evms_name = "EVMS";
  51.     global string  lv_name = "LV";
  52.     global string  dm_name = "DM";
  53.     global string  loop_name = "Loop Device";
  54.     global string  dmraid_name = "DM Raid";
  55.  
  56.     // filesystems for /win
  57.                          /* FAT32, Win95-Fat32, Win95LBA, Win95-Fat16  */
  58.     global list fsid_wintypes = [ 6, 11, 12, 14 ]; 
  59.  
  60.     // filesystems for /dos
  61.     global list fsid_dostypes = [ 1, 4 ];          /* FAT12, FAT16  */
  62.  
  63.     // filesystems for /windows
  64.     global list fsid_ntfstypes = [ 7, 23 ];       /* NTFS  */
  65.  
  66.     // filesystems mounted read-only
  67.     global list fsid_readonly = [ 7, 23 ];
  68.  
  69.     // filesystems skipped on sparc and axp
  70.     global list fsid_skipped = [ 0, 5 ];
  71.  
  72.     // partition ids not to delete when suggesting to use whole disk
  73.     global list do_not_delete = [ 0x12, 0xde, fsid_mac_hfs, fsid_gpt_service ];
  74.  
  75.     // partition ids not to display as windows when fat32 is on it
  76.     global list no_windows = [ 0x12, 0x82, 0xde, fsid_gpt_boot, fsid_gpt_service,
  77.                                fsid_gpt_msftres ];
  78.  
  79.     global integer minimal_needed_disksize = 400 * 1024 * 1024;  // for installation of a minimal system
  80.            integer minimal_needed_bootsize = 0; 
  81.  
  82.            symbol default_fs      = `unknown;
  83.            symbol default_boot_fs = `unknown;
  84.  
  85.     global list<string> not_shown_partitions = 
  86.     [
  87.     "Apple_partition_map",
  88.     "Apple_Patches",
  89.     "Apple_Driver",
  90.     "Apple_Loader",
  91.     "Apple_Boot",
  92.     "Apple_Bootstrap",
  93.     "Apple_FWDriver",
  94.     "Apple_ProDOS" 
  95.     ];
  96.  
  97.  
  98. global define void Partitions()
  99.     ``{
  100.         return ;
  101.     }
  102.  
  103. global define symbol DefaultFs()
  104.     ``{
  105.     if( default_fs == `unknown )
  106.     {
  107.     default_fs = `ext3;
  108.     }
  109.     return( default_fs );
  110.     }
  111.  
  112. global define symbol DefaultBootFs()
  113.     ``{
  114.     if( default_boot_fs == `unknown )
  115.     {
  116.     default_boot_fs = `ext3;
  117.     if( Arch::ia64 () )
  118.         {
  119.         default_boot_fs = `vfat;
  120.         }
  121.     else if( Arch::board_mac () )
  122.         {
  123.         default_boot_fs = `hfs;
  124.         }
  125.     }
  126.     return( default_boot_fs );
  127.     }
  128.  
  129. global define string BootMount()
  130.     ``{
  131.     if( boot_mount_point == "" )
  132.     {
  133.     boot_mount_point = "/boot";
  134.     if( Arch::ia64 () )
  135.         {
  136.         boot_mount_point = "/boot/efi";
  137.         }
  138.     }
  139.     return( boot_mount_point );
  140.     }
  141.  
  142. global define integer MinimalNeededBootsize()
  143.     ``{
  144.     if( minimal_needed_bootsize == 0 )
  145.     {
  146.     minimal_needed_bootsize = 64 * 1024 * 1024;
  147.     if( Arch::ia64() )
  148.         {
  149.         minimal_needed_bootsize = 200*1024*1024;
  150.         }
  151.     else if( Arch::board_chrp() )
  152.         {
  153.         minimal_needed_bootsize = 16*1024*1024;
  154.         }
  155.     else if( Arch::board_prep() )
  156.         {
  157.         minimal_needed_bootsize = 5*1024*1024;
  158.         }
  159.     else if( Arch::board_iseries() )
  160.         {
  161.         minimal_needed_bootsize = 8*1024*1024;
  162.         }
  163.     else if( Arch::board_mac() )
  164.         {
  165.         minimal_needed_bootsize = 32*1024*1024;
  166.         }
  167.     }
  168.     return( minimal_needed_bootsize );
  169.     }
  170.  
  171. global define integer MinimalRequiredBootsize()
  172.     ``{
  173.     integer need = MinimalNeededBootsize();
  174.     integer ret = need;
  175.     if( Arch::ia64() )
  176.     ret = ret / 10 * 9;
  177.     else if( Arch::board_mac() )
  178.     ret = 800 * 1024;
  179.     if( ret!=need )
  180.     y2milestone( "MinimalRequiredBootsize ret %1 Req:%2", ret, need  );
  181.     return( ret );
  182.     }
  183.  
  184. global define integer BootCyl()
  185.     ``{
  186.     if( boot_cyl == 0 )
  187.     {
  188.     boot_cyl = 1024;
  189.     if( !Arch::i386 () )
  190.         {
  191.         // Assume on non-i386 archs machine can boot from every cylinder
  192.         boot_cyl = 4*1024*1024*1024;
  193.         }
  194.     else
  195.         {
  196.         list internal_bios = (list<map>) SCR::Read (.probe.bios);
  197.         boolean lba = internal_bios[0, "lba_support"]:false;
  198.         y2milestone( "BootCyl lba_support %1", lba );
  199.         if( !lba )
  200.         {
  201.         map st = (map)SCR::Read( .target.stat, 
  202.                                  "/proc/xen/capabilities" );
  203.         y2milestone( "BootCyl /proc/xen/capabilities %1", st );
  204.         if( size(st)>0 )
  205.             lba = (integer)SCR::Execute( .target.bash,
  206.                          "grep control_d /proc/xen/capabilities" )>0;
  207.         y2milestone( "BootCyl lba_support %1", lba );
  208.         }
  209.         if( lba )
  210.         {
  211.         boot_cyl = 4*1024*1024*1024;
  212.         }
  213.         }
  214.     }
  215.     return( boot_cyl );
  216.     }
  217.  
  218. boolean prep_boot_first = true;
  219.  
  220. global define boolean PrepBoot()
  221.     ``{
  222.     boolean ret = Arch::ppc() && 
  223.           (Arch::board_chrp() || Arch::board_prep() || Arch::board_iseries());
  224.     if( ret && prep_boot_first )
  225.     {
  226.     y2milestone( "PrepBoot ret:%1", ret );
  227.     prep_boot_first = false;
  228.     }
  229.     return( ret );
  230.     };
  231.  
  232. global define boolean BootPrimary()
  233.     {
  234.     boolean ret = PrepBoot();
  235.     return( ret );
  236.     }
  237.  
  238. global define integer FsidBoot()
  239.     ``{
  240.     if( fsid_boot == 0 )
  241.     {
  242.     fsid_boot = fsid_native;
  243.     if( Arch::ia64 () )
  244.         {
  245.         fsid_boot = fsid_gpt_boot;
  246.         }
  247.     else if( PrepBoot() )
  248.         {
  249.         fsid_boot = fsid_prep_chrp_boot;
  250.         }
  251.     else if( Arch::board_mac () )
  252.         {
  253.         fsid_boot = fsid_mac_hfs;
  254.         }
  255.     }
  256.     return( fsid_boot );
  257.     }
  258.  
  259. global define boolean NeedBoot()
  260.     ``{
  261.     boolean ret = false;
  262.     if( Arch::ia64()||Arch::ppc()||Arch::sparc()||Arch::alpha() )
  263.     {
  264.     ret = true;
  265.     }
  266.     y2milestone( "NeedBoot ret %1", ret );
  267.     return( ret );
  268.     }
  269.  
  270. global define boolean IsDosPartition( integer fsid )
  271.     ``{
  272.     return (contains( fsid_dostypes, fsid) || contains( fsid_wintypes, fsid));
  273.     }
  274.  
  275. global define boolean IsDosWinNtPartition( integer fsid )
  276.     ``{
  277.     return( IsDosPartition( fsid ) || contains( fsid_ntfstypes, fsid ));
  278.     }
  279.  
  280. global define integer SwapSizeMb( integer slot_size )
  281.     ``{
  282.     integer swap_size = 0;
  283.  
  284.     // a good approach swap == mem x 2
  285.     integer mem = 256;
  286.     if( !Mode::test () )
  287.     {
  288.         map mem_info_map = (map) SCR::Read(.proc.meminfo);
  289.     y2milestone( "mem_info_map %1", mem_info_map );
  290.         mem = mem_info_map["memtotal"]:0;
  291.     mem = mem / 1024;
  292.     }
  293.     if( mem == 0 || mem == nil ) mem = 64;
  294.  
  295.     if( slot_size==0 )
  296.     {
  297.     if( mem <= 256 )
  298.         {
  299.         swap_size = mem * 2;
  300.         }
  301.     else
  302.         {
  303.         swap_size = mem + mem/2;
  304.         }
  305.     }
  306.     else
  307.     {
  308.     if( mem * 9 < slot_size )
  309.         {
  310.         swap_size = mem * 2; 
  311.         }
  312.     else if( mem * 5 < slot_size )
  313.         {
  314.         swap_size = mem; 
  315.         }
  316.     else if( mem * 3 < slot_size )
  317.         {
  318.         swap_size = mem / 2; 
  319.         }
  320.     else if( mem * 2 < slot_size )
  321.         {
  322.         swap_size = mem / 3; 
  323.         }
  324.     else 
  325.         {
  326.         swap_size = mem / 4;
  327.         }
  328.     }
  329.  
  330.     if( swap_size > 2048 )
  331.     {
  332.     swap_size = 2048;
  333.     }
  334.     if( swap_size < 0 ) 
  335.     {
  336.     swap_size = 0;
  337.     }
  338.  
  339.  
  340.     // look for a min size
  341.     // 1G    -> 128MB
  342.     // 2G    -> 256MB
  343.     // 10G   -> 512MB
  344.     // 40G   -> 1GB
  345.  
  346.     if( slot_size > (40 * 1024) &&  (swap_size + mem) < 1024 )
  347.     {
  348.     swap_size = 1024 - mem;
  349.     }
  350.     else if( slot_size > (10 * 1024)  &&  (swap_size + mem) < 512 )
  351.     {
  352.     swap_size = 512 - mem;
  353.     }
  354.     else if( slot_size > (2 * 1024)  &&  (swap_size + mem) < 256 )
  355.     {
  356.     swap_size = 256 - mem;
  357.     }
  358.     else if( slot_size > (1 * 1024)  &&  (swap_size + mem) < 128 )
  359.     {
  360.     swap_size = 128 - mem;
  361.     }
  362.  
  363.     if( swap_size == 0 )
  364.     {
  365.     swap_size = -1;
  366.     }
  367.     y2milestone( "SwapSizeMb mem %1 slot_size %2 swap_size %3", mem,
  368.                  slot_size, swap_size );
  369.     return( swap_size );
  370.     };
  371.  
  372. global define boolean UseParted()
  373.     ``{
  374.     boolean ret = true;
  375. /*
  376.     if( Arch::i386 () || Arch::x86_64 () )
  377.     ret = false;
  378. */
  379.     y2milestone( "UseParted ret:%1", ret );
  380.     return( ret );
  381.     }
  382.  
  383. global define boolean IsResizable( integer fsid )
  384.     ``{
  385.     boolean ret = false;
  386.     ret = IsDosWinNtPartition(fsid) || fsid == fsid_swap || fsid == fsid_native;
  387.     y2milestone( "IsResizable fsid:%1 ret:%2", fsid, ret );
  388.     return( ret );
  389.     }
  390.  
  391. global define boolean IsLinuxPartition( integer fsid )
  392.     ``{
  393.     return ( fsid==fsid_native || fsid==fsid_swap || fsid==fsid_lvm ||
  394.          fsid==fsid_raid || fsid==fsid_gpt_boot );
  395.     };
  396.  
  397. global define map GetLoopOn( string device )
  398.     ``{
  399.     map ret = $[];
  400.     string cmd = sformat( "/sbin/losetup %1", device );
  401.     map bash_call = (map) SCR::Execute (.target.bash_output, cmd, $[] );
  402.     if( bash_call["exit"]:1 == 0)
  403.     {
  404.     string text = bash_call["stdout"]:"";
  405.     integer fi = search( text, ")" );
  406.     if( fi!=nil && fi>0 )
  407.         {
  408.         text = substring( text, 0, fi );
  409.         fi = search( text, "(" );
  410.         if( fi!=nil && fi>0 )
  411.         {
  412.         text = substring( text, fi+1 );
  413.         ret["file"] = text;
  414.         map stat = (map) SCR::Read( .target.stat, text );
  415.         ret["blockdev"] = stat["isblock"]:false;
  416.         }
  417.         }
  418.     }
  419.     y2milestone( "dev %1 ret %2", device, ret );
  420.     return( ret );
  421.     }
  422.  
  423. global define string TranslateMapperName( string device )
  424.     ``{
  425.     string ret = device;
  426.     string regex = "[^-](--)*-[^-]";
  427.     if( search( device, "/dev/mapper/" )==0 )
  428.     {
  429.     list<integer> pos = regexppos( device, regex );
  430.     y2milestone( "pos=%1", pos );
  431.     if( size(pos)>0 )
  432.         {
  433.         ret = "/dev/" + substring(device,12,pos[0]:0+pos[1]:0-14) + "/" +
  434.               substring(device,pos[0]:0+pos[1]:0-1);
  435.         integer spos = 4;
  436.         integer newpos = search(substring(ret,spos), "--");
  437.         if( newpos!=nil )
  438.         spos = spos + newpos;
  439.         else
  440.         spos = -1;
  441.         while( spos>=0 )
  442.         {
  443.         ret = substring(ret, 0, spos+1) + substring( ret, spos+2 );
  444.         spos = spos + 1;
  445.         newpos = search(substring(ret,spos), "--");
  446.         if( newpos!=nil )
  447.             spos = spos + newpos;
  448.         else
  449.             spos = -1;
  450.         }
  451.         }
  452.     y2milestone( "TranslateMapperName %1 -> %2", device, ret );
  453.     }
  454.     return( ret );
  455.     }
  456.  
  457. /**
  458.  *    Return a list with all mounted partition
  459.  *  @return list<map>
  460.  */
  461. global define list<map> CurMounted()
  462.     ``{
  463.     SCR::UnmountAgent (.proc.mounts);
  464.     SCR::UnmountAgent (.proc.swaps);
  465.     SCR::UnmountAgent (.etc.mtab);
  466.     list<map> mounts = (list<map>) SCR::Read(.proc.mounts);
  467.     list<map> swaps  = (list<map>) SCR::Read(.proc.swaps );
  468.     list<map> mtab   = (list<map>) SCR::Read(.etc.mtab );
  469.  
  470.     foreach(map swap, swaps,
  471.     ``{
  472.     map swap_entry = $[
  473.                "file" : "swap",
  474.                "spec" :  swap["file"]:""
  475.         ];
  476.  
  477.     mounts = add( mounts, swap_entry );
  478.  
  479.     });
  480.  
  481.     map mtab_root = (map) find(map mount, mtab, ``( mount["file"]:"" == "/" ));
  482.     map root_map  = (map) find(map mount, mounts, 
  483.                                ``( mount["spec"]:"" == "/dev/root" ));
  484.     if( root_map == nil )
  485.     {
  486.     root_map = (map) find(map mount, mounts, 
  487.                               ``( mount["spec"]:"" != "rootfs"&&
  488.                       mount["file"]:"" == "/"));
  489.     }
  490.     y2milestone( "mtab_root %1 root_map %2", mtab_root, root_map );
  491. //    root_map = add (root_map, "spec", mtab_root["spec"]:"");
  492.     if( root_map["spec"]:"" == "/dev/root" )
  493.     root_map["spec"] = mtab_root["spec"]:"";
  494.     if( (search( root_map["spec"]:"", "LABEL=" )==0 ||
  495.          search( root_map["spec"]:"", "UUID=" )==0) && !Stage::initial () )
  496.     {
  497.     map bo = (map) SCR::Execute (.target.bash_output, "fsck -N /", $[] );
  498.     y2milestone( "CurMounted bo:%1", bo );
  499.     string dev = "";
  500.     if( bo["exit"]:1==0 )
  501.         {
  502.         list tmp = filter( string k, splitstring( bo["stdout"]:"", " \n" ),
  503.                            ``(size(k)>0) );
  504.         if( size(tmp)>0 )
  505.         dev = tmp[size(tmp)-1]:"";
  506.         y2milestone( "CurMounted LABEL/UUID dev:%1", dev );
  507.         }
  508.     if( size(dev)>0 )
  509.         {
  510.         root_map["spec"] = dev;
  511.         }
  512.     }
  513.     y2milestone( "root_map %1", root_map );
  514. //    this version makes some problems with interpreter, above lookup/add is OK
  515.     mounts = filter(map mount, mounts, ``( mount["file"]:"" != "/"));
  516.     mounts = add( mounts, root_map );
  517.     list<map> ret = [];
  518.     foreach(map p, mounts, ``{
  519.     if( search( p["spec"]:"", "/dev/loop" )!=nil )
  520.         {
  521.         map r = GetLoopOn( p["spec"]:"" );
  522.         if( r["blockdev"]:false )
  523.         {
  524.         p["loop_on"] = r["file"]:"";
  525.         }
  526.         }
  527.     ret = add( ret, p );
  528.     });
  529.     ret = maplist( map p, ret, 
  530.     ``{
  531.     p["spec"] = TranslateMapperName( p["spec"]:"" );
  532.     return( p );
  533.     });
  534.     y2milestone( "CurMounted all mounts %1", ret);
  535.     return ret;
  536.     };
  537.  
  538.  
  539. global define map GetFstab( string pathname )
  540.     ``{
  541.     map file = $[];
  542.     AsciiFile::SetComment( file, "^[ \t]*#" );
  543.     AsciiFile::SetDelimiter( file, " \t" );
  544.     AsciiFile::SetListWidth( file, [ 20, 20, 10, 21, 1, 1 ] );
  545.     AsciiFile::ReadFile( file, pathname );
  546.     return( file );
  547.     };
  548.  
  549. global define map GetCrypto( string pathname )
  550.     ``{
  551.     map file = $[];
  552.     AsciiFile::SetComment( file, "^[ \t]*#" );
  553.     AsciiFile::SetDelimiter( file, " \t" );
  554.     AsciiFile::SetListWidth( file, [ 11, 15, 20, 10, 10, 1 ] );
  555.     AsciiFile::ReadFile( file, pathname );
  556.     return( file );
  557.     };
  558.  
  559. global define string ToHexString( integer num ) 
  560.     ``{
  561.     string to_hex = "0123456789ABCDEF";
  562.     string ret = "";
  563.     if( num>256 )
  564.     {
  565.     ret = sformat("0x%1%2%3", substring( to_hex, num/256, 1 ),
  566.                   substring( to_hex, (num%256)/16, 1 ),
  567.                       substring( to_hex, num%16, 1 ) );
  568.     }
  569.     else
  570.     {
  571.     ret = sformat("0x%1%2", substring( to_hex, num/16, 1 ),
  572.                       substring( to_hex, num%16, 1 ) );
  573.     }
  574.     return( ret );
  575.     }
  576.  
  577. global define string FsIdToString( integer fs_id ) 
  578.     ``{
  579.     if ( fs_id == 0xa7) return( "NeXTSTEP");
  580.     if ( fs_id == 0xb7) return( "BSDI fs");
  581.     if ( fs_id == 0xb8) return( "BSDI swap");
  582.     if ( fs_id == 0xc1) return( "DRDOS/sec");
  583.     if ( fs_id == 0xc4) return( "DRDOS/sec");
  584.     if ( fs_id == 0xc6) return( "DRDOS/sec");
  585.     if ( fs_id == 0xc7) return( "Syrinx");
  586.     if ( fs_id == 0xda) return( "Non-Fs data");
  587.     if ( fs_id == 0xdb) return( "CP/M / CTOS");
  588.     if ( fs_id == 0xde) return( "Dell Utility");
  589.     if ( fs_id == 0xe1) return( "DOS access");
  590.     if ( fs_id == 0xe3) return( "DOS R/O");
  591.     if ( fs_id == 0xe4) return( "SpeedStor");
  592.     if ( fs_id == 0xeb) return( "BeOS fs");
  593.     if ( fs_id == 0xee) return( "EFI GPT");
  594.     if ( fs_id == 0xef) return( "EFI (FAT-12/16)");
  595.     if ( fs_id == 0xf1) return( "SpeedStor");
  596.     if ( fs_id == 0xf4) return( "SpeedStor");
  597.     if ( fs_id == 0xf2) return( "DOS secondary ");
  598.     if ( fs_id == 0xfd) return( "Linux RAID");
  599.     if ( fs_id == 0xfe) return( "LANstep");
  600.     if ( fs_id == 0xff) return( "BBT");
  601.     if ( fs_id == 0x0)  return( "empty");
  602.     if ( fs_id == 0x1)  return( "FAT12");
  603.     if ( fs_id == 0x2)  return( "XENIX root");
  604.     if ( fs_id == 0x3)  return( "XENIX usr");
  605.     if ( fs_id == 0x4)  return( "FAT16 <32M");
  606.     if ( fs_id == 0x5)  return( "Extended");
  607.     if ( fs_id == 0x6)  return( "FAT16");
  608.     if ( fs_id == 0x7)  return( "HPFS/NTFS");
  609.     if ( fs_id == 0x8)  return( "AIX");
  610.     if ( fs_id == 0x9)  return( "AIX boot");
  611.     if ( fs_id == 0xa)  return( "OS/2 boot manager");
  612.     if ( fs_id == 0xb)  return( "Win95 FAT32");
  613.     if ( fs_id == 0xc)  return( "Win95 FAT32 LBA");
  614.     if ( fs_id == 0xe)  return( "Win95 FAT16");
  615.     if ( fs_id == 0xf)  return( "Extended");
  616.     if ( fs_id == 0x10) return( "OPUS");
  617.     if ( fs_id == 0x11) return( "Hidden FAT12");
  618.     if ( fs_id == 0x12) return( "Vendor diag");
  619.     if ( fs_id == 0x14) return( "Hidden FAT16");
  620.     if ( fs_id == 0x16) return( "Hidden FAT16");
  621.     if ( fs_id == 0x17) return( "Hidden HPFS/NTFS");
  622.     if ( fs_id == 0x18) return( "AST Windows");
  623.     if ( fs_id == 0x1b) return( "Hidden Win95");
  624.     if ( fs_id == 0x1c) return( "Hidden Win95");
  625.     if ( fs_id == 0x1e) return( "Hidden Win95");
  626.     if ( fs_id == 0x24) return( "NEC DOS");
  627.     if ( fs_id == 0x39) return( "Plan 9");
  628.     if ( fs_id == 0x3c) return( "PartitionMagic");
  629.     if ( fs_id == 0x40) return( "Venix 80286");
  630.     if ( fs_id == 0x41) return( "PPC PReP Boot");
  631.     if ( fs_id == 0x42) return( "SFS");
  632.     if ( fs_id == 0x4d) return( "QNX4.x");
  633.     if ( fs_id == 0x4e) return( "QNX4.x 2nd par");
  634.     if ( fs_id == 0x4f) return( "QNX4.x 3rd par");
  635.     if ( fs_id == 0x50) return( "OnTrack DM");
  636.     if ( fs_id == 0x51) return( "OnTrack DM6");
  637.     if ( fs_id == 0x52) return( "CP/M");
  638.     if ( fs_id == 0x53) return( "OnTrack DM6");
  639.     if ( fs_id == 0x54) return( "OnTrack DM6");
  640.     if ( fs_id == 0x55) return( "EZ-Drive");
  641.     if ( fs_id == 0x56) return( "Golden Bow");
  642.     if ( fs_id == 0x5c) return( "Priam Edisk");
  643.     if ( fs_id == 0x61) return( "SpeedStor");
  644.     if ( fs_id == 0x63) return( "GNU HURD");
  645.     if ( fs_id == 0x64) return( "Novell Netware");
  646.     if ( fs_id == 0x65) return( "Novell Netware");
  647.     if ( fs_id == 0x70) return( "DiskSecure");
  648.     if ( fs_id == 0x75) return( "PC/IX");
  649.     if ( fs_id == 0x80) return( "Old Minix");
  650.     if ( fs_id == 0x81) return( "Minix");
  651.     if ( fs_id == 0x82) return( "Linux swap");
  652.     if ( fs_id == 0x83) return( "Linux native");
  653.     if ( fs_id == 0x84) return( "OS/2 hidden");
  654.     if ( fs_id == 0x85) return( "Linux extended");
  655.     if ( fs_id == 0x86) return( "NTFS volume");
  656.     if ( fs_id == 0x87) return( "NTFS volume");
  657.     if ( fs_id == 0x8e) return( "Linux LVM");
  658.     if ( fs_id == 0x93) return( "Amoeba");
  659.     if ( fs_id == 0x94) return( "Amoeba BBT");
  660.     if ( fs_id == 0x9f) return( "BSD/OS");
  661.     if ( fs_id == 0xa0) return( "Hibernation");
  662.     if ( fs_id == 0xa5) return( "FreeBSD");
  663.     if ( fs_id == 0xa6) return( "OpenBSD");
  664.     if ( fs_id == 0x102) return( "Apple_HFS");
  665.     if ( fs_id == 0x103) return( "EFI boot");
  666.     if ( fs_id == 0x104) return( "Service");
  667.     if ( fs_id == 0x105) return( "Microsoft reserved");
  668.     if ( fs_id == 0x106) return( "Apple_UFS");
  669.     return( "unknown" );
  670.     };
  671.  
  672. map capabilities = $[ "msdos" : $[ "extended" : true,
  673.                                    "max_primary" : 4 ],
  674.               "gpt"   : $[ "max_primary" : 16 ],
  675.               "mac"   : $[ "max_primary" : 16 ],
  676.               "amiga" : $[ "max_primary" : 16 ],
  677.               "sun"   : $[ "max_primary" : 8 ],
  678.               "bsd"   : $[ "max_primary" : 8 ],
  679.               "dasd"  : $[ "max_primary" : 3 ]
  680.             ];
  681.  
  682. global define integer MaxPrimary( string label )
  683.     ``{
  684.     integer ret = capabilities[label,"max_primary"]:4;
  685.     y2milestone( "MaxPrimary label:%1 ret:%2", label, ret );
  686.     return( ret );
  687.     }
  688.  
  689. global define integer MaxLogical( string device )
  690.     ``{
  691.     integer ret = 15;
  692.     if( search( device, "/dev/hd" )==0 )
  693.     {
  694.     ret = 63;
  695.     }
  696.     else if( search( device, "/dev/rd/c" )==0 )
  697.     {
  698.     ret = 7;
  699.     }
  700.     y2milestone( "MaxLogical:%1 ret:%2", device, ret );
  701.     return( ret );
  702.     }
  703.  
  704. global define boolean HasExtended( string label )
  705.     ``{
  706.     boolean ret = capabilities[label,"extended"]:false;
  707.     y2milestone( "HasExtended label:%1 ret:%2", label, ret );
  708.     return( ret );
  709.     }
  710.  
  711. global define string RdonlyText( string disk, boolean expert_partitioner )
  712.     ``{
  713.     string text = "";
  714.     if( expert_partitioner )
  715.     {
  716.     text = sformat( "Operation not permitted on disk %1 !\n", disk );
  717.     }
  718.     // popup text %1 is replaced by disk name e.g. /dev/hda
  719.     text = text + sformat( _("
  720. The partitioning on your disk %1 is either not readable by
  721. the partitioning tool parted used to change the
  722. partition table or is not supported by this tool.
  723.  
  724. You may use the partitions on disk %1 as they are or
  725. format them and assign mount points to them, but you
  726. cannot add, edit, resize, or remove partitions from that
  727. disk here.\n"), disk );
  728.     if( expert_partitioner )
  729.     {
  730.     // popup text 
  731.     text = text + _("
  732.  
  733. You may initialize the disk partition table to a sane state in the Expert
  734. Partitioner by selecting \"Expert\"->\"Delete Partition Table 
  735. and Disk Label\", but this will destroy all data on all partitions of this 
  736. disk.
  737. ");
  738.     }
  739.     else
  740.     {
  741.     text = text + _("
  742.  
  743. Safely ignore this message if you do not intend to use 
  744. this disk during installation.
  745. ");
  746.     }
  747.     return( text );
  748.     }
  749.  
  750.     /*---------------------------------------------------------------------
  751.      * returns for a string a string with a minimum of 9 characters:
  752.      * "1"      -> "       1"
  753.      * "22"     -> "      22"
  754.      * "145"    -> "     145"
  755.      * "2134"   -> "    2134"
  756.      *----------------------------------------------------------------------
  757.      */
  758. define string sto8string( string str )
  759.     ``{
  760.     integer nb = size( str );
  761.     if ( nb > 8  )   return( sformat( "%1", str ));
  762.     if ( nb > 7  )   return( sformat( " %1", str ));
  763.     if ( nb > 6  )   return( sformat( "  %1", str ));
  764.     if ( nb > 5  )   return( sformat( "   %1", str ));
  765.     if ( nb > 4  )   return( sformat( "    %1", str ));
  766.     if ( nb > 3  )   return( sformat( "     %1", str ));
  767.     if ( nb > 2  )   return( sformat( "      %1", str ));
  768.     if ( nb > 1  )   return( sformat( "       %1", str ));
  769.     return( sformat( "         %1", str ));
  770.     };
  771.  
  772. /*---------------------------------------------------------------------
  773.  * Convert <number-of-bytes> to XXX.X MB or XXX.X GB or XXX.X TB
  774.  *
  775.  * see also ByteToHumanStringWithZero !
  776.  * Return value: string  "unknown" if input == 0
  777.  *----------------------------------------------------------------------
  778.  */
  779. global define string ByteToHumanString ( integer number )
  780.     ``{
  781.     // column description, if disk space is not known
  782.     if( number == 0 ) return( _("unknown") );
  783.  
  784.     if( number < 1073741824 )
  785.     {
  786.     // < 1 GB
  787.     integer MB    = number / 1048576;
  788.     integer hunKB = (number - (MB * 1048576)) / 104858;
  789.     return( sto8string(sformat( "%1.%2 MB", MB,hunKB )));
  790.     }
  791.     else if ( number < 1099511627776 )
  792.     {
  793.     // < 1 TB
  794.     integer GB    = number / 1073741824;
  795.     integer hunMB = (number - (GB * 1073741824)) / 107374183;
  796.     return( sto8string(sformat( "%1.%2 GB", GB,hunMB )));
  797.     }
  798.     else
  799.         {
  800.         // >= 1 TB
  801.         integer TB    = number / 1099511627776;
  802.         integer hunGB = (number - (TB * 1099511627776)) / 109951162778;
  803.     return( sto8string(sformat( "%1.%2 TB", TB,hunGB )));
  804.         }
  805.     };
  806.  
  807.  
  808. }
  809.