package list_modules; use MDK::Common; our @ISA = qw(Exporter); our @EXPORT = qw(load_dependencies dependencies_closure category2modules module2category sub_categories); # the categories have 2 purposes # - choosing modules to include on stage1's (cf update_kernel and mdk-stage1/pci-resource/update-pci-ids.pl) # - performing a load_category or probe_category (modules.pm and many files in perl-install) our %l = ( ################################################################################ network => { main => [ if_(arch() =~ /ppc/, qw(mace bmac gmac)), if_(arch() =~ /^sparc/, qw(sunbmac sunhme sunqe)), if_(arch() !~ /alpha/ && arch() !~ /sparc/, qw(3c501 3c503 3c505 3c507 3c509 3c515), qw(82596 abyss ac3200 acenic aironet4500_card at1700 atp com20020-pci), qw(cs89x0 de600 de620), qw(defxx orinoco_plx), # most unused qw(depca dgrs dmfe e100 e2100 eepro eepro100 eexpress epic100 eth16i), qw(ewrk3 hamachi hp hp-plus hp100 ibmtr), qw(lance natsemi ne ne2k-pci ni5010 ni52 ni65 nvnet olympic pcnet32 plip rcpci), qw(sb1000 sis900 smc-ultra smc9194 starfire tlan tmspci tulip via-rhine), qw(wd winbond-840), qw(fealnx 3c990fx), qw(skfp tc35815 lanstreamer farsync sdladrv orinoco_pci prism2_plx), qw(iph5526), #- fibre channel ), qw(3c59x 8139too sundance), #rtl8139 ], gigabit => [ qw(dl2k myri_sbus yellowfin ns83820 r8169 tg3 e1000 sk98lin), qw(bcm5820 bcm5700), #- encrypted ], raw => [ qw(ppp_generic ppp_async), ], pcmcia => [ qw(3c574_cs 3c589_cs airo airo_cs aironet4500_cs axnet_cs fmvj18x_cs), qw(ibmtr_cs orinoco_cs netwave_cs nmclan_cs pcnet_cs ray_cs smc91c92_cs wavelan_cs wvlan_cs), qw(xirc2ps_cs xircom_cb xircom_tulip_cb), ], usb => [ qw(pegasus kaweth usbnet catc CDCEther), ], isdn => [ qw(b1pci c4 hisax hisax_fcpcipnp hysdn t1pci tpam), ], }, ################################################################################ disk => { scsi => [ if_(arch() =~ /ppc/, qw(mesh mac53c94)), if_(arch() =~ /^sparc/, qw(qlogicpti)), if_(arch() !~ /alpha/ && arch() !~ /sparc/, qw(3w-xxxx AM53C974 BusLogic NCR53c406a a100u2w advansys aha152x aha1542 aha1740), qw(atp870u dc395x_trm dtc g_NCR5380 in2000 initio pas16 pci2220i psi240i fdomain), qw(qla1280 qla2x00 qlogicfas qlogicfc), qw(seagate wd7000 sim710 sym53c416 t128 tmscsim u14-34f ultrastor), qw(eata eata_pio eata_dma mptscsih nsp32), ), '53c7,8xx', qw(aic7xxx pci2000 qlogicisp sym53c8xx), # ncr53c8xx ], hardware_raid => [ if_(arch() =~ /^sparc/, qw(pluto)), if_(arch() !~ /alpha/ && arch() !~ /sparc/, qw(DAC960 dpt_i2o megaraid aacraid ataraid cciss cpqarray gdth i2o_block), qw(cpqfc qla2200 qla2300 hptraid), qw(ips ppa imm), ), ], pcmcia => [ qw(aha152x_cs fdomain_cs nsp_cs qlogic_cs ide-cs) ], #ide_cs raw => [ qw(scsi_mod sd_mod) ], usb => [ qw(usb-storage) ], firewire => [ qw(sbp2) ], cdrom => [ qw(ide-cd cdrom sr_mod) ], }, ################################################################################ bus => { usb => [ qw(usbcore usb-uhci usb-ohci ehci-hcd usbkbd keybdev input) ], firewire => [ qw(ohci1394 ieee1394) ], pcmcia => [ if_(arch() !~ /^sparc/, qw(pcmcia_core tcic ds i82365 yenta_socket)), # cb_enabler ], #serial_cs #ftl_cs 3c575_cb apa1480_cb epic_cb serial_cb tulip_cb iflash2+_mtd iflash2_mtd #cb_enabler }, fs => { network => [ qw(af_packet nfs lockd sunrpc) ], cdrom => [ qw(isofs) ], loopback => [ qw(isofs loop) ], local => [ if_(arch() =~ /^i.86/, qw(vfat fat)), if_(arch() =~ /^ppc/, qw(hfs)), qw(reiserfs), ], various => [ qw(smbfs romfs jbd xfs) ], }, ################################################################################ multimedia => { sound => [ if_(arch() =~ /ppc/, qw(dmasound_awacs)), if_(arch() !~ /^sparc/, qw(ad1816 ad1848 ad1889 ali5455 awe_wave audigy cmpci cs46xx cs4232 cs4281 emu10k1 es1370 es1371 esssolo1 forte), qw(gus i810_audio ice1712 mad16 maestro maestro3 mpu401 msnd_pinnacle nvaudio opl3 opl3sa opl3sa2 nm256_audio), qw(pas2 pss rme96xx sb sgalaxy sam9407 sonicvibes sscape trident via82cxxx_audio wavefront ymfpci), qw(snd-ali5451 snd-als100 snd-als4000 snd-azt2320 snd-azt3328 snd-cmi8330 snd-cmipci), qw(snd-cs4231 snd-cs4232 snd-cs4236 snd-cs46xx snd-dt0197h snd-cs4281 snd-emu10k1), qw(snd-ad1816a snd-ad1848 snd-gusclassic snd-gusextreme snd-gusmax snd-interwave), qw(snd-mpu401 snd-opti93x snd-rme9652 snd-sb8 snd-sbawe), qw(snd-ens1370 snd-ens1371 snd-es18xx snd-es968 snd-es1938 snd-es1968 snd-es1688), qw(snd-fm801 snd-hdsp snd-ice1712 snd-intel8x0 snd-korg1212 snd-maestro3), qw(snd-nm256 snd-rme96 snd-rme32 snd-opl3sa2 snd-sb16 snd-sgalaxy snd-sonicvibes), qw(snd-trident snd-usb-audio snd-via82xx snd-wavefront snd-ymfpci), ), ], tv => [ qw(bttv cpia_usb ibmcam mod_quickcam ov511 ov518_decomp ultracam usbvideo cyber2000fb saa7134) ], photo => [ qw(dc2xx mdc800) ], radio => [ qw(radio-maxiradio) ], scanner => [ qw(scanner microtek) ], joystick => [ qw(ns558 emu10k1-gp iforce) ], }, various => # just here for classification, unused categories (nor auto-detect, nor load_thiskind) { raid => [ qw(linear raid0 raid1 raid5 lvm-mod md multipath xor), ], mouse => [ qw(busmouse msbusmouse logibusmouse serial qpmouse atixlmouse), ], char => [ qw(amd768_rng applicom n_r3964 nvram pc110pad ppdev), qw(mxser moxa isicom wdt_pci epca synclink istallion sonypi i810-tco sx), #- what are these??? ], other => [ qw(agpgart defxx i810_rng i810fb ide-floppy ide-scsi ide-tape loop lp nbd sg st), qw(parport parport_pc parport_serial), qw(btaudio), #- these need checking qw(pcilynx sktr rrunner gmac meye 3c559 buz paep), ], }, ); my %dependencies; sub load_dependencies { my ($file) = @_; %dependencies = map { my ($f, $deps) = split ':'; $f => [ split ' ', $deps ]; } cat_($file); } sub dependencies_closure { my @l = map { dependencies_closure($_) } @{$dependencies{$_[0]} || []}; (@l, $_[0]); } sub category2modules { map { my ($t1, $t2s) = m|(.*)/(.*)|; map { my $l = $l{$t1}{$_} or die "bad category $t1/$_\n" . backtrace(); @$l; } split('\|', $t2s); } split(' ', $_[0]); } sub module2category { my ($module) = @_; foreach my $t1 (keys %l) { my $h = $l{$t1}; foreach my $t2 (keys %$h) { $module eq $_ and return "$t1/$t2" foreach @{$h->{$t2}}; } } return; } sub sub_categories { my ($t1) = @_; keys %{$l{$t1}}; } 1; d='n23' href='#n23'>23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
package fsedit; # $Id$
use diagnostics;
use strict;
use vars qw(%suggestions);
#-######################################################################################
#- misc imports
#-######################################################################################
use common;
use partition_table qw(:types);
use partition_table_raw;
use detect_devices;
use fsedit;
use devices;
use loopback;
use log;
use fs;
%suggestions = (
__("simple") => [
{ mntpoint => "/", size => 300 << 11, type =>0x483, ratio => 5, maxsize =>3500 << 11 },
{ mntpoint => "swap", size => 64 << 11, type => 0x82, ratio => 1, maxsize => 250 << 11 },
{ mntpoint => "/home", size => 300 << 11, type =>0x483, ratio => 3 },
], __("with /usr") => [
{ mntpoint => "/", size => 150 << 11, type =>0x483, ratio => 1, maxsize => 500 << 11 },
{ mntpoint => "swap", size => 64 << 11, type => 0x82, ratio => 1, maxsize => 250 << 11 },
{ mntpoint => "/usr", size => 300 << 11, type =>0x483, ratio => 4, maxsize =>3000 << 11 },
{ mntpoint => "/home", size => 100 << 11, type =>0x483, ratio => 5 },
], __("server") => [
{ mntpoint => "/", size => 150 << 11, type =>0x483, ratio => 1, maxsize => 250 << 11 },
{ mntpoint => "swap", size => 64 << 11, type => 0x82, ratio => 2, maxsize => 400 << 11 },
{ mntpoint => "/usr", size => 300 << 11, type =>0x483, ratio => 3, maxsize =>3000 << 11 },
{ mntpoint => "/var", size => 100 << 11, type =>0x483, ratio => 4 },
{ mntpoint => "/home", size => 100 << 11, type =>0x483, ratio => 5 },
],
);
foreach (values %suggestions) {
if (arch() =~ /ia64/) {
@$_ = ({ mntpoint => "/boot/efi", size => 50 << 11, type => 0xb, ratio => 1, maxsize => 150 << 11 }, @$_);
}
}
my @suggestions_mntpoints = (
"/var/ftp", "/var/www", "/boot",
arch() =~ /sparc/ ? "/mnt/sunos" : arch() =~ /ppc/ ? "/mnt/macos" : "/mnt/windows",
);
my @partitions_signatures = (
[ 0x8e, 0, "HM\1\0" ],
[ 0x83, 0x438, "\x53\xEF" ],
[ 0x183, 0x10034, "ReIsErFs" ],
[ 0x183, 0x10034, "ReIsEr2Fs" ],
[ 0x283, 0, 'XFSB', 0x200, 'XAGF', 0x400, 'XAGI' ],
[ 0x383, 0x8000, 'JFS1' ],
[ 0x82, 4086, "SWAP-SPACE" ],
[ 0x82, 4086, "SWAPSPACE2" ],
[ 0x7, 0x1FE, "\x55\xAA", 0x3, "NTFS" ],
[ 0xc, 0x1FE, "\x55\xAA", 0x52, "FAT32" ],
arch() !~ /^sparc/ ? (
[ 0x6, 0x1FE, "\x55\xAA", 0x36, "FAT" ],
) : (),
);
sub typeOfPart {
my $dev = devices::make($_[0]);
my $t = typeFromMagic($dev, @partitions_signatures);
if ($t == 0x83) {
#- there is no magic to differentiate ext3 and ext2. Using libext2fs
#- to check if it has a journal
$t = 0x483 if c::is_ext3($dev);
}
$t;
}
#-######################################################################################
#- Functions
#-######################################################################################
sub empty_all_hds {
{ hds => [], lvms => [], raids => [], loopbacks => [], raw_hds => [], nfss => [], smbs => [], special => [] };
}
sub recompute_loopbacks {
my ($all_hds) = @_;
my @fstab = get_all_fstab($all_hds);
@{$all_hds->{loopbacks}} = map { isPartOfLoopback($_) ? @{$_->{loopback}} : () } @fstab;
}
sub raids {
my ($hds) = @_;
my @parts = get_fstab(@$hds);
(grep { isRawRAID($_) } @parts) && detect_devices::raidAutoStart() or return [];
fs::get_major_minor(@parts);
my %devname2part = map { $_->{dev} => { %$_, device => $_->{dev} } } read_partitions();
my @raids;
my @mdstat = cat_("/proc/mdstat");
for (my $i = 0; $i < @mdstat; $i++) {
my ($nb, $level, $mdparts) =
#- line format is:
#- md%d : {in}?active{ (read-only)}? {linear|raid1|raid4|raid5}{ DEVNAME[%d]{(F)}?}*
$mdstat[$i] =~ /^md(.).* ([^ \[\]]+) (\S+\[\d+\].*)/ or next;
$level =~ s/raid//; #- { linear | raid0 | raid1 | raid5 } -> { linear | 0 | 1 | 5 }
my $chunks = $mdstat[$i+1] =~ /(\S+) chunks/ ? $1 : "64k";
my @raw_mdparts = map { /([^\[]+)/ } split ' ', $mdparts;
my @mdparts =
map {
my $mdpart = $devname2part{$_} || { device => $_ };
if (my ($part) = grep { is_same_hd($mdpart, $_) } @parts) {
$part->{raid} = $nb;
delete $part->{mntpoint};
$part;
} else {
#- forget it when not found? that way it won't break much... beurk.
();
}
} @raw_mdparts;
my $type = typeOfPart("md$nb");
log::l("RAID: found md$nb (raid $level) chunks $chunks ", if_($type, "type $type "), "with parts ", join(", ", @raw_mdparts));
$raids[$nb] = { 'chunk-size' => $chunks, type => $type || 0x83, disks => \@mdparts,
device => "md$nb", notFormatted => !$type, level => $level };
}
require raid;
raid::update(@raids);
\@raids;
}
sub hds {
my ($drives, $flags) = @_;
my (@hds);
my $rc;
foreach (@$drives) {
my $file = devices::make($_->{device});
my $hd = partition_table_raw::get_geometry($file) or log::l("An error occurred while getting the geometry of block device $file: $!"), next;
add2hash_($hd, $_);
$hd->{file} = $file;
$hd->{prefix} = $hd->{device};
# for RAID arrays of format c0d0p1
$hd->{prefix} .= "p" if $hd->{prefix} =~ m,(rd|ida|cciss|ataraid)/,;
eval { partition_table::read($hd, $flags->{clearall} || member($_->{device}, @{$flags->{clear} || []})) };
if ($@) {
cdie "ask_before_blanking:$@";
partition_table_raw::zero_MBR($hd);
}
member($_->{device}, @{$flags->{clear} || []}) and partition_table::remove($hd, $_)
foreach partition_table::get_normal_parts($hd);
# special case for Various type
$_->{type} = typeOfPart($_->{device}) || 0x100 foreach grep { $_->{type} == 0x100 } partition_table::get_normal_parts($hd);
#- special case for type overloading (eg: reiserfs is 0x183)
foreach (grep { isExt2($_) } partition_table::get_normal_parts($hd)) {
my $type = typeOfPart($_->{device});
$_->{type} = $type if $type > 0x100 || $type && $hd->isa('partition_table_gpt');
}
push @hds, $hd;
}
#- detect raids before LVM allowing LVM on raid
my $raids = raids(\@hds);
my $all_hds = { %{ empty_all_hds() }, hds => \@hds, lvms => [], raids => $raids };
my @lvms;
if (my @pvs = grep { isRawLVM($_) } get_all_fstab($all_hds)) {
#- otherwise vgscan won't find them
devices::make($_->{device}) foreach @pvs;
require lvm;
foreach (@pvs) {
my $name = lvm::get_vg($_) or next;
my ($lvm) = grep { $_->{LVMname} eq $name } @lvms;
if (!$lvm) {
$lvm = bless { disks => [], LVMname => $name }, 'lvm';
lvm::update_size($lvm);
lvm::get_lvs($lvm);
push @lvms, $lvm;
}
$_->{lvm} = $name;
push @{$lvm->{disks}}, $_;
}
}
$all_hds->{lvms} = \@lvms;
fs::get_major_minor(get_all_fstab($all_hds));
$all_hds;
}
sub read_partitions() {
my (undef, undef, @all) = cat_("/proc/partitions");
grep {
$_->{size} != 1 && # skip main extended partition
$_->{size} != 0x3fffffff # skip cdroms (otherwise stops cd-audios)
} map {
my %l;
@l{qw(major minor size dev)} = split;
\%l;
} @all;
}
sub readProcPartitions {
my ($hds) = @_;
my @all = read_partitions();
my @parts = grep { $_->{dev} =~ /\d$/ } @all;
my @disks = grep { $_->{dev} !~ /\d$/ } @all;
my $devfs_like = grep { $_->{dev} =~ m|/disc$| } @disks;
my %devfs2normal = map {
my (undef, $major, $minor) = devices::entry($_->{device});
my ($disk) = grep { $_->{major} == $major && $_->{minor} == $minor } @disks;
$disk->{dev} => $_->{device};
} @$hds;
foreach my $part (@parts) {
my $dev;
if ($devfs_like) {
$dev = -e "/dev/$part->{dev}" ? $part->{dev} : sprintf("0x%x%02x", $part->{major}, $part->{minor});
$part->{rootDevice} = $devfs2normal{dirname($part->{dev}) . '/disc'};
} else {
$dev = $part->{dev};
foreach my $hd (@$hds) {
$part->{rootDevice} = $hd->{device} if $part->{dev} =~ /^$hd->{device}./;
}
}
$part->{device} = $dev;
$part->{start} = 0; # unknown, but we don't care
$part->{size} *= 2; # from KB to sectors
$part->{type} = typeOfPart($dev);
delete $part->{dev}; # cleanup
}
@parts;
}
sub all_hds {
my ($all_hds) = @_;
(@{$all_hds->{hds}}, @{$all_hds->{lvms}});
}
sub part2hd {
my ($part, $all_hds) = @_;
my ($hd) = grep { $part->{rootDevice} eq $_->{device} } all_hds($all_hds);
$hd;
}
sub is_same_hd {
my ($hd1, $hd2) = @_;
if ($hd1->{major} && $hd2->{major}) {
$hd1->{major} == $hd2->{major} && $hd1->{minor} == $hd2->{minor};
} else {
$hd1->{device} eq $hd2->{device};
}
}
sub is_same_part {
my ($part1, $part2) = @_;
foreach ('start', 'size', 'type', 'rootDevice') {
$part1->{$_} eq $part2->{$_} or return;
}
1;
}
#- get all normal partition including special ones as found on sparc.
sub get_fstab {
map { partition_table::get_normal_parts($_) } @_;
}
#- get normal partition that should be visible for working on.
sub get_visible_fstab {
grep { $_ && !partition_table::isWholedisk($_) && !partition_table::isHiddenMacPart($_) }
map { partition_table::get_normal_parts($_) } @_;
}
sub get_fstab_and_holes {
map {
if (isLVM($_)) {
my @parts = partition_table::get_normal_parts($_);
my $free = $_->{totalsectors} - sum map { $_->{size} } @parts;
my $free_part = { start => 0, size => $free, type => 0, rootDevice => $_->{device} };
@parts, if_($free >= $_->cylinder_size, $free_part);
} else {
partition_table::get_normal_parts_and_holes($_);
}
} @_;
}
sub get_holes {
grep { $_->{type} == 0 } get_fstab_and_holes(@_);
}
sub get_all_fstab {
my ($all_hds) = @_;
my @parts = map { partition_table::get_normal_parts($_) } all_hds($all_hds);
my @raids = grep {$_} @{$all_hds->{raids}};
@parts, @raids, @{$all_hds->{loopbacks}};
}
sub get_really_all_fstab {
my ($all_hds) = @_;
my @parts = map { partition_table::get_normal_parts($_) } all_hds($all_hds);
my @raids = grep {$_} @{$all_hds->{raids}};
@parts, @raids, @{$all_hds->{loopbacks}}, @{$all_hds->{raw_hds}}, @{$all_hds->{nfss}}, @{$all_hds->{smbs}};
}
sub get_all_fstab_and_holes {
my ($all_hds) = @_;
my @raids = grep {$_} @{$all_hds->{raids}};
get_fstab_and_holes(all_hds($all_hds)), @raids, @{$all_hds->{loopbacks}};
}
sub get_all_holes {
my ($all_hds) = @_;
grep { $_->{type} == 0 } get_all_fstab_and_holes($all_hds);
}
sub all_free_space {
my ($all_hds) = @_;
sum map { $_->{size} } get_all_holes($all_hds);
}
sub free_space {
sum map { $_->{size} } get_holes(@_);
}
sub is_one_big_fat {
my ($hds) = @_;
@$hds == 1 or return;
my @l = get_fstab(@$hds);
@l == 1 && isFat($l[0]) && free_space(@$hds) < 10 << 11;
}
sub file2part {
my ($prefix, $fstab, $file, $keep_simple_symlinks) = @_;
my $part;
$file = $keep_simple_symlinks ? common::expand_symlinks_but_simple("$prefix$file") : expand_symlinks("$prefix$file");
unless ($file =~ s/^$prefix//) {
my ($part) = grep { loopback::carryRootLoopback($_) } @$fstab or die;
log::l("found $part->{mntpoint}");
$file =~ s|/initrd/loopfs|$part->{mntpoint}|;
}
foreach (@$fstab) {
my $m = $_->{mntpoint};
$part = $_ if
$file =~ /^\Q$m/ &&
(!$part || length $part->{mntpoint} < length $m);
}
$part or die "file2part: not found $file";
$file =~ s|$part->{mntpoint}/?|/|;
($part, $file);
}
sub computeSize {
my ($part, $best, $all_hds, $suggestions) = @_;
my $max = $part->{maxsize} || $part->{size};
return min($max, $best->{size}) unless $best->{ratio};
my $free_space = all_free_space($all_hds);
my @l = my @L = grep {
if (!has_mntpoint($_->{mntpoint}, $all_hds) && $free_space >= $_->{size}) {
$free_space -= $_->{size};
1;
} else { 0 } } @$suggestions;
my $tot_ratios = 0;
while (1) {
my $old_free_space = $free_space;
my $old_tot_ratios = $tot_ratios;
$tot_ratios = sum(map { $_->{ratio} } @l);
last if $tot_ratios == $old_tot_ratios;
@l = grep {
if ($_->{ratio} && $_->{maxsize} && $tot_ratios &&
$_->{size} + $_->{ratio} / $tot_ratios * $old_free_space >= $_->{maxsize}) {
return min($max, $best->{maxsize}) if $best->{mntpoint} eq $_->{mntpoint};
$free_space -= $_->{maxsize} - $_->{size};
0;
} else {
$_->{ratio};
}
} @l;
}
my $size = int min($max, $best->{size} + $free_space * ($tot_ratios && $best->{ratio} / $tot_ratios));
#- verify other entry can fill the hole
if (grep { $_->{size} < $max - $size } @L) { $size } else { $max }
}
sub suggest_part {
my ($part, $all_hds, $suggestions) = @_;
$suggestions ||= $suggestions{server} || $suggestions{simple};
my $has_swap = grep { isSwap($_) } get_all_fstab($all_hds);
my ($best, $second) =
grep { !$_->{maxsize} || $part->{size} <= $_->{maxsize} }
grep { $_->{size} <= ($part->{maxsize} || $part->{size}) }
grep { !has_mntpoint($_->{mntpoint}, $all_hds) || isSwap($_) && !$has_swap }
grep { !$_->{hd} || $_->{hd} eq $part->{rootDevice} }
grep { !$part->{type} || $part->{type} == $_->{type} || isTrueFS($part) && isTrueFS($_) }
@$suggestions or return;
#- if (arch() =~ /i.86/) {
#- $best = $second if
#- $best->{mntpoint} eq '/boot' &&
#- $part->{start} + $best->{size} > 1024 * $hd->cylinder_size(); #- if the empty slot is beyond the 1024th cylinder, no use having /boot
#- }
defined $best or return; #- sorry no suggestion :(
$part->{mntpoint} = $best->{mntpoint};
$part->{type} = $best->{type} if !(isTrueFS($best) && isTrueFS($part));
$part->{size} = computeSize($part, $best, $all_hds, $suggestions);
$part->{options} = $best->{options} if $best->{options};
1;
}
sub suggestions_mntpoint {
my ($all_hds) = @_;
sort grep { !/swap/ && !has_mntpoint($_, $all_hds) }
(@suggestions_mntpoints, map { $_->{mntpoint} } @{$suggestions{server} || $suggestions{simple}});
}
#-sub partitionDrives {
#-
#- my $cmd = "/sbin/fdisk";
#- -x $cmd or $cmd = "/usr/bin/fdisk";
#-
#- my $drives = findDrivesPresent() or die "You don't have any hard drives available! You probably forgot to configure a SCSI controller.";
#-
#- foreach (@$drives) {
#- my $text = "/dev/" . $_->{device};
#- $text .= " - SCSI ID " . $_->{id} if $_->{device} =~ /^sd/;
#- $text .= " - Model " . $_->{info};
#- $text .= " array" if $_->{device} =~ /^c.d/;
#-
#- #- truncate at 50 columns for now
#- $text = substr $text, 0, 50;
#- }
#- #-TODO TODO
#-}
sub mntpoint2part {
my ($mntpoint, $fstab) = @_;
first(grep { $mntpoint eq $_->{mntpoint} } @$fstab);
}
sub has_mntpoint {
my ($mntpoint, $all_hds) = @_;
mntpoint2part($mntpoint, [ get_really_all_fstab($all_hds) ]);
}
sub get_root_ {
my ($fstab, $boot) = @_;