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