Commit Graph

1516 Commits

Author SHA1 Message Date
Mike Fleetwood 80d6394684 Remove deprecated Glib::thread_init() (!22)
Use of Glib::thread_init() was deprecated in glibmm 2.32 [1].  The
oldest supported distributions have these versions:
    Debian 8           glibmm 2.42.0
    RHEL / CentOS 7    glibmm 2.56.0
    SLES 12            glibmm 2.38.1
    Ubuntu 14.04 LTS   glibmm 2.39.93

Checking further the glibmm 2.32 reference manual says this about
Glib::thread_init() [2]:
    Initializes the GLib thread system.

    Deprecated:
    Calling thread_init() is no longer necessary and no longer has any
    effect.

However only some of the glibmm example programs had Glib::thread_init()
removed, others had it replaced by Glib::init() [3].  Again the glibmm
2.32 reference manual says this about Glib::init() [4]:
    Initialize glibmm.

    You may call this more than once.  You do not need to call this if
    you are using Glib::MainLoop or Gtk::Main, because they call it for
    you.

GParted does call Gtk::Main and test_PipeCapture does call
Glib::MainLoop.  Therefore just raise the minimum version to glibmm 2.32
and remove both calls to Glib::thread_init().

[1] Glibmm 2.32 NEWS file
    https://gitlab.gnome.org/GNOME/glibmm/blob/2.32.0/NEWS#L207

[2] glibmm 2.32, glibmm: Glib Namespace Reference, Glib::thread_init()
    https://developer.gnome.org/glibmm/2.32/namespaceGlib.html#ab26d01c776801f1fff00753e97af4fc7

[3] glibmm commit "Avoid use of deprecates API in tests and examples."
    3e0fbb22c0

[4] glibmm 2.32, glibmm: Glib Namespace Reference, Glib::init()
    https://developer.gnome.org/glibmm/2.32/namespaceGlib.html#ac90aee10d0b90e3d8a96a86b5394f87b

Closes !22 - Increase minimums to libparted 2.2 and glibmm 2.32
2019-01-21 16:41:31 +00:00
Mike Fleetwood 8df975c7d1 Increase minimum required libparted to 2.2 (!22)
Raise the minimum required version of GNU Parted from 1.7.1 to 2.2,
released 2010-02-16 [1][2].  The oldest supported distributions, also
with gtkmm >= 2.24, since commit [3], are:
    Debian 8           parted 3.2
    RHEL / CentOS 7    parted 3.1
    SLES 12            parted 3.1
    Ubuntu 14.04 LTS   parted 2.3

Raising the minimum required version allows removal of optional code
associated with these definitions:
*   USE_LIBPARTED_LARGE_SECTOR_SUPPORT
    Fallback code reporting ignored device with logical sector size
    other than 512 bytes.
*   ENABLE_PT_REREAD_WORKAROUND
    Fallback code re-attempting to inform the kernel of partition
    changes.

[1] GNU Parted 2.2 release announcement
    http://lists.gnu.org/archive/html/info-gnu/2010-02/msg00016.html

[2] NEWS file from GNU Parted 2.2
    http://git.savannah.gnu.org/cgit/parted.git/tree/NEWS?h=v2.2

[3] 8b42bab1ee
    modern-gtk2: Require Gtkmm version 2.24 (!17)

Closes !22 - Increase minimums to libparted 2.2 and glibmm 2.32
2019-01-21 16:41:31 +00:00
Mike Fleetwood c421bcbff6 Strip unnecessary scope from GParted::STAT_* (!20)
The code inconsistently uses GParted:: scope in front of STAT_*.

    $ fgrep 'GParted::STAT_' src/*.cc | wc -l
    3
    $ egrep '[^:]STAT_' src/*.cc | wc -l
    41

GParted:: scope resolution is unnecessary as all the code is inside the
GParted scope, except for main().  So remove it.

Closes !20 - Minor namespace and scope operator tidy-ups
2018-11-26 17:56:32 +00:00
Mike Fleetwood 2bbe7fcc45 Strip unnecessary scope from GParted::TYPE_* (!20)
The code inconsistently uses GParted:: scope in front of TYPE_*.

    $ fgrep 'GParted::TYPE_' src/*.cc | wc -l
    35
    $ egrep '[^:]TYPE_' src/*.cc | wc -l
    83

GParted:: scope resolution is unnecessary as all the code is inside the
GParted scope, except for main().  So remove it.

Closes !20 - Minor namespace and scope operator tidy-ups
2018-11-26 17:56:32 +00:00
Mike Fleetwood e0b6d2c65b Strip unnecessary scope from GParted::FS_* (!20)
The code inconsistently uses GParted:: scope in front of FS_*.

    $ fgrep 'GParted::FS_' src/*.cc | wc -l
    41
    $ egrep '[^:]FS_' src/*.cc | wc -l
    441

GParted:: scope resolution is unnecessary as all the code is inside the
GParted namespace, except for main().  So remove it.

Closes !20 - Minor namespace and scope operator tidy-ups
2018-11-26 17:56:32 +00:00
Mike Fleetwood 7f23761964 Strip unnecessary scope from GParted::FS::* (!20)
The code inconsistency uses GParted::FS::* and FS::*.

    $ fgrep 'GParted::FS::' src/*.cc | wc -l
    97
    $ egrep '[^:]FS::' src/*.cc | wc -l
    152

GParted:: scope resolution is unnecessary as all the code is inside the
GParted namespace, except for main().  So remove it.

Closes !20 - Minor namespace and scope operator tidy-ups
2018-11-26 17:56:32 +00:00
Mike Fleetwood 2c10dd2caa Put Frame_Resizer_{Base,Extended} modules into GParted namespace (!20)
All the other modules are in the GParted namespace, except for main()
which has to be in the global namespace, so put these in the GParted
namespace too.

Closes !20 - Minor namespace and scope operator tidy-ups
2018-11-26 17:56:32 +00:00
Mike Fleetwood b9d3638a12 Fix false usage figures for busy SWRAID members (#27)
Create an active Linux Software RAID member which is larger than /dev
virtual file system and GParted will report the usage figure of the /dev
virtual file system for the SWRAID member.

    # df -h /dev
    Filesystem      Size  Used Avail Use% Mounted on
    devtmpfs        732M     0  732M   0% /dev
    # sgdisk -n 1:1M:+1G /dev/sdb
    # mdadm --create --verbose /dev/md1 --level=linear --raid-devices=1 --force /dev/sdb1
    mdadm: Defaulting to version 1.2 metadata
    mdadm: array /dev/md1 started.

GParted reports the usage of /dev/sdb1 as:
    Partition  Mount Point  Size     Used   Unused     Unallocated
    /dev/sdb1  /dev/md1     1.00GiB  0.00B  731.04MiB  292.96MiB

However GParted should have reported the usage as "---" for unknown
because it isn't coded to query the size of the SWRAID member within a
partition.

The fault has been bisected to this commit:
    Extend un/mounting and usage reporting to unsupported file systems (!13)
    95903efb1f

What happens for busy Linux Software RAID array members:
*   GParted_Core::is_busy()
    has custom code to identify busy members.
*   GParted_Core::set_mountpoints()
    has custom code to add the array device name as the "mount point" of
    the member.
*   GParted_Core::set_used_sectors()
    falls into the else not a supported file system (because SWRAID
    doesn't have a derived FileSystem implementation class).
*   GParted_Core::mounted_set_used_sectors()
    is called to get the file system usage of mounted, but unsupported
    file systems, such as UFS and any others.
*   Utils::get_mounted_filesystem_usage()
    is called which queries the kernel using statvfs() and gets the file
    system usage of the /dev virtual file system because the array
    device name will always start /dev.

Fix by ensuring that GParted only asks the kernel for the usage of paths
which it knows are mount points of mounted file systems.  (As read from
/proc/mounts and cached in the Mount_Info module).  Also rename the
method, by inserting "_fs", to mounted_fs_set_used_sectors() to remind
us that it is for mounted *file systems* only.

Closes #27 - GParted may report incorrect usage for SWRAID partitions
             instead of unknown

S
2018-11-19 16:43:29 +00:00
Mike Fleetwood 4b341c8dd9 Recognise contribution by Luca Bacci 2018-11-12 21:50:42 +00:00
Luca Bacci 2fad309601 modern-gtk2: Use Cairo for drawing the partition visualizer (!17)
Third commit in a series to convert Gdk::GC based drawing to Cairo based
drawing.  This specific commit makes the transition for the graphical
partition visualizer widget that is used in the main application window.

Closed !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 7fd39932a3 modern-gtk2: Use Cairo for drawing the partition info (!17)
Second commit in a series to convert Gdk::GC based drawing to Cairo
based drawing.  This specific commit makes the transition for the
graphical partition info widget that is used in the "Information about"
dialog.

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci d17d129044 modern-gtk2: Use Cairo for drawing the partition resizer (!17)
GdkGC has been deprecated in the underlying C / GTK+ 2.22 library.  It
is less clearly stated but Gdk::GC is also deprecated in C++ / gtkmm.
Cairo based rendering should be used instead.
https://developer.gnome.org/gtk3/stable/gtk-migrating-2-to-3.html
https://gitlab.gnome.org/GNOME/gtk/blob/2.22.0/NEWS#L124
https://developer.gnome.org/gtkmm/2.24/classGdk_1_1GC.html

First commit in a series to convert Gdk::GC based drawing to Cairo based
drawing.  This specific commit makes the transition for the graphical
partition resizing widget that is used in the "Create New Partition",
"Paste" creating new partition and "Resize/Move" dialogs.

Cairo is not pixel based but instead uses a continuous coordinate space.
To draw in a pixel aligned way follow the guidance in the Cairo FAQ.
https://www.cairographics.org/FAQ/#sharp_lines

Additional references:
https://developer.gnome.org/gdk2/stable/gdk2-Drawing-Primitives.html#gdk-draw-line
https://developer.gnome.org/gdk2/stable/gdk2-Drawing-Primitives.html#gdk-draw-rectangle

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci c602170faa modern-gtk2: Delay construction of Gtk::TreeModel* objects (!17)
C++ initialises static member variables before main() is called.
Therefore the static members of:
    struct Slots
    {
        static Gtk::TreeModelColumn<Glib::ustring> text;
        static Gtk::TreeModelColumn<bool> sensitive;
    private:
        static Gtk::TreeModel::ColumnRecord record_;
    };
are constructed before Gtk::Main() is called in main().  However the
Gtkmm documentation specifically says that they must be constructed
afterwards [1].

Resolve this by using the Construct On First Use Idiom [2] to delay
initialisation until the slots are first used.  Normally this idiom uses
static local objects, however it is being applied to class static
objects here because the objects are accessed in many methods.  The
downside of this approach is that the objects are never destructed,
which memory analysers like Valgrind could see as a memory leak, but
that is actually deliberate.  That leak can be removed once we can use
C++11 and std::unique_ptr.

[1] gtkmm: Gtk::TreeModelColumnRecord Class Reference
    https://developer.gnome.org/gtkmm/2.24/classGtk_1_1TreeModelColumnRecord.html#details

    "Neither TreeModel::ColumnRecord nor the TreeModelColumns contain
    any real data - they merely describe what C++ type is stored in
    which column of a TreeModel, and save you from having to repeat that
    type information in several places.

    Thus TreeModel::ColumnRecord can be made a singleton (as long as you
    make sure it's instantiated after Gtk::Main), even when creating
    multiple models from it.
    "

[2] C++ FAQ / How do I prevent the "static initialization order
    problem"?
    https://isocpp.org/wiki/faq/ctors#static-init-order-on-first-use

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 6bfa95d427 modern-gtk2: Rename callback after OptionComboBox class switch (!17)
Final part in a series of commits to replace Gtk::OptionMenu widgets
with GParted::OptionComboBox.

This specific commit renames the signal handler callback to match the
previously renamed combobox widget variable names.

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 48d2fd2120 modern-gtk2: Use OptionComboBox class for file system combobox (!17)
Third part in a series of commits to replace Gtk::OptionMenu widgets
with GParted::OptionComboBox.

This specific commit is about file system combobox.

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci cf5e9c863f modern-gtk2: Use OptionComboBox class for partition type combobox (!17)
Second part in a series of commits to replace Gtk::OptionMenu widgets
with GParted::OptionComboBox.

This specific commit is about partition type combobox.

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 83b98885f6 modern-gtk2: Use OptionComboBox class for alignment combobox (!17)
First part in a series of commits to replace Gtk::OptionMenu widgets
with GParted::OptionComboBox.

This specific commit is about partition alignment combobox.

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 5407e8346b modern-gtk2: Introduce OptionComboBox class (!17)
Gtk::OptionMenu is a combobox type widget that is constructed from a
Gtk::Menu rather than a Gtk::TreeModel.  However Gtk::OptionMenu was
deprecated in gtkmm 2.4.1.

In GParted the Gtk::OptionMenu widget is used for:
- partition alignment combobox
- partition type combobox
- file system combobox

While they consist only of text we cannot use Gtk::ComboBoxText because
it doesn't expose functionality in its interface to make items inactive.

Create OptionComboBox helper class that builds a combobox consisting of
only text items, much like Gtk::ComboBoxText, but has the added
functionality to set items as inactive.

References:
https://developer.gnome.org/gtkmm/2.24/classGtk_1_1OptionMenu.html#details
https://gitlab.gnome.org/GNOME/gtkmm/blob/GTKMM_2_10_1/ChangeLog#L3515
bba503b047
https://developer.gnome.org/gtkmm/2.24/classGtk_1_1ComboBoxText.html

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 430ac9240c modern-gtk2: Use Gtk::Widget::set_tooltip_text() (!17)
GParted was using Gtk::Tooltips widgets for tooltips, but they were
deprecated in gtkmm 2.12 in favour of Gtk::Tooltip widgets.  (Note the
spelling difference, with and without a trailing 's').

As GParted's tooltips are all text only continue to use the shortcut,
which is now Gtk::Widget::set_tooltip_text().

References:
https://developer.gnome.org/gtkmm/2.24/classGtk_1_1Tooltips.html#details
https://developer.gnome.org/gtkmm/2.24/classGtk_1_1Tooltip.html#details
https://gitlab.gnome.org/GNOME/gtkmm/blob/2.20.0/NEWS#L740

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 6a80ca8f7d modern-gtk2: Use Gtk::MenuItem::unset_submenu() (!17)
Gtk::MenuItem::remove_submenu() was deprecated in gtkmm 2.12.  Replace
with Gtk::MenuItem::unset_submenu() introduced in gtkmm 2.22.

References:
https://developer.gnome.org/gtkmm/2.24/classGtk_1_1MenuItem.html
https://gitlab.gnome.org/GNOME/gtkmm/blob/2.22.0/NEWS#L24

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 511d597188 modern-gtk2: Use Gtk::AboutDialog::set_program_name() (!17)
Gtk::AboutDialog::set_name() was deprecated in gtkmm 2.12.  Replace with
Gtk::AboutDialog::set_program_name().

References:
https://developer.gnome.org/gtkmm/2.24/classGtk_1_1AboutDialog.html
https://gitlab.gnome.org/GNOME/gtkmm/blob/2.20.0/NEWS#L741

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 3d6ee55606 modern-gtk2: Use Gtk::AlignmentEnum::ALIGN_START (!17)
Gtkmm 2.22 deprecated Gtk::AlignmentEnum::ALIGN_{LEFT,RIGHT,TOP,BOTTOM}
replacing with Gtk::AlignmentEnum::ALIGN_{START,END}.

References:
https://developer.gnome.org/gtkmm/2.24/group__gtkmmEnums.html#ga98983d4e80f67ffa5148dd554706ffac
https://gitlab.gnome.org/GNOME/gtkmm/blob/2.22.0/NEWS#L14

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 197c88ad73 modern-gtk2: Use Gtk::TreeView::Column::get_first_cell() (!17)
Gtk::TreeView::Column::get_first_cell_renderer() was deprecated in
gtkmm 2.24.  Replace with Gtk::TreeView::Column::get_first_cell().

References:
https://developer.gnome.org/gtkmm/2.24/classGtk_1_1TreeViewColumn.html
https://gitlab.gnome.org/GNOME/gtkmm/blob/2.24.0/NEWS#L64

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 3f18318304 modern-gtk2: Use Gtk::ComboBoxText::append() (!17)
Gtk::ComboBoxText::append_text() was deprecated in gtkmm 2.24.  Replace
with Gtk::ComboBoxText::append().

References:
https://developer.gnome.org/gtkmm/2.24/classGtk_1_1ComboBoxText.html
https://gitlab.gnome.org/GNOME/gtkmm/blob/2.24.0/NEWS#L20

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci c0aa3dbfdf modern-gtk2: Always use Gtk::MessageDialog::get_message_area() (!17)
Remove check for Gtk::Messagedialog::get_message_area() and associated
fallback code as it is always available from gtkmm 2.22.

Reference:
https://gitlab.gnome.org/GNOME/gtkmm/blob/2.22.0/NEWS#L25

Closes !17 - Gtk2 modernisation
2018-11-12 21:50:42 +00:00
Luca Bacci 1f54ab6b12 Use Gtk::Viewport wrapper class
There is a GtkViewport wrapper class in gtkmm, Gtk::Viewport.  Make use
of that class instead of direct gtk calls.

Reference:
https://developer.gnome.org/gtkmm/2.24/classGtk_1_1Viewport.html
2018-11-12 21:50:42 +00:00
Mike Fleetwood dfb7d3e581 Enhance comment about the 3 levels of file system support
Add a little extra explaining how the file systems' supported actions
are determined.
2018-11-12 13:53:10 -07:00
Mike Fleetwood a0f97bfa19 Improve translation help for "unformatted" file system type 2018-11-12 13:53:04 -07:00
Mike Fleetwood 8a4f9ad205 Adjust shades of aquamarine, cyan and orange
The shades of aquamarine, cyan and orange didn't fit with the GNOME
32-colour palette.  Create a set of aquamarine, cyan and orange shades
which match the GNOME palette shades and update the colours of the
relevant file systems accordingly.
    Aquamarine Hilight (#97DFC7) -
    Aquamarine Medium  (#70D2B1) - NTFS
    Aquamarine Dark    (#3EA281) - REFS
    Aquamarine Shadow  (#1F7258) -
    Cyan Hilight       (#95E3E5) - EXTENDED
    Cyan Medium        (#6FCECE) -
    Cyan Dark          (#3C9899) -
    Cyan Shadow        (#166F70) -
    Orange Hilight     (#E59F6A) -
    Orange Medium      (#E58749) - BTRFS
    Orange Dark        (#C26825) - ZFS
    Orange Shadow      (#984F18) -

Note that the hues of aquamarine and cyan are quite close and for the
thin outlines of partitions used in GParted they aren't easy to
distinguish.  Hence also using different lightness to additionally
separate the colour for extended partitions from NTFS and ReFS file
systems.
2018-11-12 20:39:55 +00:00
Mike Fleetwood 69c1537a38 Recognise APFS (Apple File System) (#23)
Just add detection of APFS using GParted's internal magic string
detection.  It just matches 1 byte of the 2 byte object type and the
4 byte magic field found in the super block [1].  See code comment for
more details.

Blkid has just gained recognition of APFS with util-linux v2.33 released
06-Nov-2018 [2].

This will write enough for GParted's simple internal detection to find
APFS:
    # python -c '
    import sys
    sys.stdout.write("\0"*24 + "\1\0" + "\0"*6 + "NXSB")
    ' > /dev/sdb1

[1] Apple File System Reference
    https://developer.apple.com/support/apple-file-system/Apple-File-System-Reference.pdf

[2] [ANNOUNCE] util-linux v2.33
    https://marc.info/?l=linux-fsdevel&m=154150400305928&w=2

Closes #23 - GParted doesn't detect APFS (Apple File System)
2018-11-12 20:39:55 +00:00
Mike Fleetwood 893b67e2b8 Switch HFS and HFS Plus colours to a magenta range (#23)
Currently Linux Swap, Linux Suspend, and HFS use reds from the GNOME
32-colour palette with HFS Plus using serene red outside that palette.
    HFSPLUS       - Serene Red
    HFS           - Red Hilight
    LINUX_SWAP    - Red Medium
    LINUX_SUSPEND - Red Dark
                  - Red Shadow

Apple have a new file system, APFS (Apple File System), which is a
successor to HFS Plus [1][2].  With HFS Plus using a colour outside the
GNOME 32-colour palette and there not being enough distinct reds
available for a new file system, create a new range of magenta colours
which fit with the GNOME palette and use them for the group of Apple
file systems.
    Magenta Hilight (#D59FD4) - HFS
    Magenta Medium  (#B173B0) - HFSPLUS
    Magenta Dark    (#874986) - APFS
    Magenta Shadow  (#662C64) -

This commit just moves HFS and HFS Plus to their new magenta colours.

[1] About Apple File System
    https://developer.apple.com/documentation/foundation/file_system/about_apple_file_system

    "Overview
    Apple File System replaces HFS Plus as the default file system for
    iOS 10.3 and later, and for macOS High Sierra and later.  Apple File
    System offers improved file system fundamentals as well as several
    new features, including cloning, snapshots, space sharing, fast
    directory sizing, atomic safe-save, and sparse files.
    "

[2] Apple File System Reference
    https://developer.apple.com/support/apple-file-system/Apple-File-System-Reference.pdf

    "About Apple File System
    Apple File System is the default file format used on Apple
    platforms.  Apple File System is the successor to HFS Plus, so some
    aspects of its design intentionally follow HFS Plus to enable data
    migration from HFS Plus to Apple File System.  Other aspects of its
    design address limitations with HFS Plus and enable features such as
    cloning files, snapshots, encryption, and sharing free space between
    volumes.
    "

Closes #23 - GParted doesn't detect APFS (Apple File system)
2018-11-12 20:39:55 +00:00
Mike Fleetwood 39d3cd97c2 Disallow resizing btrfs if any of it's mount points are read-only (#10)
No other file system allows this, but btrfs allows simultaneous mounting
with different read-write permission.  Further, btrfs allows resizing
via read-write mounts, but not via read-only mounts.

    # mkfs.btrfs /dev/sdb1
    btrfs-progs v4.15.1
    ...
    Filesystem size:    512.00MiB
    ...
    Number of devices:  1
    Devices:
       ID        SIZE  PATH
        1   512.00MiB  /dev/sdb1

    # mount -o ro /dev/sdb1 /mnt/1
    # mount -o rw /dev/sdb1 /mnt/2
    # grep sdb1 /proc/mounts
    /dev/sdb1 /mnt/1 btrfs ro,relatime,space_cache,subvolid=5,subvol=/ 0 0
    /dev/sdb1 /mnt/2 btrfs rw,relatime,space_cache,subvolid=5,subvol=/ 0 0

    # btrfs filesystem resize 1:500M /mnt/1
    Resize '/mnt/1' of '1:500M'
    ERROR: unable to resize '/mnt/1': Read-only file system
    # echo $?
    1

    # btrfs file system resize 1:500M /mnt/2
    Resize '/mnt/2' of '1:500M'
    # echo $?
    0
    # btrfs filesystem show /dev/sdb1
    Label: none  uuid: 74ccd37a-e665-4f25-b77e-a305b8a025e9
            Total devices 1 FS bytes used 128.00KiB
            devid    1 size 500.00MiB used 88.00MiB path /dev/sdb1

Also with the above order of the read-only mount listed in /proc/mounts
first and the read-write mount second, GParted again allows a resize
operational to be tried, but if fails just like before:

    Grow /dev/sdb1 from 512.00 MiB to 1.0 GiB                  (ERROR)
    * calibrate /dev/sdb1                                      (SUCCESS)
    * grow partition from 512.00 MiB to 1.00 GiB               (SUCCESS)
    * grow filesystem to fill the partition                    (ERROR)
      * btrfs filesystem resize 1:max '/mnt/1'                 (ERROR)
          Resize '/mnt/1 to '1:max'
          ERROR: unable to resize '/mnt/1': Read-only file system

What happened is that the Mount_Info module only stores single read-only
flag against the mounted block device, not for each mount point, and as
the first and second sdb1 lines from /proc/mounts were processed, the
MountEntry became:

  1st)   mount_info[BS("/dev/sdb1")] -> {true , ["/mnt/1"]
  2nd)   mount_info[BS("/dev/sdb1")] -> {false, ["/mnt/1", "/mnt/2"]

So GParted thought the file system was mounted read-write, but used the
first mount point, /mnt/1, which was mounted read-only.

This is a very unusual situation so unlikely to be encountered by users.
Fix simply and safely by treating the mounted block device as mounted
read-only if any of the mount points are mounted read-only, rather than
just the last processed mount point.

Closes #10 - Gparted fails to resize btrfs partition that is mounted
             read-only
2018-09-20 16:30:15 +00:00
Mike Fleetwood f8512506ae Prevent online resizing of file systems mounted read-only (#10)
Resizing a file system mounted read-only fails.  Example:

    # mkfs.btrfs /dev/sdb1
    # mount -o ro /dev/sdb1 /mnt/1

In GParted try to resize partition sdb1.  The operation fails like this:

    Grow /dev/sdb1 from 512.00 MiB to 1.00 GiB                 (ERROR)
    * calibrate /dev/sdb1                                      (SUCCESS)
    * grow partition from 512.00 MiB to 1.00 GiB               (SUCCESS)
    * grow filesystem to fill the partition                    (ERROR)
      * btrfs filesystem resize 1:max '/mnt/1'                 (ERROR)
          Resize '/mnt/1' of '1:max'
          ERROR: unable to resize '/mnt/1': Read-only file system

See GitLab issue for the testing results of attempting to online resize
all supporting file system while mounted read-only.  No file system
allows online resizing while mounted read-only, except for reiserfs.
    Issue #10 - Gparted fails to resize btrfs partition that is mounted
    read-only
    https://gitlab.gnome.org/GNOME/gparted/issues/10

Fix by preventing online resizing of *all* file systems mounted
read-only, including reiserfs.  Instead of displaying the resize dialog
in this case, display an information dialog explaining why the partition
can't be resized.  This is similar to what happens when attempting to
create a new partition on a disk without a partition table.  The new
dialog looks like:

    (!) Unable to resize read-only file system /dev/sdb1
        The file system can not be resized while it is mounted read-only.
        Either unmount the file system or remount it read-write.
                                                                   [ OK ]

Closes #10 - Gparted fails to resize btrfs partition that is mounted
             read-only
2018-09-20 16:30:15 +00:00
Mike Fleetwood c82883d6a7 Add and set read-only mount flag in the Partition object (#10)
Set the partition read-only mount flag at the same time as setting the
file system mount points.

Closes #10 - Gparted fails to resize btrfs partition that is mounted
             read-only
2018-09-20 16:30:15 +00:00
Mike Fleetwood 441b39347a Add parsing of read-only mount option into mount maps (#10)
Parse file system mount options string from file and mount command
output, extracting the setting for the read-only flag and storing in the
mount maps.  Read-only flag for swap space gets the struct MountEntry
constructor default of false.

Closes #10 - Gparted fails to resize btrfs partition that is mounted
             read-only
2018-09-20 16:30:15 +00:00
Mike Fleetwood f4994a2b63 Add read-only flag to mounted file system entries (#10)
Just updates the 2 maps in the Mount_Info module so that they also have
a read-only flag for each mount.  Ensure that when a struct MountEntry
is created the readonly bool POD (Plain Old Data) type is initialised by
the constructor.  Nothing yet sets or uses the flag.

Closes #10 - Gparted fails to resize btrfs partition that is mounted
             read-only
2018-09-20 16:30:15 +00:00
Mike Fleetwood df0d4c870b White space tidy-up of Utils::get_filesystem_string()
Use smart tab alignment, list cases in enumeration order and update
translation help for unallocated space.
2018-09-17 15:36:09 +00:00
Mike Fleetwood 18bac7c927 Replace open coding FS unknown usage check in prepare_new_partition()
Back when unallocated space handling was being added, this case was not
converted from open coding to using the provided method to check for
unknown file system usage.  Specifically this commit missed using
Partition::sector_usage_known() in
Dialog_Base_Partition::prepare_new_partition():

    7ebedc4bb3
    Don't show intrinsic unallocated space (#499202)

Fix it now.
2018-09-17 15:36:09 +00:00
Mike Fleetwood 9c35d91453 Refactor get_filesystem_object()
The function was using std::map::count() [1] to test if the file system
entry existed in the map before looking up the value using
std::map::operator[] to avoid having operator[] inserting elements which
don't exist [2].

Rewrite using std::map::find() [3] so that map is only searched once,
and so that it is more obvious what is happening without having to know
the subtleties of std::map::count() and ::operator[].

[1] std::map::count()
    http://www.cplusplus.com/reference/map/map/count/

    "Searches the container for elements with a key equivalent to k and
    returns the number of matches.

    Because all elements in a map container are unique, the function can
    only return 1 (if the element is found) or zero (otherwise).
    "

[2] std::map::operator[]
    http://www.cplusplus.com/reference/map/map/operator[]/

    "If k does not match the key of any element in the container, the
    function inserts a new element with that key and returns a reference
    to its mapped value.  Notice that this always increases the
    container size by one, even if no mapped value is assigned to the
    element (the element is constructed using its default constructor).
    "

[3] std::map::find
    http://www.cplusplus.com/reference/map/map/find/

    "Searches the container for an element with a key equivalent to k
    and returns an iterator to it if found, otherwise it returns an
    iterator to map::end.
    "
2018-09-17 15:36:09 +00:00
Mike Fleetwood d3ef32096a Re-assign UFS to be a basic supported file system (!13)
There is no prospect of there being ufs-tools on Linux.  The was a
project which did release ufs-tools version 0.1 in 2004, but has been
inactive since then.
    http://ufs-linux.sourceforge.net/

Copying and moving is now implemented for file systems in the basic
supported category.  Also mounting and unmounting of unsupported file
system and reporting their usage while mounted has been added.  This is
all the support that GParted has ever implemented for UFS.  Therefore
re-assign UFS as a basic supported file system as it looses no
functionality.

Closes !13 - Support copying and moving of unsupported partition content
2018-09-17 15:36:09 +00:00
Mike Fleetwood 95903efb1f Extend un/mounting and usage reporting to unsupported file systems (!13)
For unsupported (including basic supported) file systems, also record
the mount point(s) when mounted and from /etc/fstab when not.  This
allows mounted unsupported file systems to be unmounted and ones with
/etc/fstab entries to be mounted, just like fully supported file
systems.

Also for unsupported (again including basic supported) mounted file
systems query the kernel for the usage, just like is already done for
supported file systems.

Closes !13 - Support copying and moving of unsupported partition content
2018-09-17 15:36:09 +00:00
Mike Fleetwood 4c3f4e3459 Correctly preview unknown FS usage when pasting into an existing partition (!13)
When previewing copying a partition of unknown file system usage into an
existing partition, the usage still shows that of the overwritten file
system.  This affects existing supported file systems EXFAT, F2FS, MINIX
and UFS and the new basic supported one too, all for which GParted can't
read the file system usage.

Handle the case of the source file system usage being unknown and
explicitly set the copied usage to unknown too.

Closes !13 - Support copying and moving of unsupported partition content
2018-09-17 15:36:09 +00:00
Mike Fleetwood f098cd414c Correctly preview unknown FS usage when pasting into a new partition (!13)
GParted previews copying a partition of unknown file system usage into a
new partition as 100% used.  This affects existing supported file
systems EXFAT, F2FS, MINIX and UFS and the new basic supported ones too,
all for which GParted can't read the file system usage.

When preparing the working new_partition object in the Copy / Paste
dialog, the maths for the known file system usage happened to convert
the figures of used = -1 and unused = -1 into set_sector_usage(-1, 0).
Those values passed to set_sector_usage() mean unable to query the file
system size so assume it fills the partition and unused is 0, hence 100%
used.

Fix this by specifically handling the copying of file systems with
unknown usage, setting the pasted file system usage to unknown too,
used = -1 and unused = -1.

Closes !13 - Support copying and moving of unsupported partition content
2018-09-17 15:36:09 +00:00
Mike Fleetwood 4d6d464664 Display "other" in the File System Support dialog (!13)
To display the supported actions for all basic supported file systems to
the users.

Prepare the list of file system actions in Win_GParted because calling
get_fs() for the "other" actions requires the gparted_core object and
load_filesystems() currently doesn't have access to it.  One alternative
would have been to make get_fs() and FILESYSTEMS static members of
GParted_Core class.  Another alternative would have been to pass the
gparted_core object to load_filesystems().  The chosen way seemed
simplest.

Closes !13 - Support copying and moving of unsupported partition content
2018-09-17 15:36:09 +00:00
Mike Fleetwood 9a66139eff Add "other" file system type (!13)
Want a single term under which the supported actions for all basic
supported file systems are displayed in the File System Support dialog.
"Unknown" isn't the correct adjective because the group includes
unknown, but also includes: BitLocker, GRUB2 core image, ISO9660, Linux
SWRaid, Linux Suspend, REFS and ZFS.  Add "other" file system type just
for displaying in the dialog.

Closes !13 - Support copying and moving of unsupported partition content
2018-09-17 15:36:09 +00:00
Mike Fleetwood 7a6dfb8a62 Enable copy and move for basic supported file systems (!13)
Add copy and move supported action set for each basic supported file
system.

Closes !13 - Support copying and moving of unsupported partition content
2018-09-17 15:36:09 +00:00
Mike Fleetwood ba79ddaf72 Limit FILESYSTEM_MAP entries to supported and basic supported FSs (!13)
Introduce a third category of basic file system support to go along with
the existing full and none.  Use the file system's entry in
FILESYSTEM_MAP to determine the level of support.  See comment in
GParted_Core::init_filesystems() for details.

Add and remove FILESYSTEM_MAP NULL pointer entries as required, so that
only the file system types intended to have basic support have such
entries.

Closes !13 - Support copying and moving of unsupported partition content
2018-09-17 15:36:09 +00:00
Mike Fleetwood f61481f3ae Separate unknown file system type from unsupported actions (!13)
PATCHSET OVERVIEW:

Forum user wanted to be able to move a partition with unknown content:
    Topic: Can't move/rezise partition on android device (unknown format)
    http://gparted-forum.surf4.info/viewtopic.php?id=17742

While GParted isn't going to be able to run any sort of file system
check on the unknown content there isn't any reason why such a partition
can't be copied or moved so long as the partition stays the same size.
GParted can just use it's existing internal block copy routine it uses
for copying and moving most partition content.  This is no different to
a few of the already supported file system types which don't have a
check-repair tool: exfat, f2fs, nilfs2, udf, ufs.

This patchset introduces a third category called basic file system
support to go along with the existing full and unsupported categories.
Basic supported file systems will just use GParted's inbuilt
capabilities to perform actions so they won't need a derived FileSystem
implementation class.  Unknown file systems along with all other
recognised, but otherwise unsupported, file systems will be assigned to
this new basic supported category.

THIS PATCH:

FS_UNKNOWN is used when GParted is unable to identify the contents of a
partition.  FS_UNKNOWN is also used to generate a file system support
set with no supported actions, in the FileSystem::FS::FS() constructor
and in GParted_Core::get_fs().

As support for operations on partitions with unknown content is being
added, the second usage will be confusing or even wrong.
FS( FS_UNKNOWN ) constructs the no supported actions set, yet GParted
will support some actions for the FS_UNKNOWN file system type.
Therefore add FS_UNSUPPORTED for the second usage.

Closes !13 - Support copying and moving of unsupported partition content
2018-09-17 15:36:09 +00:00
Mike Fleetwood 4542f34fed White space tidy-up of Utils::get_color()
No functional change.  The code layout is old and a mess, not lining up
vertically.  Use more common code layout and spaces to align text
vertically.  List cases in enumeration order.  Identify each colour
choice as either in the GNOME palette (no marking), an extended shade to
a colour in the GNOME palette [+], or a colour outside the GNOME palette
[*].

There's lots of other switch statements just in Utils.cc which could do
with tidying up, but this is the one I am looking at now.
2018-08-25 08:39:30 +01:00
Mike Fleetwood 1c651de338 Switch FAT16/32 colours to Accent Greens from the GNOME palette
FAT16 was a fully saturated green (RGB #00FF00) and FAT32 was a little
darker.  These are out of character with the colours from the GNOME
palette for other file systems.  Change the colours to use near
alternative Accent Greens from the GNOME colour palette.  So now we have
the following file system colours, from light to dark:
    FAT16 - Accent Green Hilight
    FAT32 - Accent Green
    EXFAT - Accent Green Dark
    UDF   - Accent Green Shadow

Strictly speaking only Accent Green and Accent Green Dark are part of
the GNOME palette.  Accent Green Hilight and Accent Green Shadow are
extensions expanding the range of Accent Greens.

    GNOME Human Interface Design 2.2.1 / Visual Design / colour /
    https://developer.gnome.org/hig-book/2.32/design-color.html.en

    "Guidelines
    * Use the GNOME color palette.  If you need a darker or lighter
      shade, start from one of the colors from the palette and darken or
      lighten as needed.
    "
2018-08-24 20:22:21 +01:00