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

Generated on Wed Apr 30 14:58:40 2008 for yast2-storage by  doxygen 1.4.6