00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef BTRFS_CO_H
00024 #define BTRFS_CO_H
00025
00026 #include "storage/Container.h"
00027 #include "storage/Btrfs.h"
00028
00029
00030 namespace storage
00031 {
00032 class SystemInfo;
00033
00034
00035 class BtrfsCo : public Container
00036 {
00037 friend class Storage;
00038
00039 public:
00040
00041 BtrfsCo(Storage * const s);
00042 BtrfsCo(Storage * const s, SystemInfo& systeminfo);
00043 BtrfsCo(const BtrfsCo& c);
00044 virtual ~BtrfsCo();
00045
00046 void addFromVolume( const Volume& v, string& uuid );
00047 void eraseVolume( Volume* v );
00048
00049 bool existSubvolume( const string& device, const string& name );
00050 int createSubvolume( const string& device, const string& name );
00051 int removeSubvolume( const string& device, const string& name );
00052 int extendVolume( const string& device, const string& dev );
00053 int extendVolume( const string& device, const list<string>& devs );
00054 int shrinkVolume( const string& device, const string& dev );
00055 int shrinkVolume( const string& device, const list<string>& devs );
00056 bool deviceToUuid( const string& device, string& uuid );
00057
00058 int doRemove( Volume* v );
00059
00060 void changeDeviceName( const string& old, const string& nw );
00061
00062 static storage::CType staticType() { return storage::BTRFSC; }
00063 friend std::ostream& operator<< (std::ostream&, const BtrfsCo& );
00064
00065 int commitChanges( CommitStage stage, Volume* vol );
00066 void getToCommit( storage::CommitStage stage, list<const Container*>& col,
00067 list<const Volume*>& vo ) const;
00068
00069 int removeVolume( Volume* v );
00070 int removeVolume( Volume* v, bool quiet );
00071 int removeUuid( const string& uuid );
00072 bool equalContent( const Container& rhs ) const;
00073 void saveData(xmlNode* node) const;
00074 string fakeUuid();
00075
00076 virtual void logDifferenceWithVolumes(std::ostream& log, const Container& rhs) const;
00077 virtual void logData(const string& Dir) const;
00078
00079
00080 protected:
00081
00082
00083 typedef CastIterator<VIter, Btrfs *> BtrfsInter;
00084 typedef CastIterator<CVIter, const Btrfs *> BtrfsCInter;
00085 template< class Pred >
00086 struct BtrfsPI { typedef ContainerIter<Pred, BtrfsInter> type; };
00087 template< class Pred >
00088 struct BtrfsCPI { typedef ContainerIter<Pred, BtrfsCInter> type; };
00089 typedef CheckFnc<const Btrfs> CheckFncBtrfs;
00090 typedef CheckerIterator< CheckFncBtrfs, BtrfsPI<CheckFncBtrfs>::type,
00091 BtrfsInter, Btrfs > BtrfsPIterator;
00092 typedef CheckerIterator< CheckFncBtrfs, BtrfsCPI<CheckFncBtrfs>::type,
00093 BtrfsCInter, const Btrfs > BtrfsCPIterator;
00094 typedef DerefIterator<BtrfsPIterator,Btrfs> BtrfsIter;
00095 typedef DerefIterator<BtrfsCPIterator,const Btrfs> ConstBtrfsIter;
00096 typedef IterPair<BtrfsIter> BtrfsPair;
00097 typedef IterPair<ConstBtrfsIter> ConstBtrfsPair;
00098
00099 BtrfsPair btrfsPair( bool (* Check)( const Btrfs& )=NULL)
00100 {
00101 return( BtrfsPair( btrfsBegin( Check ), btrfsEnd( Check ) ));
00102 }
00103 BtrfsIter btrfsBegin( bool (* Check)( const Btrfs& )=NULL)
00104 {
00105 IterPair<BtrfsInter> p( (BtrfsInter(begin())), (BtrfsInter(end())) );
00106 return( BtrfsIter( BtrfsPIterator( p, Check )) );
00107 }
00108 BtrfsIter btrfsEnd( bool (* Check)( const Btrfs& )=NULL)
00109 {
00110 IterPair<BtrfsInter> p( (BtrfsInter(begin())), (BtrfsInter(end())) );
00111 return( BtrfsIter( BtrfsPIterator( p, Check, true )) );
00112 }
00113
00114 ConstBtrfsPair btrfsPair( bool (* Check)( const Btrfs& )=NULL) const
00115 {
00116 return( ConstBtrfsPair( btrfsBegin( Check ), btrfsEnd( Check ) ));
00117 }
00118 ConstBtrfsIter btrfsBegin( bool (* Check)( const Btrfs& )=NULL) const
00119 {
00120 IterPair<BtrfsCInter> p( (BtrfsCInter(begin())), (BtrfsCInter(end())) );
00121 return( ConstBtrfsIter( BtrfsCPIterator( p, Check )) );
00122 }
00123 ConstBtrfsIter btrfsEnd( bool (* Check)( const Btrfs& )=NULL) const
00124 {
00125 IterPair<BtrfsCInter> p( (BtrfsCInter(begin())), (BtrfsCInter(end())) );
00126 return( ConstBtrfsIter( BtrfsCPIterator( p, Check, true )) );
00127 }
00128
00129 void getBtrfsData(SystemInfo& systeminfo);
00130 bool findBtrfs( const string& uuid, BtrfsIter& i );
00131 void addBtrfs( Btrfs* m );
00132
00133 virtual void print( std::ostream& s ) const { s << *this; }
00134 virtual Container* getCopy() const { return( new BtrfsCo( *this ) ); }
00135
00136 private:
00137
00138 BtrfsCo& operator=(const BtrfsCo&);
00139
00140 };
00141
00142 }
00143
00144 #endif