From 4fe3fa0731df002a22320458e5e55c5cc1ec5318 Mon Sep 17 00:00:00 2001 From: Olivier Blin Date: Thu, 30 Jul 2009 17:56:44 +0000 Subject: move / size and fs type pre-computing in a new supplement_partitions media method --- draklive | 19 ++++++++++++------- lib/MDV/Draklive/Config.pm | 1 - lib/MDV/Draklive/Media.pm | 11 +++++++++++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/draklive b/draklive index b9ec914..2061781 100755 --- a/draklive +++ b/draklive @@ -678,7 +678,7 @@ sub allocate_partition { } sub allocate_master { - my ($live, $media, $dest, $size, $fs) = @_; + my ($live, $media, $dest, $size) = @_; mkdir_p(dirname($dest)); my $geom = { heads => 16, @@ -694,7 +694,7 @@ sub allocate_master { MDV::Draklive::Utils::device_allocate_file($dest, $disk_size); my $slash = find { $_->{mntpoint} eq '/' } @{$media->{partitions}}; - $slash->{fs_type} = $fs; + my $fs = $slash->{fs_type}; #- FIXME: use fsedit::allocatePartitions and $media->{partitions}? # foreach (@{$media->{partitions}}) { # set pt_type } @@ -756,6 +756,9 @@ EOF sub create_disk_master { my ($live, $opts) = @_; + + $live->{media}->supplement_partitions(directory_usage($live->get_system_root)); + my $dest = get_disk_master_path($live); my $disk_size = @{$live->{mount}{dirs} || []} ? #- dumb guess, a bit too large, and valid for FAT only @@ -763,10 +766,9 @@ sub create_disk_master { directory_usage($live->get_builddir . $live->{prefix}{build}{boot}) + directory_usage($live->get_builddir . $live->{prefix}{build}{files}) + 70000000) : - directory_usage($live->get_system_root) + 200000000 + fold_left { $::a + $::b } map { $_->{size} * $common::SECTORSIZE } @{$live->{media}{partitions}}; - #- FIXME: use size from $live->{media}{partitions} for / too + 200000000 + fold_left { $::a + $::b } map { $_->{size} * $common::SECTORSIZE } @{$live->{media}{partitions}}; - my @loops = allocate_master($live, $live->{media}, $dest, $disk_size, $live->{media}->get_media_setting('fs')); + my @loops = allocate_master($live, $live->{media}, $dest, $disk_size); my $slash_idx = $live->{media}->find_partition_index('/'); local $opts->{device} = $loops[$slash_idx]; local $opts->{disk_device} = $dest; @@ -1155,8 +1157,11 @@ sub create_usb_replicator { my ($live) = @_; my $dest = get_disk_replicator_path($live); my %files = get_disk_replicator_files($live); - my $size = fold_left { $::a + $::b } map { directory_usage($_, 'apparent') } keys(%files); - my @loops = allocate_master($live, $live->{replicator}{media}, $dest, 8000000 + $size, 'vfat'); + + my $size = 8000000 + fold_left { $::a + $::b } map { directory_usage($_, 'apparent') } keys(%files); + $live->{replicator}{media}->supplement_partitions($size); + + my @loops = allocate_master($live, $live->{replicator}{media}, $dest, $size); my $slash_idx = $live->{replicator}{media}->find_partition_index('/'); my $opts = { device => $loops[$slash_idx], disk_device => $dest, append => $live->{replicator}{append} }; record_usb_replicator($live, $opts); diff --git a/lib/MDV/Draklive/Config.pm b/lib/MDV/Draklive/Config.pm index 3216c4d..9cf96a0 100644 --- a/lib/MDV/Draklive/Config.pm +++ b/lib/MDV/Draklive/Config.pm @@ -79,7 +79,6 @@ sub complete_config { foreach ($live->{media}, if_($live->{replicator}{media}, $live->{replicator}{media}), if_($live->{oem_rescue}{media}, $live->{oem_rescue}{media})) { bless $_, 'MDV::Draklive::Media'; - $_->{partitions} ||= [ { mntpoint => '/' } ]; } mkdir_p($live->get_builddir); diff --git a/lib/MDV/Draklive/Media.pm b/lib/MDV/Draklive/Media.pm index d75eeb4..278d463 100644 --- a/lib/MDV/Draklive/Media.pm +++ b/lib/MDV/Draklive/Media.pm @@ -2,6 +2,7 @@ package MDV::Draklive::Media; use MDK::Common; use MDV::Draklive::Storage; +use common; sub get_initrd_path { my ($media) = @_; @@ -51,4 +52,14 @@ sub find_partition_index { eval { find_index { $_->{mntpoint} eq $mntpoint } @{$media->{partitions}} }; } +sub supplement_partitions { + my ($media, $total_size) = @_; + + $media->{partitions} ||= [ { mntpoint => '/' } ]; + + my $slash = find { $_->{mntpoint} eq '/' } @{$media->{partitions}}; + $slash->{fs_type} ||= $media->get_media_setting('fs'); + $slash->{size} ||= $total_size / $common::SECTORSIZE; +} + 1; -- cgit v1.2.1