2009-11-05 11:08:32 -07:00
|
|
|
/* Copyright (C) 2004 Bart
|
2012-03-03 11:47:39 -07:00
|
|
|
* Copyright (C) 2008, 2009, 2010, 2011, 2012 Curtis Gedak
|
2004-10-06 09:32:40 -06:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-01-23 03:59:48 -07:00
|
|
|
* GNU General Public License for more details.
|
2004-10-06 09:32:40 -06:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2014-01-23 03:59:48 -07:00
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
2004-10-06 09:32:40 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* UTILS
|
|
|
|
* Some stuff i need in a lot of places so i dropped in all together in one file.
|
|
|
|
*/
|
|
|
|
|
2013-05-27 05:20:16 -06:00
|
|
|
#ifndef GPARTED_UTILS_H
|
|
|
|
#define GPARTED_UTILS_H
|
2004-10-06 09:32:40 -06:00
|
|
|
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "i18n.h"
|
2005-12-07 04:21:27 -07:00
|
|
|
|
2004-10-06 09:32:40 -06:00
|
|
|
#include <gtkmm/label.h>
|
2019-03-27 07:07:39 -06:00
|
|
|
#include <gtkmm/image.h>
|
|
|
|
#include <gdkmm/pixbuf.h>
|
2004-10-06 09:32:40 -06:00
|
|
|
#include <glibmm/ustring.h>
|
2018-12-04 09:46:27 -07:00
|
|
|
#include <glibmm/spawn.h>
|
2005-12-13 14:30:13 -07:00
|
|
|
#include <iostream>
|
2008-04-07 09:26:19 -06:00
|
|
|
#include <ctime>
|
2009-03-12 13:37:12 -06:00
|
|
|
#include <vector>
|
2004-10-06 09:32:40 -06:00
|
|
|
|
2012-01-22 13:49:52 -07:00
|
|
|
#define UUID_STRING_LENGTH 36
|
2012-09-15 14:39:14 -06:00
|
|
|
//Match RFC 4122 UUID strings. Exclude Nil UUID (all zeros) by excluding
|
|
|
|
// zero from the version field nibble.
|
|
|
|
#define RFC4122_NONE_NIL_UUID_REGEXP "[[:xdigit:]]{8}-[[:xdigit:]]{4}-[1-9a-fA-F][[:xdigit:]]{3}-[[:xdigit:]]{4}-[[:xdigit:]]{12}"
|
2012-01-22 13:49:52 -07:00
|
|
|
|
2004-10-06 09:32:40 -06:00
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
|
|
|
typedef long long Sector;
|
2010-03-16 10:18:04 -06:00
|
|
|
typedef long long Byte_Value;
|
2004-10-06 09:32:40 -06:00
|
|
|
|
2010-03-16 10:18:04 -06:00
|
|
|
//Size units defined in bytes
|
2010-04-26 13:40:38 -06:00
|
|
|
const Byte_Value KIBIBYTE=1024;
|
|
|
|
const Byte_Value MEBIBYTE=(KIBIBYTE * KIBIBYTE);
|
|
|
|
const Byte_Value GIBIBYTE=(MEBIBYTE * KIBIBYTE);
|
|
|
|
const Byte_Value TEBIBYTE=(GIBIBYTE * KIBIBYTE);
|
2013-08-14 01:21:58 -06:00
|
|
|
const Byte_Value PEBIBYTE=(TEBIBYTE * KIBIBYTE);
|
2013-08-27 08:29:26 -06:00
|
|
|
const Byte_Value EXBIBYTE=(PEBIBYTE * KIBIBYTE);
|
2010-03-16 10:18:04 -06:00
|
|
|
|
2012-01-30 11:33:33 -07:00
|
|
|
const Glib::ustring UUID_RANDOM = _("(New UUID - will be randomly generated)") ;
|
|
|
|
const Glib::ustring UUID_RANDOM_NTFS_HALF = _("(Half new UUID - will be randomly generated)") ;
|
|
|
|
|
2016-01-03 01:42:49 -07:00
|
|
|
extern const Glib::ustring DEV_MAPPER_PATH;
|
|
|
|
|
2018-01-02 10:44:01 -07:00
|
|
|
enum FSType
|
2005-12-07 04:21:27 -07:00
|
|
|
{
|
2014-10-09 13:18:22 -06:00
|
|
|
// Special partition types and functions
|
2018-09-10 11:13:15 -06:00
|
|
|
FS_UNSUPPORTED = 0, // Type with no supported actions
|
|
|
|
FS_UNALLOCATED = 1, // Unallocated space on a partitioned drive
|
|
|
|
FS_UNKNOWN = 2, // Unrecognised content in a drive or partition
|
|
|
|
FS_UNFORMATTED = 3, // Create a partition without a file system
|
|
|
|
FS_CLEARED = 4, // Clear existing file system signatures
|
2018-09-07 10:34:01 -06:00
|
|
|
FS_OTHER = 5, // Just for showing in the File System Support dialog
|
|
|
|
FS_EXTENDED = 6,
|
2012-12-08 12:41:00 -07:00
|
|
|
|
2018-09-10 12:23:17 -06:00
|
|
|
// Fully supported file system types
|
2018-09-07 10:34:01 -06:00
|
|
|
FS_BTRFS = 7,
|
|
|
|
FS_EXFAT = 8, /* Also known as fat64 */
|
|
|
|
FS_EXT2 = 9,
|
|
|
|
FS_EXT3 = 10,
|
|
|
|
FS_EXT4 = 11,
|
|
|
|
FS_F2FS = 12,
|
|
|
|
FS_FAT16 = 13,
|
|
|
|
FS_FAT32 = 14,
|
|
|
|
FS_HFS = 15,
|
|
|
|
FS_HFSPLUS = 16,
|
|
|
|
FS_JFS = 17,
|
|
|
|
FS_LINUX_SWAP = 18,
|
|
|
|
FS_LUKS = 19,
|
|
|
|
FS_LVM2_PV = 20,
|
|
|
|
FS_MINIX = 21,
|
|
|
|
FS_NILFS2 = 22,
|
|
|
|
FS_NTFS = 23,
|
|
|
|
FS_REISER4 = 24,
|
|
|
|
FS_REISERFS = 25,
|
|
|
|
FS_UDF = 26,
|
2018-09-07 09:41:29 -06:00
|
|
|
FS_XFS = 27,
|
2012-12-08 12:41:00 -07:00
|
|
|
|
2018-09-10 12:23:17 -06:00
|
|
|
// Other recognised file system types
|
2018-11-07 13:05:38 -07:00
|
|
|
FS_APFS = 28,
|
Recognise ATARAID members (#75)
PATCHSET OVERVIEW
A user had a Firmware / BIOS / ATARAID array of 2 devices configured as
a RAID 0 (stripe) set. On top of that was a GPT with the OS partitions.
GParted displays the following errors on initial load and subsequent
refresh:
Libparted Error
(-) Invalid argument during seek for read on /dev/sda
[ Retry ] [ Cancel ] [ Ignore ]
Libparted Error
(-) The backup GPT table is corrupt, but the
primary appears OK, so that will be used.
[ Ok ] [ Cancel ]
This is an Intel Software RAID array which stores metadata at the end of
each member device, and so the first 128 KiB stripe of the set is stored
in the first 128 KiB of the first member device /dev/sda which includes
the GPT for the whole RAID 0 device. Hence when libparted reads member
device /dev/sda it finds a GPT describing a block device twice it's
size and in results the above errors when trying to read the backup GPT.
A more dangerous scenario occurs when using 2 devices configured in an
Intel Software RAID 1 (mirrored) set with GPT on top. On refresh
GParted display this error for both members, /dev/sda and /dev/sdb:
Libparted Warning
/!\ Not all of the space available to /dev/sda appears to be used,
you can fix the GPT to use all of the space (an extra 9554
blocks) or continue with the current setting?
[ Fix ] [ Ignore ]
Selecting [Fix] gets libparted to re-write the backup GPT to the end of
the member device, overwriting the ISW metadata! Do that twice and both
copies of the metadata are gone!
Worked example of this more dangerous mirrored set case. Initial setup:
# dmraid -s
*** Group superset isw_caffbiaegi
--> Subset
name : isw_caffbiaegi_MyMirror
size : 16768000
stride : 128
type : mirror
status : ok
subsets: 0
devs : 2
spares : 0
# dmraid -r
/dev/sda: isw, "isw_caffbiaegi", GROUP, ok, 16777214 sectors, data@ 0
/dev/sdb: isw, "isw_caffbiaegi", GROUP, ok, 16777214 sectors, data@ 0
# wipefs /dev/sda
offset type
---------------------------------------------
0x200 gpt [partition table]
0x1fffffc00 isw_raid_member [raid]
Run GParted and click [Fix] on /dev/sda. Now the first member has gone:
# dmraid -s
*** Group superset isw_caffbiaegi
--> *Inconsistent* Subset
name : isw_caffbiaegi_MyMirror
size : 16768000
stride : 128
type : mirror
status : inconsistent
subsets: 0
devs : 1
spares : 0
# dmraid -r
/dev/sdb: isw, "isw_caffbiaegi", GROUP, ok, 16777214 sectors, data@ 0
# wipefs /dev/sda
offset type
---------------------------------------------
0x200 gpt [partition table]
Click [Fix] on /dev/sdb. Now all members of the array are gone:
# dmraid -s
no raid disks
# dmraid -r
no raid disks
# wipefs /dev/sdb
offset type
---------------------------------------------
0x200 gpt [partition table]
So GParted must not run libparted partition table scanning on the member
devices in ATARAID arrays. Only on the array device itself.
In terms of the UI GParted must show disks which are ATARAID members as
whole disk devices with ATARAID member content and detect array busy
status to avoid allowing active members from being overwritten while in
use.
THIS COMMIT
Recognise ATARAID member devices and display in GParted as whole device
"ataraid" file systems. Because they are recognised as whole device
content ("ataraid" file systems) this alone stops GParted running the
libparted partition table scanning and avoids the above errors.
The list of dmraid supported formats is matched by the signatures
recognised by blkid:
$ dmraid -l
asr : Adaptec HostRAID ASR (0,1,10)
ddf1 : SNIA DDF1 (0,1,4,5,linear)
hpt37x : Highpoint HPT37X (S,0,1,10,01)
hpt45x : Highpoint HPT45X (S,0,1,10)
isw : Intel Software RAID (0,1,5,01)
jmicron : JMicron ATARAID (S,0,1)
lsi : LSI Logic MegaRAID (0,1,10)
nvidia : NVidia RAID (S,0,1,10,5)
pdc : Promise FastTrack (S,0,1,10)
sil : Silicon Image(tm) Medley(tm) (0,1,10)
via : VIA Software RAID (S,0,1,10)
dos : DOS partitions on SW RAIDs
$ fgrep -h _raid_member util-linux/libblkid/src/superblocks/*.c
.name = "adaptec_raid_member",
.name = "ddf_raid_member",
.name = "hpt45x_raid_member",
.name = "hpt37x_raid_member",
.name = "isw_raid_member",
.name = "jmicron_raid_member",
.name = "linux_raid_member",
.name = "lsi_mega_raid_member",
.name = "nvidia_raid_member",
.name = "promise_fasttrack_raid_member",
.name = "silicon_medley_raid_member",
.name = "via_raid_member",
As they are all types of Firmware / BIOS / ATARAID arrays, report all
members as a single "ataraid" file system type. (Except for
"linux_raid_member" in the above blkid source listing which is Linux
Software RAID).
Closes #75 - Errors with GPT on RAID 0 ATARAID array
2019-11-02 11:07:12 -06:00
|
|
|
FS_ATARAID = 29,
|
2022-01-04 15:40:40 -07:00
|
|
|
FS_BCACHE = 30,
|
|
|
|
FS_BITLOCKER = 31,
|
|
|
|
FS_GRUB2_CORE_IMG = 32,
|
|
|
|
FS_ISO9660 = 33,
|
2022-01-24 15:11:39 -07:00
|
|
|
FS_JBD = 34,
|
|
|
|
FS_LINUX_SWRAID = 35,
|
|
|
|
FS_LINUX_SWSUSPEND = 36,
|
|
|
|
FS_REFS = 37,
|
|
|
|
FS_UFS = 38,
|
|
|
|
FS_ZFS = 39,
|
2012-12-08 12:41:00 -07:00
|
|
|
|
2014-10-09 13:18:22 -06:00
|
|
|
// Partition space usage colours
|
2022-01-24 15:11:39 -07:00
|
|
|
FS_USED = 40,
|
|
|
|
FS_UNUSED = 41
|
2006-03-31 03:49:27 -07:00
|
|
|
} ;
|
2004-10-06 09:32:40 -06:00
|
|
|
|
2006-01-21 17:07:27 -07:00
|
|
|
enum SIZE_UNIT
|
|
|
|
{
|
|
|
|
UNIT_SECTOR = 0,
|
|
|
|
UNIT_BYTE = 1,
|
|
|
|
|
|
|
|
UNIT_KIB = 2,
|
|
|
|
UNIT_MIB = 3,
|
|
|
|
UNIT_GIB = 4,
|
2006-03-31 03:49:27 -07:00
|
|
|
UNIT_TIB = 5
|
|
|
|
} ;
|
2006-01-21 17:07:27 -07:00
|
|
|
|
2005-12-13 14:30:13 -07:00
|
|
|
class Utils
|
2004-10-06 09:32:40 -06:00
|
|
|
{
|
2005-12-13 14:30:13 -07:00
|
|
|
public:
|
2006-03-28 05:40:29 -07:00
|
|
|
static Sector round( double double_value ) ;
|
2014-04-26 14:06:18 -06:00
|
|
|
static Gtk::Label * mk_label( const Glib::ustring & text
|
|
|
|
, bool use_markup = true
|
|
|
|
, bool wrap = false
|
|
|
|
, bool selectable = false
|
2019-05-03 07:42:45 -06:00
|
|
|
, Gtk::Align valign = Gtk::ALIGN_CENTER
|
2014-04-26 14:06:18 -06:00
|
|
|
) ;
|
2019-03-27 07:07:39 -06:00
|
|
|
static Gtk::Image* mk_image(const Gtk::StockID& stock_id, Gtk::IconSize icon_size);
|
|
|
|
static Glib::RefPtr<Gdk::Pixbuf> mk_pixbuf(Gtk::Widget& widget,
|
|
|
|
const Gtk::StockID& stock_id,
|
|
|
|
Gtk::IconSize icon_size);
|
|
|
|
static Glib::ustring get_stock_label(const Gtk::StockID& stock_id);
|
2010-01-02 15:04:30 -07:00
|
|
|
static Glib::ustring num_to_str( Sector number ) ;
|
2019-06-13 03:41:34 -06:00
|
|
|
static Glib::ustring get_color(FSType fstype);
|
|
|
|
static Glib::RefPtr<Gdk::Pixbuf> get_color_as_pixbuf(FSType fstype, int width, int height);
|
2015-03-13 16:36:08 -06:00
|
|
|
static int get_max_partition_name_length( Glib::ustring & tabletype );
|
2019-06-13 03:41:34 -06:00
|
|
|
static int get_filesystem_label_maxlength(FSType fstype);
|
2021-04-03 08:12:08 -06:00
|
|
|
static const Glib::ustring get_filesystem_string(FSType fstype);
|
2016-09-16 05:53:20 -06:00
|
|
|
static const Glib::ustring get_encrypted_string();
|
2018-01-02 10:44:01 -07:00
|
|
|
static const Glib::ustring get_filesystem_string( bool encrypted, FSType fstype );
|
|
|
|
static const Glib::ustring get_filesystem_kernel_name( FSType fstype );
|
2021-04-03 08:12:08 -06:00
|
|
|
static const Glib::ustring get_filesystem_software(FSType fstype);
|
2021-04-03 08:01:24 -06:00
|
|
|
static const Glib::ustring generate_encryption_mapping_name(const Glib::ustring& path);
|
2011-12-27 04:05:11 -07:00
|
|
|
static bool kernel_supports_fs( const Glib::ustring & fs ) ;
|
2012-02-05 02:06:44 -07:00
|
|
|
static bool kernel_version_at_least( int major_ver, int minor_ver, int patch_ver ) ;
|
2010-03-23 13:06:26 -06:00
|
|
|
static Glib::ustring format_size( Sector sectors, Byte_Value sector_size ) ;
|
2006-08-22 13:29:59 -06:00
|
|
|
static Glib::ustring format_time( std::time_t seconds ) ;
|
2010-03-23 12:14:53 -06:00
|
|
|
static double sector_to_unit( Sector sectors, Byte_Value sector_size, SIZE_UNIT size_unit ) ;
|
2006-04-02 07:04:24 -06:00
|
|
|
static int execute_command( const Glib::ustring & command ) ;
|
2006-02-15 09:05:26 -07:00
|
|
|
static int execute_command( const Glib::ustring & command,
|
|
|
|
Glib::ustring & output,
|
|
|
|
Glib::ustring & error,
|
|
|
|
bool use_C_locale = false ) ;
|
2017-10-20 12:47:00 -06:00
|
|
|
static int execute_command( const Glib::ustring & command,
|
|
|
|
const char * input,
|
|
|
|
Glib::ustring & output,
|
|
|
|
Glib::ustring & error,
|
|
|
|
bool use_C_locale = false );
|
Implement shell style exit status decoding (#754684)
Command exit status is a 1 byte value between 0 and 255. [1][2] However
at the Unix API level the value is encoded as documented in the
waitpid(2) manual page. This is true for the Glib API too. [3] This is
why, for example, the comment in ext2::check_repair() reported receiving
undocumented exit status 256. It was actually receiving exit status 1
encoded as per the waitpid(2) method.
Add shell style exit status decoding [2] to execution of all external
commands. Return value from Utils::execute_command() and
FileSystem::execute_command() functions are now:
0 - 125 - Exit status from the command
126 - Error executing the command
127 - Command not found
128+N - Command terminated by signal N
255 - Unexpected waitpid(2) condition
Also adjust checking of the returned statuses as necessary.
[1] Advanced Bash-Scripting Guide: Appendix D. Exit Codes With Special
Meanings
http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/exitcodes.html
[2] Quote from the bash(1) manual page:
EXIT STATUS
... Exit statuses fall between 0 and 255, though as
explained below, the shell may use values above 125
specially. ...
... When a command terminates on a fatal signal N, bash uses
the value of 128+N as the exit status.
If a command is not found, the child process created to
execute it returns a status of 127. If a command is found
but is not executable, the return status is 126.
[3] Quote from the Glib Reference Manual, Spawning Processes section,
for function g_spawn_check_exit_status():
https://developer.gnome.org/glib/stable/glib-Spawning-Processes.html#g-spawn-check-exit-status
The g_spawn_sync() and g_child_watch_add() family of APIs return
an exit status for subprocesses encoded in a platform-specific
way. On Unix, this is guaranteed to be in the same format
waitpid() returns, ...
Bug 754684 - Updates to FileSystem:: and Utils::execute_command()
functions
2015-09-06 07:39:07 -06:00
|
|
|
static int get_failure_status( Glib::SpawnError & e );
|
|
|
|
static int decode_wait_status( int wait_status );
|
2011-11-01 13:08:36 -06:00
|
|
|
static Glib::ustring regexp_label( const Glib::ustring & text
|
|
|
|
, const Glib::ustring & pattern
|
|
|
|
) ;
|
2008-04-07 13:41:18 -06:00
|
|
|
static Glib::ustring trim( const Glib::ustring & src, const Glib::ustring & c = " \t\r\n" ) ;
|
2022-08-12 01:38:16 -06:00
|
|
|
static Glib::ustring trim_trailing_new_line(const Glib::ustring& src);
|
2016-01-11 09:17:39 -07:00
|
|
|
static Glib::ustring last_line( const Glib::ustring & src );
|
2008-10-16 13:58:14 -06:00
|
|
|
static Glib::ustring get_lang() ;
|
2009-03-12 13:37:12 -06:00
|
|
|
static void tokenize( const Glib::ustring& str,
|
|
|
|
std::vector<Glib::ustring>& tokens,
|
|
|
|
const Glib::ustring& delimiters ) ;
|
2012-01-28 07:25:31 -07:00
|
|
|
static void split( const Glib::ustring& str,
|
|
|
|
std::vector<Glib::ustring>& result,
|
|
|
|
const Glib::ustring& delimiters ) ;
|
2011-01-28 11:09:21 -07:00
|
|
|
static int convert_to_int(const Glib::ustring & src);
|
2012-01-22 13:49:52 -07:00
|
|
|
static Glib::ustring generate_uuid(void);
|
2012-09-12 16:51:49 -06:00
|
|
|
static int get_mounted_filesystem_usage( const Glib::ustring & mountpoint,
|
|
|
|
Byte_Value & fs_size, Byte_Value & fs_free,
|
2013-09-14 08:23:49 -06:00
|
|
|
Glib::ustring & error_message ) ;
|
Report busy status of jbds (#89)
Continuing from the state in the previous commit, create an ext4 file
system using the previously created external journal and mount it.
# mke2fs -t ext4 -J device=/dev/sdb1 -L test-ext4 /dev/sdb2
# mount /dev/sdb2 /mnt/2
Did some experimenting with trying to create a second file system using
the same external journal which is already in use.
# mke2fs -t ext4 -J device=/dev/sdb1 -L 2nd-test-ext4 /dev/sdb3
...
/dev/sdb1 is apparently in use by the system; will not make a journal here!
# exit $?
1
Examined the source code of mke2fs and found that it performs an
exclusive read-only open of the named journal block device to check if
it is in use by the system or not [1]. Use the same method in GParted.
Not used alternative method would be to mark the jbd active when the
ext3/4 file system using it is active, but that requires working out the
linkage between them. That can be done using either blkid or dumpe2fs
output but that involves parsing more fields and caching more data so is
much more code than just testing the block device busy status using the
same method which mke2fs uses.
Matching UUIDs via blkid output.
# blkid /dev/sdb1 /dev/sdb2
/dev/sdb1: LABEL="test-jbd" UUID="6e52858e-0479-432f-80a1-de42f9a4093e" TYPE="jbd"
/dev/sdb2: LABEL="test-ext4" UUID="cea5c2cd-b21c-4abf-a497-8c073bb12300" EXT_JOURNAL="6e52858e-0479-432f-80a1-de42f9a4093e" TYPE="ext4"
Matching UUIDs via dumpe2fs output.
# dumpe2fs -h /dev/sdb1 | egrep 'Filesystem UUID|Journal users'
dumpe2fs 1.46.3 (27-Jul-2021)
Filesystem UUID: 6e52858e-0479-432f-80a1-de42f9a4093e
Journal users: cea5c2cd-b21c-4abf-a497-8c073bb12300
# dumpe2fs -h /dev/sdb2 | egrep 'Filesystem UUID|Journal UUID'
dumpe2fs 1.46.3 (27-Jul-2021)
Filesystem UUID: cea5c2cd-b21c-4abf-a497-8c073bb12300
Journal UUID: 6e52858e-0479-432f-80a1-de42f9a4093e
If GParted was going to show the journal to file system linkage in the
UI then doing this would be needed. However so far there has only been
a single reported case of a GParted user using an external journal,
therefore adding the code complexity for this feature is not currently
justified. The simple busy detection method used by mke2fs is all that
is needed.
[1] mke2fs source code
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/
misc/mke2fs.c:main()
check_mount(journal_device, force, _("journal"));
misc/util.c:check_mount()
ext2fs_check_if_mounted(device, &mount_flags);
lib/ext2fs/ismounted.c:ext2fs_check_if_mounted()
ext2fs_check_mount_point(file, mount_flags, NULL, 0);
lib/ext2fs/ismounted.c:ext2fs_check_if_mounted()
if (stat(device, &st_buf) == 0 &&
ext2fsP_is_disk_device(st_buf.st_mode)) {
int fd = open(device, O_RDONLY | O_EXCL);
if (fd >= 0) {
/*
* The device is not busy so it's
* definitelly not mounted. No need to
* to perform any more checks.
*/
close(fd);
*mount_flags = 0;
return 0;
} else if (errno == EBUSY) {
busy = 1;
}
}
Closes #89 - GParted doesn't recognise EXT4 fs journal partition
2022-01-25 15:31:55 -07:00
|
|
|
static bool is_dev_busy(const Glib::ustring& path);
|
Always use directory mount point when resizing btrfs (#193)
A user received the following error when attempting to resize a mounted
btrfs file system on their NixOS distribution:
Shrink /dev/nvme0n1p3 from 933.38 GiB to 894.32 GiB (ERROR)
+ calibrate /dev/nvme0n1p3 00:00:00 (SUCCESS)
+ btrfs filesystem resize 1:937759744K '/etc/machine-id' (ERROR)
ERROR: not a directory: /etc/machine-id
ERROR: resize works on mounted filesystems and accepts only
directories as argument. Passing file containing a btrfs image
would resize the underlying filesystem instead of the image.
In the partition table section of the gparted_details /dev/nvme0n1p3 was
reported with these mount points:
/etc/machine-id, /etc/NetworkManager/system-connections,
/etc/ssh/ssh_host_ed25519_key, /etc/ssh/ssh_host_ed25519_key.pub,
/etc/ssh/ssh_host_rsa_key, /etc/ssh/ssh_host_rsa_key.pub, /home,
/nix, /nix/store, /state, /var
The user had a common configuration of NixOS which boots with an empty
tmpfs as root with a few bind mounted files and directories to provide
the needed persistent data [1][2].
Re-create an equivalent situation:
1. Create a btrfs file system and mount it:
# mkfs.btrfs /dev/sdb1
# mkdir /mnt/store
# mount /dev/sdb1 /mnt/store
2. Bind mount a file from this file system else where in the hierarchy.
The only criteria is that this mount point sorts before /mnt/store.
# echo 'Test contents' > /mnt/store/test
# touch /boot/test
# mount --bind /mnt/store/test /boot/test
The kernel reports these mount mounts:
# grep sdb1 /proc/mounts
/dev/sdb1 /mnt/store btrfs rw,seclabel,relatime,space_cache=v2,subvolid=5,subvol=/ 0 0
/dev/sdb1 /boot/test btrfs rw,seclabel,relatime,space_cache=v2,subvolid=5,subvol=/ 0 0
3. Use GParted to resize this mounted btrfs file system. It fails with
the above error.
GParted read the mount points from /proc/mounts and sorted them. (See
the end of Mount_Info::load_cache() for the sorting). When resizing the
btrfs file system GParted just used the first sorted mount point. This
was the file /etc/machine-id for the user and file /boot/test in the
re-creation, hence the error.
Fix by selecting the first directory mount point to pass to the btrfs
resize command.
[1] NixOS tmpfs as root
https://elis.nu/blog/2020/05/nixos-tmpfs-as-root/
[2] Erase your darlings
https://grahamc.com/blog/erase-your-darlings
Closes #193 - path used to resize btrfs needs to be a directory
2022-05-22 02:30:24 -06:00
|
|
|
static const Glib::ustring& first_directory(const std::vector<Glib::ustring>& paths);
|
2013-08-14 01:21:58 -06:00
|
|
|
static Byte_Value floor_size( Byte_Value value, Byte_Value rounding_size ) ;
|
|
|
|
static Byte_Value ceil_size( Byte_Value value, Byte_Value rounding_size ) ;
|
2012-02-05 02:06:44 -07:00
|
|
|
|
|
|
|
private:
|
|
|
|
static bool get_kernel_version( int & major_ver, int & minor_ver, int & patch_ver ) ;
|
2005-12-13 14:30:13 -07:00
|
|
|
};
|
2008-09-04 10:36:14 -06:00
|
|
|
|
2004-10-06 09:32:40 -06:00
|
|
|
}//GParted
|
|
|
|
|
2013-05-27 05:20:16 -06:00
|
|
|
#endif /* GPARTED_UTILS_H */
|