00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LOOP_CO_H
00024 #define LOOP_CO_H
00025
00026 #include "y2storage/Container.h"
00027 #include "y2storage/Loop.h"
00028
00029 namespace storage
00030 {
00031 class ProcPart;
00032
00033 class LoopCo : public Container
00034 {
00035 friend class Storage;
00036
00037 public:
00038 LoopCo( Storage * const s, bool detect, ProcPart& ppart );
00039 LoopCo( const LoopCo& rhs );
00040
00041 virtual ~LoopCo();
00042 static storage::CType staticType() { return storage::LOOP; }
00043 friend std::ostream& operator<< (std::ostream&, const LoopCo& );
00044
00045 int createLoop( const string& file, bool reuseExisting,
00046 unsigned long long sizeK, bool dmcr, string& device );
00047 int updateLoop( const string& device, const string& file,
00048 bool reuseExisting, unsigned long long sizeK );
00049 int removeLoop( const string& file, bool removeFile = false );
00050 void loopIds( std::list<unsigned>& l ) const;
00051
00052 int removeVolume( Volume* v );
00053 bool equalContent( const Container& rhs ) const;
00054 void logDifference( const Container& d ) const;
00055
00056 protected:
00057
00058
00059 typedef CastIterator<VIter, Loop *> LoopInter;
00060 typedef CastIterator<CVIter, const Loop *> LoopCInter;
00061 template< class Pred >
00062 struct LoopPI { typedef ContainerIter<Pred, LoopInter> type; };
00063 template< class Pred >
00064 struct LoopCPI { typedef ContainerIter<Pred, LoopCInter> type; };
00065 typedef CheckFnc<const Loop> CheckFncLoop;
00066 typedef CheckerIterator< CheckFncLoop, LoopPI<CheckFncLoop>::type,
00067 LoopInter, Loop > LoopPIterator;
00068 typedef CheckerIterator< CheckFncLoop, LoopCPI<CheckFncLoop>::type,
00069 LoopCInter, const Loop > LoopCPIterator;
00070 typedef DerefIterator<LoopPIterator,Loop> LoopIter;
00071 typedef DerefIterator<LoopCPIterator,const Loop> ConstLoopIter;
00072 typedef IterPair<LoopIter> LoopPair;
00073 typedef IterPair<ConstLoopIter> ConstLoopPair;
00074
00075 LoopPair loopPair( bool (* Check)( const Loop& )=NULL)
00076 {
00077 return( LoopPair( loopBegin( Check ), loopEnd( Check ) ));
00078 }
00079 LoopIter loopBegin( bool (* Check)( const Loop& )=NULL)
00080 {
00081 IterPair<LoopInter> p( (LoopInter(begin())), (LoopInter(end())) );
00082 return( LoopIter( LoopPIterator( p, Check )) );
00083 }
00084 LoopIter loopEnd( bool (* Check)( const Loop& )=NULL)
00085 {
00086 IterPair<LoopInter> p( (LoopInter(begin())), (LoopInter(end())) );
00087 return( LoopIter( LoopPIterator( p, Check, true )) );
00088 }
00089
00090 ConstLoopPair loopPair( bool (* Check)( const Loop& )=NULL) const
00091 {
00092 return( ConstLoopPair( loopBegin( Check ), loopEnd( Check ) ));
00093 }
00094 ConstLoopIter loopBegin( bool (* Check)( const Loop& )=NULL) const
00095 {
00096 IterPair<LoopCInter> p( (LoopCInter(begin())), (LoopCInter(end())) );
00097 return( ConstLoopIter( LoopCPIterator( p, Check )) );
00098 }
00099 ConstLoopIter loopEnd( bool (* Check)( const Loop& )=NULL) const
00100 {
00101 IterPair<LoopCInter> p( (LoopCInter(begin())), (LoopCInter(end())) );
00102 return( ConstLoopIter( LoopCPIterator( p, Check, true )) );
00103 }
00104
00105 LoopCo( Storage * const s, const string& File );
00106
00107 void getLoopData( ProcPart& ppart );
00108 bool findLoop( unsigned num, LoopIter& i );
00109 bool findLoop( unsigned num );
00110 bool findLoop( const string& file, LoopIter& i );
00111 bool findLoop( const string& file );
00112 bool findLoopDev( const string& dev, LoopIter& i );
00113 void addLoop( Loop* m );
00114 void updateEntry( const Loop* m );
00115
00116 void init();
00117
00118 virtual void print( std::ostream& s ) const { s << *this; }
00119 virtual Container* getCopy() const { return( new LoopCo( *this ) ); }
00120
00121 int doCreate( Volume* v );
00122 int doRemove( Volume* v );
00123
00124 void logData( const string& Dir );
00125 };
00126
00127 }
00128
00129 #endif