Commit Graph

497 Commits

Author SHA1 Message Date
Mike Fleetwood 7255c8af40 Use UUID and label of SWRaid arrays too (#756829)
In cases where blkid wrongly reports a file system instead of an SWRaid
member (sometimes confused by metadata 0.90/1.0 mirror array or old
version not recognising SWRaid members), the UUID and label are
obviously wrong too.  Therefore have to use the UUID and label returned
by the mdadm query command and never anything reported by blkid or any
file system specific command.

Example of blkid reporting the wrong type, UUID and label for /dev/sda1
and the correct values for /dev/sdb1:

    # blkid | egrep 'sd[ab]1'
    /dev/sda1: UUID="10ab5f7d-7d8a-4171-8b6a-5e973b402501" TYPE="ext4" LABEL="chimney-boot"
    /dev/sdb1: UUID="15224a42-c25b-bcd9-15db-60004e5fe53a" UUID_SUB="0a095e45-9360-1b17-0ad1-1fe369e22b98" LABEL="chimney:1" TYPE="linux_raid_member"

    # mdadm -E -s -v
    ARRAY /dev/md/1  level=raid1 metadata=1.0 num-devices=2 UUID=15224a42:c25bbcd9:15db6000:4e5fe53a name=chimney:1
       devices=/dev/sda1,/dev/sdb1
    ...
    ARRAY /dev/md127 level=raid1 num-devices=2 UUID=8dc7483c:d74ee0a8:b6a8dc3c:a57e43f8
       devices=/dev/sdb6,/dev/sda6
    ...

NOTES:
* In mdadm terminology the label is called the array name, hence name=
  parameter for array md/1 in the above output.
* Metadata 0.90 arrays don't support naming, hence the missing name=
  parameter for array md127 in the above output.

Bug 756829 - SWRaid member detection enhancements
2015-11-02 10:03:45 -07:00
Mike Fleetwood 0ce9857380 Move busy detection of SWRaid members into the new module (#756829)
Add active attribute to the cache of SWRaid members.  Move parsing of
/proc/mdstat to discover busy SWRaid members into the cache loading
code.  New parsing code is a little different because it is finding all
members of active arrays rather than determining if a specific member is
active.

Bug 756829 - SWRaid member detection enhancements
2015-11-02 10:03:45 -07:00
Mike Fleetwood 5f02bcf463 Detect Linux SWRaid members by querying mdadm (#756829)
Detection of Linux SWRaid members currently fails in a number of cases:

1)  Arrays which use metadata type 0.90 or 1.0 store the super block at
    the end of the partition.  So file system signatures in at least
    linear and mirrored arrays occur at the same offsets in the
    underlying partitions.  As libparted only recognises file systems
    this is what is detected, rather than an SWRaid member.

    # mdadm -E -s -v
    ARRAY /dev/md/1  level=raid1 metadata=1.0 num-devices=2 UUID=15224a42:c25bbcd9:15db6000:4e5fe53a name=chimney:1
       devices=/dev/sda1,/dev/sdb1
    ...
    # wipefs /dev/sda1
    offset               type
    ----------------------------------------------------------------
    0x438                ext4   [filesystem]
                         LABEL: chimney-boot
                         UUID:  10ab5f7d-7d8a-4171-8b6a-5e973b402501

    0x1fffe000           linux_raid_member   [raid]
                         LABEL: chimney:1
                         UUID:  15224a42-c25b-bcd9-15db-60004e5fe53a

    # parted /dev/sda print
    Model: ATA VBOX HARDDISK (scsi)
    Disk /dev/sda: 34.4GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos

    Number  Start   End     Size    Type      File system  Flags
     1      1049kB  538MB   537MB   primary   ext4         boot, raid
    ...

2)  Again with metadata type 0.90 or 1.0 arrays blkid may report the
    contained file system instead of an SWRaid member.  Have a single
    example of this configuration with a mirrored array containing the
    /boot file system.  Blkid reports one member as ext4 and the other as
    SWRaid!

    # blkid | egrep 'sd[ab]1'
    /dev/sda1: UUID="10ab5f7d-7d8a-4171-8b6a-5e973b402501" TYPE="ext4" LABEL="chimney-boot"
    /dev/sdb1: UUID="15224a42-c25b-bcd9-15db-60004e5fe53a" UUID_SUB="0a095e45-9360-1b17-0ad1-1fe369e22b98" LABEL="chimney:1" TYPE="linux_raid_member"

    Bypassing the blkid cache gets the correct result.

    # blkid -c /dev/null /dev/sda1
    /dev/sda1: UUID="15224a42-c25b-bcd9-15db-60004e5fe53a" UUID_SUB="d0460f90-d11a-e80a-ee1c-3d104dae7e5d" LABEL="chimney:1" TYPE="linux_raid_member"

    However this can't be used because if a user has a floppy configured
    in the BIOS but no floppy attached, GParted will wait for minutes as
    the kernel tries to access non-existent hardware on behalf of the
    blkid query.  See commit:
        18f863151c
        Fix long scan problem when BIOS floppy setting incorrect

3)  Old versions of blkid don't recognise SWRaid members at all so always
    report the file system when found.  Occurs with blkid v1.0 on
    RedHat / CentOS 5.

The only way I can see how to fix all these cases is to use the mdadm
command to query the configured arrays.  Then use this information for
first choice when detecting partition content, making the order: SWRaid
members, libparted, blkid and internal.

GParted shell wrapper already creates temporary blank udev rules to
prevent Linux Software RAID arrays being automatically started when
GParted refreshes its device information[1].  However an administrator
could manually stop or start arrays or change their configuration
between refreshes so GParted must load this information every refresh.
On my desktop with 4 internal hard drives and 3 testing Linux Software
RAID arrays, running mdadm adds between 0.20 and 0.30 seconds to the
device refresh time.

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

Bug 756829 - SWRaid member detection enhancements
2015-11-02 10:03:45 -07:00
Mike Fleetwood 037020b116 Create new method GParted_Core::useable_device() (#755495)
Abstract code checking sector size and ensuring the first sector of a
candidate disk device can be read into new
GParted_Core::useable_device() method.

Bug 755495 - GParted allowing partitioning of large sector devices
             specified on the command line, when built with old
             libparted which doesn't support it
2015-10-08 13:00:01 -06:00
Mike Fleetwood d925bd2bb5 Stop including removed <sigc++/class_slot.h> header (#756035)
Libsigc++2 version 2.5.2 and later removed header file
<sigc++/class_slot.h>.  Quoting the NEWS file for version 2.5.2:

    Remove useless headers: sigc++/class_slot.h ...

Libsigc++2 version 2.5.2 NEWS file:
https://git.gnome.org/browse/libsigc++2/tree/NEWS?id=2.5.2

Bug 756035 - GParted does not compile with newer gtkmm libraries in
             Fedora 23
2015-10-05 10:14:35 -06:00
Albert Young 584137b32b Remove prohibited characters from FAT16/32 labels (#755608)
GParted waits forever when attempting to set a FAT16/32 file system
label which contains prohibited characters [1][2].  This is because
mlabel asks a question and is waiting for input.  Force cancelling the
operation doesn't work either as GParted sends signal 2 (interrupt i.e.
[Ctrl-C]) but mtools commands specifically ignores this and a number of
other signals.  Have to kill mlabel with signal 9 (kill) to regain
control of GParted.

Mlabel command with prohibited characters in the label:

    # export MTOOLS_SKIP_CHECK=1
    # mlabel ::"MYLABEL/   " -i /dev/sdb10
    Long file name "MYLABEL/   " contains illegal character(s).
    a)utorename A)utorename-all r)ename R)ename-all
    s)kip S)kip-all q)uit (aArRsSq):

Remove prohibited characters from FAT16/32 file systems labels when
creating and labelling them.  Also upper case the label to meet label
requirements [1][2].  This silently corrects the label and the actual
label applied will be displayed when GParted refreshes after applying
the operation.

[1] Microsoft TechNet: Label
    https://technet.microsoft.com/en-us/library/bb490925.aspx

[2] Replicated in Wikikedia: label (command)
    https://en.wikipedia.org/wiki/Label_%28command%29

Bug 755608 - Labeling fat16/fat32 partitions hangs if certain characters
             included in label
2015-10-04 09:57:07 -06:00
Mike Fleetwood cbfb7e51f5 Replace Operation class members index and index_extended with local variables (#755214)
These member variables store no Operation class information and were
being used as local variables.  Replace with local variables.

Also indent a code block within an if clause so that the compiler can
confirm that the new local variable isn't used uninitialised.  Prevents
this compiler warning:
    OperationResizeMove.cc: In member function 'void GParted::OperationResizeMove::apply_normal_to_visual(std::vector<GParted::Partition, std::allocator<GParted::Partition> >&)':
    OperationResizeMove.cc:125: warning: 'index' may be used uninitialized in this function

Bug 755214 - Refactor operation merging
2015-09-28 11:02:07 -06:00
Mike Fleetwood a1ab21285b Remove unused index parameter from Add_Operation() (#755214)
Since this commit earlier in the patchset the second optional parameter
of method Win_GParted::Add_Operation() is no longer used.  Remove it.
    Replace open coded merge of resize/move into create operation
    (#755214)

Bug 755214 - Refactor operation merging
2015-09-28 11:02:07 -06:00
Mike Fleetwood dc6ffc6a87 Move code visually re-applying create operation into parent class (#755214)
Move the code from OperationCreate::apply_to_visual() into new method
Operation::insert_new() in the parent class.  This is in preparation for
the following commit.

Bug 755214 - Refactor operation merging
2015-09-28 10:41:39 -06:00
Mike Fleetwood 27cbe36d0f Share duplicate code substituting partitions in multiple operations (#755214)
The apply_to_visual() method for the change UUID, format, label file
system and name partition operations duplicated identical code.  This
code was just substituting the partition in the disk graphic vector with
the new partition recorded in the operation, as none of these operations
change the partition boundaries.  Move this duplicate code into the
parent class in new method Operation::substitute_new().

Bug 755214 - Refactor operation merging
2015-09-28 10:41:39 -06:00
Mike Fleetwood 9b497aae14 Fix visually re-applying create operation in create-create-grow-first sequence (#755214)
After previous commit "Replace open coded merge of resize/move into
create operation (#755214)" the second created partition would disappear
from the disk graphic in the following sequence: create new #1, create
new #2 leaving space preceding, resize #1 larger.  The create new #2
operation still existed and was shown in the operation list.  It was
just that it disappeared from the disk graphic.

Remember that when each operation is created it records the partition,
or the unallocated space, to which the operation is applied at the time
the operation is created in the partition_original member variable.  In
the above sequence the resize #1 larger operation was merged back into
the create new #1 operation.  When visually re-applying the create
new #1 operation to the disk graphic, it left a smaller unallocated
partition following it.  This was smaller than the unallocated partition
recorded in the create new #2 operation, hence it failed to visually
re-apply to the disk graphic.

The insight to fix this is that it doesn't matter what size the
unallocated space was when the create new operation was constructed.  It
only matters that the new partition to be created fits in the available
unallocated space currently in the disk graphic.

Bug 755214 - Refactor operation merging
2015-09-28 10:41:39 -06:00
Mike Fleetwood cf5d8d928c Refactor merging rules into new merge_operations() (#755214)
Creation of the various operations involved various implicit rules about
how the different types of operations were merged in different cases.
This was open coded in each ::activate_*() method.  Abstract this into
new merge_operations() method and make the merging rules explicitly
specified.

NOTE:
The removal of operation type checking in the MERGE_LAST_WITH_ANY cases
is not a problem because all the Operation*::merge_operations() methods
ensure the operation types match as part of the merge attempt.

Bug 755214 - Refactor operation merging
2015-09-28 10:41:39 -06:00
Mike Fleetwood d93d8abcc4 Rename function to merge_two_operations() and update validation (#755214)
Rename Win_GParted::Merge_Operations() to merge_two_operations().  To
reflect what it does and in preparation for further refactoring of the
code.

Be more strict on the validation of the first and second indexes.  The
first operation must also be before the second operation in the
operation[] vector.  (It is actually a programming bug if first and
second fail validation.  However so far g_assert() is only being used to
validate pointers, which if wrong would likely cause the program to
eventually crash when dereferenced later.  In this case a bug would
merely cause the incorrectly specified pair of operations to not be
merged).

Move validate_display_partition_ptr() declaration in the header file to
be in the same ordering as it's definition in the source file.

Bug 755214 - Refactor operation merging
2015-09-28 10:41:39 -06:00
Mike Fleetwood 7f4ffd28d5 Encapsulate operation merging inside the Operation* classes (#755214)
Win_GParted::Merge_Operations() method was modifying the internals of
Operation* objects; in particular the partition_new member variable.
This is breaking data hiding and encapsulation tenant of object oriented
programming.

Implement exactly the same operation merge semantics, but hide the
manipulation of the internals of the Operation* objects within the
Operation* classes themselves.

Bug 755214 - Refactor operation merging
2015-09-28 10:41:39 -06:00
Mike Fleetwood 26dc3dffa7 Localise checking for an extended partition into activate_new()
As previous commit, display_partitions is now a Win_GParted member
variable so checking for the existence of an extended partition can be
localised where it is used.

Remove index_extended member variable and localise the same checking in
activate_new().
2015-09-22 09:50:11 -06:00
Mike Fleetwood 3b5471516c Localise counting of primary partitions into max_amount_prim_reached()
Now that display_partitions is a Win_GParted member variable and
therefore available throughout the class, since commit [1], calculation
of primary_count can be localised in max_amount_prim_reached() where it
is used.

Implements a FIXME and removes primary_count as a member variable.

[1] 545b75d957
    Move vector of partition objects to a Win_GParted class member (#750168)
2015-09-22 09:50:11 -06:00
Mike Fleetwood 0e32d39189 Remove unused public member variable FileSystem::success
Assume accidentally added in commit:
    52a2a9b00a
    Reduce threading (#685740)
2015-09-21 10:11:19 -06:00
Mike Fleetwood 2b57229fc2 Implement shell style exit status decoding (#754684)
Command exit status is a 1 byte value between 0 and 255. [1][2]  However
at the Unix API level the value is encoded as documented in the
waitpid(2) manual page.  This is true for the Glib API too. [3]  This is
why, for example, the comment in ext2::check_repair() reported receiving
undocumented exit status 256.  It was actually receiving exit status 1
encoded as per the waitpid(2) method.

Add shell style exit status decoding [2] to execution of all external
commands.   Return value from Utils::execute_command() and
FileSystem::execute_command() functions are now:
    0 - 125 - Exit status from the command
    126     - Error executing the command
    127     - Command not found
    128+N   - Command terminated by signal N
    255     - Unexpected waitpid(2) condition
Also adjust checking of the returned statuses as necessary.

[1] Advanced Bash-Scripting Guide: Appendix D. Exit Codes With Special
    Meanings
    http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/exitcodes.html

[2] Quote from the bash(1) manual page:

        EXIT STATUS
            ... Exit statuses fall between 0 and 255, though as
            explained below, the shell may use values above 125
            specially.  ...

            ... When a command terminates on a fatal signal N, bash uses
            the value of 128+N as the exit status.

            If a command is not found, the child process created to
            execute it returns a status of 127.  If a command is found
            but is not executable, the return status is 126.

[3] Quote from the Glib Reference Manual, Spawning Processes section,
    for function g_spawn_check_exit_status():
    https://developer.gnome.org/glib/stable/glib-Spawning-Processes.html#g-spawn-check-exit-status

        The g_spawn_sync() and g_child_watch_add() family of APIs return
        an exit status for subprocesses encoded in a platform-specific
        way.  On Unix, this is guaranteed to be in the same format
        waitpid() returns, ...

Bug 754684 - Updates to FileSystem:: and Utils::execute_command()
             functions
2015-09-21 10:11:19 -06:00
Mike Fleetwood 3eccd01f42 Time and check nearly all file system action commands (#754684)
There has been an undocumented rule that external commands displayed in
the operation details, as part of file system manipulations, only get a
time and check mark displayed when multiple commands are needed, and not
otherwise.  (GParted checks whether all commands are successful or not
regardless of whether a check mark is displayed in the operation details
or not).

EXCEPTION 1: btrfs resize

Since the following commit [1] from 2013-02-22, GParted stopped
displaying the timing for the btrfs resize command in the operation
details.  It being part of a multi-command sequence to perform the step.
This is because FileSystem::execute_command() since the commit can only
check the exit status for zero / non-zero while timing and checking the
command status but btrfs resize needs to consider some non-zero statuses
as successful.

[1] 52a2a9b00a
    Reduce threading (#685740)

EXCEPTION 2: ext2/3/4 move and copy using e2image

When use of e2image was added [2] the single command steps were timed
and check.

[2] 86111fe12a
    Use e2image to move/copy ext[234] file systems (#721516)

EXCEPTION 3: fat16/32 write label and UUID

Uses Utils::execute_command() rather than FileSystem::execute_command()
so can be separately changed.  See the following commit for resolution
of the final commands not yet timed and check mark displayed.

CHANGE:

Lets make a simpler rule of always displaying the time and a check mark
for all external commands displayed in the operation details.  However
this makes several of the other single command actions need special exit
status handling because zero success, non-zero failure is not correct
for every case.  Specifically affects resizing of reiserfs and check
repair of ext2/3/4, fat16/32, jfs and reiserfs.

After this change all external commands run as file system actions must
follow one of these two patterns of using the EXEC_CHECK_STATUS flag or
separately calling FileSystem::set_status() to register success or
failure of the command:
    exit_status = execute_command(cmd, od, EXEC_CHECK_STATUS...);
or:
    exit_status = execute_command(cmd, od, ...);
    bool success = (exit_status == 0 || exit_status == OTHER_SUCCESS_VALUE...);
    set_status(od, success );

Bug 754684 - Updates to FileSystem:: and Utils::execute_command()
             functions
2015-09-21 10:11:19 -06:00
Mike Fleetwood 83ecae4918 Refactor flags in method FileSystem::execute_command() (#754684)
Change the two optional boolean parameters into a single optional flags
parameter which uses symbolically defined names.  Makes reading the
execute_command() calls much easier to understand.  (Implemented as bit
field using the same technique as used for Glib::SpawnFlags [1]).

This changes the calls thus:

  execute_command(cmd, od)              -> (cmd, od)
  execute_command(cmd, od, false)       -> (cmd, od, EXEC_NONE)  // [2]
  execute_command(cmd, od, true )       -> (cmd, od, EXEC_CHECK_STATUS)
  execute_command(cmd, od, false, true) -> (cmd, od, EXEC_CANCEL_SAFE)
  execute_command(cmd, od, true , true) ->
                          (cmd, od, EXEC_CHECK_STATUS|EXEC_CANCEL_SAFE)

[1] SpawnFlags bitwise operators in
    /usr/include/glibmm-2.4/glibmm/spawn.h.

[2] False and EXEC_NONE are the default values for the optional third
    parameter before and after this change respectively and both mean
    the same.  This is being used in btrfs::resize() and being kept for
    now despite it being the default.

Bug 754684 - Updates to FileSystem:: and Utils::execute_command()
             functions
2015-09-21 10:11:19 -06:00
Mike Fleetwood d3e17f4484 Remove unused execute_command_timed() (#754684)
Use of execute_command_timed() was removed by this commit from
2013-02-22:
    52a2a9b00a
    Reduce threading (#685740)

Bug 754684 - Updates to FileSystem:: and Utils::execute_command()
             functions
2015-09-21 10:11:19 -06:00
Wrolf Courtney 9e950e89b4 Display list of Logical Volumes in the Partition Information dialog (754649)
Bug 754649 - Display Logical Volumes in Volume Group of LVM2 Partition
2015-09-15 20:12:12 +01:00
Mike Fleetwood 71715a1c29 Add detection of ZFS (#752862)
Requires blkid from util-linux >= 2.15, released May 2009, for
detection of ZFS.

Bug 752862 - ZFS is not recognised
2015-08-08 09:55:42 -06:00
Curtis Gedak 1561d1ae7e Add libparted ped_file_system_resize thread to avoid blocking GUI (#737022)
Since GParted commit 52a2a9b "Reduce threading (#685740)", released in
GParted 0.15.0, application of operations occurs in the main thread
running the UI, therefore long running libparted actions such as
resizing a FAT16 or FAT32 file system hang the UI for as long as it take
to complete the operation.
https://git.gnome.org/browse/gparted/commit/?id=52a2a9b00a32996921ace055e71d0e09fb33c5fe

Though this problem exists for all libparted actions, it is particularly
noticeable when performing a large resize of fat16/fat32/hfs/hfs+ file
systems.

To address this significant cause of an unresponsive GUI, this
enhancement adds threading to the libparted ped_file_system_resize
function call.

Bug 737022 - UI hangs while running libparted operations such as
             FAT16/FAT32 resizing
2015-07-19 21:57:17 +01:00
Mike Fleetwood 54d0e3d056 Remember result of searching the PATH for the hdparm command (#751251)
Previously on every refresh for every device, GParted was searching the
PATH to discover if the hdparm command existed.  Stracing GParted showed
that calling Glib::find_program_in_path("hdparm") made the following OS
calls:
    access("/usr/lib64/qt-3.3/bin/hdparm", X_OK) = -1 ENOENT (No such file or directory)
    access("/usr/local/sbin/hdparm", X_OK) = -1 ENOENT (No such file or directory)
    access("/usr/local/bin/hdparm", X_OK) = -1 ENOENT (No such file or directory)
    access("/sbin/hdparm", X_OK) = 0
    getuid()                    = 0
    stat("/sbin/hdparm", {st_mode=S_IFREG|0755, st_size=137, ...}) = 0
    stat("/sbin/hdparm", {st_mode=S_IFREG|0755, st_size=137, ...}) = 0

The Linux VFS is very fast but repeatedly doing this is wasteful.
Remember the result of searching the PATH for the hdparm command at
startup and refresh this when the [Rescan For Supported Actions] button
is pressed in the File System Support dialog.  This is the same as
GParted already does for file system specific commands and their
capabilities.

Bug 751251 - Show serial number in device information
2015-07-01 10:22:57 -06:00
Mike Fleetwood 4b72ecd44e Display device serial numbers (#751251)
Run "hdparm -I /dev/DISK" to get the hard drive serial number of
every device which has one and display it in the Device Information.
The displayed value can either be the actual serial number, "none" or
blank.  "none" means the device doesn't have a hard drive serial number,
such as for Linux software RAID arrays, BIOS fake RAID arrays or USB
flash drives.  Blank means something went wrong getting the serial
number.  Either it couldn't be found in the hdparm output or the hdparm
command wasn't installed.

Example real hard drive:
    # hdparm -I /dev/sda
    ...
    ATA device, with non-removable media
            Model Number:       SAMSUNG HM500JI
            Serial Number:      S1WFJDSZ123732
    ...

Example Linux software RAID array:
    # hdparm -I /dev/md127

    /dev/md127:
     HDIO_DRIVE_CMD(identify) failed: Inappropriate ioctl for device

On my desktop with 4 internal hard drives 2 Linux software RAID arrays
on those hard drives, 2 USB flash drives and 1 USB hard drive attached,
running hdparm 9 times added 0.07 seconds to the device refresh time.

Bug 751251 - Show serial number in device information
2015-07-01 10:22:47 -06:00
Mike Fleetwood 8308ee6051 Support changing the UUID of a btrfs file system (#751337)
Btrfs-progs 4.1, released June 2015, includes support for changing the
UUID of a btrfs file system using the btrfstune command.  Check for
availability by looking for the -u option in the btrfstune help output.
Use btrfstune like this:

    # umount /dev/sdb1
    # btrfstune -f -u /dev/sdb1
    Current fsid: e7ad5dba-d721-4f99-990b-1ba2901c8ad2
    New fsid: 231563d9-e173-410d-b1da-d34c4319a423
    Set superblock flag CHANGING_FSID
    Change fsid in extents
    Change fsid on devices
    Clear superblock flag CHANGING_FSID
    Fsid change finished
    # echo $?
    0

Bug 751337 - btrfstune in btrfs-progs 4.1 supports changing the file
             system UUID
2015-06-28 10:57:58 -06:00
Mike Fleetwood 9be8d37600 Delay loading LVM2_PV_info cache until actually needed (#750582)
The lvm query commands were always run and the cache loaded even if
GParted, actually blkid, didn't identify any LVM2 PVs.  (GParted uses
libparted and blkid to identify partition content and the lvm commands
to provide the needed configuration details).

Now implement complete lazy initialization of the cache.  Never force
loading of the cache.  The cache is only loaded when the first value is
accessed from it.  When there are no LVM2 PVs, the cache is never
queried, so never loaded.  All the needed infrastructure for delayed
loading was previously added by this commit from 2011-12-11:
    ff8ad04120
    Lazy initialize the cache from querying LVM2 PVs (#160787)
Every public member function which access values from the cache already
calls initialize_if_required().  Just need to replace force loading of
the cache with a function which just clears the cache.

On my desktop, only when there are no LVM2 PVs, not loading the cache
and therefore not executing these external commands in
load_lvm2_pv_info_cache() saves 1.0 seconds of the 3.7 seconds it takes
to perform the a refresh in GParted:
    lvm vgscan
    lvm pvs ... -o pv_name,...
    lvm pvs ... -o vg_name,...

Bug 750582 - Refactor the LVM2_PV_Info module object interface and
             internal cache representation
2015-06-13 10:56:31 -06:00
Mike Fleetwood e6f7ea01f9 Parse LVM2_PV_Info cache into fields while loading (#750582)
GParted used to cache the results of the "lvm pvs" commands used to query
the state of the Logical Volume Manager as a series of lines of text.
Then every time a particular value was queried GParted would split all
the lines of text into fields until the required value was found.

Stop this repeat splitting of cached lines of text.  Instead parse the
lines of text into separate fields and store in structures of values of
the correct type in the cache.

Bug 750582 - Refactor the LVM2_PV_Info module object interface and
             internal cache representation
2015-06-13 10:56:15 -06:00
Mike Fleetwood 2c5e7b0d90 Stop needing any LVM2_PV_Info objects (#750582)
The LVM2_PV_Info cache had a pretend multi-object interface, yet all the
data is static.  An LVM2_PV_Info object doesn't contain any member
variables, yet was needed just to call the member functions.

Make all the member functions static removing the need to use any
LVM2_PV_Info objects.

Bug 750582 - Refactor the LVM2_PV_Info module object interface and
             internal cache representation
2015-06-13 10:56:12 -06:00
Mike Fleetwood 81f0b934bc Stop borrowing the constructor to load the LVM2_PV_Info cache (#750582)
An LVM2_PV_Info object contains no member variables as all the data is
static (exists once in the program and accessed by all objects).  The
constructor did nothing, except when passed true to load the cache.

Provide a separate load_cache() member function and remove the
constructors and destructor which do nothing.  The C++ compiler will
provide a default constructor and destructor, which don't do anything as
there are no member variables to initialise and finalise.

This makes the interface a little easier to understand.  Mostly a step
along the way of refactoring how the LVM2_PV_Info cache module works.

Bug 750582 - Refactor the LVM2_PV_Info module object interface and
             internal cache representation
2015-06-13 10:55:48 -06:00
Mike Fleetwood 7a4a375ed6 Remove Set_Data() from the copy, resize/move and new dialog class APIs
The copy, resize/move and new dialog classes (Dialog_Partition_Copy,
Dialog_Partition_Resize_Move and Dialog_Partition_New respectively) had
to be used like this:

    construct dialog object passing some parameters
    call Set_Data() to pass more parameters
    run() dialog
    call Get_New_Partition()

There is nothing in the classes which forces Set_Data() to be called,
but it must be called for the dialogs to work and prevent GParted from
crashing.

Make these class APIs safer by making it impossible to program
incorrectly in this regard.  Move all the additional parameters from
each Set_Data() method to each constructor.  The constructors just call
the now private set_data() methods.
2015-06-10 10:44:33 -06:00
Mike Fleetwood 32a5ace156 Rename Dialog_Base_Partition member to new_partition
The member variable was named selected_partition.  It is assigned from
Win_GParted::selected_partition_ptr (which is a pointer to a const
partition object so is never updated).  This gives connotations that it
won't be modified.

However it is updated freely as the new resultant partition object is
prepared before being returned from the dialog, most notable in the
Get_New_Partition() methods.

Therefore rename from selected_partition to new_partition.
2015-06-10 10:44:33 -06:00
Mike Fleetwood 8b96f8409f Stop copying selected_partition back on itself in the copy dialog (#750168)
The code goes like this:

    Dialog_Partition_Copy::Get_New_Partition()
        call Dialog_Base_Partition::Get_New_Partition()
            Update this->selected_partition with results from running
            the dialog.
            return this->selected_partition by value.
        Save value back to this->selected_partition.
        Update this->selected_partition some more.
        return this->selected_partition by value.

So there is an unnecessary copy of the partition object returned from
the base class Get_New_Partition() function back to the same variable in
the derived copy class Get_New_Partition() function.

Need to keep the base class Get_New_Partition() function as derived
class Dialog_Partition_Resize_Move uses that implementation as it
doesn't override it, and it's part of the interface.

Avoid this unnecessary copy by moving base class Get_New_Partition()
code into a new private function, called prepare_new_partition(), which
doesn't return anything.  Then have Get_New_Partition() in both classes
just return the required partition object.  Like this:

    Dialog_Base_Partition::Get_New_Partition()
        call prepare_new_partition()
        return this->selected_partition by value.

    Dialog_Partition_Copy::Get_New_Partition()
        call Dialog_Base_Partition::prepare_new_partition()
        Update this->selected_partition some more.
        return this->selected_partition by value.

Bug 750168 - Reduce the amount of copying of partition objects
2015-06-10 10:44:33 -06:00
Mike Fleetwood 90e3ed68fc Shallow copy Device object into Operation object (#750168)
When Operation objects are created they take a copy of the Device object
to which the operation is to be applied.  The Device object includes a
vector of all the contained Partition objects currently on the device,
so these get copied too.

These additional deep copied Partition objects in the Operation object
are never accessed.  Therefore don't copy the contained Partition
objects when copying the Device object into the Operation object.

Bug 750168 - Reduce the amount of copying of partition objects
2015-06-10 10:44:33 -06:00
Mike Fleetwood ece945685c Stop copying selected partition object in Manage Flags dialog (#750168)
When opening the Manage Flags dialog, creation of the dialog object was
creating a copy of the selected partition object.  If this was an
extended partition it also included recursively constructing the
contained logical partitions too.

Instead, replace the partition object in the DialogManageFlags class
with a reference to it.

Bug 750168 - Reduce the amount of copying of partition objects
2015-06-10 10:44:33 -06:00
Mike Fleetwood efaea94301 Stop copying selected partition object in Information dialog (#750168)
When opening the Partition Information dialog, creation of the dialog
object was creating a copy of the partition object to be displayed.  If
this was an extended partition it also included recursively constructing
the contained logical partitions too.

Instead, replace the partition object in the Dialog_Partition_Info class
with a reference to it.

NOTE:
In C++ a reference is really just a pointer under the hood.  As such,
dereferences of a pointer to an object in the context of needing a
reference to the object doesn't copy the object.  It merely initialises
the reference from the pointer.

Specifically, with this prototype:
    Dialog_Partition_Info( const Partition & partition );
and the dialog object being constructed in Win_GParted::activate_info():
    Dialog_Partition_Info dialog( *selected_partition_ptr );
the partition object is not copy constructed.  A reference (pointer) to
it is merely passed to the dialog constructor.

Bug 750168 - Reduce the amount of copying of partition objects
2015-06-10 10:43:43 -06:00
Mike Fleetwood 6ae327c8f9 Assert selected_partition_ptr is valid before use (#750168)
Further ensure that a bug doesn't get introduced with the use of
selected_partition_ptr, by asserting that it points to a current
partition object in the vector of display partitions.

After deliberately breaking the code so that selected_partition_ptr
points to some other partition object, trying to display the Information
dialog causes this crash:

======================
libparted : 2.4
======================
**
ERROR:Win_GParted.cc:989:void GParted::Win_GParted::set_valid_operations(): assertion failed: (valid_display_partition_ptr( selected_partition_ptr ))
Aborted (core dumped)

At this point in the code:

    973  void Win_GParted::set_valid_operations()
    974  {
    ...
    986          // No partition selected ...
    987          if ( ! selected_partition_ptr )
    988                  return ;
>>  989          g_assert( valid_display_partition_ptr( selected_partition_ptr ) );  // Bug: Not pointing at a valid display partition object

Bug 750168 - Reduce the amount of copying of partition objects
2015-06-10 10:43:40 -06:00
Mike Fleetwood da39e3cad3 Change selected partition into a pointer (#750168)
Now that TreeView_Details and DrawingAreaVisualDisk classes store and
pass pointers to partition objects in the Gtk signal callbacks, change
the selected partition into a pointer too.

Bug 750168 - Reduce the amount of copying of partition objects
2015-06-10 10:43:14 -06:00
Mike Fleetwood cc1448abd2 Store pointers to partition objects in DrawingAreaVisualDisk (#750168)
This stops copying of each displayed partition object into the
DrawingAreaVisualDisk class.

Bug 750168 - Reduce the amount of copying of partition objects
2015-06-10 10:43:14 -06:00
Mike Fleetwood acd5d7e580 Store pointers to partition objects in TreeView_Details (#750168)
This stops copying of each displayed partition object into the
TreeView_Details class.

It also stops copy constructing lots of partition objects when just
clicking on a partition in the disk graphic.  The disk graphic needs to
inform the main GUI and then the partition list which partition has been
selected.  The call sequence goes like:

    DrawingAreaVisualDisk::on_button_press_event(event)
      Win_GParted::on_partition_selected(partition_ptr, src_is_treeview)
        TreeView_Detail::set_selected(partition_ptr)
          TreeView_Detail::set_selected(rows, partition_ptr,
                                        inside_extended)

Relevant source and highlighted comparison line:

   140  bool TreeView_Detail::set_selected( Gtk::TreeModel::Children rows,
   141                                      const Partition * partition_ptr, bool inside_extended )
   142  {
   143          for ( unsigned int t = 0 ; t < rows .size() ; t++ )
   144          {
>> 145                  if ( static_cast<Partition>( rows[t][treeview_detail_columns.partition] ) == *partition_ptr )
   146                  {
   147                          if ( inside_extended )
   148                                  expand_all() ;
   149
   150                          set_cursor( static_cast<Gtk::TreePath>( rows[ t ] ) ) ;
   151                          return true ;
   152                  }
   153
   154                  if ( set_selected( rows[t].children(), partition_ptr, true ) )
   155                          return true ;
   156          }
   157
   158          return false ;
   159  }

Then in this function the partition selected in the disk graphic
(partition_ptr parameter) is compared in turn with each partition object
stored in the Gtk::TreeView model to find the matching one to mark it as
selected.  This mere act of accessing the partition object stored in a
row of the Gtk::TreeView model causes it to be copy constructed.  So
clicking on the 5th partition in the disk graphic will copy construct
the first 5 partition objects just to do a compare to find the matching
one.

This is because it is not possible to get a reference from a
Gtk:TreeViewProxy in gtkmm.  Merely accessing a value in a Gtk::TreeView
model takes a copy of that value.

    Subject: get a reference from a Gtk::TreeValueProxy
    http://comments.gmane.org/gmane.comp.gnome.gtkmm/2217
    http://marc.info/?t=104400417500001&r=1&w=4

Bug 750168 - Reduce the amount of copying of partition objects
2015-06-10 10:43:14 -06:00
Mike Fleetwood c430acf52a Pass by pointer in the signal_partition_selected callbacks (#750168)
Change from passing a reference to the selected partition, to passing a
pointer to the selected partition in the signal_partition_selected
callbacks between the disk graphic, partition list and core GUI modules.

This is an enabler for the following patches.

Bug 750168 - Reduce the amount of copying of partition objects
2015-06-10 10:43:14 -06:00
Mike Fleetwood 545b75d957 Move vector of partition objects to a Win_GParted class member (#750168)
Win_GParted::Refresh_Visual() used a local variable containing a copy of
the vector of partitions in the current device to be displayed.  After
visually applying pending operations it loaded copies of each partition
object into the GUI widgets to display the disk graphic and partition
list, DrawingAreaVisualDisk and TreeView_Details classes respectively.
When a partition is selected in the UI, again a partition object is
copied.  Also several of the partition dialogs, including the
information dialog, take a copy of the partition object.  All these are
copies of the same set of partition objects, those currently being
displayed in the UI.

Move the vector of displayed partitions from a local variable in
Refresh_Visual() to a Win_GParted member variable.  This will allow for
the above cases to be changed to used pointers and references to the
same set of partition objects.

The valid lifetime of pointers to elements in this partition object
vector is from one refresh to the next, when the vector is cleared and
repopulated with a new set of partition objects.  This is exactly what
is needed as the GUI widgets are reloaded on each refresh, the selected
partition is reset and none of the partition dialog objects exist.
Dialog objects being created and destroyed on each use.

On the other hand some copies of partition objects currently being
displayed, still need to be made because they have lifetimes which need
to last longer than the next call to Refresh_Visual().  Specifically the
source of the copy partition and the partition objects copied into the
in the list of pending operations.

Bug 750168 - Reduce the amount of copying of partition objects
2015-06-10 10:42:36 -06:00
Mike Fleetwood 8bbb77f1f8 Remove cylinder size adjustments in the copy dialog (#749867)
BUF in the copy dialog class, Dialog_Partition_Copy, is use to adjust
limits in 2 cases:

1) Minimum size when copying an XFS file system

Minimum size was set to the used space + 2 * cylinder size (typically
plus ~16 MiB).  This commit from 2004-12-20 added it:
    a54b52ea33
    xfs copy now uses xfsdump and xfsrestore. icw some hacks in the other 2

Issues:
* This is increasing the minimum XFS file system size when copying it,
  which doesn't happen in the resize case for other file systems.
* It allows an XFS file system to be created which is smaller than the
  minimum size allowed by GParted.  Copying an empty XFS file system can
  create a new file system as small as 26 MiB.  This is smaller than the
  minimum GParted allows of 32 MiB because that is the minimum
  xfs_repair can handle.

Remove this addition when copying an XFS file system and enforce minimum
file system size.

2) Maximum size when copying a file system into empty space larger than
   it's maximum size

Maximum size was set to maximum file system size - cylinder size
(typically minus ~8 MiB).  Only applied to FAT16 which has a maximum
file system size set in and can be grown.  Added by this commit from
2004-12-15:
    10e8f3338d
    :get_fs now returns a const reference. in copy and resizedialog
    ...
    * in copy and resizedialog filesystems with MAX set now have a max size of MAX - one cylinder .

Issue:
* This is applying a lower maximum resize when copying the file system
  compared to that when creating the file system.
  NOTE:
  GParted currently allows all file systems to be resize to any size,
  regardless of the maximum file system size.  This is probably an
  oversight, but it does allow libparted to convert FAT16 to FAT32 file
  system when resizing.

Remove this lower maximum file system size when copying and resizing,
compared to creating.

Bug 749867 - Some limits are adjusted by arcane cylinder size amount
             when copying and resizing in a single operation
2015-05-28 12:53:41 -06:00
Mike Fleetwood b9262922a7 Remove last trace of cylinder size adjustments in the resize dialog (#749867)
This commit from 2010-05-20 removed use of cylinder size increase in the
minimum, and cylinder size decrease in the maximum file system sizes
from the resize/move dialog.
    e62a23b5b5
    Add partition alignment option to align to MiB (#617409)

This cylinder size limit adjustments were being performed using the
Dialog_Base_Partition::BUF member variable.  Now in the
Dialog_Partition_Resize_Move class it is never accessed, and only
unnecessarily set.  Move BUF from the common base class into the
Dialog_Partition_Copy class where it is still used.

Bug 749867 - Some limits are adjusted by arcane cylinder size amount
             when copying and resizing in a single operation
2015-05-28 12:44:51 -06:00
Mike Fleetwood f6e4390aaf Add const qualifier to get_custom_text() member functions
The function never modifies any member variables so make it a const
member function.

(FileSystem::get_custom_text() is a virtual function so can't be made
static).
2015-05-19 10:34:59 -06:00
Mike Fleetwood d0580d5955 Rename two GParted_Core methods to detect_filesystem*()
Rename a couple of GParted_Core methods for consistency and to better
distinguish get_filesystem() from get_filesystems() which do completely
unrelated things.

  get_filesystem()                 -> detect_filesystem()
  recognise_filesystem_signature() -> detect_filesystem_internal()

Also make detect_filesystem() a static member method as it doesn't use
any member variables.  Requirement cascades to get_partition_path().
2015-05-07 08:01:43 -06:00
Mike Fleetwood 42cd956a54 Make GParted_Core methods flush_device(), get_device(), etc static
GParted_Core methods:
    flush_device()
    get_device()
    get_disk()
    get_device_and_disk()
    destroy_device_and_disk()
    commit()
    commit_to_os()
    settle_device()

This group of methods only call libparted API functions and run external
executables.  None of them access any GParted_Core member variables.
Make them all static member functions.
2015-05-07 08:01:43 -06:00
Mike Fleetwood df000a94a6 Tidy-up GParted_Core::init/fini_filesystems() function declarations
These member functions are only used within the GParted_Core class and
only operate on the static member variable FILESYSTEM_MAP.

Make both functions private and also make init_filesystems() static.
2015-05-07 08:01:43 -06:00
Mike Fleetwood 40820bada7 Fix memory leak of FileSystem objects in init_filesystems() (#749036)
The FileSystem objects stored in the FILESYSTEM_MAP are allocated once
using new in init_filesystems() but never deleted.

Valgrind output fragment:

    # valgrind --leak-check=full ./gparted
    ==29314== 353 (72 direct, 281 indirect) bytes in 1 blocks are definitely lost in loss record 6,287 of 6,905
    ==29314==    at 0x4A075FC: operator new(unsigned long) (vg_replace_malloc.c:298)
>>  ==29314==    by 0x46EDA5: GParted::GParted_Core::init_filesystems() (GParted_Core.cc:106)
    ==29314==    by 0x46EC5F: GParted::GParted_Core::GParted_Core() (GParted_Core.cc:96)
    ==29314==    by 0x4A74F4: GParted::Win_GParted::Win_GParted(std::vector<Glib::ustring, std::allocator<Glib::ustring> > const&) (Win_GParted.cc:51)
    ==29314==    by 0x4D600A: main (main.cc:56)
    ...
    ==29314== 161 (72 direct, 89 indirect) bytes in 1 blocks are definitely lost in loss record 6,119 of 6,905
    ==29314==    at 0x4A075FC: operator new(unsigned long) (vg_replace_malloc.c:298)
>>  ==29314==    by 0x46F50C: GParted::GParted_Core::init_filesystems() (GParted_Core.cc:124)
    ==29314==    by 0x46EC5F: GParted::GParted_Core::GParted_Core() (GParted_Core.cc:96)
    ==29314==    by 0x4A74F4: GParted::Win_GParted::Win_GParted(std::vector<Glib::ustring, std::allocator<Glib::ustring> > const&) (Win_GParted.cc:51)
    ==29314==    by 0x4D600A: main (main.cc:56)

GParted_Core.cc source:

   102  void GParted_Core::init_filesystems()
   103  {
   104          FILESYSTEM_MAP[ FS_UNKNOWN ]         = NULL ;
   105          FILESYSTEM_MAP[ FS_CLEARED ]         = NULL ;
>> 106          FILESYSTEM_MAP[ FS_BTRFS ]           = new btrfs() ;
   ...
>> 124          FILESYSTEM_MAP[ FS_XFS ]             = new xfs() ;
   125          FILESYSTEM_MAP[ FS_BITLOCKER ]       = NULL ;

Fix by deleting all FILESYSTEM_MAP pointers.  Note that delete on a NULL
pointer is defined by C++ as a safe do nothing operation.

    C++ FAQ / Do I need to check for null before delete p?
    https://isocpp.org/wiki/faq/freestore-mgmt#delete-handles-null

Fixing this reduces the valgrind reported definitely lost memory blocks
count from 25 down to 6.  19 FileSystem objects deleted and 19 memory
blocks no longer lost.

Bug 749036 - FileSystem objects are memory leaked in init_filesystems()
2015-05-07 08:01:43 -06:00