1
0
mirror of https://gitlab.gnome.org/GNOME/gparted synced 2024-07-02 15:58:47 +00:00

Compare commits

..

5 Commits

Author SHA1 Message Date
Mike Fleetwood
ac4f391080 Merge branch 'bcachefs-single' into 'master'
Draft: Add support for bcachefs, single device file systems only

See merge request GNOME/gparted!123
2024-04-11 07:23:57 +00:00
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

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:");