diff options
author | Pascal Terjan <pterjan@mandriva.org> | 2009-01-09 15:03:02 +0000 |
---|---|---|
committer | Pascal Terjan <pterjan@mandriva.org> | 2009-01-09 15:03:02 +0000 |
commit | 402a88020dc9a05fdd50ede1fd78a44354246af3 (patch) | |
tree | 27f7dfcbbf9ef06c8c5bc589b8a0efe3f0c5b0cf /perl-install | |
parent | 51c2a71b9400577ef5da45437c52da9a5a59036b (diff) | |
download | drakx-402a88020dc9a05fdd50ede1fd78a44354246af3.tar drakx-402a88020dc9a05fdd50ede1fd78a44354246af3.tar.gz drakx-402a88020dc9a05fdd50ede1fd78a44354246af3.tar.bz2 drakx-402a88020dc9a05fdd50ede1fd78a44354246af3.tar.xz drakx-402a88020dc9a05fdd50ede1fd78a44354246af3.zip |
Add support for editing partition labels without formatting
Diffstat (limited to 'perl-install')
-rw-r--r-- | perl-install/NEWS | 4 | ||||
-rw-r--r-- | perl-install/diskdrake/interactive.pm | 16 | ||||
-rw-r--r-- | perl-install/fs/format.pm | 101 | ||||
-rw-r--r-- | perl-install/install/NEWS | 1 | ||||
-rw-r--r-- | perl-install/install/share/list.xml | 14 |
5 files changed, 108 insertions, 28 deletions
diff --git a/perl-install/NEWS b/perl-install/NEWS index 60a3161f7..32a46962f 100644 --- a/perl-install/NEWS +++ b/perl-install/NEWS @@ -2,6 +2,10 @@ - diskdrake: o --smb: cifs must be used instead of smbfs (#42483) o ext4dev is now stable and called ext4 in 2.6.28+ + o allow editing partition label without formatting (bootloader config is not + yet updated) + o allow setting label on NTFS and reiser4 partitions + - harddrake: o fix displaying in proper category sound coprocessor & misc ACPI event keys - prevent mdkapplet from crashing (#46477) diff --git a/perl-install/diskdrake/interactive.pm b/perl-install/diskdrake/interactive.pm index 6d40c2f0d..b23f9ff9d 100644 --- a/perl-install/diskdrake/interactive.pm +++ b/perl-install/diskdrake/interactive.pm @@ -397,7 +397,7 @@ sub part_possible_actions { N_("Mount point") => '$part->{real_mntpoint} || (!isBusy && !isSwap && !isNonMountable)', N_("Type") => '!isBusy && $::expert && (!readonly || $part->{pt_type} == 0x83)', N_("Options") => '!isSwap($part) && !isNonMountable && $::expert', - N_("Label") => '!isNonMountable && $::expert', + N_("Label") => '!isNonMountable && $::expert && fs::format::canEditLabel($part)', N_("Resize") => '!isBusy && !readonly && !isSpecial || isLVM($hd) && LVM_resizable', N_("Format") => '!isBusy && (!readonly && ($::expert || $::isStandalone) || fs::type::isRawLUKS($part))', N_("Mount") => '!isBusy && (hasMntpoint || isSwap) && maybeFormatted && ($::expert || $::isStandalone)', @@ -603,12 +603,20 @@ sub Type { sub Label { my ($in, $_hd, $part) = @_; - $in->ask_from(N("Which volume label?"), '', + my $old_label = $part->{device_LABEL}; + $in->ask_from(N("Set volume label"), N("Beware, this will be written to disk as soon as you validate!"), [ { label => N("Which volume label?"), title => 1 }, { label => N("Label:"), val => \$part->{device_LABEL} } ]) or return; + + if (!fs::format::check_package_is_installed_label($in->do_pkgs, $part->{fs_type})) { + $part->{device_LABEL} = $old_label; + return; + } $part->{prefer_device_LABEL} = to_bool($part->{device_LABEL}); + fs::format::clean_label($part); + fs::format::write_label($part); } sub Mount_point { @@ -1092,7 +1100,7 @@ sub check_type { return; } if ($::isStandalone && $type->{fs_type} && fs::format::known_type($type)) { - fs::format::check_package_is_installed($in->do_pkgs, $type->{fs_type}) or return; + fs::format::check_package_is_installed_format($in->do_pkgs, $type->{fs_type}) or return; } 1; } @@ -1167,7 +1175,7 @@ sub format_ { return &dmcrypt_format; } if ($::isStandalone) { - fs::format::check_package_is_installed($in->do_pkgs, $part->{fs_type}) or return; + fs::format::check_package_is_installed_format($in->do_pkgs, $part->{fs_type}) or return; } if ($::expert && !member($part->{fs_type}, 'reiserfs', 'xfs')) { $part->{toFormatCheck} = $in->ask_yesorno(N("Confirmation"), N("Check bad blocks?")); diff --git a/perl-install/fs/format.pm b/perl-install/fs/format.pm index 386acbad6..d621b6067 100644 --- a/perl-install/fs/format.pm +++ b/perl-install/fs/format.pm @@ -31,12 +31,33 @@ my %LABELs = ( #- option, length, handled_by_mount ext3 => [ '-L', 16, 1 ], ext4 => [ '-L', 16, 1 ], reiserfs => [ '-l', 16, 1 ], + reiser4 => [ '-L', 16, 1 ], xfs => [ '-L', 12, 1 ], jfs => [ '-L', 16, 1 ], hfs => [ '-l', 27, 0 ], dos => [ '-n', 11, 0 ], vfat => [ '-n', 11, 0 ], swap => [ '-L', 15, 1 ], + ntfs => [ '-L', 128, 0 ], + 'ntfs-3g' => [ '-L', 128, 0 ], +); + +my %edit_LABEL = ( # package, command, option +# If option is defined, run <command> <option> <label> <device> +# If no option, run <command> <device> <label> + ext2 => [ 'e2fsprogs', 'tune2fs', '-L' ], + ext3 => [ 'e2fsprogs', 'tune2fs', '-L' ], + ext4 => [ 'e2fsprogs', 'tune2fs', '-L' ], + reiserfs => [ 'reiserfsprogs', 'reiserfstune', '-l' ], +# reiser4 + xfs => [ 'xfsprogs', 'xfs_admin', '-L' ], + jfs => [ 'jfsutils', 'jfs_tune', '-L' ], +# hfs + dos => [ 'dosfstools', 'dosfslabel' ], + vfat => [ 'dosfstools', 'dosfslabel' ], +# swap => [ 'util-linux-ng', 'mkswap' ], + ntfs => [ 'ntfsprogs', 'ntfslabel' ], + 'ntfs-3g' => [ 'ntfsprogs', 'ntfslabel' ], ); sub package_needed_for_partition_type { @@ -50,13 +71,25 @@ sub known_type { to_bool($cmds{$part->{fs_type}}); } -sub check_package_is_installed { +sub check_package_is_installed_format { my ($do_pkgs, $fs_type) = @_; my ($pkg, $binary) = @{$cmds{$fs_type} || return}; whereis_binary($binary) || $do_pkgs->ensure_binary_is_installed($pkg, $binary); #- ensure_binary_is_installed checks binary chrooted, whereas we run the binary non-chrooted (pb for Mandriva One) } +sub check_package_is_installed_label { + my ($do_pkgs, $fs_type) = @_; + + my ($pkg, $binary) = @{$edit_LABEL{$fs_type} || return}; + whereis_binary($binary) || $do_pkgs->ensure_binary_is_installed($pkg, $binary); #- ensure_binary_is_installed checks binary chrooted, whereas we run the binary non-chrooted (pb for Mandriva One) +} + +sub canEditLabel { + my ($part) = @_; + to_bool($edit_LABEL{$part->{fs_type}}); +} + sub part { my ($all_hds, $part, $wait_message) = @_; if (isRAID($part)) { @@ -72,6 +105,27 @@ sub part { } } +sub write_label { + my ($part) = @_; + + $part->{device_LABEL} or return; + $part->{isNotFormatted} and return; + + if ($part->{encrypt_key}) { + fs::mount::set_loop($part); + } + + my $dev = $part->{real_device} || $part->{device}; + my ($_pkg, $cmd, @first_options) = @{$edit_LABEL{$part->{fs_type}} || die N("I do not know how to set label on %s with type %s", $part->{device}, $part->{fs_type})}; + my @args; + if (defined $first_options[0]) { + @args = ($cmd, @first_options, $part->{device_LABEL}, devices::make($dev)); + } else { + @args = ($cmd, devices::make($dev), $part->{device_LABEL}); + } + run_program::raw({ timeout => 'never' }, @args) or die N("setting label on %s failed", $dev); +} + sub part_raw { my ($part, $wait_message) = @_; @@ -101,22 +155,7 @@ sub part_raw { } if ($part->{device_LABEL}) { - if ($LABELs{$fs_type}) { - my ($option, $length, $handled_by_mount) = @{$LABELs{$fs_type}}; - if (length $part->{device_LABEL} > $length) { - my $short = substr($part->{device_LABEL}, 0, $length); - log::l("shortening LABEL $part->{device_LABEL} to $short"); - $part->{device_LABEL} = $short; - } - delete $part->{prefer_device_LABEL} - if !$handled_by_mount || $part->{mntpoint} eq '/' && !member($fs_type, qw(ext2 ext3 ext4)); - - push @options, $option, $part->{device_LABEL}; - } else { - log::l("dropping LABEL=$part->{device_LABEL} since we don't know how to set labels for fs_type $part->{fs_type}"); - delete $part->{device_LABEL}; - delete $part->{prefer_device_LABEL}; - } + push @options, @{$LABELs{$fs_type}}[0], $part->{device_LABEL}; } my ($_pkg, $cmd, @first_options) = @{$cmds{$fs_type} || die N("I do not know how to format %s in type %s", $part->{device}, $part->{fs_type})}; @@ -166,6 +205,27 @@ sub disable_forced_fsck { run_program::run("tune2fs", "-c0", "-i0", devices::make($dev)); } +sub clean_label { + my ($part) = @_; + if ($part->{device_LABEL}) { + my $fs_type = $part->{fs_type}; + if ($LABELs{$fs_type}) { + my ($option, $length, $handled_by_mount) = @{$LABELs{$fs_type}}; + if (length $part->{device_LABEL} > $length) { + my $short = substr($part->{device_LABEL}, 0, $length); + log::l("shortening LABEL $part->{device_LABEL} to $short"); + $part->{device_LABEL} = $short; + } + delete $part->{prefer_device_LABEL} + if !$handled_by_mount || $part->{mntpoint} eq '/' && !member($fs_type, qw(ext2 ext3 ext4)); + } else { + log::l("dropping LABEL=$part->{device_LABEL} since we don't know how to set labels for fs_type $fs_type"); + delete $part->{device_LABEL}; + delete $part->{prefer_device_LABEL}; + } + } +} + sub formatMount_part { my ($part, $all_hds, $fstab, $wait_message) = @_; @@ -175,8 +235,13 @@ sub formatMount_part { if (my $p = fs::get::up_mount_point($part->{mntpoint}, $fstab)) { formatMount_part($p, $all_hds, $fstab, $wait_message) if !fs::type::carry_root_loopback($part); } + + clean_label($part); + if ($part->{toFormat}) { fs::format::part($all_hds, $part, $wait_message); + } else { + fs::format::write_label($part); } #- setting user_xattr on /home (or "/" if no /home) @@ -191,7 +256,7 @@ sub formatMount_part { sub formatMount_all { my ($all_hds, $fstab, $wait_message) = @_; - formatMount_part($_, $all_hds, $fstab, $wait_message) + formatMount_part($_, $all_hds, $fstab, $wait_message) foreach sort { isLoopback($a) ? 1 : isSwap($a) ? -1 : 0 } grep { $_->{mntpoint} } @$fstab; #- ensure the link is there diff --git a/perl-install/install/NEWS b/perl-install/install/NEWS index c148ecba8..937310e73 100644 --- a/perl-install/install/NEWS +++ b/perl-install/install/NEWS @@ -1,4 +1,5 @@ - propose ext4 filesystem during install now that it is stable +- include tools to edit partition labels Version 11.76 - 18 December 2008 diff --git a/perl-install/install/share/list.xml b/perl-install/install/share/list.xml index a7efeaa0d..3fd7e121c 100644 --- a/perl-install/install/share/list.xml +++ b/perl-install/install/share/list.xml @@ -21,19 +21,21 @@ badblocks mkswap - mkfs.ext2 mkfs.ext3 e2fsck tune2fs dumpe2fs resize2fs + mkfs.ext2 mkfs.ext3 mkfs.ext4 e2fsck tune2fs dumpe2fs resize2fs - mkfs.reiserfs - mkfs.xfs - resize_reiserfs + mkfs.reiserfs resize_reiserfs reiserfstune + mkfs.xfs xfs_admin + <if ARCH="i.86|x86_64|ia64"> - mkdosfs + mkdosfs + dosfslabel mkntfs ntfsresize + ntfslabel dmraid </if> <if ARCH="i.86|x86_64"> - mkfs.jfs fsck.jfs + mkfs.jfs fsck.jfs jfs_tune </if> quotacheck cryptsetup dmsetup |