Refactor xfs::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 10:52:31 +01:00 committed by Curtis Gedak
parent a603828275
commit 5a6b8afc53
1 changed files with 34 additions and 34 deletions

View File

@ -98,47 +98,47 @@ FS xfs::get_filesystem_support()
return fs ;
}
void xfs::set_used_sectors( Partition & partition )
void xfs::set_used_sectors(Partition& partition)
{
if ( ! Utils::execute_command( "xfs_db -r -c 'sb 0' -c 'print blocksize' -c 'print dblocks'"
" -c 'print fdblocks' " + Glib::shell_quote( partition.get_path() ),
output, error, true ) )
exit_status = Utils::execute_command("xfs_db -r -c 'sb 0' -c 'print blocksize' -c 'print dblocks'"
" -c 'print fdblocks' " + Glib::shell_quote(partition.get_path()),
output, error, true);
if (exit_status != 0)
{
//blocksize
long long block_size = -1;
sscanf(output.c_str(), "blocksize = %lld", &block_size);
//filesystem blocks
long long data_blocks = -1;
Glib::ustring::size_type index = output.find( "\ndblocks" );
if (index < output.length())
sscanf(output.substr(index).c_str(), "\ndblocks = %lld", &data_blocks);
//free blocks
long long free_data_blocks = -1;
index = output .find( "\nfdblocks" ) ;
if (index < output.length())
sscanf(output.substr(index).c_str(), "\nfdblocks = %lld", &free_data_blocks);
if (block_size > -1 && data_blocks > -1 && free_data_blocks > -1)
{
Sector fs_size = data_blocks * block_size / partition.sector_size;
Sector fs_free = free_data_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
// blocksize
long long block_size = -1;
sscanf(output.c_str(), "blocksize = %lld", &block_size);
// filesystem data blocks
long long data_blocks = -1;
Glib::ustring::size_type index = output.find("\ndblocks");
if (index < output.length())
sscanf(output.substr(index).c_str(), "\ndblocks = %lld", &data_blocks);
// free data blocks
long long free_data_blocks = -1;
index = output.find("\nfdblocks");
if (index < output.length())
sscanf(output.substr(index).c_str(), "\nfdblocks = %lld", &free_data_blocks);
if (block_size > -1 && data_blocks > -1 && free_data_blocks > -1)
{
if ( ! output .empty() )
partition.push_back_message( output );
if ( ! error .empty() )
partition.push_back_message( error );
Sector fs_size = data_blocks * block_size / partition.sector_size;
Sector fs_free = free_data_blocks * block_size / partition.sector_size;
partition.set_sector_usage(fs_size, fs_free);
partition.fs_block_size = block_size;
}
}
void xfs::read_label( Partition & partition )
{
if ( ! Utils::execute_command( "xfs_db -r -c 'label' " + Glib::shell_quote( partition.get_path() ),