Refactor reiser4::set_used_sectors() into if fail return early pattern (!119)

Closes !119 -  Tidy-ups for file system interface classes
This commit is contained in:
Mike Fleetwood 2023-10-10 09:56:58 +01:00 committed by Curtis Gedak
parent 9364923d4a
commit 1f72c5f0e5
1 changed files with 32 additions and 31 deletions

View File

@ -64,44 +64,45 @@ FS reiser4::get_filesystem_support()
return fs ; 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() ), exit_status = Utils::execute_command("debugfs.reiser4 " + Glib::shell_quote(partition.get_path()),
output, error, true ) ) output, error, true);
if (exit_status != 0)
{ {
long long blocks = -1; if (! output.empty())
Glib::ustring::size_type index = output.find( "\nblocks:" ); partition.push_back_message(output);
if (index < output.length()) if (! error.empty())
sscanf(output.substr(index).c_str(), "\nblocks: %lld", &blocks); partition.push_back_message(error);
return;
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;
}
} }
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() ) Sector fs_size = blocks * block_size / partition.sector_size;
partition.push_back_message( output ); Sector fs_free = free_blocks * block_size / partition.sector_size;
partition.set_sector_usage(fs_size, fs_free);
if ( ! error .empty() ) partition.fs_block_size = block_size;
partition.push_back_message( error );
} }
} }
void reiser4::read_label( Partition & partition ) void reiser4::read_label( Partition & partition )
{ {
if ( ! Utils::execute_command( "debugfs.reiser4 " + Glib::shell_quote( partition.get_path() ), if ( ! Utils::execute_command( "debugfs.reiser4 " + Glib::shell_quote( partition.get_path() ),