From b62b2f3dc75d15d570344656f950502afeb2dc8d Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Tue, 15 Jan 2002 21:18:00 +0000 Subject: encrypted filesystem handling: - using losetup - add "Options" for partitions in diskdrake (expert mode) --- perl-install/c/stuff.xs.pm | 42 -------------------------------------- perl-install/devices.pm | 35 +++++++++++++++++++++++++------- perl-install/fs.pm | 49 ++++++++++++++++++++++++++++----------------- perl-install/fsedit.pm | 1 + perl-install/install_any.pm | 2 +- perl-install/share/list | 1 + 6 files changed, 62 insertions(+), 68 deletions(-) (limited to 'perl-install') diff --git a/perl-install/c/stuff.xs.pm b/perl-install/c/stuff.xs.pm index b57b471e2..59d8fe232 100644 --- a/perl-install/c/stuff.xs.pm +++ b/perl-install/c/stuff.xs.pm @@ -412,48 +412,6 @@ kernel_version() OUTPUT: RETVAL -int -set_loop(dev_fd, file) - int dev_fd - char *file - CODE: - RETVAL = 0; -{ - struct loop_info loopinfo; - int file_fd = open(file, O_RDWR); - - if (file_fd < 0) return; - - memset(&loopinfo, 0, sizeof(loopinfo)); - strncpy(loopinfo.lo_name, file, LO_NAME_SIZE); - loopinfo.lo_name[LO_NAME_SIZE - 1] = 0; - - if (ioctl(dev_fd, LOOP_SET_FD, file_fd) < 0) return; - if (ioctl(dev_fd, LOOP_SET_STATUS, &loopinfo) < 0) { - ioctl(dev_fd, LOOP_CLR_FD, 0); - return; - } - close(file_fd); - RETVAL = 1; -} - OUTPUT: - RETVAL - -int -del_loop(device) - char *device - CODE: - RETVAL = 0; -{ - int fd; - if ((fd = open(device, O_RDONLY)) < 0) return; - if (ioctl(fd, LOOP_CLR_FD, 0) < 0) return; - close(fd); - RETVAL = 1; -} - OUTPUT: - RETVAL - int prom_open() diff --git a/perl-install/devices.pm b/perl-install/devices.pm index 7228f9410..4ccac4901 100644 --- a/perl-install/devices.pm +++ b/perl-install/devices.pm @@ -32,17 +32,38 @@ sub size($) { $low + 1; } +sub del_loop { + my ($dev) = @_; + run_program::run("losetup", "-d", $dev); +} +sub find_free_loop { + foreach (0..7) { + my $dev = make("loop$_"); + { + local *F; + sysopen F, $dev, 2 or next; + !ioctl(F, c::LOOP_GET_STATUS(), my $tmp) && $! == 6 or next; #- 6 == ENXIO + close F; + } + return $dev; + } + die "no free loop found"; +} sub set_loop { - my ($file) = @_; + my ($file, $encrypt_key, $encryption) = @_; + my $dev = find_free_loop(); - foreach (0..7) { + if ($encrypt_key && $encryption) { + my $cmd = "losetup -p 0 -e $encryption $dev $file"; + log::l("calling $cmd"); local *F; - my $dev = make("loop$_"); - sysopen F, $dev, 2 or next; - !ioctl(F, c::LOOP_GET_STATUS(), my $tmp) && $! == 6 or next; #- 6 == ENXIO - log::l("trying with loop $dev"); - return c::set_loop(fileno F, $file) && $dev; + open F, "|$cmd"; + print F $encrypt_key; + close F or die "losetup failed"; + } else { + run_program::run("losetup", $dev, $file) or return; } + $dev; } sub entry { diff --git a/perl-install/fs.pm b/perl-install/fs.pm index 160d939a3..9a12da97e 100644 --- a/perl-install/fs.pm +++ b/perl-install/fs.pm @@ -159,7 +159,7 @@ sub write_fstab { my ($freq, $passno) = exists $_->{freq} ? ($_->{freq}, $_->{passno}) : - isTrueFS($_) ? + isTrueFS($_) && $_->{options} !~ /encryption=/ ? (1, $_->{mntpoint} eq '/' ? 1 : loopback::carryRootLoopback($_) ? 0 : 2) : (0, 0); @@ -232,6 +232,8 @@ sub mount_options_unpack { $non_defaults->{$_} = 1 foreach @$l; } + $non_defaults->{encrypted} = 1 if !$part->{isFormatted} || isSwap($part); + $non_defaults->{supermount} = 1 if member(type2fs($part), 'auto', @auto_fs); my $defaults = { reverse %$non_defaults }; @@ -488,33 +490,35 @@ sub real_format_part { $part->{isFormatted} and return; + my $dev = $part->{real_device} || $part->{device}; + my @options = $part->{toFormatCheck} ? "-c" : (); - log::l("formatting device $part->{device} (type ", type2name($part->{type}), ")"); + log::l("formatting device $dev (type ", type2name($part->{type}), ")"); if (isExt2($part)) { push @options, "-F" if isLoopback($part); push @options, "-m", "0" if $part->{mntpoint} =~ m|^/home|; - format_ext2($part->{device}, @options); + format_ext2($dev, @options); } elsif (isThisFs("ext3", $part)) { push @options, "-m", "0" if $part->{mntpoint} =~ m|^/home|; - format_ext3($part->{device}, @options); + format_ext3($dev, @options); } elsif (isThisFs("reiserfs", $part)) { - format_reiserfs($part->{device}, @options, if_(c::kernel_version() =~ /^\Q2.2/, "-v", "1")); + format_reiserfs($dev, @options, if_(c::kernel_version() =~ /^\Q2.2/, "-v", "1")); } elsif (isThisFs("xfs", $part)) { - format_xfs($part->{device}, @options); + format_xfs($dev, @options); } elsif (isThisFs("jfs", $part)) { - format_jfs($part->{device}, @options); + format_jfs($dev, @options); } elsif (isDos($part)) { - format_dos($part->{device}, @options); + format_dos($dev, @options); } elsif (isWin($part)) { - format_dos($part->{device}, @options, '-F', 32); + format_dos($dev, @options, '-F', 32); } elsif (isThisFs('hfs', $part)) { - format_hfs($part->{device}, @options, '-l', "Untitled"); + format_hfs($dev, @options, '-l', "Untitled"); } elsif (isAppleBootstrap($part)) { - format_hfs($part->{device}, @options, '-l', "bootstrap"); + format_hfs($dev, @options, '-l', "bootstrap"); } elsif (isSwap($part)) { my $check_blocks = grep { /^-c$/ } @options; - swap::make($part->{device}, $check_blocks); + swap::make($dev, $check_blocks); } else { die _("I don't know how to format %s in type %s", $_->{device}, type2name($_->{type})); } @@ -535,6 +539,14 @@ sub format_part { ################################################################################ # mounting functions ################################################################################ +sub set_loop { + my ($part) = @_; + if (!$part->{real_device}) { + eval { modules::load('loop') }; + $part->{real_device} = devices::set_loop(devices::make($part->{device}), $part->{encrypt_key}, $part->{options} =~ /encryption=(\w+)/); + } +} + sub formatMount_part { my ($part, $raids, $fstab, $prefix, $callback) = @_; @@ -544,7 +556,9 @@ sub formatMount_part { if (my $p = up_mount_point($part->{mntpoint}, $fstab)) { formatMount_part($p, $raids, $fstab, $prefix, $callback) unless loopback::carryRootLoopback($part); } - + if ($part->{encrypt_key}) { + set_loop($part); + } if ($part->{toFormat}) { $callback->($part) if $callback; format_part($raids, $part, $prefix); @@ -662,14 +676,13 @@ sub mount_part { } else { $part->{mntpoint} or die "missing mount point for partition $part->{device}"; - my $dev = $part->{device}; my $mntpoint = ($prefix || '') . $part->{mntpoint}; - if (isLoopback($part)) { - eval { modules::load('loop') }; - $dev = $part->{real_device} = devices::set_loop($part->{device}) || die; + if (isLoopback($part) || $part->{encrypt_key}) { + set_loop($part); } elsif (loopback::carryRootLoopback($part)) { $mntpoint = "/initrd/loopfs"; } + my $dev = $part->{real_device} || $part->{device}; mount($dev, $mntpoint, type2fs($part), $rdonly, $part->{options}); rmdir "$mntpoint/lost+found"; } @@ -689,7 +702,7 @@ sub umount_part { umount("/initrd/loopfs"); } else { umount(($prefix || '') . $part->{mntpoint} || devices::make($part->{device})); - c::del_loop(delete $part->{real_device}) if isLoopback($part); + devices::del_loop(delete $part->{real_device}) if $part->{real_device}; } } $part->{isMounted} = 0; diff --git a/perl-install/fsedit.pm b/perl-install/fsedit.pm index 9a3f0bb32..90554f509 100644 --- a/perl-install/fsedit.pm +++ b/perl-install/fsedit.pm @@ -416,6 +416,7 @@ sub suggest_part { $part->{mntpoint} = $best->{mntpoint}; $part->{type} = $best->{type} if !(isTrueFS($best) && isTrueFS($part)); $part->{size} = computeSize($part, $best, $all_hds, $suggestions); + $part->{options} = $best->{options} if $best->{options}; 1; } diff --git a/perl-install/install_any.pm b/perl-install/install_any.pm index ab39349c4..5c797d1a0 100644 --- a/perl-install/install_any.pm +++ b/perl-install/install_any.pm @@ -787,7 +787,7 @@ sub getAndSaveAutoInstallFloppy { fs::umount($mountdir); rmdir $mountdir; - c::del_loop($dev); + devices::del_loop($dev); require commands; commands::dd("if=$imagefile", "of=$where", "bs=1440", "count=1024"); unlink $imagefile; diff --git a/perl-install/share/list b/perl-install/share/list index 03297f105..c44614670 100644 --- a/perl-install/share/list +++ b/perl-install/share/list @@ -14,6 +14,7 @@ /sbin/tune2fs /sbin/fdisk /sbin/insmod +/sbin/losetup /sbin/mke2fs /sbin/resize2fs /sbin/dumpe2fs -- cgit v1.2.1