From 352641208a2f3a39fa1ff4db9aa4ed9d950f9027 Mon Sep 17 00:00:00 2001 From: Curtis Gedak Date: Tue, 11 Nov 2008 00:14:57 +0000 Subject: [PATCH] Added fat_compliant_label() method to limit volume labels to 11 characters. Enforced fat compliant label for FAT16 and FAT32 file systems. svn path=/trunk/; revision=959 --- AUTHORS | 1 + ChangeLog | 10 ++++++++++ include/Utils.h | 1 + src/Utils.cc | 9 +++++++++ src/fat16.cc | 6 +++--- src/fat32.cc | 6 +++--- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index dbb37f61..119fbc9f 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,6 +12,7 @@ not an invitation to misrepresent who contributed to GNU GParted. We need to keep track of copyright (see the Maintainer HOWTO on www.gnu.org). Curtis Gedak + * Wrote Utils::fat_compliant_label() method * Wrote Utils::cleanup_cursor() function * Rewrote read_label functionality for hfs * Wrote create, read_label, and check_repair functionality for hfs+ diff --git a/ChangeLog b/ChangeLog index 48024d12..ee758f0b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2008-11-10 Curtis Gedak + + * src/fat16.cc, + src/fat32.cc: Enforced fat compliant label before writing. + - Trimmed trailing spaces from label upon reading. + + * include/Utils.h, + src/Utils.cc: Created new method fat_compliant_label(). + - Limit volume label to 11 characters. + 2008-11-08 Curtis Gedak * include/ext2.h, diff --git a/include/Utils.h b/include/Utils.h index 1521c5f8..a7ae3360 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -136,6 +136,7 @@ public: bool use_C_locale = false ) ; static Glib::ustring regexp_label( const Glib::ustring & text, const Glib::ustring & regular_sub_expression ) ; + static Glib::ustring fat_compliant_label( const Glib::ustring & label ) ; static Glib::ustring create_mtoolsrc_file( char file_name[], const char drive_letter, const Glib::ustring & device_path ) ; static Glib::ustring delete_mtoolsrc_file( const char file_name[] ) ; diff --git a/src/Utils.cc b/src/Utils.cc index 5fdcc331..55a80529 100644 --- a/src/Utils.cc +++ b/src/Utils.cc @@ -279,6 +279,15 @@ Glib::ustring Utils::regexp_label( const Glib::ustring & text, return label ; } +Glib::ustring Utils::fat_compliant_label( const Glib::ustring & label ) +{ + //Limit volume label to 11 characters + Glib::ustring text = label ; + if( text .length() > 11 ) + text .resize( 11 ) ; + return text ; +} + Glib::ustring Utils::create_mtoolsrc_file( char file_name[], const char drive_letter, const Glib::ustring & device_path ) { diff --git a/src/fat16.cc b/src/fat16.cc index 6971aeb5..343bb2b1 100644 --- a/src/fat16.cc +++ b/src/fat16.cc @@ -105,7 +105,7 @@ void fat16::read_label( Partition & partition ) if ( ! Utils::execute_command( cmd, output, error, true ) ) { - partition .label = Utils::regexp_label( output, "Volume label is ([^(]*)" ); + partition .label = Utils::trim( Utils::regexp_label( output, "Volume label is ([^(]*)" ) ) ; } else { @@ -132,7 +132,7 @@ bool fat16::write_label( const Partition & partition, OperationDetail & operatio if( partition .label .empty() ) cmd = String::ucompose( "export MTOOLSRC=%1 && mlabel -c %2:", fname, dletter ) ; else - cmd = String::ucompose( "export MTOOLSRC=%1 && mlabel %2:\"%3\"", fname, dletter, partition .label ) ; + cmd = String::ucompose( "export MTOOLSRC=%1 && mlabel %2:\"%3\"", fname, dletter, Utils::fat_compliant_label( partition .label ) ) ; operationdetail .add_child( OperationDetail( cmd, STATUS_NONE, FONT_BOLD_ITALIC ) ) ; @@ -152,7 +152,7 @@ bool fat16::write_label( const Partition & partition, OperationDetail & operatio bool fat16::create( const Partition & new_partition, OperationDetail & operationdetail ) { - return ! execute_command( "mkdosfs -F16 -v -n \"" + new_partition .label + "\" " + new_partition .get_path(), operationdetail ) ; + return ! execute_command( "mkdosfs -F16 -v -n \"" + Utils::fat_compliant_label( new_partition .label ) + "\" " + new_partition .get_path(), operationdetail ) ; } bool fat16::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition ) diff --git a/src/fat32.cc b/src/fat32.cc index 8da4b70d..cfbaf9cf 100644 --- a/src/fat32.cc +++ b/src/fat32.cc @@ -105,7 +105,7 @@ void fat32::read_label( Partition & partition ) if ( ! Utils::execute_command( cmd, output, error, true ) ) { - partition .label = Utils::regexp_label( output, "Volume label is ([^(]*)" ); + partition .label = Utils::trim( Utils::regexp_label( output, "Volume label is ([^(]*)" ) ) ; } else { @@ -132,7 +132,7 @@ bool fat32::write_label( const Partition & partition, OperationDetail & operatio if( partition .label .empty() ) cmd = String::ucompose( "export MTOOLSRC=%1 && mlabel -c %2:", fname, dletter ) ; else - cmd = String::ucompose( "export MTOOLSRC=%1 && mlabel %2:\"%3\"", fname, dletter, partition .label ) ; + cmd = String::ucompose( "export MTOOLSRC=%1 && mlabel %2:\"%3\"", fname, dletter, Utils::fat_compliant_label( partition .label ) ) ; operationdetail .add_child( OperationDetail( cmd, STATUS_NONE, FONT_BOLD_ITALIC ) ) ; int exit_status = Utils::execute_command( cmd, output, error ) ; @@ -151,7 +151,7 @@ bool fat32::write_label( const Partition & partition, OperationDetail & operatio bool fat32::create( const Partition & new_partition, OperationDetail & operationdetail ) { - return ! execute_command( "mkdosfs -F32 -v -n \"" + new_partition .label + "\" " + new_partition .get_path(), operationdetail ) ; + return ! execute_command( "mkdosfs -F32 -v -n \"" + Utils::fat_compliant_label( new_partition .label ) + "\" " + new_partition .get_path(), operationdetail ) ; } bool fat32::resize( const Partition & partition_new, OperationDetail & operationdetail, bool fill_partition )