From 1f72c5f0e562534d7b3efafc43b2a20a0da45cf2 Mon Sep 17 00:00:00 2001 From: Mike Fleetwood Date: Tue, 10 Oct 2023 09:56:58 +0100 Subject: [PATCH] Refactor reiser4::set_used_sectors() into if fail return early pattern (!119) Closes !119 - Tidy-ups for file system interface classes --- src/reiser4.cc | 63 +++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/src/reiser4.cc b/src/reiser4.cc index 83f1c916..cc6da62a 100644 --- a/src/reiser4.cc +++ b/src/reiser4.cc @@ -64,44 +64,45 @@ FS reiser4::get_filesystem_support() return fs ; } -void reiser4::set_used_sectors( Partition & partition ) + +void reiser4::set_used_sectors(Partition& partition) { - if ( ! Utils::execute_command( "debugfs.reiser4 " + Glib::shell_quote( partition.get_path() ), - output, error, true ) ) + exit_status = Utils::execute_command("debugfs.reiser4 " + Glib::shell_quote(partition.get_path()), + output, error, true); + if (exit_status != 0) { - long long blocks = -1; - Glib::ustring::size_type index = output.find( "\nblocks:" ); - if (index < output.length()) - sscanf(output.substr(index).c_str(), "\nblocks: %lld", &blocks); - - long long free_blocks = -1; - index = output .find( "\nfree blocks:" ) ; - if (index < output.length()) - sscanf(output.substr(index).c_str(), "\nfree blocks: %lld", &free_blocks); - - long long block_size = -1; - index = output .find( "\nblksize:" ) ; - if (index < output.length()) - sscanf(output.substr(index).c_str(), "\nblksize: %lld", &block_size); - - if (blocks > -1 && free_blocks > -1 && block_size > -1) - { - Sector fs_size = blocks * block_size / partition.sector_size; - Sector fs_free = free_blocks * block_size / partition.sector_size; - partition.set_sector_usage(fs_size, fs_free); - partition.fs_block_size = block_size; - } + if (! output.empty()) + partition.push_back_message(output); + if (! error.empty()) + partition.push_back_message(error); + return; } - else + + long long blocks = -1; + Glib::ustring::size_type index = output.find("\nblocks:"); + if (index < output.length()) + sscanf(output.substr(index).c_str(), "\nblocks: %lld", &blocks); + + long long free_blocks = -1; + index = output.find("\nfree blocks:"); + if (index < output.length()) + sscanf(output.substr(index).c_str(), "\nfree blocks: %lld", &free_blocks); + + long long block_size = -1; + index = output.find("\nblksize:"); + if (index < output.length()) + sscanf(output.substr(index).c_str(), "\nblksize: %lld", &block_size); + + if (blocks > -1 && free_blocks > -1 && block_size > -1) { - if ( ! output .empty() ) - partition.push_back_message( output ); - - if ( ! error .empty() ) - partition.push_back_message( error ); + Sector fs_size = blocks * block_size / partition.sector_size; + Sector fs_free = free_blocks * block_size / partition.sector_size; + partition.set_sector_usage(fs_size, fs_free); + partition.fs_block_size = block_size; } } + void reiser4::read_label( Partition & partition ) { if ( ! Utils::execute_command( "debugfs.reiser4 " + Glib::shell_quote( partition.get_path() ),