From a5473711818b2519552561b33c3f181ab1bbfde6 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Sat, 21 Jan 2017 19:38:55 +0000 Subject: Ensure the kernel doesn't rescan a partially written partition table (mga#20074). When no partitions on a DOS-partitioned disk are mounted, the kernel automatically rescans the partition table when the file handle to the raw device is released. Currently the code opens and closes the raw device when writing the primary partition table and when writing each extended partition table segment. As the extended partition table segments form a linked list, this allows the kernel to get in and rescan the table when the list is not in a coherent state. This patch changes the code to open the raw device before writing the primary partition table and to close it only after writing the last extended partition table segment. The behaviour for other partition table types is unchanged. v2 (tvignaud): simplify by moving copies of noop funcs into the base class --- perl-install/partition_table.pm | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'perl-install/partition_table.pm') diff --git a/perl-install/partition_table.pm b/perl-install/partition_table.pm index c99cb10f8..049c7bb2e 100644 --- a/perl-install/partition_table.pm +++ b/perl-install/partition_table.pm @@ -482,16 +482,17 @@ sub write { #- it will never be writed back on partition table. verifyParts($hd); - $hd->write(0, $hd->{primary}{raw}, $hd->{primary}{info}) or die "writing of partition table failed"; - + my $handle = $hd->start_write(); + $hd->write($handle, 0, $hd->{primary}{raw}, $hd->{primary}{info}) or die "writing of partition table failed"; #- should be fixed but a extended exist with no real extended partition, that blanks mbr! foreach (@{$hd->{extended}}) { # in case of extended partitions, the start sector must be local to the partition $_->{normal}{local_start} = $_->{normal}{start} - $_->{start}; $_->{extended} and $_->{extended}{local_start} = $_->{extended}{start} - $hd->{primary}{extended}{start}; - $hd->write($_->{start}, $_->{raw}) or die "writing of partition table failed"; + $hd->write($handle, $_->{start}, $_->{raw}) or die "writing of partition table failed"; } + $hd->end_write($handle); $hd->{isDirty} = 0; if (my $tell_kernel = delete $hd->{will_tell_kernel}) { -- cgit v1.2.1