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

Generated on Tue Nov 28 17:50:00 2006 for yast2-storage by  doxygen 1.5.0