summaryrefslogtreecommitdiffstats
path: root/lib/MDV/Draklive/Media.pm
blob: 4c7a7f4ba38ae589b589ba5a32d044c464d8c56d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
package MDV::Draklive::Media;

use MDK::Common;
use MDV::Draklive::Storage;
use common;

sub get_initrd_path {
    my ($media) = @_;
    '/' . $media->{storage} . '/initrd.gz';
}

#- mainly for storage-specific subroutines
sub get_storage_setting {
    my ($media, $setting) = @_;
    $MDV::Draklive::Storage::storage_types{$media->{storage}}{$setting};
}

#- for actions that support an optional boot storage type
sub get_boot_setting {
    my ($media, $setting, $opts) = @_;
    $opts->{boot} ? $MDV::Draklive::Storage::storage_types{$opts->{boot}}{$setting} : get_media_setting($media, $setting);
}

#- for user-customisable media setting, that can override storage setting
sub get_media_setting {
    my ($media, $setting) = @_;
    $media->{$setting} || $media->get_storage_setting($setting);
}

sub get_media_fs_module {
    my ($media) = @_;
    my $fs = $media->get_media_setting('fs');
    $fs eq 'iso9660' ? 'isofs' : $fs eq 'ext2' ? @{[]} : $fs;
}

sub get_media_label {
    my ($media) = @_;
    first($media->get_media_setting('source') =~ /^LABEL=(.*)$/);
}

sub get_media_source_for_nash {
    my ($media) = @_;
    my $label = $media->get_media_label;
    #- strip vfat labels to 11 chars and upper-case it
    $label && $media->get_media_setting('fs') eq 'vfat' ?
      'LABEL=' . uc(substr($label, 0, 11)) :
      $media->get_media_setting('source');
}

sub find_partition_index {
    my ($media, $mntpoint) = @_;
    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');

    my $correction = 1.2;
    $slash->{size} ||= int($total_size * $correction) / $common::SECTORSIZE;
}

1;