Commit Graph

16 Commits

Author SHA1 Message Date
Mike Fleetwood 175d27c55d Rename enum FILESYSTEM to FSType
There are too many different types of things named "filesystem" in the
GParted code with the potential to cause confusion.  Namely:

    std::vector<FS> FILESYSTEMS
                              Vector of file system capabilities.

    class FileSystem          Base class interfacing to file system
                              specific executables for querying and
                              modification.

    enum FILESYSTEM           Symbolic constants representing each file
                              system type.

Many recent written or re-written functions already used a variable
named fstype.  Rename enum FILESYSTEM to enum FSType to clearly
distinguish it from the other things with very similar names.  Only
changing the name of the enumeration, not the name of variables of that
type too because that is a lot more lines of code and those can be
changed when the relevant code is re-written.
2018-01-28 10:09:35 -07:00
Mike Fleetwood ee1b2257d2 Preview resize/move operation of encrypted file systems (#774818)
Changing the Resize/Move dialog code to also handle PartitionLUKS
objects was considered too complicated.  Instead create an unencrypted
equivalent using clone_as_plain(), pass that to the Resize/Move dialog
and finally apply the change back using Partition*::resize().

Bug 774818 - Implement LUKS read-write actions NOT requiring a
             passphrase
2017-01-14 08:49:58 -07:00
Mike Fleetwood 08e4ba4eca Add Partition object resizing method Partition*::resize() (#774818)
Add a resize() method to both Partition and PartitionLUKS classes.  They
take a reference Partition object, and update the position, size and
file system usage of *this Partition to match.  This is ready for taking
a partition returned from Resize/Move dialog and applying the change.

Bug 774818 - Implement LUKS read-write actions NOT requiring a
             passphrase
2017-01-14 08:49:58 -07:00
Mike Fleetwood 30a0f4506c Add specialist clone method PartitionLUKS::clone_as_plain() (#774818)
Implement a specialist PartitionLUKS clone method.  Creates a new
Partition object which has the same space usage as the source encrypted
file system, but is a plain file system.  Namely, the overhead of the
LUKS header has been added to the file system usage.  This is ready for
feeding this representation of the partition to the Resize/Move dialog.

Bug 774818 - Implement LUKS read-write actions NOT requiring a
             passphrase
2017-01-14 08:49:58 -07:00
Mike Fleetwood 3ba7128d55 Implement new UUID operation on encrypted file systems (#774818)
When composing, describing and implementing the operation just need the
code to query and set the Partition object directly containing the file
system, instead of the enclosing encryption mapping to make it work.

The operation details for setting a new UUID on an encrypted ext4 file
system become:

    Set a new random UUID on [Encrypted] ext4 file system on /dev/sdb4
    + calibrate /dev/sdb4
    + Set UUID on /dev/mapper/sdb4_crypt to a new, random value
      + tune2fs -U random /dev/mapper/sdb4_crypt
          tune2fs 1.41.12 (17-May-2010)

Also note the now documented rule in apply_operation_to_disk() which
says each operation must leave the status of the encryption mapping and
file system as it found it.

Bug 774818 - Implement LUKS read-write actions NOT requiring a
             passphrase
2017-01-14 08:49:58 -07:00
Mike Fleetwood bd6fc67afb Provide virtual Partition::get_filesystem_string() method (#774818)
Provide and use a single interface for getting the file system string
for display, regardless of whether the partition is encrypted or the
encryption mapping is active or not.

Example return values for get_filesystem_string() for different types
and states of Partition objects:
1)  Plain ext4 file system:          -> "ext4"
2)  Closed encrypted:                -> "[Encrypted]"
3)  Open encrypted ext4 file system: -> "[Encrypted] ext4"

This simplifies the code in TreeView_Detail::create_row() which sets the
file system type displayed in the main window.  The same method will
then also be used when setting the operation description as each
operation is updated to handle encrypted file systems.

Bug 774818 - Implement LUKS read-write actions NOT requiring a
             passphrase
2017-01-14 08:49:58 -07:00
Mike Fleetwood aa49b763e4 Remove virtual PartitionLUKS::get_filesystem_label() (#774818)
The previous commit changed how the code behind the main window
retrieved the file system label for display.  This is the relevant
changes in TreeView_Detail::create_row():

  + const Partition & filesystem_ptn = partition.get_filesystem_partition();
    ...
  - Glib::ustring temp_filesystem_label = partition.get_filesystem_label();
  + Glib::ustring temp_filesystem_label = filesystem_ptn.get_filesystem_label();
    treerow[treeview_detail_columns.label] = temp_filesystem_label;

In the case of an encrypted file system get_filesystem_label() is now
called on the Partition object directly rather than on the outer
Partition object containing the LUKS encryption.

The code behind the Information dialog always obtained and used the
Partition object directly containing the file system to call
get_filesystem_label() since read-only LUKS support was added.
Therefore the virtualised PartitionLUKS::get_filesystem_label() is no
longer needed, so remove it.

Bug 774818 - Implement LUKS read-write actions NOT requiring a
             passphrase
2017-01-14 08:49:58 -07:00
Mike Fleetwood 53fd80e6ca Provide virtual Partition::get_filesystem_partition() method (#774818)
There are multiple cases of code wanting to work with the Partition
object directly containing the file system, regardless of whether it is
within a PartitionLUKS object or not.  The code had to do something
similar to this to access it:

    const Partition * filesystem_ptn = &partition;
    if ( partition.filesystem == FS_LUKS && partition.busy )
            filesystem_ptn = &dynamic_cast<const PartitionLUKS *>( &partition )->get_encrypted();
    ...
    // Access Partition object directly containing the file system
    filesystem_ptn-> ...

Implement and use virtual accessor get_filesystem_partition() which
allows the code to be simplified like this:

    const Partition & filesystem_ptn = partition.get_filesystem_partition();
    ...
    // Access Partition object directly containing the file system
    filesystem_ptn. ...

Bug 774818 - Implement LUKS read-write actions NOT requiring a
             passphrase
2017-01-14 08:49:58 -07:00
Mike Fleetwood 8979913a3f Remove "../include/" from GParted header #includes
It made the code look a little messy, is easily resolved in the build
system and made the dependencies more complicated than needed.  Each
GParted header was tracked via multiple different names (different
numbers of "../include/" prefixes).  For example just looking at how
DialogFeatures.o depends on Utils.h:

    $ cd src
    $ make DialogFeatures.o
    $ egrep ' [^ ]*Utils.h' .deps/DialogFeatures.Po
     ../include/DialogFeatures.h ../include/../include/Utils.h \
     ../include/../include/../include/../include/../include/../include/Utils.h \
     ../include/../include/../include/Utils.h \

After removing "../include/" from the GParted header #includes, just
need to add "-I../include" to the compile command via the AM_CPPFLAGS in
src/Makefile.am.  Now the dependencies on GParted header files are
tracked under a single name (with a single "../include/" prefix).  Now
DialogFeatures.o only depends on a single name to Utils.h:

    $ make DialogFeatures.o
    $ egrep ' [^ ]*Utils.h' .deps/DialogFeatures.Po
     ../include/DialogFeatures.h ../include/Utils.h ../include/i18n.h \
2016-12-12 13:15:34 -07:00
Mike Fleetwood 9f08875997 Make encrypted Partition objects look like whole disk device ones (#775932)
Until now an encryption mapping has been modelled as a Partition object
similar to a partition like this:
    .encrypted.device_path  = "/dev/sdb1"
    .encrypted.path         = "/dev/mapper/sdb1_crypt"
    .encrypted.whole_device = false
    .encrypted.sector_start = // start of the mapping in the partition
    .encrypted.sector_end   = // end of the mapping in the partition
However accessing device_path in the start to end sector range is not
equivalent to accessing the partition path as it doesn't provide access
to the encrypted data.  Therefore existing functions which read and
write partition data (GParted file system copying and signature erasure)
via libparted using the device_path won't work and will in fact destroy
the encrypted data.  This could be coded around with an extra case in
the device opening code, however it is not necessary.

An encrypted block special device /dev/mapper/CRYPTNAME looks just like
a whole disk device because it doesn't contain a partition and the file
system it contains starts at sector 0 and goes to the end.  Therefore
model an encryption mapping in the same way a whole disk device is
modelled as a Partition object like this:
    .encrypted.device_path  = "/dev/mapper/sdb1_crypt"
    .encrypted.path         = "/dev/mapper/sdb1_crypt"
    .encrypted.whole_device = true
    .encrypted.sector_start = 0
    .encrypted.sector_end   = // size of the encryption mapping - 1
Now GParted file system copy and erasure will just work without any
change.  Just need to additionally store the LUKS header size, which was
previous stored in the sector_start, for use in the
get_sectors_{used,unused,unallocated}() calculations.

Bug 775932 - Refactor mostly applying of operations
2016-12-12 13:15:34 -07:00
Mike Fleetwood 2d910494d3 Display messages for encrypted file systems (#760080)
At the moment any messages for an encrypted file system aren't shown,
only messages from the outer PartitionLUKS object are shown.  Also in
Win_GParted::activate_paste() the selected Partition object, possibly
a derived PartitionLUKS, is cloned and the messages cleared.

Therefore a set of accessor methods must be provided to query and modify
partition messages.  Messages will be stored in the Partition object to
which they are added and retrieved from all.  So in the case of a
derived PartitionLUKS they will be retrieved from the messages vector of
the PartitionLUKS object itself and the messages vector for the
encrypted file system it contains.

To replace code like this in GParted_Core:

    partition_temp->messages = messages;

We might naturally provide a set_messages() method which assigns the
messages vector and is used like this:

    partition_temp->set_messages( messages );

However on a PartitionLUKS object what should set_messages() do?  By the
name it will replace any existing messages in the PartitionLUKS object
itself, but what should happen to the messages for the contained
encrypted Partition object?  Should they be cleared or left alone?
Rather than implement set_messages() with unclear semantics implement
append_messages(), which in the PartitionLUKS object case will clearly
leave any messages for the contained encrypted Partition object alone.
Append_messages() is then used to add messages as the Partition or
PartitionLUKS objects when populating the data in GParted_Core.

Bug 760080 - Implement read-only LUKS support
2016-01-29 13:41:41 -07:00
Mike Fleetwood cb24aa4be1 Display usage of encrypted file systems (#760080)
There is already the set of methods in the Partition class to report the
file system usage.  Virtualise them and provide PartitionLUKS specific
implementations to calculate the usage of a file system wrapped in LUKS
encryption.

See the ascii art and comment in PartitionLUKS.cc for the details of
those calculations.

Bug 760080 - Implement read-only LUKS support
2016-01-29 13:41:41 -07:00
Mike Fleetwood 38a790d745 Display the label of encrypted file systems (#760080)
LUKS headers don't provide any concept of label.  Also there is already
the method Partition::get_filesystem_label() for getting the *file
system* label, so virtualise it and provide an appropriate
implementation to get the label of an encrypted file system represented
within a derived PartitionLUKS object.  This causes the label to be
displayed correctly in the main window.

It also happens to display the encrypted file system label in the
Information dialog for a LUKS formatted partition.  However the whole
Information dialog will be addressed differently in a following commit.

Bug 760080 - Implement read-only LUKS support
2016-01-29 13:41:41 -07:00
Mike Fleetwood cb3cc505ce Display "[Encrypted] FSTYPE" in the File System column (#760080)
In the File System column in the GUI, when there is an open dm-crypt
mapping, display the colour square for the encrypted file system within
and the text as "[Encrypted] FSTYPE".  For closed mappings nothing can
be known about the encrypted file system within so continue to display a
purple square and the text "[Encrypted]".

Looks like:

    Partition        | File System
      ...
      /dev/sdb3        # ext4
    v /dev/sdb4    *   # extended
        /dev/sdb5      # [Encrypted]
        /dev/sdb6  *   # [Encrypted] unknown
        /dev/sdb7  *   # [Encrypted] ext4

Bug 760080 - Implement read-only LUKS support
2016-01-29 13:41:41 -07:00
Mike Fleetwood c9a2986fb9 Populate encrypted Partition member inside PartitionLUKS (#760080)
When there exists an open dm-crypt mapping, populate the encrypted
Partition object representing the encrypted file system.

Bug 760080 - Implement read-only LUKS support
2016-01-29 13:41:40 -07:00
Mike Fleetwood 99ff0c7628 Add PartitionLUKS class and create objects (#760080)
Absolute minimum implementation of a PartitionLUKS class which can be
constructed, polymorphically copied and destroyed.  Contains an
"encrypted" member of type Partition to represent the encrypted file
system within the LUKS format.

Create PartitionLUKS objects instead of base Partition objects when a
LUKS formatted partition is found.  Only the base Partition object
member values have been populated, and the "encrypted" member remains
blank at this point.

Bug 760080 - Implement read-only LUKS support
2016-01-29 13:41:40 -07:00