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 #include "y2storage/AppUtil.h"
00010 
00011 namespace storage
00012 {
00013 
00014 class AsciiFile;
00015 struct FstabChange;
00016 
00017 struct FstabEntry
00018     {
00019     FstabEntry() { freq=passno=0; 
00020                    crypto=cryptt=loop=noauto=dmcrypt=tmpcrypt=false;
00021                    encr=storage::ENC_NONE; mount_by=storage::MOUNTBY_DEVICE; }
00022     FstabEntry& operator=( const FstabChange& rhs );
00023     friend std::ostream& operator<< (std::ostream& s, const FstabEntry &v );
00024 
00025     string device;
00026     string dentry;
00027     string mount;
00028     string fs;
00029     std::list<string> opts;
00030     int freq;
00031     int passno;
00032     bool loop;
00033     bool dmcrypt;
00034     bool noauto;
00035     bool crypto;
00036     bool cryptt;
00037     bool tmpcrypt;
00038     string loop_dev;
00039     string cr_opts;
00040     string cr_key;
00041     storage::EncryptType encr;
00042     storage::MountByType mount_by;
00043 
00044     void calcDependent();
00045     };
00046 
00047 inline std::ostream& operator<< (std::ostream& s, const FstabEntry &v )
00048     {
00049     s << "device:" << v.device
00050       << " dentry:" << v.dentry << " mount:" << v.mount
00051       << " fs:" << v.fs << " opts:" << mergeString( v.opts, "," )
00052       << " freq:" << v.freq << " passno:" << v.passno;
00053     if( v.noauto )
00054         s << " noauto";
00055     if( v.crypto )
00056         s << " crypto";
00057     if( v.cryptt )
00058         s << " cryptt";
00059     if( v.tmpcrypt )
00060         s << " tmpcrypt";
00061     if( v.loop )
00062         s << " loop";
00063     if( v.dmcrypt )
00064         s << " dmcrypt";
00065     if( !v.loop_dev.empty() )
00066         s << " loop_dev:" << v.loop_dev;
00067     if( !v.cr_key.empty() )
00068         s << " cr_key:" << v.cr_key;
00069     if( !v.cr_opts.empty() )
00070         s << " cr_opts:" << v.cr_opts;
00071     if( v.encr != storage::ENC_NONE )
00072         s << " encr:" << v.encr;
00073     return( s );
00074     }
00075 
00076 struct FstabChange
00077     {
00078     FstabChange() { freq=passno=0; encr=storage::ENC_NONE; tmpcrypt=false; }
00079     FstabChange( const FstabEntry& e ) { *this = e; }
00080     FstabChange& operator=( const FstabEntry& rhs )
00081         {
00082         device = rhs.device;
00083         dentry = rhs.dentry; mount = rhs.mount; fs = rhs.fs;
00084         opts = rhs.opts; freq = rhs.freq; passno = rhs.passno;
00085         loop_dev = rhs.loop_dev; encr = rhs.encr; 
00086         tmpcrypt = rhs.tmpcrypt;
00087         return( *this );
00088         }
00089     friend std::ostream& operator<< (std::ostream& s, const FstabChange &v );
00090     string device;
00091     string dentry;
00092     string mount;
00093     string fs;
00094     std::list<string> opts;
00095     int freq;
00096     int passno;
00097     string loop_dev;
00098     storage::EncryptType encr;
00099     bool tmpcrypt;
00100     };
00101 
00102 inline FstabEntry& FstabEntry::operator=( const FstabChange& rhs )
00103     {
00104     device = rhs.device;
00105     dentry = rhs.dentry; mount = rhs.mount; fs = rhs.fs;
00106     opts = rhs.opts; freq = rhs.freq; passno = rhs.passno;
00107     loop_dev = rhs.loop_dev; encr = rhs.encr;
00108     tmpcrypt = rhs.tmpcrypt;
00109     calcDependent();
00110     return( *this );
00111     }
00112 
00113 inline std::ostream& operator<< (std::ostream& s, const FstabChange &v )
00114     {
00115     s << "device:" << v.device
00116       << " dentry:" << v.dentry << " mount:" << v.mount
00117       << " fs:" << v.fs << " opts:" << mergeString( v.opts, "," )
00118       << " freq:" << v.freq << " passno:" << v.passno;
00119     if( !v.loop_dev.empty() )
00120         s << " loop_dev:" << v.loop_dev;
00121     if( v.encr != storage::ENC_NONE )
00122         s << " encr:" << v.encr;
00123     if( v.tmpcrypt )
00124         s << " tmpcrypt";
00125     return( s );
00126     }
00127 
00128 class EtcFstab
00129     {
00130     public:
00131         EtcFstab( const string& prefix = "", bool rootMounted=true );
00132         bool findDevice( const string& dev, FstabEntry& entry ) const;
00133         bool findDevice( const std::list<string>& dl, FstabEntry& entry ) const;
00134         bool findMount( const string& mount, FstabEntry& entry ) const;
00135         bool findUuidLabel( const string& uuid, const string& label,
00136                             FstabEntry& entry ) const;
00137         bool findIdPath( const std::list<string>& id, const string& path,
00138                          FstabEntry& entry ) const;
00139         void setDevice( const FstabEntry& entry, const string& device );
00140         int updateEntry( const string& dev, const string& mount,
00141                          const string& fs, const string& opts="defaults" );
00142         int updateEntry( const FstabChange& entry );
00143         int addEntry( const FstabChange& entry );
00144         int removeEntry( const FstabEntry& entry );
00145         int changeRootPrefix( const string& prfix );
00146         void getFileBasedLoops( const string& prefix, std::list<FstabEntry>& l );
00147         void getEntries( std::list<FstabEntry>& l );
00148         string addText( bool doing, bool crypto, const string& mp );
00149         string updateText( bool doing, bool crypto, const string& mp );
00150         string removeText( bool doing, bool crypto, const string& mp );
00151         int flush();
00152         int findPrefix( const AsciiFile& tab, const string& mount );
00153 
00154     protected:
00155         struct Entry
00156             {
00157             enum operation { NONE, ADD, REMOVE, UPDATE };
00158             Entry() { op=NONE; }
00159             operation op;
00160             FstabEntry nnew;
00161             FstabEntry old;
00162             };
00163 
00164         void readFiles();
00165         AsciiFile* findFile( const FstabEntry& e, AsciiFile*& fstab,
00166                              AsciiFile*& cryptotab, int& lineno );
00167         bool findCrtab( const FstabEntry& e, const AsciiFile& crtab,
00168                         int& lineno );
00169         bool findCrtab( const string& device, const AsciiFile& crtab,
00170                         int& lineno );
00171         void makeStringList( const FstabEntry& e, std::list<string>& ls );
00172         void makeCrtabStringList( const FstabEntry& e, std::list<string>& ls );
00173         string updateLine( const std::list<string>& ol, 
00174                            const std::list<string>& nl, const string& line );
00175         string createLine( const std::list<string>& ls, unsigned fields, 
00176                            unsigned* flen );
00177         string createTabLine( const FstabEntry& e );
00178         void makeCrStringList( const FstabEntry& e, std::list<string>& ls );
00179         string createCrtabLine( const FstabEntry& e );
00180 
00181         static unsigned fstabFields[6];
00182         static unsigned cryptotabFields[6];
00183         static unsigned crypttabFields[6];
00184 
00185         string prefix;
00186         std::list<Entry> co;
00187     };
00188 
00189 }
00190 
00191 #endif

Generated on Tue Sep 25 21:19:22 2007 for yast2-storage by  doxygen 1.5.3