Commit graph

4101 commits

Author SHA1 Message Date
Mike Fleetwood 157d4e7470 Recognise jbd (journaling block device) (#89)
A user reported that they were using an external journal with an ext4
file system, but that GParted didn't recognise it.  (They had the jbd
on an Intel Optane drive and the ext4 file system on an SSD).

Create a jbd like this:
    # mke2fs -O journal_dev -L test-jbd /dev/sdb1
    # blkid /dev/sdb1
    /dev/sdb1: LABEL="test-jbd" UUID="6e52858e-0479-432f-80a1-de42f9a4093e" TYPE="jbd"

Add recognition of jbd.  Use Blue Shadow colour, the same as ext4,
because jbd is primarily used by ext3/4 [1][2].  jbd is also used by
ocfs2 [1][3] and lustre [4][5] clustered file systems, but they are very
unlikely to encountered by GParted users.  Also xfs [6] and jfs [7] can
have external journals so if recognition of them is ever added they will
get the same colour as their respective file systems too.

[1] Journaling block device
    https://en.wikipedia.org/wiki/Journaling_block_device
    "JBD is filesystem-independent. ext3, ext4 and OCFS2 are known to
    use JBD"
[2] https://ext4.wiki.kernel.org/index.php/Frequently_Asked_Questions#What_are_the_key_differences_between_jbd_and_jbd2.3F
[3] OCFS2: The Oracle Clustered File System, Version 2
    https://www.kernel.org/doc/ols/2006/ols2006v1-pages-289-302.pdf
    "Metadata journaling is done on a per node basis with JBD"
[4] Efficient Object Storage Journaling in a Distributed Parallel File
    System
    https://www.usenix.org/legacy/event/fast10/tech/full_papers/oral.pdf
[5] Lustre Software Release 2.x Operations Manual
    https://doc.lustre.org/lustre_manual.pdf
    6.4.2. Choosing Parameters for an External Journal
[6] mkfs.xfs(8) - construct an XFS filesystem
    https://man7.org/linux/man-pages/man8/mkfs.xfs.8.html
    "OPTIONS
    ...
    logdev=device
        This is used to specify that the log section should reside on
        the device separate from the data section.  The internal=1 and
        logdev options are mutually exclusive.
    "
[7] jfs_mkfs(8) - create a JFS formatted partition
    https://manpages.debian.org/testing/jfsutils/jfs_mkfs.8.en.html
    "OPTIONS
    ...
    -j journal_device
        Create the external JFS journal on journal_device, ...
    "

Closes #89 - GParted doesn't recognise EXT4 fs journal partition
2022-03-06 16:27:20 +00:00
Mike Fleetwood 81c4788ae8 Fix translation of DocBook markup tag of the GParted Manual (!98)
As found by the GitLab Continuous Integration job on CentOS 7 with
itstool 2.0.2, building the GParted Manual breaks on the Russian
translation like this:
    $ ./autogen.sh
    $ make clean
    $ cd help
    $ make
    ...
    if ! test -d "ru/"; then mkdir "ru/"; fi
    if test -d "C"; then d="../"; else d="/home/mike/programming/c/gparted/help/"; fi; \
    mo="ru/ru.mo"; \
    if test -f "${mo}"; then mo="../${mo}"; else mo="/home/mike/programming/c/gparted/help/${mo}"; fi; \
    (cd "ru/" && itstool -m "${mo}" ${d}/C/index.docbook) && \
    touch "ru/ru.stamp"
    Error: Could not merge translations:
    'NoneType' object has no attribute 'node'
    make: *** [ru/ru.stamp] Error 1

On Fedora 35 with itstool 2.0.6 building the GParted Manual merely
reports a warning, leaving one paragraph untranslated, but the build
completes successfully:
    $ ./autogen.sh
    $ make clean
    $ cd help
    $ make
    ...
    if ! test -d "ru/"; then mkdir "ru/"; fi
    if test -d "C"; then d="../"; else d="/home/fedora/programming/c/gparted/help/"; fi; \
    mo="ru/ru.mo"; \
    if test -f "${mo}"; then mo="../${mo}"; else mo="/home/fedora/programming/c/gparted/help/${mo}"; fi; \
    (cd "ru/" && itstool -m "${mo}" ${d}/C/index.docbook) && \
    touch "ru/ru.stamp"
    Warning: Could not merge translation for msgid:
    Set the <application>grub</application> root device by specifying the device returned by the <command>find</command> command. This should be the partition containing the boot directory. <_:screen-1/>
    ...
    $ echo $?
    0

Fix translation of DocBook markup tag in the Russian translation of the
GParted Manual by commit:
    17f4c3176d
    Update Russian translation

Closes !98 - Fix translation of DocBook markup tag of the GParted Manual
2022-03-02 20:57:19 +00:00
Mike Fleetwood 2cfca5b38a Remove support for old volatile udev rules below /dev/.udev
Udev stopped supporting volatile udev rules in /dev/.udev/rules.d in
udev 176, released 2012-01-11 [1].  The oldest supported distributions
use much more recent combined systemd and udev releases.

    Distro            EOL        udevadm -V
    Debian 9          2022-Jun   232
    RHEL / CentOS 7   2024-Jun   219
    Ubuntu 18.04 LTS  2023-Apr   237

Now udev only reads volatile rules from /run/udev/ruled.d [2].  Simplify
the code a little.

[1] udev 176 NEWS
    https://git.kernel.org/pub/scm/linux/hotplug/udev.git/tree/NEWS?h=176
    "A writable /run directory (ususally tmpfs) is required now for a
    fully functional udev, there is no longer a fallback to /dev/.udev."
[2] man 7 udev
    "RULES FILES
    The udev rules are read from the files located in the system rules
    directory /usr/lib/udev/rules.d, the volatile runtime directory
    /run/udev/rules.d and the local administration directory
    /etc/udev/rules.d."
2022-03-01 16:58:46 +00:00
Mike Fleetwood 8640f91a4f Prevent GParted probe starting stopped bcache (#183)
From the setup in the previous commit, unregister (stop) all of the
bcache backing and cache devices.
    # bcache unregister /dev/sdb2
    # bcache unregister /dev/sdb1
    # bcache unregister /dev/sdc1
    # bcache show
    Name        Type        State            Bname       AttachToDev
    /dev/sdb2   1 (data)    inactive         Non-Exist   Alone
    /dev/sdb1   1 (data)    inactive         Non-Exist   Alone
    /dev/sdc1   3 (cache)   inactive         N/A         N/A

Run GParted.  Just the device scanning causes the stopped bcache devices
to be restarted.
    # bcache show
    Name        Type        State            Bname       AttachToDev
    /dev/sdb2   1 (data)    clean(running)   bcache1     /dev/sdc1
    /dev/sdb1   1 (data)    clean(running)   bcache0     /dev/sdc1
    /dev/sdc1   3 (cache)   active           N/A         N/A

This is nothing new with this patchset, but as a result of existing udev
behaviour.  The chain of events goes like this:

1. GParted calls ped_device_get() on each whole device;
2. Libparted opens each partition read-write to flush the cache;
3. When each is closed the kernel emits a block change event;
4. Udev fires block rules to detect the possibly changed content;
5. Udev fires bcache register (AKA start) rule.

More details with the help of udevadm monitor, strace and syslog:
    GParted  | set_devices_thread()
    GParted  |   ped_device_get("/dev/sdb")
    Libparted|     ...
    Libparted|     openat(AT_FDCWD, "/dev/sdb1", O_WRONLY) = 9
    Libparted|     ioctl(9, BLKFLSBUF)        = 0
    Libparted|     close(9)
    KERNEL   | change   /devices/.../block/sdb/sdb1 (block)
    KERNEL   | add      /devices/virtual/bdi/250:0 (bdi)
    KERNEL   | add      /devices/virtual/block/bcache0 (block)
    KERNEL   | change   /devices/virtual/block/bcache0 (block)
    UDEV     | change   /devices/.../block/sdb/sdb1 (block)
    UDEV     | add      /devices/virtual/bdi/250:0 (bdi)
    UDEV     | add      /devices/virtual/block/bcache0 (block)
    UDEV     | change   /devices/virtual/block/bcache0 (block)
    SYSLOG   | kernel: bcache: register_bdev() registered backing device sdb1

    # grep bcache-register /lib/udev/rules.d/69-bcache.rules
    RUN+="bcache-register $tempnode"

Fix this by temporarily adding a blank udev override rule to suppress
automatic starting of bcache devices, just as was previously done for
Linux Software RAID arrays [1].

[1] a255abf343
    Prevent GParted starting stopped Linux Software RAID arrays (#709640)

Closes #183 - Basic support for bcache
2022-03-01 16:58:46 +00:00
Mike Fleetwood 013c992428 Show bcache device as mount point of registered backing device (#183)
A bcache device provides accelerated access to a backing device in a one
to one relationship.  Multiple bcache backing devices can be attached to
and accelerated by the same cache device.  Extending the setup from the
previous commit, create an additional backing device and attach it to
the same cache.
    # bcache make -B /dev/sdb2
    # bcache attach /dev/sdc1 /dev/sdb2
    # bcache show
    Name        Type        State            Bname     AttachToDev
    /dev/sdb2   1 (data)    clean(running)   bcache1   /dev/sdc1
    /dev/sdb1   1 (data)    clean(running)   bcache0   /dev/sdc1
    /dev/sdc1   3 (cache)   active           N/A       N/A

List a couple of bcache specific sysfs files which identify registered
(active) bcache devices (components).
    # ls -l /sys/block/sd?/sd??/bcache/{dev,set}
    lrwxrwxrwx. 1 root root 0 Jan  7 10:08 /sys/block/sdb/sdb1/bcache/dev -> ../../../../../../../../../../virtual/block/bcache0
    lrwxrwxrwx. 1 root root 0 Jan  7 11:53 /sys/block/sdb/sdb2/bcache/dev -> ../../../../../../../../../../virtual/block/bcache1
    lrwxrwxrwx. 1 root root 0 Jan  7 11:53 /sys/block/sdc/sdc1/bcache/set -> ../../../../../../../../../../../fs/bcache/9945e165-0604-4f29-94bd-b155d01080ad

As was done with previous software block devices [1][2][3][4] show the
bcache (access) device as the mount point of a backing device
(component).  Use the /sys/block/DEV[/PTN]/bcache/dev sysfs symlinks to
provide the bcache device names.  Bcache cache devices (components)
don't get mount points because they aren't accessible.

[1] commit 8083f11d84
    Display LVM2 VGNAME as the PV's mount point (#160787)
[2] commit f6c2f00df7
    Populate member mount point with SWRaid array device (#756829)
[3] commit 538c866d09
    Display array device as mount point of mdadm started ATARAID members
    (#75)
[4] commit 538c866d09
    Display array device as mount point of mdadm started ATARAID members
    (#75)

Closes #183 - Basic support for bcache
2022-03-01 16:58:46 +00:00
Mike Fleetwood fd8c7857da Disable unmount of busy bcache devices (#183)
GParted automatically enables the Partition > Unmount action for busy
partitions.  Unregister (deactivate) bcache devices is not going to be
supported so disable it.

Closes #183 - Basic support for bcache
2022-03-01 16:58:46 +00:00
Mike Fleetwood 5d86c616a8 Report busy status of bcache (#183)
Make (format as) bcache backing device (-B) and cache device (-C) and
implicitly attach the backing device to the cache to enable caching, all
in one.
    # bcache make -B /dev/sdb1 -C /dev/sdc1
    # bcache show
    Name        Type        State            Bname     AttachToDev
    /dev/sdb1   1 (data)    clean(running)   bcache0   /dev/sdc1
    /dev/sdc1   3 (cache)   active           N/A       N/A

After experimenting with 'bcache unregister', 'bcache register' and
stracing 'bcache show' the bcache kernel module creates the sysfs
directory /sys/block/DEV[/PTN]/bcache and it's contents only when the
bcache device is registered with the kernel (bcache component is
active).  Use this to identify whether any bcache device (component)
should be displayed as active or not in GParted.
    # ls -ld /sys/block/sd?/sd?1/bcache
    drwxr-xr-x. 6 root root 0 Jan  7 10:08 /sys/block/sdb/sdb1/bcache
    drwxr-xr-x. 2 root root 0 Jan  7 10:08 /sys/block/sdc/sdc1/bcache

Closes #183 - Basic support for bcache
2022-03-01 16:58:46 +00:00
Mike Fleetwood f1920e306b Also pass device_path into GParted_Core::is_busy() (#183)
Will use this extra parameter when determining if a device or partition
containing bcache is busy or not.

Closes #183 - Basic support for bcache
2022-03-01 16:58:46 +00:00
Mike Fleetwood 99d683221d Enable GParted to present bcache devices (#183)
Add pattern to recognise block cache devices as valid devices for
GParted to work with.  Devices are named by the Linux kernel device
driver like /dev/bcache0 [1] with partitions named like /dev/bcache0p1
[2].

Note bcache devices can be partitioned but all the documents I have seen
guide users to create file systems directly in a bcache device and not
partition it [3][4] (plus all other Internet search results I looked
at).  This might be because bcache is a specialist use case and the
bcache backing device can be a partition itself.

[1] linux 5.15 drivers/md/bcache/super.c bcache_device_init()
    https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/md/bcache/super.c?h=v5.15#n945
[2] Contents of /proc/partitions for a bcache partitioned backing device
    $ grep bcache /proc/partitions
     251        0  524280 bcache0
     251        1  523256 bcache0p1
[3] Linux kernel document: A block layer cache (bcache)
    https://www.kernel.org/doc/Documentation/bcache.txt
[4] The Linux kernel user's and administrator's guide > A block layer
    cache (bcache)
    https://www.kernel.org/doc/html/latest/admin-guide/bcache.html

Closes #183 - Basic support for bcache
2022-03-01 16:58:46 +00:00
Mike Fleetwood e5041954cf Add detection of bcache (#183)
Use blkid to detect bcache formatted devices.  Requires blkid from
util-linux >= 2.24 for detection of bcache devices [1].

Use util-linux's FS images when testing GParted detection.
    # wget http://git.kernel.org/cgit/utils/util-linux/util-linux.git/plain/tests/ts/blkid/images-fs/bcache-B.img.xz
    # xzcat bcache-B.img.xz > /dev/sdb1
    # wget http://git.kernel.org/cgit/utils/util-linux/util-linux.git/plain/tests/ts/blkid/images-fs/bcache-C.img.xz
    # xzcat bcache-C.img.xz > /dev/sdc1
    # blkid /dev/sdb1 /dev/sdc1
    /dev/sdb1: UUID="8fb7f716-4c19-4517-bfbb-6f4a2becad60" TYPE="bcache" PARTUUID="f8f1485e-01"
    /dev/sdc1: UUID="7a343627-ac87-4bf0-b76f-46067cbc9b8c" TYPE="bcache" PARTUUID="f46e8c86-01"

To tidy-up after testing GParted detection, stop the bcache device in
case it was automatically started and wipe the signatures.  This is to
prevent udev rules from automatically starting the bcache device on
every subsequent reboot.
    # echo 1 > /sys/block/sdb/sdb1/bcache/stop
    # wipefs -a /dev/sdb1 /dev/sdc1

Closes #183 - Basic support for bcache
2022-03-01 16:58:46 +00:00
Mike Fleetwood 6617e6f3a3 Use face skin colours exclusively for software block devices (#183)
Currently the Face Skin colour range from the GNOME palette represent a
mixture of file systems and software block devices:
    JFS          - Face Skin Medium
    LVM2_PV      - Face Skin Dark
    NILFS2       - Face Skin Shadow
    LINUX_SWRAID - Dark Brown
    ATARAID      - Dark Brown

We are about to add recognition of bcache [1][2][3], another software
block device.  Reorganise the colour assignments so that Face Skin
colour range is exclusively used by types of software block devices and
assign JFS and NILFS2 new colours.
    Face Skin Light  (#EFE0CD) -
    Face Skin Medium (#E0C39E) - BCACHE         [New assignment]
    Face Skin Dark   (#B39169) - LVM2_PV
    Face Skin Shadow (#826647) - LINUX_SWRAID   [New assignment]
    Brown Dark       (#5A4733) - ATARAID

NILFS2 has flash friendly characteristics [4] so use Accent Red colours
along with F2FS.
    Accent Red      (#DF421E) - F2FS
    Accent Red Dark (#990000) - NILFS2   [New assignment]

Move JFS to a group with XFS and UFS.  The hue of the GNOME palette
Accent Yellow Dark colour, as used by UFS, was more Orange compared to
Accent Yellow and a bit too close to the Orange used by BTRFS.  So use
the hue of the GNOME Accent Yellow and extend the range and assign like
this.
    Accent Yellow             (#EED680) - XFS
    Accent Yellow Dark        (#D6B129) - JFS   [Updated hue.
                                                 New assignment]
    Accent Yellow Shadow      (#AA8F2C) - UFS   [New colour.
                                                 New assignment]
    Accent Yellow Dark Shadow (#826F2B) -       [New colour]

[1] bcache
    https://bcache.evilpiepirate.org/
[2] Linux kernel document: A block layer cache (bcache)
    https://www.kernel.org/doc/Documentation/bcache.txt
[3] The Linux kernel user's and administrator's guide > A block layer
    cache (bcache)
    https://www.kernel.org/doc/html/latest/admin-guide/bcache.html
[4] NILFS, Relative performance
    https://en.wikipedia.org/wiki/NILFS#Relative_performance

Closes #183 - Basic support for bcache
2022-03-01 16:58:46 +00:00
Sergej A 17f4c3176d Update Russian translation 2022-02-25 18:38:53 +00:00
Mike Fleetwood e85c00edb6 Remove unnecessary Glib::ustring::compose() of constant string 2022-02-22 20:04:25 +00:00
Mike Fleetwood 824287e678 Check copy destination instead of source (!95)(#723571)
GParted currently performs these relevant steps for a copy operation:
1.  Check source file system
2.  Copy to destination
3.  If destination partition is larger than source
3.1.  check destination file system
3.2.  grow destination file system

Always checking the source was added by this commit:
    a54b52ea33
    xfs copy now uses xfsdump and xfsrestore. icw some hacks in the other 2
    ...
    Also the source file system is now checked before the actual copy
    is performed.  If damaged beyond repair, the copy won't start.

I think users have an expectation that a copy operation accesses the
source read-only and performing a file system check on the source
breaks that expectation.  Also uses may accidentally or deliberately try
to copy a file system off a failing drive, where trying to check the
source could lead to further data loss.  (ddrescue is the proper tool
for recovering data from damaged drives but ddrescue is not a tool the
user may know -- they know about GParted).

For a failing drive, not checking the source first means the copy might
fail instead, however a failed copy is preferable to greater chance of
further damaging the source file system by checking it.

In order to keep the new process as similar as possible to before,
always check the destination instead.  This changes the copy operation
from performing one or two file system checks to always performing only
one check.  The new relevant copy operation steps are:
1. Copy to destination
2. check destination file system
3. If destination partition is larger than source
3.1.  grow destination file system

This has exactly the same error handling as before, if the check of the
destination file system fails the operation stops and any grow step
won't be performed.  This represents the minimum change in behaviour
from before.

Bug 723571 - Copying ext4 partitions should not fix the source but the
             destination
Closes !95 - Check copy destination instead of source
2022-02-22 20:04:25 +00:00
Luming Zh ed8ff63141 Update Chinese (China) translation 2022-02-05 15:27:34 +00:00
Matej Urbančič de93c7ec38 Update Slovenian translation 2021-11-23 18:16:09 +00:00
Mike Fleetwood 29a4fb4504 Return and use constant reference from SWRaid_Info::get_label() (!94)
Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood 0eedfa6030 Return constant reference from SWRaid_Info::get_uuid() (!94)
Since the only use of SWRaid_Info::get_uuid() assign the returned value
this doesn't actually save any copy construction.  Do it for consistency
with the other get_*() methods in SWRaid_Info.

Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood b38ee9c8ac Return and use constant reference from SWRaid::get_array() (!94)
Have to use a second constant reference variable array_path_2 in
GParted_Core::set_mountpoints() because by design C++ does not implement
rebinding of references [1].

[1] why doesn't C++ allow rebinding a reference?
    https://stackoverflow.com/questions/27037744/why-doesnt-c-allow-rebinding-a-reference

Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood 901f03c19d Return constant reference from OperationDetail::get_treepath() (!94)
Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood 1f6e81295b Return constant reference from OperationDetail::get_description() (!94)
All uses of get_description() copy construct to a local variable, not
assign to a reference, so this doesn't save anything.  It is just being
done to be consistent with making other getters return a constant
reference.

Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood 81f5dc3ead Use constant reference from LVM2_PV_Info::get_vg_cache_entry_by_name() (!94)
Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood c35422a70c Return and use constant reference from LVM2_PV_Info::get_vg_name() (!94)
Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood 55a74645f6 Use constant reference from LVM2_PV_Info::get_pv_cache_entry_by_name() (!94)
Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood 0a4761df46 Use constant reference from btrfs::get_cache_entry() (!94)
Method already returned a constant reference.  Change local variables to
constant references to avoid copy constructing them.

Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood a8e8e9fd97 Return and use constant reference from Partition::get_mountpoints() (!94)
Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood b3f1c22860 Return and use constant reference from Partition::get_mountpoint() (!94)
Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood c8f640655c Return and use constant reference from Partition::get_filesystem_label() (!94)
Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood 301690d9ff Return and use constant reference from Partition::get_path() (!94)
Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Mike Fleetwood 21dd6fe00b Return and use constant reference from Device::get_path() (!94)
A number of GParted methods named get_*() are returning properties and
are return-by-value.  For objects this implies the returned value is
copy constructed and later destroyed when it goes out of scope.  Change
them to use return-by-constant-reference to avoid unnecessary object
duplication.  Just have to make sure the reference goes out of scope
before the referenced object is destroyed to avoid having a reference
(pointer) to freed memory.  Assigning to a local variable instead of
of a local reference still duplicates the object so can be used when the
lifetime of the gotten object needs to be longer that the referenced
object.

Previously done for other getters here:
    d948cbcb91
    Make get_custom_text() and get_generic_text() return by reference

This change just makes Device::get_path() return a constant reference
and updates uses to match to avoid copy constructing the returned value.

Closes !94 - Make more getter methods use return-by-constant-reference
2021-11-16 16:08:17 +00:00
Matej Urbančič 17e451294a Update Slovenian translation 2021-11-14 21:34:52 +00:00
Yaron Shahrabani 4b560b30b5 Update Hebrew translation 2021-11-05 09:39:14 +00:00
Yaron Shahrabani 661f691791 Update Hebrew translation 2021-11-05 09:36:09 +00:00
Mike Fleetwood aab269cc53 Make MB_Needed_for_Boot_Record() a static member function
Because it doesn't access any member variables or call any member
methods.
2021-10-27 15:04:20 +00:00
Mike Fleetwood 67b07f86e6 Simplify logic in MB_Needed_for_Boot_Record() et al
The first two clauses say is the partition object type unallocated
inside an extended partition, or a logical partition (which only occur
inside an extended partition).  As these are the only two partition
object types which can occur inside an extended partition, this is
equivalent to saying is the partition object inside an extended
partition.  Simplify.
2021-10-27 15:04:20 +00:00
Mike Fleetwood eaaa5719f7 Use previous unallocated partition when determining 1 MiB reservation in resize/move dialog
The create new and paste into new dialogs are both composing a new
partition into the unallocated selected_partition they are passed.  The
starting sector of this unallocated partition is the first sector the
newly composed partition could possibly have.  To ensure it doesn't
overlay with the partition table or EBR (Extended Boot Records) it calls
MB_Needed_for_Boot_Record() to indicate if the first 1 MiB needs to be
reserved in the dialog or not.

Code:
    Dialog_Partition_New::set_data(..., selected_partition, ...)
        ...
        MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record(selected_partition);

    Dialog_Partition_Copy::set_data(selected_partition, ...)
        ...
        MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record(selected_partition);

However the resize/move dialog is different.  It is passed the existing
selected_partition object and the vector of partitions from which it
determines if there is a previous unallocated partition object or not.
When there is no previous unallocated partition object, there is no need
to reserve 1 MiB because the selected_partition can't be moved further
to the left.  In the other case when there is a previous unallocated
partition object the start of the existing selected_partition can be
moved to the left.  However the code passes the selected_partition
object to MB_Needed_for_Boot_Record() so doesn't have the first sector
the newly composed partition could possibly have so doesn't reserve the
first 1 MiB to prevent it overlapping with the partition table at the
start of the drive.  These two commits addressed this limitation:
* Ensure 1 MiB reserved when moving extended partition to start of drive
* Ensure 1 MiB reserved when moving partition to start of disk

Code:
    Dialog_Partition_Resize_Move::set_data(selected_partition, ...)
        new_partition = selected_partition.clone();
        if (selected_partition.type == TYPE_EXTENDED)
            Resize_Move_Extended(...);
        else
            Resoze_Move_Normal(...);

    Dialog_Partition_Resize_Move::Resize_Move_Normal(...)
        ...
        if (previous <= 0)
            MIN_SPACE_BEFORE_MB = 0;
        else
        {
            if (START < MEBIBYTE / new_partition->sector_size)
                MIN_SPACE_BEFORE_MB = 1;
            else
                MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record(*new_partition);
        }

    Dialog_Partition_Resize_Move::Resize_Move_Extended(...)
        ...
        if (previous <= 0)
            MIN_SPACE_BEFORE_MB = 0;
        else
        {
            if (START < MEBIBYTE / new_partition->sector_size)
                MIN_SPACE_BEFORE_MB = 1;
            else
                MIN_SPACE_BEFORE_MB = Dialog_Base_Partition::MB_Needed_for_Boot_Record(*new_partition);
        }

So instead pass the previous unallocated partition object as that
contains the left most start sector the newly composed partition could
possibly have, therefore the check for overlapping the partition table
in the first 1 MiB of the drive can succeed.
2021-10-27 15:04:20 +00:00
Mike Fleetwood 37689eef9d Ensure 1 MiB reserved when moving extended partition to start of drive
On an MSDOS partitioned drive, create an extended partition at least 2
MiBs from the start of the drive.  Like this:
    dd if=/dev/zero bs=1M of=dev/sdb
    echo 4096,4096,5 | sfdisk -uS --force /dev/sdb

The resize/move dialog appears to allow the extended partition to be
moved and/or resized to the very start of the drive, over the top of the
partition table, without reserving the first 1 MiB.  Ensure the dialog
reserves the first 1 MiB, like it does when moving normal partitions.

Reference:
    ceab9bde57
    Ensure 1 MiB reserved when moving partition to start of disk
2021-10-27 15:04:20 +00:00
Mike Fleetwood 19186e2152 Allow resize/move of partition to sector 2048 when following another (#172)
This case is an extension of the setup in the previous commit.  Add a
second partition several megabytes after the first.  It looks like this:

  [TABLE][PTN#1]                  [PTN#2]
  <-- 1st MiB -><- several MiBs ->

Just need to make the gap 2 MiB or more so that it can be seen what the
resize/move dialog is allowing.  Setup like this using an 8 MiB gap and
8 MiB partition #2.

For MSDOS use:
    dd if=/dev/zero bs=1M of=/dev/sdb
    (echo 1,2047; echo 18432,16384) | sfdisk -uS --force /dev/sdb
    mkswap /dev/sdb2

For GPT use:
    sgdisk --zap-all /dev/sdb
    sgdisk --set-alignment=1 --new 1:34:2047 /dev/sdb
    sgdisk --new 2:18432:34815 /dev/sdb
    mkswap /dev/sdb2

In GParted try to move partition sdb2 to the left as much as possible,
or try to resize the start to the left as much as possible.  GParted
insists on having a 1 MiB of padding before the start of sdb2, forcing
it to start at sector 4096, even though sector 2048 is free and aligns
to whole megabytes.

Delete the preceding partition.  Now GParted allows sdb2 to be moved or
resize to start at sector 2048.

Fix another off by one error in the sector comparison for the
resizing/moving of partitions.

Closes #172 - GParted doesn't allow creation of a partition starting at
              sector 2048 if there is a partition before it
2021-10-27 15:04:20 +00:00
Mike Fleetwood 0bfbac4f65 Allow creation of partition at sector 2048 when following another (#172)
[This commit message and test case is written assuming a drive with a
(logical) sector size of 512 bytes.  GParted equally well works with
other sector sizes because the limit is expressed as 1 MiB / sector
size.  Adjust the test case sector counts as needed when testing with
different sector sized drives.]

Prepare an MSDOS or GPT partitioned disk with the first partition within
the first 1 MiB.

For MSDOS use:
    dd if=/dev/zero bs=1M of=/dev/sdb
    echo 1,2047 | sfdisk -uS --force /dev/sdb

For GPT use:
    sgdisk --zap-all /dev/sdb
    sgdisk --set-alignment=1 --new 1:34:2047 /dev/sdb

In GParted create a new partition on /dev/sdb as near to the start of
the drive as possible.  GParted insists on added an extra 1 MiB of space
before the new partition, making it start at sector 4096, even though
sector 2048 is free and aligns to whole megabytes.

Delete the preceding partition.  Now GParted allows the new partition
to be created starting at sector 2048.

GParted only needs to add padding of 1 MiB to account for the partition
table at the start of the drive when the possible start is within the
first MiB, not already at the first MiB.  Fix this off by one error in
the sector comparison.

The reason this has bug has never occurred before is because it is very
unusual to have the first partition entirely within the first 1 MiB.
Normally either the (start of) the drive is free so GParted creates an
unallocated partition object starting at sector 0, so adding 1 MiB of
padding to preserve the partition table is correct; or the first
partition starts at 1 MiB so the possible start for a second partition
is much later in the drive.

Closes #172 - GParted doesn't allow creation of a partition starting at
              sector 2048 if there is a partition before it
2021-10-27 15:04:20 +00:00
Pascal Engélibert f31fbb986f Add accessibility relations (!92)
Accessibility relations are essential for usage with screen readers.  It
enables the screen reader to read the corresponding label along with the
value of a widget when it gains focus, rather than just the value of the
widget itself.

Test by running Orca screen reader and tab around the elements of the UI
and listen to what is read out.  For example before it would be
"500 GiB", where as after it would be "Unused 500 GiB".

Closes !92 - Add accessibility relations
2021-10-09 08:34:41 +00:00
Dušan Kazik 55be68da93 Update Slovak translation 2021-10-06 10:52:01 +00:00
Aleksandr Melman 9e96fbad7d Update Russian translation 2021-10-03 18:02:06 +00:00
Mike Fleetwood 3665bd5da7 Fix crash scrolling quickly in the drive selection combobox (#165)
A user reported that scrolling the mouse wheel quickly crashes GParted
[1].  The minimum setup required to reproduce this crash is 3 drives
partitioned like this:
    sda - any
    sdb - some unallocated space
    sdc - no unallocated space
Then move the pointer over the drive selection combobox and scroll the
mouse wheel quickly downwards.

The sequence of events goes like this:
1.  The first scroll wheel down event causes the device combobox
    selection to change to the second entry (sdb), which calls
    combo_devices_changed() -> Refresh_Visual().
2.  Refresh_Visual() sets selected_partition_ptr to point to the largest
    unallocated space partition object in sdb.
3.  The first Gtk event processing loop in Refresh_Visual() comes
    across the next scroll wheel down event.  This changes the selection
    to the third entry (sdc), which makes a recursive call to
    combo_devices_changed() -> Refresh_Visual().
4.  Refresh_Visual() sets selected_partition_ptr to NULL as sdc has no
    unallocated space and returns.
5.  The first call to Refresh_Visual() resumes after the first Gtk event
    loop, continuing the processing for drive sdb.  As sdb has a
    largest unallocated space partition (largest_unalloc_size >= 0),
    DrawingAreaVisualDisk::set_selected() is called with the now
    NULL selected_partition_ptr.
6.  One of the DrawingAreaVisualDisk::set_selected() methods
    dereferences the NULL pointer, crashing GParted.

As a comment says of selected_partition_ptr "Lifetime:   Valid until the
next call to Refresh_Visual()."  It just wasn't expected that the next
call to Refresh_Visual() would be half way through Refresh_Visual()
itself.

Considered but rejected fixes:
1.  Remove automatic selection of the largest unallocated space.
    Removes functionality.
2.  Return at the top of Refresh_Visual() when called recursively.
    This causes GParted to not update the main window with the latest
    selected drive.  In the above example the combobox would show sdc,
    but the main window graphic and partition list would have only been
    updated once showing sdb, the first scrolled selection.

Fix by only having a single Gtk event processing loop at the end of
Refresh_Visual() with the optional calls to select the largest
unallocated partition before that loop.  This makes it impossible to
call the ::set_selected() methods with selected_partition_ptr modified
by a recursive call.

This fix reverts this earlier commit:
    0fb8cce699
    Reduce flashing redraw from automatic partition selection (#696149)

That commit was in GParted 0.20.0 when Gtk 2 was still used.  Re-testing
now doesn't see any flashing redrawing from the automatic partition
selection, with GParted currently using Gtk 3.

[1] Debian bug #991998 - gparted segfaults if scrolling quickly the
    device dropdown list
    https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=991998

Closes #165 - GParted segfaults if scrolling quickly in the device
              dropdown
2021-09-27 15:11:37 +00:00
Мирослав Николић 49188a39b8 Update Serbian translation 2021-09-18 05:25:34 +00:00
Mike Fleetwood 1b85bf00cf Fix warning from double assigning to gscreen
Compiling GParted on an older distribution with gtk+-3.0 < 3.22.0, where
HAVE_GTK_SHOW_URI_ON_WINDOW is undefined, produces this warning message:
    Win_GParted.cc: In member function 'void GParted::Win_GParted::show_help(const Glib::ustring&, const Glib::ustring&)':
    Win_GParted.cc:1822:56: warning: operation on 'gscreen' may be undefined [-Wsequence-point]
      GdkScreen *gscreen = gscreen = gdk_screen_get_default();
                                                            ^

Found on Ubuntu 16.04 LTS with gtk+ 3.18.0.

Stop double assigning to gscreen.  Fixes commit:
    26f4dc504a
    Replace deprecated gtk_show_uri() method for help window (!82)
2021-09-17 15:56:10 +00:00
Mike Fleetwood ba1bafc5ac Replace /proc/mounts grep with Mount_Info cache reload and query (!89)
Creating a grep process to check if a particular mount is still mounted
is an unnecessary overhead.  All that is needed is for the Mount_Info
module to refresh it's copy of /proc/mounts and query that.

To keep the code as simple as possible just reload the whole of the
Mount_Info module and query the mount cache to determine if the
particular block device is still mounted at this particular mount point.
This therefore re-reads /proc/mounts (necessary) and /proc/swaps and
/etc/fstab (unnecessary).  This is still much less overhead than
creating a separate grep process.

Closes !89 - Fix unmount error when unmounting below a bind mount point
2021-09-17 15:56:10 +00:00
Movie Ma 6f811cfaca Fix unmount error when unmounting below a bind mount point (!89)
Bind mounts duplicate part of the file system hierarchy to an additional
mount point [1].  When mounting and unmounting a second file system
below a duplicating bind mount Linux automatically presents this lower
file system as being mounted multiple times.  GParted displays these
multiple mount points.  However using GParted to unmount this lower file
system reports an error that the second mount point is no longer
mounted, because all were unmounted by the first unmount command.

Setup:

1.  Mount an upper file system

    # mkdir /mnt/1
    # mount /dev/sdb1 /mnt/1
    # fgrep sdb /proc/mounts
    /dev/sdb1 /mnt/1 ext4 rw,seclabel,relatime,data=ordered 0 0

2.  Bind mount it to a second directory

    # mkdir /mnt/b1
    # mount --bind /mnt/1 /mnt/b1
    # fgrep sdb /proc/mounts
    /dev/sdb1 /mnt/1 ext4 rw,seclabel,relatime,data=ordered 0 0
    /dev/sdb1 /mnt/b1 ext4 rw,seclabel,relatime,data=ordered 0 0

3.  Mount a file system below the first

    # mkdir /mnt/1/lower
    # mount /dev/sdb2 /mnt/1/lower
    # fgrep sdb /proc/mounts
    /dev/sdb1 /mnt/1 ext4 rw,seclabel,relatime,data=ordered 0 0
    /dev/sdb1 /mnt/b1 ext4 rw,seclabel,relatime,data=ordered 0 0
    /dev/sdb2 /mnt/1/lower xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0
    /dev/sdb2 /mnt/b1/lower xfs rw,seclabel,relatime,attr2,inode64,noquota 0 0

    Two mount records for sdb2 were added to /proc/mounts from one mount
    command.

Then use GParted to unmount sdb2.  It reports this error dialog:
    +-------------------------------------+
    |                                     |
    | Could not unmount /dev/sdb2         |
    |                                     |
    | # umount -v '/mnt/b1/lower'         |
    | umount: /mnt/b1/lower: not mounted. |
    +-------------------------------------+
    |            [  OK  ]                 |
    +-------------------------------------+

Fix by checking that the file system is still mounted before each
unmount attempt.

[1] mount (8), Description, Bind mount operation
    https://man7.org/linux/man-pages/man8/mount.8.html#DESCRIPTION

Closes !89 - Fix unmount error when unmounting below a bind mount point
2021-09-17 15:56:10 +00:00
Goran Vidović c0532c30e4 Update Croatian translation 2021-09-11 17:47:16 +00:00
Balázs Úr fc9a4ecba7 Update Hungarian translation 2021-09-10 20:47:13 +00:00
Andika Triwidada f250697c58 Add initial Indonesian translation of help (!90)
Closes !90 - Add initial Indonesian translation of help
2021-09-08 18:20:16 +01:00