From 135e60141f8cc5db84b3d199fc00dd8b73a955a7 Mon Sep 17 00:00:00 2001 From: Curtis Gedak Date: Tue, 11 Nov 2008 17:19:46 +0000 Subject: [PATCH] Created class to read file system UUIDs svn path=/trunk/; revision=960 --- AUTHORS | 10 +++++---- ChangeLog | 7 ++++++ include/FS_Info.h | 39 ++++++++++++++++++++++++++++++++ include/Makefile.am | 1 + src/FS_Info.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 1 + 6 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 include/FS_Info.h create mode 100644 src/FS_Info.cc diff --git a/AUTHORS b/AUTHORS index 119fbc9f..2f8a7cb0 100644 --- a/AUTHORS +++ b/AUTHORS @@ -12,13 +12,15 @@ 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 + * Created FS_Info.h, FS_Info.cc * Rewrote read_label functionality for hfs * Wrote create, read_label, and check_repair functionality for hfs+ * Wrote read_label functionality for fat16 and fat32 filesystems - * Wrote Utils::regexp_label() function - * Wrote write partition label functionality + * Wrote following Utils:: methods: + regexp_label(), fat_compliant_label(), + create_mtoolsrc_file(), delete_mtoolsrc_file, + trim(), cleanup_cursor(), get_lang() + * Wrote partition write_label functionality * Created Dialog_Partion_Label.h, Dialog_Partition_Label.cc * Created OperationLabelPartition.h, OperationLabelPartition.cc * Maintained from official 0.3.5 release onward diff --git a/ChangeLog b/ChangeLog index ee758f0b..a583bda1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2008-11-11 Curtis Gedak + + * include/FS_Info.h, + include/Makefile.am, + src/FS_Info.cc, + src/Makefile.am: Created class to read file system UUIDs. + 2008-11-10 Curtis Gedak * src/fat16.cc, diff --git a/include/FS_Info.h b/include/FS_Info.h new file mode 100644 index 00000000..2647ff30 --- /dev/null +++ b/include/FS_Info.h @@ -0,0 +1,39 @@ +/* Copyright (C) 2008 Curtis Gedak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef FS_INFO_H_ +#define FS_INFO_H_ + +#include "../include/Utils.h" + +namespace GParted +{ + +class FS_Info +{ +public: + FS_Info() ; + ~FS_Info() ; + Glib::ustring get_uuid( const Glib::ustring & path ) ; +private: + void load_fs_info_cache() ; + Glib::ustring fs_info_cache ; +}; + +}//GParted + +#endif /*FS_INFO_H_*/ diff --git a/include/Makefile.am b/include/Makefile.am index 15fd51c0..67b0fca3 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -16,6 +16,7 @@ EXTRA_DIST = \ FileSystem.h \ Frame_Resizer_Base.h \ Frame_Resizer_Extended.h \ + FS_Info.h \ GParted_Core.h \ HBoxOperations.h \ Operation.h \ diff --git a/src/FS_Info.cc b/src/FS_Info.cc new file mode 100644 index 00000000..79d709d2 --- /dev/null +++ b/src/FS_Info.cc @@ -0,0 +1,55 @@ +/* Copyright (C) 2008 Curtis Gedak + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "../include/FS_Info.h" + +namespace GParted +{ + +FS_Info::FS_Info() +{ + load_fs_info_cache() ; +} + +FS_Info::~FS_Info() +{ +} + +void FS_Info::load_fs_info_cache() +{ + Glib::ustring output, error ; + if ( ! Glib::find_program_in_path( "blkid" ) .empty() ) + { + if ( ! Utils::execute_command( "blkid -c /dev/null", output, error, true ) ) + fs_info_cache = output ; + else + fs_info_cache = "" ; + } +} + +Glib::ustring FS_Info::get_uuid( const Glib::ustring & path ) +{ + //Retrieve the line containing the device path + Glib::ustring regexp = "^" + path + ":([^\n]*)$" ; + Glib::ustring temp = Utils::regexp_label( fs_info_cache, regexp ) ; + + //Retrieve the UUID + Glib::ustring uuid = Utils::regexp_label( temp, "UUID=\"([^\"]*)\"" ) ; + return uuid ; +} + +}//GParted diff --git a/src/Makefile.am b/src/Makefile.am index 43a91886..93c682b8 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -25,6 +25,7 @@ gpartedbin_SOURCES = \ FileSystem.cc \ Frame_Resizer_Base.cc \ Frame_Resizer_Extended.cc \ + FS_Info.cc \ GParted_Core.cc \ HBoxOperations.cc \ Operation.cc \