1
0
mirror of https://gitlab.gnome.org/GNOME/gparted synced 2024-06-30 23:05:09 +00:00

Compare commits

...

4 Commits

Author SHA1 Message Date
Mike Fleetwood
69fa0beaba Use Glib::build_path() to simplify remove_non_empty_lvm2_pv_dialog()
Simplify code in Win_GParted::remove_non_empty_lvm2_pv_dialog() by
replacing open coded concatenation of a vector of strings using a new
line separator with a call to Glib::build_path().
2024-04-11 08:21:05 +01:00
Mike Fleetwood
e03fb23359 Stop assigning a zero length string when constructing them
Most of the code doesn't assign a zero length string when constructing a
string object.  However there were a few places where it did.  This is
unnecessary because Glib::ustring [1] and std::string [2] objects are
constructed as the the empty string by default.

[1] Glib::ustring::ustring()
    https://developer-old.gnome.org/glibmm/stable/classGlib_1_1ustring.html#a71802782f4c2c408ef7ac69c6564b370
        "Glib::ustring::ustring()
        Default constructor, which creates an empty string.
        "
[2] std::string::string
    https://cplusplus.com/reference/string/string/string/
        "(1) empty string constructor (default constructor)
        Constructs an empty string, with a length of zero characters.
        "
2024-04-11 08:21:05 +01:00
Mike Fleetwood
7b047ec6e8 Drop the 2 decimal places when printing values in bytes
When printing a number of bytes using Utils::format_size() it always
formatted the value with 2 decimal digits and an IEC multiplier.  This
can be seen in the details of any operation which includes clearing old
file system signatures.  Fragment of operation details:
    Format /dev/sdb1 as cleared
    + calibrate /dev/sdb1
    + clear old file system signatures in /dev/sdb1
        write 512.00 KiB of zeros at byte offset 0
        write 4.00 KiB of zeros at byte offset 67108864
>>      write 512.00 B of zeros at byte offset 132537184
        write 4.00 KiB of zeros at byte offset 1072693248
        write 512.00 KiB of zeros at byte offset 133593440
        flush operating system cache of /dev/sdb1

It doesn't make sense to be reporting 100ths of a byte.  So when values
are below 1 KiB report numbers of bytes without any decimal digits.
2024-04-11 08:21:05 +01:00
Mike Fleetwood
26a3140d4b Query usage of multi-device bcachefs file systems correctly
Create an uneven used space multi-device bcachefs file system like this,
where sdb1 is about 1/2 used and sdb2 is almost empty:
    # bcachefs format /dev/sdb1
    # mount /dev/sdb1 /mnt/1
    # dd if=/dev/zero bs=1M count=512 of=/mnt/1/zeros.bin
    # bcachefs device add /mnt/1 /dev/sdb2

GParted reports both devices as having the same usage:
    Partition   File System   Mount Point   Size       Used         Unused       Flags
    /dev/sdb1   bcachefs      /mnt/1        1.00 GiB   526.00 MiB   498.00 MiB
    /dev/sdb2   bcachefs      /mnt/1        1.00 GiB   526.00 MiB   498.00 MiB

When in fact the used space is significantly different for each device:
    # bcachefs fs usage /mnt/1 | egrep ' \(device |free:|capacity:'
    (no label) (device 0):          sdb1              rw
      free:                    522190848            3984
      capacity:               1073741824            8192
    (no label) (device 1):          sdb2              rw
      free:                   1061945344            8102
      capacity:               1073741824            8192

This is because bcachefs::set_used_sectors() is always searching for the
first "free:" and "capacity:" figures.  Fix by reading the figures for
the correct device.
2024-04-11 08:20:43 +01:00
14 changed files with 54 additions and 33 deletions

View File

@ -210,12 +210,11 @@ void DMRaid::get_devices( std::vector<Glib::ustring> & device_list )
Glib::ustring DMRaid::get_dmraid_name( const Glib::ustring & dev_path )
{
//Retrieve name of dmraid device
Glib::ustring dmraid_name = "" ;
Glib::ustring regexp = "" ;
Glib::ustring dmraid_name;
for ( unsigned int k=0; k < dmraid_devices .size(); k++ )
{
regexp = ".*(" + dmraid_devices[k] + ").*" ;
Glib::ustring regexp = ".*(" + dmraid_devices[k] + ").*";
if ( Utils::regexp_label( dev_path, regexp ) == dmraid_devices[k] )
dmraid_name = dmraid_devices[k] ;
}
@ -256,7 +255,7 @@ void DMRaid::get_dmraid_dir_entries( const Glib::ustring & dev_path, std::vector
Glib::ustring dmraid_name = get_dmraid_name( dev_path ) ;
//Loop through the entries in the directory
Glib::ustring filename = "" ;
Glib::ustring filename;
Glib::Dir dir( DEV_MAPPER_PATH );
while ( ( filename = dir .read_name() ) != "" )
{
@ -277,9 +276,9 @@ int DMRaid::get_partition_number( const Glib::ustring & partition_name )
Glib::ustring DMRaid::get_udev_dm_name( const Glib::ustring & dev_path )
{
//Retrieve DM_NAME of device using udev information
Glib::ustring output = "" ;
Glib::ustring error = "" ;
Glib::ustring dm_name = "" ;
Glib::ustring output;
Glib::ustring error;
Glib::ustring dm_name;
if (udevadm_found)
Utils::execute_command( "udevadm info --query=all --name=" + Glib::shell_quote( dev_path ),

View File

@ -228,7 +228,7 @@ void Dialog_Partition_Info::Display_Info()
Sector ptn_sectors = partition .get_sector_length() ;
Glib::ustring vgname = "" ; //Also used in partition status message
Glib::ustring vgname;
if (filesystem_ptn.fstype == FS_LVM2_PV)
vgname = LVM2_PV_Info::get_vg_name( filesystem_ptn.get_path() );

View File

@ -1235,7 +1235,6 @@ FSType GParted_Core::detect_filesystem(const PedDevice *lp_device, const PedPart
{
g_assert(lp_device != nullptr); // Bug: Not initialised by call to ped_device_get() or ped_device_get_next()
Glib::ustring fsname = "";
Glib::ustring path;
DMRaid dmraid;
@ -1257,7 +1256,7 @@ FSType GParted_Core::detect_filesystem(const PedDevice *lp_device, const PedPart
// (Q2) FS_Info (blkid) file system detection
// Blkid detects more signatures and generally has less limitations so use before
// libparted detection, but it doesn't report anything for extended partitions.
fsname = FS_Info::get_fs_type( path );
Glib::ustring fsname = FS_Info::get_fs_type(path);
// (Q3) Libparted file system detection
// Only used when blkid didn't report anything and only on partitions, not whole

View File

@ -535,14 +535,17 @@ bool Utils::kernel_version_at_least( int major_ver, int minor_ver, int patch_ver
Glib::ustring Utils::format_size( Sector sectors, Byte_Value sector_size )
{
std::stringstream ss ;
ss << std::setiosflags( std::ios::fixed ) << std::setprecision( 2 ) ;
ss << std::setiosflags(std::ios::fixed);
if ( (sectors * sector_size) < KIBIBYTE )
{
ss << std::setprecision(0);
ss << sector_to_unit( sectors, sector_size, UNIT_BYTE ) ;
return Glib::ustring::compose( _("%1 B"), ss .str() ) ;
}
else if ( (sectors * sector_size) < MEBIBYTE )
ss << std::setprecision(2);
if (sectors * sector_size < MEBIBYTE)
{
ss << sector_to_unit( sectors, sector_size, UNIT_KIB ) ;
return Glib::ustring::compose( _("%1 KiB"), ss .str() ) ;

View File

@ -3322,7 +3322,7 @@ void Win_GParted::activate_change_uuid()
Gtk::MESSAGE_WARNING,
Gtk::BUTTONS_OK,
true );
Glib::ustring tmp_msg = "" ;
Glib::ustring tmp_msg;
for ( i = 1 ; filesystem_object->get_custom_text( CTEXT_CHANGE_UUID_WARNING, i ) != "" ; i++ )
{
if ( i > 1 )
@ -3563,18 +3563,8 @@ bool Win_GParted::remove_non_empty_lvm2_pv_dialog( const OperationType optype )
Gtk::Label *label_members = Utils::mk_label("<b>" + Glib::ustring(members_label) + "</b>",
true, false, false, Gtk::ALIGN_START);
grid->attach(*label_members, 0, 1, 1, 1);
Glib::ustring members_str = "" ;
if ( ! members .empty() )
{
for ( unsigned int i = 0 ; i < members .size() ; i ++ )
{
if ( i > 0 )
members_str += "\n" ;
members_str += members[i] ;
}
}
Gtk::Label *value_members = Utils::mk_label(members_str, true, false, true, Gtk::ALIGN_START);
Gtk::Label *value_members = Utils::mk_label(Glib::build_path("\n", members),
true, false, true, Gtk::ALIGN_START);
grid->attach(*value_members, 1, 1, 1, 1);
value_members->get_accessible()->add_relationship(Atk::RELATION_LABELLED_BY,
label_members->get_accessible());

View File

@ -16,6 +16,7 @@
#include "bcachefs.h"
#include "BlockSpecial.h"
#include "FileSystem.h"
#include "OperationDetail.h"
#include "Partition.h"
@ -73,6 +74,35 @@ void bcachefs::set_used_sectors(Partition& partition)
return;
}
// Example output:
// # bcachefs fs usage /mnt/1 | egrep ' \(device |free:|capacity:'
// (no label) (device 0): sdb1 rw
// free: 522190848 3984
// capacity: 1073741824 8192
// (no label) (device 1): sdb2 rw
// free: 1061945344 8102
// capacity: 1073741824 8192
//
// Substring the output down to just the device section for this partition.
BlockSpecial wanted = BlockSpecial(partition.get_path());
bool found = false;
Glib::ustring::size_type start_offset = output.find(" (device ");
while (start_offset != Glib::ustring::npos)
{
Glib::ustring device_name = Utils::regexp_label(output.substr(start_offset),
" \\(device [[:digit:]]+\\):[[:blank:]]+([[:graph:]]+)");
Glib::ustring::size_type end_offset = output.find(" (device ", start_offset + 9);
if (wanted == BlockSpecial("/dev/" + device_name))
{
output = output.substr(start_offset, end_offset - start_offset);
found = true;
break;
}
start_offset = end_offset;
}
if (! found)
return;
// Device specific free space in bytes
long long dev_free_bytes = -1;
Glib::ustring::size_type index = output.find("free:");

View File

@ -128,7 +128,7 @@ bool f2fs::create( const Partition & new_partition, OperationDetail & operationd
bool f2fs::resize(const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition)
{
Glib::ustring size = "";
Glib::ustring size;
if (! fill_partition)
// resize.f2fs works in sector size units of whatever device the file
// system is currently stored on.

View File

@ -209,7 +209,7 @@ void fat16::read_label(Partition& partition)
bool fat16::write_label( const Partition & partition, OperationDetail & operationdetail )
{
Glib::ustring cmd = "" ;
Glib::ustring cmd;
if ( partition.get_filesystem_label().empty() )
cmd = "mlabel -c -i " + Glib::shell_quote(partition.get_path()) + " ::";
else

View File

@ -57,7 +57,7 @@ FS hfs::get_filesystem_support()
bool hfs::create( const Partition & new_partition, OperationDetail & operationdetail )
{
Glib::ustring cmd = "";
Glib::ustring cmd;
if( new_partition.get_filesystem_label().empty() )
cmd = "hformat " + Glib::shell_quote( new_partition.get_path() );
else

View File

@ -55,7 +55,7 @@ FS hfsplus::get_filesystem_support()
bool hfsplus::create( const Partition & new_partition, OperationDetail & operationdetail )
{
Glib::ustring cmd = "";
Glib::ustring cmd;
if( new_partition.get_filesystem_label().empty() )
cmd = "mkfs.hfsplus " + Glib::shell_quote( new_partition.get_path() );
else

View File

@ -151,7 +151,7 @@ bool luks::resize( const Partition & partition_new, OperationDetail & operationd
}
}
Glib::ustring size = "";
Glib::ustring size;
if ( ! fill_partition )
// Cryptsetup resize takes the size of the encryption mapping, not the
// size of the underlying block device. Both device-mapper and cryptsetup

View File

@ -105,7 +105,7 @@ bool lvm2_pv::create( const Partition & new_partition, OperationDetail & operati
bool lvm2_pv::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
Glib::ustring size = "" ;
Glib::ustring size;
if ( ! fill_partition )
size = " --yes --setphysicalvolumesize " +
Utils::num_to_str(partition_new.get_byte_length() / KIBIBYTE) + "K ";

View File

@ -190,7 +190,7 @@ bool ntfs::create( const Partition & new_partition, OperationDetail & operationd
bool ntfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
bool success;
Glib::ustring size = "" ;
Glib::ustring size;
if ( ! fill_partition )
size = " -s " + Utils::num_to_str(partition_new.get_byte_length());
Glib::ustring cmd = "ntfsresize --force --force" + size ;

View File

@ -176,7 +176,7 @@ bool reiserfs::create( const Partition & new_partition, OperationDetail & operat
bool reiserfs::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )
{
Glib::ustring size = "" ;
Glib::ustring size;
if ( ! fill_partition )
size = " -s " + Utils::num_to_str(partition_new.get_byte_length());
const Glib::ustring resize_cmd = "echo y | resize_reiserfs" + size +