Removed bool Get_Any_Busy() in favor of public bool busy which is set in

* include/Device.h,
  src/Device.cc: Removed bool Get_Any_Busy() in favor of public bool busy which is set in gparted_core.
  This also fixed a small bug with incorrect mountdetection of logical partitions.
  Also added a Reset() function to properly reset the contents of a device. to zero/empty .
* include/GParted_Core.h,
  src/GParted_Core.cc: 'busyness' of a device is now determined in get_devices().
  Renamed get_partitions() to set_device_partitions to reflect its proper function.
  When a new partition is created to contain a copied filesystem the size is now properly set. This fixes
  a very annoying bug which no one knew about except for me =) .
* src/Win_GParted.cc: use boolean busy from device instead of Get_Any_Busy() .
This commit is contained in:
Bart Hakvoort 2004-11-19 11:55:38 +00:00
parent 7a3fb89e81
commit 4438e3264e
6 changed files with 61 additions and 33 deletions

View File

@ -1,3 +1,16 @@
2004-11-19 Bart Hakvoort <gparted@users.sf.net>
* include/Device.h,
src/Device.cc: Removed bool Get_Any_Busy() in favor of public bool busy which is set in gparted_core.
This also fixed a small bug with incorrect mountdetection of logical partitions.
Also added a Reset() function to properly reset the contents of a device. to zero/empty .
* include/GParted_Core.h,
src/GParted_Core.cc: 'busyness' of a device is now determined in get_devices().
Renamed get_partitions() to set_device_partitions to reflect its proper function.
When a new partition is created to contain a copied filesystem the size is now properly set. This fixes
a very annoying bug which no one knew about except for me =) .
* src/Win_GParted.cc: use boolean busy from device instead of Get_Any_Busy() .
2004-11-17 Bart Hakvoort <gparted@users.sf.net>
* src/ext3.cc: availability of 'tune2fs' command wasn't detected correctly. fixed

View File

@ -30,7 +30,7 @@ public:
Device( ) ;
~Device( ) ;
bool Get_any_busy( ) ;
void Reset( ) ;
int Get_Highest_Logical_Busy( ) ;
std::vector<Partition> device_partitions ;
@ -43,6 +43,7 @@ public:
Glib::ustring realpath;
Glib::ustring disktype;
int max_prims ;
bool busy ;
private:

View File

@ -40,7 +40,7 @@ public:
GParted_Core( ) ;
void find_supported_filesystems( ) ;
void get_devices( std::vector<Device> & devices, bool deep_scan ) ;
void get_partitions( std::vector<Partition> & partitions, const Glib::ustring & device_path, bool deep_scan = true ) ;
int get_estimated_time( Operation & operation ) ;
void Apply_Operation_To_Disk( Operation & operation );
@ -55,10 +55,11 @@ public:
Glib::RefPtr<Gtk::TextBuffer> get_textbuffer( ) ;
private:
void set_device_partitions( Device & device, bool deep_scan = true ) ;
Glib::ustring get_sym_path( const Glib::ustring & real_path ) ;
Sector Get_Used_Sectors( PedPartition *c_partition, const Glib::ustring & sym_path );
Glib::ustring Get_Flags( PedPartition *c_partition ) ;
int Create_Empty_Partition( const Glib::ustring & device_path, Partition & new_partition ) ;
int Create_Empty_Partition( const Glib::ustring & device_path, Partition & new_partition, bool copy = false ) ;
bool Resize_Extended( const Glib::ustring & device_path, const Partition & extended ) ;
void Show_Error( Glib::ustring message ) ;

View File

@ -22,15 +22,17 @@ namespace GParted
Device::Device( )
{
Reset( ) ;
}
bool Device::Get_any_busy( )
void Device::Reset( )
{
for ( unsigned int t=0;t<device_partitions.size(); t++ )
if ( device_partitions[t].busy )
return true;
return false;
device_partitions .clear( ) ;
length = 0 ;
heads = sectors = cylinders = 0 ;
model = path = realpath = disktype ;
max_prims = 0 ;
busy = false ;
}
int Device::Get_Highest_Logical_Busy( )

View File

@ -85,6 +85,8 @@ void GParted_Core::get_devices( std::vector<Device> & devices, bool deep_scan )
{
if ( open_device_and_disk( device_paths[ t ], device, disk ) )
{
temp_device .Reset( ) ;
temp_device .path = device_paths[ t ] ;
temp_device .realpath = device ->path ;
temp_device .model = device ->model ;
@ -95,7 +97,7 @@ void GParted_Core::get_devices( std::vector<Device> & devices, bool deep_scan )
temp_device .length = temp_device .heads * temp_device .sectors * temp_device .cylinders ;
temp_device .max_prims = ped_disk_get_max_primary_partition_count( disk ) ;
get_partitions( temp_device .device_partitions, temp_device .path, deep_scan ) ;
set_device_partitions( temp_device, deep_scan ) ;
devices .push_back( temp_device ) ;
@ -105,20 +107,20 @@ void GParted_Core::get_devices( std::vector<Device> & devices, bool deep_scan )
}
void GParted_Core::get_partitions( std::vector<Partition> & partitions, const Glib::ustring & device_path, bool deep_scan )
void GParted_Core::set_device_partitions( Device & device, bool deep_scan )
{
Partition partition_temp ;
Glib::ustring part_path, error ;
int EXT_INDEX = -1 ;
//clear partitions
partitions .clear( ) ;
device .device_partitions .clear( ) ;
c_partition = ped_disk_next_partition( disk, NULL ) ;
while ( c_partition )
{
partition_temp .Reset( ) ;
part_path = device_path + num_to_str( c_partition ->num ) ;
part_path = device .path + num_to_str( c_partition ->num ) ;
switch ( c_partition ->type )
{
@ -152,8 +154,10 @@ void GParted_Core::get_partitions( std::vector<Partition> & partitions, const Gl
partition_temp .flags = Get_Flags( c_partition ) ;
partition_temp .error = error .empty( ) ? error_message : error ;
break ;
if ( partition_temp .busy )
device .busy = true ;
break ;
case PED_PARTITION_EXTENDED:
partition_temp.Set( part_path ,
@ -166,24 +170,25 @@ void GParted_Core::get_partitions( std::vector<Partition> & partitions, const Gl
ped_partition_is_busy( c_partition ) );
partition_temp .flags = Get_Flags( c_partition ) ;
EXT_INDEX = partitions .size ( ) ;
EXT_INDEX = device .device_partitions .size ( ) ;
break ;
case PED_PARTITION_FREESPACE:
case 5: //freespace inside extended (there's no enumvalue for that..)
partition_temp .Set_Unallocated( c_partition ->geom .start, c_partition ->geom .end, c_partition ->type == 4 ? false : true );
break ;
case PED_PARTITION_METADATA:
if ( partitions .size( ) && partitions .back( ) .type == GParted::UNALLOCATED )
partitions .back( ) .sector_end = c_partition ->geom .end ;
if ( device .device_partitions .size( ) && device .device_partitions .back( ) .type == GParted::UNALLOCATED )
device .device_partitions .back( ) .sector_end = c_partition ->geom .end ;
break ;
case 9: //metadata inside extended (there's no enumvalue for that..)
if ( partitions[ EXT_INDEX ] .logicals .size( ) && partitions[ EXT_INDEX ] .logicals .back( ) .type == GParted::UNALLOCATED )
partitions[ EXT_INDEX ] .logicals .back( ) .sector_end = c_partition ->geom .end ;
if ( device .device_partitions[ EXT_INDEX ] .logicals .size( ) &&
device .device_partitions[ EXT_INDEX ] .logicals .back( ) .type == GParted::UNALLOCATED
)
device .device_partitions[ EXT_INDEX ] .logicals .back( ) .sector_end = c_partition ->geom .end ;
break ;
@ -193,9 +198,9 @@ void GParted_Core::get_partitions( std::vector<Partition> & partitions, const Gl
if ( partition_temp .Get_Length_MB( ) >= 1 ) // check for unallocated < 1MB, and metadatasituations (see PED_PARTITION_METADATA and 9 )
{
if ( ! partition_temp .inside_extended )
partitions.push_back( partition_temp );
device .device_partitions .push_back( partition_temp );
else
partitions[ EXT_INDEX ] .logicals .push_back( partition_temp ) ;
device .device_partitions[ EXT_INDEX ] .logicals .push_back( partition_temp ) ;
}
//reset stuff..
@ -328,7 +333,7 @@ bool GParted_Core::Resize(const Glib::ustring & device_path, const Partition & p
bool GParted_Core::Copy( const Glib::ustring & dest_device_path, const Glib::ustring & src_part_path, Partition & partition_dest )
{
if ( Create_Empty_Partition( dest_device_path, partition_dest ) > 0 )
if ( Create_Empty_Partition( dest_device_path, partition_dest, true ) > 0 )
{
set_proper_filesystem( partition_dest .filesystem ) ;
@ -438,7 +443,7 @@ Sector GParted_Core::Get_Used_Sectors( PedPartition *c_partition, const Glib::us
return -1 ; //all methods were unsuccesfull
}
int GParted_Core::Create_Empty_Partition( const Glib::ustring & device_path, Partition & new_partition )
int GParted_Core::Create_Empty_Partition( const Glib::ustring & device_path, Partition & new_partition, bool copy )
{
new_partition .partition_number = 0 ;
@ -461,17 +466,23 @@ int GParted_Core::Create_Empty_Partition( const Glib::ustring & device_path, Par
if ( c_part )
{
constraint = ped_constraint_any ( device );
if ( constraint )
{
if ( copy )
constraint ->min_size = new_partition .sector_end - new_partition .sector_start ;
if ( ped_disk_add_partition ( disk, c_part, constraint ) && Commit( disk ) )
{
sleep( 1 ) ;//the OS needs some time to create the devicenode in /dev
new_partition .partition = ped_partition_get_path( c_part ) ;
new_partition .partition_number = c_part ->num ;
}
ped_constraint_destroy ( constraint );
}
}
close_device_and_disk( device, disk ) ;

View File

@ -1141,7 +1141,7 @@ void Win_GParted::activate_apply()
//make list of involved devices which have at least one busy partition..
std::vector <Glib::ustring> devicenames ;
for ( unsigned int t = 0; t < devices .size( ); t++ )
if ( devices[ t ] .Get_any_busy( ) )
if ( devices[ t ] .busy )
for (unsigned int i = 0; i < operations .size( ); i++ )
if ( operations[ i ] .device_path == devices[ t ] .path )
{