|
yast2-storage
|
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 VOLUME_H 00024 #define VOLUME_H 00025 00026 #include "storage/Blkid.h" 00027 #include "storage/StorageInterface.h" 00028 #include "storage/StorageTypes.h" 00029 #include "storage/StorageTmpl.h" 00030 #include "storage/Device.h" 00031 #include "storage/Enum.h" 00032 00033 00034 namespace storage 00035 { 00036 using std::list; 00037 00038 00039 class SystemCmd; 00040 class ProcMounts; 00041 class EtcFstab; 00042 class FstabEntry; 00043 class Container; 00044 class Storage; 00045 00046 00047 class Volume : public Device 00048 { 00049 friend class Storage; 00050 00051 public: 00052 00053 Volume(const Container& c, unsigned Pnr, unsigned long long SizeK); 00054 Volume(const Container& c, const string& name, const string& device); 00055 Volume(const Container& c, const string& name, const string& device, 00056 SystemInfo& systeminfo); 00057 Volume(const Container& c, const xmlNode* node); 00058 Volume(const Container& c, const Volume& v); 00059 virtual ~Volume(); 00060 00061 void saveData(xmlNode* node) const; 00062 00063 const string& mountDevice() const; 00064 const string& loopDevice() const { return( loop_dev ); } 00065 const string& dmcryptDevice() const { return( dmcrypt_dev ); } 00066 00067 const Container* getContainer() const { return cont; } 00068 Storage* getStorage() const; 00069 00070 storage::CType cType() const; 00071 void setReadonly( bool val=true ) { ronly=val; } 00072 bool ignoreFstab() const { return( ignore_fstab ); } 00073 void setIgnoreFstab( bool val=true ) { ignore_fstab=val; } 00074 bool ignoreFs() const { return( ignore_fs ); } 00075 void setIgnoreFs( bool val=true ) { ignore_fs=val; } 00076 void setFstabAdded( bool val=true ) { fstab_added=val; } 00077 bool fstabAdded() const { return( fstab_added ); } 00078 00079 void getFsInfo( const Volume* source ); 00080 00081 virtual int setFormat( bool format=true, storage::FsType fs=storage::REISERFS ); 00082 void formattingDone() { format=false; fs=detected_fs; } 00083 bool getFormat() const { return format; } 00084 int changeFstabOptions( const string& options ); 00085 int changeMountBy( storage::MountByType mby ); 00086 virtual int changeMount( const string& m ); 00087 bool loop() const { return is_loop; } 00088 bool dmcrypt() const { return encryption != ENC_NONE && encryption != ENC_UNKNOWN; } 00089 bool loopActive() const { return( is_loop&&loop_active ); } 00090 bool dmcryptActive() const { return( dmcrypt()&&dmcrypt_active ); } 00091 bool needCrsetup( bool urgent=true ) const; 00092 const string& getUuid() const { return uuid; } 00093 const string& getLabel() const { return label; } 00094 int setLabel( const string& val ); 00095 int eraseLabel() { label.erase(); orig_label.erase(); return 0; } 00096 int eraseUuid() { uuid.erase(); orig_uuid.erase(); return 0; } 00097 bool needLabel() const { return( label!=orig_label ); } 00098 storage::EncryptType getEncryption() const { return encryption; } 00099 void initEncryption( storage::EncryptType val=storage::ENC_LUKS ) 00100 { encryption=orig_encryption=val; } 00101 virtual int setEncryption(bool val, storage::EncryptType typ = storage::ENC_LUKS ); 00102 const string& getCryptPwd() const { return crypt_pwd; } 00103 int setCryptPwd( const string& val ); 00104 void clearCryptPwd() { crypt_pwd.erase(); orig_crypt_pwd.erase(); } 00105 bool needCryptPwd() const; 00106 const string& getMount() const { return mp; } 00107 bool hasOrigMount() const { return !orig_mp.empty(); } 00108 bool needRemount() const; 00109 bool needShrink() const { return cType()!=BTRFSC && !del && size_k<orig_size_k; } 00110 bool needExtend() const { return cType()!=BTRFSC && !del && size_k>orig_size_k; } 00111 long long extendSize() const { return size_k-orig_size_k; } 00112 storage::FsType getFs() const { return fs; } 00113 storage::FsType detectedFs() const { return detected_fs; } 00114 void setFs( storage::FsType val ) { detected_fs=fs=val; } 00115 void initUuid( const string& id ) { uuid=orig_uuid=id; } 00116 void initLabel( const string& lbl ) { label=orig_label=lbl; } 00117 storage::MountByType getMountBy() const { return mount_by; } 00118 const string& getFstabOption() const { return fstab_opt; } 00119 void setFstabOption( const string& val ) { orig_fstab_opt=fstab_opt=val; } 00120 unsigned fstabFreq() const; 00121 unsigned fstabPassno() const; 00122 void setMount( const string& val ) { orig_mp=mp=val; } 00123 void updateFstabOptions(); 00124 bool needFstabUpdate() const; 00125 const string& getMkfsOption() const { return mkfs_opt; } 00126 int setMkfsOption( const string& val ) { mkfs_opt=val; return 0; } 00127 const string& getTunefsOption() const { return tunefs_opt; } 00128 int setTunefsOption( const string& val ) { tunefs_opt=val; return 0; } 00129 const string& getDescText() const { return dtxt; } 00130 int setDescText( const string& val ) { dtxt=val; return 0; } 00131 unsigned nr() const { return num; } 00132 unsigned long long origSizeK() const { return orig_size_k; } 00133 bool isNumeric() const { return numeric; } 00134 void setSize( unsigned long long SizeK ) { size_k=orig_size_k=SizeK; } 00135 virtual void setResizedSize( unsigned long long SizeK ) { size_k=SizeK; } 00136 void setUsedByUuid( UsedByType type, const string& uuid ); 00137 void setDmcryptDev( const string& dm, bool active ); 00138 void setDmcryptDevEnc( const string& dm, storage::EncryptType typ, bool active ); 00139 virtual void forgetResize() { size_k=orig_size_k; } 00140 virtual bool canUseDevice() const; 00141 00142 bool operator== ( const Volume& rhs ) const; 00143 bool operator!= ( const Volume& rhs ) const 00144 { return( !(*this==rhs) ); } 00145 bool operator< ( const Volume& rhs ) const; 00146 bool operator<= ( const Volume& rhs ) const 00147 { return( *this<rhs || *this==rhs ); } 00148 bool operator>= ( const Volume& rhs ) const 00149 { return( !(*this<rhs) ); } 00150 bool operator> ( const Volume& rhs ) const 00151 { return( !(*this<=rhs) ); } 00152 00153 bool equalContent(const Volume& rhs) const; 00154 00155 void logDifference(std::ostream& log, const Volume& rhs) const; 00156 00157 friend std::ostream& operator<< (std::ostream& s, const Volume &v ); 00158 00159 int prepareRemove(); 00160 int unaccessVol(); 00161 int umount( const string& mp="" ); 00162 int crUnsetup( bool force=false ); 00163 int mount( const string& mp="", bool ro=false ); 00164 int canResize( unsigned long long newSizeK ) const; 00165 int doMount(); 00166 int doFormat(); 00167 int doCrsetup(bool readonly); 00168 int doSetLabel(); 00169 int doFstabUpdate(bool force=false); 00170 int resizeFs(); 00171 void fstabUpdateDone(); 00172 bool isMounted() const { return( is_mounted ); } 00173 void setMounted( bool mtd=true ) { is_mounted=mtd; } 00174 virtual Text removeText(bool doing) const; 00175 virtual Text createText(bool doing) const; 00176 virtual Text resizeText(bool doing) const; 00177 virtual Text formatText(bool doing) const; 00178 virtual void getCommitActions(list<commitAction>& l) const; 00179 virtual Text mountText(bool doing) const; 00180 Text labelText(bool doing) const; 00181 Text losetupText(bool doing) const; 00182 Text crsetupText(bool doing) const; 00183 Text fstabUpdateText() const; 00184 bool optNoauto() const; 00185 bool inCryptotab() const { return( encryption!=ENC_NONE && 00186 encryption!=ENC_LUKS && 00187 !optNoauto() ); } 00188 bool inCrypttab() const { return( encryption==ENC_LUKS ); } 00189 bool pvEncryption() const; 00190 virtual void print( std::ostream& s ) const { s << *this; } 00191 int getFreeLoop(); 00192 int getFreeLoop( SystemCmd& loopData ); 00193 int getFreeLoop( SystemCmd& loopData, const std::list<unsigned>& ids ); 00194 void getInfo( storage::VolumeInfo& info ) const; 00195 void mergeFstabInfo( storage::VolumeInfo& tinfo, const FstabEntry& fste ) const; 00196 void updateFsData( bool setUsedByLvm=false ); 00197 void triggerUdevUpdate() const; 00198 static bool loopInUse(const Storage* sto, const string& loopdev); 00199 00200 static bool notDeleted( const Volume&d ) { return( !d.deleted() ); } 00201 static bool isDeleted( const Volume&d ) { return( d.deleted() ); } 00202 00203 static bool loopStringNum( const string& name, unsigned& num ); 00204 00205 const string& fsTypeString() const { return toString(fs); } 00206 00207 static bool isTmpCryptMp( const string& mp ); 00208 00209 protected: 00210 void init(); 00211 void setNameDev(); 00212 int checkDevice() const; 00213 int checkDevice(const string& device) const; 00214 MountByType defaultMountBy() const; 00215 bool allowedMountBy(MountByType mby) const; 00216 bool findBlkid( const Blkid& blkid, Blkid::Entry& entry ); 00217 void getFsData(const Blkid& blkid, bool setUsedByLvm=false ); 00218 void getLoopData( SystemCmd& loopData ); 00219 void getMountData(const ProcMounts& mounts, bool swap_only = false); 00220 void getFstabData( EtcFstab& fstabData ); 00221 void updateUuid( const string& new_uuid ); 00222 void replaceAltName( const string& prefix, const string& newn ); 00223 string getMountByString() const; 00224 string getFstabDevice() const; 00225 string getFstabDentry() const; 00226 list<string> getFstabOpts() const; 00227 bool getLoopFile( string& fname ) const; 00228 void setExtError( const SystemCmd& cmd, bool serr=true ); 00229 string getDmcryptName() const; 00230 void addDmCryptNames(unsigned long minor); 00231 void removeDmCryptNames(); 00232 bool needLosetup( bool urgent ) const; 00233 bool needCryptsetup() const; 00234 int doLosetup(); 00235 int doCryptsetup(bool readonly); 00236 int loUnsetup( bool force=false ); 00237 int cryptUnsetup( bool force=false ); 00238 bool pwdLengthOk( storage::EncryptType typ, const string& val, 00239 bool format ) const; 00240 bool noFreqPassno() const; 00241 int prepareTmpMount( string& m, bool& needUmount, bool useMounted=true, 00242 const string& options="" ) const; 00243 int umountTmpMount( const string& m, int ret ) const; 00244 int doFormatBtrfs(); 00245 00246 string getLosetupCmd( storage::EncryptType, const string& pwdfile ) const; 00247 string getCryptsetupCmd( storage::EncryptType e, const string& dmdev, 00248 const string& mp, const string& pwdfile, bool format, 00249 bool empty_pwd=false ) const; 00250 storage::EncryptType detectEncryption(); 00251 string getFilesysSysfsPath() const; 00252 00253 const Container* const cont; 00254 bool numeric; 00255 bool format; 00256 bool fstab_added; 00257 storage::FsType fs; 00258 storage::FsType detected_fs; 00259 storage::MountByType mount_by; 00260 storage::MountByType orig_mount_by; 00261 string uuid; 00262 string orig_uuid; 00263 string label; 00264 string orig_label; 00265 string mp; 00266 string orig_mp; 00267 string fstab_opt; 00268 string orig_fstab_opt; 00269 string mkfs_opt; 00270 string tunefs_opt; 00271 bool is_loop; 00272 bool is_mounted; 00273 bool ignore_fstab; 00274 bool ignore_fs; 00275 bool loop_active; 00276 bool dmcrypt_active; 00277 bool ronly; 00278 storage::EncryptType encryption; 00279 storage::EncryptType orig_encryption; 00280 string loop_dev; 00281 string dmcrypt_dev; 00282 string fstab_loop_dev; 00283 string crypt_pwd; 00284 string orig_crypt_pwd; 00285 unsigned num; 00286 unsigned long long orig_size_k; 00287 string dtxt; 00288 00289 static const string tmp_mount[3]; 00290 static const string ignore_opt[1]; 00291 static const string ignore_beg[4]; 00292 00293 mutable storage::VolumeInfo info; // workaround for broken ycp bindings 00294 00295 private: 00296 00297 Volume(const Volume&); // disallow 00298 Volume& operator=(const Volume&); // disallow 00299 00300 }; 00301 00302 } 00303 00304 #endif
1.7.3