summaryrefslogtreecommitdiffstats
path: root/perl-install/fs/dmcrypt.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/fs/dmcrypt.pm')
-rw-r--r--perl-install/fs/dmcrypt.pm66
1 files changed, 58 insertions, 8 deletions
diff --git a/perl-install/fs/dmcrypt.pm b/perl-install/fs/dmcrypt.pm
index bc611455e..eddf669ef 100644
--- a/perl-install/fs/dmcrypt.pm
+++ b/perl-install/fs/dmcrypt.pm
@@ -1,4 +1,4 @@
-package fs::dmcrypt; # $Id: $
+package fs::dmcrypt;
use diagnostics;
use strict;
@@ -11,8 +11,24 @@ use fs::type;
use fs::get;
use run_program;
+=head1 SYNOPSYS
+
+Manage encrypted file systems using cryptsetup
+
+=head1 Functions
+
+=over
+
+=cut
+
sub _crypttab() { "$::prefix/etc/crypttab" }
+=item init()
+
+Load kernel modules and init device mapper.
+
+=cut
+
sub init() {
whereis_binary('cryptsetup') or die "cryptsetup not installed";
@@ -25,25 +41,38 @@ sub _ensure_initialized() {
$initialized++ or init();
}
-sub read_crypttab {
- my ($all_hds) = @_;
+sub read_crypttab_ {
+ my ($all_hds, $crypttab) = @_;
- -e _crypttab() or return;
+ -e $crypttab or return;
my @raw_parts = grep { fs::type::isRawLUKS($_) } fs::get::really_all_fstab($all_hds);
- foreach (cat_(_crypttab())) {
+ foreach (cat_($crypttab)) {
+ next if /^#/;
my ($dm_name, $dev) = split;
my $raw_part = fs::get::device2part($dev, \@raw_parts)
or log::l("crypttab: unknown device $dev for $dm_name"), next;
$raw_part->{dm_name} = $dm_name;
+ _get_existing_one_with_state($raw_part);
}
}
-sub save_crypttab {
+=item read_crypttab($all_hds)
+
+Read /etc/crypttab
+
+=cut
+
+sub read_crypttab {
my ($all_hds) = @_;
+ read_crypttab_($all_hds, _crypttab());
+}
+
+sub save_crypttab_ {
+ my ($all_hds, $crypttab) = @_;
my @raw_parts = grep { $_->{dm_name} } fs::get::really_all_fstab($all_hds) or return;
@@ -57,7 +86,18 @@ sub save_crypttab {
if (eof) {
$_ .= join('', map { "$_ $names{$_}\n" } sort keys %names);
}
- } _crypttab();
+ } $crypttab;
+}
+
+=item save_crypttab($all_hds)
+
+Save /etc/crypttab
+
+=cut
+
+sub save_crypttab {
+ my ($all_hds) = @_;
+ save_crypttab_($all_hds, _crypttab());
}
sub format_part {
@@ -80,9 +120,15 @@ sub open_part {
});
run_program::run('udevadm', 'settle');
+ push @$dmcrypts, _get_existing_one_with_state($part);
+}
+
+
+sub _get_existing_one_with_state {
+ my ($part) = @_;
my $active_dmcrypt = _parse_dmsetup_table($part->{dm_name},
run_program::get_stdout('dmsetup', 'table', $part->{dm_name}));
- push @$dmcrypts, _get_existing_one([$part], $active_dmcrypt);
+ _get_existing_one([$part], $active_dmcrypt);
}
sub close_part {
@@ -158,4 +204,8 @@ sub active_dm() {
} run_program::get_stdout('dmsetup', 'table');
}
+=back
+
+=cut
+
1;