00001 #ifndef DM_PART_CO_H
00002 #define DM_PART_CO_H
00003
00004 #include <list>
00005
00006 #include "y2storage/PeContainer.h"
00007 #include "y2storage/Disk.h"
00008 #include "y2storage/DmPart.h"
00009
00010 namespace storage
00011 {
00012
00013 class Storage;
00014 class SystemCmd;
00015 class ProcPart;
00016 class Region;
00017
00018 class DmPartCo : public PeContainer
00019 {
00020 friend class Storage;
00021
00022 public:
00023 DmPartCo( Storage * const s, const string& Name, storage::CType t,
00024 ProcPart& ppart );
00025 DmPartCo( const DmPartCo& rhs );
00026 virtual ~DmPartCo();
00027
00028 unsigned long long sizeK() const { return size_k; }
00029 unsigned isValid() const { return valid; }
00030 const string& labelName() const { return disk->labelName(); }
00031 const string& udevPath() const { return udev_path; }
00032 const std::list<string>& udevId() const { return udev_id; }
00033 unsigned numPartitions() const { return disk->numPartitions(); }
00034 static storage::CType staticType() { return storage::DMRAID; }
00035 friend std::ostream& operator<< (std::ostream&, const DmPartCo& );
00036 void setUdevData(const list<string>& id);
00037
00038 int createPartition( storage::PartitionType type, long unsigned start,
00039 long unsigned len, string& device,
00040 bool checkRelaxed=false );
00041 int createPartition( long unsigned len, string& device,
00042 bool checkRelaxed=false );
00043 int createPartition( storage::PartitionType type, string& device );
00044 int removePartition( unsigned nr );
00045 int changePartitionId( unsigned nr, unsigned id );
00046 int forgetChangePartitionId( unsigned nr );
00047 int changePartitionArea( unsigned nr, unsigned long start,
00048 unsigned long size, bool checkRelaxed=false );
00049 int nextFreePartition(storage::PartitionType type, unsigned& nr,
00050 string& device) const;
00051 int destroyPartitionTable( const string& new_label );
00052 int freeCylindersAfterPartition(const DmPart* p, unsigned long& freeCyls) const;
00053 int resizePartition( DmPart* p, unsigned long newCyl );
00054 int resizeVolume( Volume* v, unsigned long long newSize );
00055 int removeVolume( Volume* v );
00056 int removeDmPart();
00057
00058 unsigned maxPrimary() const { return disk->maxPrimary(); }
00059 bool extendedPossible() const { return disk->extendedPossible(); }
00060 unsigned maxLogical() const { return disk->maxLogical(); }
00061
00062 unsigned int numPrimary() const { return disk->numPrimary(); }
00063 bool hasExtended() const { return disk->hasExtended(); }
00064 unsigned int numLogical() const { return disk->numLogical(); }
00065
00066 void getUnusedSpace(std::list<Region>& free, bool all = true, bool logical = false) const
00067 { disk->getUnusedSpace(free, all, logical); }
00068
00069 unsigned long long cylinderToKb( unsigned long val ) const
00070 { return disk->cylinderToKb( val ); }
00071 unsigned long kbToCylinder( unsigned long long val ) const
00072 { return disk->kbToCylinder( val ); }
00073 string getPartName( unsigned nr ) const;
00074
00075 virtual void getCommitActions( std::list<storage::commitAction*>& l ) const;
00076 virtual int getToCommit( storage::CommitStage stage,
00077 std::list<Container*>& col,
00078 std::list<Volume*>& vol );
00079 virtual int commitChanges( storage::CommitStage stage );
00080 int commitChanges( storage::CommitStage stage, Volume* vol );
00081
00082 Partition* getPartition( unsigned nr, bool del );
00083 void getInfo( storage::DmPartCoInfo& info ) const;
00084 bool equalContent( const DmPartCo& rhs ) const;
00085 virtual string getDiffString( const Container& d ) const;
00086 void logDifference( const DmPartCo& d ) const;
00087 DmPartCo& operator= ( const DmPartCo& rhs );
00088 static string undevName( const string& name );
00089 string numToName( unsigned num ) const;
00090
00091 protected:
00092
00093
00094 typedef CastIterator<VIter, DmPart *> DmPartInter;
00095 typedef CastIterator<CVIter, const DmPart *> DmPartCInter;
00096 template< class Pred >
00097 struct DmPartPI { typedef ContainerIter<Pred, DmPartInter> type; };
00098 template< class Pred >
00099 struct DmPartCPI { typedef ContainerIter<Pred, DmPartCInter> type; };
00100 typedef CheckFnc<const DmPart> CheckFncDmPart;
00101 typedef CheckerIterator< CheckFncDmPart, DmPartPI<CheckFncDmPart>::type,
00102 DmPartInter, DmPart > DmPartPIterator;
00103 typedef CheckerIterator< CheckFncDmPart, DmPartCPI<CheckFncDmPart>::type,
00104 DmPartCInter, const DmPart > DmPartCPIterator;
00105 typedef DerefIterator<DmPartPIterator,DmPart> DmPartIter;
00106 typedef DerefIterator<DmPartCPIterator,const DmPart> ConstDmPartIter;
00107 typedef IterPair<DmPartIter> DmPartPair;
00108 typedef IterPair<ConstDmPartIter> ConstDmPartPair;
00109
00110 DmPartPair dmpartPair( bool (* CheckDmPart)( const DmPart& )=NULL)
00111 {
00112 return( DmPartPair( dmpartBegin( CheckDmPart ), dmpartEnd( CheckDmPart ) ));
00113 }
00114 DmPartIter dmpartBegin( bool (* CheckDmPart)( const DmPart& )=NULL)
00115 {
00116 IterPair<DmPartInter> p( (DmPartInter(begin())), (DmPartInter(end())) );
00117 return( DmPartIter( DmPartPIterator( p, CheckDmPart )) );
00118 }
00119 DmPartIter dmpartEnd( bool (* CheckDmPart)( const DmPart& )=NULL)
00120 {
00121 IterPair<DmPartInter> p( (DmPartInter(begin())), (DmPartInter(end())) );
00122 return( DmPartIter( DmPartPIterator( p, CheckDmPart, true )) );
00123 }
00124
00125 ConstDmPartPair dmpartPair( bool (* CheckDmPart)( const DmPart& )=NULL) const
00126 {
00127 return( ConstDmPartPair( dmpartBegin( CheckDmPart ), dmpartEnd( CheckDmPart ) ));
00128 }
00129 ConstDmPartIter dmpartBegin( bool (* CheckDmPart)( const DmPart& )=NULL) const
00130 {
00131 IterPair<DmPartCInter> p( (DmPartCInter(begin())), (DmPartCInter(end())) );
00132 return( ConstDmPartIter( DmPartCPIterator( p, CheckDmPart )) );
00133 }
00134 ConstDmPartIter dmpartEnd( bool (* CheckDmPart)( const DmPart& )=NULL) const
00135 {
00136 IterPair<DmPartCInter> p( (DmPartCInter(begin())), (DmPartCInter(end())) );
00137 return( ConstDmPartIter( DmPartCPIterator( p, CheckDmPart, true )) );
00138 }
00139
00140 DmPartCo( Storage * const s, const string& File );
00141 virtual void print( std::ostream& s ) const { s << *this; }
00142 virtual Container* getCopy() const { return( new DmPartCo( *this ) ); }
00143 void activate_part( bool val );
00144 void init( ProcPart& ppart );
00145 void createDisk( ProcPart& ppart );
00146 void getVolumes( ProcPart& ppart );
00147 void updatePointers( bool invalid=false );
00148 void updateMinor();
00149 virtual void newP( DmPart*& dm, unsigned num, Partition* p );
00150 int addNewDev( string& device );
00151 int updateDelDev();
00152 void handleWholeDevice();
00153 void removeFromMemory();
00154 void removePresentPartitions();
00155 bool validPartition( const Partition* p );
00156 bool findDm( unsigned nr, DmPartIter& i );
00157
00158 static bool partNotDeleted( const DmPart&d ) { return( !d.deleted() ); }
00159
00160 int doCreate( Volume* v );
00161 int doRemove( Volume* v );
00162 int doResize( Volume* v );
00163 int doSetType( DmPart* v );
00164 int doCreateLabel();
00165 virtual int doRemove();
00166 virtual string removeText( bool doing ) const;
00167 virtual string setDiskLabelText( bool doing ) const;
00168
00169 void logData( const string& Dir );
00170 string udev_path;
00171 std::list<string> udev_id;
00172 string logfile_name;
00173
00174 Disk* disk;
00175 bool active;
00176 bool valid;
00177 bool del_ptable;
00178 unsigned num_part;
00179
00180 mutable storage::DmPartCoInfo info;
00181 };
00182
00183 }
00184
00185 #endif