|
yast2-storage
|
00001 /* 00002 * Copyright (c) [2004-2010] Novell, Inc. 00003 * 00004 * All Rights Reserved. 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of version 2 of the GNU General Public License as published 00008 * by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, but WITHOUT 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 * more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, contact Novell, Inc. 00017 * 00018 * To contact Novell about this file by physical or electronic mail, you may 00019 * find current contact information at www.novell.com. 00020 */ 00021 00022 00023 #ifndef ETC_FSTAB_H 00024 #define ETC_FSTAB_H 00025 00026 #include <string> 00027 #include <list> 00028 #include <boost/algorithm/string.hpp> 00029 00030 #include "storage/StorageInterface.h" 00031 #include "storage/AppUtil.h" 00032 00033 00034 namespace storage 00035 { 00036 using std::string; 00037 using std::list; 00038 00039 00040 class AsciiFile; 00041 struct FstabChange; 00042 00043 struct FstabEntry 00044 { 00045 FstabEntry() : freq(0), passno(0), loop(false), dmcrypt(false), noauto(false), 00046 cryptotab(false), crypttab(false), tmpcrypt(false), encr(ENC_NONE), 00047 mount_by(MOUNTBY_DEVICE) {} 00048 00049 explicit FstabEntry(const FstabChange& change) { *this = change; } 00050 00051 FstabEntry& operator=(const FstabChange& rhs); 00052 00053 friend std::ostream& operator<< (std::ostream& s, const FstabEntry &v ); 00054 00055 string device; 00056 string dentry; 00057 string mount; 00058 string fs; 00059 std::list<string> opts; 00060 int freq; 00061 int passno; 00062 bool loop; 00063 bool dmcrypt; 00064 bool noauto; 00065 bool cryptotab; 00066 bool crypttab; 00067 bool tmpcrypt; 00068 string loop_dev; 00069 string cr_opts; 00070 string cr_key; 00071 storage::EncryptType encr; 00072 storage::MountByType mount_by; 00073 00074 void calcDependent(); 00075 bool optUser() const; 00076 }; 00077 00078 00079 struct FstabChange 00080 { 00081 FstabChange() : freq(0), passno(0), encr(ENC_NONE), tmpcrypt(false) {} 00082 00083 explicit FstabChange(const FstabEntry& entry) { *this = entry; } 00084 00085 FstabChange& operator=(const FstabEntry& rhs); 00086 00087 friend std::ostream& operator<< (std::ostream& s, const FstabChange &v ); 00088 00089 string device; 00090 string dentry; 00091 string mount; 00092 string fs; 00093 std::list<string> opts; 00094 int freq; 00095 int passno; 00096 string loop_dev; 00097 storage::EncryptType encr; 00098 bool tmpcrypt; 00099 }; 00100 00101 00102 class EtcFstab 00103 { 00104 public: 00105 EtcFstab( const string& prefix = "", bool rootMounted=true ); 00106 bool findDevice( const string& dev, FstabEntry& entry ) const; 00107 bool findDevice( const std::list<string>& dl, FstabEntry& entry ) const; 00108 bool findMount( const string& mount, FstabEntry& entry ) const; 00109 bool findMount( const string& mount ) const 00110 { FstabEntry e; return( findMount( mount,e )); } 00111 bool findUuidLabel( const string& uuid, const string& label, 00112 FstabEntry& entry ) const; 00113 bool findIdPath(const list<string>& id, const string& path, FstabEntry& entry) const; 00114 void setDevice( const FstabEntry& entry, const string& device ); 00115 int updateEntry( const FstabChange& entry ); 00116 int addEntry( const FstabChange& entry ); 00117 int removeEntry( const FstabEntry& entry ); 00118 int changeRootPrefix( const string& prfix ); 00119 void getFileBasedLoops( const string& prefix, std::list<FstabEntry>& l ) const; 00120 list<FstabEntry> getEntries() const; 00121 Text addText( bool doing, bool crypto, const string& mp ) const; 00122 Text updateText( bool doing, bool crypto, const string& mp ) const; 00123 Text removeText( bool doing, bool crypto, const string& mp ) const; 00124 int flush(); 00125 00126 protected: 00127 struct Entry 00128 { 00129 enum operation { NONE, ADD, REMOVE, UPDATE }; 00130 Entry() : op(NONE) {} 00131 operation op; 00132 FstabEntry nnew; 00133 FstabEntry old; 00134 }; 00135 00136 void readFiles(); 00137 00138 int findPrefix( const AsciiFile& tab, const string& mount ) const; 00139 00140 AsciiFile* findFile( const FstabEntry& e, AsciiFile*& fstab, 00141 AsciiFile*& cryptotab, int& lineno ) const; 00142 00143 bool findCrtab( const FstabEntry& e, const AsciiFile& crtab, 00144 int& lineno ) const; 00145 bool findCrtab( const string& device, const AsciiFile& crtab, 00146 int& lineno ) const; 00147 00148 string updateLine( const std::list<string>& ol, 00149 const std::list<string>& nl, const string& line ) const; 00150 string createLine( const std::list<string>& ls, unsigned fields, 00151 const unsigned* flen ) const; 00152 00153 string createTabLine( const FstabEntry& e ) const; 00154 string createCrtabLine( const FstabEntry& e ) const; 00155 void updateTabLine( list<string>(*fnc)(const FstabEntry& e), 00156 const FstabEntry& old, const FstabEntry& nnew, 00157 string& line ) const; 00158 00159 static string fstabEncode(const string&); 00160 static string fstabDecode(const string&); 00161 00162 static const unsigned fstabFields[6]; 00163 static const unsigned cryptotabFields[6]; 00164 static const unsigned crypttabFields[6]; 00165 00166 string prefix; 00167 std::list<Entry> co; 00168 }; 00169 00170 } 00171 00172 #endif
1.7.3