Commit Graph

3003 Commits

Author SHA1 Message Date
Mike Fleetwood 902afaa010 Simplify Device object to a single path (#767842)
Background

GParted stored a list of paths for Device and Partition objects.  It
sorted this list [1][2] and treated the first specially as that is what
get_path() returned and was used almost everywhere; with the file system
specific tools, looked up in various *_Info caches, etc.

[1] Device::add_path(), ::add_paths()
[2] Partition::add_path(), ::add_paths()

Mount point display [3] was the only bit of GParted which really worked
with the path list.  Busy file system detection [4] just used the path
provided by libparted, or for LUKS /dev/mapper/* names.  It checked that
single path against the mounted file systems found from /proc/mounts,
expanded with additional block device names when symlinks were
encountered.

[3] GParted_Core::set_mountpoints() -> set_mountpoints_helper()
[4] GParted_Core::set_device_partitions() -> is_busy()
    GParted_Core::set_device_one_partition() -> is_busy()
    GParted_Core::set_luks_partition() -> is_busy()

Having the first path, by sort order, treated specially by being used
everywhere and virtually ignoring the others was wrong, complicated to
remember and difficult code with.  As all the additional paths were
virtually unused and made no difference, remove them.  The "improved
detection of mountpoins, free space, etc.." benefit from commit [5]
doesn't seem to exist.  Therefore simplify to a single path for Device
and Partition objects.

[5] commit 6d8b169e73
    changed the way devices and partitions store their device paths.
    Instead of holding a 'realpath' and a symbolic path we store paths
    in a list.  This allows for improved detection of mountpoins, free
    space, etc..

This patch

Simplify the Device object from a vector of paths to a single path.
Remove add_paths() and get_paths() methods.  Keep add_path() and
get_path() for now.

Bug 767842 - File system usage missing when tools report alternate block
             device names
2016-08-06 09:47:58 -06:00
Balázs Úr 7745abd767 Updated Hungarian translation 2016-08-04 21:59:54 +00:00
Piotr Drąg 0778e4fdd1 Add Language headers to po files
Future versions of gettext will fail if this header is missing.
2016-07-21 22:35:03 +02:00
Andika Triwidada b8de6d0006 Updated Indonesian translation 2016-07-08 12:56:16 +00:00
Tiago Santos b2a4956d77 Updated Portuguese translation 2016-07-04 14:01:27 +00:00
Natanael Copa 25209904a9 Fix sscanf modifier for long long (#768239)
POSIX says that %lld is the modifier for long long.
http://pubs.opengroup.org/onlinepubs/9699919799/functions/fscanf.html

This fixes wrong sizes with musl libc.

Bug 768239 - sizes are wrong with musl libc due to use of non-standard
             sscanf "%Ld" modifier
2016-07-01 15:37:01 +01:00
Mike Fleetwood 8ac3a0e4ad Recognise GRUB2 core.img (#766989)
Recognise GRUB2 core.img boot code written to a partition without a file
system.  Such setups are possible/likely with GPT partitioned disks as
there is a specific partition type reserved for it [1][2]:
    21686148-6449-6E6F-744E-656564454649  (BIOS Boot partition)

[1] GUID Partition Table, Partition types
    https://en.wikipedia.org/wiki/GUID_Partition_Table#Partition_type_GUIDs

[2] BIOS boot partition
    https://en.wikipedia.org/wiki/BIOS_boot_partition

Bug 766989 - zfsonline support - need file system name support for ZFS
             type codes
2016-06-15 12:45:05 -06:00
Curtis Gedak 74e0aad7a4 Append -git to version for continuing development 2016-06-13 11:04:38 -06:00
Curtis Gedak 9eb9f503db ========== gparted-0.26.1 ========== 2016-06-13 10:13:02 -06:00
Milo Casagrande 553a76abfa Updated Italian translation 2016-06-13 09:07:21 +00:00
GNOME Translation Robot a2fecf01ee Updated Scottish Gaelic translation 2016-06-11 08:02:16 +00:00
Marek Černocký 991edb9566 Updated Czech translation 2016-06-10 07:38:36 +02:00
A S Alam 7b9bf718e3 Completed Punjabi Translation 2016-06-09 15:12:12 -05:00
Daniel Șerbănescu 20706140f3 Updated Romanian translation 2016-06-09 19:42:33 +00:00
A S Alam b7613cd609 updated Punjabi Translation 2016-06-08 18:44:31 -05:00
Wolfgang Stöggl 03ad03a500 Updated German translation 2016-06-07 12:12:13 +00:00
Alexandre Franke da17e38bcd Updated French translation 2016-06-07 08:35:36 +00:00
Mike Fleetwood 3daf73a01b Prevent assert failure from OperationDelete::get_partition_new() (#767233)
Composing these operations caused GParted to abort on an assert failure:
(1) Delete an existing partition,
(2) Create a new partition,
(3) Delete new partition.

This is the equivalent issue as fixed in the previous commit, except with
the delete operation rather than the check operation:
    Prevent assert failure from OperationCheck::get_partition_new() (#767233)

    # ./gpartedbin
    ======================
    libparted : 2.4
    ======================
    **
    ERROR:OperationDelete.cc:41:virtual GParted::Partition& GParted::OperationDelete::get_partition_new(): assertion failed: (false)
    Aborted (core dumped)

    # gdb ./gpartedbin core.19232 --batch --quiet --ex backtrace -ex quit
    [New Thread 19232]
    [New Thread 19234]
    [Thread debugging using libthread_db enabled]
    Core was generated by `./gpartedbin'.
    Program terminated with signal 6, Aborted.
    #0  0x000000361f2325e5 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
    64	  return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);
    #0  0x000000361f2325e5 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
    #1  0x000000361f233dc5 in abort () at abort.c:92
    #2  0x0000003620a67324 in g_assertion_message (domain=<value optimized out>, file=<value optimized out>, line=<value optimized out>, func=0x50fcc0 "virtual GParted::Partition& GParted::OperationDelete::get_partition_new()", message=0x1b55f60 "assertion failed: (false)") at gtestutils.c:1358
    #3  0x0000003620a678f0 in g_assertion_message_expr (domain=0x0, file=0x50fa68 "OperationDelete.cc", line=41, func=0x50fcc0 "virtual GParted::Partition& GParted::OperationDelete::get_partition_new()", expr=<value optimized out>) at gtestutils.c:1369
    #4  0x000000000049aa0d in GParted::OperationDelete::get_partition_new (this=0x1b321b0) at OperationDelete.cc:41
    #5  0x00000000004c6700 in GParted::Win_GParted::activate_delete (this=0x7ffc91403670) at Win_GParted.cc:2068
    ...

As before the crash is happened in Win_GParted::activate_delete() as it
was going through the list of operations removing those which applied to
the never created partition.  It came across the delete operation of an
existing partition and called get_partition_new().  As partition_new was
not set or used by the delete operation this asserted false and crashed
GParted.

Unlike the check operation case, the delete operation doesn't have a
partition afterwards.  (As GParted represents unallocated space with
partition objects then the delete operation could be populated with a
new partition by constructing the correctly merged unallocated space
partition object, but that is what OperationDelete::apply_to_visual()
does and having a place holder doesn't seem like the right thing to do).
Instead exclude delete operations, on existing partitions, when looking
for operations applying to this not yet created partition as they are
mutually exclusive.

Bug 767233 - GParted core dump on assert failure in
             OperationDelete::get_partition_new()
2016-06-05 13:14:34 -06:00
Mike Fleetwood 1f2a50544d Prevent assert failure from OperationCheck::get_partition_new() (#767233)
Composing these operations caused GParted to abort on an assert failure:
(1) Check an existing partition,
(2) Create a new partition,
(3) Delete new partition.

    # ./gpartedbin
    ======================
    libparted : 2.4
    ======================
    **
    ERROR:OperationCheck.cc:40:virtual GParted::Partition& GParted::OperationCheck::get_partition_new(): assertion failed: (false)
    Aborted (core dumped)

    # gdb ./gpartedbin core.8876 --batch --quiet --ex backtrace -ex quit
    [New Thread 8876]
    [New Thread 8879]
    [Thread debugging using libthread_db enabled]
    Core was generated by `./gpartedbin'.
    Program terminated with signal 6, Aborted.
    #0  0x000000361f2325e5 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
    64	  return INLINE_SYSCALL (tgkill, 3, pid, selftid, sig);
    #0  0x000000361f2325e5 in raise (sig=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:64
    #1  0x000000361f233dc5 in abort () at abort.c:92
    #2  0x0000003620a67324 in g_assertion_message (domain=<value optimized out>, file=<value optimized out>, line=<value optimized out>, func=0x50f400 "virtual GParted::Partition& GParted::OperationCheck::get_partition_new()", message=0x1d37a00 "assertion failed: (false)") at gtestutils.c:1358
    #3  0x0000003620a678f0 in g_assertion_message_expr (domain=0x0, file=0x50f1a8 "OperationCheck.cc", line=40, func=0x50f400 "virtual GParted::Partition& GParted::OperationCheck::get_partition_new()", expr=<value optimized out>) at gtestutils.c:1369
    #4  0x0000000000498e21 in GParted::OperationCheck::get_partition_new (this=0x1d1bb30) at OperationCheck.cc:40
    #5  0x00000000004c66ec in GParted::Win_GParted::activate_delete (this=0x7fff031c3e30) at Win_GParted.cc:2068
    ...

When Win_GParted::activate_delete() was stepping through the operation
list removing operations (2 & 3 in the above recreation steps) which
related to the new partition never to be created it called
get_partition_new() on all operations in the list.  This included
calling get_partition_new() on the check operation (1 in the above
recreation steps).  As partition_new was not set or used by the check
operation get_partition_new() asserted false and crashed GParted.

Fix by populating the partition_new member in OperationCheck objects,
thus allowing get_partition_new() to be called on the object.  As a
check operation doesn't change any partition boundaries or file system
attributes, just duplicate the new partition from the original
partition.

Bug 767233 - GParted core dump on assert failure in
             OperationDelete::get_partition_new()
2016-06-05 13:14:34 -06:00
Mike Fleetwood cc7e412bc6 Only enable ext4 64bit feature when required (#766910)
E2fsprogs version 1.43 always creates 64bit ext4 file systems by default
[1][2] regardless of the partition size.  Previously it only enabled the
64bit feature when required on ext4 volumes 16 TiB and larger.  Also
note that RHEL / CentOS 7 always create 64bit ext4 file systems by
default from e2fsprogs 1.42.9 [3].

(At least some versions of) Grub 2 and syslinux boot loaders don't work
with 64bit ext4 file systems [4][5][6].  For maximum boot loader
compatibility make GParted implement what mke2fs previously did, only
setting the 64bit feature on volumes 16 TiB and larger and clearing it
otherwise.  Only applied to mkfs.ext4 version 1.42 and later.

[1] Release notes, E2fsprogs 1.43 (May 17, 2016)
    http://e2fsprogs.sourceforge.net/e2fsprogs-release.html#1.43

    "Mke2fs will now create file systems with the metadata_csum and
    64bit features enabled by default".

[2] http://git.kernel.org/cgit/fs/ext2/e2fsprogs.git/commit/?id=cd27af3ecb83e8fd1e3eaa14994284a1818c7c15
    mke2fs: enable the metadata_csum and 64bit features by default

[3] Comment 20 and 21 in Red Hat bug 1099237
    https://bugzilla.redhat.com/show_bug.cgi?id=1099237#c20

    "..., is rhel7 default behavior w.r.t. 64 bit really different from
    upstream ?

    Yes it is. This is what we have in RHEL7:
    Patch6: e2fsprogs-1.42.9-enable-64bit-feature-by-default.patch
    it fixed this bz: https://bugzilla.redhat.com/show_bug.cgi?id=982871
    and this is upstream proposal:
    http://www.spinics.net/lists/linux-ext4/msg42294.html"

[4] Grub 2 not working on Slackware with 64bit EXT4
    http://www.linuxquestions.org/questions/slackware-14/grub-mkconfig-error-in-slackware-current-64-bit-4175580544/

[5] Syslinux not working on Slackware with 64bit EXT4
    http://www.linuxquestions.org/questions/slackware-14/slackware64-current-5-20-2016-syslinux-booting-and-ext4-formatting-4175580324/

[6] Syslinux not working on RHEL 7 with 64bit EXT4
    Bug 1099237 - rhel7 ext4 defaults to 64 bit, which extlinux can't reliably read
    https://bugzilla.redhat.com/show_bug.cgi?id=1099237

Bug 766910 - Multiple boot loaders don't work on 64bit EXT4 file systems
2016-06-05 09:40:11 -06:00
Mike Fleetwood a13526bf41 Don't limit ext4 volume size when 64bit feature is available (#766910)
E2fsprogs 1.42 adds ext4 64bit feature [1] allowing volume sizes larger
than 16 TiB.  However only enable large volumes from e2fsprogs 1.42.9
when a large number of 64bit bugs were fixed [2].  (Also RHEL / CentOS 7
use e2fsprogs 1.42.9 and always enable 64bit feature by default).

[1] Release notes, E2fsprogs 1.42 (November 29, 2011)
    http://e2fsprogs.sourceforge.net/e2fsprogs-release.html#1.42

    "This release of e2fsprogs has support for file systems > 16TB.
    Online resize requires kernel support which will hopefully be in
    Linux version 3.2.  Offline support is not yet available for > 16TB
    file systems, but will be coming".

[2] Release notes, E2fsprogs 1.42.9 (December 28, 2013)
    http://e2fsprogs.sourceforge.net/e2fsprogs-release.html#1.42.9

    "Fixed a large number of bugs in resize2fs, e2fsck, debugfs, and
    libext2fs to correctly handle bigalloc and 64-bit file systems.
    There were many corner cases that had not been noticed in previous
    uses of these file systems, since they are not as common.  Some of
    the bugs could cause file system corruption or data loss, so users
    of 64-bit or bigalloc file systems are strongly urged to upgrade to
    e2fsprogs 1.42.9".

Bug 766910 - Multiple boot loaders don't work on 64bit EXT4 file systems
2016-06-05 09:40:11 -06:00
Mike Fleetwood af17808d08 Limit maximum ext2/3/4 volume size to just less than 16 TiB (#766910)
Maximum size of an ext2/3/4 volume is 2^32 - 1 blocks [1], ignoring ext4
with 64bit feature.  That is just under 16 TiB with a 4K block size.

    # truncate -s 16T /mnt/1/sparse.img
    # ls -l /mnt/1/sparse.img
    -rw-r--r--. 1 root root 17592186044416 May 28 19:33 /mnt/1/sparse.img
    # losetup /dev/loop0 /mnt/1/sparse.img
    # mkfs.ext3 /dev/loop0
    mke2fs 1.43 (17-May-2016)
    mkfs.ext3: Size of device (0x100000000 blocks) /dev/loop0 too big to be expressed
            in 32 bits using a blocksize of 4096.
    # losetup -d /dev/loop0
    #
    #
    # truncate -s $((16*1024**3-4))K sparse.img
    # ls -l /mnt/1/sparse.img
    -rw-r--r--. 1 root root 17592186040320 May 28 19:51 /mnt/1/sparse.img
    # losetup /dev/loop0 /mnt/1/sparse.img
    # mkfs.ext3 /dev/loop0
    mke2fs 1.43 (17-May-2016)
    Discarding device blocks: done
    Creating filesystem with 4294967295 4k blocks and 536870912 inodes
    Filesystem UUID: 9721d8d9-8711-499b-aae4-8ea4d9e16ca2
    Superblock backups stored on blocks:
            32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
            4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
            102400000, 214990848, 512000000, 550731776, 644972544, 1934917632,
            2560000000, 3855122432

    Allocating group tables: done
    Writing inode tables: done
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done

    # losetup -d /dev/loop0
    # rm /mnt/1/sparse.img

Actually limit the maximum volume size to 1 MiB less than 16 TiB for
coding reasons explained in the FIXME comment.

[1] Ext4 Disk Layout, Blocks
    https://ext4.wiki.kernel.org/index.php/Ext4_Disk_Layout#Blocks

Bug 766910 - Multiple boot loaders don't work on 64bit EXT4 file systems
2016-06-05 09:40:11 -06:00
Enrico Nicoletto 58d409787b Updated Brazilian Portuguese translation 2016-05-30 20:28:07 +00:00
Daniel Mustieles 0cc98564cf Updated Spanish translation 2016-05-30 19:15:39 +02:00
Mike Fleetwood 3724421e30 Stop leaking PedGeometry object memory (#767009)
Calling libparted ped_geometry_new() creates a new PedGeometry object
from malloced memory, however the corresponding ped_geometry_destroy()
is never called to destroy the object and free the memory.

Perform a resize of a FAT file system when running GParted under
valgrind identifies several memory blocks leaked via ped_geometry_new()
from resize_move_filesystem_using_libparted().  One such example:

    # valgrind --track-origins=yes --leak-check=full ./gpartedbin
    ...
    ==32069== 32 bytes in 1 blocks are definitely lost in loss record 5,419 of 11,542
    ==32069==    at 0x4C29BFD: malloc (in /usr/lib64/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==32069==    by 0x8ECD8C5: ped_malloc (libparted.c:231)
    ==32069==    by 0x8ED23C1: ped_geometry_new (geom.c:79)
    ==32069==    by 0x4764F3: GParted::GParted_Core::resize_move_filesystem_using_libparted(GParted::Partition const&, GParted::Partition const&, GParted::OperationDetail&) (GParted_Core.cc:2666)
    ==32069==    by 0x478007: GParted::GParted_Core::resize_filesystem(GParted::Partition const&, GParted::Partition const&, GParted::OperationDetail&, bool) (GParted_Core.cc:2990)
    ==32069==    by 0x478440: GParted::GParted_Core::maximize_filesystem(GParted::Partition const&, GParted::OperationDetail&) (GParted_Core.cc:3037)
    ==32069==    by 0x4769A0: GParted::GParted_Core::resize(GParted::Partition const&, GParted::Partition const&, GParted::OperationDetail&) (GParted_Core.cc:2746)
    ==32069==    by 0x47582B: GParted::GParted_Core::resize_move(GParted::Partition const&, GParted::Partition&, GParted::OperationDetail&) (GParted_Core.cc:2457)
    ==32069==    by 0x46DDB2: GParted::GParted_Core::apply_operation_to_disk(GParted::Operation*) (GParted_Core.cc:767)
    ...

There is also a leak of a PedGeometry object from
resize_move_partition().  Fix by calling ped_geometry_destroy() to
delete all the allocated PedGeometry objects and free the memory.

Bug 767009 - PedGeometry objects are memory leaked
2016-05-30 10:59:31 -06:00
Anders Jonsson b7a0cc4724 Updated Swedish translation 2016-05-25 08:59:43 +00:00
Piotr Drąg a5f1d2afec Updated Polish translation 2016-05-21 15:08:42 +02:00
Anders Jonsson 22dcc58fab Updated Swedish translation 2016-05-21 11:11:40 +00:00
Dušan Kazik 2477dffc06 Updated Slovak translation 2016-05-21 07:31:12 +00:00
Mike Fleetwood 29be7547cd Remove outdated comment fragment from activate_mount_partition()
Outdated by commit:
    6e97a63f49
    Always use blkid file system detection before libparted (#757781)
2016-05-20 09:25:48 -06:00
Mike Fleetwood ab923121de Replace whole path list after calibrate in apply_operation_to_disk() (#766349)
When replacing the list of paths for the other partition object involved
in either a Resize/Move or Format operation in apply_operation_to_disk()
should replace the whole list of partitions not just replace with the
first path.  Copy the whole path list is the correct action.  It makes
no material difference because secondary partition paths are only used
to discover mount points during refresh phase and not at the apply
phase, where only the primary path is used.

Bug 766349 - Resolve code ugliness with partition path getting set to
             "copy of /dev/SRC"
2016-05-20 09:25:35 -06:00
Mike Fleetwood b77fef0dd5 Stop relying on sort order when adding real paths in calibrate (#766349)
Quoting the relevant comments from GParted_Core::calibrate_partition():
    Re-add the real partition path from libparted.

    When creating a copy operation by pasting into unallocated space the
    list of paths for the partition object was set to
    ["Copy of /dev/SRC"] because the partition didn't yet exist before
    the operations were applied.  Additional operations on that new
    partition also got the list of paths set to ["Copy of /dev/SRC"].
    This re-adds the real path to the start of the list making it
    ["/dev/NEW", "Copy of /dev/SRC"].  This provides the real path for
    file system specific tools used during those additional operations
    such mkfs for the format operation or fsck and others for the
    resize/move operation.

    FIXME: Having this work just because "/dev/NEW" happens to sort
    before "Copy of /dev/SRC" is ugly!  Probably have a separate display
    path which can be changed at will without affecting the list of real
    paths for the partition.

Having a separate display path is overly complicated and unnecessary.
Just replace the list of paths with the real one reported by libparted
if it contained "Copy of /dev/SRC", determined by checking if the file
exists.  Otherwise continue to add the libparted name as an alternate
path.  Whole disk devices can never be named "Copy of /dev/SRC" because
they are not partitioned so never created or deleted by GParted, only
ever written to, hence don't need the extra exists test logic.

Bug 766349 - Resolve code ugliness with partition path getting set to
             "copy of /dev/SRC"
2016-05-20 09:20:02 -06:00
Mike Fleetwood 302cc8041e Stop overriding real path when pasting into existing partitions (#766349)
When composing a copy operation it always named the destination
partition as "copy of /dev/SRC".  For the case of pasting into
unallocated space creating a new partition this was the right thing to
do as the partition doesn't yet exist so the path is not yet known.
However for the case of pasting into an existing partition the path is
known and replacing it with "copy of /dev/SRC" is wrong.  No other
operation when operating on an existing partition changes it path.

Given a set of existing partitions, sdb1 to sdb4, compose a set of copy
operations as: copy sdb1 to sdb2, copy sdb2 to sdb3 and copy sdb3 to
sdb4.  The displayed partitions before being applied become:
    /dev/sdb1
    copy of /dev/sdb1
    copy of copy of /dev/sdb1
    copy of copy of copy of /dev/sdb1
And the pending operations are named:
    Copy /dev/sdb1 to /dev/sdb2
    Copy copy of /dev/sdb1 to /dev/sdb3
    Copy copy of copy of /dev/sdb1 to /sev/sdb4

This is perverse.  In the case of pasting into an existing partition
keep the real path name.  This keeps the partitions being displayed as:
    /dev/sdb1
    /dev/sdb2
    /dev/sdb3
    /dev/sdb4
And the pending operations named as:
    Copy /dev/sdb1 to /dev/sdb2
    Copy /dev/sdb2 to /dev/sdb3
    Copy /dev/sdb3 to /dev/sdb4
Much more understandable.

Also switch to an upper case "C" in "Copy of /dev/SRC" as the temporary
path name when pasting into unallocated space.  Finally update the
comment in calibrate_partition() to describe the remaining cases when
re-adding the path is still required.

Bug 766349 - Resolve code ugliness with partition path getting set to
             "copy of /dev/SRC"
2016-05-20 09:20:02 -06:00
Baurzhan Muftakhidinov 7bf8760346 Updated Kazakh translation 2016-05-17 10:37:49 +00:00
Curtis Gedak 4761f2e7cb Append -git to version for continuing development 2016-04-26 09:20:15 -06:00
Curtis Gedak d66c544a45 ========== gparted-0.26.0 ========== 2016-04-26 09:02:57 -06:00
Daniel Șerbănescu bf00339d71 Updated Romanian translation 2016-04-22 07:54:08 +00:00
Sveinn í Felli c8bc8a81f1 Updated Icelandic translation 2016-04-19 19:58:41 +00:00
Cédric Valmary a77698c64b Updated Occitan translation 2016-04-19 17:42:52 +00:00
Rafael Fontenelle 5258426f72 Updated Brazilian Portuguese translation 2016-04-19 17:18:34 +00:00
Rafael Fontenelle 3a8ba26937 Updated Brazilian Portuguese translation 2016-04-19 17:18:09 +00:00
Claude Paroz 3f28e5df2b Updated French translation 2016-04-19 18:52:54 +02:00
Mike Fleetwood 94979a3805 Add symbolic constants SETTLE_DEVICE_*_MAX_WAIT_SECONDS
Make the code a little more self documenting by adding the symbolic
constants:
    SETTLE_DEVICE_APPLY_MAX_WAIT_SECONDS
    SETTLE_DEVICE_PROBE_MAX_WAIT_SECONDS
which highlight that settle_device() is called in two different
contexts, device probe and apply operations, with two different timeout
values.
2016-04-18 12:56:51 -06:00
Mike Fleetwood fd9013d5f6 Wait for udev to recreate /dev/PTN entries when calibrating (#762941)
File system specific commands sometimes fail reporting that the
partition specific /dev entry doesn't exist.  Example failing check
operation details:

    Check and repair file system (ext4) on dev/sdb4
      calibrate /dev/sdb4
        path: /dev/sdb4 (partition)
        start: 4196352
        end: 6293503
        size: 2097152 (1.00 GiB)
      check file system on /dev/sdb4 for errors and (if possible) fix them
        e2fsck -f -y -bv -C 0 /dev/sdb4
          e2fsck 1.42.9 (28-Dec-2013)
          e2fsck: No such file or directory while trying to open /dev/sdb4
          Possibly non-existent device?

This has been reproduced on CentOS 7.  Debugging shows that the
libparted calls used to re-read the partition details in
GParted_Core::calibrate_partition() leads to udev removing and re-adding
all the partition /dev entries for the disk.

    # udevadm monitor &
    # gpartedbin
    ...
     16.480662 +12.618659 calibrate_partition()          calling get_device("/dev/sdb", lp_device) ...
     16.483644 +0.002982 calibrate_partition()          get_device() returned
     16.483678 +0.000034 calibrate_partition()          calling get_disk(lp_device, lp_disk) ...
     16.618113 +0.134435 calibrate_partition()          get_disk() returned
    KERNEL[19275.707968] remove   /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb1 (block)
     16.618561 +0.000448 destroy_device_and_disk()      calling ped_disk_destroy(lp_disk) ...
     16.618584 +0.000023 destroy_device_and_disk()      ped_disk_destroy() returned
     16.618591 +0.000007 destroy_device_and_disk()      calling ped_device_destroy(lp_disk) ...
     16.618602 +0.000011 destroy_device_and_disk()      ped_device_destroy() returned
     16.618687 +0.000085 calibrate_partition()          return true
     16.618851 +0.000164 execute_command()              e2fsck -f -y -v -C 0 /dev/sdb4
    KERNEL[19275.708389] remove   /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb2 (block)
    KERNEL[19275.708500] remove   /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb3 (block)
    KERNEL[19275.708643] remove   /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb4 (block)
    KERNEL[19275.768278] change   /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb (block)
    KERNEL[19275.771171] add      /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb1 (block)
    KERNEL[19275.771360] add      /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb2 (block)
    KERNEL[19275.771542] add      /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb3 (block)
    KERNEL[19275.775858] add      /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb4 (block)
    UDEV  [19275.820153] remove   /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb3 (block)
    UDEV  [19275.823152] remove   /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb4 (block)
    UDEV  [19275.828275] remove   /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb1 (block)
     16.742735 +0.123884 execute_command()              exit status 8
    UDEV  [19275.841425] remove   /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb2 (block)
    UDEV  [19275.905478] change   /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb (block)
    UDEV  [19276.013580] add      /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb3 (block)
    UDEV  [19276.034728] add      /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb4 (block)
    UDEV  [19276.174840] add      /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb1 (block)
    UDEV  [19276.237105] add      /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0/block/sdb/sdb2 (block)

So exactly when GParted is running the external e2fsck command, udev is
in the middle of removing and re-adding all the /dev partition entries
for the disk.  Hence the above failure reporting that /dev/sdb4 didn't
exist.  This error depends on the timing between GParted running the
external file system specific command and udev removing and re-adding
the entries, so sometimes it works and sometimes it fails.

Further debugging showed that simply opening and closing the whole disk
device read-write triggers the same removing and re-adding of all the
partition /dev entries with udev >= 219.  Opening the whole disk device
read-write is what libparted has always done until this post
libparted 3.2 patch to make it open read-only when probing:

    http://git.savannah.gnu.org/cgit/parted.git/commit/?id=44d5ae0115c4ecfe3158748309e9912c5aede92d
    libparted: Use read only when probing devices on linux (#1245144)

To fix this simply wait for udev devices to settle in
calibrate_partitions().  The longest I have seen udev take to do this is
0.80 seconds in a VM.  Wait up to 10 seconds as is done in commit() ->
commit_to_os(), also called when applying operations.

On configurations which don't have this issue execution of udevadm
settle, which will return immediately, adds at most 0.1 seconds to the
time taken for the calibrate step.  This won't be noticed in the time
taken of the operation details so there is no point in trying to avoid
executing udevadm settle when not needed.

Bug 762941 - Operations sometimes failing with: No such file or
             directory
2016-04-18 12:56:51 -06:00
Γιάννης Κουτσούκος a93a678a7b Updated Greek translation 2016-04-17 18:39:33 +00:00
Stas Solovey 127e02cd04 Updated Russian translation 2016-04-13 18:19:30 +00:00
Cédric Valmary 50e47e41df Updated Occitan translation 2016-04-11 19:35:47 +00:00
Mike Fleetwood e0a208576d Minor tidyup in load_proc_partitions_info_cache()
Minor issues:
1) In the while loop reading from /proc/partitions into variable line,
   just after the sscanf() call the variable was re-purposed to hold the
   device name making the code unnecessarily hard to follow.
2) Variable c_str was a fixed sized buffer holding the device name read
   from /proc/partitions.
3) Variable c_str name provides no meaning as to what data it holds.
4) Return value from all the Utils::regexp_label() calls is converted
   from Glib::ustring to std::string to be stored in device variable.

Resolve by using Utils::regexp_label() to extract the device name from
each line in /proc/partitions and store in the variable device, already
used for this purpose and now changed to type Glib::ustring.
2016-04-07 10:05:40 -06:00
Mike Fleetwood d04826cc27 Use realpath() safely (#764369)
realpath(3) manual page says:

    BUGS
        The POSIX.1-2001 standard version of this function is broken by
        design, since it is impossible to determine a suitable size for
        the output buffer, resolved_path.  According to POSIX.1-2001 a
        buffer of size PATH_MAX suffices, but PATH_MAX need not be a
        defined constant, and may have to be obtained using pathconf(3).
        And asking pathconf(3) does not really help, since, on the one
        hand POSIX warns that the result of pathconf(3) may be huge and
        unsuitable for mallocing memory, and on the other hand
        pathconf(3) may return -1 to signify that PATH_MAX is not
        bounded.  The resolved_path == NULL feature, not standardized in
        POSIX.1-2001, but standardized in POSIX.1-2008, allows this
        design problem to be avoided.

The resolved_path == NULL feature of realpath() has existed as a Glibc
extension since realpath() was first added to Glibc 1.90, released in
June 1996.  Therefore it can be used unconditionally.

    https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=fa0bc87c32d02cd81ec4d0ae00e0d943c683e6e1

Bug 764369 - Use realpath() safely
2016-04-07 10:05:40 -06:00
Mike Fleetwood a681f9f637 Replace 32-bit member variable "index" with wider local variables (#764658)
The previous commit (Fix crash reading NTFS usage when there is no
/dev/PTN entry) identified that the FileSystem member variable "index"
is too small on 64-bit machines.  Also this member variable stores no
FileSystem class information and was being used as a local variable.

Replace with local variables of the of the correct type, wide enough to
store the npos not found value.

Bug 764658 - GParted crashes when reading NTFS usage when there is no
             /dev/PTN entry
2016-04-07 09:56:00 -06:00