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

Generated on Tue Nov 28 17:50:01 2006 for yast2-storage by  doxygen 1.5.0