[gparted/lucab/btrfs: 5/5] Provide set_used_sectors() for Btrfs



commit 5c05233072b2f600e0d9fbec0b2a9d4eab5e51f0
Author: Luca Bruno <lucab debian org>
Date:   Sun Oct 3 16:57:42 2010 +0200

    Provide set_used_sectors() for Btrfs
    
    Add set_used_sectors() method to Btrfs handler, to show usage statistics
    on unmounted volumes.

 src/btrfs.cc |   39 +++++++++++++++++++++++++++++++++++++--
 1 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/src/btrfs.cc b/src/btrfs.cc
index e2f7e41..7d69803 100644
--- a/src/btrfs.cc
+++ b/src/btrfs.cc
@@ -61,8 +61,43 @@ bool btrfs::check_repair( const Partition & partition, OperationDetail & operati
 
 void btrfs::set_used_sectors( Partition & partition )
 {
-// TODO
-    return;
+	if ( ! Utils::execute_command( "btrfs-show " + partition .get_path(), output, error, true ) )
+	{
+		Glib::ustring size_label;
+		if ( ((index = output .find( "FS bytes" )) < output .length()) &&
+			  (size_label=Utils::regexp_label(output .substr( index ), "^FS bytes used (.*)B")) .length() > 0)
+		{
+			gchar *suffix;
+			gdouble rawN = g_ascii_strtod (size_label.c_str(),&suffix);
+			unsigned long long mult=0;
+			switch(suffix[0]){
+				case 'K':
+					mult=KIBIBYTE;
+					break;
+				case 'M':
+					mult=MEBIBYTE;
+					break;
+				case 'G':
+					mult=GIBIBYTE;
+					break;
+				case 'T':
+					mult=TEBIBYTE;
+					break;
+				default:
+					mult=1;
+					break;
+					}
+			partition .set_used( Utils::round( (rawN * mult)/ double(partition .sector_size) ) ) ;
+		}
+	}
+	else
+	{
+		if ( ! output .empty() )
+			partition .messages .push_back( output ) ;
+
+		if ( ! error .empty() )
+			partition .messages .push_back( error ) ;
+	}
 }
 
 bool btrfs::write_label( const Partition & partition, OperationDetail & operationdetail )



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]