Commit Graph

102 Commits

Author SHA1 Message Date
Mike Fleetwood 5a6b8afc53 Refactor xfs::set_used_sectors() into if fail return early pattern (!119)
Closes !119 -  Tidy-ups for file system interface classes
2023-10-29 15:50:43 +00:00
Mike Fleetwood 9c6ea6457e Stop using member variables T, N & S in xfs class (!119)
Restructure the variable parsing code into "if leading text found then
scan the number" pattern.

Closes !119 -  Tidy-ups for file system interface classes
2023-10-29 15:50:43 +00:00
Mike Fleetwood 92dfbac0d1 Stop using floating point calculation in most FS set_used_sectors() methods (!119)
Replace floating point calculation to convert size and space figures
from file system block sized units to sectors with an integer
calculation.  Do this for the same reasons discussed in commit "Stop
using floating point calculations in FS resize() methods" earlier in
this patchset.  This will limit the largest file system that GParted can
read the usage of to 8 EiB - 1 bytes.

There is still a floating point calculation in btrfs::set_used_sectors()
which is being left because that is apportioning used space figure
between multiple devices.

Closes !119 -  Tidy-ups for file system interface classes
2023-10-29 15:50:43 +00:00
Mike Fleetwood 84866d81d0 Increase minimum XFS size to 300 MiB (#217)
As documented in the previous commit xfsprogs >= 5.19.0 refuses to
create an XFS file system smaller than 300 MiB.

    $ truncate -s $((300*1024*1024-1)) test.img
    $ ls -l test.img
    -rw-r--r--    1 auser    auser   314572799 Dec 21 11:01 test.img
    $ mkfs.xfs -V
    mkfs.xfs version 6.0.0
    $ mkfs.xfs test.img
    Filesystem must be larger than 300MB.
    ...
    $ echo $?
    1

Successfully create an XFS file system at minimum size of 300 MiB.

    $ truncate -s $((300*1024*1024)) test.img
    $ ls -l test.img
    -rw-r--r--    1 auser    auser   314572800 Dec 21 11:05 test.img
    $ mkfs.xfs test.img
    ...
    $ echo $?
    0
    $ blkid test.img
    test.img: UUID="..." BLOCK_SIZE="512" TYPE="xfs"

Increase the GParted minimum XFS size to 300 MiB.  For simplicity and
because the XFS developers said of smaller XFS file systems [1]:
    "are known to have performance and redundancy problems that are not
    present on the volume sizes that XFS is best at handling"
regardless of the version of mkfs.xfs used to create that XFS then apply
to all versions of xfsprogs.

[1] https://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git/commit/?id=6e0ed3d19c54603f0f7d628ea04b550151d8a262
    mkfs: stop allowing tiny filesystems

Closes #217 - GitLab CI test job failing with new mkfs.xfs error
              "Filesystem must be larger than 300MB."
2022-12-22 21:09:58 +00:00
Mike Fleetwood bf5c6bb618 Fix typo in comment in xfs::write_label() 2022-07-04 17:50:25 +00:00
Mike Fleetwood 0c13855d52 Add labelling of mounted xfs (#163)
XFS also supports labelling of the file system while it is mounted.
This was added into Linux kernel 4.18 [1] and xfsprogs 4.17.0 [2].
These versions are newer than available in older but still supported
distributions so we'll need to detect versions before enabling support.
These are the oldest releases of distributions which meet the
requirements.

    Distro             EOL        Linux kernel   xfsprogs
    Debian 10          2024-Jun   4.19.0         4.20.0
    RHEL 8             2029-May   4.18.0         5.0.0
    Ubuntu 20.04 LTS   2030-Apr   5.4            5.3.0

As with btrfs a mounted XFS is labelled via it's mount point:
    # mkfs.xfs -L label_1 /dev/sdb2
    # mount /dev/sdb2 /mnt/2
    # xfs_io -c 'label -s mnt_label_2' /mnt/2
    label = "mnt_label_2"
    # blkid /dev/sdb2
    /dev/sdb2: LABEL="mnt_label_2" ...

And cleared with:
    # xfs_io -c 'label -c' /mnt/2
    label = ""

Note that in some error situations xfs_io reports exit status zero and
writes the failure message to stdout.
    # xfs_io -c 'label -s "mnt label 3"' /mnt/2
    bad argument count 4 to label, expected between 0 and 3 arguments
    # echo $?
    0
Therefore determine success based on stdout starting with 'label = "'
reporting the new label or not.

Also note that as seen in this failure case, it is not possible to set
an XFS label which contains a space character using xfs_io.  However
that is nothing new as that can't be done using the existing xfs_admin
command for an unmounted XFS either.
    # umount /mnt/2
    # xfs_admin -L 'umnt label 4' /dev/sdb2
    Usage: xfs_admin [-efjlpuV] [-c 0|1] [-L label] [-U uuid] device
    # echo $?
    2

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=f7664b31975bd893190708e76b2c424328f0c49b
    xfs: implement online get/set fs label
[2] https://git.kernel.org/pub/scm/fs/xfs/xfsprogs-dev.git/commit/?id=cfa10b0f972005b38ed294bca66cebf2f65298ec
    xfs_io: add label command

Closes #163 - Feature request: set label on a mounted btrfs
2021-07-30 16:12:24 +00:00
Mike Fleetwood 39e7156697 Copy XFS UUID when copying the file system (!85)
For the same reason as in the previous commit, the UUID is copied when
copying every file system type except for XFS, where a new XFS is
created with a new UUID.

Again preview of the copy operation expects the UUID to be copied.
(Look in Partition > Information of the source and pasted partitions
before the operation is applied).

Fix as before by specifying the desired file system UUID when creating
the new XFS as part of the copy operation.

However there is an extra complication.  The XFS kernel driver refuses
to mount a file system with a duplicate UUID of an already mounted XFS.

    # mkfs.xfs -L xfs_copy /dev/sdb1
    # mount /dev/sdb1 /mnt/1
    # tail -2 /var/log/messages
    Jun  3 21:41:24 localhost kernel: XFS (sdb1): Mounting V5 Filesystem
    Jun  3 21:41:24 localhost kernel: XFS (sdb1): Ending clean mount

    # /dev/sdb1: LABEL="xfs_copy" UUID="d654fc7f-e417-4ec6-88e8-8a7d0d46b7d8" TYPE="xfs"
    # mkfs.xfs -L xfs_copy -m uuid="d654fc7f-e417-4ec6-88e8-8a7d0d46b7d8" /dev/sdb2
    # mount /dev/sdb2 /mnt/2
    mount: wrong fs type, bad option, bad superblock on /dev/sdb2,
           missing codepage or helper program, or other error.

           In some cases useful info is found in syslog - try
           dmesg | tail or so.
    # echo $?
    32
    # tail -1 /var/log/messages
    Jun  3 21:41:31 localhost kernel: XFS (sdb2): File system has duplicate UUID d654fc7f-e417-4ec6-88e8-8a7d0d46b7d8 - can't mount

Handle this specifying the needed option [1] when mounting the second
XFS during the copy.

    # mount -o nouuid /dev/sdb2 /mnt/2
    # mount | grep /dev/sdb
    /dev/sdb1 on /mnt/1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota)
    /dev/sdb1 on /mnt/1 type xfs (rw,relatime,seclabel,nouuid,attr2,inode64,noquota)

Duplicating the UUID may seem troublesome, but it is being done:
1.  To make the GParted copied XFS be as much a clone as possible, to
    match what is does with other file systems.
2.  It has a valid use case; of cloning a Linux installation to a new
    drive or restoring a partition image backup.  In these cases it is
    much simpler if the UUID of the copy remains the same because it
    avoids having to edit GRUB2 configuration and fstab file system
    mounting which is nearly always done via UUID.
3.  GParted has the new UUID operation, to change the UUID for cases
    when a copied file system needs to be mounted at the same time as
    the source.

[1] xfs(5) - xfs - layout, mount options, and supported file attributes
    for the XFS filesystem
    https://man7.org/linux/man-pages/man5/xfs.5.html
    "MOUNT OPTIONS
    ...
    nouuid Don't check for double mounted file systems using the file
           system uuid.
    "

Closes !85 - Make XFS copy duplicate the file system label and UUID
2021-06-06 18:52:13 +00:00
Mike Fleetwood 36e43ed7a7 Copy XFS label when copying the file system (!85)
As GParted performs block copy of partitions then the label, which is
stored in the file system superblock, is also copied.  This is true for
copies performed using the GParted internal block copy and for EXT2/3/4
and NTFS which are copied using the file system specific commands
e2image and ntfsclone respectively.  However when an XFS file system is
copied the label is not copied because a new file system is created
using mkfs.xfs and the files copied using xfsdump | xfsrestore.

Preview of the copy operation in GParted also reflects the fact that the
label will be copied.

Fix this by simply specifying the desired label when creating the new
destination XFS.

Closes !85 - Make XFS copy duplicate the file system label and UUID
2021-06-06 18:52:13 +00:00
Luca Bacci 4b87839502 port-to-gtk3: Rework Glibmm header includes (#7)
Now that we are compiling against Gtkmm3 there are missing declarations
of Glibmm identifiers due to changes in Gtkmm internal header structure.

All we have to do is bring back the declarations by including the
appropriate headers where needed.

Add necessary Glibmm header includes.

Closes #7 - Port to Gtk3
2019-02-11 08:57:18 +00:00
Mike Fleetwood 7f23761964 Strip unnecessary scope from GParted::FS::* (!20)
The code inconsistency uses GParted::FS::* and FS::*.

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

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

Closes !20 - Minor namespace and scope operator tidy-ups
2018-11-26 17:56:32 +00:00
Mike Fleetwood 32df1de163 Move the xfs_db -r flag to the start when reading XFS usage
I completely missed that when reading XFS file system size and usage it
was using the '-r' read-only flag to xfs_db because it was at the end of
the string on the following line of code.  Move it to the start of the
xfs_db command line, like it is when reading the file system label.
2018-06-18 10:15:33 -06:00
Mike Fleetwood a3b47ca14a Move struct FS and FS_Limits into FileSystem.h
Struct FS and struct FS_Limits are strongly related to the FileSystem
class, both being return values from members and associated with storing
file system attributes.  Move their definitions from Utils.h into
FileSystem.h.
2018-01-28 10:09:35 -07:00
Mike Fleetwood e234df6b2e Remove struct FS members .MIN & .MAX (#787204)
All the code has been switched to call get_filesystem_limits() and use
struct FS_Limits.  Remove struct FS members .MIN & .MAX.

Bug 787204 - Minimum and maximum size of the UDF partition/disk
2018-01-28 10:09:35 -07:00
Mike Fleetwood aea0070799 Assign to duplicate FS_Limits (#787204)
Duplicate the assignment of file system size limits into
struct FS_Limits, matching the fixed values currently assigned to
struct FS members .MIN and .MAX.

Bug 787204 - Minimum and maximum size of the UDF partition/disk
2018-01-28 10:09:35 -07:00
Mike Fleetwood f9ae35584b Remove left behind #include "ProgressBar.h"
The includes were missed being removed by this earlier refactoring
commit which reduced direct access to the single ProgressBar object:
    b1313281bd
    Simplify use of the progress bar via OperationDetail (#760709)
2017-11-26 10:53:52 -07:00
Pali Rohár 8fdc2c21a6 Correctly quote and escape arguments passed to external commands (#787203)
Trying to set a file system label to (including the double quotes):
    " --help "
fails.  For example labelling an ext4 file system would try to run this
command:
    # e2label /dev/sdb1 "" --help ""
    Usage: e2label device [newlabel]
    # echo $?
    1

Alternatively trying to create a file system with a label of just a
double quote also fails.  The Applying Pending Operations dialog waits
forever and won't cancel or force cancel.  Have to use the window
manager close window button to close the dialog.  Also GParted reports
this error to the console:
    (gpartedbin:9648): glibmm-CRITICAL **:
    unhandled exception (type Glib::Error) in signal handler:
    domain: g-shell-error-quark
    code  : 0
    what  : Text ended before matching quote was found for ". (The text was 'mkfs.xfs -f -L """ /dev/sdb2')

Command strings are parsed and split into argv array by function
Glib::shell_parse_argv() which calls internal glib function
tokenize_command_line() for shell tokenization.  It expects the command
string to be properly quoted and escaped and after tokenization, calls
g_shell_unquote() on every parsed argument.  So to prevent constructing
incorrect commands, every non-static string needs to be properly quoted.

GParted only puts labels and mount points into double quotes, but has
not escaped special characters in those values itself.  This patch
fixes all these problems by using Glib::shell_quote() on all variable
values.  Labels, mount points, paths and all others too.

Probably a better solution would be to use a new function which takes
argv array instead of one string with all the, correctly quoted and
escaped, arguments concatenated together.

Bug 787203 - Correctly quote and escape arguments of external programs
             passed to execute_command()
2017-09-21 20:00:26 +01:00
Pali Rohár f422052356 Correctly quote and escape command line argument passed to "sh -c" (#787203)
Shell fragments must be properly quoted and escaped to prevent execution
of unintended commands derived from user controllable data.  For
example:

    $ printf '#!/bin/sh\necho test > out\n' > script.sh
    $ chmod +x script.sh
    $ truncate -s 20M 'jfs;script.sh'
    $ mkfs.jfs -q 'jfs;script.sh'
    $ ls -l out
    ls: cannot access out: No such file or directory

    $ sudo PATH=$PWD:$PATH /usr/local/bin/gparted 'jfs;script.sh'
    $ sudo PATH=$PWD:$PATH /usr/local/bin/gparted 'jfs;script.sh'

    $ ls -l out
    -rw-r--r-- 1 root root 5 Sep 12 23:11 out
    $ cat out
    test

What is happening is that jfs::set_used_sectors() is using the device
name 'jfs;script.sh' without quoting it and passing it to the shell to
execute like this:
    sh -c 'echo dm | jfs_debugfs jfs;script.sh'
which the shell duly executes as these two commands:
    echo dm | jfs_debugfs jfs
    script.sh

This could be a security related issue as "sh -c" is able to execute
arbitrary shell commands from the argument if if contains shell special
characters.  Use Glib::shell_quote() [1] to quote and escape file names
and whole commands passed to the shell.

[1] Glib::shell_quote(const std::string & unquoted_string)
    https://developer.gnome.org/glibmm/stable/group__ShellUtils.html
    "Quotes a string so that the shell (/bin/sh) will interpret the
    quoted string to mean unquoted_string.

    If you pass a filename to the shell, for example, you should first
    quote it with this function."

Bug 787203 - Correctly quote and escape arguments of external programs
             passed to execute_command()
2017-09-21 20:00:26 +01:00
Mike Fleetwood 2025581029 Quote mount point when copying and resizing xfs (#782681)
Attempting to grow an already mounted xfs where the mount point
contained spaces failed like this:

    Grow /dev/sdb4 from 1.00 GiB to 1.50 GiB
    + calibrate /dev/sdb4
    + grow partition from 1.00 GiB to 1.50 GiB
    + grow file system to fill the partition
      + xfs_growfs /tmp/File System Label
        Usage: xfs_growfs [options] mountpoint
        ...

Apply the rule and quote all uses of mount points within command lines.
This is also applied to copying xfs file systems even though it was safe
because it only ever used GParted generated mount points.

Also for the xfs copy operation switch unmounting of partitions to
specify mount points instead of partitions.  This is just to be
consistent with how it is done in all the online file system resizing
code.

Bug 782681 - btrfs partitions mounted with whitespace cannot be resized
2017-05-21 09:44:20 -06: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
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 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
Mike Fleetwood 075154b4e8 Simplify XFS copy specific code progress bar usage (#760709)
Remove starting and stopping the progress bar in xfs::copy().  The
progress bar will be automatically started in xfs::copy_progress()
callback when run_progressbar() is called; and automatically stopped in
FileSystem::execute_command() when it calls stop_progress() at the end.

Note that this will now not initialise the progress bar from zero
immediately that the XFS copy is started, but instead 0.5 seconds into
the copy when xfs::copy_progress() timed callback is called for the
first time.

Bug 760709 - Add progress bars to XFS and EXT2/3/4 file system specific
             copy methods
2016-02-12 09:09:57 -07:00
Mike Fleetwood 438b35aed9 Connect timed progress tracking callbacks inside execute_command() (#760709)
The timed progress tracking callback for execution of xfs copy follows
this pattern:

    sigc::connection c;
    ...
    c = Glib::signal_timeout().connect( ... sigc::mem_fun( *this, &xfs::copy_progress ) ..., 500 /*ms*/ );
    ... execute_command( ... );
    c.disconnect();

As with output progress tracking callbacks for ext2/3/4 and ntfs file
system specific commands, pass the callback slot and a flag into
execute_command() and connect the timed callback inside.  This
simplified the pattern to:

    ... execute_command( ...|EXEC_PROGRESS_TIMED,
                         static_cast<TimedSlot>( sigc::mem_fun( *this, &xfs::copy_progress ) ) );

NOTE:
The type of sigc::mem_fun() doesn't allow the compiler to choose between
the two overloaded variants of execute_command() with the fourth
parameter of either (full types without typedefs of StreamSlot and
TimedSlot respectively):
    sigc::slot<void, OperationDetail *> stream_progress_slot
    sigc::slot<bool, OperationDetail *> timed_progress_slot
Therefore have to cast the result of all callback slots to the relevant
type.  Hence:
    static_cast<StreamSlot>( sigc::mem_fun( *this, &{CLASS}::{NAME}_progress ) )
    static_cast<TimedSlot>( sigc::mem_fun( *this, &xfs::copy_progress ) )

References:
*   [sigc] Functor not resolving between overloaded methods with
    different slot types
    https://mail.gnome.org/archives/libsigc-list/2016-February/msg00000.html
*   Bug 306705 - Can't overload methods based on different slot<>
    parameters.
    https://bugzilla.gnome.org/show_bug.cgi?id=306705

Bug 760709 - Add progress bars to XFS and EXT2/3/4 file system specific
             copy methods
2016-02-12 09:09:57 -07:00
Mike Fleetwood b1313281bd Simplify use of the progress bar via OperationDetail (#760709)
Most of the file system specific command progress trackers followed this
pattern:

    void {CLASS}::{NAME}_progress( OperationDetail *operationdetail )
    {
            ProgressBar & progressbar = operationdetail->get_progressbar();
            // parse output for progress and target values
            if ( // have progress and target values )
            {
                    if ( ! progressbar.running() )
                            progressbar.start( target );
                    progressbar.update( progress );
                    operationdetail->signal_update( *operationdetail );
            }
            else if ( // found progress finished )
            {
                    if ( progressbar.running() )
                            progressbar.stop();
                    operationdetail->signal_update( *operationdetail );
            }
    }

That is a lot of repetition handling progress bar updates and
OperationDetail object update signalling.  Remove the need for direct
access to the single ProgressBar object and provide these two
OperationDetail methods instead:
    // Start and update in one
    run_progressbar( progress, target, optional text_mode );
    stop_progressbar();

Now the file system specific command progress trackers can become:

    void {CLASS}::{NAME}_progress( OperationDetail *operationdetail )
    {
            // parse output for progress and target values
            if ( // have progress and target values )
            {
                    operationdetail->run_progressbar( progress, target );
            }
            else if ( // found progress finished )
            {
                    operationdetail->stop_progressbar();
            }
    }

Make ProgressBar::get_progressbar() a private method to enforce use of
the new way to access the progress bar via the run_progress() and
stop_progressbar() methods.  Then make the Dialog_Progress a friend
class to OperationDetail so that the Apply pending operations dialog can
still access the single ProgressBar object for its querying needs.

Bug 760709 - Add progress bars to XFS and EXT2/3/4 file system specific
             copy methods
2016-02-12 09:09:57 -07:00
Mike Fleetwood 324d99a172 Record file system block size where known (#760709)
Record the file system block size in the Partition object.  Only
implemented for file systems when set_used_sectors() method has already
parsed the value or can easily parse the value from the existing
executed command(s).

Needed for ext2/3/4 copies and moves performed using e2image so that
they can be tracked in bytes by the ProgressBar class as e2image reports
progress in file system block size units.

Bug 760709 - Add progress bars to XFS and EXT2/3/4 file system specific
             copy methods
2016-02-12 09:09:57 -07:00
Mike Fleetwood 809a7e0954 Display progress of XFS file system specific copy operation (#760709)
XFS uses a file system specific method to copy the partition using
"xfsdump | xfsrestore".  Monitor progress by periodically querying the
destination file system usage and comparing to the source file system
usage.  Use 0.5 seconds as the polling interval to match that used by
the internal block copying algorithm.

NOTE:
The number of used blocks in the source and destination file system will
be very close but may not match exactly.  I have seen an XFS copy finish
with the following progress text:
    1.54 GiB of 1.50 GiB copied (-00:00:02 remaining)
Allow the progress bar to overrun like this as it is informing the user
that it actually copied a little more data and took a little longer than
expected.  Needs these two previous commits to correctly round and
format the negative time remaining:
    Fix rounding of negative numbers (#760709)
    Fix formatting of negative time values (#760709)

Bug 760709 - Add progress bars to XFS and EXT2/3/4 file system specific
             copy methods
2016-02-12 09:09:57 -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 1a4cefb960 Initialise all struct FS members
The struct FS constructor initialised every member *except* filesystem
and busy.  Then in *most* cases after declaring struct FS, assignments
followed like this:
    FS fs;
    fs.filesystem = FS_BTRFS;
    fs.busy       = FS::GPARTED;
But member busy wasn't always initialised.

Add initialisation of members filesystem and busy to the struct FS
constructor.  Specify optional parameter to the constructor to set the
filesystem member, or when left off filesystem is initialised to
FS_UNKNOWN.
2016-01-26 10:11:35 -07:00
Mike Fleetwood 48d898ebfd Include Partition.h header everywhere it's used
Lots of files which use the Partition class relied on the declaration
being included via other header files.  This is bad practice.

Add #include "Partition.h" into every file which uses the Partition
class which doesn't already include it.  Header file #include guards are
specifically to allow this.
2016-01-26 10:11:35 -07: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 70cc6187d5 Fix double quote error creating XFS file systems (#744108)
Trying to create an XFS file system causes the following error and
the create new xfs file system step to never complete.

    # ./gpartedbin
    ======================
    libparted : 2.4
    ======================

    (gpartedbin:15572): glibmm-CRITICAL **:
    unhandled exception (type Glib::Error) in signal handler:
    domain: g-shell-error-quark
    code  : 0
    what  : Text ended before matching quote was found for ". (The text was 'mkfs.xfs -f -L "mylabel" " /dev/sdb8')

Creation of XFS file systems was broken by the extra stray double quote
added to the command before the device name, by commit:

    63aeb150ac
    Rename member variables and methods in Partition class (#741424)

Bug 744108 - Creating an XFS file system never completes
2015-02-07 10:33:12 -07:00
Mike Fleetwood 63aeb150ac Rename member variables and methods in Partition class (#741424)
class Partition:
    have_label    -> have_filesystem_label
    label         -> filesystem_label
    label_known() -> filesystem_label_known()
    get_label()   -> get_filesystem_label()
    set_label()   -> set_filesystem_label()

Bug 741424 - Add support for GPT partition names
2015-02-01 10:08:23 -07:00
Mike Fleetwood b1dc9e69e3 Make partition busy detection method selectable per file system (#723842)
GParted's primary inbuilt busy detection method is "is the partition
mounted?".  A custom method is used for LVM2 PV because its not a
mounted file system.

Make busy detection selectable per file system type.

    .fs.busy = FS::NONE  (default)
        No busy detection.

    .fs.busy = FS::GPARTED
        Use internal GParted method which checks if the partition is
        mounted.

    .fs.busy = FS:EXTERNAL
        Call the file system type's member function is_busy().

LVM2 PV busy detection changes from a special case to just electing to
call the lvm2_pv::is_busy() method.  Linux Software RAID remains a
special case because it's only recognised, but not otherwise supported.

Bug #723842 - GParted resizes the wrong filesystem (does not pass the
              devid to btrfs filesystem resize)
2014-07-28 10:03:16 -06:00
Curtis Gedak 7b1011237c Avoid using String::ucompose to build command lines
The String::ucompose method is for easy, i18n-friendly composition of
strings with Gtkmm.  From past experience, String::ucompose should not
be used to build command lines due to differences in how locales handle
number translation.  More specifically, not all locales use number
separators (spaces, commas or periods) and the decimal separator
(period or comma) in the same way.

The problem with using String::ucompose for command lines was
originally encountered and corrected in the following commit:

Fix attempt data rescue fail to open read-only view (#673246)
e494eca1f7
2014-03-05 22:12:10 +00:00
Daniel Mustieles 3861b9257b Replace obsolete FSF postal address in copyright notices (#721565)
This is part of parent bug:
    Bug #721455 - Obsolete info in license text on multiple modules

and GNOME Goal:
    https://wiki.gnome.org/Initiatives/GnomeGoals/Proposals

    * verify all source files to make sure they have a license and a
      copyright, and that both are up-to-date

Bug #721565 -  License text contains obsolete FSF postal address
2014-01-26 10:53:23 +00:00
Phillip Susi de2844d02d Add online resize support (#694622)
Many file systems are capable of growing while mounted, and a few can
even shrink.  This support must be explicitly enabled at configure time
with the --enable-online-resize flag and depends on a patched libparted.
Also requires kernel >= 3.6 for partition resizing, even if the
partition is in use (BLKPG_RESIZE_PARTITION).

Thanks to Mike Fleetwood for double check mark idea instead of a second
column to show the online grow/shrink.

Bug #694622 - Add support for online resize
2013-11-24 10:10:37 +00:00
Sinlu Bes 20006e1f8e Add create_with_label flag to struct FS (#701569)
It was difficult to retrieve whether a filesystem's label can be set on reformat.

The read_label flag can't be used as it decides whether to use the logic in the filesystem class
rather than the fallback in GParted::set_device_partitions, to determine the label of a partition.

The create_with_label flag is NONE for file systems that we cannot format with a
label (or that we cannot format at all).
The value is usually EXTERNAL for file systems that we can format with a label.
2013-06-09 09:50:54 -06:00
Phillip Susi a92380b503 Pass Partition instead of just its path to FileSystem::copy()
Other operations get the Partition object and can look up the path or other
attributes they need.  The copy method should be no different.
2013-03-11 18:40:31 -06:00
Phillip Susi e4210ba08d Cleanup duplicate fs code
Many filesystems do not implement some of their methods, but had to provide
dummy implementations.  Remove all of the dummy implementations and instead
just provide one in the base FileSystem class.
2013-03-11 18:40:31 -06:00
Phillip Susi 723209e59f Flag mkfs and copy operations as safe to cancel (#601239)
Closes Bug #601239 - Please allow 'Cancel after current operation'
2013-03-11 18:40:31 -06:00
Phillip Susi 52a2a9b00a Reduce threading (#685740)
Win_Gparted and Dialog_Progress were creating threads to perform most
functions in the background.  Most of the time, the only reason the
threads blocked was to execute an external command.  The external command
execution has been changed to spawn the command asynchronously and wait
for completion with a nested main loop.  While waiting for completion,
the pipe output is captured via events.  In the future, this will allow
for it to be parsed in real time to obtain progress information.

Those tasks in GParted_Core that still block now spawn a background thread
and wait for it to complete with a nested main loop to avoid hanging the
gui.

Part of Bug #685740 - Refactor to use asynchronous command execution
2013-03-11 18:40:31 -06:00
Mike Fleetwood d0fec5e26f Remove redundant code trimming labels to length before use (#689318)
No longer need to trim fat16, fat32 and xfs labels as all labels are
limited to their maximum lengths during entry.

Bug #689318 - filesystem type specific support for partition name
              maximum length
2013-01-02 11:33:32 -07:00
Mike Fleetwood 686ec8f713 Make GParted recognise reading blank file system labels (#685656)
GParted doesn't notice when a file system label is changed to blank.
GParted first calls the file system specific read_label() method.  When
the label is blank read_label() correctly sets partition.label to the
zero length string.  Second GParted_Core::set_device_partitions() treats
the zero length string to mean that the label is unset and calls
FS_Info::get_label() to retrieve it from the cache of blkid output.
Blkid also doesn't notice when the file system label has been changed to
blank so reports the previous label.  Hence GParted displays the
previous file system label.

Fix by making label a private member variable of the class Partition and
providing access methods set_label(), get_label() and label_known()
which track whether the label has been set or not.  This only fixes the
fault for file systems which use file system specific commands to read
the label and when these tools are installed.  Otherwise GParted uses,
or has to fall back on using, the buggy blkid command to read the file
system label.

NOTE:
Many of the file system specific read_label() methods use a tool which
outputs more than just the label and use Utils::regexp_label() to match
leading text and the label itself.  If the surrounding text changes or
disappears altogether to indicated a blank label, regexp_label() doesn't
match anything and returns the zero length string.  This  is exactly
what is required and is passed to set_label() to set the label to blank.

Bug 685656 - GParted doesn't notice when file system label is changed to
             blank
2012-11-04 12:26:09 +00:00
Mike Fleetwood e7bfd52a4d Remove old #include <cerrno> from jfs and xfs modules
Use of errno disappeared from jfs and xfs when they switched to using
helper functions for file system resizing.
2012-10-02 13:19:30 -06:00
Mike Fleetwood 01150758c3 Make mounted partition usage method selectable per file system (#683255)
Each file system class can now choose how the size and free space of the
file system is determined when it is mounted.

    .fs.online_read = FS::NONE  (default)
        Do nothing.  Don't get the file system size and free space.

    .fs.online_read = FS::GPARTED
        Use internal GParted method which calls statvfs() system call on
        the mounted file system.

    .fs.online_read = FS::EXTERNAL
        Call the file system's member function set_used_sectors().  This
        is the same function as called when the file system is not
        mounted.   It can determine if the file system is mounted or not
        by testing partition.busy and acting accordingly.

This means that determining the size and free space of active LVM2
Physical Volumes is no longer a special case.  Instead the lvm2_pv class
just elects to have its set_used_sectors() method called for both the
active and deactive cases.

Bug #683255 - ext2: statvfs differs from dumpe2fs (x MB unallocated
              space within the partition)
2012-10-02 13:19:29 -06:00
Mike Fleetwood 4f235ecb06 Update file system specific validation of RFC 4122 UUIDs
Use the new RFC 4122 none Nil UUID regular expression to validate the
UUID read in all the Linux native file system specific read_uuid()
methods.  No longer need to explicitly exclude "<none>" or all zeros Nil
UUID as the regular expression does this.
2012-09-28 16:45:43 -06:00
Mike Fleetwood 795a92f5b2 Add file system specific remove() methods (#670171)
This commit only adds a remove() method to every file system and an
optional call to it in the relevant operations.  All remove() methods
are no operations and not enabled.

The remove() method provides explicit controlled removal of a file
system before the partition is deleted or overwritten by being formatted
or pasted into.  When implemented, it appears as an extra step in the
relevant operation.  The file system specific remove() method is
explicitly allowed to fail and stop the operations currently being
applied.

This is different to the existing erase_filesystem_signatures() which
wipes any previous file system signatures immediately before a new file
system is written to ensure there is no possibility of the partition
containing two or more different file system signatures.  It never fails
or reports anything to the user.

NOTE:
Most file systems should NOT implement a remove() method as it will
prevent recovery from accidental partition deletion.

Bug #670171 - Add LVM PV read-write support
2012-08-30 13:47:45 -06:00
Mike Fleetwood 719e73e335 Query unallocated space for unmounted file systems (#499202)
Update file system specific implementations to set the size and free
space, thus allowing the unallocated space in the partition to be
calculated, for the following unmounted file systems:
    btrfs, ext2, ext3, ext4, fat16, fat32, jfs, nilfs2, ntfs, reiserfs,
    reiser4, xfs

Bug #499202 - gparted does not see the difference if partition size
              differs from filesystem size
2012-06-18 10:24:28 -06:00
Rogier Goossens 9e96159bb2 Add support for setting UUID (#667278)
Add the ability to set a new random UUID on file systems that provide
the appropriate tools to perform this action.

Update the help manual to include this new functionality.  Also add
reference links to "setting a partition label" and "changing a
partition UUID" in the "copying and pasting a partition" section.

This patch does not include setting the UUID on an NTFS file system.

Bug #667278 - Add support for setting UUID

Bug #608308 - fix documentation - Copying and Pasting a Partition
2012-01-23 12:32:27 -07:00