|
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 STORAGE_TYPES_H 00024 #define STORAGE_TYPES_H 00025 00026 00027 #include <string> 00028 #include <vector> 00029 #include <ostream> 00030 #include <boost/algorithm/string.hpp> 00031 00032 #include "storage/Regex.h" 00033 #include "storage/AppUtil.h" 00034 #include "storage/StorageInterface.h" 00035 #include "storage/XmlFile.h" 00036 #include "storage/Enum.h" 00037 00038 00039 namespace storage 00040 { 00041 using std::string; 00042 using std::vector; 00043 00044 00045 inline bool operator<(CType a, CType b) 00046 { 00047 static const int order[] = { 00048 0, // CUNKNOWN 00049 1, // DISK 00050 5, // MD 00051 8, // LOOP 00052 7, // LVM 00053 6, // DM 00054 2, // DMRAID 00055 9, // NFSC 00056 3, // DMMULTIPATH 00057 4, // MDPART 00058 10, // BTRFSC 00059 }; 00060 00061 bool ret = order[a] < order[b]; 00062 y2mil("a:" << toString(a) << " o(a):" << order[a] << " b:" << toString(b) << " o(b):" << 00063 order[b] << " ret:" << ret); 00064 return ret; 00065 } 00066 00067 inline bool operator<=( CType a, CType b ) 00068 { 00069 return( a==b || a<b ); 00070 } 00071 00072 inline bool operator>=( CType a, CType b ) 00073 { 00074 return( !(a<b) ); 00075 } 00076 00077 inline bool operator>( CType a, CType b ) 00078 { 00079 return( a!=b && !(a<b) ); 00080 } 00081 00082 struct contOrder 00083 { 00084 contOrder(CType t) : order(0) 00085 { 00086 if( t==LOOP ) 00087 order=1; 00088 } 00089 operator unsigned() const { return( order ); } 00090 protected: 00091 unsigned order; 00092 }; 00093 00094 std::ostream& operator<<(std::ostream& s, const PartitionSlotInfo& a); 00095 std::ostream& operator<<(std::ostream& s, const FsCapabilities& a); 00096 00097 enum CommitStage { DECREASE, INCREASE, FORMAT, SUBVOL, MOUNT }; 00098 00099 00100 class Volume; 00101 class Container; 00102 00103 struct commitAction 00104 { 00105 commitAction(CommitStage s, CType t, const Text& d, const Volume* v, 00106 bool destr = false) 00107 : stage(s), type(t), description(d), destructive(destr), container(false), u(v) 00108 { 00109 } 00110 00111 commitAction(CommitStage s, CType t, const Text& d, const Container* c, 00112 bool destr = false) 00113 : stage(s), type(t), description(d), destructive(destr), container(true), u(c) 00114 { 00115 } 00116 00117 commitAction(CommitStage s, CType t, const Volume* v) 00118 : stage(s), type(t), description(), destructive(false), container(false), u(v) 00119 { 00120 } 00121 00122 commitAction(CommitStage s, CType t, const Container* c) 00123 : stage(s), type(t), description(), destructive(false), container(true), u(c) 00124 { 00125 } 00126 00127 const CommitStage stage; 00128 const CType type; 00129 const Text description; 00130 const bool destructive; 00131 const bool container; 00132 00133 const union U 00134 { 00135 U(const Volume* v) : vol(v) {} 00136 U(const Container* c) : co(c) {} 00137 00138 const Volume* vol; 00139 const Container* co; 00140 } u; 00141 00142 const Container* co() const { return container ? u.co : NULL; } 00143 const Volume* vol() const { return container ? NULL : u.vol; } 00144 00145 bool operator==(const commitAction& rhs) const 00146 { return stage == rhs.stage && type == rhs.type; } 00147 bool operator<(const commitAction& rhs) const; 00148 bool operator<=(const commitAction& rhs) const 00149 { return *this < rhs || *this == rhs; } 00150 bool operator>=(const commitAction& rhs) const 00151 { return !(*this < rhs); } 00152 bool operator>(const commitAction& rhs) const 00153 { return !(*this < rhs && *this == rhs); } 00154 00155 friend std::ostream& operator<<(std::ostream& s, const commitAction& a); 00156 }; 00157 00158 00159 struct stage_is 00160 { 00161 stage_is(CommitStage t) : val(t) {} 00162 bool operator()(const commitAction& t) const { return t.stage == val; } 00163 const CommitStage val; 00164 }; 00165 00166 00167 class UsedBy 00168 { 00169 00170 public: 00171 00172 UsedBy(UsedByType type, const string& device) : ub_type(type), ub_device(device) {} 00173 00174 bool operator==(const UsedBy& rhs) const 00175 { return ub_type == rhs.ub_type && ub_device == rhs.ub_device; } 00176 bool operator!=(const UsedBy& rhs) const 00177 { return !(*this == rhs); } 00178 00179 UsedByType type() const { return ub_type; } 00180 string device() const { return ub_device; } 00181 00182 friend std::ostream& operator<<(std::ostream&, const UsedBy&); 00183 00184 friend void setChildValue(xmlNode* node, const char* name, const UsedBy& value); 00185 00186 operator UsedByInfo() const { return UsedByInfo(ub_type, ub_device); } 00187 00188 private: 00189 00190 UsedByType ub_type; 00191 string ub_device; 00192 00193 }; 00194 00195 class Subvolume 00196 { 00197 00198 public: 00199 00200 Subvolume(const string& path) : p(path), del(false), create(false) {} 00201 Subvolume(const xmlNode* node) : p() 00202 { 00203 getChildValue(node, "path", p); 00204 } 00205 00206 bool operator==(const Subvolume& rhs) const 00207 { return p == rhs.p && del == rhs.del; } 00208 bool operator!=(const Subvolume& rhs) const 00209 { return !(*this == rhs); } 00210 00211 string path() const { return p; } 00212 bool deleted() const { return del; } 00213 void setDeleted( bool val=true ) { del=val; } 00214 bool created() const { return create; } 00215 void setCreated( bool val=true ) { create=val; } 00216 00217 friend std::ostream& operator<<(std::ostream&, const Subvolume&); 00218 00219 friend void setChildValue(xmlNode* node, const char* name, const Subvolume& value); 00220 00221 operator SubvolInfo() const { return SubvolInfo(p); } 00222 00223 private: 00224 string p; 00225 bool del; 00226 bool create; 00227 00228 }; 00229 00230 00231 struct regex_matches 00232 { 00233 regex_matches(const Regex& t) : val(t) {} 00234 bool operator()(const string& s) const { return val.match(s); } 00235 const Regex& val; 00236 }; 00237 00238 struct string_starts_with 00239 { 00240 string_starts_with(const string& t) : val(t) {} 00241 bool operator()(const string& s) const { return boost::starts_with(s, val); } 00242 const string& val; 00243 }; 00244 00245 struct string_contains 00246 { 00247 string_contains(const string& t) : val(t) {} 00248 bool operator()(const string& s) const { return boost::contains(s, val); } 00249 const string& val; 00250 }; 00251 00252 00253 template <class Pred> 00254 vector<string>::iterator 00255 find_if(vector<string>& lines, Pred pred) 00256 { 00257 return std::find_if(lines.begin(), lines.end(), pred); 00258 } 00259 00260 template <class Pred> 00261 vector<string>::const_iterator 00262 find_if(const vector<string>& lines, Pred pred) 00263 { 00264 return std::find_if(lines.begin(), lines.end(), pred); 00265 } 00266 00267 } 00268 00269 00270 #endif
1.7.3