Confdump Agent  1.4.0
MountEntry.cpp
Go to the documentation of this file.
00001 /* 
00002  * Confdump-Agent - Dump static and runtime system configuration
00003  * Copyright (C) 2009-2012  Straton IT, SAS
00004  * 
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  * 
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  * 
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  */
00017 
00018 extern "C"
00019 {
00020     #include <mntent.h>
00021     #include <errno.h>
00022 }
00023 
00024 #include "Confdump/System/LinuxDumper.hpp"
00025 #include "Confdump/System/Linux/MountEntry.hpp"
00026 
00027 using boost::shared_ptr;
00028 
00029 namespace Confdump
00030 {
00031 
00032 namespace System
00033 {
00034 
00035 namespace Linux
00036 {
00037 
00038 MountEntry::MountEntry( const struct mntent *entry )
00039  :  fileSystem_( QString::fromLocal8Bit( entry->mnt_fsname ) ),
00040     mountPoint_( QString::fromLocal8Bit( entry->mnt_dir ) ),
00041     type_( QString::fromLocal8Bit( entry->mnt_type ) ),
00042     options_( QString::fromLocal8Bit( entry->mnt_opts ) ),
00043     checkFrequency_( entry->mnt_freq ),
00044     checkPassNumber_( entry->mnt_passno )
00045 {
00046 }
00047 
00048 MountEntry::~MountEntry()
00049 {
00050 }
00051 
00052 QString MountEntry::fileSystem() const
00053 {
00054     return fileSystem_;
00055 }
00056 
00057 QString MountEntry::mountPoint() const
00058 {
00059     return mountPoint_;
00060 }
00061 
00062 QString MountEntry::type() const
00063 {
00064     return type_;
00065 }
00066 
00067 QString MountEntry::options() const
00068 {
00069     return options_;
00070 }
00071 
00072 std::vector< shared_ptr< MountEntry > > MountEntry::allMountEntriesFrom( boost::shared_ptr<LinuxDumper> driver, const boost::filesystem::path &fstab_path )
00073 {
00074     // FIXME: this reads the file twice, so it could be modified meanwhile. The
00075     // right way would be to write the slurped file to a temporary location and
00076     // to setmntent() the result. However, we don't have temporary files OO
00077     // handling so far.
00078 
00079     driver->systemContext().slurpConfigurationFile( fstab_path, "CD_MountEntry" );
00080     FILE *fstab = setmntent( fstab_path.string().c_str(), "r" );
00081     if ( !fstab )
00082     {
00083         using namespace boost::system;
00084         throw system_error( errno, system_category, "setmntent " + fstab_path.string() );
00085     }
00086 
00087     std::vector< shared_ptr< MountEntry > > mountEntries;
00088     while ( struct mntent *systemEntry = getmntent( fstab ) )
00089     {
00090         shared_ptr< MountEntry > entry( new MountEntry( systemEntry ) );
00091         mountEntries.push_back( entry );
00092     }
00093 
00094     return mountEntries;
00095 }
00096 
00097 } // ns Linux
00098 } // ns System
00099 } // ns Confdump
00100 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends