Disk.h

Go to the documentation of this file.
00001 #ifndef DISK_H
00002 #define DISK_H
00003 
00004 #include <list>
00005 
00006 #include "y2storage/Container.h"
00007 #include "y2storage/Partition.h"
00008 
00009 namespace storage
00010 {
00011 
00012 class Storage;
00013 class SystemCmd;
00014 class ProcPart;
00015 class Region;
00016 
00017 class Disk : public Container
00018     {
00019     friend class Storage;
00020     friend class DmPartCo;
00021 
00022     struct label_info
00023         {
00024         string name;
00025         bool extended;
00026         unsigned primary;
00027         unsigned logical;
00028         unsigned long long max_size_k;
00029         };
00030 
00031     public:
00032         Disk( Storage * const s, const string& Name, unsigned long long Size );
00033         Disk( Storage * const s, const string& Name, unsigned num, 
00034               unsigned long long Size, ProcPart& ppart );
00035         Disk( const Disk& rhs );
00036         virtual ~Disk();
00037 
00038         unsigned long cylinders() const { return cyl; }
00039         unsigned heads() const { return head; }
00040         unsigned sectors() const { return sector; }
00041         unsigned long numMinor() const { return range; }
00042         unsigned long cylSizeB() const { return byte_cyl; }
00043         unsigned maxPrimary() const { return max_primary; }
00044         unsigned maxLogical() const { return max_logical; }
00045         const string& labelName() const { return label; }
00046         const string& udevPath() const { return udev_path; }
00047         const std::list<string>& udevId() const { return udev_id; }
00048         void setSlave( bool val=true ) { dmp_slave=val; }
00049         void setNumMinor( unsigned long val ) { range=val; }
00050         void addMpAlias( const string& dev ); 
00051         void clearMpAlias() { mp_alias.clear(); }
00052         const std::list<string>& mpAlias() const { return mp_alias; }
00053         const string& sysfsDir() const { return sysfs_dir; }
00054         unsigned numPartitions() const;
00055         bool isDasd() const { return( nm.find("dasd")==0 ); }
00056         bool isLogical( unsigned nr ) const;
00057         bool detect( ProcPart& ppart );
00058         static storage::CType const staticType() { return storage::DISK; }
00059         friend std::ostream& operator<< (std::ostream&, const Disk& );
00060         void triggerUdevUpdate();
00061 
00062         static bool needP( const string& dev );
00063         void setUdevData( const string& path, const string& id );
00064         virtual int createPartition( storage::PartitionType type, long unsigned start,
00065                                      long unsigned len, string& device,
00066                                      bool checkRelaxed=false );
00067         int createPartition( long unsigned len, string& device,
00068                              bool checkRelaxed=false );
00069         int createPartition( storage::PartitionType type, string& device );
00070         virtual int removePartition( unsigned nr );
00071         virtual int changePartitionId( unsigned nr, unsigned id );
00072         virtual int initializeDisk( bool ) { return storage::DISK_INIT_NOT_POSSIBLE;}
00073         bool initializeDisk() const { return init_disk; }
00074         void resetInitDisk() { init_disk=false; }
00075         int forgetChangePartitionId( unsigned nr );
00076         int changePartitionArea( unsigned nr, unsigned long start, 
00077                                  unsigned long size, bool checkRelaxed=false );
00078         int nextFreePartition( storage::PartitionType type, unsigned& nr,
00079                                string& device );
00080         int destroyPartitionTable( const string& new_label );
00081         unsigned availablePartNumber( storage::PartitionType type=storage::PRIMARY );
00082         virtual void getCommitActions( std::list<storage::commitAction*>& l ) const;
00083         virtual int getToCommit( storage::CommitStage stage, 
00084                                  std::list<Container*>& col,
00085                                  std::list<Volume*>& vol );
00086         virtual int commitChanges( storage::CommitStage stage );
00087         int commitChanges( storage::CommitStage stage, Volume* vol );
00088         virtual int resizePartition( Partition* p, unsigned long newCyl );
00089         int resizeVolume( Volume* v, unsigned long long newSize );
00090         int removeVolume( Volume* v );
00091         void getUnusedSpace( std::list<Region>& free, bool all=true, 
00092                              bool logical=false );
00093         bool hasExtended() const;
00094         string setDiskLabelText( bool doing=true ) const;
00095         unsigned long long cylinderToKb( unsigned long ) const;
00096         unsigned long kbToCylinder( unsigned long long ) const;
00097         string getPartName( unsigned nr ) const;
00098         void getInfo( storage::DiskInfo& info ) const;
00099         bool equalContent( const Container& rhs ) const;
00100         void logDifference( const Container& d ) const;
00101         Disk& operator= ( const Disk& rhs );
00102         bool FakeDisk() const { return(range==1); }
00103 
00104         static string getPartName( const string& disk, unsigned nr );
00105         static string getPartName( const string& disk, const string& nr );
00106         static std::pair<string,unsigned> getDiskPartition( const string& dev );
00107         static unsigned long long maxSizeLabelK( const string& label );
00108 
00109     protected:
00110 
00111         // iterators over partitions
00112         // protected typedefs for iterators over partitions
00113         typedef CastIterator<VIter, Partition *> PartInter;
00114         typedef CastIterator<CVIter, const Partition *> PartCInter;
00115         template< class Pred >
00116             struct PartitionPI { typedef ContainerIter<Pred, PartInter> type; };
00117         template< class Pred >
00118             struct PartitionCPI { typedef ContainerIter<Pred, PartCInter> type; };
00119         typedef CheckFnc<const Partition> CheckFncPartition;
00120         typedef CheckerIterator< CheckFncPartition, PartitionPI<CheckFncPartition>::type,
00121                                  PartInter, Partition > PartPIterator;
00122         typedef CheckerIterator< CheckFncPartition, PartitionCPI<CheckFncPartition>::type,
00123                                  PartCInter, const Partition > PartCPIterator;
00124         typedef DerefIterator<PartPIterator,Partition> PartIter;
00125         typedef IterPair<PartIter> PartPair;
00126 
00127         PartPair partPair( bool (* CheckPart)( const Partition& )=NULL)
00128             {
00129             return( PartPair( partBegin( CheckPart ), partEnd( CheckPart ) ));
00130             }
00131         PartIter partBegin( bool (* CheckPart)( const Partition& )=NULL)
00132             {
00133             IterPair<PartInter> p( (PartInter(begin())), (PartInter(end())) );
00134             return( PartIter( PartPIterator( p, CheckPart )) );
00135             }
00136         PartIter partEnd( bool (* CheckPart)( const Partition& )=NULL)
00137             {
00138             IterPair<PartInter> p( (PartInter(begin())), (PartInter(end())) );
00139             return( PartIter( PartPIterator( p, CheckPart, true )) );
00140             }
00141 
00142     public:
00143         typedef DerefIterator<PartCPIterator,const Partition> ConstPartIter;
00144         typedef IterPair<ConstPartIter> ConstPartPair;
00145         ConstPartPair partPair( bool (* CheckPart)( const Partition& )=NULL) const
00146             {
00147             return( ConstPartPair( partBegin( CheckPart ), partEnd( CheckPart ) ));
00148             }
00149         ConstPartIter partBegin( bool (* CheckPart)( const Partition& )=NULL) const
00150             {
00151             IterPair<PartCInter> p( (PartCInter(begin())), (PartCInter(end())) );
00152             return( ConstPartIter( PartCPIterator( p, CheckPart )) );
00153             }
00154         ConstPartIter partEnd( bool (* CheckPart)( const Partition& )=NULL) const
00155             {
00156             IterPair<PartCInter> p( (PartCInter(begin())), (PartCInter(end())) );
00157             return( ConstPartIter( PartCPIterator( p, CheckPart, true )) );
00158             }
00159 
00160     protected:
00161         Disk( Storage * const s, const string& File );
00162         virtual bool detectGeometry();
00163         virtual bool detectPartitions( ProcPart& ppart );
00164         bool getSysfsInfo( const string& SysFsDir );
00165         int checkSystemError( const string& cmd_line, const SystemCmd& cmd );
00166         int execCheckFailed( const string& cmd_line );
00167         int execCheckFailed( SystemCmd& cmd, const string& cmd_line );
00168         bool checkPartedOutput( const SystemCmd& cmd, ProcPart& ppart );
00169         bool scanPartedLine( const string& Line, unsigned& nr,
00170                              unsigned long& start, unsigned long& csize,
00171                              storage::PartitionType& type, 
00172                              unsigned& id, bool& boot );
00173         bool checkPartedValid( const ProcPart& pp, const string& diskname,
00174                                std::list<Partition*>& pl, unsigned long& rng );
00175         bool getPartedValues( Partition *p );
00176         bool getPartedSectors( const Partition *p, unsigned long long& start,
00177                                unsigned long long& end );
00178         const Partition * getPartitionAfter( const Partition * p );
00179         virtual void print( std::ostream& s ) const { s << *this; }
00180         virtual Container* getCopy() const { return( new Disk( *this ) ); }
00181         void getGeometry( const string& line, unsigned long& c, 
00182                           unsigned& h, unsigned& s );
00183         virtual void redetectGeometry();
00184         void changeNumbers( const PartIter& b, const PartIter& e, 
00185                             unsigned start, int incr );
00186         int createChecks( storage::PartitionType& type, unsigned long start,
00187                           unsigned long len, bool checkRelaxed );
00188         void removePresentPartitions();
00189         void removeFromMemory();
00190         void enlargeGpt();
00191 
00192         static bool notDeleted( const Partition&d ) { return( !d.deleted() ); }
00193         static bool bootSpecial( const Partition&d ) { return( !d.deleted()&&(d.id()==0x41||d.id()==0x06) ); }
00194 
00195         virtual int doCreate( Volume* v );
00196         virtual int doRemove( Volume* v );
00197         virtual int doResize( Volume* v );
00198         virtual int doSetType( Volume* v );
00199         virtual int doCreateLabel();
00200 
00201         //std::list<Region> getUnusedRegions();
00202         void logData( const string& Dir );
00203         bool haveBsdPart( const std::list<Partition*>& pl) const;
00204         void setLabelData( const string& );
00205 
00206         static string defaultLabel();
00207         static label_info labels[];
00208         static string p_disks[];
00209 
00210         unsigned long cyl;
00211         unsigned head;
00212         unsigned sector;
00213         unsigned long new_cyl;
00214         unsigned new_head;
00215         unsigned new_sector;
00216         string label;
00217         string udev_path;
00218         std::list<string> udev_id;
00219         std::list<string> mp_alias;
00220         string detected_label;
00221         string system_stderr;
00222         string logfile_name;
00223         string sysfs_dir;
00224         unsigned max_primary;
00225         bool ext_possible;
00226         bool init_disk;
00227         bool iscsi;
00228         bool dmp_slave;
00229         bool gpt_enlarge;
00230         unsigned max_logical;
00231         unsigned long byte_cyl;
00232         unsigned long range;
00233         mutable storage::DiskInfo info;
00234     };
00235 
00236 }
00237 
00238 #endif

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