From 5f9a55fdcb37adc15655753dce1e714a3ab50075 Mon Sep 17 00:00:00 2001 From: Phillip Susi Date: Wed, 5 Feb 2014 13:43:02 -0500 Subject: [PATCH] Remove incorrect rounding in file system resize (#723543) Work on bug 701075 inadvertently introduced a problem where ext2/3/4, resierfs, and ntfs file systems were rounding the file system size up to the nearest kiB. The problem was discovered when a user resized a partition by moving only the start boundary to the right thereby shrinking the partition. In the situation where the resulting partition size was not an integer kiB value (such as might occur on a 512 byte per sector device) the file system size was rounded up to the nearest kiB. This resulted in a file system size being set one sector larger than the partition size. This problem was introduced with the following commit: Shrink file systems to exact size (#701075) 3461413d283f1bac77e541b1054e775ec105212f The fix chosen for this problem involved removing the rounding logic. Bug 723543 - Shrink ext2/3/4 results in attempt to set partition smaller than file system --- src/ext2.cc | 4 ++-- src/ntfs.cc | 2 +- src/reiserfs.cc | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ext2.cc b/src/ext2.cc index 34f50ec7..c77d49ac 100644 --- a/src/ext2.cc +++ b/src/ext2.cc @@ -189,8 +189,8 @@ bool ext2::resize( const Partition & partition_new, OperationDetail & operationd Glib::ustring str_temp = "resize2fs -p " + partition_new .get_path() ; if ( ! fill_partition ) - str_temp += " " + Utils::num_to_str( Utils::round( Utils::sector_to_unit( - partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K" ; + str_temp += " " + Utils::num_to_str( floor( Utils::sector_to_unit( + partition_new .get_sector_length(), partition_new .sector_size, UNIT_KIB ) ) ) + "K"; return ! execute_command( str_temp, operationdetail ) ; } diff --git a/src/ntfs.cc b/src/ntfs.cc index 6ac19cb3..61da5012 100644 --- a/src/ntfs.cc +++ b/src/ntfs.cc @@ -203,7 +203,7 @@ bool ntfs::resize( const Partition & partition_new, OperationDetail & operationd Glib::ustring size = "" ; if ( ! fill_partition ) { - size = " -s " + Utils::num_to_str( Utils::round( Utils::sector_to_unit( + size = " -s " + Utils::num_to_str( floor( Utils::sector_to_unit( partition_new .get_sector_length(), partition_new .sector_size, UNIT_BYTE ) ) ) ; } Glib::ustring cmd = "ntfsresize --force --force" + size ; diff --git a/src/reiserfs.cc b/src/reiserfs.cc index 2c44471d..fc89a08b 100644 --- a/src/reiserfs.cc +++ b/src/reiserfs.cc @@ -165,7 +165,7 @@ bool reiserfs::resize( const Partition & partition_new, OperationDetail & operat Glib::ustring size = "" ; if ( ! fill_partition ) { - size = " -s " + Utils::num_to_str( Utils::round( Utils::sector_to_unit( + size = " -s " + Utils::num_to_str( floor( Utils::sector_to_unit( partition_new .get_sector_length(), partition_new .sector_size, UNIT_BYTE ) ) ) ; } Glib::ustring cmd = "sh -c 'echo y | resize_reiserfs" + size + " " + partition_new .get_path() + "'" ;