summaryrefslogtreecommitdiffstats
path: root/perl-install/diskdrake/interactive.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/diskdrake/interactive.pm')
-rw-r--r--perl-install/diskdrake/interactive.pm371
1 files changed, 243 insertions, 128 deletions
diff --git a/perl-install/diskdrake/interactive.pm b/perl-install/diskdrake/interactive.pm
index 5c184c9f4..e5e2090a7 100644
--- a/perl-install/diskdrake/interactive.pm
+++ b/perl-install/diskdrake/interactive.pm
@@ -1,4 +1,4 @@
-package diskdrake::interactive; # $Id: interactive.pm 246710 2008-09-26 09:24:08Z pixel $
+package diskdrake::interactive; # $Id: interactive.pm 269771 2010-06-03 11:50:24Z pterjan $
use diagnostics;
use strict;
@@ -41,6 +41,7 @@ struct part {
bool prefer_device_UUID # should the {device_UUID} or the {device} be used in fstab
bool prefer_device # should the {device} be used in fstab
bool faked_device # false if {device} is a real device, true for nfs/smb/dav/none devices. If the field does not exist, we do not know
+ bool device_LABEL_changed # true if device_LABEL is different from the one on the disk
string rootDevice # 'sda', 'hdc' ... (can also be a VG_name)
string real_mntpoint # directly on real /, '/tmp/hdimage' ...
@@ -49,13 +50,13 @@ struct part {
string device_windobe # 'C', 'D' ...
string encrypt_key # [0-9A-Za-z./]{20,}
string comment # comment to have in fstab
- string volume_label #
+ string volume_label #
bool is_removable # is the partition on a removable drive
bool isMounted
bool isFormatted
- bool notFormatted
+ bool notFormatted
# isFormatted means the device is formatted
# !isFormatted && notFormatted means the device is not formatted
# !isFormatted && !notFormatted means we do not know which state we're in
@@ -72,13 +73,13 @@ struct part {
string real_device # '/dev/loop0', '/dev/loop1' ... (used for encrypted loopback)
# internal CHS (Cylinder/Head/Sector)
- int start_cyl, start_head, start_sec, end_cyl, end_head, end_sec,
+ int start_cyl, start_head, start_sec, end_cyl, end_head, end_sec,
}
struct part_allocate inherits part {
int maxsize # in sectors (alike "size")
int min_hd_size # in sectors (do not allocate if the drive is smaller than the given size)
- int ratio #
+ int ratio #
string hd # 'hda', 'hdc'
string parts # for creating raid partitions. eg: 'foo bar' where 'foo' and 'bar' are mntpoint
}
@@ -121,7 +122,7 @@ struct partition_table_elem {
}
struct geom {
- int heads
+ int heads
int sectors
int cylinders
int totalcylinders # for SUN, forget it
@@ -138,7 +139,7 @@ struct hd {
bool readonly # is it allowed to modify the partition table
bool getting_rid_of_readonly_allowed # is it forbidden to write because the partition table is badly handled, or is it because we MUST not change the partition table
- bool isDirty # does it need to be written to the disk
+ bool isDirty # does it need to be written to the disk
list will_tell_kernel # list of actions to tell to the kernel so that it knows the new partition table
bool rebootNeeded # happens when a kernel reread failed
list partitionsRenumbered # happens when you
@@ -146,7 +147,9 @@ struct hd {
# - add an extended partition which is the first extended partition
list allPartitionsRenumbered # used to update bootloader configuration
int bus, id
-
+
+ bool is_removable # is it a removable drive
+
partition_table_elem primary
partition_table_elem extended[]
@@ -203,12 +206,12 @@ sub main {
}
my ($current_part, $current_hd);
-
+
while (1) {
my $choose_txt = $current_part ? N_("Choose another partition") : N_("Choose a partition");
my $parts_and_holes = [ fs::get::fstab_and_holes($all_hds) ];
my $choose_part = sub {
- $current_part = $in->ask_from_listf('diskdrake', translate($choose_txt),
+ $current_part = $in->ask_from_listf('diskdrake', translate($choose_txt),
sub {
my $hd = fs::get::part2hd($_[0] || return, $all_hds);
format_part_info_short($hd, $_[0]);
@@ -220,33 +223,33 @@ sub main {
return if !$current_part;
my %actions = my @actions = (
- if_($current_part,
+ if_($current_part,
(map { my $s = $_; $_ => sub { $diskdrake::interactive::{$s}($in, $current_hd, $current_part, $all_hds) } } part_possible_actions($in, $current_hd, $current_part, $all_hds)),
'____________________________' => sub {},
),
if_(@$parts_and_holes > 1, $choose_txt => $choose_part),
if_($current_hd,
(map { my $s = $_; $_ => sub { $diskdrake::interactive::{$s}($in, $current_hd, $all_hds) } } hd_possible_actions_interactive($in, $current_hd, $all_hds)),
- ),
+ ),
(map { my $s = $_; $_ => sub { $diskdrake::interactive::{$s}($in, $all_hds) } } general_possible_actions($in, $all_hds)),
);
my ($actions) = list2kv(@actions);
my $a;
if ($current_part) {
$in->ask_from_({
- cancel => N("Exit"),
+ cancel => N("Exit"),
title => 'diskdrake',
messages => format_part_info($current_hd, $current_part),
},
[ { val => \$a, list => $actions, format => \&translate, type => 'list', sort => 0, gtk => { use_boxradio => 0 } } ]) or last;
my $v = eval { $actions{$a}() };
if (my $err = $@) {
- $in->ask_warn(N("Error"), formatError($err));
+ $in->ask_warn(N("Error"), formatError($err));
}
if ($v eq 'force_reload') {
$all_hds = $do_force_reload->();
}
- $current_hd = $current_part = '' if !is_part_existing($current_part, $all_hds);
+ $current_hd = $current_part = '' if !is_part_existing($current_part, $all_hds);
} else {
$choose_part->();
}
@@ -283,6 +286,9 @@ sub Done {
$in->ask_yesorno(N("Quit without saving"), N("Quit without writing the partition table?"), 1) or return;
}
}
+ foreach (@{$all_hds->{raids}}) {
+ raid::make($all_hds->{raids}, $_);
+ }
if (!$::isInstall) {
my $new = fs::fstab_to_string($all_hds);
if ($new ne $all_hds->{current_fstab} && $in->ask_yesorno(N("Confirmation"), N("Do you want to save /etc/fstab modifications"), 1)) {
@@ -309,8 +315,8 @@ Quit anyway?", $part->{device}, $part->{mntpoint})) or return if $::isStandalone
################################################################################
sub hd_possible_actions_base {
my ($hd) = @_;
- (
- if_(!$hd->{readonly} || $hd->{getting_rid_of_readonly_allowed}, N_("Clear all")),
+ (
+ if_(!$hd->{readonly} || $hd->{getting_rid_of_readonly_allowed}, N_("Clear all")),
if_(!$hd->{readonly} && $::isInstall, N_("Auto allocate")),
);
}
@@ -361,9 +367,9 @@ sub Auto_allocate {
if ($@) {
$@ =~ /partition table already full/ or die;
- $in->ask_warn("", [
+ $in->ask_warn("", [
N("All primary partitions are used"),
- N("I can not add any more partitions"),
+ N("I can not add any more partitions"),
N("To have more partitions, please delete one to be able to create an extended partition"),
]);
}
@@ -394,12 +400,13 @@ sub part_possible_actions {
$part or return;
my %actions = my @l = (
+ N_("View") => '!isSwap && !isNonMountable && maybeFormatted',
N_("Mount point") => '$part->{real_mntpoint} || (!isBusy && !isSwap && !isNonMountable)',
N_("Type") => '!isBusy && $::expert && (!readonly || $part->{pt_type} == 0x83)',
N_("Options") => '!isSwap($part) && !isNonMountable && $::expert',
- N_("Label") => '!isNonMountable && $::expert',
+ N_("Label") => '!isNonMountable && $::expert && fs::format::canEditLabel($part)',
N_("Resize") => '!isBusy && !readonly && !isSpecial || isLVM($hd) && LVM_resizable',
- N_("Format") => '!isBusy && (!readonly && ($::expert || $::isStandalone) || fs::type::isRawLUKS($part))',
+ N_("Format") => '!isBusy && !isRawLVM && !isPartOfLVM && (!readonly && ($::expert || $::isStandalone) || fs::type::isRawLUKS($part))',
N_("Mount") => '!isBusy && (hasMntpoint || isSwap) && maybeFormatted && ($::expert || $::isStandalone)',
N_("Add to RAID") => '!isBusy && isRawRAID && (!isSpecial || isRAID)',
N_("Add to LVM") => '!isBusy && isRawLVM',
@@ -417,16 +424,16 @@ sub part_possible_actions {
my %macros = (
readonly => '$hd->{readonly}',
hasMntpoint => '$part->{mntpoint}',
- LVM_resizable => '$part->{fs_type} eq "reiserfs" || (isMounted ? $part->{fs_type} eq "xfs" : member($part->{fs_type}, qw(ext3 ext4dev)))',
+ LVM_resizable => 'member($part->{fs_type}, qw(reiserfs xfs ext3 ext4 btrfs))',
canModifyRAID => 'isPartOfRAID($part) && !isMounted(fs::get::device2part($part->{raid}, $all_hds->{raids}))',
);
if (isEmpty($part)) {
if_(!$hd->{readonly}, N_("Create"));
} elsif ($part->{pt_type} == 0xbf && detect_devices::is_xbox()) {
#- XBox OS partitions, do not allow anything
- return;
+ return;
} else {
- grep {
+ grep {
my $cond = $actions{$_};
while (my ($k, $v) = each %macros) {
$cond =~ s/$k/qq(($v))/e;
@@ -437,10 +444,20 @@ sub part_possible_actions {
}
}
-#- in case someone use diskdrake only to create partitions,
+sub View {
+ my ($in, $hd, $part, $all_hds) = @_;
+ my $handle = any::inspect($part, $::prefix);
+ if ($handle) {
+ $in->ask_directory({'directory'=>$handle->{dir}});
+ } else {
+ $in->ask_warn(N("Error"), N("Failed to mount partition"));
+ }
+}
+
+#- in case someone use diskdrake only to create partitions,
#- ie without assigning a mount point,
#- do not suggest mount points anymore
-my $do_suggest_mount_point = 1;
+my $do_suggest_mount_point = $::isInstall;
sub Create {
my ($in, $hd, $part, $all_hds) = @_;
@@ -451,7 +468,7 @@ sub Create {
$part->{mntpoint} = '' if !$do_suggest_mount_point;
} else {
$part->{size} = $part->{maxsize};
- fs::type::suggest_fs_type($part, 'ext3');
+ fs::type::suggest_fs_type($part, defaultFS());
}
if (isLVM($hd)) {
lvm::suggest_lv_name($hd, $part);
@@ -464,18 +481,20 @@ sub Create {
my $type_name = fs::type::part2type_name($part);
my $mb_size = to_Mb($part->{size});
my $has_startsector = ($::expert || arch() !~ /i.86/) && !isLVM($hd);
+ my $use_dmcrypt;
+ my $requested_type;
$in->ask_from(N("Create a new partition"), '',
[
{ label => N("Create a new partition"), title => 1 },
if_($has_startsector,
- { label => N("Start sector: "), val => \$part->{start}, min => $def_start, max => ($max - min_partition_size($hd)),
+ { label => N("Start sector: "), val => \$part->{start}, min => $def_start, max => ($max - min_partition_size($hd)),
type => 'range', SpinButton => $::expert, changed => sub { $mb_size = min($mb_size, to_Mb($max - $part->{start})) } },
),
- { label => N("Size in MB: "), val => \$mb_size, min => to_Mb(min_partition_size($hd)), max => to_Mb($def_size),
+ { label => N("Size in MB: "), val => \$mb_size, min => to_Mb(min_partition_size($hd)), max => to_Mb($def_size),
type => 'range', SpinButton => $::expert, changed => sub { $part->{start} = min($part->{start}, $max - $mb_size * 2048) } },
- { label => N("Filesystem type: "), val => \$type_name, list => [ fs::type::type_names($::expert, $hd) ],
- sort => 0, if_($::expert, gtk => { wrap_width => 4 }, do_not_ellipsize => 1) },
+ { label => N("Filesystem type: "), val => \$type_name, list => [ fs::type::type_names($::expert, $hd) ],
+ sort => 0, if_($::expert, gtk => { wrap_width => 2 }, do_not_ellipsize => 1) },
{ label => N("Mount point: "), val => \$part->{mntpoint}, list => [ fsedit::suggestions_mntpoint($all_hds), '' ],
disabled => sub { my $p = fs::type::type_name2subpart($type_name); isSwap($p) || isNonMountable($p) }, type => 'combo', not_edit => 0,
},
@@ -485,19 +504,36 @@ sub Create {
if_($::expert && isLVM($hd),
{ label => N("Logical volume name "), val => \$part->{lv_name}, list => [ qw(root swap usr home var), '' ], sort => 0, not_edit => 0 },
),
+ { label => N("Encrypt partition"), type => 'bool', val => \$use_dmcrypt },
+ { label => N("Encryption key "), val => \$part->{dmcrypt_key}, disabled => sub { !$use_dmcrypt }, hidden => 1, weakness_check => 1 },
+ { label => N("Encryption key (again)"), val => \$part->{dmcrypt_key2}, disabled => sub { !$use_dmcrypt }, hidden => 1 },
], complete => sub {
$part->{size} = from_Mb($mb_size, min_partition_size($hd), $max - $part->{start}); #- need this to be able to get back the approximation of using MB
- put_in_hash($part, fs::type::type_name2subpart($type_name));
$do_suggest_mount_point = 0 if !$part->{mntpoint};
+ put_in_hash($part, fs::type::type_name2subpart($type_name));
$part->{mntpoint} = '' if isNonMountable($part);
$part->{mntpoint} = 'swap' if isSwap($part);
fs::mount_options::set_default($part, ignore_is_removable => 1);
+ # if user asked to encrypt the partition, use dm-crypt and create requested fs inside
+ if ($use_dmcrypt) {
+ my $err;
+ $err = N("The encryption keys do not match") unless ($part->{dmcrypt_key} eq $part->{dmcrypt_key2});
+ $err = N("Missing encryption key") unless ($part->{dmcrypt_key});
+ if ($err) {
+ $in->ask_warn(N("Error"), $err);
+ return 1;
+ }
+ $requested_type = $type_name;
+ $type_name = 'Encrypted';
+ }
+
+ put_in_hash($part, fs::type::type_name2subpart($type_name));
check($in, $hd, $part, $all_hds) or return 1;
$migrate_files = need_migration($in, $part->{mntpoint}) or return 1;
-
+
my $seen;
- eval {
+ eval {
catch_cdie { fsedit::add($hd, $part, $all_hds, { force => 1, primaryOrExtended => $primaryOrExtended }) }
sub { $seen = 1; $in->ask_okcancel('', formatError($@)) };
};
@@ -516,9 +552,32 @@ First remove a primary partition and create an extended partition."));
},
) or return;
+ if ($use_dmcrypt) {
+ write_partitions($in, $hd) or return;
+ # Initialize it and format it
+ dmcrypt_format($in, $hd, $part, $all_hds);
+ my $p = find { $part->{dm_name} eq $_->{dmcrypt_name} } @{$all_hds->{dmcrypts}};
+ my $p2 = fs::type::type_name2subpart($requested_type);
+ $p->{fs_type} = $p2->{fs_type};
+ $p->{type_name} = $requested_type;
+ $p->{mntpoint} = $part->{mntpoint};
+ $part->{mntpoint} = '';
+ if ($::isStandalone) {
+ fs::format::check_package_is_installed_format($in->do_pkgs, $p->{fs_type}) or log::l("Missing package");
+ }
+ if ($::expert && !member($p->{fs_type}, 'reiserfs', 'reiser4', 'xfs', 'hfs', 'ntfs', 'ntfs-3g')) {
+ $p->{toFormatCheck} = $in->ask_yesorno(N("Confirmation"), N("Check bad blocks?"));
+ }
+ $p->{isFormatted} = 0; #- force format;
+ # Wait for the newly created device to appear before formatting it
+ my ($_w, $wait_message) = $in->wait_message_with_progress_bar;
+ fs::format::part($all_hds, $p, $wait_message) unless isRawLVM($p);
+ }
+
warn_if_renumbered($in, $hd);
if ($migrate_files eq 'migrate') {
+ # FIXME check encrypt case
format_($in, $hd, $part, $all_hds) or return;
migrate_files($in, $hd, $part);
fs::mount::part($part);
@@ -527,6 +586,11 @@ First remove a primary partition and create an extended partition."));
sub Delete {
my ($in, $hd, $part, $all_hds) = @_;
+ if (fs::type::isLUKS($part)) {
+ my $p = find { $_->{dm_name} eq $part->{dmcrypt_name} } partition_table::get_normal_parts($hd);
+ RemoveFromDm($in, $hd, $p, $all_hds);
+ $part = $p;
+ }
if (isRAID($part)) {
raid::delete($all_hds->{raids}, $part);
} elsif (isLVM($hd)) {
@@ -553,41 +617,50 @@ sub Type {
my ($in, $hd, $part) = @_;
my $warned;
- my $warn = sub {
- $warned = 1;
- ask_alldatawillbelost($in, $part, N_("After changing type of partition %s, all data on this partition will be lost"));
+ my $warn = sub {
+ $warned = 1;
+ if (maybeFormatted($part)) {
+ ask_alldatawillbelost($in, $part, N_("After changing type of partition %s, all data on this partition will be lost"));
+ } else {
+ 1;
+ }
};
- #- for ext2, warn after choosing as ext2->ext3 can be achieved without loosing any data :)
- $part->{fs_type} eq 'ext2' || $part->{fs_type} =~ /ntfs/ or $warn->() or return;
+ #- for ext2/ext3, warn after choosing as ext2->ext3 and ext*->ext4 can be achieved without loosing any data :)
+ member($part->{fs_type}, qw(ext2 ext3)) || $part->{fs_type} =~ /ntfs/ or $warn->() or return;
my @types = fs::type::type_names($::expert, $hd);
#- when readonly, Type() is allowed only when changing {fs_type} but not {pt_type}
- #- eg: switching between ext2, ext3, ext4dev, reiserfs...
+ #- eg: switching between ext2, ext3, ext4, reiserfs...
@types = grep { fs::type::type_name2pt_type($_) == $part->{pt_type} } @types if $hd->{readonly};
my $type_name = fs::type::part2type_name($part);
$in->ask_from_({ title => N("Change partition type") },
[
{ label => N("Which filesystem do you want?"), title => 1 },
- { label => N("Type"), val => \$type_name, list => \@types, sort => 0, do_not_ellipsize => 1,
- focus => sub { 1 }, not_edit => 1, gtk => { wrap_width => 4 } } ]) or return;
+ { label => N("Type"), val => \$type_name, type => 'list', list => \@types, sort => 1, do_not_ellipsize => 1,
+ focus => sub { 1 }, not_edit => 1, gtk => { wrap_width => 2 } } ]) or return;
my $type = $type_name && fs::type::type_name2subpart($type_name);
- if (member($type->{fs_type}, qw(ext2 ext3 ext4dev))) {
+ if ($part->{fs_type} eq 'ext2' && $type->{fs_type} eq 'ext3') {
my $_w = $in->wait_message(N("Please wait"), N("Switching from %s to %s", 'ext2', $type->{fs_type}));
if (run_program::run("tune2fs", "-j", devices::make($part->{device}))) {
put_in_hash($part, $type);
set_isFormatted($part, 1); #- assume that if tune2fs works, partition is formatted
#- disable the fsck (do not do it together with -j in case -j fails?)
- fs::format::disable_forced_fsck($part->{device});
+ fs::format::disable_forced_fsck($part->{device});
return;
}
+ } elsif (member($part->{fs_type}, qw(ext2 ext3)) && $type->{fs_type} eq 'ext4') {
+ # FIXME enable some nice flags
+ put_in_hash($part, $type);
+ return;
} elsif ($type->{fs_type} =~ /ntfs/ && $part->{fs_type} =~ /ntfs/) {
if ($type->{fs_type} eq 'ntfs-3g') {
+ local $::prefix = ''; # For draklive-install
$in->do_pkgs->ensure_binary_is_installed('ntfs-3g', 'mount.ntfs-3g') or return;
}
put_in_hash($part, $type);
@@ -603,12 +676,25 @@ sub Type {
sub Label {
my ($in, $_hd, $part) = @_;
- $in->ask_from(N("Which volume label?"), '',
+ my $new_label = $part->{device_LABEL} || "";
- [
+ write_partitions($in, $_hd) or return;
+
+ $in->ask_from(N("Set volume label"),
+ maybeFormatted($part) ?
+ N("Beware, this will be written to disk as soon as you validate!")
+ : N("Beware, this will be written to disk only after formatting!"),
+ [
{ label => N("Which volume label?"), title => 1 },
- { label => N("Label:"), val => \$part->{device_LABEL} } ]) or return;
- $part->{prefer_device_LABEL} = to_bool($part->{device_LABEL});
+ { label => N("Label:"), val => \$new_label } ]) or return;
+
+ fs::format::check_package_is_installed_label($in->do_pkgs, $part->{fs_type}) or return;
+ $part->{prefer_device_LABEL} = to_bool($part->{device_LABEL}) && !isLVM($part);
+ return if $new_label eq $part->{device_LABEL};
+ $part->{device_LABEL} = $new_label;
+ $part->{device_LABEL_changed} = 1;
+ fs::format::clean_label($part);
+ fs::format::write_label($part);
}
sub Mount_point {
@@ -626,7 +712,7 @@ sub Mount_point {
$in->ask_from_({
callbacks => {
complete => sub {
- !isPartOfLoopback($part) || $mntpoint or $in->ask_warn(N("Error"),
+ !isPartOfLoopback($part) || $mntpoint or $in->ask_warn(N("Error"),
N("Can not unset mount point as this partition is used for loop back.
Remove the loopback first")), return 1;
$part->{mntpoint} eq $mntpoint || check_mntpoint($in, $mntpoint, $part, $all_hds) or return 1;
@@ -636,8 +722,8 @@ Remove the loopback first")), return 1;
},
[
{ label => $msg, title => 1 },
- { label => N("Mount point"), val => \$mntpoint,
- list => [ uniq(if_($mntpoint, $mntpoint), fsedit::suggestions_mntpoint($all_hds), '') ],
+ { label => N("Mount point"), val => \$mntpoint,
+ list => [ uniq(if_($mntpoint, $mntpoint), fsedit::suggestions_mntpoint($all_hds), '') ],
focus => sub { 1 },
not_edit => 0 } ],
) or return;
@@ -658,8 +744,8 @@ sub Mount_point_raw_hd {
'',
[
{ label => N("Where do you want to mount %s?", $part->{device}), title => 1 },
- { label => N("Mount point"), val => \$mntpoint,
- list => [ if_($mntpoint, $mntpoint), '', @propositions ],
+ { label => N("Mount point"), val => \$mntpoint,
+ list => [ if_($mntpoint, $mntpoint), '', @propositions ],
not_edit => 0 } ],
complete => sub {
$part->{mntpoint} eq $mntpoint || check_mntpoint($in, $mntpoint, $part, $all_hds) or return 1;
@@ -672,7 +758,13 @@ sub Mount_point_raw_hd {
sub Resize {
my ($in, $hd, $part) = @_;
my (%nice_resize);
- my ($min, $max) = (min_partition_size($hd), max_partition_resize($hd, $part));
+ my $low_part = $part;
+
+ if (isLUKS($part)) {
+ $low_part = find { $_->{dm_name} eq $part->{dmcrypt_name} } partition_table::get_normal_parts($hd);
+ }
+
+ my ($min, $max) = (min_partition_size($hd), max_partition_resize($hd, $low_part));
if (maybeFormatted($part)) {
# here we may have a non-formatted or a formatted partition
@@ -686,8 +778,8 @@ sub Resize {
require resize_fat::main;
$nice_resize{fat} = resize_fat::main->new($part->{device}, devices::make($part->{device}));
$min = max($min, $nice_resize{fat}->min_size);
- $max = min($max, $nice_resize{fat}->max_size);
- } elsif (member($part->{fs_type}, qw(ext2 ext3 ext4dev))) {
+ $max = min($max, $nice_resize{fat}->max_size);
+ } elsif (member($part->{fs_type}, qw(ext2 ext3 ext4))) {
write_partitions($in, $hd) or return;
require diskdrake::resize_ext2;
if ($nice_resize{ext2} = diskdrake::resize_ext2->new($part->{device}, devices::make($part->{device}))) {
@@ -704,15 +796,21 @@ sub Resize {
} elsif ($part->{fs_type} eq 'reiserfs') {
write_partitions($in, $hd) or return;
if ($part->{isMounted}) {
- $nice_resize{reiserfs} = 1;
+ $nice_resize{reiserfs} = 1;
$min = $part->{size}; #- ensure the user can only increase
} elsif (defined(my $free = fs::df($part))) {
- $nice_resize{reiserfs} = 1;
+ $nice_resize{reiserfs} = 1;
$min = max($min, $part->{size} - $free);
}
} elsif ($part->{fs_type} eq 'xfs' && isLVM($hd) && $::isStandalone && $part->{isMounted}) {
$min = $part->{size}; #- ensure the user can only increase
$nice_resize{xfs} = 1;
+ } elsif ($part->{fs_type} eq 'btrfs') {
+ write_partitions($in, $hd) or return;
+ if (defined(my $free = fs::df($part))) {
+ $nice_resize{btrfs} = 1;
+ $min = max($min, $part->{size} - $free);
+ }
}
#- make sure that even after normalizing the size to cylinder boundaries, the minimun will be saved,
#- this save at least a cylinder (less than 8Mb).
@@ -730,7 +828,7 @@ sub Resize {
my $mb_size = to_Mb($part->{size});
my ($gmin, $gmax) = (to_Mb($min), to_Mb($max));
- $in->ask_from(N("Resize"), '', [
+ $in->ask_from(N("Resize"), '', [
{ label => N("Choose the new size"), title => 1 },
{ label => N("New size in MB: "), val => \$mb_size, min => $gmin, max => $gmax, type => 'range', SpinButton => $::expert },
{ label => N("Minimum size: %s MB", $gmin) },
@@ -742,8 +840,8 @@ sub Resize {
$part->{size} == $size and return;
my $oldsize = $part->{size};
- $part->{size} = $size;
- $hd->adjustEnd($part);
+ $low_part->{size} = $part->{size} = $size;
+ $hd->adjustEnd($low_part);
undef $@;
my $_b = before_leaving { $@ and $part->{size} = $oldsize };
@@ -752,12 +850,18 @@ sub Resize {
my ($write_partitions) = @_;
if (isLVM($hd)) {
- lvm::lv_resize($part, $oldsize);
+ lvm::lv_resize($low_part, $oldsize);
} else {
- partition_table::will_tell_kernel($hd, resize => $part);
- partition_table::adjust_local_extended($hd, $part);
+ if ($write_partitions && isLUKS($part)) {
+ run_program::run('cryptsetup', 'luksClose', $part->{dmcrypt_name}) or die ("Failed to resize partition, maybe it is mounted");
+ }
+ partition_table::will_tell_kernel($hd, resize => $low_part);
+ partition_table::adjust_local_extended($hd, $low_part);
partition_table::adjust_main_extended($hd);
write_partitions($in, $hd) or return if $write_partitions && %nice_resize;
+ if ($write_partitions && isLUKS($part)) {
+ fs::dmcrypt::open_part([], $low_part);
+ }
}
1;
};
@@ -775,7 +879,7 @@ sub Resize {
log::l("ntfs resize to $part->{size} sectors");
$nice_resize{ntfs}->resize($part->{size});
$wait = undef;
- $in->ask_warn(N("Warning"), N("To ensure data integrity after resizing the partition(s),
+ $in->ask_warn(N("Warning"), N("To ensure data integrity after resizing the partition(s),
filesystem checks will be run on your next boot into Microsoft Windows®"));
} elsif ($nice_resize{reiserfs}) {
log::l("reiser resize to $part->{size} sectors");
@@ -783,6 +887,21 @@ filesystem checks will be run on your next boot into Microsoft Windows®"));
} elsif ($nice_resize{xfs}) {
#- happens only with mounted LVM, see above
run_program::run_or_die("xfs_growfs", $part->{mntpoint});
+ } elsif ($nice_resize{btrfs}) {
+ my $dir = "/tmp/tmp_resize_btrfs.$$";
+ if ($part->{isMounted}) {
+ $dir = ($::prefix || '') . $part->{mntpoint};
+ } else {
+ mkdir_p($dir);
+ fs::mount::mount(devices::make($part->{device}), $dir, $part->{fs_type});
+ }
+ if (!run_program::run("btrfsctl", "-r", $part->{size}*512, $dir)) {
+ $nice_resize{btrfs} = undef;
+ if (!$part->{isMounted}) {
+ fs::mount::umount($dir);
+ unlink($dir);
+ }
+ }
}
if (%nice_resize) {
@@ -795,6 +914,7 @@ filesystem checks will be run on your next boot into Microsoft Windows®"));
$adjust->(0) if $size < $oldsize;
}
+
sub Format {
my ($in, $hd, $part, $all_hds) = @_;
format_($in, $hd, $part, $all_hds);
@@ -823,9 +943,9 @@ sub dmcrypt_open {
if (!$part->{dmcrypt_key}) {
$in->ask_from_({
- title => N("Filesystem encryption key"),
+ title => N("Filesystem encryption key"),
messages => N("Enter your filesystem encryption key"),
- }, [ { label => N("Encryption key"), val => \$part->{dmcrypt_key},
+ }, [ { label => N("Encryption key"), val => \$part->{dmcrypt_key},
hidden => 1, focus => sub { 1 } } ]) or return;
}
@@ -856,6 +976,7 @@ sub Add2RAID {
sub Add2LVM {
my ($in, $hd, $part, $all_hds) = @_;
my $lvms = $all_hds->{lvms};
+ my @lvm_names = map { $_->{VG_name} } @$lvms;
write_partitions($in, $_) or return foreach isRAID($part) ? @{$all_hds->{hds}} : $hd;
my $lvm = $in->ask_from_listf_(N("Add to LVM"), N("Choose an existing LVM to add to"),
@@ -864,8 +985,23 @@ sub Add2LVM {
require lvm;
if (!ref $lvm) {
# create new lvm
- # FIXME: when mdv2006 is out: remove the question mark from the dialog title
- my $name = $in->ask_from_entry(N("LVM name?"), N("LVM name?")) or return;
+ my $n = 0;
+ while (member("vg$n", @lvm_names)) {
+ $n++;
+ }
+
+ my $name = "vg$n";
+ $in->ask_from_({ title => N("LVM name"),
+ messages => N("Enter a name for the new LVM volume group"),
+ focus_first => 1,
+ ok_disabled => sub { !$name },
+ validate => sub {
+ member($name, @lvm_names) or return 1;
+ $in->ask_warn(N("Error"), N("\"%s\" already exists", $name));
+ return 0;
+ } },
+ [{label=>N("LVM name"),val=> \$name}]) or return;
+
$lvm = new lvm($name);
push @$lvms, $lvm;
}
@@ -877,11 +1013,11 @@ sub Unmount {
my ($_in, $_hd, $part) = @_;
fs::mount::umount_part($part);
}
-sub RemoveFromRAID {
+sub RemoveFromRAID {
my ($_in, $_hd, $part, $all_hds) = @_;
raid::removeDisk($all_hds->{raids}, $part);
}
-sub RemoveFromDm {
+sub RemoveFromDm {
my ($_in, $_hd, $part, $all_hds) = @_;
fs::dmcrypt::close_part($all_hds->{dmcrypts}, $part);
}
@@ -903,7 +1039,7 @@ Do you want to move used physical extents on this volume to other volumes?", $pa
$all_hds->{lvms} = $other_lvms;
}
}
-sub ModifyRAID {
+sub ModifyRAID {
my ($in, $_hd, $part, $all_hds) = @_;
modifyRAID($in, $all_hds->{raids}, fs::get::device2part($part->{raid}, $all_hds->{raids}));
}
@@ -919,7 +1055,7 @@ sub Loopback {
my $part = { maxsize => $max, size => 0, loopback_device => $real_part, notFormatted => 1 };
if (!fsedit::suggest_part($part, $all_hds)) {
$part->{size} = $part->{maxsize};
- fs::type::suggest_fs_type($part, 'ext3');
+ fs::type::suggest_fs_type($part, defaultFS());
}
delete $part->{mntpoint}; # we do not want the suggested mntpoint
@@ -965,13 +1101,13 @@ sub Options {
relatime => sub { $options->{noatime} = 0 },
noatime => sub { $options->{relatime} = 0 },
);
-
+
$in->ask_from(N("Mount options"),
'',
- [
+ [
{ label => N("Mount options"), title => 1 },
- (map {
+ (map {
{ label => $_, text => scalar warp_text(formatAlaTeX($help{$_}), 60), val => \$options->{$_}, hidden => scalar(/password/),
advanced => !$part->{rootDevice} && !member($_, @simple_options), if_(!/=$/, type => 'bool'),
if_($callbacks{$_}, changed => $callbacks{$_}),
@@ -983,27 +1119,6 @@ sub Options {
if (($options->{usrquota} || $options->{grpquota}) && !$::isInstall) {
$in->do_pkgs->ensure_binary_is_installed('quota', 'quotacheck');
}
- if ($options->{encrypted}) {
- # modify $part->{options} for the check
- local $part->{options};
- fs::mount_options::pack($part, $options, $unknown);
- if (!check($in, $hd, $part, $all_hds)) {
- $options->{encrypted} = 0;
- } elsif (!$part->{encrypt_key} && !isSwap($part)) {
- if (my ($encrypt_key, $encrypt_algo) = choose_encrypt_key($in, $options, '')) {
- $options->{'encryption='} = $encrypt_algo;
- $part->{encrypt_key} = $encrypt_key;
- } else {
- $options->{encrypted} = 0;
- }
- }
- #- don't be sure of anything
- set_isFormatted($part, 0);
- $part->{notFormatted} = 0;
- } else {
- delete $options->{'encryption='};
- delete $part->{encrypt_key};
- }
}) or return;
fs::mount_options::pack($part, $options, $unknown);
@@ -1011,8 +1126,8 @@ sub Options {
}
-{
- no strict;
+{
+ no strict;
*{'Toggle to normal mode'} = sub() { $::expert = 0 };
*{'Toggle to expert mode'} = sub() { $::expert = 1 };
*{'Clear all'} = \&Clear_all;
@@ -1020,11 +1135,11 @@ sub Options {
*{'Mount point'} = \&Mount_point;
*{'Modify RAID'} = \&ModifyRAID;
*{'Add to RAID'} = \&Add2RAID;
- *{'Remove from RAID'} = \&RemoveFromRAID;
+ *{'Remove from RAID'} = \&RemoveFromRAID;
*{'Use'} = \&dmcrypt_open;
- *{'Remove from dm'} = \&RemoveFromDm;
+ *{'Remove from dm'} = \&RemoveFromDm;
*{'Add to LVM'} = \&Add2LVM;
- *{'Remove from LVM'} = \&RemoveFromLVM;
+ *{'Remove from LVM'} = \&RemoveFromLVM;
*{'Use for loopback'} = \&Loopback;
*{'Hard drive information'} = \&Hd_info;
}
@@ -1045,7 +1160,7 @@ sub modifyRAID {
$in->ask_from(N("Options"), '',
[
{ label => N("device"), val => \$new_device, list => [ $md_part->{device}, raid::free_mds($raids) ], sort => 0 },
-{ label => N("level"), val => \$md_part->{level}, list => [ qw(0 1 4 5 6 linear) ] },
+{ label => N("level"), val => \$md_part->{level}, list => [ qw(0 1 4 5 6 10 linear) ] },
{ label => N("chunk size in KiB"), val => \$md_part->{'chunk-size'} },
],
) or return;
@@ -1063,7 +1178,7 @@ sub ask_alldatamaybelost {
#- here we may have a non-formatted or a formatted partition
#- -> doing as if it was formatted
- $in->ask_okcancel(N("Read carefully"),
+ $in->ask_okcancel(N("Read carefully"),
[ N("Be careful: this operation is dangerous."), sprintf(translate($msg), $part->{device}) ], 1);
}
sub ask_alldatawillbelost {
@@ -1078,7 +1193,7 @@ sub ask_alldatawillbelost {
sub partitions_suggestions {
my ($in) = @_;
- my $t = $::expert ?
+ my $t = $::expert ?
$in->ask_from_list_(N("Partitioning Type"), N("What type of partitioning?"), [ keys %fsedit::suggestions ]) :
'simple';
$fsedit::suggestions{$t};
@@ -1092,14 +1207,14 @@ sub check_type {
return;
}
if ($::isStandalone && $type->{fs_type} && fs::format::known_type($type)) {
- fs::format::check_package_is_installed($in->do_pkgs, $type->{fs_type}) or return;
+ fs::format::check_package_is_installed_format($in->do_pkgs, $type->{fs_type}) or return;
}
1;
}
sub check_mntpoint {
my ($in, $mntpoint, $part, $all_hds) = @_;
my $seen;
- eval {
+ eval {
catch_cdie { fsedit::check_mntpoint($mntpoint, $part, $all_hds) }
sub { $seen = 1; $in->ask_okcancel(N("Error"), formatError($@)) };
};
@@ -1130,17 +1245,14 @@ sub write_partitions {
partition_table::write($hd) if !$::testing;
check_rebootNeeded($in, $hd) if !$b_skip_check_rebootNeeded;
# fix resizing's failures due to udev's race when writing the partition table
- run_program::run('udevadm', 'settle');
+ run_program::run('udevadm', 'settle') unless $::isInstall;
1;
}
sub ensure_we_have_encrypt_key_if_needed {
my ($in, $part) = @_;
- if ($part->{options} =~ /encrypted/ && !$part->{encrypt_key}) {
- my ($options, $_unknown) = fs::mount_options::unpack($part);
- $part->{encrypt_key} = choose_encrypt_key($in, $options, 'skip_encrypt_algo') or return;
- } elsif (fs::type::isRawLUKS($part)) {
+ if (fs::type::isRawLUKS($part)) {
$part->{dmcrypt_key} ||= choose_encrypt_key($in, {}, 'skip_encrypt_algo') or return;
}
1;
@@ -1167,9 +1279,9 @@ sub format_ {
return &dmcrypt_format;
}
if ($::isStandalone) {
- fs::format::check_package_is_installed($in->do_pkgs, $part->{fs_type}) or return;
+ fs::format::check_package_is_installed_format($in->do_pkgs, $part->{fs_type}) or return;
}
- if ($::expert && !member($part->{fs_type}, 'reiserfs', 'xfs')) {
+ if ($::expert && !member($part->{fs_type}, 'reiserfs', 'reiser4', 'xfs', 'hfs', 'ntfs', 'ntfs-3g')) {
$part->{toFormatCheck} = $in->ask_yesorno(N("Confirmation"), N("Check bad blocks?"));
}
$part->{isFormatted} = 0; #- force format;
@@ -1189,12 +1301,12 @@ sub need_migration {
(%s)
You can either choose to move the files into the partition that will be mounted there or leave them where they are (which results in hiding them by the contents of the mounted partition)",
- $mntpoint, formatList(5, @l)),
+ $mntpoint, formatList(5, @l)),
[ { val => \$choice, list => \@choices, type => 'list', format => sub { translate($_[0]) } } ]) or return;
$choice eq $choices[0] ? 'migrate' : 'hide';
} else {
'hide';
- }
+ }
}
sub migrate_files {
@@ -1204,11 +1316,11 @@ sub migrate_files {
my $handle = any::inspect($part, '', 'rw');
my @l = glob_("$part->{mntpoint}/*");
foreach (@l) {
- $wait->set(N("Copying %s", $_));
+ $wait->set(N("Copying %s", $_));
system("cp", "-a", $_, $handle->{dir}) == 0 or die "copying failed";
}
foreach (@l) {
- $wait->set(N("Removing %s", $_));
+ $wait->set(N("Removing %s", $_));
system("rm", "-rf", $_) == 0 or die "removing files failed";
}
}
@@ -1220,7 +1332,7 @@ sub warn_if_renumbered {
push @{$hd->{allPartitionsRenumbered}}, @$l;
- my @l = map {
+ my @l = map {
my ($old, $new) = @$_;
N("partition %s is now known as %s", $old, $new) } @$l;
$in->ask_warn(N("Warning"), join("\n", N("Partitions have been renumbered: "), @l));
@@ -1249,7 +1361,7 @@ sub format_part_info {
$info .= N("Mount point: ") . "$part->{mntpoint}\n" if $part->{mntpoint};
$info .= N("Device: ") . "$part->{device}\n" if $part->{device} && !isLoopback($part);
- $info .= N("Volume label: ") . "$part->{device_LABEL}\n" if $part->{device_LABEL} && $::expert;
+ $info .= N("Volume label: ") . "$part->{device_LABEL}\n" if $part->{device_LABEL};
$info .= N("UUID: ") . "$part->{device_UUID}\n" if $::expert && $part->{device_UUID};
$info .= N("DOS drive letter: %s (just a guess)\n", $part->{device_windobe}) if $part->{device_windobe};
if (arch() eq "ppc") {
@@ -1277,10 +1389,13 @@ sub format_part_info {
$info .= N("Not formatted\n") if !$part->{isFormatted} && $part->{notFormatted};
$info .= N("Mounted\n") if $part->{isMounted};
$info .= N("RAID %s\n", $part->{raid}) if isPartOfRAID($part);
- if (fs::type::isRawLUKS($part)) {
- $info .= N("Encrypted") . ($part->{dm_active} && $part->{dm_name} ? N(" (mapped on %s)", $part->{dm_name}) :
- $part->{dm_name} ? N(" (to map on %s)", $part->{dm_name}) :
- N(" (inactive)")) . "\n";
+ if (fs::type::isRawLUKS($part) || fs::type::isLUKS($part)) {
+ $info .= N("Encrypted")."\n";
+ if (fs::type::isRawLUKS($part)) {
+ $info .= ($part->{dm_active} && $part->{dm_name} ? N(" (mapped on %s)", $part->{dm_name}) :
+ $part->{dm_name} ? N(" (to map on %s)", $part->{dm_name}) :
+ N(" (inactive)")) . "\n";
+ }
}
if (isPartOfLVM($part)) {
$info .= sprintf "LVM %s\n", $part->{lvm};
@@ -1306,7 +1421,7 @@ sub format_part_info {
$info;
}
-sub format_part_info_short {
+sub format_part_info_short {
my ($hd, $part) = @_;
isEmpty($part) ? N("Free space on %s (%s)", $hd->{device}, formatXiB($part->{size}, 512))
: partition_table::description($part);
@@ -1367,9 +1482,9 @@ sub choose_encrypt_key {
$in->ask_from_(
{
- title => N("Filesystem encryption key"),
+ title => N("Filesystem encryption key"),
messages => N("Choose your filesystem encryption key"),
- callbacks => {
+ callbacks => {
complete => sub {
length $encrypt_key < 6 and $in->ask_warn(N("Warning"), N("This encryption key is too simple (must be at least %d characters long)", 6)), return 1,0;
$encrypt_key eq $encrypt_key2 or $in->ask_warn(N("Error"), [ N("The encryption keys do not match"), N("Please try again") ]), return 1,1;
@@ -1391,7 +1506,7 @@ sub tell_wm_and_reboot() {
if (!$wm) {
system('reboot');
- } else {
+ } else {
any::ask_window_manager_to_logout_then_do($wm, $pid, 'reboot');
}
}