summaryrefslogtreecommitdiffstats
path: root/perl-install/diskdrake
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/diskdrake')
-rw-r--r--perl-install/diskdrake/dav.pm73
-rw-r--r--perl-install/diskdrake/diskdrake.html139
-rw-r--r--perl-install/diskdrake/hd_gtk.pm416
-rw-r--r--perl-install/diskdrake/interactive.pm1466
-rw-r--r--perl-install/diskdrake/removable.pm29
-rw-r--r--perl-install/diskdrake/removable_gtk.pm31
-rw-r--r--perl-install/diskdrake/resize_ext2.pm37
-rw-r--r--perl-install/diskdrake/resize_ntfs.pm36
-rw-r--r--perl-install/diskdrake/smbnfs_gtk.pm193
9 files changed, 1427 insertions, 993 deletions
diff --git a/perl-install/diskdrake/dav.pm b/perl-install/diskdrake/dav.pm
index 09510696d..9036596b3 100644
--- a/perl-install/diskdrake/dav.pm
+++ b/perl-install/diskdrake/dav.pm
@@ -1,22 +1,20 @@
-package diskdrake::dav; # $Id$
+package diskdrake::dav;
use diagnostics;
use strict;
use diskdrake::interactive;
use common;
-use fsedit;
-use fs;
sub main {
my ($in, $all_hds) = @_;
my $davs = $all_hds->{davs};
- $in->do_pkgs->ensure_is_installed('davfs', '/sbin/mount.davfs') or return;
+ $in->do_pkgs->ensure_binary_is_installed('davfs2', 'mount.davfs2') or return;
my $quit;
do {
$in->ask_from_({ ok => '', messages => formatAlaTeX(
-_("WebDAV is a protocol that allows you to mount a web server's directory
+N("WebDAV is a protocol that allows you to mount a web server's directory
locally, and treat it like a local filesystem (provided the web server is
configured as a WebDAV server). If you would like to add WebDAV mount
points, select \"New\".")) },
@@ -24,10 +22,10 @@ points, select \"New\".")) },
(map {
my $dav = $_;
{ label => $dav->{device}, val => $dav->{mntpoint}, clicked_may_quit => sub { config($in, $dav, $all_hds); 1 } } } @$davs),
- { val => _("New"), clicked_may_quit => sub { create($in, $all_hds); 1 } },
- { val => _("Quit"), icon => "exit", clicked_may_quit => sub { $quit = 1 } },
+ { val => N("New"), clicked_may_quit => sub { create($in, $all_hds); 1 } },
+ { val => N("Quit"), clicked_may_quit => sub { $quit = 1 } },
]);
- } until ($quit);
+ } until $quit;
diskdrake::interactive::Done($in, $all_hds);
}
@@ -35,10 +33,11 @@ points, select \"New\".")) },
sub create {
my ($in, $all_hds) = @_;
- my $dav = { type => 'davfs' };
+ my $dav = { fs_type => 'davfs2', mntpoint => 'none' };
ask_server($in, $dav, $all_hds) or return;
push @{$all_hds->{davs}}, $dav;
config($in, $dav, $all_hds);
+ return;
}
sub config {
@@ -47,11 +46,12 @@ sub config {
my $dav = { %$dav_ }; #- working on a local copy so that "Cancel" works
my $action;
- while ($action ne 'Done') {
+ my $exit;
+ while (!$exit && $action ne 'Done') {
my %actions = my @actions = actions($dav);
$action = $in->ask_from_list_('', format_dav_info($dav),
[ map { $_->[0] } group_by2 @actions ], 'Done') or return;
- $actions{$action}->($in, $dav, $all_hds);
+ $exit = $actions{$action}->($in, $dav, $all_hds);
}
%$dav_ = %$dav; #- applying
}
@@ -60,12 +60,13 @@ sub actions {
my ($dav) = @_;
(
- if_($dav && $dav->{isMounted}, __("Unmount") => sub { try('Unmount', @_) }),
- if_($dav && $dav->{mntpoint} && !$dav->{isMounted}, __("Mount") => sub { try('Mount', @_) }),
- __("Server") => \&ask_server,
- __("Mount point") => \&mount_point,
- __("Options") => \&options,
- __("Done") => sub {},
+ if_($dav && $dav->{isMounted}, N_("Unmount") => sub { try('Unmount', @_) }),
+ if_($dav && $dav->{mntpoint} && !$dav->{isMounted}, N_("Mount") => sub { try('Mount', @_) }),
+ N_("Server") => \&ask_server,
+ N_("Mount point") => \&mount_point,
+ N_("Options") => \&options,
+ N_("Remove") => \&remove,
+ N_("Done") => sub {},
);
}
@@ -74,41 +75,55 @@ sub try {
my $f = $diskdrake::interactive::{$name} or die "unknown function $name";
eval { $f->($in, {}, $dav) };
if (my $err = $@) {
- $in->ask_warn(_("Error"), formatError($err));
+ $in->ask_warn(N("Error"), formatError($err));
}
}
sub ask_server {
- my ($in, $dav, $all_hds) = @_;
+ my ($in, $dav, $_all_hds) = @_;
my $server = $dav->{device};
- $in->ask_from('', _("Please enter the WebDAV server URL"),
- [ { val => \$server } ],
- complete => sub {
- $server =~ m!https?://! or $in->ask_warn('', _("The URL must begin with http:// or https://")), return 1;
- 0;
- },
- ) or return;
+ $in->ask_from_({ messages => N("Please enter the WebDAV server URL"),
+ focus_first => 1,
+ callbacks => {
+ complete => sub {
+ $server =~ m!https?://! or $in->ask_warn('', N("The URL must begin with http:// or https://")), return 1;
+ 0;
+ },
+ } },
+ [ { val => \$server } ]) or return;
$dav->{device} = $server;
}
sub options {
my ($in, $dav, $all_hds) = @_;
diskdrake::interactive::Options($in, {}, $dav, $all_hds);
+ return;
+}
+
+sub remove {
+ my ($in, $dav, $all_hds) = @_;
+ if ($in->ask_yesorno(N("Warning"), N("Are you sure you want to delete this mount point?"))) {
+ @{$all_hds->{davs}} = grep { $_->{mntpoint} ne $dav->{mntpoint} } @{$all_hds->{davs}};
+ return 1;
+ }
+ return;
}
+
sub mount_point {
my ($in, $dav, $all_hds) = @_;
my $proposition = $dav->{device} =~ /(\w+)/ ? "/mnt/$1" : "/mnt/dav";
diskdrake::interactive::Mount_point_raw_hd($in, $dav, $all_hds, $proposition);
+ return;
}
sub format_dav_info {
my ($dav) = @_;
my $info = '';
- $info .= _("Server: ") . "$dav->{device}\n" if $dav->{device};
- $info .= _("Mount point: ") . "$dav->{mntpoint}\n" if $dav->{mntpoint};
- $info .= _("Options: %s", $dav->{options}) if $dav->{options};
+ $info .= N("Server: ") . "$dav->{device}\n" if $dav->{device};
+ $info .= N("Mount point: ") . "$dav->{mntpoint}\n" if $dav->{mntpoint};
+ $info .= N("Options: %s", $dav->{options}) if $dav->{options};
$info;
}
diff --git a/perl-install/diskdrake/diskdrake.html b/perl-install/diskdrake/diskdrake.html
deleted file mode 100644
index 7e85c3cde..000000000
--- a/perl-install/diskdrake/diskdrake.html
+++ /dev/null
@@ -1,139 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
-<html>
- <head>
- <title>DiskDrake</title>
- </head>
- <body bgcolor="#ffffff">
-
-<center>
-<table width=80% border=0 cellpadding=10 cellspacing=10>
-<tr>
-<td bgcolor=#ffffff>
-
- <p>
- <img src="images/diskdrake1-def.jpg" alt="diskdrake logo" width=400 height=100>
- <p>
-
- <H2>I- What's it?</H2>
-
- The purpose of the DiskDrake project is to make easier the hard disk
- partitionning. It is graphical, simple and powerful. The license is
- the GPL (General Public License).
- <BR>
- Different skill levels will be available (newbie, advanced user, expert).
- <BR>
- It's written entirely in Perl and Perl/Gtk. It uses resize_fat which is
- a perl rewrite of the work of Andrew Clausen (libresize).
- <P>
- DiskDrake is a project from MandrakeSoft, the company behind the popular
- <a href="http://www.linux-mandrake.com">Linux-Mandrake</a>
- operating-system.
- <P>
- A <A href="http://www.eatel.net/~john/diskdrake/faq.html">FAQ</A> is in construction.
-
- <H2>II - What's available now</H2>
-
- DiskDrake should be usable now...
-
- it can:
- <UL>
- <LI> create partitions
- <LI> delete partitions
- <LI> change type of partition
- <LI> format partitions
- <LI> assign a mount point (<IMG SRC="/images/updated.gif" ALT="updated"><SMALL>(21/07/99)</SMALL> propose a list
- of classic mount points and verify the mount point is valid)
- <LI> mount partitions
- <LI> resize fat partitions
- <LI> resize partitions (when not caring loosing its data)
- <LI> clear partition table
- <LI> auto allocation (usefull for install)
- <LI> write fstab
- </UL>
-
-with nice contextual menu (shortcuts available, but dangerous as all actions are
-available, whereas with the contextual menu these actions are hidden. This will
-change)
-
- <P><IMG SRC="/images/updated.gif" ALT="updated"><SMALL>(25/07/99)</SMALL>
- A new Expert button appear now. It toggles between
- expert and normal mode. Some changes in information displayed:
- <UL>
- <LI> when you click (or focus) the drive tab (eg: hda), you get
- information about your drive: size, geometry
- (cylinders/sectors/heads number), type (eg: IBM DDRS-39130D), and bus/id.
- In normal mode you have only the size.
- <LI> the windows drive letter (eg: C: D: ...)
- <LI> the `start sector' information from normal mode, it still appears in
- expert mode
- <LI> the start&end cylinder of each partition is now displayed in expert
- mode
- <LI> the type is displayed numerically in expert mode
- </UL>
-
- <P><IMG SRC="/images/updated.gif" ALT="updated"><SMALL>(25/07/99)</SMALL>
- The mount point in the `Create' window and `Change type' window is now a
- combo box. It lets you choose between classical mount points (/ /usr /var
- ...) but with already allocated mount points removed.
-
- <H2>III - Actual developpment</H2>
-
- We need people!!!
-
- <UL>
- <LI><B>Tests</B> and remove bugs (no known yet :)
- <LI>integrate ext2resize (which has been release in version 1.0.0 <IMG
- SRC="/images/updated.gif" ALT="updated"><SMALL>(26/07/99)</SMALL>)
- <LI>add possibility to move partition without loosing data (by copying all
- data) <IMG SRC="/images/updated.gif" ALT="updated">
- <LI>Improve the look
- <LI>Add a text-only version
- <LI>Help text, tutorial...
- <LI>Internationalization
- <LI>Add some features...
- <LI>Packaging (rpm, deb, slp...)
- </UL>
-
- <H2>IV- ScreenShot</H2>
-
- Warning: features was the main focus, so don't be too hard :)
-
- <P>
- <CENTER><IMG SRC="1.gif"></IMG></CENTER>
- <CENTER>DiskDrake main interface</CENTER>
-
- <BR>
- <CENTER><IMG SRC="3.gif"></IMG></CENTER>
- <CENTER>create dialog box</CENTER>
-
- <H2>V - Contacts</H2>
-
- A Mailing List has been created to allow developpers to discuss about DiskDrake.<BR>
-
- <P>
- Send a mail to: <A HREF="mailto:sympa@linux-mandrake.com">sympa@linux-mandrake.com</A>
-
- <BR>Put in the subject: subscribe diskdrake
- <BR>When you're subscribed, send your messages to: <A HREF="mailto:diskdrake@linux-mandrake.com">diskdrake@linux-mandrake.com</A>
-
- <P>Otherwise you can contact directly the <A HREF="mailto:pixel@linux-mandrake.com">project leader</A>.
-
- <H2>VI - Download</H2>
-
- Warning: You must have <a href="http://www.perl.com/CPAN/modules/by-module/Gtk/Gtk-Perl-0.5121.tar.gz">Gtk-Perl</a>.
- You can get the rpm from the <a href="http://linux-mandrake.com/cooker/">Cooker</a> distribution.
-
- <P>You also need perl version 5.00503 or better
-
- <P> Here you can find the plain tgz or a rpm:
- <a href="ftp://ftp.phys.ttu.edu/pub/mandrake-devel/contrib/others/diskdrake/">diskdrake</a> (Other mirrors in <a href="http://linux-mandrake.com/cooker/">Cooker</a>)
-
-</td>
-</tr>
-</table>
-<p>
-<a href="/en/fpowerpack.php3"><img src="/images/mandrake6.0-loop.gif" width=468 height=60 alt="Mandrake 6.0 PowerPack"></a>
-</center>
- </body>
- <address><a href="mailto:pixel@linux-mandrake.com"></a></address>
-</html>
diff --git a/perl-install/diskdrake/hd_gtk.pm b/perl-install/diskdrake/hd_gtk.pm
index 454da1735..ed3955ea7 100644
--- a/perl-install/diskdrake/hd_gtk.pm
+++ b/perl-install/diskdrake/hd_gtk.pm
@@ -1,36 +1,34 @@
-package diskdrake::hd_gtk; # $Id$
+package diskdrake::hd_gtk;
use diagnostics;
use strict;
use common;
-use resize_fat::main;
-use my_gtk qw(:helpers :wrappers :ask);
-use partition_table qw(:types);
-use partition_table::raw;
+use mygtk3 qw(gtknew);
+use ugtk3 qw(:helpers :wrappers :create);
+use partition_table;
+use fs::type;
use detect_devices;
use diskdrake::interactive;
use run_program;
-use loopback;
use devices;
-use raid;
-use any;
use log;
use fsedit;
-use fs;
+use feature qw(state);
-my ($width, $height, $minwidth) = (400, 50, 5);
-my ($all_hds, $in, $current_kind, $current_entry, $update_all);
+my ($width, $height, $minwidth) = (400, 50, 16);
+my ($all_hds, $in, $do_force_reload, $current_kind, $current_entry, $update_all);
my ($w, @notebook, $done_button);
-=begin
-struct {
+=head1 SYNOPSYS
+
+ struct {
string name # which is displayed in tab of the notebook
bool no_auto # wether the kind can disappear after creation
- string type # one of { 'hd', 'raid', 'lvm', 'loopback', 'removable', 'nfs', 'smb' }
- hd | hd_lvm | part_raid[] | part_loopback[] | raw_hd[] val
-
+ string type # one of { 'hd', 'raid', 'lvm', 'loopback', 'removable', 'nfs', 'smb', 'dmcrypt' }
+ hd | hd_lvm | part_raid[] | part_dmcrypt[] | part_loopback[] | raw_hd[] val
+
#
widget main_box
widget display_box
@@ -38,64 +36,105 @@ struct {
widget info_box
} current_kind
-part current_entry
+ part current_entry
-notebook current_kind[]
+ notebook current_kind[]
=cut
+sub load_theme() {
+ my $css = "/usr/share/libDrakX/diskdrake.css";
+ -r $css or $css = dirname(__FILE__) . "/../diskdrake.css";
+ -r $css or $css = dirname(__FILE__) . "/../share/diskdrake.css";
+ my $pl = Gtk3::CssProvider->new;
+ $pl->load_from_path($css);
+ Gtk3::StyleContext::add_provider_for_screen(Gtk3::Gdk::Screen::get_default(), $pl, Gtk3::STYLE_PROVIDER_PRIORITY_APPLICATION);
+}
+
sub main {
- ($in, $all_hds, my $nowizard) = @_;
+ ($in, $all_hds, $do_force_reload) = @_;
@notebook = ();
local $in->{grab} = 1;
- $w = my_gtk->new('DiskDrake');
- my $rc = "/usr/share/libDrakX/diskdrake.rc";
- -r $rc or $rc = dirname(__FILE__) . "/../diskdrake.rc";
- -r $rc or $rc = dirname(__FILE__) . "/../share/diskdrake.rc";
- Gtk::Rc->parse($rc);
+ $w = ugtk3->new(N("Partitioning"));
+ mygtk3::register_main_window($w->{real_window}) if !$::isEmbedded && !$::isInstall;
+
+ load_theme();
+ $w->{window}->signal_connect('style-updated' => \&load_theme);
# TODO
# is_empty_array_ref($all_hds->{raids}) or raid::stopAll;
# updateLoopback();
gtkadd($w->{window},
- gtkpack_(new Gtk::VBox(0,7),
- 0, (my $filesystems_button_box = filesystems_button_box()),
- 1, (my $notebook_widget = new Gtk::Notebook),
- 0, (my $per_kind_action_box = new Gtk::HBox(0,0)),
- 0, (my $general_action_box = new Gtk::HBox(0,0)),
+ gtkpack_(Gtk3::VBox->new(0,7),
+ 0, gtknew(($::isInstall ? ('Title1', 'label') : ('Label_Left', 'text'))
+ => N("Click on a partition, choose a filesystem type then choose an action"),
+ # workaround infamous 6 years old gnome bug #101968:
+ width => mygtk3::get_label_width()
+ ),
+ 1, (my $notebook_widget = Gtk3::Notebook->new),
+ 0, (my $per_kind_action_box = gtknew('HButtonBox', layout => 'edge')),
+ 0, Gtk3::HSeparator->new,
+ 0, (my $general_action_box = gtknew('HBox', spacing => 5)),
),
);
- my $lock;
+ my ($lock, $initializing) = (undef, 1);
$update_all = sub {
+ my ($o_refresh_gui) = @_;
+ state $not_first;
+ return if $initializing && $not_first;
+ $not_first = 1;
$lock and return;
$lock = 1;
- partition_table::assign_device_numbers($_) foreach fsedit::all_hds($all_hds);
+ partition_table::assign_device_numbers($_) foreach fs::get::hds($all_hds);
create_automatic_notebooks($notebook_widget);
- general_action_box($general_action_box, $nowizard);
+ general_action_box($general_action_box);
per_kind_action_box($per_kind_action_box, $current_kind);
current_kind_changed($in, $current_kind);
current_entry_changed($current_kind, $current_entry);
$lock = 0;
+ if ($o_refresh_gui) {
+ my $new_page = $o_refresh_gui > 1 ? $notebook_widget->get_current_page : 0;
+ $notebook_widget->set_current_page(-1);
+ $notebook_widget->set_current_page($new_page);
+ }
};
create_automatic_notebooks($notebook_widget);
- $notebook_widget->signal_connect('switch_page' => sub {
+ $notebook_widget->signal_connect(switch_page => sub {
$current_kind = $notebook[$_[2]];
$current_entry = '';
$update_all->();
});
+ # ensure partitions bar is properly sized on first display:
+ $notebook_widget->signal_connect(realize => $update_all);
$w->sync;
+ # add a bogus tab so that gtk+ displayed everything when there's only one disk:
+ $notebook_widget->prepend_page(Gtk3::Label->new, Gtk3::Label->new);
+ $notebook_widget->set_current_page(0);
+ # there's always at least one child (at least a button for create a new part on empty discs):
+ my @children = $current_kind->{display_box} ? $current_kind->{display_box}->get_children : ();
+ # workaround for $notebook_widget being realized too early:
+ if (!@children ||!$done_button) {
+ $notebook_widget->set_current_page(-1);
+ $notebook_widget->set_current_page(0);
+ undef $initializing;
+ $update_all->(2);
+ }
+ undef $initializing;
+ # remove bogus tab we added just to be sure gtk+ displayed everything:
+ $notebook_widget->remove_page(0);
+ # restore position when there's several disks:
+ $notebook_widget->set_current_page(0);
$done_button->grab_focus;
- $my_gtk::pop_it = 1;
- $in->ask_okcancel(_("Read carefully!"), _("Please make a backup of your data first"), 1) or return
- if $::isStandalone;
- $in->ask_warn('',
-_("If you plan to use aboot, be carefull to leave a free space (2048 sectors is enough)
-at the beginning of the disk")) if (arch() eq 'alpha') and !$::isEmbedded;
+ if (!$::testing) {
+ $in->ask_from_list_(N("Read carefully"), N("Please make a backup of your data first"),
+ [ N_("Exit"), N_("Continue") ], N_("Continue")) eq N_("Continue") or return
+ if $::isStandalone;
+ }
$w->main;
}
@@ -103,25 +142,38 @@ at the beginning of the disk")) if (arch() eq 'alpha') and !$::isEmbedded;
sub try {
my ($name, @args) = @_;
my $f = $diskdrake::interactive::{$name} or die "unknown function $name";
- try_($name, \&{$f}, @args);
+ try_($name, \&$f, @args);
}
sub try_ {
my ($name, $f, @args) = @_;
- fsedit::undo_prepare($all_hds) if $name ne 'Undo';
-
+ my $dm_active_before = ($current_entry && $current_entry->{dm_active} && $current_entry->{dm_name});
my $v = eval { $f->($in, @args, $all_hds) };
if (my $err = $@) {
- $err =~ /setstep/ and die '';
- $in->ask_warn(_("Error"), formatError($err));
+ warn $err, "\n", backtrace() if $in->isa('interactive::gtk');
+ $in->ask_warn(N("Error"), formatError($err));
+ }
+ my $refresh = 0;
+ if ($v eq 'force_reload') {
+ $all_hds = $do_force_reload->();
+ $refresh = 1;
}
- $current_entry = '' if !diskdrake::interactive::is_part_existing($current_entry, $all_hds);
- $update_all->();
-
- if ($v && member($name, 'Done', 'Wizard')) {
- $::isEmbedded ? kill('USR1', $::CCPID) : Gtk->main_quit;
+ if (!diskdrake::interactive::is_part_existing($current_entry, $all_hds)) {
+ $current_entry = '';
+ } elsif (!$dm_active_before && $current_entry->{dm_active} && $current_entry->{dm_name}) {
+ if (my $mapped_part = fs::get::device2part("mapper/$current_entry->{dm_name}", $all_hds->{dmcrypts})) {
+ $current_entry = $mapped_part;
+ $refresh = 2;
+ }
}
+ $update_all->($refresh);
+
+ Gtk3->main_quit if $v && member($name, 'Done');
+}
+
+sub get_action_box_size() {
+ $::isStandalone ? 200 : 150, $::isEmbedded ? 150 : 180;
}
################################################################################
@@ -131,91 +183,108 @@ sub add_kind2notebook {
my ($notebook_widget, $kind) = @_;
die if $kind->{main_box};
- $kind->{display_box} = gtkset_usize(new Gtk::HBox(0,0), $width, $height);
- $kind->{action_box} = gtkset_usize(new Gtk::VBox(0,0), 150, 180);
- $kind->{info_box} = new Gtk::VBox(0,0);
- $kind->{main_box} =
- gtkpack_(new Gtk::VBox(0,7),
- 0, $kind->{display_box},
- 1, gtkpack_(new Gtk::HBox(0,7),
- 0, $kind->{action_box},
- 1, $kind->{info_box}));
- my_gtk::add2notebook($notebook_widget, $kind->{name}, $kind->{main_box});
+ $kind->{display_box} = gtkset_size_request(Gtk3::HBox->new(0,0), $width, $height);
+ $kind->{action_box} = gtkset_size_request(Gtk3::VBox->new, get_action_box_size());
+ $kind->{info_box} = Gtk3::VBox->new(0,0);
+ my $box =
+ gtkpack_(Gtk3::VBox->new(0,7),
+ 0, create_scrolled_window($kind->{display_box}, [ 'automatic', 'never' ]),
+ 0, filesystems_button_box(),
+ 1, $kind->{info_box});
+ $kind->{main_box} = gtknew('HBox', spacing => 5, children => [
+ 1, $box,
+ 0, $kind->{action_box},
+ ]);
+ ugtk3::add2notebook($notebook_widget, $kind->{name}, $kind->{main_box});
push @notebook, $kind;
$kind;
}
+sub interactive_help() {
+ if ($::isInstall) {
+ $in->display_help({ interactive_help_id => 'diskdrake' });
+ } else {
+ require run_program;
+ run_program::raw({ detach => 1 }, 'drakhelp', '--id', 'diskdrake');
+ }
+}
+
sub general_action_box {
- my ($box, $nowizard) = @_;
- $_->widget->destroy foreach $box->children;
- my @actions = (if_($::isInstall && !$nowizard, __("Wizard")),
+ my ($box) = @_;
+ $_->destroy foreach $box->get_children;
+
+ my $box_start = gtknew('HButtonBox', layout => 'start', children_tight => [
+ gtknew('Install_Button', text => N("Help"), clicked => \&interactive_help)
+ ]);
+
+ my @actions = (
diskdrake::interactive::general_possible_actions($in, $all_hds),
- __("Done"));
+ N_("Done"));
+ my $box_end = gtknew('HButtonBox', layout => 'end', spacing => 5);
foreach my $s (@actions) {
- my $button = new Gtk::Button(translate($s));
+ my $button = Gtk3::Button->new(translate($s));
$done_button = $button if $s eq 'Done';
- gtkadd($box, gtksignal_connect($button, clicked => sub { try($s) }));
+ gtkadd($box_end, gtksignal_connect($button, clicked => sub { try($s) }));
}
+ gtkadd($box, $box_start, $box_end);
}
sub per_kind_action_box {
my ($box, $kind) = @_;
- $_->widget->destroy foreach $box->children;
-
- $kind->{type} =~ /hd|lvm/ or return;
+ $_->destroy foreach $box->get_children;
- foreach my $s (diskdrake::interactive::hd_possible_actions($in, kind2hd($kind), $all_hds)) {
+ my @actions = (if_($kind->{type} =~ /hd|lvm/, diskdrake::interactive::hd_possible_actions_base($in)),
+ diskdrake::interactive::hd_possible_actions_extra($in));
+ foreach my $s (@actions) {
gtkadd($box,
- gtksignal_connect(new Gtk::Button(translate($s)),
+ gtksignal_connect(Gtk3::Button->new(translate($s)),
clicked => sub { try($s, kind2hd($kind)) }));
}
+ # make sure a big translations window to resize (as by default all buttons have the same size):
+ $box->set_child_non_homogeneous($_, Glib::TRUE), "\n" foreach $box->get_children;
}
sub per_entry_action_box {
my ($box, $kind, $entry) = @_;
- $_->widget->destroy foreach $box->children;
+ $_->destroy foreach $box->get_children;
if ($entry) {
my @buttons = map {
my $s = $_;
- my $w = new Gtk::Button(translate($s));
+ my $w = Gtk3::Button->new(translate($s));
$w->signal_connect(clicked => sub { try($s, kind2hd($kind), $entry) });
$w;
} diskdrake::interactive::part_possible_actions($in, kind2hd($kind), $entry, $all_hds);
- gtkadd($box, gtkadd(new Gtk::Frame(_("Choose action")),
- createScrolledWindow(gtkpack__(new Gtk::VBox(0,0), @buttons)))) if @buttons;
+ gtkadd($box, create_scrolled_window(gtkpack__(Gtk3::VBox->new, @buttons), undef, 'none')) if @buttons;
} else {
- my $txt = !$::isStandalone && fsedit::is_one_big_fat($all_hds->{hds}) ?
-_("You have one big FAT partition
-(generally used by MicroSoft Dos/Windows).
+ my $txt = !$::isStandalone && fsedit::is_one_big_fat_or_NT($all_hds->{hds}) ?
+N("You have one big Microsoft Windows partition.
I suggest you first resize that partition
-(click on it, then click on \"Resize\")") : _("Please click on a partition");
- gtkpack($box, gtktext_insert(new Gtk::Text, $txt));
+(click on it, then click on \"Resize\")") : N("Please click on a partition");
+ gtkpack($box, gtktext_insert(Gtk3::TextView->new, $txt));
}
}
sub per_entry_info_box {
my ($box, $kind, $entry) = @_;
- $_->widget->destroy foreach $box->children;
+ $_->destroy foreach $box->get_children;
my $info;
if ($entry) {
$info = diskdrake::interactive::format_part_info(kind2hd($kind), $entry);
} elsif ($kind->{type} =~ /hd|lvm/) {
$info = diskdrake::interactive::format_hd_info($kind->{val});
}
- gtkpack($box, gtkadd(new Gtk::Frame(_("Details")), gtkset_justify(new Gtk::Label($info), 'left')));
+ gtkpack($box, gtkadd(gtkcreate_frame(N("Details")),
+ gtknew('HBox', border_width => 5, children_loose => [
+ gtkset_alignment(gtkset_justify(gtknew('Label', selectable => 1, text => $info), 'left'), 0, 0) ])));
}
sub current_kind_changed {
- my ($in, $kind) = @_;
-
- $_->widget->destroy foreach $kind->{display_box}->children;
+ my ($_in, $kind) = @_;
- my $v = $kind->{val};
- my @parts =
- $kind->{type} eq 'raid' ? grep { $_ } @$v :
- $kind->{type} eq 'loopback' ? @$v : fsedit::get_fstab_and_holes($v);
- my $totalsectors =
- $kind->{type} =~ /raid|loopback/ ? sum(map { $_->{size} } @parts) : $v->{totalsectors};
+ return if !$kind->{display_box};
+ $_->destroy foreach $kind->{display_box}->get_children;
+ my @parts = kind2parts($kind);
+ my $totalsectors = kind2sectors($kind, @parts);
create_buttons4partitions($kind, $totalsectors, @parts);
}
@@ -230,7 +299,6 @@ sub current_entry_changed {
sub create_automatic_notebooks {
my ($notebook_widget) = @_;
- my @l = fsedit::all_hds($all_hds);
$_->{marked} = 0 foreach @notebook;
my $may_add = sub {
@@ -242,39 +310,71 @@ sub create_automatic_notebooks {
};
$may_add->(hd2kind($_)) foreach @{$all_hds->{hds}};
$may_add->(lvm2kind($_)) foreach @{$all_hds->{lvms}};
- $may_add->(raid2kind()) if grep { $_ } @{$all_hds->{raids}};
+ $may_add->(raid2kind()) if @{$all_hds->{raids}};
$may_add->(loopback2kind()) if @{$all_hds->{loopbacks}};
- @notebook = grep_index {
- my $b = $_->{marked} or $notebook_widget->remove_page($::i);
- $b;
+ my $i = 0;
+ @notebook = grep {
+ if ($_->{marked}) {
+ $i++;
+ 1;
+ } else {
+ $notebook_widget->remove_page($i);
+ 0;
+ }
} @notebook;
- @notebook or die _("No hard drives found");
+ @notebook or $in->ask_warn(N("Error"), N("No hard disk drives found")), $in->exit(1);
}
################################################################################
# parts: helpers
################################################################################
sub create_buttons4partitions {
- my ($kind, $totalsectors, @parts) = @_;
+ my ($kind, $totalsectors, @all_parts) = @_;
- $width = max($width, 0.9 * second($w->{window}->window->get_size)) if $w->{window}->window;
+ if ($w->{window}->get_window) {
+ my $windowwidth = $w->{window}->get_allocated_width;
+ $windowwidth = $::real_windowwidth if $windowwidth <= 1;
+ $width = $windowwidth - first(get_action_box_size()) - 25;
+ }
+
+ my @parts = grep { $_->{size} > MB(2) || !isEmpty($_) } @all_parts;
my $ratio = $totalsectors ? ($width - @parts * $minwidth) / $totalsectors : 1;
- while (1) {
+ my $i = 1;
+ while ($i < 30) {
+ $i++;
my $totalwidth = sum(map { $_->{size} * $ratio + $minwidth } @parts);
$totalwidth <= $width and last;
$ratio /= $totalwidth / $width * 1.1;
}
+ my $current_button;
+ my $set_current_button = sub {
+ my ($w) = @_;
+ $current_button->set_active(0) if $current_button;
+ ($current_button = $w)->set_active(1);
+ };
+
foreach my $entry (@parts) {
- my $w = new Gtk::Button($entry->{mntpoint} || '') or die '';
- $w->signal_connect(focus_in_event => sub { current_entry_changed($kind, $entry) });
- $w->signal_connect(button_press_event => sub { current_entry_changed($kind, $entry) });
+ if (isRawLUKS($entry) && $entry->{dm_active}) {
+ my $p = find { $entry->{dm_name} eq $_->{dmcrypt_name} } @{$all_hds->{dmcrypts}};
+ $entry = $p if $p;
+ }
+ my $info = $entry->{mntpoint} || $entry->{device_LABEL} || '';
+ $info .= "\n" . ($entry->{size} ? formatXiB($entry->{size}, 512) : N("Unknown")) if $info;
+ my $w = ($info ? Gtk3::ToggleButton->new_with_label($info) : Gtk3::ToggleButton->new) or internal_error('new_with_label');
+ $info and $w->get_child->set_ellipsize('end');
+ $w->set_tooltip_text($info);
+ $w->signal_connect(clicked => sub {
+ $current_button != $w or return;
+ current_entry_changed($kind, $entry);
+ $set_current_button->($w);
+ });
$w->signal_connect(key_press_event => sub {
- my ($w, $e) = @_;
- $e->{state} & 4 or return;
- my $c = chr $e->{keyval};
+ my (undef, $event) = @_;
+ member('control-mask', @{$event->state}) && $w == $current_button or return;
+ my $c = chr $event->keyval;
foreach my $s (diskdrake::interactive::part_possible_actions($in, kind2hd($kind), $entry, $all_hds)) {
${{
@@ -289,10 +389,19 @@ sub create_buttons4partitions {
last;
}
});
- $w->set_name("PART_" . type2name($entry->{type}));
- $w->set_usize($entry->{size} * $ratio + $minwidth, 0);
- gtkpack__($kind->{display_box}, $w);
- $w->grab_focus if $current_entry && fsedit::is_same_part($current_entry, $entry);
+ if (isLUKS($entry) || isRawLUKS($entry)) {
+ $w->set_image(gtknew("Image", file => "security-strong"));
+ }
+ my @colorized_fs_types = qw(ext3 ext4 xfs swap vfat ntfs ntfs-3g exfat);
+ $w->set_name("PART_" . (isEmpty($entry) ? 'empty' :
+ $entry->{fs_type} && member($entry->{fs_type}, @colorized_fs_types) ? $entry->{fs_type} :
+ 'other'));
+ $w->set_size_request($entry->{size} * $ratio + $minwidth, 0);
+ gtkpack($kind->{display_box}, $w);
+ if ($current_entry && fsedit::are_same_partitions($current_entry, $entry)) {
+ $set_current_button->($w);
+ $w->grab_focus;
+ }
}
}
@@ -300,18 +409,18 @@ sub create_buttons4partitions {
################################################################################
# disks: helpers
################################################################################
-sub current_hd {
- $current_kind->{type} eq 'hd' or die 'current_hd called but $current_kind is not an hd';
+sub current_hd() {
+ $current_kind->{type} =~ /hd|lvm/ or die 'current_hd called but $current_kind is not an hd (' . $current_kind->{type} . ')';
$current_kind->{val};
}
-sub current_part {
+sub current_part() {
current_hd();
$current_entry;
}
sub kind2hd {
my ($kind) = @_;
- $kind->{type} =~ /hd|lvm/ ? $kind->{val} : {}
+ $kind->{type} =~ /hd|lvm/ ? $kind->{val} : bless({}, 'partition_table::raw');
}
sub hd2kind {
@@ -320,43 +429,63 @@ sub hd2kind {
}
sub filesystems_button_box() {
- my @types = (__("Ext2"), __("Journalised FS"), __("Swap"), arch() =~ /sparc/ ? __("SunOS") : arch() eq "ppc" ? __("HFS") : __("FAT"),
- __("Other"), __("Empty"));
- my %name2type = (Ext2 => 0x83, 'Journalised FS' => 0x483, Swap => 0x82, Other => 1, FAT => 0xb, HFS => 0x402);
-
- gtkpack(new Gtk::HBox(0,0),
- _("Filesystem types:"),
- map { my $w = new Gtk::Button(translate($_));
- my $t = $name2type{$_};
- $w->signal_connect(clicked => sub { try_('', \&createOrChangeType, $t, current_hd(), current_part()) });
- $w->can_focus(0);
- $w->set_name($_);
+ my @types = (N_("Ext4"), N_("XFS"), N_("Swap"), N_("Windows"),
+ N_("Other"), N_("Empty"));
+ my %name2fs_type = (Ext3 => 'ext3', Ext4 => 'ext4', 'XFS' => 'xfs', Swap => 'swap', Other => 'other', "Windows" => 'vfat', HFS => 'hfs');
+
+ gtkpack(Gtk3::HBox->new,
+ map {
+ my $t = $name2fs_type{$_};
+ my $w = gtknew('Button', text => translate($_), widget_name => 'PART_' . ($t || 'empty'),
+ tip => N("Filesystem types:"),
+ clicked => sub { try_('', \&createOrChangeType, $t, current_hd(), current_part()) });
+ $w->set_can_focus(0);
$w;
} @types);
}
sub createOrChangeType {
- my ($in, $type, $hd, $part, $all_hds) = @_;
+ my ($in, $fs_type, $hd, $part, $all_hds) = @_;
- $part ||= !fsedit::get_fstab($hd) &&
- { type => 0, start => 1, size => $hd->{totalsectors} - 1 };
+ $part ||= !fs::get::hds_fstab($hd) &&
+ { pt_type => 0, start => 1, size => $hd->{totalsectors} - 1 };
$part or return;
- if ($type == 1) {
- $in->ask_warn('', _("Use ``%s'' instead", $part->{type} ? _("Type") : _("Create")));
- } elsif (!$type) {
- $in->ask_warn('', _("Use ``%s'' instead", _("Delete"))) if $part->{type};
- } elsif ($part->{type}) {
- return unless $::expert;
- return if $type == $part->{type};
- isBusy($part) and $in->ask_warn('', _("Use ``Unmount'' first")), return;
- diskdrake::interactive::ask_alldatawillbelost($in, $part, __("After changing type of partition %s, all data on this partition will be lost")) or return;
- diskdrake::interactive::check_type($in, $type, $hd, $part) and fsedit::change_type($type, $hd, $part);
- } else {
- $part->{type} = $type;
+ if ($fs_type eq 'other') {
+ if (isEmpty($part)) {
+ try('Create', $hd, $part);
+ } else {
+ try('Type', $hd, $part);
+ }
+ } elsif (!$fs_type) {
+ if (isEmpty($part)) {
+ $in->ask_warn(N("Warning"), N("This partition is already empty"));
+ } else {
+ try('Delete', $hd, $part);
+ }
+ } elsif (isEmpty($part)) {
+ fs::type::set_fs_type($part, $fs_type);
diskdrake::interactive::Create($in, $hd, $part, $all_hds);
+ } else {
+ return if $fs_type eq $part->{fs_type};
+ $in->ask_warn('', isBusy($part) ? N("Use ``Unmount'' first") : N("Use ``%s'' instead (in expert mode)", N("Type")));
}
}
+sub kind2parts {
+ my ($kind) = @_;
+ my $v = $kind->{val};
+ my @parts =
+ $kind->{type} eq 'raid' ? grep { $_ } @$v :
+ $kind->{type} eq 'loopback' ? @$v : fs::get::hds_fstab_and_holes($v);
+ @parts;
+}
+
+sub kind2sectors {
+ my ($kind, @parts) = @_;
+ my $v = $kind->{val};
+ $kind->{type} =~ /raid|loopback/ ? sum(map { $_->{size} } @parts) : $v->{totalsectors};
+}
+
################################################################################
# lvms: helpers
################################################################################
@@ -368,14 +497,19 @@ sub lvm2kind {
################################################################################
# raids: helpers
################################################################################
-sub raid2kind {
+sub raid2kind() {
{ type => 'raid', name => 'raid', val => $all_hds->{raids} };
}
+sub raid2real_kind {
+ my ($raid) = @_;
+ { type => 'raid', name => 'raid', val => $raid };
+}
+
################################################################################
# loopbacks: helpers
################################################################################
-sub loopback2kind {
+sub loopback2kind() {
{ type => 'loopback', name => 'loopback', val => $all_hds->{loopbacks} };
}
diff --git a/perl-install/diskdrake/interactive.pm b/perl-install/diskdrake/interactive.pm
index 6d482e8af..59e79782c 100644
--- a/perl-install/diskdrake/interactive.pm
+++ b/perl-install/diskdrake/interactive.pm
@@ -1,30 +1,47 @@
-package diskdrake::interactive; # $Id$
+package diskdrake::interactive;
use diagnostics;
use strict;
+use utf8;
+use lib qw(/usr/lib/libDrakX); # for perl_checker
+use MDK::Common; # for perl_checker
use common;
-use partition_table qw(:types);
+use fs::type;
+use fs::loopback;
+use fs::format;
+use fs::mount_options;
+use fs;
+use partition_table;
use partition_table::raw;
use detect_devices;
use run_program;
-use loopback;
use devices;
use fsedit;
use raid;
use any;
use log;
-use fs;
+=head1 SYNOPSYS
-=begin
-
-struct part {
+ struct part {
int active # one of { 0 | 0x80 } x86 only, primary only
int start # in sectors
int size # in sectors
- int type # 0x82, 0x83, 0x6 ...
+ int pt_type # 0x82, 0x83, 0x6 ...
+ string fs_type # 'ext2', 'nfs', ...
+ string type_name # 'Linux RAID', 'Linux Logical Volume Manager', ...
+
+ int part_number # 1 for hda1...
string device # 'hda5', 'sdc1' ...
+ string device_LABEL # volume label. LABEL=xxx or /dev/disk/by-label/xxx can be used in fstab instead of the device
+ string device_UUID # volume UUID. UUID=xxx or /dev/disk/by-uuid/xxx can be used in fstab instead of the device
+ bool prefer_device_LABEL # should the {device_LABEL} or the {device} be used in fstab
+ 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' ...
string mntpoint # '/', '/usr' ...
@@ -32,126 +49,145 @@ 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 #
+
+ 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 don't know which state we're in
-
- int raid # for partitions of type isRawRAID and which isPartOfRAID, the raid device number
+ # !isFormatted && !notFormatted means we do not know which state we're in
+
+ string raid # for partitions of type isRawRAID and which isPartOfRAID, the raid device
string lvm # partition used as a PV for the VG with {lvm} as VG_name #-#
loopback loopback[] # loopback living on this partition
-
+
+ string dmcrypt_key
+ string dm_name
+ bool dm_active
+
# internal
- string real_device # '/dev/loop0', '/dev/loop1' ...
-
+ 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 {
+ struct part_allocate inherits part {
int maxsize # in sectors (alike "size")
- int ratio #
+ int min_hd_size # in sectors (do not allocate if the drive is smaller than the given size)
+ int ratio #
string hd # 'hda', 'hdc'
string parts # for creating raid partitions. eg: 'foo bar' where 'foo' and 'bar' are mntpoint
}
-struct part_raid inherits part {
- string chunk-size # usually '64k'
+ struct part_raid inherits part {
+ string chunk-size # in KiB, usually '64'
string level # one of { 0, 1, 4, 5, 'linear' }
-
+ string UUID
+
part disks[]
-
+
# invalid: active, start, rootDevice, device_windobe?, CHS
}
-struct part_loopback inherits part {
+ struct part_dmcrypt inherits part {
+ string dmcrypt_name
+
+ # rootDevice is special here: it is the device hosting the dm
+}
+
+ struct part_loopback inherits part {
string loopback_file # absolute file name which is relative to the partition
part loopback_device # where the loopback file live
-
+
# device is special here: it is the absolute filename of the loopback file.
-
+
# invalid: active, start, rootDevice, device_windobe, CHS
}
-struct part_lvm inherits part {
+ struct part_lvm inherits part {
# invalid: active, start, device_windobe, CHS
+ string lv_name
}
-struct partition_table_elem {
+ struct partition_table_elem {
part normal[] #
part extended # the main/next extended
part raw[4] # primary partitions
}
-struct geom {
- int heads
+ struct geom {
+ int heads
int sectors
int cylinders
int totalcylinders # for SUN, forget it
int start # always 0, forget it
}
-struct hd {
+ struct hd {
int totalsectors # size in sectors
string device # 'hda', 'sdc' ...
string device_alias # 'cdrom', 'floppy' ...
string media_type # one of { 'hd', 'cdrom', 'fd', 'tape' }
string capacity # contain of the strings of { 'burner', 'DVD' }
string info # name of the hd, eg: 'QUANTUM ATLAS IV 9 WLS'
-
+
bool readonly # is it allowed to modify the partition table
- bool isDirty # does it need to be written to the disk
- bool needKernelReread # must we tell the kernel to reread the partition table
- bool hasBeenDirty # for undo
+ 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
+ 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
- bool partitionsRenumbered # happens when you
+ list partitionsRenumbered # happens when you
# - remove an extended partition which is not the last one
# - 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[]
-
+
geom geom
-
+
# internal
string prefix # for some RAID arrays device=>c0d0 and prefix=>c0d0p
string file # '/dev/hda' ...
}
-struct hd_lvm inherits hd {
+ struct hd_lvm inherits hd {
int PE_size # block size (granularity, similar to cylinder size on x86)
string VG_name # VG name
-
+
part_lvm disks[]
-
+
# invalid: bus, id, extended, geom
}
-struct raw_hd inherits hd {
- string type # 0x82, 0x83, 'nfs', ...
+ struct raw_hd inherits hd {
+ string fs_type # 'ext2', 'nfs', ...
string mntpoint # '/', '/usr' ...
string options # 'defaults', 'noauto'
-
- # invalid: isDirty, needKernelReread, hasBeenDirty, rebootNeeded, primary, extended
+
+ # invalid: isDirty, will_tell_kernel, rebootNeeded, primary, extended
}
-struct all_hds {
+ struct all_hds {
hd hds[]
hd_lvm lvms[]
- part_raid raids[] # indexed by number: raids[$n]{device} is "md$n"
+ part_raid raids[]
+ part_dmcrypt dmcrypts[]
part_loopback loopbacks[]
raw_hd raw_hds[]
raw_hd nfss[]
raw_hd smbs[]
raw_hd davs[]
raw_hd special[]
-
+
# internal: if fstab_to_string($all_hds) eq current_fstab then no need to save
string current_fstab
}
@@ -161,7 +197,7 @@ struct all_hds {
sub main {
- my ($in, $all_hds) = @_;
+ my ($in, $all_hds, $do_force_reload) = @_;
if ($in->isa('interactive::gtk')) {
require diskdrake::hd_gtk;
@@ -169,46 +205,60 @@ sub main {
}
my ($current_part, $current_hd);
-
+
while (1) {
- my $choose_txt = $current_part ? __("Choose another partition") : __("Choose a partition");
- my $parts_and_holes = [ fsedit::get_all_fstab_and_holes($all_hds) ];
+ 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), sub { format_part_info_short(fsedit::part2hd($_[0], $all_hds), $_[0]) }, $parts_and_holes, $current_part) || return;
- $current_hd = fsedit::part2hd($current_part, $all_hds);
+ $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]);
+ }, $parts_and_holes, $current_part) || return;
+ $current_hd = fs::get::part2hd($current_part, $all_hds);
};
$choose_part->() if !$current_part;
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 => _("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;
- $actions{$a}();
- $current_hd = $current_part = '' if !is_part_existing($current_part, $all_hds);
+ my $v = eval { $actions{$a}() };
+ if (my $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);
} else {
$choose_part->();
}
- partition_table::assign_device_numbers($_) foreach fsedit::all_hds($all_hds);
+ partition_table::assign_device_numbers($_) foreach fs::get::hds($all_hds);
+ }
+ return if eval { Done($in, $all_hds) };
+ if (my $err = $@) {
+ $in->ask_warn(N("Error"), formatError($err));
}
- Done($in, $all_hds) or goto &main;
+ goto &main;
}
@@ -218,18 +268,8 @@ sub main {
# general actions
################################################################################
sub general_possible_actions {
- __("Undo"), ($::expert ? __("Toggle to normal mode") : __("Toggle to expert mode"));
-}
-
-
-sub Undo {
- my ($in, $all_hds) = @_;
- fsedit::undo($all_hds);
-}
-
-sub Wizard {
- $::o->{wizard} = 1;
- goto &Done;
+ my ($_in, $_all_hds) = @_;
+ if_($::isInstall, N_("More"));
}
sub Done {
@@ -237,20 +277,34 @@ sub Done {
eval { raid::verify($all_hds->{raids}) };
if (my $err = $@) {
$::expert or die;
- $in->ask_okcancel('', [ formatError($err), _("Continue anyway?")]) or return;
+ $in->ask_okcancel(N("Confirmation"), [ formatError($err), N("Continue anyway?") ]) or return;
}
foreach (@{$all_hds->{hds}}) {
- if (!write_partitions($in, $_)) {
+ if (!write_partitions($in, $_, 'skip_check_rebootNeeded')) {
return if !$::isStandalone;
- $in->ask_yesorno(_("Quit without saving"), _("Quit without writing the partition table?"), 1) or return;
+ $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('', _("Do you want to save /etc/fstab modifications"), 1)) {
+ if ($new ne $all_hds->{current_fstab} && $in->ask_yesorno(N("Confirmation"), N("Do you want to save the /etc/fstab modifications?"), 1)) {
$all_hds->{current_fstab} = $new;
fs::write_fstab($all_hds);
}
+ update_bootloader_for_renumbered_partitions($in, $all_hds);
+
+ if (any { $_->{rebootNeeded} } @{$all_hds->{hds}}) {
+ $in->ask_warn(N("Partitioning"), N("You need to reboot for the partition table modifications to take effect"));
+ tell_wm_and_reboot();
+ }
+ }
+ if (my $part = find { $_->{mntpoint} && !maybeFormatted($_) } fs::get::fstab($all_hds)) {
+ $in->ask_okcancel(N("Warning"), N("You should format partition %s.
+Otherwise no entry for mount point %s will be written in fstab.
+Quit anyway?", $part->{device}, $part->{mntpoint})) or return if $::isStandalone;
}
1;
}
@@ -258,220 +312,250 @@ sub Done {
################################################################################
# per-hd actions
################################################################################
+sub hd_possible_actions_base {
+ my ($hd) = @_;
+ (
+ if_(!$hd->{readonly} || $hd->{getting_rid_of_readonly_allowed}, N_("Clear all")),
+ if_(!$hd->{readonly} && $::isInstall, N_("Auto allocate")),
+ );
+}
+
+sub hd_possible_actions_extra {
+ my ($_hd) = @_;
+ $::expert ? N_("Normal mode") : N_("Expert mode");
+}
+
+
sub hd_possible_actions {
- my ($in, $hd, $all_hds) = @_;
- __("Clear all"), if_($::isInstall && !$hd->{readonly}, __("Auto allocate")), __("More");
+ my ($_in, $hd, $_all_hds) = @_;
+ hd_possible_actions_base($hd);
+ hd_possible_actions_extra($hd);
}
+
sub hd_possible_actions_interactive {
- my ($in, $hd, $all_hds) = @_;
- &hd_possible_actions, __("Hard drive information");
+ my ($_in, $_hd, $_all_hds) = @_;
+ &hd_possible_actions, N_("Hard disk drive information");
}
sub Clear_all {
my ($in, $hd, $all_hds) = @_;
-
+ return if detect_devices::is_xbox(); #- do not let them wipe the OS
my @parts = partition_table::get_normal_parts($hd);
foreach (@parts) {
RemoveFromLVM($in, $hd, $_, $all_hds) if isPartOfLVM($_);
RemoveFromRAID($in, $hd, $_, $all_hds) if isPartOfRAID($_);
+ RemoveFromDm($in, $hd, $_, $all_hds) if $_->{dm_active};
}
if (isLVM($hd)) {
- lvm::lv_delete($hd, $_) foreach @parts
+ lvm::lv_delete($hd, $_) foreach @parts;
} else {
- $hd->{readonly} = 0; #- give a way out of readonly-ness. Dangerous!
- partition_table::raw::zero_MBR_and_dirty($hd);
+ $hd->{readonly} = 0; #- give a way out of readonly-ness. only allowed when getting_rid_of_readonly_allowed
+ $hd->{getting_rid_of_readonly_allowed} = 0; #- we don't need this flag anymore
+ fsedit::partition_table_clear_and_initialize($all_hds->{lvms}, $hd, $in);
}
+ fsedit::init_mntpnt_suggestions($all_hds, $hd, 1);
}
sub Auto_allocate {
my ($in, $hd, $all_hds) = @_;
- my $suggestions = partitions_suggestions($in) or return;
+ my $suggestions = partitions_suggestions($in, $all_hds, $hd) or return;
my %all_hds_ = %$all_hds;
- $all_hds_{hds} = [ sort { $a == $hd ? -1 : 1 } @{$all_hds->{hds}} ];
+ $all_hds_{hds} = [ sort { $a == $hd ? -1 : 1 } fs::get::hds($all_hds) ];
- eval { fsedit::auto_allocate(\%all_hds_, $suggestions) };
+ eval { fsedit::auto_allocate(\%all_hds_, $suggestions, $hd) };
if ($@) {
$@ =~ /partition table already full/ or die;
- $in->ask_warn("", [
- _("All primary partitions are used"),
- _("I can't add any more partition"),
- _("To have more partitions, please delete one to be able to create an extended partition"),
+ $in->ask_warn("", [
+ N("All primary partitions are used"),
+ N("I cannot add any more partitions"),
+ N("To have more partitions, please delete one to be able to create an extended partition"),
]);
}
}
sub More {
- my ($in, $hd) = @_;
+ my ($in, $_hd) = @_;
- $in->ask_from('', '',
+ my $r;
+ $in->ask_from(N("More"), '',
[
- { val => _("Save partition table"), clicked_may_quit => sub { SaveInFile($in, $hd); 1 } },
- { val => _("Restore partition table"), clicked_may_quit => sub { ReadFromFile($in, $hd); 1 } },
- { val => _("Rescue partition table"), clicked_may_quit => sub { Rescuept($in, $hd); 1 } },
- if_($::isInstall,
- { val => _("Reload partition table"), clicked => sub {
- $::o->{all_hds} = fsedit::empty_all_hds();
- die "setstep doPartitionDisks\n" if $::setstep;
- } }),
- if_($::isInstall,
- { text => _("Removable media automounting"), val => \$::o->{useSupermount}, type => 'bool' },
- ),
+ { val => N("Reload partition table"), clicked_may_quit => sub { $r = 'force_reload'; 1 } },
],
- );
-}
-
-sub ReadFromFile {
- my ($in, $hd) = @_;
-
- my $file = $::isStandalone ? $in->ask_file(_("Select file")) : devices::make("fd0") or return;
-
- eval {
- catch_cdie { partition_table::load($hd, $file) }
- sub {
- $@ =~ /bad totalsectors/ or return;
- $in->ask_yesorno('',
-_("The backup partition table has not the same size
-Still continue?"), 0);
- };
- };
- if (my $err = $@) {
- $in->ask_warn(_("Error"), formatError($err));
- }
-}
-
-sub SaveInFile {
- my ($in, $hd) = @_;
-
- my $file = $::isStandalone ?
- $in->ask_file(_("Select file")) :
- $in->ask_okcancel(_("Warning"),
-_("Insert a floppy in drive
-All data on this floppy will be lost"), 1) && devices::make(detect_devices::floppy()) or return;
-
- eval { partition_table::save($hd, $file) };
- if (my $err = $@) {
- $in->ask_warn(_("Error"), formatError($err));
- }
-}
-
-sub Rescuept {
- my ($in, $hd) = @_;
- my $w = $in->wait_message('', _("Trying to rescue partition table"));
- fsedit::rescuept($hd);
+ ) && $r;
}
sub Hd_info {
my ($in, $hd) = @_;
- $in->ask_warn('', [ _("Detailed information"), format_hd_info($hd) ]);
+ $in->ask_warn(N("Warning"), [ N("Detailed information"), format_hd_info($hd) ]);
}
################################################################################
# per-part actions
################################################################################
+sub is_LVM_resizable {
+ my ($part) = @_;
+ member($part->{fs_type}, qw(btrfs ext3 ext4 nilfs2 reiserfs xfs));
+}
sub part_possible_actions {
- my ($in, $hd, $part, $all_hds) = @_;
+ my ($_in, $hd, $part, $all_hds) = @_;
$part or return;
my %actions = my @l = (
- __("Mount point") => '($part->{real_mntpoint} && common::usingRamdisk()) || (!isBusy && !isSwap && !isNonMountable)',
- __("Type") => '!isBusy && $::expert && (!readonly || ($part->{type} & 0xff) == 0x83)',
- __("Options") => '$::expert',
- __("Resize") => '!isBusy && !readonly && !isSpecial || isLVM($hd) && isMounted && isThisFs("xfs", $part)',
- __("Move") => '!isBusy && !readonly && !isSpecial && $::expert && 0', # disable for the moment
- __("Format") => '!isBusy && !readonly && ($::expert || $::isStandalone)',
- __("Mount") => '!isBusy && (hasMntpoint || isSwap) && maybeFormatted && ($::expert || $::isStandalone)',
- __("Add to RAID") => '!isBusy && isRawRAID && !isSpecial',
- __("Add to LVM") => '!isBusy && isRawLVM',
- __("Unmount") => '!$part->{real_mntpoint} && isMounted',
- __("Delete") => '!isBusy && !readonly',
- __("Remove from RAID") => 'isPartOfRAID',
- __("Remove from LVM") => 'isPartOfLVM',
- __("Modify RAID") => 'isPartOfRAID && !isMounted($all_hds->{raids}[$part->{raid}])',
- __("Use for loopback") => '!$part->{real_mntpoint} && isMountableRW && !isSpecial && hasMntpoint && $::expert',
+ 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 && fs::format::canEditLabel($part)',
+ N_("Resize") => '!isBusy && !readonly && !isSpecial || isLVM($hd) && is_LVM_resizable',
+ N_("Format") => '!isBusy && isFormatable && (!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',
+ N_("Use") => '!isBusy && fs::type::isRawLUKS($part) && !$part->{notFormatted}',
+ N_("Unmount") => '!$part->{real_mntpoint} && isMounted',
+ N_("Delete") => '!isBusy && !readonly',
+ N_("Remove from RAID") => 'isPartOfRAID',
+ N_("Remove from LVM") => 'isPartOfLVM',
+ N_("Remove from dm") => '$part->{dm_active}',
+ N_("Modify RAID") => 'canModifyRAID',
+ N_("Use for loopback") => '!$part->{real_mntpoint} && isMountableRW && !isSpecial && hasMntpoint && maybeFormatted && $::expert',
);
my ($actions_names) = list2kv(@l);
+ my $_all_hds = $all_hds; #- help perl_checker know the $all_hds *is* used in the macro below
my %macros = (
readonly => '$hd->{readonly}',
hasMntpoint => '$part->{mntpoint}',
- isPrimary => 'isPrimary($part, $hd)',
+ canModifyRAID => 'isPartOfRAID($part) && !isMounted(fs::get::device2part($part->{raid}, $all_hds->{raids}))',
);
- if ($part->{type} == 0) {
- if_(!$hd->{readonly}, __("Create"));
+ 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;
} else {
- grep {
+ grep {
my $cond = $actions{$_};
while (my ($k, $v) = each %macros) {
$cond =~ s/$k/qq(($v))/e;
}
$cond =~ s/(^|[^:\$]) \b ([a-z]\w{3,}) \b ($|[\s&\)])/$1 . $2 . '($part)' . $3/exg;
- eval $cond;
+ my $res = eval $cond;
+ if (my $err = $@) {
+ warn "ERROR: Bogus condition for '$actions{$_}': $err\n";
+ }
+ $res;
} @$actions_names;
}
}
+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 = $::isInstall;
+
sub Create {
my ($in, $hd, $part, $all_hds) = @_;
my ($def_start, $def_size, $max) = ($part->{start}, $part->{size}, $part->{start} + $part->{size});
$part->{maxsize} = $part->{size}; $part->{size} = 0;
- if (!fsedit::suggest_part($part, $all_hds)) {
+ if (fsedit::suggest_part($part, $all_hds)) {
+ $part->{mntpoint} = '' if !$do_suggest_mount_point;
+ } else {
$part->{size} = $part->{maxsize};
- $part->{type} ||= 0x483;
+ fs::type::suggest_fs_type($part, defaultFS());
+ }
+ if (isLVM($hd)) {
+ lvm::suggest_lv_name($hd, $part);
}
#- update adjustment for start and size, take into account the minimum partition size
#- including one less sector for start due to a capacity to increase the adjustement by
#- one.
my ($primaryOrExtended, $migrate_files);
- my $type = type2name($part->{type});
- my $mb_size = $part->{size} >> 11;
+ 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;
- my $w = $in->ask_from(_("Create a new partition"), '',
+ $in->ask_from(N("Create a new partition"), '',
[
+ { label => N("Create a new partition"), title => 1 },
if_($has_startsector,
- { label => _("Start sector: "), val => \$part->{start}, min => $def_start, max => ($max - min_partition_size($hd)), type => 'range' },
+ { 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 => _("Size in MB: "), val => \$mb_size, min => min_partition_size($hd) >> 11, max => $def_size >> 11, type => 'range' },
- { label => _("Filesystem type: "), val => \$type, list => [ partition_table::important_types() ], sort => 0 },
- { label => _("Mount point: "), val => \$part->{mntpoint}, list => [ fsedit::suggestions_mntpoint($all_hds), '' ],
- disabled => sub { my $p = { type => name2type($type) }; isSwap($p) || isNonMountable($p) }, type => 'combo', not_edit => 0,
+ { 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 => 2 }, do_not_ellipsize => 1) },
+ { label => N("Mount point: "), val => \$part->{mntpoint}, list => [ fsedit::suggestions_mntpoint($all_hds), '' ],
+ if_(isLVM($hd), changed => sub {
+ undef $part->{lv_name};
+ lvm::suggest_lv_name($hd, $part);
+ }), type => 'combo', not_edit => 0,
+ disabled => sub { my $p = fs::type::type_name2subpart($type_name); isSwap($p) || isNonMountable($p) }, type => 'combo', not_edit => 0,
},
if_($::expert && $hd->hasExtended,
- { label => _("Preference: "), val => \$primaryOrExtended, list => [ '', "Extended", "Primary", if_($::expert, "Extended_0x85") ] },
+ { label => N("Preference: "), val => \$primaryOrExtended, list => [ '', "Extended", "Primary", if_($::expert, "Extended_0x85") ] },
),
- ], changed => sub {
- if ($part->{start} + ($mb_size << 11) > $max) {
- if ($_[0] == 0) {
- # Start sector changed => restricting Size
- $mb_size = ($max - $part->{start}) >> 11;
- } else {
- # Size changed => restricting Start sector
- $part->{start} = $max - ($mb_size << 11);
- }
- }
- }, complete => sub {
+ if_(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, disabled => sub { $part->{mntpoint} eq "/boot" } },
+ { 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
- $part->{type} = name2type($type);
+ $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::set_default_options($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;
- eval { fsedit::add($hd, $part, $all_hds, { force => 1, primaryOrExtended => $primaryOrExtended }) };
+ my $seen;
+ eval {
+ catch_cdie { fsedit::add($hd, $part, $all_hds, { force => 1, primaryOrExtended => $primaryOrExtended }) }
+ sub { $seen = 1; $in->ask_okcancel('', formatError($@)) };
+ };
if (my $err = $@) {
if ($err =~ /raw_add/ && $hd->hasExtended && !$hd->{primary}{extended}) {
- $in->ask_warn(_("Error"), _("You can't create a new partition
+ $in->ask_warn(N("Error"), N("You cannot create a new partition
(since you reached the maximal number of primary partitions).
First remove a primary partition and create an extended partition."));
return 0;
} else {
- $in->ask_warn(_("Error"), $@);
+ $in->ask_warn(N("Error"), formatError($err)) if !$seen;
return 1;
}
}
@@ -479,24 +563,46 @@ 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");
+ }
+ _format_raw($in, $p, $all_hds, 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);
+ fs::mount::part($part);
}
}
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)) {
lvm::lv_delete($hd, $part);
} elsif (isLoopback($part)) {
my $f = "$part->{loopback_device}{mntpoint}$part->{loopback_file}";
- if (-e $f && $in->ask_yesorno('', _("Remove the loopback file?"))) {
+ if (-e $f && $in->ask_yesorno(N("Warning"), N("Remove the loopback file?"))) {
unlink $f;
}
my $l = $part->{loopback_device}{loopback};
@@ -504,9 +610,6 @@ sub Delete {
delete $part->{loopback_device}{loopback} if @$l == 0;
fsedit::recompute_loopbacks($all_hds);
} else {
- if (arch() =~ /ppc/) {
- undef $partition_table::mac::bootstrap_part if (isAppleBootstrap($part) && ($part->{device} = $partition_table::mac::bootstrap_part));
- }
partition_table::remove($hd, $part);
warn_if_renumbered($in, $hd);
}
@@ -515,42 +618,87 @@ sub Delete {
sub Type {
my ($in, $hd, $part) = @_;
- my $warn = sub { ask_alldatawillbelost($in, $part, __("After changing type of partition %s, all data on this partition will be lost")) };
+ my $warned;
+ 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 :)
- isExt2($part) 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 = partition_table::important_types();
+ my @types = fs::type::type_names($::expert, $hd);
- #- when readonly, Type() is allowed only when changing between various { 0x83, 0x183, ... }
- @types = grep { (name2type($_) & 0xff) == 0x83 } @types if $hd->{readonly};
+ #- when readonly, Type() is allowed only when changing {fs_type} but not {pt_type}
+ #- eg: switching between ext2, ext3, ext4, reiserfs...
+ @types = grep { fs::type::type_name2pt_type($_) == $part->{pt_type} } @types if $hd->{readonly};
- my $type_name = type2name($part->{type});
- $in->ask_from(_("Change partition type"),
- _("Which filesystem do you want?"),
- [ { label => _("Type"), val => \$type_name, list => \@types, sort => 0, not_edit => !$::expert } ]) or return;
+ 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, 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 && name2type($type_name);
+ my $type = $type_name && fs::type::type_name2subpart($type_name);
- if (isExt2($part) && isThisFs('ext3', { type => $type })) {
- my $w = $in->wait_message('', _("Switching from ext2 to ext3"));
+ 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}))) {
- $part->{type} = $type;
- $part->{isFormatted} = 1; #- assume that if tune2fs works, partition is formatted
+ put_in_hash($part, $type);
+ set_isFormatted($part, 1); #- assume that if tune2fs works, partition is formatted
- #- disable the fsck (don't do it together with -j in case -j fails?)
- fs::disable_forced_fsck($part->{device});
+ #- disable the fsck (do not do it together with -j in case -j fails?)
+ 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);
+ return;
}
#- either we switch to non-ext3 or switching losslessly to ext3 failed
- !isExt2($part) or $warn->() or return;
+ $warned or $warn->() or return;
if (defined $type) {
check_type($in, $type, $hd, $part) and fsedit::change_type($type, $hd, $part);
}
}
+sub Label {
+ my ($in, $hd, $part) = @_;
+ 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 => \$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 {
my ($in, $hd, $part, $all_hds) = @_;
@@ -558,31 +706,35 @@ sub Mount_point {
my $mntpoint = $part->{mntpoint} || do {
my $part_ = { %$part };
if (fsedit::suggest_part($part_, $all_hds)) {
- fsedit::has_mntpoint('/', $all_hds) || $part_->{mntpoint} eq '/boot' ? $part_->{mntpoint} : '/';
+ fs::get::has_mntpoint('/', $all_hds) || $part_->{mntpoint} eq '/boot' ? $part_->{mntpoint} : '/';
} else { '' }
};
- $in->ask_from(
- '',
- isLoopback($part) ? _("Where do you want to mount loopback file %s?", $part->{loopback_file}) :
- _("Where do you want to mount device %s?", $part->{device}),
- [ { label => _("Mount point"), val => \$mntpoint,
- list => [ if_($mntpoint, $mntpoint), fsedit::suggestions_mntpoint($all_hds), '' ],
- not_edit => 0 } ],
- complete => sub {
- !isPartOfLoopback($part) || $mntpoint or $in->ask_warn('',
-_("Can't unset mount point as this partition is used for loop back.
+ my $msg = isLoopback($part) ? N("Where do you want to mount the loopback file %s?", $part->{loopback_file}) :
+ N("Where do you want to mount device %s?", $part->{device});
+ $in->ask_from_({
+ callbacks => {
+ complete => sub {
+ !isPartOfLoopback($part) || $mntpoint or $in->ask_warn(N("Error"),
+N("Cannot 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, $hd, $part, $all_hds) or return 1;
+ $part->{mntpoint} eq $mntpoint || check_mntpoint($in, $mntpoint, $part, $all_hds) or return 1;
$migrate_files = need_migration($in, $mntpoint) or return 1;
0;
- }
+ } },
+ },
+ [
+ { label => $msg, title => 1 },
+ { label => N("Mount point"), val => \$mntpoint,
+ list => [ uniq(if_($mntpoint, $mntpoint), fsedit::suggestions_mntpoint($all_hds), '') ],
+ focus => sub { 1 },
+ not_edit => 0 } ],
) or return;
$part->{mntpoint} = $mntpoint;
if ($migrate_files eq 'migrate') {
format_($in, $hd, $part, $all_hds) or return;
migrate_files($in, $hd, $part);
- fs::mount_part($part);
+ fs::mount::part($part);
}
}
sub Mount_point_raw_hd {
@@ -590,77 +742,126 @@ sub Mount_point_raw_hd {
my $mntpoint = $part->{mntpoint} || shift @propositions;
$in->ask_from(
+ N("Mount point"),
'',
- _("Where do you want to mount %s?", $part->{device}),
- [ { label => _("Mount point"), val => \$mntpoint,
- list => [ if_($mntpoint, $mntpoint), '', @propositions ],
+ [
+ { label => N("Where do you want to mount %s?", $part->{device}), title => 1 },
+ { 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;
+ $part->{mntpoint} eq $mntpoint || check_mntpoint($in, $mntpoint, $part, $all_hds) or return 1;
0;
}
) or return;
$part->{mntpoint} = $mntpoint;
}
+#- side-effects: mounts the fs
+sub _get_dir_for_online_resize {
+ my ($part) = @_;
+ my $dir = "/tmp/tmp_resize_" . $part->{fs_type} . ".$$";
+ if ($part->{isMounted}) {
+ $dir = ($::prefix || '') . $part->{mntpoint};
+ } else {
+ mkdir_p($dir);
+ fs::mount::mount(devices::make($part->{device}), $dir, $part->{fs_type});
+ }
+ return $dir;
+}
+
+sub _set_min_size_from_avail_space {
+ my ($part, $min) = @_;
+ if (defined(my $free = fs::df($part))) {
+ $$min = max($$min, $part->{size} - $free);
+ }
+}
+
sub Resize {
my ($in, $hd, $part) = @_;
- my (%nice_resize, $block_count, $free_block, $block_size);
- my ($min, $max) = (min_partition_size($hd), partition_table::next_start($hd, $part) - $part->{start});
+ my (%nice_resize, $online_resize);
+ 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
# -> doing as if it was formatted
- if (isFat($part)) {
+ if ($part->{fs_type} eq 'vfat') {
write_partitions($in, $hd) or return;
#- try to resize without losing data
- my $w = $in->wait_message(_("Resizing"), _("Computing FAT filesystem bounds"));
+ my $_w = $in->wait_message(N("Resizing"), N("Computing FAT filesystem bounds"));
+ 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 (isExt2($part) || isThisFs('ext3', $part)) {
+ $max = min($max, $nice_resize{fat}->max_size);
+ } elsif (member($part->{fs_type}, qw(ext2 ext3 ext4))) {
write_partitions($in, $hd) or return;
- $nice_resize{ext2} = devices::make($part->{device});
- my $r = `dumpe2fs $nice_resize{ext2} 2>/dev/null`;
- $r =~ /Block count:\s*(\d+)/ and $block_count = $1;
- $r =~ /Free blocks:\s*(\d+)/ and $free_block = $1;
- $r =~ /Block size:\s*(\d+)/ and $block_size = $1;
- log::l("dumpe2fs $nice_resize{ext2} gives: Block_count=$block_count, Free_blocks=$free_block, Block_size=$block_size");
- if ($block_count && $free_block && $block_size) {
- $min = max($min, ($block_count - $free_block) * $block_size / 512);
- $max = min($max, $block_count * $block_size / 512);
+ require diskdrake::resize_ext2;
+ if ($nice_resize{ext2} = diskdrake::resize_ext2->new($part->{device}, devices::make($part->{device}))) {
+ $min = max($min, $nice_resize{ext2}->min_size);
} else {
delete $nice_resize{ext2};
}
- } elsif (isThisFs("reiserfs", $part)) {
+ } elsif ($part->{fs_type} eq 'f2fs') {
+ $min = $part->{size}; #- ensure the user can only increase
+ $nice_resize{f2fs} = 1;
+ } elsif ($part->{fs_type} =~ /ntfs/) {
write_partitions($in, $hd) or return;
- if (defined (my $free = fs::df($part))) {
- $nice_resize{reiserfs} = 1;
- $min = max($min, $part->{size} - $free);
+ require diskdrake::resize_ntfs;
+ diskdrake::resize_ntfs::check_prog($in) or return;
+ $nice_resize{ntfs} = diskdrake::resize_ntfs->new($part->{device}, devices::make($part->{device}));
+ $min = $nice_resize{ntfs}->min_size or delete $nice_resize{ntfs};
+ } elsif ($part->{fs_type} eq 'reiserfs') {
+ write_partitions($in, $hd) or return;
+ $nice_resize{reiserfs} = 1;
+ if ($part->{isMounted}) {
+ $min = $part->{size}; #- ensure the user can only increase
+ } else {
+ _set_min_size_from_avail_space($part, \$min);
}
- } elsif (isThisFs('xfs', $part) && isLVM($hd) && $::isStandalone && isMounted($part)) {
+ } elsif ($part->{fs_type} eq 'xfs') {
$min = $part->{size}; #- ensure the user can only increase
- $nice_resize{xfs} = 1;
+ $online_resize = $part->{fs_type};
+ } elsif (member($part->{fs_type}, qw(btrfs nilfs2))) {
+ $online_resize = $part->{fs_type};
+ }
+
+ # Btrf, nilfs2 && XFS only support online resizing
+ # (Ext3/4 too but we can resize it offline so we don't care - though growing online is interesting)
+ if ($online_resize) {
+ write_partitions($in, $hd) or return;
+ $nice_resize{$online_resize} = 1;
+ _set_min_size_from_avail_space($part, \$min);
}
+
#- 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).
$min += partition_table::raw::cylinder_size($hd);
- $min >= $max and return $in->ask_warn('', _("This partition is not resizeable"));
+ $min >= $max and return $in->ask_warn(N("Warning"), N("This partition is not resizeable"));
#- for these, we have tools to resize partition table
#- without losing data (or at least we hope so :-)
if (%nice_resize) {
- ask_alldatamaybelost($in, $part, __("All data on this partition should be backed-up")) or return;
+ ask_alldatamaybelost($in, $part, N_("All data on this partition should be backed up")) or return;
} else {
- ask_alldatawillbelost($in, $part, __("After resizing partition %s, all data on this partition will be lost")) or return;
+ ask_alldatawillbelost($in, $part, N_("After resizing partition %s, all data on this partition will be lost")) or return;
}
}
- my $mb_size = $part->{size} >> 11;
- $in->ask_from(_("Resize"), _("Choose the new size"), [
- { label => _("New size in MB: "), val => \$mb_size, min => $min >> 11, max => $max >> 11, type => 'range' },
+ my $mb_size = to_Mb($part->{size});
+ my ($gmin, $gmax) = (to_Mb($min), to_Mb($max));
+ $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) },
+ { label => N("Maximum size: %s MB", $gmax) },
]) or return;
@@ -668,159 +869,261 @@ sub Resize {
$part->{size} == $size and return;
my $oldsize = $part->{size};
- $hd->{isDirty} = $hd->{needKernelReread} = 1;
- $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 };
- my $w = $in->wait_message(_("Resizing"), '');
+ my $_b = before_leaving { $@ and $part->{size} = $oldsize };
- if (isLVM($hd)) {
- lvm::lv_resize($part, $oldsize) if $size > $oldsize;
- }
+ my $adjust = sub {
+ my ($write_partitions) = @_;
+
+ if (isLVM($hd)) {
+ lvm::lv_resize($low_part, $oldsize);
+ } else {
+ 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 || isLUKS($part));
+ if ($write_partitions && isLUKS($part)) {
+ require fs::dmcrypt;
+ fs::dmcrypt::open_part([], $low_part);
+ }
+ }
+ 1;
+ };
+
+ $adjust->(1) or return if $size > $oldsize;
+
+ my $wait = $in->wait_message(N("Please wait"), N("Resizing"));
if ($nice_resize{fat}) {
- local *log::l = sub { $w->set(join(' ', @_)) };
+ local *log::l = sub { $wait->set(join(' ', @_)) };
$nice_resize{fat}->resize($part->{size});
} elsif ($nice_resize{ext2}) {
- my $s = int(($part->{size} << 9) / $block_size);
- log::l("resize2fs $nice_resize{ext2} to size $s in block of $block_size bytes");
- run_program::run("resize2fs", "-pf", $nice_resize{ext2}, $s);
+ $nice_resize{ext2}->resize($part->{size});
+ } elsif ($nice_resize{ntfs}) {
+ 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),
+filesystem checks will be run on your next boot into Microsoft Windows®"));
} elsif ($nice_resize{reiserfs}) {
log::l("reiser resize to $part->{size} sectors");
- run_program::run("resize_reiserfs", "-f", "-q", "-s" . $part->{size}/2 . "K", devices::make($part->{device}));
- } elsif ($nice_resize{xfs}) {
- #- happens only with mounted LVM, see above
- run_program::run("xfs_growfs", $part->{mntpoint});
+ run_program::run_or_die('resize_reiserfs', '-f', '-q', '-s' . int($part->{size}/2) . 'K', devices::make($part->{device}));
+ } elsif ($online_resize) {
+ my $dir = _get_dir_for_online_resize($part);
+ my @cmd;
+ if ($nice_resize{btrfs}) {
+ # FIXME: only works for a FS on a single device. Multi-device FS would need to specify the device to enlarge
+ @cmd = (qw(btrfs filesystem resize), $part->{size}*512, $dir);
+ } elsif ($nice_resize{nilfs2}) {
+ @cmd = ('nilfs-resize', devices::make($part->{device}), $part->{size}*512);
+ } elsif ($nice_resize{xfs}) {
+ @cmd = ("xfs_growfs", $dir);
+ } else {
+ die("I don't know how to proceed");
+ }
+ if (!run_program::run(@cmd)) {
+ $nice_resize{$part->{fs_type}} = undef;
+ }
+ # umount after online resize if it was mounted on demand:
+ if (!$part->{isMounted}) {
+ fs::mount::umount($dir);
+ unlink($dir);
+ }
+ } elsif ($nice_resize{f2fs}) {
+ run_program::run_or_die("resize.f2fs", devices::make($part->{device}));
}
if (%nice_resize) {
- $part->{isFormatted} = 1;
+ set_isFormatted($part, 1);
} else {
- $part->{notFormatted} = 1;
- $part->{isFormatted} = 0;
- partition_table::verifyParts($hd);
+ set_isFormatted($part, 0);
+ partition_table::verifyParts($hd) if !isLVM($hd);
+ $part->{mntpoint} = '' if isNonMountable($part); #- mainly for ntfs, which we cannot format
}
- if (isLVM($hd)) {
- lvm::lv_resize($part, $oldsize) if $size < $oldsize;
- } else {
- partition_table::adjust_local_extended($hd, $part);
- partition_table::adjust_main_extended($hd);
- }
+ $adjust->(0) if $size < $oldsize;
}
-sub Move {
- my ($in, $hd, $part, $all_hds) = @_;
- my $hd2 = $in->ask_from_listf(_("Move"),
- _("Which disk do you want to move it to?"), \&partition_table::description, @{$all_hds->{hds}}) or return;
- my $start2 = $in->ask_from_entry(_("Sector"),
- _("Which sector do you want to move it to?"));
- defined $start2 or return;
- my $w = $in->wait_message(_("Moving"), _("Moving partition..."));
- fsedit::move($hd, $part, $hd2, $start2);
-}
sub Format {
my ($in, $hd, $part, $all_hds) = @_;
format_($in, $hd, $part, $all_hds);
}
sub Mount {
my ($in, $hd, $part) = @_;
+
+ ensure_we_have_encrypt_key_if_needed($in, $part) or return;
write_partitions($in, $hd) or return;
- fs::mount_part($part);
+
+ my $w;
+ fs::mount::part($part, 0, sub {
+ my ($msg) = @_;
+ $w ||= $in->wait_message(N("Please wait"), $msg);
+ $w->set($msg);
+ });
}
+
+sub dmcrypt_open {
+ my ($in, $_hd, $part, $all_hds) = @_;
+ $part->{dm_name} ||= do {
+ my $s = $part->{device};
+ $s =~ s/\W/_/g;
+ "crypt_$s";
+ };
+
+ if (!$part->{dmcrypt_key}) {
+ $in->ask_from_({
+ title => N("Filesystem encryption key"),
+ messages => N("Enter your filesystem encryption key"),
+ }, [ { label => N("Encryption key"), val => \$part->{dmcrypt_key},
+ hidden => 1, focus => sub { 1 } } ]) or return;
+ }
+
+ eval { require fs::dmcrypt; fs::dmcrypt::open_part($all_hds->{dmcrypts}, $part) };
+ if ($@) {
+ delete $part->{dmcrypt_key};
+ die(($? >> 8) == 255 ? N("Invalid key") : $@);
+ }
+ detect_lvms_on_dmcrypt($all_hds);
+}
+
+# Detect LVMs on top of dmcrypt
+sub detect_lvms_on_dmcrypt {
+ my ($all_hds) = @_,
+ require File::Temp;
+ require fs::dmcrypt;
+ my (undef, $tmp_file) = File::Temp::mkstemp('/tmp/crypttab.XXXXXXX');
+ fs::dmcrypt::save_crypttab_($all_hds, $tmp_file);
+ require lvm;
+ lvm::detect_during_install();
+ $all_hds->{lvms} = [ fsedit::lvms($all_hds) ];
+ fs::dmcrypt::read_crypttab_($all_hds, $tmp_file);
+ rm_rf($tmp_file);
+}
+
sub Add2RAID {
- my ($in, $hd, $part, $all_hds) = @_;
+ my ($in, $_hd, $part, $all_hds) = @_;
my $raids = $all_hds->{raids};
- local $_ = @$raids == () ? "new" :
- $in->ask_from_list_('', _("Choose an existing RAID to add to"),
- [ (grep { $_ } map_index { $_ && "md$::i" } @$raids), __("new") ]) or return;
+ my $md_part = $in->ask_from_listf(N("Add to RAID"), N("Choose an existing RAID to add to"),
+ sub { ref($_[0]) ? $_[0]{device} : $_[0] },
+ [ @$raids, N_("new") ]) or return;
- if (/new/) {
- my $nb1 = raid::new($raids, $part);
- defined modifyRAID($in, $raids, $nb1) or return raid::delete($raids, $nb1);
+ if (ref($md_part)) {
+ raid::add($md_part, $part);
+ raid::write_conf($raids) if $::isStandalone;
} else {
- raid::add($raids, $part, $_);
+ raid::check_prog($in) or return;
+ my $md_part = raid::new($raids, disks => [ $part ]);
+ modifyRAID($in, $raids, $md_part) or return raid::delete($raids, $md_part);
}
- raid::update(@$raids);
}
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_('', _("Choose an existing LVM to add to"),
- sub { ref $_[0] ? $_[0]{VG_name} : $_[0] },
- [ @$lvms, __("new") ]) or return;
+ my $lvm = $in->ask_from_listf_(N("Add to LVM"), N("Choose an existing LVM to add to"),
+ sub { ref($_[0]) ? $_[0]{VG_name} : $_[0] },
+ [ @$lvms, N_("new") ]) or return;
+ require lvm;
if (!ref $lvm) {
# create new lvm
- my $name = $in->ask_from_entry('', _("LVM name?")) or return;
- $name =~ s/\W/_/g;
- $name = substr($name, 0, 63); # max length must be < NAME_LEN / 2 where NAME_LEN is 128
- $lvm = bless { disks => [], VG_name => $name }, 'lvm';
+ my $n; my $str = "vg-mga";
+ while (member("$str$n", @lvm_names)) {
+ $n++;
+ }
+
+ my $name = "$str$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;
}
+ my $_w = $in->wait_message(N("Please wait"), N("Setting up LVM"));
raid::make($all_hds->{raids}, $part) if isRAID($part);
- $part->{lvm} = $lvm->{VG_name};
- push @{$lvm->{disks}}, $part;
- delete $part->{mntpoint};
-
- require lvm;
- lvm::check($in) if $::isStandalone;
- lvm::vg_add($part);
- lvm::update_size($lvm);
+ lvm::check($in->do_pkgs) if $::isStandalone;
+ lvm::add_to_VG($part, $lvm);
}
sub Unmount {
- my ($in, $hd, $part) = @_;
- fs::umount_part($part);
+ my ($_in, $_hd, $part) = @_;
+ fs::mount::umount_part($part);
}
-sub RemoveFromRAID {
- my ($in, $hd, $part, $all_hds) = @_;
+sub RemoveFromRAID {
+ my ($_in, $_hd, $part, $all_hds) = @_;
raid::removeDisk($all_hds->{raids}, $part);
}
+sub RemoveFromDm {
+ my ($_in, $_hd, $part, $all_hds) = @_;
+ require fs::dmcrypt;
+ fs::dmcrypt::close_part($all_hds->{dmcrypts}, $part);
+}
sub RemoveFromLVM {
- my ($in, $hd, $part, $all_hds) = @_;
- my $lvms = $all_hds->{lvms};
+ my ($in, $_hd, $part, $all_hds) = @_;
isPartOfLVM($part) or die;
- my ($lvm) = grep { $_->{VG_name} eq $part->{lvm} } @$lvms;
- lvm::vg_destroy($lvm);
- @$lvms = grep { $_ != $lvm } @$lvms;
+ my ($lvm, $other_lvms) = partition { $_->{VG_name} eq $part->{lvm} } @{$all_hds->{lvms}};
+ if (@{$lvm->[0]{disks}} > 1) {
+ my ($used, $_total) = lvm::pv_physical_extents($part);
+ if ($used) {
+ $in->ask_yesorno(N("Warning"), N("Physical volume %s is still in use.
+Do you want to move used physical extents on this volume to other volumes?", $part->{device})) or return;
+ my $_w = $in->wait_message(N("Please wait"), N("Moving physical extents"));
+ lvm::pv_move($part);
+ }
+ lvm::vg_reduce($lvm->[0], $part);
+ } else {
+ lvm::vg_destroy($lvm->[0]);
+ $all_hds->{lvms} = $other_lvms;
+ }
}
-sub ModifyRAID {
- my ($in, $hd, $part, $all_hds) = @_;
- modifyRAID($in, $all_hds->{raids}, $part->{raid});
+sub ModifyRAID {
+ my ($in, $_hd, $part, $all_hds) = @_;
+ modifyRAID($in, $all_hds->{raids}, fs::get::device2part($part->{raid}, $all_hds->{raids}));
}
sub Loopback {
my ($in, $hd, $real_part, $all_hds) = @_;
write_partitions($in, $hd) or return;
- my $handle = any::inspect($real_part) or $in->ask_warn('', _("This partition can't be used for loopback")), return;
+ my $handle = any::inspect($real_part) or $in->ask_warn(N("Error"), N("This partition cannot be used for loopback")), return;
- my ($min, $max) = (1, loopback::getFree($handle->{dir}, $real_part));
- $max = max($max, 1 << (31 - 9)) if isFat($real_part); #- FAT doesn't handle file size bigger than 2GB
+ my ($min, $max) = (1, fs::loopback::getFree($handle->{dir}, $real_part));
+ $max = min($max, 1 << (31 - 9)) if $real_part->{fs_type} eq 'vfat'; #- FAT does not handle file size bigger than 2GB
my $part = { maxsize => $max, size => 0, loopback_device => $real_part, notFormatted => 1 };
if (!fsedit::suggest_part($part, $all_hds)) {
$part->{size} = $part->{maxsize};
- $part->{type} ||= 0x483;
+ fs::type::suggest_fs_type($part, defaultFS());
}
- delete $part->{mntpoint}; # we don't want the suggested mntpoint
-
- my $type = type2name($part->{type});
- my $mb_size = $part->{size} >> 11;
- $in->ask_from(_("Loopback"), '', [
- { label => _("Loopback file name: "), val => \$part->{loopback_file} },
- { label => _("Size in MB: "), val => \$mb_size, min => $min >> 11, max => $max >> 11, type => 'range' },
- { label => _("Filesystem type: "), val => \$type, list => [ partition_table::important_types() ], not_edit => !$::expert, sort => 0 },
+ delete $part->{mntpoint}; # we do not want the suggested mntpoint
+
+ my $type_name = fs::type::part2type_name($part);
+ my $mb_size = to_Mb($part->{size});
+ $in->ask_from(N("Loopback"), '', [
+ { label => N("Loopback file name: "), val => \$part->{loopback_file} },
+ { label => N("Size in MB: "), val => \$mb_size, min => to_Mb($min), max => to_Mb($max), type => 'range', SpinButton => $::expert },
+ { label => N("Filesystem type: "), val => \$type_name, list => [ fs::type::type_names($::expert, $hd) ], not_edit => !$::expert, sort => 0 },
],
complete => sub {
- $part->{loopback_file} or $in->ask_warn('', _("Give a file name")), return 1, 0;
+ $part->{loopback_file} or $in->ask_warn(N("Give a file name"), N("Give a file name")), return 1, 0;
$part->{loopback_file} =~ s|^([^/])|/$1|;
- if (my $size = loopback::verifFile($handle->{dir}, $part->{loopback_file}, $real_part)) {
- $size == -1 and $in->ask_warn('', _("File already used by another loopback, choose another one")), return 1, 0;
- $in->ask_yesorno('', _("File already exists. Use it?")) or return 1, 0;
+ if (my $size = fs::loopback::verifFile($handle->{dir}, $part->{loopback_file}, $real_part)) {
+ $size == -1 and $in->ask_warn(N("Warning"), N("File is already used by another loopback, choose another one")), return 1, 0;
+ $in->ask_yesorno(N("Warning"), N("File already exists. Use it?")) or return 1, 0;
delete $part->{notFormatted};
$part->{size} = divide($size, 512);
} else {
@@ -828,75 +1131,69 @@ sub Loopback {
}
0;
}) or return;
- $part->{type} = name2type($type);
+ put_in_hash($part, fs::type::type_name2subpart($type_name));
push @{$real_part->{loopback}}, $part;
fsedit::recompute_loopbacks($all_hds);
}
sub Options {
- my ($in, $hd, $part, $all_hds) = @_;
+ my ($in, $_hd, $part, $_all_hds) = @_;
- my @simple_options = qw(user noauto supermount);
+ my @simple_options = qw(users noauto username= password=);
- my (undef, $user_implies) = fs::mount_options();
- my ($options, $unknown) = fs::mount_options_unpack($part);
- my %help = fs::mount_options_help(keys %$options);
+ my (undef, $user_implies) = fs::mount_options::list();
+ my ($options, $unknown) = fs::mount_options::unpack($part);
+ my %help = fs::mount_options::help();
- my $prev_user = $options->{user};
- $in->ask_from(_("Mount options"),
+ my %callbacks = (
+ # we don't want both user and users
+ user => sub { $options->{users} = 0; $options->{$_} = $options->{user} foreach @$user_implies },
+ users => sub { $options->{user} = 0; $options->{$_} = $options->{users} foreach @$user_implies },
+ # we don't want both relatime and noatime
+ relatime => sub { $options->{noatime} = 0 },
+ noatime => sub { $options->{relatime} = 0 },
+ );
+
+
+ $in->ask_from(N("Mount options"),
'',
- [
- (map {
- { label => $_, text => scalar warp_text(formatAlaTeX($help{$_})), val => \$options->{$_},
- advanced => !$part->{rootDevice} && !member($_, @simple_options), if_(!/=$/, type => 'bool'), }
+ [
+ { label => N("Mount options"), title => 1 },
+ (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{$_}),
+ };
} keys %$options),
- { label => _("Various"), val => \$unknown, advanced => 1 },
+ { label => N("Various"), val => \$unknown, advanced => 1 },
],
- changed => sub {
- if ($prev_user != $options->{user}) {
- $prev_user = $options->{user};
- $options->{$_} = $options->{user} foreach @$user_implies;
+ complete => sub {
+ 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 = choose_encrypt_key($in)) {
- $options->{'encryption='} = 'AES128';
- $part->{encrypt_key} = $encrypt_key;
- } else {
- $options->{encrypted} = 0;
- }
- }
- } else {
- delete $options->{'encryption='};
- delete $part->{encrypt_key};
- }
- },
- ) or return;
+ }) or return;
- fs::mount_options_pack($part, $options, $unknown);
+ fs::mount_options::pack($part, $options, $unknown);
1;
}
-{
- no strict;
- *{"Toggle to normal mode"} = sub { $::expert = 0 };
- *{"Toggle to expert mode"} = sub { $::expert = 1 };
- *{"Clear all"} = *Clear_all;
- *{"Auto allocate"} = *Auto_allocate;
- *{"Mount point"} = *Mount_point;
- *{"Modify RAID"} = *ModifyRAID;
- *{"Add to RAID"} = *Add2RAID;
- *{"Remove from RAID"} = *RemoveFromRAID;
- *{"Add to LVM"} = *Add2LVM;
- *{"Remove from LVM"} = *RemoveFromLVM;
- *{"Use for loopback"} = *Loopback;
- *{"Hard drive information"} = *Hd_info;
+{
+ no strict;
+ *{'Normal mode'} = sub() { $::expert = 0 };
+ *{'Expert mode'} = sub() { $::expert = 1 };
+ *{'Clear all'} = \&Clear_all;
+ *{'Auto allocate'} = \&Auto_allocate;
+ *{'Mount point'} = \&Mount_point;
+ *{'Modify RAID'} = \&ModifyRAID;
+ *{'Add to RAID'} = \&Add2RAID;
+ *{'Remove from RAID'} = \&RemoveFromRAID;
+ *{Use} = \&dmcrypt_open;
+ *{'Remove from dm'} = \&RemoveFromDm;
+ *{'Add to LVM'} = \&Add2LVM;
+ *{'Remove from LVM'} = \&RemoveFromLVM;
+ *{'Use for loopback'} = \&Loopback;
+ *{'Hard disk drive information'} = \&Hd_info;
}
@@ -906,21 +1203,23 @@ sub Options {
sub is_part_existing {
my ($part, $all_hds) = @_;
- $part && grep { fsedit::is_same_part($part, $_) } fsedit::get_all_fstab_and_holes($all_hds);
+ $part && any { fsedit::are_same_partitions($part, $_) } fs::get::fstab_and_holes($all_hds);
}
sub modifyRAID {
- my ($in, $raids, $nb) = @_;
- my $md = "md$nb";
- $in->ask_from('', '',
+ my ($in, $raids, $md_part) = @_;
+ my $new_device = $md_part->{device};
+ $in->ask_from(N("Options"), '',
[
-{ label => _("device"), val => \$md, list => [ map { "md$_" } grep { $nb == $_ || !$raids->[$_] } 0..8 ] },
-{ label => _("level"), val => \$raids->[$nb]{level}, list => [ qw(0 1 4 5 linear) ] },
-{ label => _("chunk size"), val => \$raids->[$nb]{'chunk-size'} },
+{ 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 10 linear) ] },
+{ label => N("chunk size in KiB"), val => \$md_part->{'chunk-size'} },
],
) or return;
- raid::updateSize($raids->[$nb]); # changing the raid level changes the size available
- raid::changeNb($raids, $nb, first($md =~ /(\d+)/));
+ raid::change_device($md_part, $new_device);
+ raid::updateSize($md_part); # changing the raid level changes the size available
+ raid::write_conf($raids) if $::isStandalone;
+ 1;
}
@@ -931,7 +1230,8 @@ sub ask_alldatamaybelost {
#- here we may have a non-formatted or a formatted partition
#- -> doing as if it was formatted
- $in->ask_okcancel(_("Read carefully!"), [ _("Be careful: this operation is dangerous."), _($msg, $part->{device}) ], 1);
+ $in->ask_okcancel(N("Read carefully"),
+ [ N("Be careful: this operation is dangerous."), sprintf(translate($msg), $part->{device}) ], 1);
}
sub ask_alldatawillbelost {
my ($in, $part, $msg) = @_;
@@ -940,93 +1240,112 @@ sub ask_alldatawillbelost {
#- here we may have a non-formatted or a formatted partition
#- -> doing as if it was formatted
- $in->ask_okcancel(_("Read carefully!"), _($msg, $part->{device}), 1);
+ $in->ask_okcancel(N("Read carefully"), sprintf(translate($msg), $part->{device}), 1);
}
sub partitions_suggestions {
- my ($in) = @_;
- my $t = $::expert ?
- $in->ask_from_list_('', _("What type of partitioning?"), [ keys %fsedit::suggestions ]) :
+ my ($in, $all_hds, $hd) = @_;
+ fsedit::init_mntpnt_suggestions($all_hds, $hd);
+ my $t = $::expert ?
+ $in->ask_from_list_(N("Partitioning Type"), N("What type of partitioning?"), [ keys %fsedit::suggestions ]) :
'simple';
$fsedit::suggestions{$t};
}
sub check_type {
my ($in, $type, $hd, $part) = @_;
- eval { fsedit::check_type($type, $hd, $part) };
+ eval { fs::type::check($type->{fs_type}, $hd, $part) };
if (my $err = $@) {
- $in->ask_warn('', $err);
+ $in->ask_warn(N("Error"), formatError($err));
return;
}
- if ($::isStandalone) {
- if (my $pkg = fsedit::package_needed_for_partition_type({ type => $type })) {
- my $fs = type2fs({ type => $type });
- if (!-x "/sbin/mkfs.$fs") {
- $in->ask_yesorno('', _("The package %s is needed. Install it?", $pkg), 1) or return;
- $in->do_pkgs->install($pkg);
- }
- -x "/sbin/mkfs.$fs" or $in->ask_warn('', "Mandatory package $pkg is missing"), return;
- }
+ if ($::isStandalone && $type->{fs_type} && fs::format::known_type($type)) {
+ fs::format::check_package_is_installed_format($in->do_pkgs, $type->{fs_type}) or return;
}
1;
}
sub check_mntpoint {
- my ($in, $mntpoint, $hd, $part, $all_hds) = @_;
- eval { fsedit::check_mntpoint($mntpoint, $hd, $part, $all_hds) };
- local $_ = $@;
- if (m|/boot ending on cylinder > 1024|) {
- $in->ask_warn('',
-_("Sorry I won't accept to create /boot so far onto the drive (on a cylinder > 1024).
-Either you use LILO and it won't work, or you don't use LILO and you don't need /boot"));
- } elsif (m|/ ending on cylinder > 1024|) {
- $in->ask_warn('',
-_("The partition you've selected to add as root (/) is physically located beyond
-the 1024th cylinder of the hard drive, and you have no /boot partition.
-If you plan to use the LILO boot manager, be careful to add a /boot partition"));
- undef $_;
- } elsif (m|raid / with no /boot|) {
- $in->ask_warn('',
-_("You've selected a software RAID partition as root (/).
-No bootloader is able to handle this without a /boot partition.
-So be careful to add a /boot partition"));
- undef $_;
- } elsif ($_) {
- $in->ask_warn('', formatError($_));
+ my ($in, $mntpoint, $part, $all_hds) = @_;
+ my $seen;
+ eval {
+ catch_cdie { fsedit::check_mntpoint($mntpoint, $part, $all_hds) }
+ sub { $seen = 1; $in->ask_okcancel(N("Error"), formatError($@)) };
+ };
+ if (my $err = $@) {
+ $in->ask_warn(N("Error"), formatError($err)) if !$seen;
+ return;
}
- !$_;
+ 1;
}
sub check {
my ($in, $hd, $part, $all_hds) = @_;
- check_type($in, $part->{type}, $hd, $part) &&
- check_mntpoint($in, $part->{mntpoint}, $hd, $part, $all_hds);
+ check_type($in, $part, $hd, $part) &&
+ check_mntpoint($in, $part->{mntpoint}, $part, $all_hds);
+}
+
+sub check_rebootNeeded {
+ my ($_in, $hd) = @_;
+ $hd->{rebootNeeded} and die N("You'll need to reboot before the modification can take effect");
}
sub write_partitions {
- my ($in, $hd) = @_;
+ my ($in, $hd, $b_skip_check_rebootNeeded) = @_;
+ check_rebootNeeded($in, $hd) if !$b_skip_check_rebootNeeded;
$hd->{isDirty} or return 1;
isLVM($hd) and return 1;
- $in->ask_okcancel(_("Read carefully!"), _("Partition table of drive %s is going to be written to disk!", $hd->{device}), 1) or return;
- if (!$::testing) {
- partition_table::write($hd);
+ $in->ask_okcancel(N("Read carefully"), N("Partition table of drive %s is going to be written to disk", $hd->{device}), 1) or return;
+ 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');
+ 1;
+}
+
+sub ensure_we_have_encrypt_key_if_needed {
+ my ($in, $part) = @_;
+
+ if (fs::type::isRawLUKS($part)) {
+ $part->{dmcrypt_key} ||= choose_encrypt_key($in, {}, 'skip_encrypt_algo') or return;
}
- $hd->{rebootNeeded} and die _("You'll need to reboot before the modification can take place");
1;
}
-sub unmount {
- my ($hd, $part) = @_;
- fs::umount_part($part);
+sub dmcrypt_format {
+ my ($in, $_hd, $part, $_all_hds) = @_;
+ my $_wait = $in->wait_message(N("Please wait"), N("Formatting partition %s", $part->{device}));
+ require fs::dmcrypt;
+ fs::dmcrypt::format_part($part);
+ # we open it now:
+ &dmcrypt_open;
}
+
sub format_ {
my ($in, $hd, $part, $all_hds) = @_;
+
+ ensure_we_have_encrypt_key_if_needed($in, $part) or return;
write_partitions($in, $_) or return foreach isRAID($part) ? @{$all_hds->{hds}} : $hd;
- ask_alldatawillbelost($in, $part, __("After formatting partition %s, all data on this partition will be lost")) or return;
+
+ ask_alldatawillbelost($in, $part, N_("After formatting partition %s, all data on this partition will be lost")) or return;
+
+ if (fs::type::isRawLUKS($part)) {
+ return &dmcrypt_format;
+ }
+ if ($::isStandalone) {
+ fs::format::check_package_is_installed_format($in->do_pkgs, $part->{fs_type}) or return;
+ }
+ _format_raw($in, $part, $all_hds);
+}
+
+sub _format_raw {
+ my ($in, $part, $all_hds, $o_skip) = @_;
+ if ($::expert && isBlockCheckable($part)) {
+ $part->{toFormatCheck} = $in->ask_yesorno(N("Confirmation"), N("Check for bad blocks?"));
+ }
$part->{isFormatted} = 0; #- force format;
- my $w = $in->wait_message(_("Formatting"),
- isLoopback($part) ? _("Formatting loopback file %s", $part->{loopback_file}) :
- _("Formatting partition %s", $part->{device}));
- fs::format_part($all_hds->{raids}, $part);
+ # 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, $part, $wait_message) if !$o_skip;
1;
}
@@ -1036,28 +1355,32 @@ sub need_migration {
my @l = grep { $_ ne "lost+found" } all($mntpoint);
if (@l && $::isStandalone) {
my $choice;
- my @choices = (__("Move files to the new partition"), __("Hide files"));
- $in->ask_from('', _("Directory %s already contains data\n(%s)", $mntpoint, formatList(5, @l)),
- [ { val => \$choice, list => \@choices, type => 'list' } ]) or return;
+ my @choices = (N_("Move files to the new partition"), N_("Hide files"));
+ $in->ask_from(N("Warning"), N("Directory %s already contains data
+(%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)),
+ [ { val => \$choice, list => \@choices, type => 'list', format => sub { translate($_[0]) } } ]) or return;
$choice eq $choices[0] ? 'migrate' : 'hide';
} else {
'hide';
- }
+ }
}
sub migrate_files {
- my ($in, $hd, $part, $all_hds) = @_;
+ my ($in, $_hd, $part) = @_;
- my $wait = $in->wait_message('', _("Moving files to the new partition"));
+ my $wait = $in->wait_message(N("Please wait"), N("Moving files to the new partition"));
my $handle = any::inspect($part, '', 'rw');
my @l = glob_("$part->{mntpoint}/*");
foreach (@l) {
- $wait->set(_("Copying %s", $_));
- system("cp", "-a", $_, $handle->{dir});
+ $wait->set(N("Copying %s", $_));
+ system("cp", "-a", $_, $handle->{dir}) == 0 or die "copying failed";
}
foreach (@l) {
- $wait->set(_("Removing %s", $_));
- system("rm", "-rf", $_);
+ $wait->set(N("Removing %s", $_));
+ system("rm", "-rf", $_) == 0 or die "removing files failed";
}
}
@@ -1066,8 +1389,12 @@ sub warn_if_renumbered {
my $l = delete $hd->{partitionsRenumbered};
return if is_empty_array_ref($l);
- my @l = map { _("partition %s is now known as %s", @$_) } @$l;
- $in->ask_warn('', join("\n", 'Partitions have been renumbered: ', @l));
+ push @{$hd->{allPartitionsRenumbered}}, @$l;
+
+ 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));
}
#- unit of $mb is mega bytes, min and max are in sectors, this
@@ -1076,84 +1403,98 @@ sub warn_if_renumbered {
#- modified to take into account a true bounding with min and max.
sub from_Mb {
my ($mb, $min, $max) = @_;
- $mb <= $min >> 11 and return $min;
- $mb >= $max >> 11 and return $max;
+ $mb <= to_Mb($min) and return $min;
+ $mb >= to_Mb($max) and return $max;
$mb * 2048;
}
+sub to_Mb {
+ my ($size_sector) = @_;
+ to_int($size_sector / 2048);
+}
+
sub format_part_info {
my ($hd, $part) = @_;
my $info = '';
- $info .= _("Mount point: ") . "$part->{mntpoint}\n" if $part->{mntpoint};
- $info .= _("Device: ") . "$part->{device}\n" if $part->{device} && !isLoopback($part);
- $info .= _("DOS drive letter: %s (just a guess)\n", $part->{device_windobe}) if $part->{device_windobe};
- if (arch() eq "ppc") {
- my $new_value = $part->{pType};
- $new_value =~ s/[^A-Za-z0-9_]//g;
- $info .= _("Type: ") . $new_value . ($::expert ? sprintf " (0x%x)", $part->{type} : '') . "\n";
- if (defined $part->{pName}) {
- $new_value = $part->{pName};
- $new_value =~ s/[^A-Za-z0-9_]//g;
- $info .= _("Name: ") . $new_value . "\n";
- }
- } elsif ($part->{type}) {
- my $type = substr(type2name($part->{type}), 0, 40); # limit the length
- $info .= _("Type: ") . $type . ($::expert ? sprintf " (0x%x)", $part->{type} : '') . "\n";
+ $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};
+ $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 (isEmpty($part)) {
+ $info .= N("Empty") . "\n";
+ } else {
+ $info .= N("Type: ") . (fs::type::part2type_name($part) || $part->{fs_type}) . ($::expert ? sprintf " (0x%x)", $part->{pt_type} : '') . "\n";
+ }
+ $info .= N("Start: sector %s\n", $part->{start}) if $::expert && !isSpecial($part) && !isLVM($hd);
+ if ($hd->{totalsectors}) {
+ $info .= N("Size: %s (%s%% of disk)", formatXiB($part->{size}, 512), int 100 * $part->{size} / $hd->{totalsectors});
} else {
- $info .= _("Empty") . "\n";
+ $info .= N("Size: %s", formatXiB($part->{size}, 512));
}
- $info .= _("Start: sector %s\n", $part->{start}) if $::expert && !isSpecial($part);
- $info .= _("Size: %s", formatXiB($part->{size}, 512));
- $info .= sprintf " (%s%%)", int 100 * $part->{size} / $hd->{totalsectors} if $hd->{totalsectors};
- $info .= _(", %s sectors", $part->{size}) if $::expert;
+ $info .= N(", %s sectors", $part->{size}) if $::expert;
$info .= "\n";
- $info .= _("Cylinder %d to %d\n", $part->{start} / $hd->cylinder_size(), ($part->{start} + $part->{size} - 1) / $hd->cylinder_size()) if ($::expert || !$part->{type}) && !isSpecial($part);
- $info .= _("Formatted\n") if $part->{isFormatted};
- $info .= _("Not formatted\n") if !$part->{isFormatted} && $part->{notFormatted};
- $info .= _("Mounted\n") if $part->{isMounted};
- $info .= _("RAID md%s\n", $part->{raid}) if isPartOfRAID($part);
- $info .= sprintf "LVM %s\n", $part->{lvm} if isPartOfLVM($part);
- $info .= _("Loopback file(s):\n %s\n", join(", ", map { $_->{loopback_file} } @{$part->{loopback}})) if isPartOfLoopback($part);
- $info .= _("Partition booted by default\n (for MS-DOS boot, not for lilo)\n") if $part->{active} && $::expert;
+ $info .= N("Cylinder %d to %d\n", $part->{start} / $hd->cylinder_size, ($part->{start} + $part->{size} - 1) / $hd->cylinder_size) if ($::expert || isEmpty($part)) && !isSpecial($part) && !isLVM($hd) && $hd->cylinder_size;
+ $info .= N("Number of logical extents: %d\n", $part->{size} / $hd->cylinder_size) if $::expert && isLVM($hd);
+ $info .= N("Formatted\n") if $part->{isFormatted};
+ $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) || 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};
+ $info .= sprintf "Used physical extents %d / %d\n", lvm::pv_physical_extents($part);
+ }
+ $info .= N("Loopback file(s):\n %s\n", join(", ", map { $_->{loopback_file} } @{$part->{loopback}})) if isPartOfLoopback($part);
+ $info .= N("Partition booted by default\n (for MS-DOS boot, not for lilo)\n") if $part->{active} && $::expert;
if (isRAID($part)) {
- $info .= _("Level %s\n", $part->{level});
- $info .= _("Chunk size %s\n", $part->{'chunk-size'});
- $info .= _("RAID-disks %s\n", join ", ", map { $_->{device} } @{$part->{disks}});
+ $info .= N("Level %s\n", $part->{level});
+ $info .= N("Chunk size %d KiB\n", $part->{'chunk-size'});
+ $info .= N("RAID-disks %s\n", join ", ", map { $_->{device} } @{$part->{disks}});
} elsif (isLoopback($part)) {
- $info .= _("Loopback file name: %s", $part->{loopback_file});
+ $info .= N("Loopback file name: %s", $part->{loopback_file});
}
if (isApple($part)) {
- $info .= _("\nChances are, this partition is\na Driver partition, you should\nprobably leave it alone.\n");
+ $info .= N("\nChances are, this partition is\na Driver partition. You should\nprobably leave it alone.\n");
}
if (isAppleBootstrap($part)) {
- $info .= _("\nThis special Bootstrap\npartition is for\ndual-booting your system.\n");
+ $info .= N("\nThis special Bootstrap\npartition is for\ndual-booting your system.\n");
}
# restrict the length of the lines
$info =~ s/(.{60}).*/$1.../mg;
$info;
}
-sub format_part_info_short {
+sub format_part_info_short {
my ($hd, $part) = @_;
- $part->{type} ?
- partition_table::description($part) :
- format_part_info($hd, $part);
+ isEmpty($part) ? N("Free space on %s (%s)", $hd->{device}, formatXiB($part->{size}, 512))
+ : partition_table::description($part);
}
sub format_hd_info {
my ($hd) = @_;
my $info = '';
- $info .= _("Device: ") . "$hd->{device}\n";
- $info .= _("Read-only") . "\n" if $hd->{readonly};
- $info .= _("Size: %s\n", formatXiB($hd->{totalsectors}, 512)) if $hd->{totalsectors};
- $info .= _("Geometry: %s cylinders, %s heads, %s sectors\n", @{$hd->{geom}}{qw(cylinders heads sectors)}) if $::expert && $hd->{geom};
- $info .= _("Info: ") . ($hd->{info} || $hd->{media_type}) . "\n" if $::expert && ($hd->{info} || $hd->{media_type});
- $info .= _("LVM-disks %s\n", join ", ", map { $_->{device} } @{$hd->{disks}}) if isLVM($hd) && $hd->{disks};
- $info .= _("Partition table type: %s\n", $1) if $::expert && ref($hd) =~ /_([^_]+)$/;
- $info .= _("on channel %d id %d\n", $hd->{channel}, $hd->{id}) if $::expert && exists $hd->{channel};
+ $info .= N("Device: ") . "$hd->{device}\n";
+ $info .= N("Read-only") . "\n" if $hd->{readonly};
+ $info .= N("Size: %s\n", formatXiB($hd->{totalsectors}, 512)) if $hd->{totalsectors};
+ $info .= N("Geometry: %s cylinders, %s heads, %s sectors\n", $hd->{geom}{cylinders}, $hd->{geom}{heads}, $hd->{geom}{sectors}) if $::expert && $hd->{geom};
+ $info .= N("Name: ") . $hd->{info} . "\n" if $hd->{info};
+ $info .= N("Medium type: ") . $hd->{media_type} . "\n" if $hd->{media_type} && $::expert;
+ $info .= N("LVM-disks %s\n", join ", ", map { $_->{device} } @{$hd->{disks}}) if isLVM($hd) && $hd->{disks};
+ $info .= N("Partition table type: %s\n", $1) if $::expert && ref($hd) =~ /_([^_]+)$/;
+ $info .= N("on channel %d id %d\n", $hd->{channel}, $hd->{id}) if $::expert && exists $hd->{channel};
+ # restrict the length of the lines
+ $info =~ s/(.{60}).*/$1.../mg;
$info;
}
@@ -1161,37 +1502,74 @@ sub format_raw_hd_info {
my ($raw_hd) = @_;
my $info = '';
- $info .= _("Mount point: ") . "$raw_hd->{mntpoint}\n" if $raw_hd->{mntpoint};
+ $info .= N("Mount point: ") . "$raw_hd->{mntpoint}\n" if $raw_hd->{mntpoint};
$info .= format_hd_info($raw_hd);
- if ($raw_hd->{type}) {
- my $type = substr(type2name($raw_hd->{type}), 0, 40); # limit the length
- $info .= _("Type: ") . $type . "\n";
+ if (!isEmpty($raw_hd)) {
+ $info .= N("Type: ") . (fs::type::part2type_name($raw_hd) || $raw_hd->{fs_type}) . "\n";
+ }
+ if (my $s = $raw_hd->{options}) {
+ $s =~ s/password=([^\s,]*)/'password=' . ('x' x length($1))/e;
+ $info .= N("Options: %s", $s);
}
- $info .= _("Options: %s", $raw_hd->{options}) if $raw_hd->{options};
$info;
}
#- get the minimal size of partition in sectors to help diskdrake on
#- limit cases, include a cylinder + start of a eventually following
#- logical partition.
-sub min_partition_size { $_[0]->cylinder_size() + 2*$_[0]{geom}{sectors} }
+sub min_partition_size { $_[0]->cylinder_size + 2*$_[0]{geom}{sectors} }
+sub max_partition_resize {
+ my ($hd, $part) = @_;
+ if (isLVM($hd)) {
+ $part->{size} + fs::get::vg_free_space($hd);
+ } else {
+ partition_table::next_start($hd, $part) - $part->{start};
+ }
+}
sub choose_encrypt_key {
- my ($in) = @_;
+ my ($in, $options, $skip_encrypt_algo) = @_;
my ($encrypt_key, $encrypt_key2);
+ my @algorithms = map { "AES$_" } 128, 196, 256, 512, 1024, 2048;
+ my $encrypt_algo = $options->{'encryption='} || "AES128";
+
$in->ask_from_(
{
- title => _("Filesystem encryption key"),
- messages => _("Choose your filesystem encryption key"),
- callbacks => {
+ title => N("Filesystem encryption key"),
+ messages => N("Choose your filesystem encryption key"),
+ callbacks => {
complete => sub {
- length $encrypt_key < 20 and $in->ask_warn('', _("This encryption key is too simple (must be at least %d characters long)", 20)), return (1,0);
- $encrypt_key eq $encrypt_key2 or $in->ask_warn('', [ _("The encryption keys do not match"), _("Please try again") ]), return (1,1);
- return 0
+ 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;
+ return 0;
} } }, [
-{ label => _("Encryption key"), val => \$encrypt_key, hidden => 1 },
-{ label => _("Encryption key (again)"), val => \$encrypt_key2, hidden => 1 },
- ]) && $encrypt_key;
+{ label => N("Encryption key"), val => \$encrypt_key, hidden => 1, focus => sub { 1 } },
+{ label => N("Encryption key (again)"), val => \$encrypt_key2, hidden => 1 },
+if_(!$skip_encrypt_algo,
+{ label => N("Encryption algorithm"), type => 'list', val => \$encrypt_algo, list => \@algorithms },
+),
+ ]) or return;
+
+ $skip_encrypt_algo ? $encrypt_key : ($encrypt_key, $encrypt_algo);
+}
+
+
+sub tell_wm_and_reboot() {
+ my ($wm, $pid) = any::running_window_manager();
+
+ if (!$wm) {
+ system('reboot');
+ } else {
+ any::ask_window_manager_to_logout_then_do($wm, $pid, 'reboot');
+ }
+}
+
+sub update_bootloader_for_renumbered_partitions {
+ my ($in, $all_hds) = @_;
+ my @renumbering = map { @{$_->{allPartitionsRenumbered} || []} } @{$all_hds->{hds}} or return;
+
+ require bootloader;
+ bootloader::update_for_renumbered_partitions($in, \@renumbering, $all_hds);
}
diff --git a/perl-install/diskdrake/removable.pm b/perl-install/diskdrake/removable.pm
index f781f43d0..f3b73ed4b 100644
--- a/perl-install/diskdrake/removable.pm
+++ b/perl-install/diskdrake/removable.pm
@@ -1,10 +1,9 @@
-package diskdrake::removable; # $Id$
+package diskdrake::removable;
use diagnostics;
use strict;
use diskdrake::interactive;
use common;
-use fsedit;
use fs;
sub main {
@@ -19,17 +18,17 @@ sub main {
}
}
-sub actions {
+sub actions() {
(
- __("Mount point") => \&mount_point,
- __("Options") => \&options,
- __("Type") => \&type,
- __("Done") => \&done,
+ N_("Mount point") => \&mount_point,
+ N_("Options") => \&options,
+ N_("Type") => \&type,
+ N_("Done") => \&done,
);
}
sub done {
- my ($in, $raw_hd, $all_hds) = @_;
+ my ($in, $_raw_hd, $all_hds) = @_;
diskdrake::interactive::Done($in, $all_hds);
}
sub options {
@@ -38,16 +37,16 @@ sub options {
}
sub mount_point {
my ($in, $raw_hd, $all_hds) = @_;
- diskdrake::interactive::Mount_point_raw_hd($in, $raw_hd, $all_hds, "/mnt/$raw_hd->{device}");
+ diskdrake::interactive::Mount_point_raw_hd($in, $raw_hd, $all_hds, "/media/$raw_hd->{device}");
}
sub type {
my ($in, $raw_hd) = @_;
- my @fs = ('auto', fs::auto_fs());
- my $type = $raw_hd->{type};
- $in->ask_from(_("Change type"),
- _("Which filesystem do you want?"),
- [ { label => _("Type"), val => \$type, list => [@fs], not_edit => !$::expert } ]) or return;
- $raw_hd->{type} = $type;
+ my @fs = ('auto', fs::type::guessed_by_mount());
+ my $fs_type = $raw_hd->{fs_type};
+ $in->ask_from(N("Change type"),
+ N("Which filesystem do you want?"),
+ [ { label => N("Type"), val => \$fs_type, list => [@fs] } ]) or return;
+ $raw_hd->{fs_type} = $fs_type;
}
1;
diff --git a/perl-install/diskdrake/removable_gtk.pm b/perl-install/diskdrake/removable_gtk.pm
deleted file mode 100644
index da897b67a..000000000
--- a/perl-install/diskdrake/removable_gtk.pm
+++ /dev/null
@@ -1,31 +0,0 @@
-package diskdrake::removable_gtk; # $Id$
-
-use diagnostics;
-use strict;
-
-use my_gtk qw(:helpers :wrappers :ask);
-
-
-sub per_entry_action_box {
- my ($box, $kind, $entry) = @_;
- $_->widget->destroy foreach $box->children;
-
- if ($entry) {
- my @l = (
- _("Mount point") => \&raw_hd_mount_point,
- _("Options") => \&raw_hd_options,
- _("Type") => \&removable_type,
- );
- @buttons = map_each {
- my ($txt, $f) = @_;
- gtksignal_connect(new Gtk::Button($txt), clicked => sub { try_('', $f, $entry) });
- } group_by2 @l;
-
- gtkadd($box, gtkadd(new Gtk::Frame(_("Choose action")),
- createScrolledWindow(gtkpack__(new Gtk::VBox(0,0), @buttons)))) if @buttons;
-
- } else {
- my $txt = _("Please click on a medium");
- gtkpack($box, gtktext_insert(new Gtk::Text, $txt));
- }
-}
diff --git a/perl-install/diskdrake/resize_ext2.pm b/perl-install/diskdrake/resize_ext2.pm
new file mode 100644
index 000000000..a09cdb542
--- /dev/null
+++ b/perl-install/diskdrake/resize_ext2.pm
@@ -0,0 +1,37 @@
+package diskdrake::resize_ext2;
+
+use diagnostics;
+use strict;
+
+use run_program;
+use common;
+
+
+sub new {
+ my ($type, $_device, $dev) = @_;
+
+ my $o = bless { dev => $dev }, $type;
+
+ my $r = run_program::get_stdout('dumpe2fs', $dev);
+ $o->{block_count} = $r =~ /^Block count:\s*(\d+)/m && $1;
+ $o->{free_block} = $r =~ /^Free blocks:\s*(\d+)/m && $1;
+ $o->{block_size} = $r =~ /^Block size:\s*(\d+)/m && $1;
+ log::l("dumpe2fs $dev gives: Block_count=$o->{block_count}, Free_blocks=$o->{free_block}, Block_size=$o->{block_size}");
+
+ $o->{block_size} && $o;
+}
+
+sub min_size {
+ my ($o) = @_;
+ ($o->{block_count} - $o->{free_block}) * ($o->{block_size} / 512);
+}
+
+sub resize {
+ my ($o, $size) = @_;
+
+ my $s = int($size / ($o->{block_size} / 512));
+ log::l("resize2fs $o->{dev} to size $s in block of $o->{block_size} bytes");
+ run_program::raw({ timeout => 60 * 60 }, "resize2fs", "-pf", $o->{dev}, $s) or die "resize2fs failed";
+}
+
+1;
diff --git a/perl-install/diskdrake/resize_ntfs.pm b/perl-install/diskdrake/resize_ntfs.pm
new file mode 100644
index 000000000..db591e968
--- /dev/null
+++ b/perl-install/diskdrake/resize_ntfs.pm
@@ -0,0 +1,36 @@
+package diskdrake::resize_ntfs;
+
+use diagnostics;
+use strict;
+
+use run_program;
+use common;
+# perl_checker: require interactive
+
+sub new {
+ my ($type, $_device, $dev) = @_;
+ bless { dev => $dev }, $type;
+}
+
+sub check_prog {
+ my ($in) = @_; # perl_checker: $in = interactive->new
+ #- ensure_binary_is_installed checks binary chrooted, whereas we run the binary non-chrooted (pb for Mageia One)
+ $::isInstall || whereis_binary('ntfsresize') || $in->do_pkgs->ensure_binary_is_installed('ntfs-3g', 'ntfsresize');
+}
+
+sub min_size {
+ my ($o) = @_;
+ my $r;
+ run_program::run('ntfsresize', '>', \$r, '-f', '-i', $o->{dev}) or die "ntfsresize failed:\n$r\n";
+ $r =~ /You might resize at (\d+) bytes or / && $1 / 512;
+}
+
+sub resize {
+ my ($o, $size) = @_;
+ my @l = ('-ff', '-s' . int($size / 2) . 'ki', $o->{dev});
+ my $r;
+ run_program::run('ntfsresize', '>', \$r, '-n', @l) or die "ntfsresize failed: $r\n";
+ run_program::raw({ timeout => 'never' }, 'ntfsresize', '>', \$r, @l) or die "ntfsresize failed: $r\n";
+}
+
+1;
diff --git a/perl-install/diskdrake/smbnfs_gtk.pm b/perl-install/diskdrake/smbnfs_gtk.pm
index d16bba988..b2417ce83 100644
--- a/perl-install/diskdrake/smbnfs_gtk.pm
+++ b/perl-install/diskdrake/smbnfs_gtk.pm
@@ -1,28 +1,25 @@
-package diskdrake::smbnfs_gtk; # $Id$
+package diskdrake::smbnfs_gtk;
use diagnostics;
use strict;
-use any;
-use fs;
+use fs::get;
use diskdrake::interactive;
use common;
use interactive;
-use network::smb;
-use network::nfs;
-use my_gtk qw(:helpers :wrappers :ask);
+use fs::remote::smb;
+use fs::remote::nfs;
+use mygtk3 qw(gtknew gtkset);
+use ugtk3 qw(:helpers :wrappers :create);
-my ($all_hds, $in, $tree, $current_entry, $current_leaf, %icons);
+my ($all_hds, $in, $tree_model, $current_entry, $current_leaf, %icons);
sub main {
($in, $all_hds, my $type) = @_;
my ($kind) = $type eq 'smb' ? smb2kind() : nfs2kind();
- {
- local $my_gtk::pop_it = 1;
- $kind->check($in) or return;
- }
+ $kind->check($in) or return;
- my $w = my_gtk->new('DiskDrake');
+ my $w = ugtk3->new(N("Partitioning"));
add_smbnfs($w->{window}, $kind);
$w->{rwindow}->set_default_size(400, 300) if $w->{rwindow}->can('set_default_size');
@@ -36,21 +33,21 @@ sub main {
sub try {
my ($kind, $name, @args) = @_;
my $f = $diskdrake::interactive::{$name} or die "unknown function $name";
- try_($kind, $name, \&{$f}, @args);
+ try_($kind, $name, \&$f, @args);
}
sub try_ {
my ($kind, $name, $f, @args) = @_;
eval { $f->($in, @args, $all_hds) };
if (my $err = $@) {
- $in->ask_warn(_("Error"), formatError($err));
+ $in->ask_warn(N("Error"), formatError($err));
}
update($kind);
- Gtk->main_quit if member($name, 'Cancel', 'Done');
+ Gtk3->main_quit if member($name, 'Cancel', 'Done');
}
sub raw_hd_options {
my ($in, $raw_hd) = @_;
- diskdrake::interactive::Options($in, {}, $raw_hd);
+ diskdrake::interactive::Options($in, {}, $raw_hd, fs::get::empty_all_hds());
}
sub raw_hd_mount_point {
my ($in, $raw_hd) = @_;
@@ -61,38 +58,36 @@ sub raw_hd_mount_point {
sub per_entry_info_box {
my ($box, $kind, $entry) = @_;
- $_->isa('Gtk::Button') or $_->destroy foreach map { $_->widget } $box->children;
- my $info;
- if ($entry) {
- $info = diskdrake::interactive::format_raw_hd_info($entry);
- }
- gtkpack($box, gtkadd(new Gtk::Frame(_("Details")), gtkset_justify(new Gtk::Label($info), 'left')));
+ my $info = $entry ? diskdrake::interactive::format_raw_hd_info($entry) : '';
+ $kind->{per_entry_info_box}->destroy if $kind->{per_entry_info_box};
+ gtkpack($box, $kind->{per_entry_info_box} = gtknew('Frame', text => N("Details"), child => gtknew('Label', text => $info, justify => 'left')));
}
sub per_entry_action_box {
my ($box, $kind, $entry) = @_;
- $_->widget->destroy foreach $box->children;
+ $_->destroy foreach $box->get_children;
my @buttons;
push @buttons, map {
my $s = $_;
- gtksignal_connect(new Gtk::Button(translate($s)), clicked => sub { try($kind, $s, {}, $entry) });
- } (if_($entry->{isMounted}, __("Unmount")),
- if_($entry->{mntpoint} && !$entry->{isMounted}, __("Mount"))) if $entry;
+ gtknew('Button', text => translate($s), clicked => sub { try($kind, $s, {}, $entry) });
+ } (if_($entry->{isMounted}, N_("Unmount")),
+ if_($entry->{mntpoint} && !$entry->{isMounted}, N_("Mount"))) if $entry;
my @l = (
- if_($entry, __("Mount point") => \&raw_hd_mount_point),
- if_($entry && $entry->{mntpoint}, __("Options") => \&raw_hd_options),
- __("Cancel") => sub {},
- __("Done") => \&done,
+ if_($entry, N_("Mount point") => \&raw_hd_mount_point),
+ if_($entry && $entry->{mntpoint}, N_("Options") => \&raw_hd_options),
+ N_("Cancel") => sub {},
+ N_("Done") => \&done,
);
push @buttons, map {
- my ($txt, $f) = @$_;
- gtksignal_connect(new Gtk::Button(translate($txt)), clicked => sub { try_($kind, $txt, $f, $entry) });
+ my ($txt, $f) = @$_;
+ $f ? gtknew('Button', text => translate($txt), clicked => sub { try_($kind, $txt, $f, $entry) })
+ : gtknew('Label', text => "");
} group_by2(@l);
-
- gtkadd($box, gtkpack(new Gtk::HBox(0,0), @buttons));
+
+ gtkadd($box, gtknew('HBox', children_loose => \@buttons));
}
sub done {
@@ -100,28 +95,27 @@ sub done {
diskdrake::interactive::Done($in, $all_hds);
}
-sub set_export_icon {
- my ($entry, $w) = @_;
+sub export_icon {
+ my ($entry) = @_;
$entry ||= {};
- my $icon = $icons{$entry->{isMounted} ? 'mounted' : $entry->{mntpoint} ? 'has_mntpoint' : 'default'};
- ugtk::ctree_set_icon($tree, $w, @$icon);
+ $icons{$entry->{isMounted} ? 'mounted' : $entry->{mntpoint} ? 'has_mntpoint' : 'default'};
}
sub update {
my ($kind) = @_;
per_entry_action_box($kind->{action_box}, $kind, $current_entry);
per_entry_info_box($kind->{info_box}, $kind, $current_entry);
- set_export_icon($current_entry, $current_leaf) if $current_entry;
+ $tree_model->set($current_leaf, 0 => export_icon($current_entry)) if $current_entry;
}
sub find_fstab_entry {
- my ($kind, $e, $add_or_not) = @_;
+ my ($kind, $e, $b_add_or_not) = @_;
my $fs_entry = $kind->to_fstab_entry($e);
- if (my ($fs_entry_) = grep { $fs_entry->{device} eq $_->{device} } @{$kind->{val}}) {
+ if (my $fs_entry_ = find { $fs_entry->{device} eq $_->{device} } @{$kind->{val}}) {
$fs_entry_;
- } elsif ($add_or_not) {
+ } elsif ($b_add_or_not) {
push @{$kind->{val}}, $fs_entry;
$fs_entry;
} else {
@@ -129,26 +123,34 @@ sub find_fstab_entry {
}
}
-sub import_ctree {
+sub import_tree {
my ($kind, $info_box) = @_;
- my (%servers_displayed, %wservers, %wexports, $inside);
+ my (%servers_displayed, %wservers, %wexports);
+
+ $tree_model = Gtk3::TreeStore->new("Gtk3::Gdk::Pixbuf", "Glib::String");
+ my $tree = Gtk3::TreeView->new_with_model($tree_model);
+ $tree->get_selection->set_mode('browse');
- $tree = Gtk::CTree->new(1, 0);
- $tree->set_column_auto_resize(0, 1);
- $tree->set_selection_mode('browse');
- $tree->set_row_height($tree->style->font->ascent + $tree->style->font->descent + 1);
+ my $col = Gtk3::TreeViewColumn->new;
+ $col->pack_start(my $pixrender = Gtk3::CellRendererPixbuf->new, 0);
+ $col->add_attribute($pixrender, 'pixbuf', 0);
+ $col->pack_start(my $texrender = Gtk3::CellRendererText->new, 1);
+ $col->add_attribute($texrender, 'text', 1);
+ $tree->append_column($col);
+
+ $tree->set_headers_visible(0);
foreach ('default', 'server', 'has_mntpoint', 'mounted') {
- $icons{$_} = [ gtkcreate_png("smbnfs_$_") ];
+ $icons{$_} = gtknew('Pixbuf', file => "smbnfs_$_");
}
my $add_server = sub {
my ($server) = @_;
+ my $identifier = $server->{ip} || $server->{name};
my $name = $server->{name} || $server->{ip};
- $servers_displayed{$name} ||= do {
- my $w = $tree->insert_node(undef, undef, [$name], 5, (undef) x 4, 0, 0);
- ugtk::ctree_set_icon($tree, $w, @{$icons{server}});
- $wservers{$w->{_gtk}} = $server;
+ $servers_displayed{$identifier} ||= do {
+ my $w = $tree_model->append_set(undef, [ 0 => $icons{server}, 1 => $name ]);
+ $wservers{$tree_model->get_path_str($w)} = $server;
$w;
};
};
@@ -159,25 +161,25 @@ sub import_ctree {
return @l if !$@;
if ($server->{username}) {
- $in->ask_warn('', _("Can't login using username %s (bad password?)", $server->{username}));
- network::smb::remove_bad_credentials($server);
+ $in->ask_warn('', N("Cannot login using username %s (bad password?)", $server->{username}));
+ fs::remote::smb::remove_bad_credentials($server);
} else {
- if (my @l = network::smb::authentifications_available($server)) {
- my $user = $in->ask_from_list_(_("Domain Authentication Required"),
- _("Which username"), [ @l, __("Another one") ]) or return;
+ if (my @l = fs::remote::smb::authentications_available($server)) {
+ my $user = $in->ask_from_list_(N("Domain Authentication Required"),
+ N("Which username"), [ @l, N_("Another one") ]) or return;
if ($user ne 'Another one') {
- network::smb::read_credentials($server, $user);
+ fs::remote::smb::read_credentials($server, $user);
goto $find_exports;
}
}
}
- if ($in->ask_from(_("Domain Authentication Required"),
- _("Please enter your username, password and domain name to access this host."),
+ if ($in->ask_from(N("Domain Authentication Required"),
+ N("Please enter your username, password and domain name to access this host."),
[
- { label => _("Username"), val => \$server->{username} },
- { label => _("Password"), val => \$server->{password} },
- { label => _("Domain"), val => \$server->{domain} },
+ { label => N("Username"), val => \$server->{username} },
+ { label => N("Password"), val => \$server->{password}, hidden => 1 },
+ { label => N("Domain"), val => \$server->{domain} },
])) {
goto $find_exports;
} else {
@@ -188,21 +190,25 @@ sub import_ctree {
my $add_exports = sub {
my ($node) = @_;
- $tree->expand($node);
- foreach ($find_exports->($wservers{$node->{_gtk}} || return)) { #- can't die here since insert_node provoque a tree_select_row before the %wservers is filled
- my $w = $tree->insert_node($node, undef, [$kind->to_string($_)], 5, (undef) x 4, 1, 0);
- set_export_icon(find_fstab_entry($kind, $_), $w);
- $wexports{$w->{_gtk}} = $_;
+
+ my $path = $tree_model->get_path($node);
+ $tree->expand_row($path, 0);
+
+ foreach ($find_exports->($wservers{$tree_model->get_path_str($node)} || return)) { #- cannot die here since insert_node provoque a tree_select_row before the %wservers is filled
+ my $s = $kind->to_string($_);
+ my $w = $tree_model->append_set($node, [ 0 => export_icon(find_fstab_entry($kind, $_)),
+ 1 => $s ]);
+ $wexports{$tree_model->get_path_str($w)} = $_;
}
};
{
- my $search = new Gtk::Button(_("Search servers"));
+ my $search = gtknew('Button', text => N("Search servers"));
gtkpack__($info_box,
gtksignal_connect($search,
clicked => sub {
$add_server->($_) foreach sort { $a->{name} cmp $b->{name} } $kind->find_servers;
- $search->destroy;
+ gtkset($search, text => N("Search for new servers"));
}));
}
@@ -211,24 +217,23 @@ sub import_ctree {
$add_exports->($node);
}
- $tree->signal_connect(tree_select_row => sub {
- my $curr = $_[1];
- $inside and return;
- $inside = 1;
- if ($curr->row->is_leaf) {
+ $tree->get_selection->signal_connect(changed => sub {
+ my ($_model, $curr) = $_[0]->get_selected;
+ $curr or return;
+
+ if ($tree_model->iter_parent($curr)) {
$current_leaf = $curr;
- $current_entry = find_fstab_entry($kind, $wexports{$curr->{_gtk}} || die(''), 'add');
+ $current_entry = find_fstab_entry($kind, $wexports{$tree_model->get_path_str($curr)} || die(''), 'add');
} else {
- if (!$curr->row->children) {
- gtkset_mousecursor_wait($tree->window);
- my_gtk::flush();
+ if (!$tree_model->iter_has_child($curr)) {
+ gtkset_mousecursor_wait($tree->get_window);
+ ugtk3::flush();
$add_exports->($curr);
- gtkset_mousecursor_normal($tree->window);
+ gtkset_mousecursor_normal($tree->get_window);
}
$current_entry = undef;
}
update($kind);
- $inside = 0;
});
$tree;
}
@@ -237,16 +242,16 @@ sub add_smbnfs {
my ($widget, $kind) = @_;
die if $kind->{main_box};
- $kind->{info_box} = new Gtk::VBox(0,0);
- $kind->{display_box} = createScrolledWindow(import_ctree($kind, $kind->{info_box}));
- $kind->{action_box} = new Gtk::HBox(0,0);
+ $kind->{info_box} = gtknew('VBox');
+ $kind->{display_box} = gtknew('ScrolledWindow', child => import_tree($kind, $kind->{info_box}));
+ $kind->{action_box} = gtknew('HBox');
$kind->{main_box} =
- gtkpack_(new Gtk::VBox(0,7),
- 1, gtkpack(new Gtk::HBox(0,7),
- gtkset_usize($kind->{display_box}, 200, 0),
- $kind->{info_box}),
+ gtknew('VBox', spacing => 7, children => [
+ 1, gtknew('HBox', spacing => 7, children_loose => [
+ gtkset($kind->{display_box}, width => 200),
+ $kind->{info_box} ]),
0, $kind->{action_box},
- );
+ ]);
$widget->add($kind->{main_box});
$current_entry = undef;
@@ -254,12 +259,12 @@ sub add_smbnfs {
$kind;
}
-sub nfs2kind {
- network::nfs->new({ type => 'nfs', name => 'NFS', val => $all_hds->{nfss}, no_auto => 1 });
+sub nfs2kind() {
+ fs::remote::nfs->new({ type => 'nfs', name => 'NFS', val => $all_hds->{nfss}, no_auto => 1 });
}
-sub smb2kind {
- network::smb->new({ type => 'smb', name => 'Samba', val => $all_hds->{smbs}, no_auto => 1 });
+sub smb2kind() {
+ fs::remote::smb->new({ type => 'smb', name => 'Samba', val => $all_hds->{smbs}, no_auto => 1 });
}