Make the partition label length dependent from the file system (#689318)

fixes Bug #689318 - filesystem type specific support for partition name
                    maximum length
This commit is contained in:
sinlu bes 2012-12-16 16:41:30 +01:00 committed by Mike Fleetwood
parent 2eb50f9590
commit ecb1f57594
4 changed files with 53 additions and 2 deletions

View File

@ -158,6 +158,7 @@ public:
static Glib::ustring num_to_str( Sector number ) ;
static Glib::ustring get_color( FILESYSTEM filesystem ) ;
static Glib::RefPtr<Gdk::Pixbuf> get_color_as_pixbuf( FILESYSTEM filesystem, int width, int height ) ;
static int get_filesystem_label_maxlength( FILESYSTEM filesystem ) ;
static Glib::ustring get_filesystem_string( FILESYSTEM filesystem ) ;
static Glib::ustring get_filesystem_software( FILESYSTEM filesystem ) ;
static bool kernel_supports_fs( const Glib::ustring & fs ) ;

View File

@ -44,7 +44,7 @@ Dialog_Partition_Label::Dialog_Partition_Label( const Partition & partition )
Gtk::FILL);
//Create Text entry box
entry = manage(new Gtk::Entry());
entry->set_max_length(30);
entry->set_max_length( Utils::get_filesystem_label_maxlength( partition.filesystem ) ) ;
entry->set_width_chars(20);
entry->set_activates_default(true);
entry->set_text(partition.get_label());

View File

@ -129,7 +129,6 @@ void Dialog_Partition_New::Set_Data( const Partition & partition,
table_create .attach( * Utils::mk_label( Glib::ustring( _("Label:") ) ),
0, 1, 3, 4, Gtk::FILL ) ;
//Create Text entry box
entry .set_max_length( 30 );
entry .set_width_chars( 20 );
entry .set_activates_default( true );
entry .set_text( partition .get_label() );
@ -316,6 +315,9 @@ void Dialog_Partition_New::optionmenu_changed( bool type )
frame_resizer_base->set_rgb_partition_color(color_temp);
}
//set partition name entry box length
entry .set_max_length( Utils::get_filesystem_label_maxlength( fs.filesystem ) ) ;
frame_resizer_base ->Draw_Partition() ;
}

View File

@ -118,6 +118,54 @@ Glib::RefPtr<Gdk::Pixbuf> Utils::get_color_as_pixbuf( FILESYSTEM filesystem, int
return pixbuf ;
}
int Utils::get_filesystem_label_maxlength( FILESYSTEM filesystem )
{
switch( filesystem )
{
//All file systems commented out are not supported for labelling
// by either the new partition or label partition operations.
case FS_BTRFS : return 255 ;
//case FS_EXFAT : return ;
case FS_EXT2 : return 16 ;
case FS_EXT3 : return 16 ;
case FS_EXT4 : return 16 ;
case FS_FAT16 : return 11 ;
case FS_FAT32 : return 11 ;
//mkfs.hfsplus can create hfs and hfs+ file systems with labels up to 255
// characters. However there is no specific tool to read the labels and
// blkid, the only tool currently available, only display the first 27
// and 63 character respectively.
// Reference:
// util-linux-2.20.1/libblkid/src/superblocks/hfs.c:struct hfs_mdb
case FS_HFS : return 27 ;
case FS_HFSPLUS : return 63 ;
//mkfs.jfs and jfs_tune can create and update labels to 16 characters but
// only displays the first 11 characters. This is because version 1 jfs
// file systems only have an 11 character field for the label but version
// 2 jfs has extra fields containing a 16 character label. mkfs.jfs
// writes the extra fields containing the 16 character label, but then
// sets it to version 1 jfs. It does this to be backwardly compatible
// with jfs before 1.0.18, released May 2002. Blkid does display the
// full 16 character label by just ignoring the file system version.
// As using jfs_tune to get the label stick with an 11 character limit.
// References:
// jfsutils-1.1.15/tune/tune.c:main()
// jfsutils-1.1.15/mkfs/mkfs.c:create_aggregate()
// http://jfs.cvs.sourceforge.net/viewvc/jfs/jfsutils/NEWS?revision=HEAD
case FS_JFS : return 11 ;
case FS_LINUX_SWAP : return 15 ;
//case FS_LVM2_PV : return ;
case FS_NILFS2 : return 80 ;
case FS_NTFS : return 128 ;
case FS_REISER4 : return 16 ;
case FS_REISERFS : return 16 ;
//case FS_UFS : return ;
case FS_XFS : return 12 ;
default : return 30 ;
}
}
Glib::ustring Utils::get_filesystem_string( FILESYSTEM filesystem )
{
switch( filesystem )