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
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
#include "../include/i18n.h"
|
|
|
|
|
2004-10-06 09:32:40 -06:00
|
|
|
#include <gtkmm/label.h>
|
|
|
|
#include <glibmm/ustring.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)") ;
|
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
enum FILESYSTEM
|
|
|
|
{
|
2014-10-09 13:18:22 -06:00
|
|
|
// Special partition types and functions
|
2013-10-05 09:28:24 -06:00
|
|
|
FS_UNALLOCATED = 0,
|
|
|
|
FS_UNKNOWN = 1,
|
|
|
|
FS_UNFORMATTED = 2,
|
|
|
|
FS_CLEARED = 3, //Clear existing file system signatures
|
|
|
|
FS_EXTENDED = 4,
|
2012-12-08 12:41:00 -07:00
|
|
|
|
2014-10-09 13:18:22 -06:00
|
|
|
// Supported file system types
|
2013-10-05 09:28:24 -06:00
|
|
|
FS_BTRFS = 5,
|
|
|
|
FS_EXFAT = 6, /* Also known as fat64 */
|
|
|
|
FS_EXT2 = 7,
|
|
|
|
FS_EXT3 = 8,
|
|
|
|
FS_EXT4 = 9,
|
|
|
|
FS_F2FS = 10,
|
|
|
|
FS_FAT16 = 11,
|
|
|
|
FS_FAT32 = 12,
|
|
|
|
FS_HFS = 13,
|
|
|
|
FS_HFSPLUS = 14,
|
|
|
|
FS_JFS = 15,
|
|
|
|
FS_LINUX_SWAP = 16,
|
|
|
|
FS_LVM2_PV = 17,
|
|
|
|
FS_NILFS2 = 18,
|
|
|
|
FS_NTFS = 19,
|
|
|
|
FS_REISER4 = 20,
|
|
|
|
FS_REISERFS = 21,
|
|
|
|
FS_UFS = 22,
|
|
|
|
FS_XFS = 23,
|
2012-12-08 12:41:00 -07:00
|
|
|
|
2014-10-09 13:18:22 -06:00
|
|
|
// Recognised signatures but otherwise unsupported file system types
|
|
|
|
FS_BITLOCKER = 24,
|
|
|
|
FS_LUKS = 25,
|
|
|
|
FS_LINUX_SWRAID = 26,
|
|
|
|
FS_LINUX_SWSUSPEND = 27,
|
2014-10-13 06:20:08 -06:00
|
|
|
FS_REFS = 28,
|
2015-07-25 08:51:32 -06:00
|
|
|
FS_ZFS = 29,
|
2012-12-08 12:41:00 -07:00
|
|
|
|
2014-10-09 13:18:22 -06:00
|
|
|
// Partition space usage colours
|
2015-07-25 08:51:32 -06:00
|
|
|
FS_USED = 30,
|
|
|
|
FS_UNUSED = 31
|
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
|
|
|
|
2012-01-27 11:14:53 -07:00
|
|
|
enum CUSTOM_TEXT
|
|
|
|
{
|
|
|
|
CTEXT_NONE,
|
2012-02-13 05:44:45 -07:00
|
|
|
CTEXT_ACTIVATE_FILESYSTEM, // Activate text ('Mount', 'Swapon', VG 'Activate', ...)
|
|
|
|
CTEXT_DEACTIVATE_FILESYSTEM, // Deactivate text ('Unmount', 'Swapoff', VG 'Deactivate', ...)
|
2012-01-30 11:33:33 -07:00
|
|
|
CTEXT_CHANGE_UUID_WARNING, // Warning to print when changing UUIDs
|
2012-08-25 15:25:23 -06:00
|
|
|
CTEXT_RESIZE_DISALLOWED_WARNING // File system resizing currently disallowed reason
|
2012-01-27 11:14:53 -07:00
|
|
|
} ;
|
|
|
|
|
2008-11-18 16:58:17 -07:00
|
|
|
//struct to store file system information
|
2004-10-06 09:32:40 -06:00
|
|
|
struct FS
|
|
|
|
{
|
2005-11-26 17:57:11 -07:00
|
|
|
enum Support
|
|
|
|
{
|
|
|
|
NONE = 0,
|
2006-05-23 15:17:34 -06:00
|
|
|
GPARTED = 1,
|
|
|
|
LIBPARTED = 2,
|
|
|
|
EXTERNAL = 3
|
2005-11-26 17:57:11 -07:00
|
|
|
};
|
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
FILESYSTEM filesystem ;
|
2014-02-14 18:26:32 -07:00
|
|
|
Support busy ; //How to determine if partition/file system is busy
|
2012-09-10 09:41:58 -06:00
|
|
|
Support read ; //Can and how to read sector usage while inactive
|
2008-11-08 16:55:17 -07:00
|
|
|
Support read_label ;
|
|
|
|
Support write_label ;
|
2012-01-22 13:49:52 -07:00
|
|
|
Support read_uuid ;
|
|
|
|
Support write_uuid ;
|
2005-11-26 17:57:11 -07:00
|
|
|
Support create ;
|
2013-06-05 15:15:47 -06:00
|
|
|
Support create_with_label ; //Can and how to format file system with label
|
2005-11-26 17:57:11 -07:00
|
|
|
Support grow ;
|
|
|
|
Support shrink ;
|
|
|
|
Support move ; //startpoint and endpoint
|
|
|
|
Support check ; //some checktool available?
|
|
|
|
Support copy ;
|
2012-07-25 14:05:33 -06:00
|
|
|
Support remove ;
|
2012-09-10 09:41:58 -06:00
|
|
|
Support online_read ; //Can and how to read sector usage while active
|
2013-11-15 09:27:12 -07:00
|
|
|
Support online_grow ;
|
|
|
|
Support online_shrink ;
|
2006-02-17 14:18:07 -07:00
|
|
|
|
2010-03-16 11:24:08 -06:00
|
|
|
Byte_Value MIN ;
|
2010-03-16 13:25:58 -06:00
|
|
|
Byte_Value MAX ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2006-01-21 17:07:27 -07:00
|
|
|
FS()
|
2004-12-09 15:56:33 -07:00
|
|
|
{
|
2013-06-05 15:15:47 -06:00
|
|
|
read = read_label = write_label = read_uuid = write_uuid = create = create_with_label =
|
2013-11-15 09:27:12 -07:00
|
|
|
grow = shrink = move = check = copy = remove = online_read =
|
|
|
|
online_grow = online_shrink = NONE ;
|
2005-08-30 20:30:25 -06:00
|
|
|
MIN = MAX = 0 ;
|
2004-12-09 15:56:33 -07:00
|
|
|
}
|
2006-03-31 03:49:27 -07:00
|
|
|
} ;
|
2004-11-17 06:00:25 -07:00
|
|
|
|
2004-10-06 09:32:40 -06: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
|
2014-04-26 14:21:55 -06:00
|
|
|
, float yalign = 0.5 /* ALIGN_CENTER */
|
2014-04-26 14:06:18 -06:00
|
|
|
) ;
|
2010-01-02 15:04:30 -07:00
|
|
|
static Glib::ustring num_to_str( Sector number ) ;
|
2006-03-28 05:40:29 -07:00
|
|
|
static Glib::ustring get_color( FILESYSTEM filesystem ) ;
|
2005-12-15 08:10:34 -07:00
|
|
|
static Glib::RefPtr<Gdk::Pixbuf> get_color_as_pixbuf( FILESYSTEM filesystem, int width, int height ) ;
|
2015-03-13 16:36:08 -06:00
|
|
|
static int get_max_partition_name_length( Glib::ustring & tabletype );
|
2012-12-16 08:41:30 -07:00
|
|
|
static int get_filesystem_label_maxlength( FILESYSTEM filesystem ) ;
|
2006-03-28 05:40:29 -07:00
|
|
|
static Glib::ustring get_filesystem_string( FILESYSTEM filesystem ) ;
|
2015-01-11 03:01:02 -07:00
|
|
|
static const Glib::ustring get_filesystem_kernel_name( FILESYSTEM fstype );
|
2008-11-14 12:45:14 -07:00
|
|
|
static Glib::ustring get_filesystem_software( FILESYSTEM filesystem ) ;
|
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 ) ;
|
2013-10-07 16:37:31 -06:00
|
|
|
static bool swraid_member_is_active( const Glib::ustring & path ) ;
|
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 ) ;
|
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" ) ;
|
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 ) ;
|
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 */
|