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