Commit Graph

591 Commits

Author SHA1 Message Date
Mike Fleetwood 4087cb2e2b Workaround older blkid not distinguishing between FAT16 and FAT32 (#743181)
Older versions of blkid don't correctly distinguish between FAT16 and
FAT32 file systems when overwriting one with the other.  This effects
GParted too with these file systems on whole disk devices where only
blkid is used to recognise the contents.  See previous fix for why only
blkid is used in this case:
    Avoid whole disk FAT being detected as MSDOS partition table
    (#743181)

Example:

    # blkid -v
    blkid from util-linux 2.20.1 (liblkid 2.20.0, 19-Oct-2011)
    # mkdosfs -F16 -I /dev/md1
    # blkid | fgrep md1
    /dev/md1: SEC_TYPE="msdos" UUID="7C23-95D9" TYPE="vfat"
    # mkdosfs -F32 -I /dev/md1
    # blkid | fgrep md1
    /dev/md1: SEC_TYPE="msdos" UUID="7F93-98F4" TYPE="vfat"

So blkid recognised the UUID changed but didn't remove the SEC_TYPE for
the FAT32 file system.  See FS_Info::get_fs_type() as it uses this to
distinguish between FAT16 and FAT32.  This is a caching update bug in
blkid, because telling blkid not to use the cache gets the right
results:

    # blkid -c /dev/null | fgrep md1
    /dev/md1: UUID="7F93-98F4" TYPE="vfat"

With testing determined that blkid from util-linux 2.23 and later are
not affected and earlier versions are affected.  Mostly recently known
affected distribution is Ubuntu 14.04 LTS with util-linux 2.20.1.

The straight forward fix would be to instruct blkid to not use its cache
with 'blkid -c /dev/null'.  But using blkid's cache is needed to prevent
blkid hanging for minutes when trying to access a non-existent floppy
drive when the BIOS is set incorrectly.  See commit:

    18f863151c
    Fix long scan problem when BIOS floppy setting incorrect

Instead, when using an older affected version of blkid and when blkid
cache reports a vfat file system, run blkid again bypassing the cache.
The device is known to exist and contain a vfat file system, just not
whether it is a FAT16 or FAT32 file system, so can't be a non-existent
floppy device and won't hang.

Bug 743181 - Add unpartitioned drive read-write support
2015-03-09 11:04:13 -06:00
Mike Fleetwood e7ed209020 Erase file system signatures before creating a partition table (#743181)
When writing "loop" partition table over the top of some whole disk
device file system types GParted continued to show those whole disk
device file systems rather than the virtual unknown partition from the
"loop" partition table.

This affected btrfs, jfs, reiser4 and reiserfs.  It occurred because of
several factors:
1) Libparted only zeroed the first and last 9.5 KiB (assuming 512 byte
   sectors) of the device before writing a new partition table.  See
   ped_disk_clobber().
2) These file systems have their super blocks and therefore signatures
   after the first 9.5 KiB.
3) Whole disk device file system detection is performed using blkid
   before checking for a libparted "loop" partition table.  See
   GParted_Core::set_devices_thread().

Ref:
libparted 3.2: disk.c:ped_disk_clobber()
http://git.savannah.gnu.org/cgit/parted.git/tree/libparted/disk.c?id=v3.2#n302

Fix by always erasing any possible file system signatures on the device
before creating a new "loop" partition table.

NOTE:
This is typically taking up to 0.5 seconds in my testing on a 5400 RPM
hard drive, during which time the GParted UI is hung and the create
partition table dialog shows the apply button pressed but no other
progress indication.

Bug 743181 - Add unpartitioned drive read-write support
2015-03-09 11:04:13 -06:00
Mike Fleetwood 51ac4d5648 Split get_device_and_disk() into two (#743181)
get_device_and_disk() basically calls libparted to get a PedDevice
object representing a disk device and a PedDisk object representing a
partition table.  Re-implement get_device_and_disk() using two separate
functions, get_device() and get_disk(), to get one of these objects
each.

No functionality changes with this commit.  It enables future commits to
incrementally add support for whole disk devices into GParted without
needing libparted to recognise the contents and create a virtual "loop"
partition table.

Bug 743181 - Add unpartitioned drive read-write support
2015-03-09 11:04:13 -06:00
Mike Fleetwood 5098744f9a Add whole_device flag to the partition object (#743181)
Need to be able to take different actions in the GParted_Core partition
manipulation methods and in Win_GParted UI methods to deal with
libparted supported partitions or whole disk devices without a partition
table.  Add boolean whole_device to the partition object and set
appropriately to allow for this.

Bug 743181 - Add unpartitioned drive read-write support
2015-03-09 11:04:13 -06:00
Mike Fleetwood 0bdc1fef14 Add lookup for Linux kernel names of mountable file systems (#742741)
Function Utils::get_filesystem_kernel_name() returns the name of the
file system as needed for use in the mount command:
    mount -t TYPE DEVICE DIR

Needed because the kernel / mount name is 'hfsplus' where as libparted /
GParted, as reported by Utils::get_filesystem_string(), calls it 'hfs+'.
So far just added debugging when mounting a file system to test the
function works.

    # ./gartedbin
    ======================
    libparted : 2.1
    ======================
    DEBUG: (hfsplus) # mount -v /dev/sdb5 "/mnt/5"
    DEBUG: (nilfs2) # mount -v /dev/sdb1 "/mnt/1"

Bug 742741 - Nilfs2 file system is unusable on RHEL/CentOS 6
2015-03-09 10:50:40 -06:00
Mike Fleetwood cbf8bd741d Display whole disk file systems via partition table "none" (#741430)
For file systems which libparted recognises, when found on the whole
disk device, it reports with partition table "loop" and a partition
covering the whole disk.  GParted duly displays this to the user.

For file systems which libparted doesn't recognise it reports
"unrecognised disk label".  As of the latest libparted 3.2, these file
system aren't recognised and can't currently be shown when on the whole
disk device:

    BitLocker, Crypt LUKS, exFAT, F2FS, LVM2 Physical Volume,
    Linux Software RAID, ReFS, Reiser 4

So only when libparted doesn't recognise a file system on the whole disk
device and GParted does, either via blkid or it's internal code, display
this with partition table "none".

Bug 741430 - GParted cannot recognise LVM signature on unpartitioned
             drive
2015-03-09 10:17:22 -06:00
Mike Fleetwood ed827cf59a Create helper function set_partition_label_and_uuid() (#741430)
Move code which queries the file system label and UUID of a partition
into a separate helper function.

Bug 741430 - GParted cannot recognise LVM signature on unpartitioned
             drive
2015-03-09 10:17:22 -06:00
Mike Fleetwood cb645b16cf Refactor GParted internal file system signature detection (#741430)
Refactor GParted internal file system signature detection to remove code
duplication.  There were 5 separate copies of code to: allocate a
buffer, open, read and close the device, free the buffer and compare the
signature.

Bug 741430 - GParted cannot recognise LVM signature on unpartitioned
             drive
2015-03-09 10:17:22 -06:00
Michael Zimmermann 1f5841b4ad Add support for GPT partition names (#741424)
Embedded devices (Android) use GPT partition names to identify
partitions, instead of file system labels.  Add support for viewing and
changing them.

As partition names are used to provide unique identification they are
never copied when copying the contents of one partition to another.

Note that GNU/Linux uses file system labels, UUIDs or device names for
identification during the boot process and afterwards so while partition
names can be used, they are optional and purely for user information.

Bug 741424 - Add support for GPT partition names
2015-02-01 10:08:23 -07:00
Mike Fleetwood e1dc89cd11 Rename class to Dialog_FileSystem_Label (#741424)
class Dialog_Partition_Label   -> Dialog_FileSystem_Label
file Dialog_Partition_Label.h  -> Dialog_FileSystem_Label.h
file Dialog_Partition_Label.cc -> Dialog_FileSystem_Label.cc

Bug 741424 - Add support for GPT partition names
2015-02-01 10:08:23 -07:00
Mike Fleetwood 04450c577c Rename class to OperationLabelFileSystem (#741424)
class OperationLabelPartition   -> OperationLabelFileSystem
file OperationLabelPartition.h  -> OperationLabelFileSystem.h
file OperationLabelPartition.cc -> OperationLabelFileSystem.cc

Bug 741424 - Add support for GPT partition names
2015-02-01 10:08:23 -07:00
Mike Fleetwood 3630b9c83b Rename methods in GParted_Core and Win_GParted classes (#741424)
class GParted_Core:
    label_partition() -> label_filesystem()

class Win_GParted:
    allow_label_partition()    -> allow_label_filesystem()
    activate_label_partition() -> activate_label_filesystem()

Bug 741424 - Add support for GPT partition names
2015-02-01 10:08:23 -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 d480800600 Rename enum to OPERATION_LABEL_FILESYSTEM (#741424)
This and the following few commits rename variables, methods, classes,
etc from *label_partition* to *label_filesystem* so that the code also
reflects that it is the label of the file system that is being modified
and to separate it from the name partition operation about to be added.

enum OPERATION_LABEL_PARTITION -> OPERATION_LABEL_FILESYSTEM

Bug 741424 - Add support for GPT partition names
2015-02-01 10:08:23 -07:00
Mike Fleetwood 3373ef07fa Recognise ReFS file system (#738471)
Only recognises ReFS file system.  No other actions are supported.
Requires blkid from util-linux >= 2.24.

Bug #738471 - ReFS file system is not recognised
2014-10-30 09:55:01 -06:00
Mike Fleetwood 8b4b73a8f3 Add supported_filesystem() predicate method (#738471)
Helper to check whether a recognised file system type is supported by
GParted or not.  Supported means there is an implementation class and
will appear in the File System Support dialog.

Make supported_filesystem() a static member function so that it can be
called without a class object so that GParted_Core::GParted_Core()
initialiser isn't called multiple times.  This requires FILESYSTEM_MAP
to become a static member variable too.

Bug #738471 - ReFS file system is not recognised
2014-10-30 09:55:01 -06:00
Mike Fleetwood 58618572b5 Comment and re-order FILESYSTEM enumeration type 2014-10-30 09:55:01 -06:00
Mike Fleetwood e3a1b93a6d Pass by value to get_filesystem_object()
get_filesystem_object() takes a constant reference to a FILESYSTEM, but
FILESYSTEM is just an enumeration.  So that's a pointer to a constant
int.  Just pass by value instead.
2014-10-30 09:55:01 -06:00
Mike Fleetwood f672f68863 Check for e4fsprogs commands for ext4 support on RHEL/CentOS 5.x (#738706)
RHEL / CentOS 5.6 and later officially support ext4 file system [1].
From RHEL / CentOS 5.3 ext4 file system was included as a technology
preview.  Ext4 file system tools are in a separate package e4fsprogs,
using uniquely named commands.  The standard e2fsprogs commands only
support ext2 and ext3 file systems.

    # mkfs.ext4 /dev/sdb3
    # tune2fs -l /dev/sdb3
    tune2fs 1.39 (29-May-2006)
    tune2fs: Filesystem has unsupported feature(s) while trying to open /dev/sdb3
    Couldn't find valid filesystem superblock.
    # echo $?
    1
    # tune4fs -l /dev/sdb3
    tune4fs 1.41.12 (17-May-2010)
    Filesystem volume name:   <none>
    Last mounted on:          <not available>
    Filesystem UUID:          ba4a9d58-7728-4b47-8a90-80e772615637
    Filesystem magic number:  0xEF53
    Filesystem revision #:    1 (dynamic)
    Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
    ...

For ext4 only, search for the e4fsprogs specific commands first and the
standard e2fsprogs commands second.

[1] RHEL 5.6 Release Notes, 5. Filesystems and Storage
https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/5.6_Release_Notes/ar01s05.html

Bug #738706 - GParted doesn't support ext4 on RHEL/CentOS 5.x
2014-10-27 09:32:36 -06:00
Mike Fleetwood 52ee26f971 Prevent flashing redraw of the devices combobox (#696149)
The device combobox was getting drawn blank, then getting drawn again
with the selected device.  This was happening because at the start of
Win_GParted::refresh_combo_devices() the GTK model behind the combobox,
liststore_devices, was cleared, changing the active item, causing the
combobox to get redrawn empty.  After the GTK model had been repopulated
the active item was reset causing the comboxbox to get redrawn again,
now showing the selected device.  Call flow:

    Win_GParted::refresh_combo_devices()
        liststore_devices->clear()
            //Gtk::Combobox emits signal_change.  Registered callbacks
            //called.
                Win_GParted::combo_devices_changed()
                    Win_GParted::Refresh_Visual()
                        ...
        ...
        combo_devices.set_active(current_device);
            //Gtk::Combobox emits signal_change.  Registered callbacks
            //called.
                Win_GParted::combo_devices_changed()
                    Win_GParted::Refresh_Visual()
                        ...

This has always been the case, since the device combobox was first added
to GParted before version 0.1 by commit:

    3a4b43e0ad
    replaced deprecated OptionMenu with ComboBox ...

Fix by temporarily blocking the devices comboxbox from emitting
signal_changed while the GTK model behind the combobox is recreated.

However, since automatic selection of the largest free space was added
[1] in GParted 0.15.0, a more noticeable flashing redraw issue was
caused in which the partition graphic and partition list were both drawn
blank then redrawn fully populated.  Some distributions were not
affected by this at all, some only experienced a single flash and others
suffered from two or more flashing redraws.  Some affected
distributions: CentOS 5.10, 6.5, 7.0, Debian 6, Fedora 14, 19, 20,
Ubuntu 13.10, Xubuntu 14.04 LTS.  Did not occur on Kubuntu 12.04 LTS.

[1] 5b53c12f6e
    Select largest unallocated partition by default (#667365)

Bug #696149 - Double refresh of display introduced with default
              unallocated space
2014-10-07 10:38:27 -06:00
Mike Fleetwood c1db9811e1 Use Autoconf check specifically for libparted-fs-resize (#734718)
Remove HAVE_LIBPARTED_3_1_0_PLUS definition and replace Autoconf
    check for libparted >= 3.1

Currently uses custom check which compiles an executable to check for
libparted version >= 3.1 to determine the availability of the library
parted-fs-resize and the need to include the header <parted/filesys.h>.

Change to use a direct Autoconf check to determine the availability of
the ped_file_system_resize() function in the parted-fs-resize library.
Remove inclusion of the header <parted/filesys.h> as it has always been
included via <parted/parted.h>, at least as far back as parted 1.8.0,
and even in parted 3.0 when ped_file_system_resize() and libparted file
system resize capability didn't exist.

Bug #734718 - Update Autoconf version specific libparted checks and
              defines to feature specific ones
2014-08-18 15:48:34 -06:00
Mike Fleetwood 3bea067596 Flush devices when scanning to prevent reading stale signatures (#723842)
While one partition is busy, reformat another partition from the command
line.  Afterwards parted/libparted still detects the original file
system and GParted shows errors from the file system specific tools
reporting the new file system doesn't exist.  Only limitation is that
the new new file system must be recognised by libparted (or by GParted's
fallback file system signature detection).

Case #1, File system reformatting:

    # parted /dev/sdb print
    Model: ATA SAMSUNG SSD UM41 (scsi)
    Disk /dev/sdb: 8012MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos

    Number  Start   End     Size    Type     File system  Flags
     1      1049kB  2149MB  2147MB  primary  ext2
     2      2149MB  4296MB  2147MB  primary  ext2
    # mount | fgrep sdb
    /dev/sdb1 on /mnt/1 type ext2 (rw)

    # mkfs.xfs -f /dev/sdb2
    # blkid /dev/sdb2
    /dev/sdb2: UUID="c31823a2-b81b-46fa-8246-0a59695e4834" TYPE="xfs"
    # parted /dev/sdb print
    Model: ATA SAMSUNG SSD UM41 (scsi)
    Disk /dev/sdb: 8012MB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos

    Number  Start   End     Size    Type     File system  Flags
     1      1049kB  2149MB  2147MB  primary  ext2
     2      2149MB  4296MB  2147MB  primary  ext2
    # e2label /dev/sdb2
    e2label: Bad magic number in super-block while trying to open /dev/sdb2
    Couldn't find valid filesystem superblock.
    # dumpe2fs /dev/sdb2
    dumpe2fs 1.41.12 (17-May-2010)
    dumpe2fs: Bad magic number in super-block while trying to open /dev/sdb2
    Couldn't find valid filesystem superblock.

Case #2, Removing device from multi-device btrfs:

    # btrfs filesystem show /dev/sdb1
    Label: none  uuid: a05db434-efd5-4e8c-902f-05f89a88b610
            Total devices 2 FS bytes used 156.00KB
            devid    2 size 2.00GB used 512.00MB path /dev/sdb2
            devid    1 size 2.00GB used 240.75MB path /dev/sdb1

    # mount /dev/sdb1 /mnt/1
    # btrfs device delete /dev/sdb2
    # btrfs filesystem show /dev/sdb1
    Label: none  uuid: a05db434-efd5-4e8c-902f-05f89a88b610
            Total devices 1 FS bytes used 92.00KB
            devid    1 size 2.00GB used 714.25MB path /dev/sdb1
    # btrfs filesystem show /dev/sdb2

and GParted reports this error for partition /dev/sdb2:
    Unable to read the contents of this file system!
    Because of this some operations may be unavailable.
    The cause might be a missing software package.
    The following list of software packages is required for btrfs
    file system support:  btrfs-tools.

This is another case of libparted reading from the whole disk device
(/dev/sdb) yet the file system tools use the partition specific block
device (/dev/sdb2), and the Linux buffer cache not providing cache
coherency.  Previous scenario was fixed with:

    797f0b8eeb
    Flush device after wiping a file system (#688882)

This affects libparted 2.0 to 3.1 inclusive and is fixed by:

    http://git.savannah.gnu.org/cgit/parted.git/commit/?id=fb99ba5ebd0dc34204fc9f1014131d5d494805bc
    Revert "linux-commit: do not unnecessarily open partition device nodes"

Fix by calling ped_device_sync() to guarantee cache coherency for each
device during scanning.

Bug #723842 - GParted resizes the wrong filesystem (does not pass the
              devid to btrfs filesystem resize)
2014-07-28 10:03:16 -06:00
Mike Fleetwood 20f52e2866 Display btrfs members in the Partition Information dialog (#723842)
Bug #723842 - GParted resizes the wrong filesystem (does not pass the
              devid to btrfs filesystem resize)
2014-07-28 10:03:16 -06:00
Mike Fleetwood 4b63e46a4e Fallback to reading mount command output instead of /etc/mtab (#723842)
With linux 3.5 and later, the device used to mount a btrfs file system
is updated in /proc/mounts when the previous mounting device is removed
from the file system.  Most recent distributions make /etc/mtab a
symbolic link to /proc/mounts.  However some still have /etc/mtab as a
plain file only updated by mount and umount, thus showing the old device
name which is no longer part of the file system.

On Ubuntu 13.10, which has /etc/mtab as a plain file managed by mount
and umount:

    # mkfs.btrfs /dev/sdb1
    # mount /dev/sdb1 /mnt/1
    # btrfs device add /dev/sdb2 /mnt/1
    # btrfs device delete /dev/sdb1 /mnt/1
    # sync
    # btrfs filesystem show /dev/sdb1
    # btrfs filesystem show /dev/sdb2
    Label: none  uuid: e47775a6-e5ad-4fb4-9ea4-1570aa5b4009
            Total devices 2 FS bytes used 28.00KB
            devid    2 size 2.00GB used 272.00MB path /dev/sdb2

    # fgrep btrfs /proc/mounts
    /dev/sdb2 /mnt/1 btrfs rw,relatime,space_cache 0 0
    # ls -l /etc/mtab
    -rw-r--r-- 1 root root 842 Apr 15 19:41 /etc/mtab
    # fgrep btrfs /etc/mtab
    /dev/sdb1 /mnt/1 btrfs rw 0 0

This causes GParted to report /dev/sdb1 as busy and mounted at /mnt/1
when it is no longer mounted.  This effects recent releases of Ubuntu,
13.04, 13.10 and 14.04.

Either /etc/mtab is a symlink and is identical to /proc/mounts or
/etc/mtab is a plain file with wrong information.  Fix by not reading
mounted file systems from /etc/mtab.

However old distributions only contain 'rootfs' and '/dev/root' device
names for the / (root) file system with '/dev/root' being a block device
rather than a symlink to the true device.  For example from CentOS 5.x:

    # fgrep ' / ' /proc/mounts
    rootfs / rootfs rw 0 0
    /dev/root / ext3 rw,data=ordered 0 0
    # ls -l /dev/root
    brw------- 1 root root 8, 3 Jun  4  2013 /dev/root

This prevents identification, and therefore busy detection, of the
device containing the / (root) file system.  Used to read /etc/mtab to
get the root file system device name.

    # fgrep ' / ' /etc/mtab
    /dev/sda3 / ext3 rw 0 0
    # ls -l /dev/sda3
    brw-r----- 1 root disk 8, 3 Jun  4  2013 /dev/sda3

As per commit:

    409096f739
    improved scanning for root mountpoint (/) ...

but, as discussed above, this contains an out of date device name after
the mounting device has been dynamically removed from a multi-device
btrfs, thus identifying the wrong device as busy.  Instead fall back to
reading mounted file systems from the output of the mount command, but
only when required.

    # mount | fgrep ' / '
    /dev/sda3 on / type ext3 (rw)

Bug #723842 - GParted resizes the wrong filesystem (does not pass the
              devid to btrfs filesystem resize)
2014-07-28 10:03:16 -06:00
Mike Fleetwood 287526681d Add devid to the cache of btrfs device information (#723842)
Bug #723842 - GParted resizes the wrong filesystem (does not pass the
              devid to btrfs filesystem resize)
2014-07-28 10:03:16 -06:00
Mike Fleetwood a086e115e5 Display mount points for multi-device btrfs file systems (#723842)
Linux can only show a single device name in /proc/mounts and /etc/mtab
for each mounted btrfs, even if it is a multi-device file system.  So
GParted only shows a mount point for one of the devices in the btrfs, no
matter how many devices are part of the file system.

    # mkfs.btrfs /dev/sdb1 /dev/sdb2
    # btrfs filesystem show /dev/sdb1
    Label: none  uuid: 36eb51a2-2927-4c92-820f-b2f0b5cdae50
            Total devices 2 FS bytes used 156.00KB
            devid    2 size 2.00GB used 512.00MB path /dev/sdb2
            devid    1 size 2.00GB used 240.75MB path /dev/sdb1
    # mount /dev/sdb1 /mnt/1
    # grep btrfs /proc/mounts
    /dev/sdb1 /mnt/1 btrfs rw,seclabel,relatime,ssd,space_cache 0 0

GParted only shows the mount point for /dev/sdb1 as /mnt/1, but nothing
for /dev/sdb2.

Make GParted report the same mount point for all devices included in a
multi-device btrfs file system.

Add btrfs specific get_mount_device() method to report the mounting
device, if any, for the btrfs file system in the occupying the device in
question.  Uses the existing cache of btrfs file system device
membership.  Also extract common code from GParted_Core::
set_mountpoints() into set_mountpoints_helper().

Bug #723842 - GParted resizes the wrong filesystem (does not pass the
              devid to btrfs filesystem resize)
2014-07-28 10:03:16 -06:00
Mike Fleetwood 76e64f2905 Detect busy status of multi-device btrfs file systems (#723842)
Busy detection of file systems works by checking if the device is
mounted (appears in the mount_info map).  For a multi-device btrfs file
system this will only report one of the devices as busy, not all of
them.

    # btrfs filesystem show /dev/sdb1
    Label: none  uuid: 36eb51a2-2927-4c92-820f-b2f0b5cdae50
            Total devices 2 FS bytes used 156.00KB
            devid    2 size 2.00GB used 512.00MB path /dev/sdb2
            devid    1 size 2.00GB used 240.75MB path /dev/sdb1
    # mount /dev/sdb1 /mnt/1
    # grep btrfs /proc/mounts
    /dev/sdb1 /mnt/1 btrfs rw,seclabel,relatime,ssd,space_cache 0 0

GParted will only report /dev/sdb1 as busy, but not /dev/sdb2.

Add btrfs specific is_busy() method which reports the device as busy if
any of the devices in the btrfs file system are mounted.  This uses a
cache which maps device membership in all btrfs file systems.  The cache
is cleared on GParted refresh and incrementally populated as each btrfs
partition is checked for busy status.

WARNING:
Removal of the mounting device from a btrfs file system makes it
impossible to determine whether the file system is mounted or not for
linux <= 3.4.  This is because /proc/mounts continues to show the old
device which is no longer a member of the file system.

    # btrfs device delete /dev/sdb1 /mnt/1
    # sync
    # grep btrfs /proc/mounts
    /dev/sdb1 /mnt/1 btrfs rw,seclabel,relatime,ssd,space_cache 0 0
    # btrfs filesystem show /dev/sdb1
    # btrfs filesystem show /dev/sdb2
    Label: none  uuid: 36eb51a2-2927-4c92-820f-b2f0b5cdae50
            Total devices 1 FS bytes used 28.00KB
            devid    2 size 2.00GB used 1.02GB path /dev/sdb2

Fixed in linux 3.5 by commit:
    Btrfs: implement ->show_devname
    https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=9c5085c147989d48dfe74194b48affc23f376650

Bug #723842 - GParted resizes the wrong filesystem (does not pass the
              devid to btrfs filesystem resize)
2014-07-28 10:03:16 -06:00
Mike Fleetwood a0c0533e3e Add is_dev_mounted() to expose core partition is mounted test (#723842)
Add static member function GParted_Core::is_dev_mounted() so that other
modules can determine if a particular partition contains a mounted file
system or not.

Make it a static member function so that it can be called without
needing the gparted_core object.  Extend to make the group of
manipulated variables (mount_info, fstab_info) and manipulating
functions (init_maps(), read_mountpoints_from_file(),
read_mountpoints_from_file_swaps(), get_all_mountpoints()) static too.

Bug #723842 - GParted resizes the wrong filesystem (does not pass the
              devid to btrfs filesystem resize)
2014-07-28 10:03:16 -06: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
Mike Fleetwood 0fcfd18061 Prevent cross thread write after free in _OnReadable() (#731752)
Fragment of debugging and valgrind output:
D: tid=2193 main()
...
D: tid=2202 GParted_Core::set_devices_thread()
...
D: tid=2202 Utils::execute_command(command="dumpe2fs -h /dev/sda1", output, error, use_C_locale=1)
D: tid=2202 this=0x13fef4a0 PipeCapture::PipeCapture()
D: tid=2202 this=0x13fef4f0 PipeCapture::PipeCapture()
D: tid=2202 this=0x13fef4a0 PipeCapture::connect_signal()
D:  sourceid=77
D: tid=2202 this=0x13fef4f0 PipeCapture::connect_signal()
D:  sourceid=78
D: tid=2193 data=0x13fef4a0 PipeCapture::_OnReadable()
D: tid=2193 this=0x13fef4a0 PipeCapture::OnReadable()
D:  signal_update.emit()
D:  return true
D: tid=2193 data=0x13fef4f0 PipeCapture::_OnReadable()
D: tid=2193 this=0x13fef4f0 PipeCapture::OnReadable()
D:  signal_update.emit()
D:  return true
D: tid=2193 data=0x13fef4a0 PipeCapture::_OnReadable()
D: tid=2193 this=0x13fef4a0 PipeCapture::OnReadable()
D:  signal_update.emit()
D:  return true
D: tid=2193 data=0x13fef4f0 PipeCapture::_OnReadable()
D: tid=2193 this=0x13fef4f0 PipeCapture::OnReadable()
D:  signal_eof.emit()
D:  return false
D:  (!rc)  &(pc->sourceid)=0x13fef518
D: tid=2193 data=0x13fef4a0 PipeCapture::_OnReadable()
D: tid=2193 this=0x13fef4a0 PipeCapture::OnReadable()
D:  signal_update.emit()
D:  return true
D: tid=2193 data=0x13fef4a0 PipeCapture::_OnReadable()
D: tid=2193 this=0x13fef4a0 PipeCapture::OnReadable()
D:  signal_update.emit()
D:  return true
D: tid=2193 data=0x13fef4a0 PipeCapture::_OnReadable()
D: tid=2193 this=0x13fef4a0 PipeCapture::OnReadable()
D:  signal_eof.emit()
D: tid=2202 this=0x13fef4f0 PipeCapture::~PipeCapture()
D:  sourceid=0
D: tid=2202 this=0x13fef4a0 PipeCapture::~PipeCapture()
D:  sourceid=77
D:  return false
D:  (!rc)  &(pc->sourceid)=0x13fef4c8
==2193== Thread 1:
==2193== Invalid write of size 4
==2193==    at 0x490580: GParted::PipeCapture::_OnReadable(_GIOChannel*, GIOCondition, void*) (PipeCapture.cc:56)
==2193==    by 0x38662492A5: g_main_context_dispatch (gmain.c:3066)
==2193==    by 0x3866249627: g_main_context_iterate.isra.24 (gmain.c:3713)
==2193==    by 0x3866249A39: g_main_loop_run (gmain.c:3907)
==2193==    by 0x3D7FD45C26: gtk_main (gtkmain.c:1257)
==2193==    by 0x469743: GParted::GParted_Core::set_devices(std::vector<GParted::Device, std::allocator<GParted::Device> >&) (GParted_Core.cc:155)
==2193==    by 0x4A78F1: GParted::Win_GParted::menu_gparted_refresh_devices() (Win_GParted.cc:1259)
==2193==    by 0x4A7886: GParted::Win_GParted::on_show() (Win_GParted.cc:1253)
==2193==    by 0x3D82B2009C: Gtk::Widget_Class::show_callback(_GtkWidget*) (widget.cc:3855)
==2193==    by 0x3867210297: g_closure_invoke (gclosure.c:777)
==2193==    by 0x3867221B86: signal_emit_unlocked_R (gsignal.c:3516)
==2193==    by 0x386722A0F1: g_signal_emit_valist (gsignal.c:3330)
==2193==  Address 0x13fef4c8 is not stack'd, malloc'd or (recently) free'd
==2193==

PipeCapture.cc (with debugging):
    46  gboolean PipeCapture::_OnReadable( GIOChannel *source,
    47                                     GIOCondition condition,
    48                                     gpointer data )
    49  {
    50          std::cout << "D: tid=" << (long int)syscall(SYS_gettid) << " data=" << data << " PipeCapture::_OnReadable()" << std::endl;
    51          PipeCapture *pc = static_cast<PipeCapture *>(data);
    52          gboolean rc = pc->OnReadable( Glib::IOCondition(condition) );
    53          if (!rc)
    54          {
    55                  std::cout << "D:  (!rc)  &(pc->sourceid)=" << &(pc->sourceid) << std::endl;
    56                  pc->sourceid = 0;
    57          }
    58          return rc;
    59  }

The use after free across threads only happens when an external program
is being executed from a thread other than the main() thread.  This is
because by default glib registered callbacks are run by the glib main
loop, which is only called from the main() thread with Gtk::Main::run().

Event sequence:
tid=2193                      tid=2202

main()
...
  GParted_Core::set_devices()
    Glib::Thread::create(... set_devices_thread ...)
    Gtk::Main::run()          GParted_Core::set_devices_thread()
                              ...
                                Utils::execute_command("dumpe2fs ... /dev/sda1" ...)
                                  Glib::spawn_async_with_pipes()
                                  PipeCapture outputcapture(out, output)
                                  outputcapture.connect_signal()
      //Glib main loop runs callback
      PipeCapture::_OnReadable()
        pc->OnReadable()
          //output read
          signal_update.emit()
          return true
      ...
      //Glib main loop runs callback
      PipeCapture::_OnReadable()
        pc->OnReadable()
          //eof reached
[1]       signal_eof.emit()
                                  return status.exit_status
[2]                               PipeCapture::~PipeCapture()
[3]       return false
[4]     pc->sourceid = 0

What is happening is that the PipeCapture destructor [2] is running in
the set_devices_thread() thread and freeing the object's memory as soon
as signal_eof.emit() [1] has been called.  Then signal_eof.emit()
returns back to OnReadable() which then returns false [3] back to the
_OnReadable() callback function which then assigns 0 to sourceid member
variable [4] in the already freed object, detected by valgrind as:
    Invalid write of size 4
       at ... GParted::PipeCapture::_OnReadable(...) (PipeCapture.cc:56)

This is happening because PipeCapture member variable sourceid is being
saved, in a different thread, just so the _OnReadable() callback can be
removed.  However a glib IOChannel callback, type GIOFunc(), returning
false will be automatically removed.

    GLib Reference Manual 2.26 / IO Channels
    https://developer.gnome.org/glib/2.26/glib-IO-Channels.html#GIOFunc

    GIOFunc()

    Returns : the function should return FALSE if the event source
              should be removed

Therefore fix by just not saving the event sourceid at all, and not
calling g_source_remove() to manually remove the callback, but instead
letting glib automatically remove the callback when it returns false.

Bug #731752 - Write after free cross thread race in
              PipeCapture::_OnReadable()
2014-07-06 10:22:40 -06:00
Phillip Susi 947cd02857 Change OperationDetail to not store complex objects in STL containers (#729139)
OperationDetail was storing its children in a std::vector.  This means they
can be moved around in memory arbitrarily, going through indeterminate
lifetimes.  This is generally a bad thing for any non trivial object and
in the case of OperationDetail, it created havoc with the way it maintains
pointers between parent/child objects for signal connections.  It will now
keep only pointers to children in a std::vector instead, so their lifetime
can be controlled, fixing various crashes.

Bug 729139 - Refactor OperationDetail to address random behavior
2014-05-18 10:07:45 -06:00
Curtis Gedak 6efa623401 Add optional yalign argument to Utils::mk_label() method
As part of the work on bug 652044 - uses deprecated APIs, selectable
vertical alignment was defaulted to ALIGN_CENTER for all labels.  The
relevant commits can be viewed in comment 26 of said bug report.
https://bugzilla.gnome.org/show_bug.cgi?id=652044#c26

For multi-line labels a vertical ALIGN_CENTER value is not
consistently aesthetically pleasing.  This becomes obvious when a
single-line heading label is paired with a multi-line value label.
To improve the aesthetics, a vertical alignment of ALIGN_TOP is
preferred.

Hence re-add the ability to optionally specify a vertical alignment for
labels.  If a yalign value is not specified a default vertical alignment
of ALIGN_CENTER is used.
2014-04-28 08:42:40 +01:00
Curtis Gedak e075ab006e Remove unused text_color argument from Utils::mk_label() method
None of the current GParted code uses the text_color argument for
Utils::mk_label().  Remove unused argument to simplify code.
2014-04-28 08:42:40 +01:00
Curtis Gedak ccaeb8dc51 Make the partition information dialog resizable (#690542)
Make the dialog resizable, add a vertical scrollbar to the information
and messages section, and set the initial height to ensure the dialog
fits entirely on an 800x600 screen.

A default height is required because some window managers, such as
fluxbox used in GParted Live, only permit resizing the height by using
the bottom corners of the dialog.  If the dialog is too large for the
screen then the user would not be able to resize it.

Note that two default initial heights are used in an effort to minimize
the amount of extra whitespace.

Bug 690542 - Partition Information Dialog Warning not readable
2014-04-28 08:42:40 +01:00
Mike Fleetwood 5f6656f267 Initialise file system objects only once
The code used to unnecessarily destroy and re-create the file system
objects on every scan for file system support tools.

Instead only create the file system objects once and just call each
object's get_filesystem_support() method on each rescan.
2014-04-23 10:25:56 -06:00
Mike Fleetwood 131098a797 Remove set_proper_filesystem() method
Prior to commit:

    1f3b11748e
    Remove GParted_Core::p_filesystem (#683149)

set_proper_filesystems() used to set GParted_Core::p_filesystem member
variable to one of the FileSystem objects, but that was just treating it
like a local variable.  After the commit local variables named
p_filesystem were used where required and set_proper_filesystem() became
a function which did nothing other than call get_filesystem_object().

Now remove set_proper_filesystem() altogether and use
get_filesystem_object() in its place.
2014-04-23 10:25:27 -06:00
Mike Fleetwood 67115eeff2 Remove unused member variable GParted_Core::buf 2014-04-23 09:54:20 -06:00
Phillip Susi 86111fe12a Use e2image to move/copy ext[234] file systems (#721516)
Use e2image features added in e2fsprogs 1.42.9 to move/copy
an ext[234] file system more efficiently by skipping unused blocks.
Fall back to the internal copy algorithm if e2image is not found
or does not support move/copy.

Bug #721516 - Use e2image to move/copy ext[234] filesystems
2014-03-05 22:12:10 +00:00
Mike Fleetwood 9728479771 Recognise BitLocker encrypted partitions (#723232)
Only recognises partitions containing BitLocker Disk Encryption content.
No other actions are supported.

Bug #723232 - BitLocker Disk Encryption not recognised
2014-01-31 09:55:05 -07:00
Mike Fleetwood a70bfd32fe Restore compilation order of source files
Restore the order of the source files so that they are once again
compiled in order A-Z, a-z.  Order is obtained with:

    fgrep .cc src/Makefile.am | LANG=C sort
    fgrep .h include/Makefile.am | LANG=C sort
2014-01-27 10:54:48 -07:00
Mike Fleetwood 6f9b99f138 Make the File System Support dialog resizable (#342682)
Make the dialog resizable, add a vertical scrollbar and set the minimum
(and therefore initial) height to 500 pixels.  This is so that the
dialog entirely fits on an 800x600 screen, thus allowing the rescan
button to be pressed.

100 pixel difference is to account for the size of the top and bottom
GNOME 2 panels and two sets of title bars.  Two sets of title bars
because the window manager tries to place the top of dialog title bars
in line with the bottom of the main window title bar.

Bug #342682 - too much information in 'features' dialog
2014-01-27 10:54:48 -07:00
Mike Fleetwood 59f684d8cd Always show the File System Support dialog legend (#342682)
Make the legend always shown, ready for when the dialog is resizable.

Change the widget containing the legend from an expander to a frame
widget.  Set the frame to be borderless using a bold label as
recommended in the GNOME Human Interface Guidelines 2.2.1 / Controls /
Frames and Separators.

    https://developer.gnome.org/hig-book/2.32/controls-frames.html.en

Bug #342682 - too much information in 'features' dialog
2014-01-27 10:54:48 -07: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
Mike Fleetwood 7b43d52720 Display partition table types in order (#711098)
In the Create Partition Table dialog display the entries in the combobox
in order.

Previously the default of MSDOS or GPT was moved to the first item in
the combobox.  Now the partition table types remain in order with just
either MSDOS or GPT being selected as as the default as required.

The partition table types are displayed in the order supplied by
libparted, which is alphabetic except with "loop" last.

Bug #711098 - Default partition table can not handle > 2 TiB disks
2014-01-06 10:45:00 +00:00
Phillip Susi 07bd72ba80 Default to GPT on disks >= 2 TiB (#711098)
MSDOS partition table is limited to addressing 2^32 sectors, limiting
disks using 512 byte sectors to 2 TiB in size.  Fdisk reports the
following warning on disks 2 TiB and larger.

    # truncate -s 2T /var/tmp/loop-2T
    # losetup /dev/loop0 /var/tmp/loop-2T
    # fdisk /dev/loop0

    WARNING: The size of this disk is 2.2 TB (2199023255552 bytes).
    DOS partition table format can not be used on drives for volumes
    larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
    partition table format (GPT).

(Fdisk arguably reports this warning one sector too early.  Anyway for
safety and consistency GParted will use this limit too).  Continue to
use MSDOS as the default partition table type for disks smaller than 2
TiB and use GPT as the default for disks 2 TiB and larger.  This
maximises compatibility.

Also remove the advanced expander and always show the partition table
list box.

Bug #711098 - Default partition table can not handle > 2 TiB disks
2014-01-06 10:44:59 +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
Mike Fleetwood 7ae05b7241 Remove unused function declarations for *_mtoolsrc_file()
Remove left behind function declarations create_mtoolsrc_file() and
delete_mtoolsrc_file() after commit:

    2706f0174a
    Remove mtoolsrc file
2013-10-19 10:21:09 -06:00
Mike Fleetwood d2e1130ad2 Detect busy status of Linux Software RAID members (#709640)
Read the contents of /proc/mdstat file to determine if a device is a
member of of an active RAID array.

    $ cat /proc/mdstat
    Personalities : [raid1]
    md1 : active raid1 sda1[2] sdb1[3]
          524224 blocks super 1.0 [2/2] [UU]

    md2 : active raid1 sdb2[2] sda2[3](F)
          5238720 blocks super 1.1 [2/1] [U_]

    md3 : active raid1 sdb3[1]
          10477440 blocks super 1.1 [2/1] [_U]
          bitmap: 1/1 pages [4KB], 65536KB chunk

    md4 : inactive sda4[0](S)
          1048564 blocks super 1.2

    unused devices: <none>

There are 5 example Linux Software RAID arrays, md1 to md5.  All are
RAID1 mirrors with 2 members, in various states.

    Array  Members     Status
    md1    sda1, sdb2  Fully operational.
    md2    sda2, sdb2  Member sda2 marked as faulty.  (Device sda2 is
                       still in use).
    md3    sda3, sdb3  Member sda3 has been removed.  (Device sda3 is
                       not in use).
    md4    sda4, sdb4  Incremental start of member sda4 only.  (Neither
                       member devices is in use).
    md5    sda5, sdb5  Array stopped.  (Neither member device is in
                       use).

Also disable "Unmount" in the partition menu for active RAID array
members.

Bug #709640 - Linux Swap Suspend and Software RAID partitions not
              recognised
2013-10-19 10:21:03 -06:00
Mike Fleetwood fac3f5b865 Recognise Linux Swap Suspend and Software RAID partitions (#709640)
Recognise in kernel, Linux Swap Suspend partitions.  (When hibernated
the kernel write the RAM out to swap space and changes the magic string
from swap space to suspend).  Recognition required either
libparted >= 1.8.8.1 or blkid from util-linux >= 2.15 or before that
blkid from e2fsprogs >= 1.39.

Recognise Linux Software RAID partitions.  Recognition requires blkid
from util-linux >= 2.15.

Example:

    # blkid /dev/sda10 /dev/sda11
    /dev/sda10: ... TYPE="swsuspend"
    /dev/sda11: ... TYPE="linux_raid_member"

    # parted /dev/sda print
    Model: ATA SAMSUNG HM500JI (scsi)
    Disk /dev/sda: 500GB
    Sector size (logical/physical): 512B/512B
    Partition Table: msdos

    Number  Start   End     Size    Type      File system     Flags
    ...
    10      361GB   362GB   1074MB  logical   swsusp
    11      362GB   363GB   1074MB  logical                   raid

Bug #709640 - Linux Swap Suspend and Software RAID partitions not
              recognised
2013-10-19 10:05:54 -06:00
Mike Fleetwood be2689ad25 Stop using deprecated widget alignment enumerators (#652044)
Step 3 of 3:

Now that all label widgets are created with ALIGN_LEFT and ALIGN_CENTER
alignment remove the x_align and y_align parameters from mk_label() and
always use this alignment.  Also specify this alignment via floats
rather than enumerators, one of which was deprecated.

Bug #652044 - uses deprecated APIs
2013-10-18 10:17:22 -06:00
Mike Fleetwood 1b54123580 Enhance line discipline in PipeCapture::OnReadable() (#709276)
Add concept of cursor position within the current line, separate from
the end of the buffer.  This is so that programs which output a text
progress bar using backspace, such as resize2fs -p, are displayed
correctly.

Bug #709276 - Percentage indicator for subcommand
2013-10-03 10:23:46 -06:00
Mike Fleetwood 293c8929a7 Actually display error message from statvfs() failure
Pass error_message parameter by reference to
get_mounted_filesystem_usage() so that the caller can access the
modified error message when required.
2013-09-24 09:49:10 -06:00
Mike Fleetwood 387b391d6d Add reporting of linux-swap usage (#708107)
For active swap space read the usage from /proc/swaps.  (Linux kernel
uses units of 1 KiB).  By definition inactive swap space is 100% free.

    $ cat /proc/swaps
    Filename                                Type            Size    Used    Priority
    /dev/sda2                               partition       5242876 430552  -1

Always set fs.read = FS::EXTERNAL even if /proc/swaps doesn't exist so
that an attempt is made to open the file generating a specific error, in
addition to the generic error.

    open("/proc/swaps", O_RDONLY): No such file or directory

    Unable to read the contents of this file system!
    Because of this some operations may be unavailable.

    The cause might be a missing software package.
    The following list of software packages is required for linux-
    swap file system support: util-linux.

Closes Bug #708107 - Usage of swap space is not reported
2013-09-24 09:49:10 -06:00
Mike Fleetwood 78c558c350 Also accept btrfs tools using IEC prefix multipliers (#706914)
Currently the btrfs command outputs figures to 2 decimal places followed
by an SI multiplier, e.g. 1.00GB.

This patch to btrfs-progs has been included in the integration
repository and will likely be included in the official btrfs-progs
repository at some point.  It changes btrfs-progs to use IEC
multipliers, e.g. 1.00GiB.  In fact multipliers already aren't used for
figures less than 1024.
    [PATCH] btrfs-progs: use IEC units for size
    http://permalink.gmane.org/gmane.comp.file-systems.btrfs/26888
    https://patchwork.kernel.org/patch/2825841/

Make GParted capable of also accepting IEC prefix multipliers, just "B"
for bytes and no multiplier, as well as an optional space between the
number and multiplier.  Therefore accept values like these:
    1.00GB         1.00 GB
    1.00GiB        1.00 GiB
    1073741824B    1073741824 B
    1073741824

Closes Bug #706914 - Prepare for btrfs tools using IEC prefix
                     multipliers
2013-08-29 10:20:52 -06:00
Mike Fleetwood 246e05559d Clear btrfs file system super block mirror copies too (#705426)
With recent btrfs-progs, GParted failed to format a btrfs file system
over the top of an existing one.  Make btrfs failed with this error:

    # mkfs.btrfs /dev/sdb1
    ...
    /dev/sdb1 appears to contain an existing filesystem (btrfs).
    Use the -f option to force overwrite.

With this commit to btrfs-progs on 2013-02-19, mkfs.btrfs checks for
existing file system signatures, including all mirror copies of btrfs
super blocks, before writing to the partition.

    http://git.kernel.org/cgit/linux/kernel/git/mason/btrfs-progs.git/commit/?id=2a2d8e1962e8b6cda7b0a7584f6d2fb95d442cb6
    btrfs-progs: require mkfs -f force option to overwrite filesystem or partition table

Make GParted clear all the mirror copies of the btrfs file system super
blocks as erase_filesystem_signatures() is intended to prevent detection
of old signatures.  This also avoids having to determine if the -f
option to mkfs.btrfs is available before trying to use it.

Closes Bug #705426 - Formatting Existing BTRFS Partition as BTRFS Fails
                     Because mkfs.btrfs Is Not Run with "-f"
2013-08-26 10:16:01 -06:00
Mike Fleetwood 1ae03dee95 Recognise new dosfstools program names (#704629)
Dosfstools >= 3.0.18, released June 2013, renamed the programs thus:

    dosfslabel becomes fatlabel,
    dosfsck becomes fsck.fat,
    and mkdosfs becomes mkfs.fat.

Dosfstools creates symbolic links for the old names for backward
compatibility, but unfortunately the Debian dosfstools-3.0.22-1
(experimental) package doesn't include those symbolic links.  This
causes create, check and read unmounted FAT16/32 file systems to not be
supported.

Make GParted look for the new names first and the old names second.

Closes Bug #704629 - Program name changes in dosfstools 3.0.18+ break
                     FAT16/32 support
2013-07-27 11:32:20 -06: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
Mike Fleetwood aed1fb58cf Remove unused read-only functionality from internal block copy
The read-only functionality is unused and the readonly parameter is
always false in copy_filesystem() and copy_blocks() methods.  This has
been the case since the copy simulation was dropped by commit:

    b9b4b2e55d
    Remove simulation pass ( read test ) on move
2013-06-05 10:57:39 -06:00
Mike Fleetwood 2b51d87147 Make include guards unique (#539297)
Include guards need to be unique within GParted code and all included
library header files.
    http://en.wikipedia.org/wiki/Include_guard#Difficulties

Use this model for all include guards:
    #ifndef GPARTED_FILE_NAME_H
    #define GPARTED_FILE_NAME_H
    ...
    #endif /* GPARTED_FILE_NAME_H */

Closes Bug #539297 - Make include guards unique
2013-06-05 10:57:39 -06:00
Mike Fleetwood 4cc426c6cf Only allow Undo and Apply after merging operations (#699452)
It was possible to make GParted crash by adding a label, check or new
UUID operation and then applying the operation before the view of
pending operations had finished fully opening.  The operation would be
successfully applied but GParted would crash afterwards.

The fault was that Add_Operation() still enabled the Undo and Apply
buttons and processed the GTK event loop before merging the list of
pending operations.  Faulty code flow went like this:

    activate_*()
        Add_Operation()
            Add operation to the operations[] vector
            Enable Undo and Apply buttons
            Refresh_Visual()
                Process GTK event loop
                    Process Apply button callback applying operations,
                    refreshing display and clearing operations[] vector
        Merge operations in the operations[] vector
        << Core dump here >>
            Merge_Operations()
                Refresh_Visual()

This faulty code flow came about when merging of operations was added
and it didn't appreciate that the operations[] vector could have been
processed and cleared by Add_Operations() before the merge step.
Relevant commit:

    b10349ae37
    Merge overlapping operations (#438573)

Fragment of code in the label operation case:

  2454  void Win_GParted::activate_label_partition()
  2455  {
  ...
  2472          Add_Operation( operation ) ;
  2473
  2474          // Verify if the two operations can be merged
  2475          for ( unsigned int t = 0 ; t < operations .size() - 1 ; t++ )
  2476          {
  2477              if ( operations[ t ] ->type == OPERATION_LABEL_PARTITION )
  2478              {
  2479                  if ( Merge_Operations( t, operations .size() - 1 ) )
  2480                      break;
  2481              }
  2482          }

Commentary in the crashing label operation case:

  2472  The pending operation was already applied when Add_Operation()
        returned resulting in the operations[] vector being cleared
        setting its size to 0.
  2475  The return type of operations.size() is an unsigned integral, so
        the upper limit of the for loop is t < 0UL - 1.  Assuming a
        32-bit machine that's t < 4294967295.
  2477  operations[] vector is access from out of bounds offset 0
        upwards until unallocated memory is accessed resulting in a core
        dump.

Fix this by not enabling the Undo and Apply buttons and processing the
GTK event loop until after merging of operations has been performed.
Fixed code flow goes like this:

    activate_*()
        Add_Operation()
            Add operation to the operations[] vector
        Merge operations in the operations[] vector
            Merge_Operations()
        show_operationslist()
            Enable Undo and Apply buttons
            Refresh_Visual()
                Process GTK event loop
                    Process Apply button callback applying operations,
                    refreshing display and clearing operations[] vector

Not allowing the operations list to be process until after the merge
step is the be correct ordering.  This also prevents the new operation
from flashing up in the operations list and then immediately
disappearing if merged.  In the case of adding the first operation,
delaying enabling the Undo and Apply buttons is enough as the buttons
were previously disabled preventing the operation being applied before
the merge.  In the case of adding further operations, processing of the
GTK event loop must also be delayed until after the merge to prevent the
operations being applied before the merge.  Although that window of
opportunity would only be microseconds.

Bug #699452 - Crash when applying operations before pending operations
              fully displayed
2013-05-19 13:18:25 -06:00
Mike Fleetwood 7ede0ca3cc Pad fat16/32 file system labels with spaces (#700228)
Mlabel sometimes writes uninitialised memory at the end of the label.
This causes mlabel, and therefore GParted, to display extra junk at the
end of the label.  Depending on the bytes written GParted may also show
the following error on stdout:

    (gpartedbin:18116): glibmm-CRITICAL **:
    unhandled exception (type Glib::Error) in signal handler:
    domain: g_convert_error
    code  : 1
    what  : Invalid byte sequence in conversion input

This is caused by a bug in mlabel, believed fixed in mtools 4.0.14.
Effects at least Fedora 14, RHEL/CentOS 6.x and Debian 6.  (Use label
"1234567890" on Debian 6 to reproduce).  Reproduction steps:

    # mkdosfs -F16 /dev/sda7
    mkdosfs 3.0.9 (31 Jan 2010)
    # export MTOOLS_SKIP_CHECK=1
    # mlabel ::123456 -i /dev/sda7
    # mlabel -s :: -i /dev/sda7
     Volume label is 123456~1t

It is not possible to detect which characters are junk so they can't be
trimmed.  Instead just space pad labels so that at least newly written
labels aren't effected.  (Fat labels are space padded on the disk by
definition anyway).

Bug #700228 - FAT16/32 labels are sometimes shown corrupted
2013-05-17 09:23:56 -06:00
Mike Fleetwood 519af1a7c0 Combine duplicate code for fat16/32
There was virtually no difference between the separate modules for fat16
and fat32.  Remove module fat32 and patch fat16 to serve both file
system subtypes.  This is equivalent to what was previously done for
ext[234] by commit:

    38dc55d49c
    Combine duplicate code for ext[234]
2013-05-17 09:23:56 -06:00
Mike Fleetwood 0d52cd19d7 Rename signals update and eof
Rename the libsigc++ signals to signal_update and signal_eof to match
the naming used for signals in GParted.
    fgrep 'sigc::signal' include/*.h

Also explicitly use the emit() method rather than using the object
operator().  This again is to match the convention in GParted and make
it more obvious what is happening.
    fgrep '.emit(' include/*.h
2013-05-10 10:03:53 -06:00
Phillip Susi 9475731ac8 Avoid glibmm GSource bug/crash (again) (#697727)
The previous commit missed one glibmm GSource wrapper in the form of the
io watch for the PipeCapture class.  Convert this one to use glib
directly as well.

Bug #697727 - Segfault in livecd Gparted v 0.15.0-3 when copying
              partition
2013-04-29 18:42:53 +01:00
Mike Fleetwood 1386984def Add copyright notice to PipeCapture .cc and .h files 2013-04-28 13:51:06 -06:00
Phillip Susi c36934aca5 Avoid glibmm GSource bug/crash (#697727)
The glibmm GSource wrappers have a bug where they do not do
reference counting properly, and have a race condition where
the background thread can try to touch the source after the
main thread has already processed and destroyed it.  This
results in writes to freed memory and sometimes this causes
crashes or other erratic behavior.  Avoid using the glibmm
wrappers and use glib directly.  See bug #561885 for details
of the glibmm bug.

Bug #697727 - Segfault in livecd Gparted v 0.15.0-3 when copying partition
2013-04-17 11:53:55 -06:00
Mike Fleetwood 6c33a8f5ca Remove unused function copy_filesystem_simulation()
The function is no longer used after commit:

    b9b4b2e55d
    Remove simulation pass ( read test ) on move
2013-03-25 10:06:40 -06:00
Mike Fleetwood e218ba3358 Refactor and rename GParted_Core::open/close_device_and_disk()
These functions in GParted_Core:
    open_device()
    open_device_and_disk()
    close_disk()
    close_device_and_disk()
call the following functions in the libparted API:
    ped_device_get()
    ped_disk_new()
    ped_disk_destroy()
    ped_device_destroy()
which don't open or close anything.  Instead they allocate and
deallocate PedDevice and PedDisk memory structures which describe block
devices and partition tables respectively.

Rename functions:
    open_device_and_disk()  -> get_device_and_disk()
    close_device_and_disk() -> destroy_device_and_disk()
and merge open_device() and open_device() as each only wrapped one
libparted function and was only called from a single place.
2013-03-25 10:06:39 -06:00
Mike Fleetwood 2b7e469473 Remove use of wipefs to clear file system signatures (#688882)
The wipefs command has the following significant limitations which were
worked around in previous commits:

1)  Wasn't available in the earliest distributions supported by GParted;

2)  Had to be called 3 times to erase vfat (fat16/32) signatures in all
    but the most recent versions.

This meant we had all the code to clear file system signatures without
using the wipefs command as well as extra complexity of using wipefs
too.  So just remove use of the wipefs command.

Bug #688882 - Improve clearing of file system signatures
2013-03-25 10:06:39 -06:00
Mike Fleetwood 6982f68e21 Workaround not so old wipefs only erasing 1 of 3 vfat signatures (#688882)
Before util-linux 2.21.0, released Feb 2012, wipefs only cleared one of
the three vfat (fat16/fat32) signatures it can be detected by each time
wipefs was run.  Also if a nilfs2 file system was created before all
three signatures were cleared the partition was still recognised as a
vfat file system, albeit a corrupted one, rather than as a nilfs2 file
system.

Old wipefs clearing vfat signatures:
    # wipefs --version
    wipefs from util-linux 2.20.1
    # wipefs -a /dev/sda7
    8 bytes were erased at offset 0x52 (vfat)
    they were: 46 41 54 33 32 20 20 20
    # wipefs -a /dev/sda7
    1 bytes were erased at offset 0x0 (vfat)
    they were: eb
    # wipefs -a /dev/sda7
    2 bytes were erased at offset 0x1fe (vfat)
    they were: 55 aa

New wipefs clearing vfat signatures:
    # wipefs --version
    wipefs from util-linux 2.21.2
    # wipefs -a /dev/sda12
    8 bytes were erased at offset 0x00000052 (vfat): 46 41 54 33 32 20 20 20
    1 bytes were erased at offset 0x00000000 (vfat): eb
    2 bytes were erased at offset 0x000001fe (vfat): 55 aa

Workaround by calling "wipefs -a" three times if the output indicated
only one vfat signature was cleared.

Bug #688882 - Improve clearing of file system signatures
2013-03-25 10:06:39 -06:00
Mike Fleetwood d4f68eb730 Add new "cleared" file system format (#688882)
Add "cleared" to the bottom of list of file system formats available in
the Create new Partition dialog and in the Format to --> (file system
list) menu.  This clears existing file system signatures in the newly
created partitions and existing partitions respectively.

Bug #688882 - Improve clearing of file system signatures
2013-03-25 10:06:39 -06:00
Mike Fleetwood bc5b57ab35 Refactor Win_GParted::create_format_menu() (#688882)
Move some code into new create_format_menu_add_item() sub-function which
adds one file system entry to the Partition --> Format to -->
(file system list) menu.

Bug #688882 - Improve clearing of file system signatures
2013-03-25 10:06:39 -06:00
Mike Fleetwood 3c75f3f5b1 Use wipefs to clear old signatures before creating new file systems (#688882)
Previously the function erase_filesystem_signatures() was used to clear
file system signatures when a new partition was created and when an
existing partition was formatted with a file system.  However this was
only available with libparted <= 2.4 and then only for the file systems
which libparted supports.

Having multiple different file system signatures on a partition leads to
misidentification of file system.  For example creating a nilfs2 over
the top of a fat32 file system is detected as a fat32, not nilfs2.  This
shows that old file system signatures must be cleared before a new file
system is created.

Fix by always using "wipefs -a /dev/PARTITION" command to clear all old
file system signatures rather than libparted API calls.  Failure from
wipefs is only considered a warning so doesn't fail the file system
creation.  (This doesn't yet fully meet the "MUST be cleared"
requirement above.  Will be fully met later in this patchset).  Output
from the wipefs command is displayed as a new sub-step which looks like
this:

    v Format /dev/sda7 as xfs                            00:00:05
      > calibrate /dev/sda14                             00:00:01
      v clear old file system signatures in /dev/sda7    00:00:01  [NEW]
        > wipefs -a /dev/sda7                                      [NEW]
      > set partition type on /dev/sda7                  00:00:02
      v create new xfs file system                       00:00:01
        > mkfs.xfs -f -L "" /dev/sda7

Also signatures are only cleared immediately before a new file system is
written and not when an unformatted partition is created.  This allows
recovery from accidental partition deletion by re-creating the deleted
partition as unformatted.

Bug #688882 - Improve clearing of file system signatures
2013-03-25 10:06:39 -06:00
Patrick Verner 9b649ed445 Add f2fs file system support (#695396)
Only supports detection and creation of f2fs file systems.  Requires
f2fs-tools and a blkid with f2fs support, util-linux > 2.22.2.

f2fs-tools v1.1.0 only supports file system creation.
Currently requires util-linux directly from the git repository as f2fs
support was only committed on 5 Feb 2013 and it has not yet been
released.

Closes Bug #695396 - Please apply f2fs patch
2013-03-19 22:13:34 +00: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 4c249b4d65 Fix dialog progress details view size (#602635) (#662722)
The details view refused to use additional space, even after the window was
expanded, instead continuing to use the scrollbars.  Now resizing the
window will be allowed regardless of the state of the details expander, and
the details view will expand to use the extra space.  Also request enough
initial width to not need a horizontal scrollbar.

Closes:
Bug 602635 - list of tasks in apply dialog does not expand to the available
             vertical space

Bug 662722 - Increase default width of "applying..." dialog to include the
             "Details" status icons
2013-03-11 18:40:31 -06:00
Phillip Susi 38dc55d49c Combine duplicate code for ext[234]
There were separate modules for ext3 and ext4 even though there
were virtually no differences with ext2.  Remove the duplicate
modules and patch ext2 to serve as a common reference for all
three sub types.
2013-03-11 18:40:31 -06:00
Phillip Susi 89de9a5026 Add proper cancel support (#601239)
Interested operations can now connect a signal to their OperationDetail
to be notified of a cancelation request.  The internal copy/move code
will now cleanly stop on cancelation, allowing the partition to be
rolled back to its previous state.  This makes canceling a move
perfectly safe.

After clicking cancel, the button changes to "Force Cancel" and is
disabled for 5 seconds.  Operations that are safe to cancel will do so
and those that are not will continue to run.  Clicking force cancel
asks operations to cancel, even if doing so is unsafe.  For the
internal copy/move algorithm, canceling is always safe because an
error results in a rollback operation.  Canceling the rollback is
unsafe.  For external commands, filesystem modules may indicate
that the command is safe to cancel or not.  Canceled commands will
be terminated with SIGINT.

As a result of the new safe cancel vs force cancel distinction, the
scary warning about cancl causing corruption has been moved to
after clicking the force cancel button.

Part of Bug #601239 - Please allow 'Cancel after current operation'
2013-03-11 18:40:31 -06:00
Phillip Susi bd9e16f22f Thread the internal copy algorithm (#685740)
Have the copy code create a background thread to do the actual copying so
that it won't block the main loop.

Part of Bug 685740 - Refactor to use asynchronous command execution
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
Phillip Susi ddd92cf86a Switch Dialog_Progress to use Glib thread instead of pthread (#601239)
Dialog_Progress was using pthread_create() so that it could later
pthread_cancel() the thread.  pthread_cancel() is wildly unsafe and full
of errors.  Changed to use Glib's threads like the rest, and only cancel
between operations.  Because it can take some time to cancel, disable
the cancel button once it has been clicked once.

Bug 601239 - Please allow 'Cancel after current operation'
2013-03-11 18:40:31 -06:00
Phillip Susi 124342e979 Use a full fledged nested main loop while waiting and pulsing progress bars (#685740)
Win_Gparted and Dialog_Progress were looping on Gtk::Main::events_pending()
and iteration() with usleeps in between.  Use a full mainloop instead and
a proper timeout to trigger pulsebar updates instead of usleeps.

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
sinlu bes ecb1f57594 Make the partition label length dependent from the file system (#689318)
fixes Bug #689318 - filesystem type specific support for partition name
                    maximum length
2012-12-30 16:55:03 +00:00
Curtis Gedak de99c530d4 Remove SWRaid method as it is no longer needed (#678379)
Active Linux software RAID devices are detected in the
Proc_Partitions_Info method.  Hence the SWRaid method is no longer
required.

Removal of the SWRaid method fixes the problem with the error message:

  Could not stat device /dev/md/0 - No such file or directory

This fixes the problem because we no longer use "mdadm --examine
--scan" in an attempt to detect Linux software RAID devices.  The
mdadm command was returning device names such as /dev/md/0, which are
incorrect for GParted.

NOTE:  With this change, GParted no longer requires the mdadm command
       to detect Linux software RAID devices.

Closes Bug #678379 - Could not stat device /dev/md/0 - No such file or
                     directory
2012-12-05 09:51:50 -07:00
Matthias Gehre 1f3b11748e Remove GParted_Core::p_filesystem (#683149)
Bug #683149 - Cleanup(?): Remove lp_device and lp_disk from GParted_Core
2012-11-11 11:47:59 +00:00
Matthias Gehre 52af838df2 Remove GParted_Core::fs (#683149)
Bug #683149 - Cleanup(?): Remove lp_device and lp_disk from GParted_Core
2012-11-11 11:47:59 +00:00
Matthias Gehre d2ced08355 Remove GParted_Core::partition_temp (#683149)
Bug #683149 - Cleanup(?): Remove lp_device and lp_disk from GParted_Core
2012-11-11 11:47:59 +00:00
Matthias Gehre a13bed6424 Remove GParted_Core::temp (#683149)
Bug #683149 - Cleanup(?): Remove lp_device and lp_disk from GParted_Core
2012-11-11 11:47:59 +00:00
Matthias Gehre 6a3b17adc0 Remove lp_partition from GParted_Core (#683149)
Bug #683149 - Cleanup(?): Remove lp_device and lp_disk from GParted_Core
2012-11-11 11:47:59 +00:00
Matthias Gehre 500f1bcd9b Remove lp_device and lp_disk from GParted_Core (#683149)
They were used like global variables.  Now they are moved to the
functions that actually use them to make clearer how the data flow is.

Bug #683149 - Cleanup(?): Remove lp_device and lp_disk from GParted_Core
2012-11-11 11:47:59 +00: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 3828019030 Read file system size for mounted ext2/3/4 from superblock (#683255)
A user had a 190 MiB partition containing an old ext2 file system.  When
unmounted it was reported as filling the partition, but when mounted it
was reported as having 6% unallocated space.  The file system's inode
tables were approximately twice the size of those created by default
with the current mkfs.ext2 defaults.

To create an equivalent file system in a 190 MiB partition:
    mkfs.ext2 -N 97344 /dev/sda15

It turns out that for ext2, ext3 and ext4 file systems what was
described as intrinsic unallocated space during the development of
Bug #499202 is actually file system overhead.  When mounted the ext2/3/4
kernel code reports the size of the file system after subtracting the
overhead.  Overhead is made up of superblock backups, group descriptors,
allocation bitmaps and largest of all inode tables.  E2fsprogs tools
don't subtract this overhead when reporting the file system size.

References:

 *  The Second Extended File System, Internal Layout, by Dave Poirier
    http://www.nongnu.org/ext2-doc/ext2.html

 *  Linux ext2_statfs() function
    http://lxr.linux.no/#linux+v3.5.3/fs/ext2/super.c#L1311

Call the file system specific method for reading the usage of ext2, ext3
and ext4 file systems while mounted.  Make it read the file system size
from the on disk superblock to avoid subtraction of overhead and use the
statvfs() system call to return an up to date free space figure.

Bug #683255 - ext2: statvfs differs from dumpe2fs (x MB unallocated
              space within the partition)
2012-10-02 13:19:29 -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 eca986c96d Ignore invalid reiserfs UUIDs (#684115)
On Fedora up to and including Fedora 16 and Red Hat and CentOS up to the
current 6.3 release the UUID of an unmounted reiserfs file system is
displayed as "<no" and a GTK markup warning is written to the terminal.

This was because the reiserfs-utils package isn't linked with libuuid
support so reiserfs file systems were created with a Nil UUID (all
zeros).  To read the UUID GParted first tries to retrieve the UUID from
the blkid command output via the FS_Info cache.  Secondly it tries the
reiserfs file system specific read_uuid() method which uses the first
space separated word following the text "UUID:", hence it gets "<no".

    # debugreiserfs /dev/sda15 2> /dev/null | grep UUID
    UUID: <no libuuid installed>

In September 2012 Red Hat bug 660285 "reiserfstune compiled without UUID
support" was fixed for Fedora 16 and later releases.  On Fedora with
this fix applied GParted will display the Nil UUID (all zeros) for a
previously created reiserfs file system rather than suppressing it.

Only accept valid, none Nil UUIDs in the reiserfs file system specific
read_uuid() method.

Bug #684115 - Reiserfs UUID reading issues on Fedora and CentOS
2012-09-28 16:45:42 -06:00
Mike Fleetwood 60d7728177 Add a partition warning for LVM2 PVs which can't be resized (#670171)
As LVM2 Physical Volumes can't be resized when they are members of
exported Volume Groups add a warning message to explain this fact.
Display the message as a partition specific warning and as additional
text when growing the file system to fill the partition is skipped for
the check operation and when pasting into an existing larger partition.

Bug #670171 - Add LVM PV read-write support
2012-08-30 13:47:46 -06:00
Mike Fleetwood ee49891611 Disallow resizing of LVM2 PVs which are members of exported VGs (#670171)
When an inactive LVM2 Volume Group is exported it makes it unknown to
the local system, ready for moving the member Physical Volumes to
another system, where the VG can be imported and used.  In this state a
PV can't be resized.

    # lvm pvresize /dev/sda10
      Volume group Test-VG1 is exported
      Unable to read volume group "Test-VG1".
      0 physical volume(s) resized / 1 physical volume(s) not resized
    # echo $?
    5

Fix this by preventing resizing of such a PV.  This has been coded in a
generic way using new function filesystem_resize_disallowed() to
determine whether a file system is allowed to be resized or not.  For
a file system which can be resized, but is currently not allowed to be
resized, the behaviour is as follows:

1)  Pasting into unallocated space is limited to creating a new
    partition which is the same size as the copied partition.

2)  Resizing the partition is disallowed, only moving the partition is
    allowed.

3)  Pasting into an existing partition will only copy the file system.
    If the destination partition is larger a warning will report that
    growing the file system is not currently allowed.

4)  Checking a partition will also report a warning that growing the
    file system is not currently allowed.

This is exactly the same behaviour as for a file system which does not
implement resizing, except for a different warning message.

Bug #670171 - Add LVM PV read-write support
2012-08-30 13:47:46 -06:00
Mike Fleetwood 96c9fc129c Implement common LVM2_PV_Info cache search and index functions
Create common cache search and index functions get_attr_by_name() and
get_attr_by_row() as the existing ones, get_pv_attr_by_*() and
get_vg_attr_by_*(), only differ from each other by the string vector
they use.
2012-08-30 13:47:46 -06:00
Mike Fleetwood fdb7e9fe89 Correctly show multiple "unknown device" LVM2 VG members (#670171)
If an LVM2 Volume Group has two or more missing Physical Volumes, the VG
is displayed as only having one "unknown device" because
get_vg_members() only adds unique names to the list of members.

    # lvm pvcreate /dev/sda11 /dev/sda12 /dev/sda13
    # lvm vgcreate Test-VG1 /dev/sda11 /dev/sda12 /dev/sda13
    # wipefs -a /dev/sda12
    # wipefs -a /dev/sda13
    View partition information in GParted

The simplest fix would be to include the PV's UUID in the cache of LVM2
information and add PV names based on unique UUIDs being a member of the
relevant VG.  Unfortunately "lvm pvs" seems to have a bug when
displaying Logical Volume attributes, and there are two or more missing
PVs, which causes one of the PVs to be displayed multiple times, rather
than displaying each PV once.

Without LV attributes, every PV is listed:

    # lvm pvs --nosuffix --separator , --units b -o pv_name,pv_uuid,vg_name,vg_attr 2> /dev/null
      PV,PV UUID,VG,Attr
      /dev/sda11,pJ3R51-AOPP-rKlr-CKCT-nfPS-G5FP-B5Vyjm,Test-VG1,wz-pn-
      unknown device,Y72oSm-uBcE-ktZL-OIFA-Q129-Uv1B-x5IsrA,Test-VG1,wz-pn-
      unknown device,1ESORF-7wlR-0tnO-fy2z-nOL1-MrnJ-2O5yjK,Test-VG1,wz-pn-

With LV attributes, one missing PV is repeated:

    # lvm pvs --nosuffix --separator , --units b -o pv_name,pv_uuid,vg_name,vg_attr,lv_name,lv_attr 2> /dev/null
      PV,PV UUID,VG,Attr,LV,Attr
      /dev/sda11,pJ3R51-AOPP-rKlr-CKCT-nfPS-G5FP-B5Vyjm,Test-VG1,wz-pn-,,
      unknown device,Y72oSm-uBcE-ktZL-OIFA-Q129-Uv1B-x5IsrA,Test-VG1,wz-pn-,,
      unknown device,Y72oSm-uBcE-ktZL-OIFA-Q129-Uv1B-x5IsrA,Test-VG1,wz-pn-,,

Also "lvm vgs" and "lvm lvs" don't display anything when including both
VG and LV attributes.

Instead query the LVM2 information in two separate commands, one
querying PV attributes and one querying VG and LV attributes, saving the
results in lvm_pv_cache and lvm_vg_cache respectively.

Bug #670171 - Add LVM PV read-write support
2012-08-30 13:47:46 -06:00
Mike Fleetwood 5cb6c687ba New LVM2_PV_Info::bit_set() testing VG and LV attribs "bits"
Abstract repeated code used to test the setting of individual LVM Volume
Group and Logical Volume "bits" attributes into bit_set() function.
2012-08-30 13:47:46 -06:00
Mike Fleetwood c90365a6db Update declarations of some LVM2_PV_Info member functions
Add const qualifier to get_pv_attr_by_path() and get_pv_attr_by_row() as
they only access member variables read-only.

Make lvm2_pv_attr_to_num() a static member function as it doesn't access
any member variables.
2012-08-30 13:47:45 -06:00
Mike Fleetwood ca3d40d9c7 Rename *toggle_swap_mount* -> *toggle_busy*
Rename functions and a variable to use a generic term for the menu item
which changes the busy state of partitions now that it also activates
and deactivates LVM2 Physical Volumes as well as mounting and unmounting
file systems and enables and disables swap partitions.
2012-08-30 13:47:45 -06:00
Mike Fleetwood 69c8acce75 Add warning dialog when deleting non-empty LVM2 PVs (#670171)
When attempting to delete a non-empty LVM2 Physical Volume (one which is
still a member of a Volume Group) display a warning dialog which
includes the VG name and a list of the PV members to allow the user to
make an informed choice whether to go ahead and perform the deletion or
cancel to the operation.  This dialog is displayed when a partition
containing a PV is being deleted or being overwritten by being
reformatted or pasted into.

Bug #670171 - Add LVM PV read-write support
2012-08-30 13:47:45 -06:00
Mike Fleetwood 307f489177 Add LVM2 VG member details to the Information dialog (#670171)
For LVM2 Physical Volumes display the Volume Group name and all the
members in the Information dialog.

Bug #670171 - Add LVM PV read-write support
2012-08-30 13:47:45 -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 619bda5d8b Enable LVM2 VG activation / deactivation (#670171)
In the Partition menu enable activation / deactivation of the LVM2
Volume Group of which the Physical Volume is a member.

Bug #670171 - Add LVM PV read-write support
2012-08-30 13:47:45 -06:00
Mike Fleetwood 87625c2b0a Prevent crash from pressing Esc in dialogs with number entry (#682658)
Steps to reproduce:
1) Open any of these dialogs: Create New Partition, Resize/Move or
   Paste;
2) Update any of the following numeric entry fields to a different value
   using the keyboard: Free space preceding, New size or Free space
   following;
3) Press [Esc] key;
Gparted crashes.

What is happening is that the [Esc] key is leading to the dialog being
closed and calling the ~Dialog_Base_Partition() destructor.  However
after this the GTK widget is calling the on_spinbutton_value_change()
registered callbacks for the change to the other two values, on the now
just deleted object.

Fix by disconnecting the change notification callbacks in the
destructor.

Closes bug #682658 - GParted crash by pressing Esc in dialogs with
                     number entry
2012-08-30 13:14:04 -06:00
Mike Fleetwood a6ff181faf Make btrfs_size_*() static member functions
The member functions btrfs_size_to_num(), btrfs_size_max_delta() and
btrfs_size_to_gdouble() don't access any member variables.  Therefore
they don't need the const qualifier allowing them to be called when the
btrfs object is const for read-only access to member variables, but
instead need to be static member functions with no access to member
variables.
2012-07-08 12:12:16 -06:00
Mike Fleetwood 6c96ab34b3 Simplify calc_usage_triple() interface and rename
Now that every call to calc_usage_triple() just passes usage figures
returned by get_sectors_*(), remove those parameters, call
get_sectors_*() internally and rename to get_usage_triple().
2012-06-26 14:13:31 -06:00
Mike Fleetwood ac3ce5ec2b Simplify main window partition usage graphic code
Stop using fraction_unallocated and fraction_used member variables of
the DrawingAreaVisualDisk class as intermediate storage of partition
usage fractions.  Instead get the figures straight from the partition
class and use the new calc_usage_triple() to directly set pixels widths
for the partition usage graphic.
2012-06-26 14:13:31 -06:00
Mike Fleetwood 67f334a8ac Fix minor unallocated space display issue in the Info dialog (#499202)
For specific partition usage values the right hand border of the
partition graphic in the Information dialog would be displayed as grey
rather than the color assigned to the partition.

Steps to reproduce fault:
    Create 1024 MiB partition
    # lvm pvcreate /dev/sda12
    # lvm vgcreate GParted-VG1 /dev/sda12
    View partition information

Fragment from Dialog_Partition_Info::init_drawingarea():
    139  else if ( partition .sector_usage_known() )
    140  {
    141          used        = Utils::round( ( 400 - BORDER *2 ) / ( dlength / partition .get_sectors_used()   ) ) ;
    142          unused      = Utils::round( ( 400 - BORDER *2 ) / ( dlength / partition .get_sectors_unused() ) ) ;
    143          unallocated = 400 - BORDER *2 - used - unused ;
    144  }

For this issue the above values are both exactly x.5 and both round
upwards, resulting in unallocated being -1.
    used        = round((400 - 8*2)/(2097152.0/8192))    = round(1.5)
    unused      = round((400 - 8*2)/(2097152.0/2088960)) = round(382.5)
    unallocated = 400 - 8*2 - 2 - 383 = -1

The simple fix would be to use floor() instead of round() in the
calculation of either used or unused.  The same fix would also need to
be applied in Display_Info() for the calculation of the percentage
figures.  Unfortunately this simple fix can lead to odd figures when the
used or unused is close to zero and floor() or ceil() is effectively
applied rather than round().  For example:
    Size:           227.23 GiB
    Used:           28.00 KiB   ( 1% )
    Unused:         180.00 GiB  ( 79% )
    Unallocated:    47.23 GiB   ( 20% )
Used figure of 28 KiB in 227 GiB partition should be rounded to 0% but
wasn't.

Write Partition::calc_usage_triple() which calculates the "best" figures
by rounding the smaller two figures and subtracts them from the desired
total for the largest figure.  Apply to the calculation of the partition
usage percentage figures in the Information dialog and the partition
usage graphic in the same dialog and the main window.

Bug #499202 - gparted does not see the difference if partition size
              differs from filesystem size
2012-06-26 14:13:31 -06:00
Mike Fleetwood 7ebedc4bb3 Don't show intrinsic unallocated space (#499202)
Most file systems report intrinsic unallocated space using the statvfs()
system call when mounted, but not using their own tools.  They are:
ext2/3/4, fat16/32, hfs, nilfs2, reiserfs and xfs.  Showing either a
little or no unallocated space, depending on whether a file system is
mounted or not, could be confusing to the user.

When all file systems are created filling their partitions the unused
figure reported by statvfs() and their own tools are the same or very
close.  Also the used plus unallocated figure from statvfs() agrees with
the used figure from their own tools.

For all file systems don't display intrinsic unallocated space (that
below the threshold of 2 to 5%), instead include it as used space.  As
soon as the amount of unallocated space becomes significant display it
everywhere and also trigger the warning.

For display purposes always use the new Partition methods:
get_sectors_used(), get_sectors_unused(), and get_sectors_unallocated().
When calculating new usage figures during Paste and Resize/Move
operations directly access sectors_used, sectors_unused and
sectors_unallocated members.

Bug #499202 - gparted does not see the difference if partition size
              differs from filesystem size
2012-06-18 12:41:59 -06:00
Mike Fleetwood 3737224028 Include intrinsic unallocated space for resizing purposes (#499202)
A number of file systems report intrinsic unallocated space even when
they are created filling the partition.  As reported using their own
specific tools, they are: jfs, lvm2 pv and ntfs.  Therefore when
resizing a partition estimate its minimum size to be used sectors plus
any unallocated sectors up to the significant amount.

Bug #499202 - gparted does not see the difference if partition size
              differs from filesystem size
2012-06-18 10:24:29 -06:00
Mike Fleetwood 7fc16a1b69 Handle btrfs tools rounding of figures (#499202)
The btrfs programs only provide approximations of file system sizes
because they display figures using binary prefix multipliers to two
decimal places of precision.  E.g. 2.00GB.  For partition sizes where
the contained file system size rounds upwards, GParted will fail to read
the file system usage and report a warning because the file system will
appear to be larger than the partition.

For example, create a 2047 MiB partition containing a btrfs file system
and display its size.

    # btrfs filesystem show
    Label: none  uuid: 92535375-5e76-4a70-896a-8d796a577993
            Total devices 1 FS bytes used 28.00KB
            devid    1 size 2.00GB used 240.62MB path /dev/sda12

The file system size appears to be 2048 MiB, but that is larger than the
partition, hence the issue GParted has.  (Actually uses the btrfs devid
size which is the size of the btrfs file system within the partition in
question).

This issue is new with the fix for Bug #499202 because it queries the
file system sizes for the first time.  The same issue could
theoretically occur previously, but with the used figure (FS bytes
used).  This would have been virtually impossible to trigger because
btrfs file system would have to have been greater than 99% full, but
btrfs has been notorious for early reporting of file system full.

The fix is that if a btrfs file system size appears larger than the
partition size, but the minimum possible size which could have been
rounded to the reported figure is within the partition size use the
smaller partition size instead.  Apply the method to the used figure
too, in case the file system is 100% full.  Also if the btrfs file
system size appears smaller than the partition size, but the maximum
possible size which could have been rounded to the reported figure is
within the partition size use the larger partition size instead to avoid
reporting, presumably false, unallocated space.  Not applied to file
system used figure.

Bug 499202 - gparted does not see the difference if partition size
             differs from filesystem size
2012-06-18 10:24:29 -06:00
Mike Fleetwood 7ddbc9bd92 Set unallocated space for paste or resize/move operations (#499202)
When pasting a copied partition into free space or move/resizing a
partition set its space utilisation so that any unallocated space within
the partition is displayed correctly before the operation is applied.

NOTE:
If the file system does not support file system resizing the Paste and
Move/Resize dialogs don't allow resizing the partition so the preview
will always be correct, unlike the case in the previous patch:
    Set unallocated space when performing simple operations (#499202)

Also remove the deprecated and no longer used Partition::Set_Unused()
and Partition::set_used() methods.

Bug #499202 - gparted does not see the difference if partition size
              differs from filesystem size
2012-06-18 10:24:29 -06:00
Mike Fleetwood 2b9c6425b5 Display unallocated space in the main window (#499202)
Display the unallocated space within a partition in the main window's
graphical disk representation.

Bug #499202 - gparted does not see the difference if partition size
              differs from filesystem size
2012-06-18 10:24:28 -06:00
Mike Fleetwood e6290dbbcf Query unallocated space for LVM2 PVs (#499202)
Add reporting of the LVM2 Physical Volume size allowing the unallocated
space in the partition to be calculated.

Bug #499202 - gparted does not see the difference if partition size
              differs from filesystem size
2012-06-18 10:24:28 -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
Mike Fleetwood 8ffd68b012 Display unallocated space in the information dialog (#499202)
Display the unallocated space in the graphical partition representation
and numeric figures in the Partition Information dialog.

Bug #499202 - gparted does not see the difference if partition size
              differs from filesystem size
2012-06-18 10:24:28 -06:00
Mike Fleetwood 8093ba2ebd Record unallocated space within a partition (#499202)
Currently GParted assumes that a file system fills its containing
partition.  This is not always true and can occur when resizing is
performed outside of GParted or a resize operation fails.  GParted
doesn't display any information about unallocated space to the user
and in most cases it is simply included in used space.

Add partition unallocated space accounting.  Make GParted record the
unallocated space for mounted file system and display a warning in the
Partition Information dialog when too much unallocated space is found.

Partition::set_sector_usage( fs_size, fs_unused ), is the new preferred
method of recording file system usage because it allows the unallocated
space in a partition to be calculated.  Partition::Set_Unused() and
Partition::set_used() are now deprecated.

NOTES:

1)  Set the minimum unallocated space to be 5% before considering it
    significant to avoid false reporting.  Worst case found was a
    mounted xfs file system in a 100MiB partition, which reports as
    ~4.7% unallocated according to file system size from statvfs().
    However, it reports as having no unallocated space using xfs
    specific tools.

2)  Unallocated space is only a graphical representation for the user.
    GParted must still use relevant tools to resize file systems before
    shrinking the data and can't assume all unallocated space exists
    after the file system at the end of the partition.

Bug #499202 - gparted does not see the difference if partition size
              differs from filesystem size
2012-06-18 10:24:28 -06:00
Curtis Gedak 0fda1d011d Enable new fs resize library available with parted-3.1 (#668281)
The parted-3.1 release brings back FAT16/FAT32 and HFS/HFS+ file
system resize capabilities in a new libparted fs resize library.

The following operations are again available when GParted is linked
with parted-3.1:

   FAT16 - grow and shrink
   FAT32 - grow and shrink
   HFS   - shrink
   HFS+  - shrink

Note that there is a difference in how move actions are handled for
FAT16/FAT32 file systems based on parted version.

When GParted is linked with parted >= 3.0:

   FAT16 - move performed internally by GParted
   FAT32 - move performed internally by GParted

When GParted is linked with parted < 3.0:

   FAT16 - move performed by libparted
   FAT32 - move performed by libparted

Thanks goes to Jim Meyering for restoring these file system resizing
capabilities in Parted 3.1 with a new libparted fs resize library.

Closes Bug #668281 - minimal file-system resize API? (FAT and HFS*
                     only)
2012-03-03 11:55:20 -07:00
Mike Fleetwood ea1c0c023e Warn when an LVM2 PV is a member of a damaged VG (#160878)
Generate a warning for each LVM2 Physical Volume which is a member of a
Volume Group which has other members missing.

Bug #160787 - lvm support
2012-02-12 11:02:55 -07:00
Mike Fleetwood 6d665d669d Display VG export status with an LVM2 PVs busy status (#160787)
Also update to use LVM terminology, such that a Physical Volume is
referred to as a member of a Volume Group.  Status of an LVM2 PV is now
displayed using one of the following messages:
    Not active (Not a member of any volume group)
    VGNAME not active
    VGNAME not active and exported
    VGNAME active

Bug #160787 - lvm support
2012-02-12 10:43:01 -07:00
Mike Fleetwood 3fbdb8055f Prevent crash in the LVM2 PV information cache (#160787)
GParted would crash if there were any embeded spaces in the output from
the command used to query LVM2 PVs.  There aren't normally any embeded
spaces, but they can occur in certain degrated situations.  For example
if one of the PVs in a VG spanning two PVs is lost the PV is displayed
as "unknown device" rather than its actual device name:

    # lvm pvs --nosuffix --units b --separator , -o pv_name,pv_free,vg_name,lv_name,lv_attr
      Couldn't find device with uuid DMEi8r-9Vvy-w0Ok-CSSn-oLmY-YrY3-1PBznz.
      PV,PFree,VG,LV,Attr
      /dev/sda11,2143289344,GParted-VG1,,
      unknown device,1619001344,GParted-VG1,lvol0,-wi---
      unknown device,1619001344,GParted-VG1,,

This was loaded into the cache as:

    ["/dev/sda11,2143289344,GParted-VG1,,",
     "unknown",
     "device,1619001344,GParted-VG1,lvol0,-wi---",
     "unknown",
     "device,1619001344,GParted-VG1,,"]

The crash would happen when trying to access the VG name or LV flags on
a line without enough comma separated fields.

Improve parsing of the output from "lvm pvs" so that lines are not split
on embeded spaces.  Don't crash on lines without without enough comma
separated fields.

Bug #160787 - lvm support
2012-02-12 10:42:40 -07:00
Mike Fleetwood c24170927d Display any errors from querying LVM2 PVs to the user (#160787)
Previously any errors which occurred when running LVM commands used to
load the LVM2_PV_Info cache were simply ignored and the cache wasn't
loaded.  This lead to missing information about LVM2 PVs, but the user
had no indication as to why.

Now when any errors occur the command ran and all output is captured.
This is displayed to the user, along with a suitable warning message, in
the Partition Information dialog.

Bug #160787 - lvm support
2012-02-12 10:24:02 -07:00
Mike Fleetwood 4b30a2ddbf Fix detection of LVM2 PV busy status when exported VGs exist (#160787)
If a Volume Group is exported the "lvm lvs" command returns non-zero
exit status causing its output to not be loaded into the LVM2_PV_Info
cache and detection of busy Physical Volumes completely fail.

    # lvm lvs -o lv_name,vg_name,lv_attr
      Volume group GParted_VG4 is exported
      LV    VG          Attr
      lvol0 GParted-VG2 -wi---
      lvol0 GParted_VG3 -wi-a-
      lvol1 GParted_VG3 -wi-a-
    # echo $?
    5

Switch to using "lvm pvs" to query all cached information using one
command, which doesn't return non-zero when exported VGs exist.

    # lvm pvs --nosuffix --units b -o pv_name,pv_free,vg_name,lv_name,lv_attr
      PV         PFree      VG          LV    Attr
      /dev/sda10 2147483648
      /dev/sda11 2143289344 GParted-VG1
      /dev/sda12 1619001344 GParted-VG2 lvol0 -wi---
      /dev/sda12 1619001344 GParted-VG2
      /dev/sda13  830472192 GParted_VG3 lvol0 -wi-a-
      /dev/sda13  830472192 GParted_VG3 lvol1 -wi-a-
      /dev/sda13  830472192 GParted_VG3
      /dev/sda14 1619001344 GParted_VG4 lvol0 -wi---
      /dev/sda14 1619001344 GParted_VG4
    # echo $?
    0

Bug #160787 - lvm support
2012-02-12 10:24:02 -07:00
Mike Fleetwood 5967966ff7 Create helper functions to check for minimum kernel version
Create function Utils::kernel_version_at_least() to check that the
current Linux kernel is a particular version or higher.

Update nilfs2 to use this function to determine whether the kernel is
new enough to support file system resizing.
2012-02-10 11:20:47 -07:00
Rogier Goossens 4108daf15f Implement changing UUID for NTFS (#667278)
Part 4 of 4 to provide new UUID support for NTFS.

Closes Bug #667278 - Add support for setting UUID
2012-02-10 10:33:13 -07:00
Rogier Goossens 170a79b3a0 Use custom text functions for mount/unmount and swapon/swapoff texts
Part 3 of 4 to provide new UUID support for NTFS.

See Bug #667278 - Add support for setting UUID
2012-02-10 10:33:12 -07:00
Rogier Goossens 8735227dd7 Add support for custom text strings depending on the filesystem
Part 2 of 4 to provide new UUID support for NTFS.

See Bug #667278 - Add support for setting UUID
2012-02-10 10:33:12 -07:00
Rogier Goossens ce9feeda0e Make FileSystem objects in GParted_Core accessible and usable by others
Part 1 of 4 to provide new UUID support for NTFS.

See Bug #667278 - Add support for setting UUID
2012-02-10 10:33:12 -07:00
Curtis Gedak d2d830108b Place file system types in alphabetical order 2012-02-03 16:16:04 -07:00
Mike Fleetwood 820242635a Switch to using lvs to identify active LVM LVs (#160787)
Previously used "dmsetup info" to directly list device-mapper mapping
names in the kernel to identify active Logical Volumes.  However GParted
failed to recognise active LVs if the VGNAME contains any hyphens (-).
This is because LVM encodes hyphens as double hyphens in the mapping
name.

To avoid having to duplicate the LVM hyphen encoding in GParted, switch
to using "lvm lvs" to list LVs.

    # dmsetup info --columns --noheadings --separator , -o name
    GParted_VG1-lvol_00
    GParted--VG2-lvol--00

    # lvm lvs --noheadings --separator , -o lv_name,vg_name,lv_attr
      lvol_00,GParted_VG1,-wi-a-
      lvol-00,GParted-VG2,-wi-a-
      lvol-01,GParted-VG3,-wi---
                             .^.
(-) not active, (a) or any other character considered active.  Reference
lvs(8).

Bug #160787 - lvm support
2012-02-02 10:24:31 -07:00
Mike Fleetwood 8083f11d84 Display LVM2 VGNAME as the PV's mount point (#160787)
As the Mount Point column is being borrowed to display the PV's VGNAME,
also suppress generation of the "Mount on" submenu for LVM2 PVs.

Bug #160787 - lvm support
2012-02-02 10:24:31 -07:00
Mike Fleetwood ff8ad04120 Lazy initialize the cache from querying LVM2 PVs (#160787)
Previously when GParted was started LVM2_PV_Info cache was loaded twice,
executing LVM2 PV querying commands twice.  Firstly when
lvm2_pv::get_filesystem_support() was checking if LVM2 PV support was
available, and secondly when forced by a refresh in
GParted_Core::set_devices().

Implement lazy initialization.  Only load the cache when forced by the
above mentioned refresh or having to return a value when the cache is
not yet loaded.  Do not initialize the cache when just checking if LVM2
PV support is available.

Bug #160787 - lvm support
2012-02-02 10:24:31 -07:00
Mike Fleetwood 608d992e82 Cache results from querying all LVM2 PVs (#160787)
Cache results from querying all LVM2 PVs in one go to minimise the
number of times lvm commands are executed.  Take inspiration from
caching performed by FS_Info and Proc_Partitions_Info.

Bug #160787 - lvm support
2012-02-02 10:24:28 -07:00
Mike Fleetwood abd0dd0426 Report space usage of LVM2 PVs (#160787)
Add minimal support for just reporting the space usage of LVM2 PVs.
Accept libparted / blkid detection of LVM2 PVs first, falling back on
GParted's specific detection code otherwise.  Maintain LVM not supported
warning message.

Bug #160787 - lvm support
2012-02-02 10:17:29 -07:00
Mike Fleetwood 391e5e12f9 Rename FS_LVM2 -> FS_LVM2_PV (#160787)
This is the first step of adding support for just LVM2 Phyiscal Volumes,
a subset of full LVM2 support.

Make it clear that it is only LVM2 PVs being treated like a file system.

Bug #160787 - lvm support
2012-01-31 10:26:51 -07: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
Mike Fleetwood 4ab3fe0ee7 Add helper functions for mounted file system resizing operations
There is a lot of commonality and code repetition for resizing of file
systems which can only be resized while mounted.  Resizing of btrfs, jfs
and xfs all follow the pattern: mkdir, mount, resize, umount and rmdir.
Copying an xfs file system also uses a similar pattern, but for the
source and destination xfs file systems simultaneously.

Add three helper functions to the FileSystem class which implement
common tasks, allowing mounted file system resizing to be implemented
more simply.

Also add a function to the Utils class which checks whether the kernel
supports a file system.  It handles the case of non-loaded modules,
which currently leads to reporting the growing of jfs and xfs as
unsupported.
2012-01-11 12:49:13 -07:00
Phillip Susi a1f843e74a Display pop up dialog on libparted exceptions
We used to just log libparted exceptions without handling them.  This patch
changes the exception handler to display a modal dialog box and return the
chosen action to libparted.
2012-01-08 13:03:20 -07:00
Mike Fleetwood df20b54d00 Add nilfs2 support (#642842)
Requires libparted 2.4 or higher, or blkid from utils-linux 2.20 or
higher for nilfs2 file system detection.

Requires nilfs-utils for nilfs2 file system support.

Closes Bug #642842 - nilfs is not detected
2011-12-16 11:40:46 -07:00
Curtis Gedak b6f1c56fb1 Enhance regexp_label method to handle unicode characters
Prompted by Bug #662537 - Ext4 unicode labels not shown correctly
2011-11-01 13:08:36 -06:00
Curtis Gedak 7cbc125a2e Add detection of exfat file systems (#639760)
Note that util-linux v2.18 or higher is required to detect exfat file
systems.

Part of Bug #639760 - exfat / fat64 support
2011-10-22 11:54:54 -06:00
Curtis Gedak 2bcd5d2954 Cleanup btrfs code
Move btrfs higher up the file system list.
Remove btrfs skip references as btrfs is now supported.
2011-10-22 10:44:29 -06:00
Jérôme Dumesnil 03cdaed946 Improve Merge_Operations method parameters and checks 2011-10-13 11:26:16 -06:00
Jérôme Dumesnil b10349ae37 Merge overlapping operations (#438573)
When a new operation is added to operations list, check if a merge
is possible depending on the operation type:

    OPERATION_RESIZE_MOVE:  2 consecutive "resize" operations on the
                            same  partition
OPERATION_LABEL_PARTITION:  2 "label change" operations (need not be
                            consecutive) on the same partition
          OPERATION_CHECK:  2 "check" operations (need not be
                            consecutive) on the same partition
         OPERATION_FORMAT:  2 consecutive "format" operations on the
                            same partition

Closes Bug #438573 - Cancel out overlapping actions

Also fix a bug when copying partition using the Partition::Set(...)
method.  This method did not initialize "sectors_used" and
"sectors_unused" members.
2011-10-05 15:08:44 -06:00
Curtis Gedak 55b71a77bc Fix unused parameter compiler warning
Removed unused parameter.  Prior to this change the compiler would
complain with the following message:

error: unused parameter ‘cylinder_size’
2011-07-18 13:31:54 -06:00
Markus Elfring 91b971691d Bug #634090: Change some attributes to local variables
Some classes contained private attributes which were used only by a single
member function. Such items were moved to the corresponding function implementations
to stress their limited usage scope.

A few unused variables were also deleted.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
2011-07-18 13:28:49 -06:00
Curtis Gedak 8a58b5b53e Enable compile and link with libparted 3.0 (#651559)
The release of (lib)parted 3.0 includes a change to the Application
Programing Interface - API.  Most importantly, libparted 3.0 removes
many file system specific function calls, and hence the capabilities
provided by these functions.  In order for GParted to compile and link
with libparted 3.0, this libparted functionality is lost.

Specifically, the functionality that is lost when GParted is compiled
and linked with libparted 3.0 is as follows:

  - Loss of ability to grow and shrink FAT16 and FAT32 file systems
  - Loss of ability to shrink HFS and HFS+ file systems
  - Loss of ability to determine used and unused sectors in HFS and
      HFS+ file systems
  - Loss of ability to erase file system signatures on partition
      create and format

It is hoped that other free software projects will include some or all
of the above lost functionality, which can then be added back to
GParted.

This commit includes a change in how FAT16 and FAT32 file systems are
moved.  Specifically the move is now performed internally by GParted
when linked with libparted 3.0.  The move functionality is provided by
libparted for prior libparted versions (e.g. less than 3.0).

This is the final enhancement in a series of commits that enable
GParted to compile with libparted version 3.0.

Closes Bug #651559 - Doesn't compile against parted 3.0
2011-06-09 09:59:41 -06:00
Curtis Gedak 87acba030c Remove all usage of kpartx to avoid partition entry duplicates
Usage of the kpartx package to create partition names has been
completely removed.  Hence kpartx is no longer even an optionally used
package by gparted.

This change is related to the following bug report:

Ubuntu launchpad bug 719129 - [Natty] Gparted duplicates dmraid
                              partition devices
https://bugs.launchpad.net/ubuntu/+source/gparted/+bug/719129
2011-02-22 14:40:02 -07:00
Joan Lledó ef37bdb7de Added support to lost data recovery using gpart 2011-01-29 14:58:02 -07:00
Curtis Gedak 128b1439a1 Add methods to FS_Info class to get path by uuid and by label 2010-12-09 14:06:38 -07:00
Curtis Gedak fd77e73c46 Refactor device parsing logic into Proc_Partitions_Info class
The reason for refactoring is to simplify the large GParted_Core
class, to help minimize disk reads, and to group the logic for
processing the file /proc/partitions into a single logical class.
2010-12-07 16:01:54 -07:00
Curtis Gedak 319255d3bc Refactor alternate_paths logic into new Proc_Partitions_Info class
This reason for refactoring is to simplify the large GParted_Core
class, to help minimize disk reads, and to group the logic for
processing the file /proc/partitions into a single logical class.
2010-12-07 11:49:50 -07:00
Curtis Gedak ca30f986f7 Add virtual move method to FileSystem class
This is preparation work for the following bug report:
Bug #589555 - Moving a swap partition needlessly copies
              all "data" on it
2010-10-19 13:35:53 -06:00
Curtis Gedak b0e36132b0 Make btrfs support a normal part of gparted
Remove need to configure with the --enable-btrfs option in order
to include btrfs support in gparted.
2010-10-18 15:28:40 -06:00
Luca Bruno 66a3a71842 Initial Btrfs-handling modules
This adds initial handlers for Btrfs; only .create, .check and
.read_label are done for now, via external btrfs-tools.
Other methods are still only stubs.
2010-10-03 17:00:53 +02:00
Curtis Gedak cf68fc0704 Enable to work with new dmraid and parted without dmraid support
Newer versions (dmraid-1.0.0-rc16?) of dmraid default to always
creating partition names by inserting the letter 'p' between the
device name and the partition number.  Since this is not
consistent with older versions of dmraid, add extra logic to
ensure that newer versions of dmraid do not insert this extra
letter 'p'.

Rename method get_udev_name to get_udev_dm_name and enhance to
retrieve the property DM_NAME.

Handle situation where parted, and hence libparted, has been
configured with --disable-device-mapper.  In this situation on
some distros the device name could be /dev/dm-0.  This results in
invalid partition names such as /dev/dm-0p1.  Add logic to decode
the actual /dev/mapper name.
2010-08-25 10:33:02 -06:00
Curtis Gedak 73e7f85a2f Create new method make_path_dmraid_compatible
This method will be used to ensure that the partition path
matches the name that would be created by the dmraid command.
2010-08-17 10:36:00 -06:00
Curtis Gedak 9bd8b14871 Create new method get_partition_path
This method will be used as an entry point to the libparted
function ped_partition_get_path
2010-08-17 10:36:00 -06:00
Curtis Gedak f7cb37831a Add new method active_partitions_on_device_count 2010-08-10 13:01:40 -06:00
Curtis Gedak d5064dfe03 Move method to match header file
Also update copyright year
2010-08-10 13:01:40 -06:00
Curtis Gedak 44698448aa Add new method partition_in_operation_queue_count 2010-08-09 13:33:28 -06:00
Curtis Gedak 95c9577d8f Limit graphic movement according to required boot record space
Also respect minimum size for extended partition in graphical
representation.

This change is part of adding the option to align to MiB (#617409).
2010-05-25 16:26:08 -06:00
Curtis Gedak e62a23b5b5 Add partition alignment option to align to MiB (#617409)
Make align to MiB the default setting instead of align to cylinder.

Migrate logic for alignment to cylinder into its own method
snap_to_cylinder, and place common logic in snap_to_alignment.

Add alignment checks for situations where space is needed for Master
Boot Record or Extended Boot Record.

Adjust ranges on spin buttons according to required boot record space.

Copy fix for off by one sector (#596552) from
Dialog_Partition_New::Get_New_Partition to
Dialog_Base_Partition::Get_New_Partition

Enhance resize / move logic for checking locations of nearby logical
partitions to not depend on the partition ordering.

Note: This commit does not include limiting graphic movement according
to required boot record space.
2010-05-20 10:00:14 -06:00
Curtis Gedak 2cdfb4c55a Change partition alignment check box to a drop down menu
Also add signal handler to alignment menu to update file system
minimum size.
This enhancement is to prepare for adding a third alignment
option to align to MiB.
2010-05-09 14:45:26 -06:00
Curtis Gedak 7e2ca14756 Rename get_length method to get_sector_length
This rename is to try to reduce future confusion between
partition length in sectors versus partition length in bytes.
2010-04-28 09:11:44 -06:00
Curtis Gedak fe9ee68385 Create get_byte_length method 2010-04-27 11:28:36 -06:00
Curtis Gedak cb08e8c7dd Remove 512 byte based units and rename _FACTOR to BYTE
With the removal of the 512 byte constants, such as MEBIBYTE, it
was possible to rename the _FACTOR constants back to BYTE
constants.  The _FACTOR constants, such as MEBI_FACTOR, were a
temporary measure to help in the transition to support devices
with sector sizes > 512 bytes.
2010-04-26 13:40:38 -06:00
Curtis Gedak f46fbedd34 Remove default sector size
The DEFAULT_SECTOR_SIZE was a temporary measure to help in the
transition to support devices with sector sizes > 512 bytes.  It
is no longer needed.
2010-04-26 13:04:39 -06:00
Curtis Gedak 896dab7192 Enhance copy_filesystem method to work with sector sizes
This change is in preparation for supporting sectors sizes > 512 bytes.
2010-04-26 11:43:59 -06:00
Curtis Gedak 74ecd2ed3f Set sector size and add to operation and dialog methods
This change is in preparation for supporting sectors sizes > 512 bytes.
2010-04-19 19:22:31 -06:00
Curtis Gedak 4bcd0a3704 Add device sector size to partition object
The device sector size is needed in all calculations that convert
between sectors and bytes.  The device sector_size is included in
the partition object because this object is used to contain
operation information in addition to actual partitions and
unallocated space.  A second option was considered to pass the
device object to many methods, but this was considered a much
larger task that might not provide significant gains in
maintainability.
2010-04-19 19:06:08 -06:00
Curtis Gedak 8fb40d843d Enhance copy methods for sector sizes > 512 bytes 2010-04-07 11:39:42 -06:00
Curtis Gedak 44e5176ee5 Enhance format_size() for sector sizes > 512 bytes 2010-03-24 14:37:08 -06:00
Curtis Gedak 1aa81bba94 Enhance sector_to_unit() for sector sizes > 512 bytes 2010-03-24 14:37:08 -06:00
Curtis Gedak f9f603256e Convert file system maximum from sector to byte value 2010-03-24 14:37:08 -06:00
Curtis Gedak 40d7dbac4b Convert file system minimum from sector to byte value 2010-03-24 14:37:08 -06:00
Curtis Gedak 4d658a10a8 Add constants to aid in transition to support sector sizes > 512 bytes 2010-03-24 14:37:08 -06:00
Curtis Gedak 70584176de Disable extended option for non-MSDOS and non-DVH disk types (#583906)
According to parted documentation, only "msdos" and "dvh" disk
types (or partition table types) support extended partitions.
All other disk types support primary partitions only.
2010-02-24 11:39:42 -07:00
Curtis Gedak 19d8f0dfc8 Add sector size to device display pane
Also add sector_size to Device class.  This is the start of an
enhancement to add support for devices with sector sizes other
than 512 bytes (#607165).
2010-02-20 15:12:26 -07:00
Curtis Gedak 20f5c6f83b Clean up code for old bug #157871
Remove commented code and boolean use-C-lang parameter for
Utils::num_to_str() method because this bug was fixed in
gcc-4.0.3.  The GNU gcc compiler versions 4 and up are now
commonly in use.  Also due to previous partial commenting and
removal of the code, the code was non-functional

Thanks goes to Jan Claeys for pointing out this clean up
opportunity.
2010-01-02 15:04:30 -07:00
Curtis Gedak 8cfb27b718 Cleanup file copyright entries
Restore copyright entries by original author to those of his last
known repository commit titled "released gparted-0.3.4 on
LarryT's request." on Feb 25, 2007.

Add my own copyright entries for files in which I changed source
code.  Files in which I only made spelling changes do not have my
copyright entry added.
2009-11-05 11:08:49 -07:00
Curtis Gedak 1607d13a06 Added auto detection of Linux software RAID devices
Auto detection of Linux software RAID devices was lost in GParted
0.3.8.  This was because device scanning by the libparted device
call ped_device_probe_all() was replaced with custom code within
GParted to scan /proc/partitions for devices.

The reason the libparted call was replaced was due to a long
scanning problem with ped_device_probe_all(), a non-existent
physical floppy device, and a BIOS setting indicating a floppy
drive existed.  See bug #351753:
https://bugzilla.gnome.org/show_bug.cgi?id=351753
2009-11-03 13:30:44 -07:00
Curtis Gedak c2d19a8ab4 Replace gnome-open with gtk_show_uri (#600046)
This change was performed to align with a GNOME goal:
http://live.gnome.org/GnomeGoals/RemoveGnomeOpenGnomeHelp

For backwards compatibility, the gnome-open command is used
when gtkmm < 2.14.0.
2009-11-03 10:27:35 -07:00
Curtis Gedak 0723c82f30 Update copyright year for Win_GParted class 2009-10-24 15:17:13 -06:00
Curtis Gedak 73471032c9 Improve feedback when creating or pasting partition (#579266)
Improve the feedback to the user when creating or pasting a
partition on a device with no partition table found.

Prior to this enhancement if a user tried to create or paste a
partition onto a device with no partition table found, GParted
would present the user with a Create Partition Table dialog.

When creating a new partition this could cause confusion for
users who were trying to format the disk.  The user could
mistakenly believe the choice of an MS-DOS file system was being
presented.

Similarly on a paste operation it could be confusing to be
presented with a dialog to create a partition table without any
explanation of why a partition table was suddenly required in the
midst of the paste operation.

Neither the new partition creation, nor the partition paste
actions were performed after the Create Partition Table dialog
was displayed.
2009-10-24 14:16:40 -06:00
Curtis Gedak 0af42af3d0 Add padding to progress dialog window 2009-10-22 10:19:47 -06:00
Curtis Gedak 301bd77312 Refactor some logic into separate settle_device method 2009-05-02 10:59:49 -06:00
Curtis Gedak 2a89d936d6 Remove get_dmraid_prefix method used to specify a single device
It appears that different dmraid versions handle specifying a
single dmraid device differently.

dmraid-1.0.0.rc14 uses a partial name only,
  such as "isw" or "isw_cjbdddajhi".
dmriad-1.0.0.rc15 uses a full name only,
  such as "isw_cjbdddajhi_Vol0".

To maintain compatibility with the broadest range of dmraid versions,
the ability to specify a single dmraid device is being removed.
2009-04-29 16:34:30 -06:00
Curtis Gedak 9816f5c18a Refactor some logic into separate get_udev_name method 2009-04-28 13:42:47 -06:00
Curtis Gedak ce4de8b51e Improve dmraid device detection with checking udev if needed
Some distros appear to display /dev/dm-# device names with
libparted.  Since this fails a pattern match with the dmraid
device name, check with udev to see if a pattern match is
possible with the name returned from udevinfo or udevadm info.

For example:
     /dev/mapper/isw_cjbdddajhi_Vol0 is the device name
     /dev/dm-0 is a symbolic link pointing to the above device name
2009-04-26 16:45:53 -06:00
Curtis Gedak 5112e41815 Update copyright year for FS_Info class 2009-04-26 15:49:30 -06:00
Curtis Gedak 47f0d6bd5d Enhance UUID detection to fallback to vol_id if available
Normally, the blkid command will detect the UUID for a file system.
In cases where blkid fails to detect the UUID and the vol_id command
is available, then try using the vol_id command.
2009-04-24 17:46:05 -06:00
Curtis Gedak 8d024d86df Improve initialization logic for FS_Info class
Ensure that fs_info_cache is populated in any first instantiation in
a program, even for an instantiation such as:
    FS_Info A(false);
2009-04-24 17:18:36 -06:00
Curtis Gedak 946b462757 Enhanced dmraid partition deletion
svn path=/trunk/; revision=1098
2009-03-16 22:59:50 +00:00
Curtis Gedak eda5bf16aa Improved swap and dmraid mountpoint detection
svn path=/trunk/; revision=1097
2009-03-16 22:55:24 +00:00
Curtis Gedak 5865c92dc0 Added new class for dmraid support
svn path=/trunk/; revision=1092
2009-03-14 20:02:41 +00:00