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

Generated on Tue Sep 25 21:19:22 2007 for yast2-storage by  doxygen 1.5.3