From 407faa9cfa7626ff3e4029eaf00e653dbdb7a473 Mon Sep 17 00:00:00 2001 From: Ben Hutchings Date: Thu, 11 Mar 2010 00:54:45 +0000 Subject: [PATCH] Replace CD/DVD/BD device names with udev-provided persistent aliases svn path=/dists/trunk/linux-2.6/; revision=15349 --- debian/changelog | 1 + debian/linux-base.postinst | 46 ++++++++++++++++++++++++++++---------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/debian/changelog b/debian/changelog index a47a1b56a..e13276930 100644 --- a/debian/changelog +++ b/debian/changelog @@ -12,6 +12,7 @@ linux-2.6 (2.6.33-1~experimental.3) UNRELEASED; urgency=low - Don't accept empty filesystem labels as identifiers (Closes: #572438) - For consistency with fresh installations, use or assign UUIDs rather than labels where both are available (Closes: #572376) + - Replace CD/DVD/BD device names with udev-provided persistent aliases -- Ben Hutchings Sun, 28 Feb 2010 17:01:33 +0000 diff --git a/debian/linux-base.postinst b/debian/linux-base.postinst index 893daa798..9ae900b95 100644 --- a/debian/linux-base.postinst +++ b/debian/linux-base.postinst @@ -877,6 +877,20 @@ sub udev_next { return @results; } +sub udev_parse_symlink_rule { + my ($path, $symlink); + for (@_) { + my ($text, $key, $op, $value) = @$_; + next if !defined($key); + if ($key eq 'ENV{ID_PATH}' && $op eq '==') { + $path = $value; + } elsif ($key eq 'SYMLINK' && $op eq '+=') { + $symlink = $value; + } + } + return ($path, $symlink); +} + # Find symlink rules using IDE device paths that aren't matched by rules # using the corresponding SCSI device path. Return an array containing # the corresponding path for each rule where this is the case and undef @@ -891,17 +905,7 @@ sub udev_cd_find_unmatched_ide_rules { my @keys = udev_next($file); last if $#keys < 0; - my ($path, $symlink); - for (@keys) { - my ($text, $key, $op, $value) = @$_; - next if !defined($key); - if ($key eq 'ENV{ID_PATH}' && $op eq '==') { - $path = $value; - } elsif ($key eq 'SYMLINK' && $op eq '+=') { - $symlink = $value; - } - } - + my ($path, $symlink) = udev_parse_symlink_rule(@keys); if (defined($path) && defined($symlink)) { if ($path =~ /-ide-\d+:\d+$/) { # libata uses the PATA controller and device numbers @@ -1315,11 +1319,29 @@ sub scan_devices { } } - # Discard all device ids that are ambiguous. + # Discard all labels and UUIDs(!) that are ambiguous. for my $bdev (keys(%bdev_map)) { @{$bdev_map{$bdev}->{ids}} = grep({ $#{$id_map{$_}} == 0 } @{$bdev_map{$bdev}->{ids}}); } + + # Add persistent aliases for CD/DVD/BD drives + my $cd_rules = + new FileHandle('/etc/udev/rules.d/70-persistent-cd.rules', 'r'); + while (defined($cd_rules)) { + my @keys = udev_next($cd_rules); + last if $#keys < 0; + + my ($path, $symlink) = udev_parse_symlink_rule(@keys); + if (defined($path) && defined($symlink)) { + $symlink =~ s{^(?!/)}{/dev/}; + my $bdev = readlink($symlink) or next; + $bdev =~ s{^(?!/)}{/dev/}; + if (exists($bdev_map{$bdev})) { + push @{$bdev_map{$bdev}->{ids}}, $symlink; + } + } + } } sub assign_new_ids {