Volume.h

Go to the documentation of this file.
00001 #ifndef VOLUME_H
00002 #define VOLUME_H
00003 
00004 #include "y2storage/StorageInterface.h"
00005 #include "y2storage/StorageTypes.h"
00006 #include "y2storage/StorageTmpl.h"
00007 
00008 namespace storage
00009 {
00010 
00011 class SystemCmd;
00012 class ProcMounts;
00013 class EtcFstab;
00014 class FstabEntry;
00015 class Container;
00016 class Storage;
00017 
00018 class Volume
00019     {
00020     friend class Storage;
00021 
00022     public:
00023         Volume( const Container& d, unsigned Pnr, unsigned long long SizeK );
00024         Volume( const Container& d, const string& PName, unsigned long long SizeK );
00025         Volume( const Container& d );
00026         Volume( const Volume& );
00027         Volume& operator=( const Volume& );
00028 
00029         virtual ~Volume();
00030 
00031         const string& device() const { return dev; }
00032         const string& mountDevice() const { return( is_loop?loop_dev:dev ); }
00033         const string& loopDevice() const { return( loop_dev ); }
00034         const Container* getContainer() const { return cont; }
00035         storage::CType cType() const;
00036         bool deleted() const { return del; }
00037         bool created() const { return create; }
00038         bool silent() const { return silnt; }
00039         virtual const std::list<string> udevId() const { return(empty_slist); }
00040         virtual const string& udevPath() const { return(empty_string); }
00041         virtual string sysfsPath() const; 
00042         void setDeleted( bool val=true ) { del=val; }
00043         void setCreated( bool val=true ) { create=val; }
00044         void setReadonly( bool val=true ) { ronly=val; }
00045         void setSilent( bool val=true ) { silnt=val; }
00046         bool ignoreFstab() const { return( ignore_fstab ); }
00047         void setIgnoreFstab( bool val=true ) { ignore_fstab=val; }
00048         void setFstabAdded( bool val=true ) { fstab_added=val; }
00049         bool fstabAdded() const { return( fstab_added ); }
00050         const storage::usedBy& getUsedBy()  const{ return( uby ); }
00051         storage::UsedByType getUsedByType() const { return( uby.type() ); }
00052         const string& usedByName() const { return( uby.name() ); }
00053         void setUsedBy( storage::UsedByType t, const string& name ) { uby.set( t, name );}
00054 
00055         virtual int setFormat( bool format=true, storage::FsType fs=storage::REISERFS );
00056         void formattingDone() { format=false; detected_fs=fs; }
00057         bool getFormat() const { return format; }
00058         void rename( const string& newName );
00059         int changeFstabOptions( const string& options );
00060         int changeMountBy( storage::MountByType mby );
00061         virtual int changeMount( const string& m );
00062         bool loop() const { return is_loop; }
00063         bool loopActive() const { return( is_loop&&loop_active ); }
00064         bool needLosetup() const; 
00065         const string& getUuid() const { return uuid; }
00066         const string& getLabel() const { return label; }
00067         int setLabel( const string& val );
00068         bool needLabel() const { return( label!=orig_label ); }
00069         storage::EncryptType getEncryption() const { return encryption; }
00070         void setEncryption( storage::EncryptType val=storage::ENC_TWOFISH )
00071             { encryption=orig_encryption=val; }
00072         int setEncryption( bool val );
00073         const string& getCryptPwd() const { return crypt_pwd; }
00074         int setCryptPwd( const string& val );
00075         void clearCryptPwd() { crypt_pwd.erase(); }
00076         const string& getMount() const { return mp; }
00077         bool needRemount() const;
00078         bool needShrink() const { return(size_k<orig_size_k); }
00079         bool needExtend() const { return(size_k>orig_size_k); }
00080         long long extendSize() const { return(orig_size_k-size_k);}
00081         storage::FsType getFs() const { return fs; }
00082         void setFs( storage::FsType val ) { detected_fs=fs=val; }
00083         void setUuid( const string& id ) { uuid=id; }
00084         void initLabel( const string& lbl ) { label=orig_label=lbl; }
00085         storage::MountByType getMountBy() const { return mount_by; }
00086         const string& getFstabOption() const { return fstab_opt; }
00087         void setFstabOption( const string& val ) { fstab_opt=val; }
00088         bool needFstabUpdate() const
00089             { return( !ignore_fstab &&
00090                       (fstab_opt!=orig_fstab_opt || mount_by!=orig_mount_by ||
00091                        encryption!=orig_encryption) ); }
00092         const string& getMkfsOption() const { return mkfs_opt; }
00093         int setMkfsOption( const string& val ) { mkfs_opt=val; return 0; }
00094         const std::list<string>& altNames() const { return( alt_names ); }
00095         unsigned nr() const { return num; }
00096         unsigned long long sizeK() const { return size_k; }
00097         unsigned long long origSizeK() const { return orig_size_k; }
00098         const string& name() const { return nm; }
00099         unsigned long minorNr() const { return mnr; }
00100         unsigned long majorNr() const { return mjr; }
00101         void setMajorMinor( unsigned long Major, unsigned long Minor )
00102             { mjr=Major; mnr=Minor; }
00103         void setSize( unsigned long long SizeK ) { size_k=orig_size_k=SizeK; }
00104         virtual void setResizedSize( unsigned long long SizeK ) { size_k=SizeK; }
00105         virtual void forgetResize() { size_k=orig_size_k; }
00106         virtual bool canUseDevice() const;
00107 
00108         bool operator== ( const Volume& rhs ) const;
00109         bool operator!= ( const Volume& rhs ) const
00110             { return( !(*this==rhs) ); }
00111         bool operator< ( const Volume& rhs ) const;
00112         bool operator<= ( const Volume& rhs ) const
00113             { return( *this<rhs || *this==rhs ); }
00114         bool operator>= ( const Volume& rhs ) const
00115             { return( !(*this<rhs) ); }
00116         bool operator> ( const Volume& rhs ) const
00117             { return( !(*this<=rhs) ); }
00118         bool equalContent( const Volume& rhs ) const;
00119         string logDifference( const Volume& c ) const;
00120         friend std::ostream& operator<< (std::ostream& s, const Volume &v );
00121 
00122         int prepareRemove();
00123         int umount( const string& mp="" );
00124         int loUnsetup();
00125         int mount( const string& mp="" );
00126         int canResize( unsigned long long newSizeK ) const;
00127         int doMount();
00128         int doFormat();
00129         int doLosetup();
00130         int doSetLabel();
00131         int doFstabUpdate();
00132         int resizeFs();
00133         void fstabUpdateDone();
00134         bool isMounted() const { return( is_mounted ); }
00135         virtual string removeText(bool doing=true) const;
00136         virtual string createText(bool doing=true) const;
00137         virtual string resizeText(bool doing=true) const;
00138         virtual string formatText(bool doing=true) const;
00139         virtual void getCommitActions( std::list<storage::commitAction*>& l ) const;
00140         string mountText( bool doing=true ) const;
00141         string labelText( bool doing=true ) const;
00142         string losetupText( bool doing=true ) const;
00143         string fstabUpdateText() const;
00144         string sizeString() const;
00145         string bootMount() const;
00146         bool optNoauto() const;
00147         bool inCrypto() const { return( is_loop && !optNoauto() ); }
00148         virtual void print( std::ostream& s ) const { s << *this; }
00149         int getFreeLoop();
00150         void getInfo( storage::VolumeInfo& info ) const;
00151         void mergeFstabInfo( storage::VolumeInfo& tinfo, const FstabEntry& fste ) const;
00152         void updateFsData();
00153         static bool loopInUse( Storage* sto, const string& loopdev );
00154 
00155         struct SkipDeleted
00156             {
00157             bool operator()(const Volume&d) const { return( !d.deleted());}
00158             };
00159         static SkipDeleted SkipDel;
00160         static bool notDeleted( const Volume&d ) { return( !d.deleted() ); }
00161         static bool isDeleted( const Volume&d ) { return( d.deleted() ); }
00162         static bool getMajorMinor( const string& device,
00163                                    unsigned long& Major, unsigned long& Minor );
00164         static bool loopStringNum( const string& name, unsigned& num );
00165         static storage::EncryptType toEncType( const string& val );
00166         static storage::FsType toFsType( const string& val );
00167         static storage::MountByType toMountByType( const string& val );
00168         const string& fsTypeString() const { return fs_names[fs]; }
00169         static const string& fsTypeString( const storage::FsType type )
00170             { return fs_names[type]; }
00171         static const string& encTypeString( const storage::EncryptType type )
00172             { return enc_names[type]; }
00173         static const string& mbyTypeString( const storage::MountByType type )
00174             { return mb_names[type]; }
00175 
00176 
00177     protected:
00178         void init();
00179         void setNameDev();
00180         int checkDevice();
00181         int checkDevice( const string& device );
00182         storage::MountByType defaultMountBy( const string& mp="" );
00183         bool allowedMountBy( storage::MountByType mby, const string& mp="" );
00184         void getFsData( SystemCmd& blkidData );
00185         void getLoopData( SystemCmd& loopData );
00186         void getMountData( const ProcMounts& mountData );
00187         void getFstabData( EtcFstab& fstabData );
00188         void getTestmodeData( const string& data );
00189         string getMountByString( storage::MountByType mby, const string& dev,
00190                                  const string& uuid, const string& label ) const;
00191         void setExtError( const SystemCmd& cmd, bool serr=true );
00192 
00193         std::ostream& logVolume( std::ostream& file ) const;
00194         string getLosetupCmd( storage::EncryptType e, const string& pwdfile ) const;
00195         storage::EncryptType detectLoopEncryption();
00196         string getFilesysSysfsPath() const;
00197         void triggerUdevUpdate();
00198 
00199         const Container* const cont;
00200         bool numeric;
00201         bool create;
00202         bool del;
00203         bool format;
00204         bool silnt;
00205         bool fstab_added;
00206         storage::FsType fs;
00207         storage::FsType detected_fs;
00208         storage::MountByType mount_by;
00209         storage::MountByType orig_mount_by;
00210         string uuid;
00211         string label;
00212         string orig_label;
00213         string mp;
00214         string orig_mp;
00215         string fstab_opt;
00216         string orig_fstab_opt;
00217         string mkfs_opt;
00218         bool is_loop;
00219         bool is_mounted;
00220         bool ignore_fstab;
00221         bool loop_active;
00222         bool ronly;
00223         storage::EncryptType encryption;
00224         storage::EncryptType orig_encryption;
00225         string loop_dev;
00226         string fstab_loop_dev;
00227         string crypt_pwd;
00228         string nm;
00229         std::list<string> alt_names;
00230         unsigned num;
00231         unsigned long long size_k;
00232         unsigned long long orig_size_k;
00233         string dev;
00234         unsigned long mnr;
00235         unsigned long mjr;
00236         storage::usedBy uby;
00237 
00238         static string fs_names[storage::FSNONE+1];
00239         static string mb_names[storage::MOUNTBY_PATH+1];
00240         static string enc_names[storage::ENC_UNKNOWN+1];
00241         static string empty_string;
00242         static std::list<string> empty_slist;
00243 
00244         mutable storage::VolumeInfo info;
00245     };
00246 
00247 }
00248 
00249 #endif

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