2009-11-05 11:08:32 -07:00
|
|
|
/* Copyright (C) 2004 Bart
|
2010-04-19 19:22:31 -06:00
|
|
|
* Copyright (C) 2008, 2009, 2010 Curtis Gedak
|
2004-09-19 14:24:53 -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-09-19 14:24:53 -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-09-19 14:24:53 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* READ THIS!!
|
2004-10-02 13:30:20 -06:00
|
|
|
* Partition isn't really a partition. It's more like a geometry, a continuous part of the disk.
|
|
|
|
* I use it to represent partitions as well as unallocated spaces
|
2004-09-19 14:24:53 -06:00
|
|
|
*/
|
2013-05-27 05:20:16 -06:00
|
|
|
|
|
|
|
#ifndef GPARTED_PARTITION_H
|
|
|
|
#define GPARTED_PARTITION_H
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2016-10-18 16:45:28 -06:00
|
|
|
#include "Utils.h"
|
|
|
|
#include "PartitionVector.h"
|
2004-09-20 09:46:21 -06:00
|
|
|
|
2016-01-16 03:40:58 -07:00
|
|
|
#include <glibmm/ustring.h>
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
namespace GParted
|
|
|
|
{
|
|
|
|
|
2005-12-07 04:21:27 -07:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
enum PartitionType {
|
2016-08-13 05:25:46 -06:00
|
|
|
TYPE_PRIMARY = 0, // Primary partition on a partitioned drive
|
|
|
|
TYPE_LOGICAL = 1, // Logical partition on a partitioned drive
|
|
|
|
TYPE_EXTENDED = 2, // Extended partition on a partitioned drive
|
|
|
|
TYPE_UNALLOCATED = 3, // Unallocated space on a partitioned drive
|
|
|
|
TYPE_UNPARTITIONED = 4 // Unpartitioned whole drive
|
2004-09-19 14:24:53 -06:00
|
|
|
};
|
|
|
|
|
2004-09-25 08:12:07 -06:00
|
|
|
enum PartitionStatus {
|
2006-03-18 14:38:19 -07:00
|
|
|
STAT_REAL = 0,
|
|
|
|
STAT_NEW = 1,
|
|
|
|
STAT_COPY = 2,
|
|
|
|
STAT_FORMATTED = 3
|
2004-09-25 08:12:07 -06:00
|
|
|
};
|
|
|
|
|
2010-05-09 14:45:26 -06:00
|
|
|
enum PartitionAlignment {
|
|
|
|
ALIGN_CYLINDER = 0, //Align to nearest cylinder
|
2010-05-20 10:00:14 -06:00
|
|
|
ALIGN_MEBIBYTE = 1, //Align to nearest mebibyte
|
|
|
|
ALIGN_STRICT = 2 //Strict alignment - no rounding
|
2010-05-09 14:45:26 -06:00
|
|
|
// Indicator if start and end sectors must remain unchanged
|
|
|
|
};
|
|
|
|
|
2015-05-22 14:01:59 -06:00
|
|
|
class Partition; // Forward declarations as Partition and PartitionVector are
|
|
|
|
class PartitionVector; // mutually recursive classes.
|
|
|
|
// References:
|
|
|
|
// * Mutually recursive classes
|
|
|
|
// http://stackoverflow.com/questions/3410637/mutually-recursive-classes
|
|
|
|
// * recursive definition in CPP
|
|
|
|
// http://stackoverflow.com/questions/4300420/recursive-definition-in-cpp
|
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
class Partition
|
|
|
|
{
|
|
|
|
public:
|
2005-12-23 17:06:05 -07:00
|
|
|
Partition() ;
|
2015-12-05 09:26:30 -07:00
|
|
|
virtual ~Partition();
|
|
|
|
virtual Partition * clone() const;
|
2004-10-11 04:23:24 -06:00
|
|
|
|
2005-12-23 17:06:05 -07:00
|
|
|
void Reset() ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//simple Set-functions. only for convenience, since most members are public
|
2015-01-04 04:29:01 -07:00
|
|
|
void Set( const Glib::ustring & device_path,
|
|
|
|
const Glib::ustring & partition,
|
|
|
|
int partition_number,
|
|
|
|
PartitionType type,
|
2018-01-02 10:44:01 -07:00
|
|
|
FSType filesystem,
|
2015-01-04 04:29:01 -07:00
|
|
|
Sector sector_start,
|
|
|
|
Sector sector_end,
|
|
|
|
Byte_Value sector_size,
|
|
|
|
bool inside_extended,
|
|
|
|
bool busy );
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2012-01-10 07:13:41 -07:00
|
|
|
void set_sector_usage( Sector sectors_fs_size, Sector sectors_fs_unused ) ;
|
2015-12-28 06:47:12 -07:00
|
|
|
virtual bool sector_usage_known() const;
|
|
|
|
virtual Sector estimated_min_size() const;
|
|
|
|
virtual Sector get_sectors_used() const;
|
|
|
|
virtual Sector get_sectors_unused() const;
|
|
|
|
virtual Sector get_sectors_unallocated() const;
|
2012-06-21 14:47:11 -06:00
|
|
|
void get_usage_triple( int imax, int & i1, int & i2, int & i3 ) const ;
|
2016-12-04 13:44:46 -07:00
|
|
|
virtual void resize( const Partition & new_size );
|
2004-10-11 04:23:24 -06:00
|
|
|
|
2015-01-04 04:29:01 -07:00
|
|
|
void Set_Unallocated( const Glib::ustring & device_path,
|
|
|
|
Sector sector_start,
|
|
|
|
Sector sector_end,
|
|
|
|
Byte_Value sector_size,
|
|
|
|
bool inside_extended );
|
2016-08-13 06:28:58 -06:00
|
|
|
void set_unpartitioned( const Glib::ustring & device_path,
|
|
|
|
const Glib::ustring & partition_path,
|
2018-01-02 10:44:01 -07:00
|
|
|
FSType fstype,
|
2016-08-13 06:28:58 -06:00
|
|
|
Sector length,
|
|
|
|
Byte_Value sector_size,
|
|
|
|
bool busy );
|
2004-10-11 04:23:24 -06:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
//update partition number (used when a logical partition is deleted)
|
|
|
|
void Update_Number( int new_number );
|
|
|
|
|
2016-06-03 02:18:21 -06:00
|
|
|
void set_path( const Glib::ustring & path );
|
2010-04-27 11:28:36 -06:00
|
|
|
Byte_Value get_byte_length() const ;
|
2010-04-28 09:11:44 -06:00
|
|
|
Sector get_sector_length() const ;
|
2006-03-14 14:37:47 -07:00
|
|
|
Glib::ustring get_path() const ;
|
2016-12-15 09:08:54 -07:00
|
|
|
void add_mountpoint( const Glib::ustring & mountpoint );
|
|
|
|
void add_mountpoints( const std::vector<Glib::ustring> & mountpoints );
|
2006-03-15 09:12:11 -07:00
|
|
|
Glib::ustring get_mountpoint() const ;
|
fixed issues with copying (see also #335004) cleanups + added FIXME added
* include/GParted_Core.h,
src/GParted_Core.cc,
src/Win_GParted.cc,
src/ext2.cc,
src/ext3.cc,
src/fat16.cc,
src/fat32.cc,
src/jfs.cc,
src/ntfs.cc,
src/reiserfs.cc: fixed issues with copying (see also #335004)
* include/Operation.h,
src/Operation.cc: cleanups + added FIXME
* include/Partition.h,
src/Partition.cc: added clear_mountpoints()
* src/DrawingAreaVisualDisk.cc: added FIXME
2006-03-19 08:30:20 -07:00
|
|
|
void clear_mountpoints() ;
|
2006-03-15 09:12:11 -07:00
|
|
|
std::vector<Glib::ustring> get_mountpoints() const ;
|
2006-08-01 06:47:03 -06:00
|
|
|
Sector get_sector() const ;
|
2006-09-07 14:31:05 -06:00
|
|
|
bool test_overlap( const Partition & partition ) const ;
|
2014-12-16 15:04:34 -07:00
|
|
|
bool filesystem_label_known() const;
|
2016-09-08 09:00:01 -06:00
|
|
|
Glib::ustring get_filesystem_label() const;
|
2014-12-16 15:04:34 -07:00
|
|
|
void set_filesystem_label( const Glib::ustring & filesystem_label );
|
2005-12-22 15:20:55 -07:00
|
|
|
|
2015-12-31 09:32:08 -07:00
|
|
|
// Message accessors. Messages are stored locally and accessed globally.
|
|
|
|
// Stored locally means the messages are stored in the Partition object to which
|
|
|
|
// they are added so push_back_messages() and append_messages() are non-virtual.
|
|
|
|
// Accessed globally means that in the case of derived objects which are composed
|
|
|
|
// of more that one Partition object, i.e. PartitionLUKS, the messages have to be
|
|
|
|
// accessible from all copies within the derived object hierarchy. Hence
|
|
|
|
// have_messages(), get_messages() and clear_messages() are virtual to allow for
|
|
|
|
// overridden implementations.
|
|
|
|
virtual bool have_messages() const { return ! messages.empty(); };
|
|
|
|
virtual std::vector<Glib::ustring> get_messages() const { return messages; };
|
|
|
|
virtual void clear_messages() { messages.clear(); };
|
2019-03-23 04:19:09 -06:00
|
|
|
void push_back_message(const Glib::ustring& msg) { messages.push_back(msg); };
|
|
|
|
void append_messages(const std::vector<Glib::ustring>& msgs)
|
2015-12-31 09:32:08 -07:00
|
|
|
{ messages.insert( messages.end(), msgs.begin(), msgs.end() ); }
|
|
|
|
|
2016-09-06 00:33:26 -06:00
|
|
|
// Interface to return reference to the Partition object directly containing the
|
|
|
|
// file system. Will be overridden in derived PartitionLUKS.
|
|
|
|
virtual const Partition & get_filesystem_partition() const { return *this; };
|
2016-09-06 09:03:05 -06:00
|
|
|
virtual Partition & get_filesystem_partition() { return *this; };
|
2016-09-06 00:33:26 -06:00
|
|
|
|
2016-09-02 00:53:19 -06:00
|
|
|
virtual const Glib::ustring get_filesystem_string() const
|
|
|
|
{ return Utils::get_filesystem_string( filesystem ); };
|
|
|
|
|
2005-12-23 17:06:05 -07:00
|
|
|
bool operator==( const Partition & partition ) const ;
|
2006-03-29 12:21:42 -07:00
|
|
|
bool operator!=( const Partition & partition ) const ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
|
|
|
//some public members
|
2005-12-07 15:44:40 -07:00
|
|
|
Glib::ustring device_path ;
|
2004-09-19 14:24:53 -06:00
|
|
|
int partition_number;
|
|
|
|
PartitionType type;// UNALLOCATED, PRIMARY, LOGICAL, etc...
|
2004-09-25 08:12:07 -06:00
|
|
|
PartitionStatus status; //STAT_REAL, STAT_NEW, etc..
|
2010-05-09 14:45:26 -06:00
|
|
|
PartitionAlignment alignment; //ALIGN_CYLINDER, ALIGN_STRICT, etc
|
2018-01-02 10:44:01 -07:00
|
|
|
FSType filesystem;
|
2008-11-11 10:21:22 -07:00
|
|
|
Glib::ustring uuid ;
|
2014-12-12 00:00:02 -07:00
|
|
|
Glib::ustring name;
|
2004-09-19 14:24:53 -06:00
|
|
|
Sector sector_start;
|
|
|
|
Sector sector_end;
|
|
|
|
Sector sectors_used;
|
|
|
|
Sector sectors_unused;
|
2012-01-10 07:13:41 -07:00
|
|
|
Sector sectors_unallocated; //Difference between the size of the partition and the file system
|
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-15 06:16:30 -06:00
|
|
|
Sector significant_threshold; //Threshold from intrinsic to significant unallocated sectors
|
2005-12-23 17:06:05 -07:00
|
|
|
bool inside_extended;
|
2004-09-19 14:24:53 -06:00
|
|
|
bool busy;
|
2018-09-17 08:22:16 -06:00
|
|
|
bool fs_readonly; // Is the file system mounted read-only?
|
2006-02-17 16:20:28 -07:00
|
|
|
std::vector<Glib::ustring> flags ;
|
2015-05-23 13:22:37 -06:00
|
|
|
|
|
|
|
PartitionVector logicals;
|
2006-01-07 08:04:42 -07:00
|
|
|
|
2009-02-16 12:37:27 -07:00
|
|
|
bool strict_start ; //Indicator if start sector must stay unchanged
|
2010-05-20 10:00:14 -06:00
|
|
|
Sector free_space_before ; //Free space preceding partition value
|
2010-04-19 19:06:08 -06:00
|
|
|
|
|
|
|
Byte_Value sector_size ; //Sector size of the disk device needed for converting to/from sectors and bytes.
|
2016-01-16 03:40:58 -07:00
|
|
|
Byte_Value fs_block_size; // Block size of of the file system, or -1 when unknown.
|
2010-04-19 19:06:08 -06:00
|
|
|
|
2004-09-19 14:24:53 -06:00
|
|
|
private:
|
2015-12-20 04:28:09 -07:00
|
|
|
Partition & operator=( Partition & rhs ); // Not implemented copy assignment operator
|
|
|
|
|
2012-06-21 14:47:11 -06:00
|
|
|
static void get_usage_triple_helper( Sector stot, Sector s1, Sector s2, Sector s3, int imax, int & i1, int & i2, int & i3 ) ;
|
2012-06-20 16:53:05 -06:00
|
|
|
|
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-15 06:16:30 -06:00
|
|
|
Sector calc_significant_unallocated_sectors() const ;
|
2004-09-19 14:24:53 -06:00
|
|
|
|
2016-06-02 14:48:06 -06:00
|
|
|
Glib::ustring path;
|
2006-03-15 09:12:11 -07:00
|
|
|
std::vector<Glib::ustring> mountpoints ;
|
2014-12-16 15:04:34 -07:00
|
|
|
bool have_filesystem_label;
|
|
|
|
Glib::ustring filesystem_label;
|
2015-12-31 09:32:08 -07:00
|
|
|
std::vector<Glib::ustring> messages;
|
2004-09-19 14:24:53 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
}//GParted
|
2013-05-27 05:20:16 -06:00
|
|
|
|
|
|
|
#endif /* GPARTED_PARTITION_H */
|