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

Generated on Wed Apr 30 15:02:08 2008 for yast2-storage by  doxygen 1.4.6