tdestoragedevice.h
00001 /* This file is part of the TDE libraries 00002 Copyright (C) 2012 Timothy Pearson <kb9vqf@pearsoncomputing.net> 00003 (C) 2013 Golubev Alexander <fatzer2@gmail.com> 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License version 2 as published by the Free Software Foundation. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef _TDESTORAGEDEVICE_H 00021 #define _TDESTORAGEDEVICE_H 00022 00023 #include "tdegenericdevice.h" 00024 00025 // Keep readDiskDeviceSubtypeFromString() in tdehardwaredevices.cpp in sync with this enum 00026 namespace TDEDiskDeviceType { 00027 #if __cplusplus >= 201103L 00028 enum TDEDiskDeviceType : unsigned long long { 00029 #else 00030 enum TDEDiskDeviceType { 00031 #endif 00032 Null = 0x0000000000000000ULL, 00033 MediaDevice = 0x0000000000000001ULL, 00034 Floppy = 0x0000000000000002ULL, 00035 CDROM = 0x0000000000000004ULL, 00036 CDR = 0x0000000000000008ULL, 00037 CDRW = 0x0000000000000010ULL, 00038 CDMO = 0x0000000000000020ULL, 00039 CDMRRW = 0x0000000000000040ULL, 00040 CDMRRWW = 0x0000000000000080ULL, 00041 DVDROM = 0x0000000000000100ULL, 00042 DVDRAM = 0x0000000000000200ULL, 00043 DVDR = 0x0000000000000400ULL, 00044 DVDRW = 0x0000000000000800ULL, 00045 DVDRDL = 0x0000000000001000ULL, 00046 DVDRWDL = 0x0000000000002000ULL, 00047 DVDPLUSR = 0x0000000000004000ULL, 00048 DVDPLUSRW = 0x0000000000008000ULL, 00049 DVDPLUSRDL = 0x0000000000010000ULL, 00050 DVDPLUSRWDL = 0x0000000000020000ULL, 00051 BDROM = 0x0000000000040000ULL, 00052 BDR = 0x0000000000080000ULL, 00053 BDRW = 0x0000000000100000ULL, 00054 HDDVDROM = 0x0000000000200000ULL, 00055 HDDVDR = 0x0000000000400000ULL, 00056 HDDVDRW = 0x0000000000800000ULL, 00057 Zip = 0x0000000001000000ULL, 00058 Jaz = 0x0000000002000000ULL, 00059 Camera = 0x0000000004000000ULL, 00060 LUKS = 0x0000000008000000ULL, 00061 OtherCrypted = 0x0000000010000000ULL, 00062 CDAudio = 0x0000000020000000ULL, 00063 CDVideo = 0x0000000040000000ULL, 00064 DVDVideo = 0x0000000080000000ULL, 00065 BDVideo = 0x0000000100000000ULL, 00066 Flash = 0x0000000200000000ULL, 00067 USB = 0x0000000400000000ULL, 00068 Tape = 0x0000000800000000ULL, 00069 HDD = 0x0000001000000000ULL, 00070 Optical = 0x0000002000000000ULL, 00071 RAM = 0x0000004000000000ULL, 00072 Loop = 0x0000008000000000ULL, 00073 CompactFlash = 0x0000010000000000ULL, 00074 MemoryStick = 0x0000020000000000ULL, 00075 SmartMedia = 0x0000040000000000ULL, 00076 SDMMC = 0x0000080000000000ULL, 00077 UnlockedCrypt = 0x0000100000000000ULL, 00078 Other = 0x8000000000000000ULL 00079 }; 00080 00081 inline TDEDiskDeviceType operator|(TDEDiskDeviceType a, TDEDiskDeviceType b) 00082 { 00083 return static_cast<TDEDiskDeviceType>(static_cast<unsigned long long>(a) | static_cast<unsigned long long>(b)); 00084 } 00085 00086 inline TDEDiskDeviceType operator&(TDEDiskDeviceType a, TDEDiskDeviceType b) 00087 { 00088 return static_cast<TDEDiskDeviceType>(static_cast<unsigned long long>(a) & static_cast<unsigned long long>(b)); 00089 } 00090 00091 inline TDEDiskDeviceType operator~(TDEDiskDeviceType a) 00092 { 00093 return static_cast<TDEDiskDeviceType>(~static_cast<unsigned long long>(a)); 00094 } 00095 }; 00096 00097 namespace TDEDiskDeviceStatus { 00098 enum TDEDiskDeviceStatus { 00099 Null = 0x00000000, 00100 Mountable = 0x00000001, 00101 Removable = 0x00000002, 00102 Inserted = 0x00000004, 00103 Blank = 0x00000008, 00104 UsedByDevice = 0x00000010, 00105 UsesDevice = 0x00000020, 00106 ContainsFilesystem = 0x00000040, 00107 Hotpluggable = 0x00000080, 00108 Hidden = 0x00000100, 00109 Other = 0x80000000 00110 }; 00111 00112 inline TDEDiskDeviceStatus operator|(TDEDiskDeviceStatus a, TDEDiskDeviceStatus b) 00113 { 00114 return static_cast<TDEDiskDeviceStatus>(static_cast<int>(a) | static_cast<int>(b)); 00115 } 00116 00117 inline TDEDiskDeviceStatus operator&(TDEDiskDeviceStatus a, TDEDiskDeviceStatus b) 00118 { 00119 return static_cast<TDEDiskDeviceStatus>(static_cast<int>(a) & static_cast<int>(b)); 00120 } 00121 00122 inline TDEDiskDeviceStatus operator~(TDEDiskDeviceStatus a) 00123 { 00124 return static_cast<TDEDiskDeviceStatus>(~static_cast<int>(a)); 00125 } 00126 }; 00127 00128 typedef TQMap<TQString,TQString> TDEStorageMountOptions; 00129 00130 class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice 00131 { 00132 public: 00137 TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null); 00138 00142 ~TDEStorageDevice(); 00143 00147 TQString diskLabel(); 00148 00152 TQString diskUUID(); 00153 00157 TDEDiskDeviceType::TDEDiskDeviceType diskType(); 00158 00162 TDEDiskDeviceStatus::TDEDiskDeviceStatus diskStatus(); 00163 00167 bool mediaInserted(); 00168 00172 TQString fileSystemName(); 00173 00177 TQString fileSystemUsage(); 00178 00182 TQStringList holdingDevices(); 00183 00187 TQStringList slaveDevices(); 00188 00199 TQString mountDevice(TQString mediaName=TQString::null, TDEStorageMountOptions mountOptions=TDEStorageMountOptions(), TQString* errRet=0, int* retcode=0); 00200 00212 TQString mountEncryptedDevice(TQString passphrase, TQString mediaName=TQString::null, TDEStorageMountOptions mountOptions=TDEStorageMountOptions(), TQString* errRet=0, int* retcode=0); 00213 00222 bool unmountDevice(TQString* errRet, int* retcode=0); 00223 00227 TQString mountPath(); 00228 00232 unsigned long long deviceSize(); 00233 00237 TQString deviceFriendlySize(); 00238 00246 TQPixmap icon(TDEIcon::StdSizes size); 00247 00253 TQString friendlyName(); 00254 00260 TQString detailedFriendlyName(); 00261 00267 TQString friendlyDeviceType(); 00268 00272 bool isDiskOfType(TDEDiskDeviceType::TDEDiskDeviceType tf); 00273 00277 bool checkDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus sf); 00278 00285 bool lockDriveMedia(bool lock); 00286 00292 bool ejectDriveMedia(); 00293 00299 bool ejectDrive(); 00300 00306 static TQString determineFileSystemType(TQString path); 00307 00308 protected: 00313 void internalSetDiskLabel(TQString dn); 00314 00319 void internalSetDiskUUID(TQString id); 00320 00325 void internalSetDiskType(TDEDiskDeviceType::TDEDiskDeviceType tf); 00326 00331 void internalSetDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus st); 00332 00337 void internalSetMediaInserted(bool inserted); 00338 00343 void internalSetFileSystemName(TQString fn); 00344 00349 void internalSetFileSystemUsage(TQString fu); 00350 00355 void internalSetHoldingDevices(TQStringList hd); 00356 00361 void internalSetSlaveDevices(TQStringList sd); 00362 00363 private: 00364 TDEDiskDeviceType::TDEDiskDeviceType m_diskType; 00365 TDEDiskDeviceStatus::TDEDiskDeviceStatus m_diskStatus; 00366 TQString m_diskName; 00367 TQString m_diskUUID; 00368 TQString m_fileSystemName; 00369 TQString m_fileSystemUsage; 00370 bool m_mediaInserted; 00371 TQString m_mountPath; 00372 TQStringList m_holdingDevices; 00373 TQStringList m_slaveDevices; 00374 00375 friend class TDEHardwareDevices; 00376 }; 00377 00378 #endif // _TDESTORAGEDEVICE_H