20#include "tdestoragedevice.h"
26#include <linux/cdrom.h>
35#include "kiconloader.h"
36#include "tdetempfile.h"
37#include "tdestandarddirs.h"
38#include "tdehardwaredevices.h"
39#include "disksHelper.h"
43#if defined(WITH_CRYPTSETUP)
44 #ifdef CRYPTSETUP_OLD_API
45 #define class cryptsetup_class
46 #define CRYPT_SLOT_INACTIVE SLOT_INACTIVE
47 #define CRYPT_SLOT_ACTIVE SLOT_ACTIVE
48 #define CRYPT_SLOT_ACTIVE_LAST SLOT_ACTIVE_LAST
49 #include <libcryptsetup.h>
52 #include <libcryptsetup.h>
56TDEStorageDevice::TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn), m_mediaInserted(true), m_cryptDevice(NULL) {
57 m_diskType = TDEDiskDeviceType::Null;
58 m_diskStatus = TDEDiskDeviceStatus::Null;
61TDEStorageDevice::~TDEStorageDevice() {
62#if defined(WITH_CRYPTSETUP)
64 crypt_free(m_cryptDevice);
70TQString TDEStorageDevice::mappedName() {
74void TDEStorageDevice::internalUpdateMappedName() {
76 m_mappedName = TQString::null;
77 TQString dmnodename = systemPath();
78 dmnodename.append(
"/dm/name");
79 TQFile dmnamefile(dmnodename);
80 if (dmnamefile.open(IO_ReadOnly)) {
81 TQTextStream stream(&dmnamefile);
82 m_mappedName = stream.readLine();
85 if (!m_mappedName.isEmpty()) {
86 m_mappedName.prepend(
"/dev/mapper/");
90TDEDiskDeviceType::TDEDiskDeviceType TDEStorageDevice::diskType() {
94void TDEStorageDevice::internalGetLUKSKeySlotStatus() {
95#if defined(WITH_CRYPTSETUP)
97 crypt_keyslot_info keyslot_status;
98 TDELUKSKeySlotStatus::TDELUKSKeySlotStatus tde_keyslot_status;
100 m_cryptKeyslotStatus.clear();
101 for (i = 0; i < m_cryptKeySlotCount; i++) {
102 keyslot_status = crypt_keyslot_status(m_cryptDevice, i);
103 tde_keyslot_status = TDELUKSKeySlotStatus::Invalid;
104 if (keyslot_status == CRYPT_SLOT_INACTIVE) {
105 tde_keyslot_status = TDELUKSKeySlotStatus::Inactive;
107 else if (keyslot_status == CRYPT_SLOT_ACTIVE) {
108 tde_keyslot_status = TDELUKSKeySlotStatus::Active;
110 else if (keyslot_status == CRYPT_SLOT_ACTIVE_LAST) {
111 tde_keyslot_status = TDELUKSKeySlotStatus::Active | TDELUKSKeySlotStatus::Last;
113 m_cryptKeyslotStatus.append(tde_keyslot_status);
118void TDEStorageDevice::internalInitializeLUKSIfNeeded() {
119#if defined(WITH_CRYPTSETUP)
122 if (m_diskType & TDEDiskDeviceType::LUKS) {
123 if (!m_cryptDevice) {
124 TQString node = deviceNode();
126 ret = crypt_init(&m_cryptDevice, node.ascii());
128 ret = crypt_load(m_cryptDevice, NULL, NULL);
131#if defined(CRYPTSETUP_OLD_API) || !defined(HAVE_CRYPTSETUP_GET_TYPE)
132 kdWarning() <<
"TDEStorageDevice: The version of libcryptsetup that TDE was compiled against was too old! Most LUKS features will not function" <<
endl;
133 m_cryptDeviceType = TQString::null;
136 m_cryptDeviceType = crypt_get_type(m_cryptDevice);
137 keyslot_count = crypt_keyslot_max(m_cryptDeviceType.ascii());
139 if (keyslot_count < 0) {
140 m_cryptKeySlotCount = 0;
143 m_cryptKeySlotCount = keyslot_count;
145 internalGetLUKSKeySlotStatus();
149 m_cryptDevice = NULL;
156 crypt_free(m_cryptDevice);
157 m_cryptDevice = NULL;
163void TDEStorageDevice::cryptSetOperationsUnlockPassword(TQByteArray password) {
164#if defined(WITH_CRYPTSETUP)
165 crypt_memory_lock(NULL, 1);
166 m_cryptDevicePassword = password;
170void TDEStorageDevice::cryptClearOperationsUnlockPassword() {
171 m_cryptDevicePassword.fill(0);
172 m_cryptDevicePassword.resize(0);
173#if defined(WITH_CRYPTSETUP)
174 crypt_memory_lock(NULL, 0);
178bool TDEStorageDevice::cryptOperationsUnlockPasswordSet() {
179 if (m_cryptDevicePassword.size() > 0) {
187TDELUKSResult::TDELUKSResult TDEStorageDevice::cryptCheckKey(
unsigned int keyslot) {
188#if defined(WITH_CRYPTSETUP)
192 if (keyslot < m_cryptKeySlotCount) {
193 ret = crypt_activate_by_passphrase(m_cryptDevice, NULL, keyslot, m_cryptDevicePassword.data(), m_cryptDevicePassword.size(), 0);
195 return TDELUKSResult::KeyslotOpFailed;
198 return TDELUKSResult::Success;
202 return TDELUKSResult::InvalidKeyslot;
206 return TDELUKSResult::LUKSNotFound;
209 return TDELUKSResult::LUKSNotSupported;
213TDELUKSResult::TDELUKSResult TDEStorageDevice::cryptAddKey(
unsigned int keyslot, TQByteArray password) {
214#if defined(WITH_CRYPTSETUP)
218 if (keyslot < m_cryptKeySlotCount) {
219 ret = crypt_keyslot_add_by_passphrase(m_cryptDevice, keyslot, m_cryptDevicePassword.data(), m_cryptDevicePassword.size(), password.data(), password.size());
221 return TDELUKSResult::KeyslotOpFailed;
224 internalGetLUKSKeySlotStatus();
225 return TDELUKSResult::Success;
229 return TDELUKSResult::InvalidKeyslot;
233 return TDELUKSResult::LUKSNotFound;
236 return TDELUKSResult::LUKSNotSupported;
240TDELUKSResult::TDELUKSResult TDEStorageDevice::cryptDelKey(
unsigned int keyslot) {
241#if defined(WITH_CRYPTSETUP)
245 if (keyslot < m_cryptKeySlotCount) {
246 ret = crypt_keyslot_destroy(m_cryptDevice, keyslot);
248 return TDELUKSResult::KeyslotOpFailed;
251 internalGetLUKSKeySlotStatus();
252 return TDELUKSResult::Success;
256 return TDELUKSResult::InvalidKeyslot;
260 return TDELUKSResult::LUKSNotFound;
263 return TDELUKSResult::LUKSNotSupported;
267unsigned int TDEStorageDevice::cryptKeySlotCount() {
268 return m_cryptKeySlotCount;
271TDELUKSKeySlotStatusList TDEStorageDevice::cryptKeySlotStatus() {
272 return m_cryptKeyslotStatus;
275TQString TDEStorageDevice::cryptKeySlotFriendlyName(TDELUKSKeySlotStatus::TDELUKSKeySlotStatus status) {
276 if (status & TDELUKSKeySlotStatus::Inactive) {
277 return i18n(
"Inactive");
279 else if (status & TDELUKSKeySlotStatus::Active) {
280 return i18n(
"Active");
283 return i18n(
"Unknown");
287void TDEStorageDevice::internalSetDeviceNode(TQString dn) {
288 TDEGenericDevice::internalSetDeviceNode(dn);
289 internalInitializeLUKSIfNeeded();
292void TDEStorageDevice::internalSetDiskType(TDEDiskDeviceType::TDEDiskDeviceType dt) {
294 internalInitializeLUKSIfNeeded();
297bool TDEStorageDevice::isDiskOfType(TDEDiskDeviceType::TDEDiskDeviceType tf) {
298 return ((m_diskType&tf)!=TDEDiskDeviceType::Null);
301TDEDiskDeviceStatus::TDEDiskDeviceStatus TDEStorageDevice::diskStatus() {
305void TDEStorageDevice::internalSetDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus st) {
309bool TDEStorageDevice::checkDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus sf) {
310 return ((m_diskStatus&sf)!=(TDEDiskDeviceStatus::TDEDiskDeviceStatus)0);
313bool TDEStorageDevice::lockDriveMedia(
bool lock) {
314 int fd =
open(deviceNode().ascii(), O_RDWR | O_NONBLOCK);
318 if (ioctl(fd, CDROM_LOCKDOOR, (lock)?1:0) != 0) {
328TQStringVariantMap TDEStorageDevice::ejectDrive() {
329 TQStringVariantMap result;
330 TQStringVariantMap ejectResult;
333 if (!mountPath().isEmpty()) {
339 ejectResult = udisks2EjectDrive(
this);
340 if (ejectResult[
"result"].toBool()) {
341 result[
"result"] =
true;
345 result[
"errStr"] = ejectResult[
"errStr"];
346 result[
"result"] =
false;
353 ejectResult = udisksEjectDrive(
this);
354 if (ejectResult[
"result"].toBool()) {
355 result[
"result"] =
true;
359 result[
"errStr"] = ejectResult[
"errStr"];
360 result[
"result"] =
false;
367 TQString command = TQString(
"eject -v '%1' 2>&1").arg(deviceNode());
369 FILE *exepipe = popen(command.ascii(),
"r");
371 TQString eject_output;
372 TQTextStream ts(exepipe, IO_ReadOnly);
373 eject_output = ts.read();
374 int retcode = pclose(exepipe);
376 result[
"result"] =
true;
380 result[
"errStr"] = eject_output;
381 result[
"retCode"] = retcode;
386 result[
"result"] =
false;
390bool TDEStorageDevice::ejectDriveMedia() {
391 int fd =
open(deviceNode().ascii(), O_RDWR | O_NONBLOCK);
395 if (ioctl(fd, CDROMEJECT) != 0) {
405TQString TDEStorageDevice::diskLabel() {
409void TDEStorageDevice::internalSetDiskLabel(TQString dn) {
413bool TDEStorageDevice::mediaInserted() {
414 return m_mediaInserted;
417void TDEStorageDevice::internalSetMediaInserted(
bool inserted) {
418 m_mediaInserted = inserted;
421TQString TDEStorageDevice::fileSystemName() {
422 return m_fileSystemName;
425void TDEStorageDevice::internalSetFileSystemName(TQString fn) {
426 m_fileSystemName = fn;
429TQString TDEStorageDevice::fileSystemUsage() {
430 return m_fileSystemUsage;
433void TDEStorageDevice::internalSetFileSystemUsage(TQString fu) {
434 m_fileSystemUsage = fu;
437TQString TDEStorageDevice::diskUUID() {
441void TDEStorageDevice::internalSetDiskUUID(TQString
id) {
445TQStringList TDEStorageDevice::holdingDevices() {
446 return m_holdingDevices;
449void TDEStorageDevice::internalSetHoldingDevices(TQStringList hd) {
450 m_holdingDevices = hd;
453TQStringList TDEStorageDevice::slaveDevices() {
454 return m_slaveDevices;
457void TDEStorageDevice::internalSetSlaveDevices(TQStringList sd) {
461TQString decodeHexEncoding(TQString str) {
462 TQRegExp hexEncRegExp(
"\\\\x[0-9A-Fa-f]{1,2}");
463 hexEncRegExp.setMinimal(
false);
464 hexEncRegExp.setCaseSensitive(
true);
467 while((s = hexEncRegExp.search(str, s+1))>=0){
468 str.replace(s, hexEncRegExp.cap(0).length(), TQChar((
char)strtol(hexEncRegExp.cap(0).mid(2).ascii(), NULL, 16)));
474TQString TDEStorageDevice::friendlyName() {
476 TQString devicevendorid = vendorEncoded();
477 TQString devicemodelid = modelEncoded();
479 devicevendorid = decodeHexEncoding(devicevendorid);
480 devicemodelid = decodeHexEncoding(devicemodelid);
482 devicevendorid = devicevendorid.stripWhiteSpace();
483 devicemodelid = devicemodelid.stripWhiteSpace();
484 devicevendorid = devicevendorid.simplifyWhiteSpace();
485 devicemodelid = devicemodelid.simplifyWhiteSpace();
487 TQString devicename = devicevendorid +
" " + devicemodelid;
489 devicename = devicename.stripWhiteSpace();
490 devicename = devicename.simplifyWhiteSpace();
492 if (devicename !=
"") {
496 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
497 return TDEGenericDevice::friendlyName();
500 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
501 return friendlyDeviceType();
504 TQString
label = diskLabel();
505 if (
label.isNull()) {
506 if (deviceSize() > 0) {
507 if (checkDiskStatus(TDEDiskDeviceStatus::Removable)) {
508 label =
i18n(
"%1 Removable Device").arg(deviceFriendlySize());
511 label =
i18n(
"%1 Fixed Storage Device").arg(deviceFriendlySize());
516 if (!
label.isNull()) {
520 return friendlyDeviceType();
523TQString TDEStorageDevice::detailedFriendlyName() {
524 return TQString(
"%1 [%2]").arg(friendlyName()).arg(deviceNode());
527TQString TDEStorageDevice::friendlyDeviceType() {
528 TQString ret =
i18n(
"Hard Disk Drive");
531 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
532 ret =
i18n(
"Floppy Drive");
534 if (isDiskOfType(TDEDiskDeviceType::Optical)) {
535 ret =
i18n(
"Optical Drive");
537 if (isDiskOfType(TDEDiskDeviceType::CDROM)) {
538 ret =
i18n(
"CDROM Drive");
540 if (isDiskOfType(TDEDiskDeviceType::CDRW)) {
541 ret =
i18n(
"CDRW Drive");
543 if (isDiskOfType(TDEDiskDeviceType::DVDROM)) {
544 ret =
i18n(
"DVD Drive");
546 if (isDiskOfType(TDEDiskDeviceType::DVDRW)) {
547 ret =
i18n(
"DVDRW Drive");
549 if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) {
550 ret =
i18n(
"DVDRAM Drive");
552 if (isDiskOfType(TDEDiskDeviceType::Zip)) {
553 ret =
i18n(
"Zip Drive");
555 if (isDiskOfType(TDEDiskDeviceType::Tape)) {
556 ret =
i18n(
"Tape Drive");
558 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
559 ret =
i18n(
"Digital Camera");
562 if (isDiskOfType(TDEDiskDeviceType::HDD)) {
563 ret =
i18n(
"Hard Disk Drive");
564 if (checkDiskStatus(TDEDiskDeviceStatus::Removable)) {
565 ret =
i18n(
"Removable Storage");
567 if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) {
568 ret =
i18n(
"Compact Flash");
570 if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) {
571 ret =
i18n(
"Memory Stick");
573 if (isDiskOfType(TDEDiskDeviceType::SmartMedia)) {
574 ret =
i18n(
"Smart Media");
576 if (isDiskOfType(TDEDiskDeviceType::SDMMC)) {
577 ret =
i18n(
"Secure Digital");
581 if (isDiskOfType(TDEDiskDeviceType::RAM)) {
582 ret =
i18n(
"Random Access Memory");
584 if (isDiskOfType(TDEDiskDeviceType::Loop)) {
585 ret =
i18n(
"Loop Device");
592 TQString mountString;
593 if (mountPath() != TQString::null) {
594 mountString =
"-mounted";
597 mountString =
"-unmounted";
600 TQPixmap ret =
DesktopIcon(
"drive-harddisk" + mountString, size);
602 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
603 ret =
DesktopIcon(
"media-floppy-3_5" + mountString, size);
605 if (isDiskOfType(TDEDiskDeviceType::Optical)) {
606 ret =
DesktopIcon(
"media-optical-cdrom" + mountString, size);
608 if (isDiskOfType(TDEDiskDeviceType::CDROM)) {
609 ret =
DesktopIcon(
"media-optical-cdrom" + mountString, size);
611 if (isDiskOfType(TDEDiskDeviceType::CDRW)) {
614 if (isDiskOfType(TDEDiskDeviceType::DVDROM)) {
615 ret =
DesktopIcon(
"media-optical-dvd" + mountString, size);
617 if (isDiskOfType(TDEDiskDeviceType::DVDRW)) {
618 ret =
DesktopIcon(
"media-optical-dvd" + mountString, size);
620 if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) {
621 ret =
DesktopIcon(
"media-optical-dvd" + mountString, size);
623 if (isDiskOfType(TDEDiskDeviceType::Zip)) {
624 ret =
DesktopIcon(
"media-floppy-zip" + mountString, size);
626 if (isDiskOfType(TDEDiskDeviceType::Tape)) {
627 ret =
DesktopIcon(
"media-tape" + mountString, size);
629 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
633 if (isDiskOfType(TDEDiskDeviceType::HDD)) {
634 ret =
DesktopIcon(
"drive-harddisk" + mountString, size);
635 if (checkDiskStatus(TDEDiskDeviceStatus::Removable)) {
636 ret =
DesktopIcon(
"media-flash-usb" + mountString, size);
638 if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) {
639 ret =
DesktopIcon(
"media-flash-compact_flash" + mountString, size);
641 if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) {
642 ret =
DesktopIcon(
"media-flash-memory_stick" + mountString, size);
644 if (isDiskOfType(TDEDiskDeviceType::SmartMedia)) {
645 ret =
DesktopIcon(
"media-flash-smart_media" + mountString, size);
647 if (isDiskOfType(TDEDiskDeviceType::SDMMC)) {
648 ret =
DesktopIcon(
"media-flash-sd_mmc" + mountString, size);
652 if (isDiskOfType(TDEDiskDeviceType::RAM)) {
655 if (isDiskOfType(TDEDiskDeviceType::Loop)) {
662unsigned long long TDEStorageDevice::deviceSize() {
663 TQString bsnodename = systemPath();
666 TQString blocksize =
"512";
668 TQString dsnodename = systemPath();
669 dsnodename.append(
"/size");
670 TQFile dsfile( dsnodename );
672 if ( dsfile.open( IO_ReadOnly ) ) {
673 TQTextStream stream( &dsfile );
674 devicesize = stream.readLine();
678 return ((
unsigned long long)blocksize.toULong()*(
unsigned long long)devicesize.toULong());
681TQString TDEStorageDevice::deviceFriendlySize() {
682 return TDEHardwareDevices::bytesToFriendlySizeString(deviceSize());
685TQString TDEStorageDevice::mountPath()
690void TDEStorageDevice::internalUpdateMountPath()
702 m_mountPath = TQString::null;
705 TQFile file(
"/proc/mounts" );
706 if ( file.open( IO_ReadOnly ) ) {
707 TQTextStream stream( &file );
709 while ( !stream.atEnd() ) {
710 line = stream.readLine();
711 TQStringList mountInfo = TQStringList::split(
" ", line,
true);
712 TQString testNode = *mountInfo.at(0);
714 if ((testNode == deviceNode()) || (testNode == mappedName()) || (testNode == (
"/dev/disk/by-uuid/" + diskUUID()))) {
715 m_mountPath = *mountInfo.at(1);
716 m_mountPath.replace(
"\\040",
" ");
726TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOptions mountOptions) {
727 TQStringVariantMap result;
730 TQString mountpath = mountPath();
731 if (!mountpath.isEmpty()) {
732 result[
"mountPath"] = mountpath;
733 result[
"result"] =
true;
737 TQString devNode = deviceNode();
738 devNode.replace(
"'",
"'\\''");
739 mediaName.replace(
"'",
"'\\''");
740 TQString command = TQString::null;
742#if defined(WITH_UDISKS2) || defined(WITH_UDISKS) || defined(WITH_UDEVIL)
744 TQStringList udisksOptions;
745 if (mountOptions[
"ro"] ==
"true") {
746 udisksOptions.append(
"ro");
749 if (mountOptions[
"atime"] !=
"true") {
750 udisksOptions.append(
"noatime");
753 if (mountOptions[
"sync"] ==
"true") {
754 udisksOptions.append(
"sync");
757 if ((mountOptions[
"filesystem"] ==
"fat") || (mountOptions[
"filesystem"] ==
"vfat") ||
758 (mountOptions[
"filesystem"] ==
"msdos") || (mountOptions[
"filesystem"] ==
"umsdos")) {
759 if (mountOptions.contains(
"shortname")) {
760 udisksOptions.append(TQString(
"shortname=%1").arg(mountOptions[
"shortname"]));
764 if ((mountOptions[
"filesystem"] ==
"jfs")) {
765 if (mountOptions[
"utf8"] ==
"true") {
771 if ((mountOptions[
"filesystem"] ==
"ntfs-3g")) {
772 if (mountOptions.contains(
"locale")) {
773 udisksOptions.append(TQString(
"locale=%1").arg(mountOptions[
"locale"]));
777 if ((mountOptions[
"filesystem"] ==
"ext3") || (mountOptions[
"filesystem"] ==
"ext4")) {
778 if (mountOptions.contains(
"journaling")) {
784 TQString optionString;
785 for (TQStringList::Iterator it = udisksOptions.begin(); it != udisksOptions.end(); ++it) {
786 optionString.append(
",");
787 optionString.append(*it);
790 if (!optionString.isEmpty()) {
791 optionString.remove(0, 1);
794 TQString fileSystemType;
795 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
796 fileSystemType = mountOptions[
"filesystem"];
799 TQStringVariantMap mountResult;
802#if defined(WITH_UDISKS2)
804 mountResult = udisks2MountDrive(devNode, fileSystemType, optionString);
805 if (mountResult[
"result"].toBool()) {
807 TDEGlobal::hardwareDevices()->processModifiedMounts();
808 result[
"mountPath"] = mountPath();
809 result[
"result"] =
true;
812 else if (mountResult[
"retcode"].toInt() == -1) {
814 TDEGlobal::hardwareDevices()->processModifiedMounts();
815 result[
"errStr"] = mountResult[
"errStr"];
816 result[
"result"] =
false;
821#if defined(WITH_UDISKS)
824 mountResult = udisksMountDrive(devNode, fileSystemType, udisksOptions);
825 if (mountResult[
"result"].toBool()) {
827 TDEGlobal::hardwareDevices()->processModifiedMounts();
828 result[
"mountPath"] = mountPath();
829 result[
"result"] =
true;
832 else if (mountResult[
"retcode"].toInt() == -1) {
834 TDEGlobal::hardwareDevices()->processModifiedMounts();
835 result[
"errStr"] = mountResult[
"errStr"];
836 result[
"result"] =
false;
841#if defined(WITH_UDEVIL)
845 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
846 fileSystemType = TQString(
"-t %1").arg(mountOptions[
"filesystem"]);
849 if (mountOptions.contains(
"mountpoint") && !mountOptions[
"mountpoint"].isEmpty() &&
850 (mountOptions[
"mountpoint"] !=
"/media/")) {
851 mountpoint = mountOptions[
"mountpoint"];
852 mountpoint.replace(
"'",
"'\\''");
855 mountpoint = TQString(
"/media/%1").arg(mediaName);
857 command = TQString(
"udevil mount %1 -o '%2' '%3' '%4' 2>&1")
858 .arg(fileSystemType).arg(optionString).arg(devNode).arg(mountpoint);
863 if(command.isEmpty()) {
865 TQString optionString;
866 if (mountOptions[
"ro"] ==
"true") {
867 optionString.append(
" -r");
870 if (mountOptions[
"atime"] !=
"true") {
871 optionString.append(
" -A");
874 if (mountOptions[
"utf8"] ==
"true") {
875 optionString.append(
" -c utf8");
878 if (mountOptions[
"sync"] ==
"true") {
879 optionString.append(
" -s");
882 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
883 optionString.append(TQString(
" -t %1").arg(mountOptions[
"filesystem"]));
886 if (mountOptions.contains(
"locale")) {
887 optionString.append(TQString(
" -c %1").arg(mountOptions[
"locale"]));
891 if (mountOptions.contains(
"mountpoint") && !mountOptions[
"mountpoint"].isEmpty() &&
892 (mountOptions[
"mountpoint"] !=
"/media/")) {
893 mountpoint = mountOptions[
"mountpoint"];
894 mountpoint.replace(
"'",
"'\\''");
897 mountpoint = mediaName;
901 command = TQString(
"pmount %1 '%2' '%3' 2>&1")
902 .arg(optionString).arg(devNode).arg(mountpoint);
906 if(command.isEmpty()) {
907 result[
"errStr"] =
i18n(
"No supported mounting methods were detected on your system");
908 result[
"result"] =
false;
912 FILE *exepipe = popen(command.local8Bit(),
"r");
914 TQTextStream* ts =
new TQTextStream(exepipe, IO_ReadOnly);
915 TQString mount_output = ts->read();
917 int retcode = pclose(exepipe);
918 result[
"errStr"] = mount_output;
919 result[
"retCode"] = retcode;
923 TDEGlobal::hardwareDevices()->processModifiedMounts();
924 result[
"mountPath"] = mountPath();
925 result[
"result"] = !mountPath().isEmpty();
929TQStringVariantMap TDEStorageDevice::unmountDevice() {
930 TQStringVariantMap result;
933 TQString mountpath = mountPath();
934 if (mountpath.isEmpty()) {
935 result[
"result"] =
true;
939 mountpath.replace(
"'",
"'\\''");
940 TQString devNode = deviceNode();
941 TQString command = TQString::null;
942 TQStringVariantMap unmountResult;
944#if defined(WITH_UDISKS2)
946 unmountResult = udisks2UnmountDrive(devNode, TQString::null);
947 if (unmountResult[
"result"].toBool()) {
949 TDEGlobal::hardwareDevices()->processModifiedMounts();
950 result[
"result"] =
true;
953 else if (unmountResult[
"retcode"].toInt() == -1) {
955 TDEGlobal::hardwareDevices()->processModifiedMounts();
956 result[
"errStr"] = unmountResult[
"errStr"];
957 result[
"result"] =
false;
962#if defined(WITH_UDISKS)
965 unmountResult = udisksUnmountDrive(devNode, TQStringList());
966 if (unmountResult[
"result"].toBool()) {
968 TDEGlobal::hardwareDevices()->processModifiedMounts();
969 result[
"result"] =
true;
972 else if (unmountResult[
"retcode"].toInt() == -1) {
974 TDEGlobal::hardwareDevices()->processModifiedMounts();
975 result[
"errStr"] = unmountResult[
"errStr"];
976 result[
"result"] =
false;
981#if defined(WITH_UDEVIL)
985 command = TQString(
"udevil umount '%1' 2>&1").arg(mountpath);
991 command = TQString(
"pumount '%1' 2>&1").arg(mountpath);
994 if(command.isEmpty()) {
995 result[
"errStr"] =
i18n(
"No supported unmounting methods were detected on your system");
996 result[
"result"] =
false;
1000 FILE *exepipe = popen(command.local8Bit(),
"r");
1002 TQTextStream* ts =
new TQTextStream(exepipe, IO_ReadOnly);
1003 TQString umount_output = ts->read();
1005 int retcode = pclose(exepipe);
1008 TDEGlobal::hardwareDevices()->processModifiedMounts();
1009 result[
"result"] =
true;
1013 result[
"errStr"] = umount_output;
1014 result[
"retCode"] = retcode;
1019 TDEGlobal::hardwareDevices()->processModifiedMounts();
1020 result[
"result"] =
false;
1024TQStringVariantMap TDEStorageDevice::unlockDevice(
const TQString &passphrase)
1026 TQStringVariantMap result;
1028 TQString devNode = deviceNode();
1029 devNode.replace(
"'",
"'\\''");
1031 TQStringVariantMap unlockResult;
1033#if defined(WITH_UDISKS2)
1035 unlockResult = udisks2UnlockDrive(devNode, passphrase);
1036 if (unlockResult[
"result"].toBool()) {
1037 result[
"unlockedDevice"] = unlockResult[
"unlockedDevice"];
1038 result[
"result"] =
true;
1041 else if (unlockResult[
"retcode"].toInt() == -1) {
1042 result[
"errStr"] = unlockResult[
"errStr"];
1043 result[
"result"] =
false;
1051 KTempFile passwordFile(TQString::null,
"tmp", 0600);
1052 passwordFile.setAutoDelete(
true);
1053 TQFile *pwFile = passwordFile.file();
1055 result[
"errStr"] =
i18n(
"Cannot create temporary password file");
1056 result[
"result"] =
false;
1059 pwFile->writeBlock(passphrase.local8Bit(), passphrase.length());
1061 TQString passFileName = passwordFile.name();
1062 passFileName.replace(
"'",
"'\\''");
1064 TQString command = TQString(
"pmount -p '%1' '%2'").arg(passFileName).arg(devNode);
1065 FILE *exepipe = popen(command.local8Bit(),
"r");
1067 TQTextStream* ts =
new TQTextStream(exepipe, IO_ReadOnly);
1068 TQString unlock_output = ts->read();
1070 int retcode = pclose(exepipe);
1072 result[
"result"] =
true;
1075 result[
"errStr"] = unlock_output;
1076 result[
"retCode"] = retcode;
1077 result[
"result"] =
false;
1084 result[
"errStr"] =
i18n(
"No supported unlocking methods were detected on your system.");
1085 result[
"result"] =
false;
1089TQStringVariantMap TDEStorageDevice::lockDevice()
1091 TQStringVariantMap result;
1093 TQString devNode = deviceNode();
1094 devNode.replace(
"'",
"'\\''");
1096 TQStringVariantMap lockResult;
1098#if defined(WITH_UDISKS2)
1100 lockResult = udisks2LockDrive(devNode);
1101 if (lockResult[
"result"].toBool()) {
1102 result[
"result"] =
true;
1105 else if (lockResult[
"retcode"].toInt() == -1) {
1106 result[
"errStr"] = lockResult[
"errStr"];
1107 result[
"result"] =
false;
1114 TQString command = TQString(
"pumount '%1'").arg(devNode);
1115 FILE *exepipe = popen(command.local8Bit(),
"r");
1117 TQTextStream* ts =
new TQTextStream(exepipe, IO_ReadOnly);
1118 TQString lock_output = ts->read();
1120 int retcode = pclose(exepipe);
1122 result[
"result"] =
true;
1125 result[
"errStr"] = lock_output;
1126 result[
"retCode"] = retcode;
1127 result[
"result"] =
false;
1134 result[
"errStr"] =
i18n(
"No supported locking methods were detected on your system.");
1135 result[
"result"] =
false;
1139#include "tdestoragedevice.moc"
The KTempFile class creates and opens a unique file for temporary use.
static TDEStandardDirs * dirs()
Returns the application standard dirs object.
TQPixmap DesktopIcon(const TQString &name, int size=0, int state=TDEIcon::DefaultState, TDEInstance *instance=TDEGlobal::instance())
Load a desktop icon.
StdSizes
These are the standard sizes for icons.
TQString i18n(const char *text)
i18n is the function that does everything you need to translate a string.
static TQString findExe(const TQString &appname, const TQString &pathstr=TQString::null, bool ignoreExecBit=false)
Finds the executable in the system path.
kdbgstream kdWarning(int area=0)
Returns a warning stream.
kdbgstream & endl(kdbgstream &s)
Prints an "\n".
TDEAction * close(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TDEAction * open(const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0)
TQString label(StdAccel id)
Returns a localized label for user-visible display.