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         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         static storage::CType const staticType() { return storage::DISK; }
00058         friend std::ostream& operator<< (std::ostream&, const Disk& );
00059 
00060         static bool needP( const string& dev );
00061         void setUdevData( const string& path, const string& id );
00062         virtual int createPartition( storage::PartitionType type, long unsigned start,
00063                                      long unsigned len, string& device,
00064                                      bool checkRelaxed=false );
00065         int createPartition( long unsigned len, string& device,
00066                              bool checkRelaxed=false );
00067         int createPartition( storage::PartitionType type, string& device );
00068         virtual int removePartition( unsigned nr );
00069         virtual int changePartitionId( unsigned nr, unsigned id );
00070         virtual int initializeDisk( bool ) { return storage::DISK_INIT_NOT_POSSIBLE;}
00071         bool initializeDisk() const { return init_disk; }
00072         void resetInitDisk() { init_disk=false; }
00073         int forgetChangePartitionId( unsigned nr );
00074         int changePartitionArea( unsigned nr, unsigned long start, 
00075                                  unsigned long size, bool checkRelaxed=false );
00076         int nextFreePartition( storage::PartitionType type, unsigned& nr,
00077                                string& device );
00078         int destroyPartitionTable( const string& new_label );
00079         unsigned availablePartNumber( storage::PartitionType type=storage::PRIMARY );
00080         virtual void getCommitActions( std::list<storage::commitAction*>& l ) const;
00081         virtual int getToCommit( storage::CommitStage stage, 
00082                                  std::list<Container*>& col,
00083                                  std::list<Volume*>& vol );
00084         virtual int commitChanges( storage::CommitStage stage );
00085         int commitChanges( storage::CommitStage stage, Volume* vol );
00086         virtual int resizePartition( Partition* p, unsigned long newCyl );
00087         int resizeVolume( Volume* v, unsigned long long newSize );
00088         int removeVolume( Volume* v );
00089         void getUnusedSpace( std::list<Region>& free, bool all=true, 
00090                              bool logical=false );
00091         bool hasExtended() const;
00092         string setDiskLabelText( bool doing=true ) const;
00093         unsigned long long cylinderToKb( unsigned long ) const;
00094         unsigned long kbToCylinder( unsigned long long ) const;
00095         string getPartName( unsigned nr ) const;
00096         void getInfo( storage::DiskInfo& info ) const;
00097         bool equalContent( const Disk& rhs ) const;
00098         void logDifference( const Disk& d ) const;
00099         Disk& operator= ( const Disk& rhs );
00100         bool FakeDisk() const { return(range==1); }
00101 
00102         static string getPartName( const string& disk, unsigned nr );
00103         static string getPartName( const string& disk, const string& nr );
00104         static std::pair<string,long> getDiskPartition( const string& dev );
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 
00189         virtual int doCreate( Volume* v );
00190         virtual int doRemove( Volume* v );
00191         virtual int doResize( Volume* v );
00192         virtual int doSetType( Volume* v );
00193         virtual int doCreateLabel();
00194 
00195         //std::list<Region> getUnusedRegions();
00196         void logData( const string& Dir );
00197         bool haveBsdPart( const std::list<Partition*>& pl) const;
00198         void setLabelData( const string& );
00199 
00200         static string defaultLabel();
00201         static label_info labels[];
00202         static string p_disks[];
00203 
00204         unsigned long cyl;
00205         unsigned head;
00206         unsigned sector;
00207         unsigned long new_cyl;
00208         unsigned new_head;
00209         unsigned new_sector;
00210         string label;
00211         string udev_path;
00212         std::list<string> udev_id;
00213         std::list<string> mp_alias;
00214         string detected_label;
00215         string system_stderr;
00216         string logfile_name;
00217         string sysfs_dir;
00218         unsigned max_primary;
00219         bool ext_possible;
00220         bool init_disk;
00221         unsigned max_logical;
00222         unsigned long byte_cyl;
00223         unsigned long long size_k;
00224         unsigned long mnr;
00225         unsigned long mjr;
00226         unsigned long range;
00227         mutable storage::DiskInfo info;
00228     };
00229 
00230 }
00231 
00232 #endif

Generated on Thu Jul 6 00:40:24 2006 for yast2-storage by  doxygen 1.4.6