Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

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 class Storage;
00010 class SystemCmd;
00011 class ProcPart;
00012 class Region;
00013 
00014 class Disk : public Container
00015     {
00016     friend class Storage;
00017 
00018     struct label_info
00019         {
00020         string name;
00021         bool extended;
00022         unsigned primary;
00023         unsigned logical;
00024         };
00025 
00026     public:
00027         Disk( Storage * const s, const string& Name, unsigned long long Size );
00028         Disk( const Disk& rhs );
00029         virtual ~Disk();
00030 
00031         unsigned long cylinders() const { return cyl; }
00032         unsigned heads() const { return head; }
00033         unsigned sectors() const { return sector; }
00034         unsigned long long sizeK() const { return size_k; }
00035         unsigned long minorNr() const { return mnr; }
00036         unsigned long majorNr() const { return mjr; }
00037         unsigned long numMinor() const { return range; }
00038         unsigned long cylSizeB() const { return byte_cyl; }
00039         unsigned maxPrimary() const { return max_primary; }
00040         unsigned maxLogical() const { return max_logical; }
00041         const string& labelName() const { return label; }
00042         unsigned numPartitions() const;
00043         static storage::CType const staticType() { return storage::DISK; }
00044         friend std::ostream& operator<< (std::ostream&, const Disk& );
00045 
00046         static bool needP( const string& dev );
00047         int createPartition( storage::PartitionType type, long unsigned start,
00048                              long unsigned len, string& device,
00049                              bool checkRelaxed=false );
00050         int createPartition( long unsigned len, string& device,
00051                              bool checkRelaxed=false );
00052         int createPartition( storage::PartitionType type, string& device );
00053         int removePartition( unsigned nr );
00054         int changePartitionId( unsigned nr, unsigned id );
00055         int forgetChangePartitionId( unsigned nr );
00056         int changePartitionArea( unsigned nr, unsigned long start, 
00057                                  unsigned long size, bool checkRelaxed=false );
00058         int nextFreePartition( storage::PartitionType type, unsigned& nr,
00059                                string& device );
00060         int destroyPartitionTable( const string& new_label );
00061         unsigned availablePartNumber( storage::PartitionType type=storage::PRIMARY );
00062         void getCommitActions( std::list<storage::commitAction*>& l ) const;
00063         int getToCommit( storage::CommitStage stage, std::list<Container*>& col,
00064                          std::list<Volume*>& vol );
00065         int commitChanges( storage::CommitStage stage );
00066         int commitChanges( storage::CommitStage stage, Volume* vol );
00067         int resizePartition( Partition* p, unsigned long newCyl );
00068         int resizeVolume( Volume* v, unsigned long long newSize );
00069         int removeVolume( Volume* v );
00070         void getUnusedSpace( std::list<Region>& free, bool all=true, 
00071                              bool logical=false );
00072         bool hasExtended() const;
00073         string setDiskLabelText( bool doing=true ) const;
00074         unsigned long long cylinderToKb( unsigned long ) const;
00075         unsigned long kbToCylinder( unsigned long long ) const;
00076         string getPartName( unsigned nr ) const;
00077         void getInfo( storage::DiskInfo& info ) const;
00078         bool equalContent( const Disk& rhs ) const;
00079         void logDifference( const Disk& d ) const;
00080 
00081 
00082         static string getPartName( const string& disk, unsigned nr );
00083         static string getPartName( const string& disk, const string& nr );
00084         static std::pair<string,long> getDiskPartition( const string& dev );
00085 
00086     protected:
00087 
00088         // iterators over partitions
00089         // protected typedefs for iterators over partitions
00090         typedef CastIterator<VIter, Partition *> PartInter;
00091         typedef CastIterator<CVIter, const Partition *> PartCInter;
00092         template< class Pred >
00093             struct PartitionPI { typedef ContainerIter<Pred, PartInter> type; };
00094         template< class Pred >
00095             struct PartitionCPI { typedef ContainerIter<Pred, PartCInter> type; };
00096         typedef CheckFnc<const Partition> CheckFncPartition;
00097         typedef CheckerIterator< CheckFncPartition, PartitionPI<CheckFncPartition>::type,
00098                                  PartInter, Partition > PartPIterator;
00099         typedef CheckerIterator< CheckFncPartition, PartitionCPI<CheckFncPartition>::type,
00100                                  PartCInter, const Partition > PartCPIterator;
00101         typedef DerefIterator<PartPIterator,Partition> PartIter;
00102         typedef DerefIterator<PartCPIterator,const Partition> ConstPartIter;
00103         typedef IterPair<PartIter> PartPair;
00104         typedef IterPair<ConstPartIter> ConstPartPair;
00105 
00106         PartPair partPair( bool (* CheckPart)( const Partition& )=NULL)
00107             {
00108             return( PartPair( partBegin( CheckPart ), partEnd( CheckPart ) ));
00109             }
00110         PartIter partBegin( bool (* CheckPart)( const Partition& )=NULL)
00111             {
00112             IterPair<PartInter> p( (PartInter(begin())), (PartInter(end())) );
00113             return( PartIter( PartPIterator( p, CheckPart )) );
00114             }
00115         PartIter partEnd( bool (* CheckPart)( const Partition& )=NULL)
00116             {
00117             IterPair<PartInter> p( (PartInter(begin())), (PartInter(end())) );
00118             return( PartIter( PartPIterator( p, CheckPart, true )) );
00119             }
00120 
00121         ConstPartPair partPair( bool (* CheckPart)( const Partition& )=NULL) const
00122             {
00123             return( ConstPartPair( partBegin( CheckPart ), partEnd( CheckPart ) ));
00124             }
00125         ConstPartIter partBegin( bool (* CheckPart)( const Partition& )=NULL) const
00126             {
00127             IterPair<PartCInter> p( (PartCInter(begin())), (PartCInter(end())) );
00128             return( ConstPartIter( PartCPIterator( p, CheckPart )) );
00129             }
00130         ConstPartIter partEnd( bool (* CheckPart)( const Partition& )=NULL) const
00131             {
00132             IterPair<PartCInter> p( (PartCInter(begin())), (PartCInter(end())) );
00133             return( ConstPartIter( PartCPIterator( p, CheckPart, true )) );
00134             }
00135 
00136         Disk( Storage * const s, const string& File );
00137         unsigned long long capacityInKb() const { return size_k; }
00138         bool detectGeometry();
00139         bool detectPartitions();
00140         bool getSysfsInfo( const string& SysFsDir );
00141         int checkSystemError( const string& cmd_line, const SystemCmd& cmd );
00142         int execCheckFailed( const string& cmd_line );
00143         bool checkPartedOutput( const SystemCmd& cmd );
00144         bool scanPartedLine( const string& Line, unsigned& nr,
00145                              unsigned long& start, unsigned long& csize,
00146                              storage::PartitionType& type, 
00147                              unsigned& id, bool& boot );
00148         bool checkPartedValid( const ProcPart& pp, const std::list<string>& ps,
00149                                const std::list<Partition*>& pl );
00150         bool getPartedValues( Partition *p );
00151         virtual void print( std::ostream& s ) const { s << *this; }
00152         virtual Container* getCopy() const { return( new Disk( *this ) ); }
00153         void getGeometry( const string& line, unsigned long& c, unsigned& h,
00154                           unsigned& s );
00155         void redetectGeometry();
00156 
00157         static bool notDeleted( const Partition&d ) { return( !d.deleted() ); }
00158 
00159         int doCreate( Volume* v );
00160         int doRemove( Volume* v );
00161         int doResize( Volume* v );
00162         int doSetType( Volume* v );
00163         int doCreateLabel();
00164 
00165         //std::list<Region> getUnusedRegions();
00166         void logData( const string& Dir );
00167         bool haveBsdPart( const std::list<Partition*>& pl) const;
00168         void setLabelData( const string& );
00169         Disk& operator= ( const Disk& rhs );
00170 
00171         static string defaultLabel();
00172         static label_info labels[];
00173         static string p_disks[];
00174 
00175         unsigned long cyl;
00176         unsigned head;
00177         unsigned sector;
00178         unsigned long new_cyl;
00179         unsigned new_head;
00180         unsigned new_sector;
00181         string label;
00182         string detected_label;
00183         string system_stderr;
00184         unsigned max_primary;
00185         bool ext_possible;
00186         unsigned max_logical;
00187         unsigned long byte_cyl;
00188         unsigned long long size_k;
00189         unsigned long mnr;
00190         unsigned long mjr;
00191         unsigned long range;
00192         mutable storage::DiskInfo info;
00193     };
00194 
00195 #endif

Generated on Wed Sep 14 11:27:07 2005 for yast2-storage by  doxygen 1.4.4