gparted/include/Partition.h

148 lines
4.7 KiB
C
Raw Normal View History

/* Copyright (C) 2004 Bart
* 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
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/* 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
*/
#ifndef PARTITION
#define PARTITION
2004-10-06 09:32:40 -06:00
#include "../include/Utils.h"
2004-09-20 09:46:21 -06:00
2004-09-19 14:24:53 -06:00
namespace GParted
{
2004-09-19 14:24:53 -06:00
enum PartitionType {
TYPE_PRIMARY = 0,
TYPE_LOGICAL = 1,
TYPE_EXTENDED = 2,
TYPE_UNALLOCATED = 3
2004-09-19 14:24:53 -06:00
};
2004-09-25 08:12:07 -06:00
enum PartitionStatus {
STAT_REAL = 0,
STAT_NEW = 1,
STAT_COPY = 2,
STAT_FORMATTED = 3
2004-09-25 08:12:07 -06:00
};
enum PartitionAlignment {
ALIGN_CYLINDER = 0, //Align to nearest cylinder
ALIGN_MEBIBYTE = 1, //Align to nearest mebibyte
ALIGN_STRICT = 2 //Strict alignment - no rounding
// Indicator if start and end sectors must remain unchanged
};
2004-09-19 14:24:53 -06:00
class Partition
{
public:
Partition() ;
Partition( const Glib::ustring & path ) ;
~Partition() ;
void Reset() ;
2004-09-19 14:24:53 -06:00
//simple Set-functions. only for convenience, since most members are public
void Set( const Glib::ustring & device_path,
const Glib::ustring & partition,
int partition_number,
PartitionType type,
FILESYSTEM filesystem,
Sector sector_start,
Sector sector_end,
Byte_Value sector_size,
bool inside_extended,
bool busy ) ;
2004-09-19 14:24:53 -06:00
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-01-10 07:13:41 -07:00
void set_sector_usage( Sector sectors_fs_size, Sector sectors_fs_unused ) ;
bool sector_usage_known() const ;
Sector estimated_min_size() const ;
Sector get_sectors_used() const ;
Sector get_sectors_unused() const ;
Sector get_sectors_unallocated() const ;
void Set_Unallocated( const Glib::ustring & device_path,
Sector sector_start,
Sector sector_end,
Byte_Value sector_size,
bool inside_extended );
2004-09-19 14:24:53 -06:00
//update partition number (used when a logical partition is deleted)
void Update_Number( int new_number );
void add_path( const Glib::ustring & path, bool clear_paths = false ) ;
void add_paths( const std::vector<Glib::ustring> & paths, bool clear_paths = false ) ;
2010-04-27 11:28:36 -06:00
Byte_Value get_byte_length() const ;
Sector get_sector_length() const ;
Glib::ustring get_path() const ;
std::vector<Glib::ustring> get_paths() const ;
void add_mountpoint( const Glib::ustring & mountpoint, bool clear_mountpoints = false ) ;
void add_mountpoints( const std::vector<Glib::ustring> & mountpoints, bool clear_mountpoints = false ) ;
Glib::ustring get_mountpoint() const ;
void clear_mountpoints() ;
std::vector<Glib::ustring> get_mountpoints() const ;
Sector get_sector() const ;
bool test_overlap( const Partition & partition ) const ;
bool operator==( const Partition & partition ) const ;
bool operator!=( const Partition & partition ) const ;
2004-09-19 14:24:53 -06:00
//some public members
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..
PartitionAlignment alignment; //ALIGN_CYLINDER, ALIGN_STRICT, etc
FILESYSTEM filesystem ;
Glib::ustring label ;
Glib::ustring uuid ;
2004-09-19 14:24:53 -06:00
Sector sector_start;
Sector sector_end;
Sector sectors_used;
Sector sectors_unused;
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-01-10 07:13:41 -07:00
Sector sectors_unallocated; //Difference between the size of the partition and the file system
Sector significant_threshold; //Threshold from intrinsic to significant unallocated sectors
2004-09-19 14:24:53 -06:00
Gdk::Color color;
bool inside_extended;
2004-09-19 14:24:53 -06:00
bool busy;
std::vector<Glib::ustring> messages ;
std::vector<Glib::ustring> flags ;
2004-09-19 14:24:53 -06:00
std::vector<Partition> logicals ;
bool strict_start ; //Indicator if start sector must stay unchanged
Sector free_space_before ; //Free space preceding partition value
Byte_Value sector_size ; //Sector size of the disk device needed for converting to/from sectors and bytes.
2004-09-19 14:24:53 -06:00
private:
void sort_paths_and_remove_duplicates() ;
Sector calc_significant_unallocated_sectors() const ;
2004-09-19 14:24:53 -06:00
static bool compare_paths( const Glib::ustring & A, const Glib::ustring & B ) ;
std::vector<Glib::ustring> paths ;
std::vector<Glib::ustring> mountpoints ;
2004-09-19 14:24:53 -06:00
};
}//GParted
#endif //PARTITION