00001 #ifndef STORAGE_TYPES_H
00002 #define STORAGE_TYPES_H
00003
00004 #include <iostream>
00005 #include <ext/stdio_filebuf.h>
00006
00007 #include "y2storage/Regex.h"
00008 #include "y2storage/AppUtil.h"
00009 #include "y2storage/StorageInterface.h"
00010
00011 namespace storage
00012 {
00013
00014 inline bool operator<( CType a, CType b )
00015 {
00016 static int order[COTYPE_LAST_ENTRY] = { 0, 1, 3, 7, 5, 4, 6, 2, 8 };
00017 bool ret = order[a] < order[b];
00018 y2mil( "a:" << a << " o(a):" << order[a] << " b:" << b << " o(b):" << order[b] << " ret:" << ret );
00019 return( ret );
00020 }
00021
00022 inline bool operator<=( CType a, CType b )
00023 {
00024 return( a==b || a<b );
00025 }
00026
00027 inline bool operator>=( CType a, CType b )
00028 {
00029 return( !(a<b) );
00030 }
00031
00032 inline bool operator>( CType a, CType b )
00033 {
00034 return( a!=b && !(a<b) );
00035 }
00036
00037 struct contOrder
00038 {
00039 contOrder(CType t) : order(0)
00040 {
00041 if( t==LOOP )
00042 order=1;
00043 }
00044 operator unsigned() const { return( order ); }
00045 protected:
00046 unsigned order;
00047 };
00048
00049 typedef enum { DECREASE, INCREASE, FORMAT, MOUNT } CommitStage;
00050
00051 class Volume;
00052 class Container;
00053
00054 struct commitAction
00055 {
00056 commitAction( CommitStage s, CType t, const string& d, const Volume* v,
00057 bool destr=false )
00058 { stage=s; type=t; descr=d; destructive=destr; container=false;
00059 u.vol=v; }
00060 commitAction( CommitStage s, CType t, const string& d, const Container* co,
00061 bool destr=false )
00062 { stage=s; type=t; descr=d; destructive=destr; container=true;
00063 u.co=co; }
00064 commitAction( CommitStage s, CType t, Volume* v )
00065 { stage=s; type=t; destructive=false; container=false; u.vol=v; }
00066 commitAction( CommitStage s, CType t, Container* c )
00067 { stage=s; type=t; destructive=false; container=true; u.co=c; }
00068 CommitStage stage;
00069 CType type;
00070 string descr;
00071 bool destructive;
00072 bool container;
00073 union
00074 {
00075 const Volume* vol;
00076 const Container* co;
00077 } u;
00078 const Container* co() const { return( container?u.co:NULL ); }
00079 const Volume* vol() const { return( container?NULL:u.vol ); }
00080 bool operator==( const commitAction& rhs ) const
00081 { return( stage==rhs.stage && type==rhs.type ); }
00082 bool operator<( const commitAction& rhs ) const;
00083 bool operator<=( const commitAction& rhs ) const
00084 { return( *this < rhs || *this == rhs ); }
00085 bool operator>=( const commitAction& rhs ) const
00086 { return( ! (*this < rhs) ); }
00087 bool operator>( const commitAction& rhs ) const
00088 { return( !(*this < rhs && *this == rhs) ); }
00089 };
00090
00091 struct usedBy
00092 {
00093 usedBy() : t(storage::UB_NONE) {;}
00094 usedBy( storage::UsedByType typ, const string& n ) : t(typ), nm(n) {;}
00095 void clear() { t=storage::UB_NONE; nm.erase(); }
00096 void set( storage::UsedByType type, const string& n )
00097 { t=type; (t==storage::UB_NONE)?nm.erase():nm=n; }
00098 bool operator==( const usedBy& rhs ) const
00099 { return( t==rhs.t && nm==rhs.nm ); }
00100 bool operator!=( const usedBy& rhs ) const
00101 { return( !(*this==rhs)); }
00102 inline operator string() const;
00103
00104 storage::UsedByType type() const { return( t ); }
00105 const string& name() const { return( nm ); }
00106 friend inline std::ostream& operator<< (std::ostream&, const usedBy& );
00107
00108 storage::UsedByType t;
00109 string nm;
00110 };
00111
00112 inline usedBy::operator string() const
00113 {
00114 string st;
00115 if( t!=storage::UB_NONE )
00116 {
00117 switch( t )
00118 {
00119 case storage::UB_LVM:
00120 st = "lvm";
00121 break;
00122 case storage::UB_MD:
00123 st = "md";
00124 break;
00125 case storage::UB_EVMS:
00126 st = "evms";
00127 break;
00128 case storage::UB_DM:
00129 st = "dm";
00130 break;
00131 case storage::UB_DMRAID:
00132 st = "dmraid";
00133 break;
00134 default:
00135 st = "UNKNOWN";
00136 break;
00137 }
00138 st += "[" + nm + "]";
00139 }
00140 return( st );
00141 }
00142
00143 inline std::ostream& operator<< (std::ostream& s, const usedBy& d )
00144 {
00145 if( d.t!=storage::UB_NONE )
00146 {
00147 s << " UsedBy:" << string(d);
00148 }
00149 return( s );
00150 }
00151
00152 struct match_string
00153 {
00154 match_string( const string& t ) : r(t) {};
00155 bool operator()(const string&s) { return( r.match( s )); }
00156 Regex r;
00157 };
00158
00159 struct find_begin
00160 {
00161 find_begin( const string& t ) : val(t) {};
00162 bool operator()(const string&s) { return( s.find(val)==0 ); }
00163 const string& val;
00164 };
00165
00166 struct find_any
00167 {
00168 find_any( const string& t ) : val(t) {};
00169 bool operator()(const string&s) { return( s.find(val)!=string::npos ); }
00170 const string& val;
00171 };
00172
00173 }
00174
00175 #endif