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

Generated on Wed May 3 17:21:20 2006 for yast2-storage by  doxygen 1.4.6