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 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, bool dmcr, 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 void loopIds( std::list<unsigned>& l ) const;
00029
00030 int removeVolume( Volume* v );
00031 bool equalContent( const Container& rhs ) const;
00032 void logDifference( const Container& d ) const;
00033
00034 protected:
00035
00036
00037 typedef CastIterator<VIter, Loop *> LoopInter;
00038 typedef CastIterator<CVIter, const Loop *> LoopCInter;
00039 template< class Pred >
00040 struct LoopPI { typedef ContainerIter<Pred, LoopInter> type; };
00041 template< class Pred >
00042 struct LoopCPI { typedef ContainerIter<Pred, LoopCInter> type; };
00043 typedef CheckFnc<const Loop> CheckFncLoop;
00044 typedef CheckerIterator< CheckFncLoop, LoopPI<CheckFncLoop>::type,
00045 LoopInter, Loop > LoopPIterator;
00046 typedef CheckerIterator< CheckFncLoop, LoopCPI<CheckFncLoop>::type,
00047 LoopCInter, const Loop > LoopCPIterator;
00048 typedef DerefIterator<LoopPIterator,Loop> LoopIter;
00049 typedef DerefIterator<LoopCPIterator,const Loop> ConstLoopIter;
00050 typedef IterPair<LoopIter> LoopPair;
00051 typedef IterPair<ConstLoopIter> ConstLoopPair;
00052
00053 LoopPair loopPair( bool (* Check)( const Loop& )=NULL)
00054 {
00055 return( LoopPair( loopBegin( Check ), loopEnd( Check ) ));
00056 }
00057 LoopIter loopBegin( bool (* Check)( const Loop& )=NULL)
00058 {
00059 IterPair<LoopInter> p( (LoopInter(begin())), (LoopInter(end())) );
00060 return( LoopIter( LoopPIterator( p, Check )) );
00061 }
00062 LoopIter loopEnd( bool (* Check)( const Loop& )=NULL)
00063 {
00064 IterPair<LoopInter> p( (LoopInter(begin())), (LoopInter(end())) );
00065 return( LoopIter( LoopPIterator( p, Check, true )) );
00066 }
00067
00068 ConstLoopPair loopPair( bool (* Check)( const Loop& )=NULL) const
00069 {
00070 return( ConstLoopPair( loopBegin( Check ), loopEnd( Check ) ));
00071 }
00072 ConstLoopIter loopBegin( bool (* Check)( const Loop& )=NULL) const
00073 {
00074 IterPair<LoopCInter> p( (LoopCInter(begin())), (LoopCInter(end())) );
00075 return( ConstLoopIter( LoopCPIterator( p, Check )) );
00076 }
00077 ConstLoopIter loopEnd( bool (* Check)( const Loop& )=NULL) const
00078 {
00079 IterPair<LoopCInter> p( (LoopCInter(begin())), (LoopCInter(end())) );
00080 return( ConstLoopIter( LoopCPIterator( p, Check, true )) );
00081 }
00082
00083 LoopCo( Storage * const s, const string& File );
00084
00085 void getLoopData( ProcPart& ppart );
00086 bool findLoop( unsigned num, LoopIter& i );
00087 bool findLoop( unsigned num );
00088 bool findLoop( const string& file, LoopIter& i );
00089 bool findLoop( const string& file );
00090 bool findLoopDev( const string& dev, LoopIter& i );
00091 void addLoop( Loop* m );
00092 void updateEntry( const Loop* m );
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