yast2-storage

Partition.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) [2004-2010] Novell, Inc.
00003  *
00004  * All Rights Reserved.
00005  *
00006  * This program is free software; you can redistribute it and/or modify it
00007  * under the terms of version 2 of the GNU General Public License as published
00008  * by the Free Software Foundation.
00009  *
00010  * This program is distributed in the hope that it will be useful, but WITHOUT
00011  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013  * more details.
00014  *
00015  * You should have received a copy of the GNU General Public License along
00016  * with this program; if not, contact Novell, Inc.
00017  *
00018  * To contact Novell about this file by physical or electronic mail, you may
00019  * find current contact information at www.novell.com.
00020  */
00021 
00022 
00023 #ifndef PARTITION_H
00024 #define PARTITION_H
00025 
00026 #include "storage/StorageInterface.h"
00027 #include "storage/Volume.h"
00028 #include "storage/Region.h"
00029 
00030 namespace storage
00031 {
00032 
00033 class Disk;
00034 
00035 class Partition : public Volume
00036     {
00037     public:
00038 
00039         enum IdNum { ID_DOS12=0x01, ID_DOS16=0x06, ID_DOS32=0x0c, ID_NTFS=0x07,
00040                      ID_EXTENDED=0x0f, ID_PPC_PREP = 0x41, ID_LINUX=0x83, ID_SWAP=0x82, ID_LVM=0x8e,
00041                      ID_RAID=0xfd, ID_APPLE_OTHER=0x101, ID_APPLE_HFS=0x102,
00042                      ID_GPT_BOOT=0x103, ID_GPT_SERVICE=0x104, ID_GPT_MSFTRES=0x105,
00043                      ID_APPLE_UFS=0x106, ID_GPT_PREP = 0x108 };
00044 
00045         Partition(const Disk& c, const string& name, const string& device, unsigned Pnr,
00046                   unsigned long long SizeK, const Region& cylRegion, PartitionType Type,
00047                   unsigned id = ID_LINUX, bool Boot = false);
00048         Partition(const Disk& c, const string& name, const string& device, unsigned Pnr,
00049                   SystemInfo& systeminfo, unsigned long long SizeK, const Region& cylRegion,
00050                   PartitionType Type, unsigned id = ID_LINUX, bool Boot = false);
00051         Partition(const Disk& c, const xmlNode* node);
00052         Partition(const Disk& c, const Partition& v);
00053         virtual ~Partition();
00054 
00055         void saveData(xmlNode* node) const;
00056 
00057         unsigned long cylStart() const { return reg.start(); }
00058         unsigned long cylSize() const { return reg.len(); }
00059         unsigned long cylEnd() const { return reg.end(); }
00060         const Region& cylRegion() const { return reg; }
00061 
00062         virtual string udevPath() const;
00063         virtual list<string> udevId() const;
00064 
00065         virtual string procName() const { return nm; }
00066         virtual string sysfsPath() const;
00067 
00068         bool intersectArea( const Region& r, unsigned fuzz=0 ) const;
00069         bool contains( const Region& r, unsigned fuzz=0 ) const;
00070         unsigned OrigNr() const { return( orig_num ); }
00071         bool boot() const { return bootflag; }
00072         unsigned id() const { return idt; }
00073         storage::PartitionType type() const { return typ; }
00074 
00075         void changeRegion(const Region& cylRegion, unsigned long long SizeK);
00076         void changeNumber( unsigned new_num );
00077         int changeId(unsigned id);
00078         void changeIdDone();
00079         void unChangeId();
00080         Text removeText(bool doing) const;
00081         Text createText(bool doing) const;
00082         Text formatText(bool doing) const;
00083         Text resizeText(bool doing) const;
00084         void getCommitActions(list<commitAction>& l) const;
00085         Text setTypeText(bool doing) const;
00086         int setFormat( bool format=true, storage::FsType fs=storage::REISERFS );
00087         int changeMount( const string& val );
00088         const Disk* disk() const;
00089         bool isWindows() const;
00090         friend std::ostream& operator<< (std::ostream& s, const Partition &p );
00091         static bool notDeleted( const Partition&d ) { return( !d.deleted() ); }
00092         static bool toChangeId( const Partition&d ) { return( !d.deleted() && d.idt!=d.orig_id ); }
00093         virtual void print( std::ostream& s ) const { s << *this; }
00094         void setResizedSize( unsigned long long SizeK );
00095         void forgetResize(); 
00096         bool canUseDevice() const;
00097 
00098         /* partition region from sysfs in 512 byte blocks */
00099         Region detectSysfsBlkRegion(bool log_error = true) const;
00100 
00101         void getInfo( storage::PartitionInfo& info ) const;
00102         void getInfo( storage::PartitionAddInfo& info ) const;
00103 
00104         bool equalContent( const Partition& rhs ) const;
00105 
00106         void logDifference(std::ostream& log, const Partition& rhs) const;
00107 
00108         void addUdevData();
00109 
00110         int zeroIfNeeded() const;
00111 
00112         bool operator== ( const Partition& rhs ) const;
00113         bool operator!= ( const Partition& rhs ) const
00114             { return( !(*this==rhs) ); }
00115         bool operator< ( const Partition& rhs ) const;
00116         bool operator<= ( const Partition& rhs ) const
00117             { return( *this<rhs || *this==rhs ); }
00118         bool operator>= ( const Partition& rhs ) const
00119             { return( !(*this<rhs) ); }
00120         bool operator> ( const Partition& rhs ) const
00121             { return( !(*this<=rhs) ); }
00122 
00123         virtual list<string> getUsing() const;
00124 
00125     protected:
00126 
00127         Region reg;
00128         bool bootflag;
00129         storage::PartitionType typ;
00130         unsigned idt;
00131         unsigned orig_id;
00132         unsigned orig_num;
00133 
00134         void addAltUdevId( unsigned num );
00135         void addAltUdevPath( unsigned num );
00136 
00137         mutable storage::PartitionInfo info; // workaround for broken ycp bindings
00138 
00139     private:
00140 
00141         Partition(const Partition&); // disallow
00142         Partition& operator=(const Partition&); // disallow
00143 
00144     };
00145 
00146 }
00147 
00148 #endif