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 #include "tqvariant.h" 00025 00026 struct crypt_device; 00027 00028 // Keep readDiskDeviceSubtypeFromString() in tdehardwaredevices.cpp in sync with this enum 00029 namespace TDEDiskDeviceType { 00030 #if __cplusplus >= 201103L 00031 enum TDEDiskDeviceType : unsigned long long { 00032 #else 00033 enum TDEDiskDeviceType { 00034 #endif 00035 Null = 0x0000000000000000ULL, 00036 MediaDevice = 0x0000000000000001ULL, 00037 Floppy = 0x0000000000000002ULL, 00038 CDROM = 0x0000000000000004ULL, 00039 CDR = 0x0000000000000008ULL, 00040 CDRW = 0x0000000000000010ULL, 00041 CDMO = 0x0000000000000020ULL, 00042 CDMRRW = 0x0000000000000040ULL, 00043 CDMRRWW = 0x0000000000000080ULL, 00044 DVDROM = 0x0000000000000100ULL, 00045 DVDRAM = 0x0000000000000200ULL, 00046 DVDR = 0x0000000000000400ULL, 00047 DVDRW = 0x0000000000000800ULL, 00048 DVDRDL = 0x0000000000001000ULL, 00049 DVDRWDL = 0x0000000000002000ULL, 00050 DVDPLUSR = 0x0000000000004000ULL, 00051 DVDPLUSRW = 0x0000000000008000ULL, 00052 DVDPLUSRDL = 0x0000000000010000ULL, 00053 DVDPLUSRWDL = 0x0000000000020000ULL, 00054 BDROM = 0x0000000000040000ULL, 00055 BDR = 0x0000000000080000ULL, 00056 BDRW = 0x0000000000100000ULL, 00057 HDDVDROM = 0x0000000000200000ULL, 00058 HDDVDR = 0x0000000000400000ULL, 00059 HDDVDRW = 0x0000000000800000ULL, 00060 Zip = 0x0000000001000000ULL, 00061 Jaz = 0x0000000002000000ULL, 00062 Camera = 0x0000000004000000ULL, 00063 LUKS = 0x0000000008000000ULL, 00064 OtherCrypted = 0x0000000010000000ULL, 00065 CDAudio = 0x0000000020000000ULL, 00066 CDVideo = 0x0000000040000000ULL, 00067 DVDVideo = 0x0000000080000000ULL, 00068 BDVideo = 0x0000000100000000ULL, 00069 Flash = 0x0000000200000000ULL, 00070 USB = 0x0000000400000000ULL, 00071 Tape = 0x0000000800000000ULL, 00072 HDD = 0x0000001000000000ULL, 00073 Optical = 0x0000002000000000ULL, 00074 RAM = 0x0000004000000000ULL, 00075 Loop = 0x0000008000000000ULL, 00076 CompactFlash = 0x0000010000000000ULL, 00077 MemoryStick = 0x0000020000000000ULL, 00078 SmartMedia = 0x0000040000000000ULL, 00079 SDMMC = 0x0000080000000000ULL, 00080 UnlockedCrypt = 0x0000100000000000ULL, 00081 Other = 0x8000000000000000ULL 00082 }; 00083 00084 inline TDEDiskDeviceType operator|(TDEDiskDeviceType a, TDEDiskDeviceType b) 00085 { 00086 return static_cast<TDEDiskDeviceType>(static_cast<unsigned long long>(a) | static_cast<unsigned long long>(b)); 00087 } 00088 00089 inline TDEDiskDeviceType operator&(TDEDiskDeviceType a, TDEDiskDeviceType b) 00090 { 00091 return static_cast<TDEDiskDeviceType>(static_cast<unsigned long long>(a) & static_cast<unsigned long long>(b)); 00092 } 00093 00094 inline TDEDiskDeviceType operator~(TDEDiskDeviceType a) 00095 { 00096 return static_cast<TDEDiskDeviceType>(~static_cast<unsigned long long>(a)); 00097 } 00098 }; 00099 00100 namespace TDEDiskDeviceStatus { 00101 enum TDEDiskDeviceStatus { 00102 Null = 0x00000000, 00103 Mountable = 0x00000001, 00104 Removable = 0x00000002, 00105 Inserted = 0x00000004, 00106 Blank = 0x00000008, 00107 UsedByDevice = 0x00000010, 00108 UsesDevice = 0x00000020, 00109 ContainsFilesystem = 0x00000040, 00110 Hotpluggable = 0x00000080, 00111 Hidden = 0x00000100, 00112 Other = 0x80000000 00113 }; 00114 00115 inline TDEDiskDeviceStatus operator|(TDEDiskDeviceStatus a, TDEDiskDeviceStatus b) 00116 { 00117 return static_cast<TDEDiskDeviceStatus>(static_cast<int>(a) | static_cast<int>(b)); 00118 } 00119 00120 inline TDEDiskDeviceStatus operator&(TDEDiskDeviceStatus a, TDEDiskDeviceStatus b) 00121 { 00122 return static_cast<TDEDiskDeviceStatus>(static_cast<int>(a) & static_cast<int>(b)); 00123 } 00124 00125 inline TDEDiskDeviceStatus operator~(TDEDiskDeviceStatus a) 00126 { 00127 return static_cast<TDEDiskDeviceStatus>(~static_cast<int>(a)); 00128 } 00129 }; 00130 00131 namespace TDELUKSKeySlotStatus { 00132 enum TDELUKSKeySlotStatus { 00133 Invalid = 0x00000000, 00134 Inactive = 0x00000001, 00135 Active = 0x00000002, 00136 Last = 0x00000004, 00137 Other = 0x80000000 00138 }; 00139 00140 inline TDELUKSKeySlotStatus operator|(TDELUKSKeySlotStatus a, TDELUKSKeySlotStatus b) 00141 { 00142 return static_cast<TDELUKSKeySlotStatus>(static_cast<int>(a) | static_cast<int>(b)); 00143 } 00144 00145 inline TDELUKSKeySlotStatus operator&(TDELUKSKeySlotStatus a, TDELUKSKeySlotStatus b) 00146 { 00147 return static_cast<TDELUKSKeySlotStatus>(static_cast<int>(a) & static_cast<int>(b)); 00148 } 00149 00150 inline TDELUKSKeySlotStatus operator~(TDELUKSKeySlotStatus a) 00151 { 00152 return static_cast<TDELUKSKeySlotStatus>(~static_cast<int>(a)); 00153 } 00154 }; 00155 00156 typedef TQValueList<TDELUKSKeySlotStatus::TDELUKSKeySlotStatus> TDELUKSKeySlotStatusList; 00157 00158 namespace TDELUKSResult { 00159 enum TDELUKSResult { 00160 Invalid = 0x00000000, 00161 Success = 0x00000001, 00162 LUKSNotSupported = 0x00000002, 00163 LUKSNotFound = 0x00000003, 00164 InvalidKeyslot = 0x00000004, 00165 KeyslotOpFailed = 0x00000005, 00166 Other = 0x80000000 00167 }; 00168 }; 00169 00170 typedef TQMap<TQString, TQString> TDEStorageMountOptions; 00171 00172 class TDECORE_EXPORT TDEStorageDevice : public TDEGenericDevice 00173 { 00174 public: 00179 TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn=TQString::null); 00180 00184 ~TDEStorageDevice(); 00185 00189 TQString diskLabel(); 00190 00194 TQString diskUUID(); 00195 00199 TDEDiskDeviceType::TDEDiskDeviceType diskType(); 00200 00204 TDEDiskDeviceStatus::TDEDiskDeviceStatus diskStatus(); 00205 00209 bool mediaInserted(); 00210 00214 TQString fileSystemName(); 00215 00219 TQString fileSystemUsage(); 00220 00224 TQStringList holdingDevices(); 00225 00229 TQStringList slaveDevices(); 00230 00239 TQStringVariantMap mountDevice(TQString mediaName = TQString::null, 00240 TDEStorageMountOptions mountOptions = TDEStorageMountOptions()); 00241 00251 TQStringVariantMap mountEncryptedDevice(TQString passphrase, TQString mediaName = TQString::null, 00252 TDEStorageMountOptions mountOptions = TDEStorageMountOptions()); 00253 00259 TQStringVariantMap unmountDevice(); 00260 00264 TQString mountPath(); 00265 00269 unsigned long long deviceSize(); 00270 00274 TQString deviceFriendlySize(); 00275 00283 TQPixmap icon(TDEIcon::StdSizes size); 00284 00290 TQString friendlyName(); 00291 00297 TQString detailedFriendlyName(); 00298 00304 TQString friendlyDeviceType(); 00305 00309 bool isDiskOfType(TDEDiskDeviceType::TDEDiskDeviceType tf); 00310 00314 bool checkDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus sf); 00315 00322 bool lockDriveMedia(bool lock); 00323 00329 bool ejectDriveMedia(); 00330 00336 bool ejectDrive(); 00337 00343 static TQString determineFileSystemType(TQString path); 00344 00351 void cryptSetOperationsUnlockPassword(TQByteArray password); 00352 00357 void cryptClearOperationsUnlockPassword(); 00358 00364 bool cryptOperationsUnlockPasswordSet(); 00365 00376 TDELUKSResult::TDELUKSResult cryptCheckKey(unsigned int keyslot); 00377 00389 TDELUKSResult::TDELUKSResult cryptAddKey(unsigned int keyslot, TQByteArray password); 00390 00399 TDELUKSResult::TDELUKSResult cryptDelKey(unsigned int keyslot); 00400 00404 unsigned int cryptKeySlotCount(); 00405 00409 TDELUKSKeySlotStatusList cryptKeySlotStatus(); 00410 00415 TQString cryptKeySlotFriendlyName(TDELUKSKeySlotStatus::TDELUKSKeySlotStatus status); 00416 00417 protected: 00424 void internalSetDeviceNode(TQString sn); 00425 00430 void internalSetDiskLabel(TQString dn); 00431 00436 void internalSetDiskUUID(TQString id); 00437 00442 void internalSetDiskType(TDEDiskDeviceType::TDEDiskDeviceType tf); 00443 00448 void internalSetDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus st); 00449 00454 void internalSetMediaInserted(bool inserted); 00455 00460 void internalSetFileSystemName(TQString fn); 00461 00466 void internalSetFileSystemUsage(TQString fu); 00467 00472 void internalSetHoldingDevices(TQStringList hd); 00473 00478 void internalSetSlaveDevices(TQStringList sd); 00479 00483 void internalInitializeLUKSIfNeeded(); 00484 00488 void internalGetLUKSKeySlotStatus(); 00489 00490 private: 00491 TDEDiskDeviceType::TDEDiskDeviceType m_diskType; 00492 TDEDiskDeviceStatus::TDEDiskDeviceStatus m_diskStatus; 00493 TQString m_diskName; 00494 TQString m_diskUUID; 00495 TQString m_fileSystemName; 00496 TQString m_fileSystemUsage; 00497 bool m_mediaInserted; 00498 TQString m_mountPath; 00499 TQStringList m_holdingDevices; 00500 TQStringList m_slaveDevices; 00501 struct crypt_device* m_cryptDevice; 00502 TQByteArray m_cryptDevicePassword; 00503 TQString m_cryptDeviceType; 00504 unsigned int m_cryptKeySlotCount; 00505 TDELUKSKeySlotStatusList m_cryptKeyslotStatus; 00506 00507 friend class TDEHardwareDevices; 00508 }; 00509 00510 #endif // _TDESTORAGEDEVICE_H
Trinity API Reference