DmPartCo.h

Go to the documentation of this file.
00001 #ifndef DMPART_CO_H
00002 #define DMPART_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 const staticType() { return storage::DMRAID; }
00035         friend std::ostream& operator<< (std::ostream&, const DmPartCo& );
00036         void setUdevData( const 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 );
00051         int destroyPartitionTable( const string& new_label );
00052         unsigned availablePartNumber( storage::PartitionType type=storage::PRIMARY );
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         void getUnusedSpace( std::list<Region>& free, bool all=true, 
00058                              bool logical=false );
00059         bool hasExtended() const;
00060         unsigned long long cylinderToKb( unsigned long val ) const 
00061             { return disk->cylinderToKb( val ); }
00062         unsigned long kbToCylinder( unsigned long long val ) const
00063             { return disk->kbToCylinder( val ); }
00064         string getPartName( unsigned nr ) const;
00065 
00066         virtual void getCommitActions( std::list<storage::commitAction*>& l ) const;
00067         virtual int getToCommit( storage::CommitStage stage,
00068                                  std::list<Container*>& col,
00069                                  std::list<Volume*>& vol );
00070         virtual int commitChanges( storage::CommitStage stage );
00071         int commitChanges( storage::CommitStage stage, Volume* vol );
00072 
00073         Partition* getPartition( unsigned nr, bool del );
00074         void getInfo( storage::DmPartCoInfo& info ) const;
00075         bool equalContent( const DmPartCo& rhs ) const;
00076         virtual string getDiffString( const Container& d ) const;
00077         void logDifference( const DmPartCo& d ) const;
00078         DmPartCo& operator= ( const DmPartCo& rhs );
00079         static string undevName( const string& name );
00080         string numToName( unsigned num ) const;
00081 
00082     protected:
00083         // iterators over partitions
00084         // protected typedefs for iterators over partitions
00085         typedef CastIterator<VIter, DmPart *> DmPartInter;
00086         typedef CastIterator<CVIter, const DmPart *> DmPartCInter;
00087         template< class Pred >
00088             struct DmPartPI { typedef ContainerIter<Pred, DmPartInter> type; };
00089         template< class Pred >
00090             struct DmPartCPI { typedef ContainerIter<Pred, DmPartCInter> type; };
00091         typedef CheckFnc<const DmPart> CheckFncDmPart;
00092         typedef CheckerIterator< CheckFncDmPart, DmPartPI<CheckFncDmPart>::type,
00093                                  DmPartInter, DmPart > DmPartPIterator;
00094         typedef CheckerIterator< CheckFncDmPart, DmPartCPI<CheckFncDmPart>::type,
00095                                  DmPartCInter, const DmPart > DmPartCPIterator;
00096         typedef DerefIterator<DmPartPIterator,DmPart> DmPartIter;
00097         typedef DerefIterator<DmPartCPIterator,const DmPart> ConstDmPartIter;
00098         typedef IterPair<DmPartIter> DmPartPair;
00099         typedef IterPair<ConstDmPartIter> ConstDmPartPair;
00100 
00101         DmPartPair dmpartPair( bool (* CheckDmPart)( const DmPart& )=NULL)
00102             {
00103             return( DmPartPair( dmpartBegin( CheckDmPart ), dmpartEnd( CheckDmPart ) ));
00104             }
00105         DmPartIter dmpartBegin( bool (* CheckDmPart)( const DmPart& )=NULL)
00106             {
00107             IterPair<DmPartInter> p( (DmPartInter(begin())), (DmPartInter(end())) );
00108             return( DmPartIter( DmPartPIterator( p, CheckDmPart )) );
00109             }
00110         DmPartIter dmpartEnd( bool (* CheckDmPart)( const DmPart& )=NULL)
00111             {
00112             IterPair<DmPartInter> p( (DmPartInter(begin())), (DmPartInter(end())) );
00113             return( DmPartIter( DmPartPIterator( p, CheckDmPart, true )) );
00114             }
00115 
00116         ConstDmPartPair dmpartPair( bool (* CheckDmPart)( const DmPart& )=NULL) const
00117             {
00118             return( ConstDmPartPair( dmpartBegin( CheckDmPart ), dmpartEnd( CheckDmPart ) ));
00119             }
00120         ConstDmPartIter dmpartBegin( bool (* CheckDmPart)( const DmPart& )=NULL) const
00121             {
00122             IterPair<DmPartCInter> p( (DmPartCInter(begin())), (DmPartCInter(end())) );
00123             return( ConstDmPartIter( DmPartCPIterator( p, CheckDmPart )) );
00124             }
00125         ConstDmPartIter dmpartEnd( bool (* CheckDmPart)( const DmPart& )=NULL) const
00126             {
00127             IterPair<DmPartCInter> p( (DmPartCInter(begin())), (DmPartCInter(end())) );
00128             return( ConstDmPartIter( DmPartCPIterator( p, CheckDmPart, true )) );
00129             }
00130 
00131         DmPartCo( Storage * const s, const string& File );
00132         virtual void print( std::ostream& s ) const { s << *this; }
00133         virtual Container* getCopy() const { return( new DmPartCo( *this ) ); }
00134         void activate_part( bool val );
00135         void init( ProcPart& ppart );
00136         void createDisk( ProcPart& ppart );
00137         void getVolumes( ProcPart& ppart );
00138         void updatePointers( bool invalid=false );
00139         void updateMinor();
00140         virtual void newP( DmPart*& dm, unsigned num, Partition* p );
00141         int addNewDev( string& device );
00142         int updateDelDev();
00143         void handleWholeDevice();
00144         void removeFromMemory();
00145         void removePresentPartitions();
00146         bool validPartition( const Partition* p );
00147         bool findDm( unsigned nr, DmPartIter& i );
00148 
00149         static bool partNotDeleted( const DmPart&d ) { return( !d.deleted() ); }
00150 
00151         int doCreate( Volume* v );
00152         int doRemove( Volume* v );
00153         int doResize( Volume* v );
00154         int doSetType( DmPart* v );
00155         int doCreateLabel();
00156         virtual int doRemove();
00157         virtual string removeText( bool doing ) const;
00158         virtual string setDiskLabelText( bool doing ) const;
00159 
00160         void logData( const string& Dir );
00161         string udev_path;
00162         std::list<string> udev_id;
00163         string logfile_name;
00164         string sysfs_dir;
00165 
00166         Disk* disk;
00167         bool active;
00168         bool valid;
00169         bool del_ptable;
00170         unsigned num_part;
00171 
00172         mutable storage::DmPartCoInfo info;
00173     };
00174 
00175 }
00176 
00177 #endif

Generated on Tue Sep 25 21:19:22 2007 for yast2-storage by  doxygen 1.5.3