|
yast2-storage
|
00001 /* 00002 * Copyright (c) [2004-2009] Novell, Inc. 00003 * 00004 * All Rights Reserved. 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of version 2 of the GNU General Public License as published 00008 * by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, but WITHOUT 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 * more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, contact Novell, Inc. 00017 * 00018 * To contact Novell about this file by physical or electronic mail, you may 00019 * find current contact information at www.novell.com. 00020 */ 00021 00022 00023 #ifndef DM_PART_CO_H 00024 #define DM_PART_CO_H 00025 00026 #include <list> 00027 00028 #include "storage/PeContainer.h" 00029 #include "storage/Disk.h" 00030 #include "storage/DmPart.h" 00031 00032 00033 namespace storage 00034 { 00035 using std::list; 00036 00037 00038 class Storage; 00039 class SystemInfo; 00040 class Region; 00041 00042 00043 class DmPartCo : public PeContainer 00044 { 00045 friend class Storage; 00046 00047 public: 00048 00049 DmPartCo(Storage* s, const string& name, const string& device, CType t, 00050 SystemInfo& systeminfo); 00051 DmPartCo(const DmPartCo& c); 00052 virtual ~DmPartCo(); 00053 00054 unsigned long long sizeK() const { return size_k; } 00055 const string& labelName() const { return disk->labelName(); } 00056 virtual list<string> udevId() const { return udev_id; } 00057 unsigned numPartitions() const { return disk->numPartitions(); } 00058 static storage::CType staticType() { return storage::DMRAID; } 00059 friend std::ostream& operator<< (std::ostream&, const DmPartCo& ); 00060 void setUdevData(const list<string>& id); 00061 00062 virtual string procName() const { return "dm-" + decString(mnr); } 00063 virtual string sysfsPath() const; 00064 00065 int createPartition( storage::PartitionType type, long unsigned start, 00066 long unsigned len, string& device, 00067 bool checkRelaxed=false ); 00068 int createPartition( long unsigned len, string& device, 00069 bool checkRelaxed=false ); 00070 int createPartition( storage::PartitionType type, string& device ); 00071 int removePartition( unsigned nr ); 00072 int changePartitionId( unsigned nr, unsigned id ); 00073 int forgetChangePartitionId( unsigned nr ); 00074 int changePartitionArea(unsigned nr, const Region& cylRegion, bool checkRelaxed = false); 00075 int nextFreePartition(storage::PartitionType type, unsigned& nr, 00076 string& device) const; 00077 int destroyPartitionTable( const string& new_label ); 00078 int freeCylindersAroundPartition(const DmPart* p, unsigned long& freeCylsBefore, 00079 unsigned long& freeCylsAfter) const; 00080 int resizePartition( DmPart* p, unsigned long newCyl ); 00081 int resizeVolume( Volume* v, unsigned long long newSize ); 00082 int removeVolume( Volume* v ); 00083 int removeDmPart(); 00084 00085 unsigned maxPrimary() const { return disk->maxPrimary(); } 00086 bool extendedPossible() const { return disk->extendedPossible(); } 00087 unsigned maxLogical() const { return disk->maxLogical(); } 00088 00089 unsigned int numPrimary() const { return disk->numPrimary(); } 00090 bool hasExtended() const { return disk->hasExtended(); } 00091 unsigned int numLogical() const { return disk->numLogical(); } 00092 00093 void getUnusedSpace(std::list<Region>& free, bool all = true, bool logical = false) const 00094 { disk->getUnusedSpace(free, all, logical); } 00095 00096 unsigned long long cylinderToKb( unsigned long val ) const 00097 { return disk->cylinderToKb( val ); } 00098 unsigned long kbToCylinder( unsigned long long val ) const 00099 { return disk->kbToCylinder( val ); } 00100 00101 string getPartName(unsigned nr) const; 00102 string getPartDevice(unsigned nr) const; 00103 00104 virtual void getCommitActions(list<commitAction>& l) const; 00105 virtual void getToCommit(storage::CommitStage stage, list<const Container*>& col, 00106 list<const Volume*>& vol) const; 00107 virtual int commitChanges( storage::CommitStage stage ); 00108 int commitChanges( storage::CommitStage stage, Volume* vol ); 00109 00110 Partition* getPartition( unsigned nr, bool del ); 00111 void getInfo( storage::DmPartCoInfo& info ) const; 00112 bool equalContent( const DmPartCo& rhs ) const; 00113 00114 void logDifference(std::ostream& log, const DmPartCo& rhs) const; 00115 00116 static string undevName( const string& name ); 00117 00118 protected: 00119 // iterators over partitions 00120 // protected typedefs for iterators over partitions 00121 typedef CastIterator<VIter, DmPart *> DmPartInter; 00122 typedef CastIterator<CVIter, const DmPart *> DmPartCInter; 00123 template< class Pred > 00124 struct DmPartPI { typedef ContainerIter<Pred, DmPartInter> type; }; 00125 template< class Pred > 00126 struct DmPartCPI { typedef ContainerIter<Pred, DmPartCInter> type; }; 00127 typedef CheckFnc<const DmPart> CheckFncDmPart; 00128 typedef CheckerIterator< CheckFncDmPart, DmPartPI<CheckFncDmPart>::type, 00129 DmPartInter, DmPart > DmPartPIterator; 00130 typedef CheckerIterator< CheckFncDmPart, DmPartCPI<CheckFncDmPart>::type, 00131 DmPartCInter, const DmPart > DmPartCPIterator; 00132 typedef DerefIterator<DmPartPIterator,DmPart> DmPartIter; 00133 typedef DerefIterator<DmPartCPIterator,const DmPart> ConstDmPartIter; 00134 typedef IterPair<DmPartIter> DmPartPair; 00135 typedef IterPair<ConstDmPartIter> ConstDmPartPair; 00136 00137 DmPartPair dmpartPair( bool (* CheckDmPart)( const DmPart& )=NULL) 00138 { 00139 return( DmPartPair( dmpartBegin( CheckDmPart ), dmpartEnd( CheckDmPart ) )); 00140 } 00141 DmPartIter dmpartBegin( bool (* CheckDmPart)( const DmPart& )=NULL) 00142 { 00143 IterPair<DmPartInter> p( (DmPartInter(begin())), (DmPartInter(end())) ); 00144 return( DmPartIter( DmPartPIterator( p, CheckDmPart )) ); 00145 } 00146 DmPartIter dmpartEnd( bool (* CheckDmPart)( const DmPart& )=NULL) 00147 { 00148 IterPair<DmPartInter> p( (DmPartInter(begin())), (DmPartInter(end())) ); 00149 return( DmPartIter( DmPartPIterator( p, CheckDmPart, true )) ); 00150 } 00151 00152 ConstDmPartPair dmpartPair( bool (* CheckDmPart)( const DmPart& )=NULL) const 00153 { 00154 return( ConstDmPartPair( dmpartBegin( CheckDmPart ), dmpartEnd( CheckDmPart ) )); 00155 } 00156 ConstDmPartIter dmpartBegin( bool (* CheckDmPart)( const DmPart& )=NULL) const 00157 { 00158 IterPair<DmPartCInter> p( (DmPartCInter(begin())), (DmPartCInter(end())) ); 00159 return( ConstDmPartIter( DmPartCPIterator( p, CheckDmPart )) ); 00160 } 00161 ConstDmPartIter dmpartEnd( bool (* CheckDmPart)( const DmPart& )=NULL) const 00162 { 00163 IterPair<DmPartCInter> p( (DmPartCInter(begin())), (DmPartCInter(end())) ); 00164 return( ConstDmPartIter( DmPartCPIterator( p, CheckDmPart, true )) ); 00165 } 00166 00167 virtual void print( std::ostream& s ) const { s << *this; } 00168 virtual Container* getCopy() const = 0; // { return( new DmPartCo( *this ) ); } 00169 void activate_part( bool val ); 00170 void init(SystemInfo& systeminfo); 00171 void createDisk(SystemInfo& systeminfo); 00172 void getVolumes(SystemInfo& si); 00173 void updatePointers( bool invalid=false ); 00174 void updateMinor(); 00175 virtual void newP( DmPart*& dm, unsigned num, Partition* p, SystemInfo& si ); 00176 virtual void newP( DmPart*& dm, unsigned num, Partition* p ); 00177 int addNewDev( string& device ); 00178 int updateDelDev(); 00179 void handleWholeDevice(); 00180 void handleWholeDevice(SystemInfo& si); 00181 void removeFromMemory(); 00182 void removePresentPartitions(); 00183 bool validPartition( const Partition* p ); 00184 bool findDm( unsigned nr, DmPartIter& i ); 00185 00186 int doCreate( Volume* v ); 00187 int doRemove( Volume* v ); 00188 int doResize( Volume* v ); 00189 int doSetType( DmPart* v ); 00190 int doCreateLabel(); 00191 virtual int doRemove(); 00192 virtual Text removeText( bool doing ) const; 00193 virtual Text setDiskLabelText( bool doing ) const; 00194 00195 list<string> udev_id; 00196 Disk* disk; 00197 bool active; 00198 00199 mutable storage::DmPartCoInfo info; // workaround for broken ycp bindings 00200 00201 private: 00202 00203 DmPartCo& operator=(const DmPartCo&); // disallow 00204 00205 }; 00206 00207 } 00208 00209 #endif
1.7.3