EtcFstab.h

Go to the documentation of this file.
00001 #ifndef ETC_FSTAB_H
00002 #define ETC_FSTAB_H
00003 
00004 #include <string>
00005 #include <list>
00006 #include <map>
00007 
00008 #include "y2storage/StorageInterface.h"
00009 
00010 namespace storage
00011 {
00012 
00013 class AsciiFile;
00014 struct FstabChange;
00015 
00016 struct FstabEntry
00017     {
00018     FstabEntry() { freq=passno=0; crypto=loop=noauto=false;
00019                    encr=storage::ENC_NONE; mount_by=storage::MOUNTBY_DEVICE; }
00020     FstabEntry& operator=( const FstabChange& rhs );
00021     friend std::ostream& operator<< (std::ostream& s, const FstabEntry &v );
00022 
00023     string device;
00024     string dentry;
00025     string mount;
00026     string fs;
00027     std::list<string> opts;
00028     int freq;
00029     int passno;
00030     bool loop;
00031     bool noauto;
00032     bool crypto;
00033     string loop_dev;
00034     storage::EncryptType encr;
00035     storage::MountByType mount_by;
00036 
00037     void calcDependent();
00038     };
00039 
00040 inline std::ostream& operator<< (std::ostream& s, const FstabEntry &v )
00041     {
00042     s << "device:" << v.device
00043       << " dentry:" << v.dentry << " mount:" << v.mount
00044       << " fs:" << v.fs << " opts:" << mergeString( v.opts, "," )
00045       << " freq:" << v.freq << " passno:" << v.passno;
00046     if( v.noauto )
00047         s << " noauto";
00048     if( v.crypto )
00049         s << " crypto";
00050     if( v.loop )
00051         s << " loop";
00052     if( !v.loop_dev.empty() )
00053         s << " loop_dev:" << v.loop_dev;
00054     if( v.encr != storage::ENC_NONE )
00055         s << " encr:" << v.encr;
00056     return( s );
00057     }
00058 
00059 struct FstabChange
00060     {
00061     FstabChange() { freq=passno=0; encr=storage::ENC_NONE; }
00062     FstabChange( const FstabEntry& e ) { *this = e; }
00063     FstabChange& operator=( const FstabEntry& rhs )
00064         {
00065         device = rhs.device;
00066         dentry = rhs.dentry; mount = rhs.mount; fs = rhs.fs;
00067         opts = rhs.opts; freq = rhs.freq; passno = rhs.passno;
00068         loop_dev = rhs.loop_dev; encr = rhs.encr;
00069         return( *this );
00070         }
00071     friend std::ostream& operator<< (std::ostream& s, const FstabChange &v );
00072     string device;
00073     string dentry;
00074     string mount;
00075     string fs;
00076     std::list<string> opts;
00077     int freq;
00078     int passno;
00079     string loop_dev;
00080     storage::EncryptType encr;
00081     };
00082 
00083 inline FstabEntry& FstabEntry::operator=( const FstabChange& rhs )
00084     {
00085     device = rhs.device;
00086     dentry = rhs.dentry; mount = rhs.mount; fs = rhs.fs;
00087     opts = rhs.opts; freq = rhs.freq; passno = rhs.passno;
00088     loop_dev = rhs.loop_dev; encr = rhs.encr;
00089     calcDependent();
00090     return( *this );
00091     }
00092 
00093 inline std::ostream& operator<< (std::ostream& s, const FstabChange &v )
00094     {
00095     s << "device:" << v.device
00096       << " dentry:" << v.dentry << " mount:" << v.mount
00097       << " fs:" << v.fs << " opts:" << mergeString( v.opts, "," )
00098       << " freq:" << v.freq << " passno:" << v.passno;
00099     if( !v.loop_dev.empty() )
00100         s << " loop_dev:" << v.loop_dev;
00101     if( v.encr != storage::ENC_NONE )
00102         s << " encr:" << v.encr;
00103     return( s );
00104     }
00105 
00106 class EtcFstab
00107     {
00108     public:
00109         EtcFstab( const string& prefix = "", bool rootMounted=true );
00110         bool findDevice( const string& dev, FstabEntry& entry ) const;
00111         bool findDevice( const std::list<string>& dl, FstabEntry& entry ) const;
00112         bool findMount( const string& mount, FstabEntry& entry ) const;
00113         bool findUuidLabel( const string& uuid, const string& label,
00114                             FstabEntry& entry ) const;
00115         bool findIdPath( const std::list<string>& id, const string& path,
00116                          FstabEntry& entry ) const;
00117         void setDevice( const FstabEntry& entry, const string& device );
00118         int updateEntry( const string& dev, const string& mount,
00119                          const string& fs, const string& opts="defaults" );
00120         int updateEntry( const FstabChange& entry );
00121         int addEntry( const FstabChange& entry );
00122         int removeEntry( const FstabEntry& entry );
00123         int changeRootPrefix( const string& prfix );
00124         void getFileBasedLoops( const string& prefix, std::list<FstabEntry>& l );
00125         void getEntries( std::list<FstabEntry>& l );
00126         string addText( bool doing, bool crypto, const string& mp );
00127         string updateText( bool doing, bool crypto, const string& mp );
00128         string removeText( bool doing, bool crypto, const string& mp );
00129         int flush();
00130 
00131     protected:
00132         struct Entry
00133             {
00134             enum operation { NONE, ADD, REMOVE, UPDATE };
00135             Entry() { op=NONE; }
00136             operation op;
00137             FstabEntry nnew;
00138             FstabEntry old;
00139             };
00140 
00141         void readFiles();
00142         AsciiFile* findFile( const FstabEntry& e, AsciiFile*& fstab,
00143                              AsciiFile*& cryptotab, int& lineno );
00144         void makeStringList( const FstabEntry& e, std::list<string>& ls );
00145         string createTabLine( const FstabEntry& e );
00146 
00147         static unsigned fstabFields[6];
00148         static unsigned cryptotabFields[6];
00149 
00150         string prefix;
00151         std::list<Entry> co;
00152     };
00153 
00154 }
00155 
00156 #endif

Generated on Thu Jul 6 00:40:24 2006 for yast2-storage by  doxygen 1.4.6