From 7bf6c422ff32d54176499bf0639da65d0a452e4c Mon Sep 17 00:00:00 2001 From: Curtis Gedak Date: Thu, 8 May 2008 16:25:43 +0000 Subject: [PATCH] Added parse devices from /proc/partitions for "Scanning all devices..." code svn path=/trunk/; revision=847 --- ChangeLog | 6 ++++++ src/GParted_Core.cc | 35 +++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index c11ab7cc..dca581de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-05-08 Curtis Gedak + + * src/GParted_Core.cc: Added parse devices from /proc/partitions + - If /proc/partitions doesn't exist then use ped_device_probe_all + - Closes GParted bugs #351753, and #453555 + 2008-05-06 Curtis Gedak * gparted.in: Fixed problem with command line devices being ignored diff --git a/src/GParted_Core.cc b/src/GParted_Core.cc index 867a1372..d24558d7 100644 --- a/src/GParted_Core.cc +++ b/src/GParted_Core.cc @@ -39,7 +39,7 @@ #include "../include/ufs.h" #include -#include +#include std::vector libparted_messages ; //see ped_exception_handler() @@ -65,7 +65,7 @@ GParted_Core::GParted_Core() std::cout << "======================" << std::endl ; std::cout << "libparted : " << ped_get_version() << std::endl ; std::cout << "======================" << std::endl ; - + //initialize filesystemlist find_supported_filesystems() ; } @@ -135,9 +135,34 @@ void GParted_Core::set_devices( std::vector & devices ) if ( probe_devices ) { device_paths .clear() ; - + //try to find all available devices - ped_device_probe_all(); + std::ifstream proc_partitions( "/proc/partitions" ) ; + if ( proc_partitions ) + { + //parse device names from /proc/partitions + std::string line ; + std::string device ; + while ( getline( proc_partitions, line ) ) + { + //Device names without a trailing digit refer to the whole disk. + //These whole disk devices are the ones we want. + device = Utils::regexp_label(line, "^[\t ]+[0-9]+[\t ]+[0-9]+[\t ]+[0-9]+[\t ]+([^0-9]+)$") ; + if ( device != "" ) + { + //try to have libparted detect the device and add it to the list + device = "/dev/" + device; + ped_device_get( device .c_str() ) ; + } + } + proc_partitions .close() ; + } + else + { + //file /proc/partitions doesn't exist so use libparted to probe devices + ped_device_probe_all(); + } + lp_device = ped_device_get_next( NULL ); while ( lp_device ) { @@ -152,10 +177,8 @@ void GParted_Core::set_devices( std::vector & devices ) ped_device_close( lp_device ) ; } - free( buf ) ; } - lp_device = ped_device_get_next( lp_device ) ; } close_device_and_disk() ;