20 #include "tdestoragedevice.h" 25 #include <sys/ioctl.h> 26 #include <linux/cdrom.h> 34 #include "tdeglobal.h" 35 #include "kiconloader.h" 36 #include "tdetempfile.h" 37 #include "kstandarddirs.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_INVALID INVALID 47 #define CRYPT_SLOT_INACTIVE INACTIVE 48 #define CRYPT_SLOT_ACTIVE ACTIVE 49 #define CRYPT_SLOT_BUSY BUSY 50 #define CRYPT_SLOT_ACTIVE_LAST ACTIVE 51 #include <libcryptsetup.h> 54 #include <libcryptsetup.h> 58 TDEStorageDevice::TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn), m_mediaInserted(true), m_cryptDevice(NULL) {
59 m_diskType = TDEDiskDeviceType::Null;
60 m_diskStatus = TDEDiskDeviceStatus::Null;
63 TDEStorageDevice::~TDEStorageDevice() {
64 #if defined(WITH_CRYPTSETUP) 66 crypt_free(m_cryptDevice);
72 TDEDiskDeviceType::TDEDiskDeviceType TDEStorageDevice::diskType() {
76 void TDEStorageDevice::internalGetLUKSKeySlotStatus() {
77 #if defined(WITH_CRYPTSETUP) 79 crypt_keyslot_info keyslot_status;
80 TDELUKSKeySlotStatus::TDELUKSKeySlotStatus tde_keyslot_status;
82 m_cryptKeyslotStatus.clear();
83 for (i = 0; i < m_cryptKeySlotCount; i++) {
84 keyslot_status = crypt_keyslot_status(m_cryptDevice, i);
85 tde_keyslot_status = TDELUKSKeySlotStatus::Invalid;
86 if (keyslot_status == CRYPT_SLOT_INACTIVE) {
87 tde_keyslot_status = TDELUKSKeySlotStatus::Inactive;
89 else if (keyslot_status == CRYPT_SLOT_ACTIVE) {
90 tde_keyslot_status = TDELUKSKeySlotStatus::Active;
92 else if (keyslot_status == CRYPT_SLOT_ACTIVE_LAST) {
93 tde_keyslot_status = TDELUKSKeySlotStatus::Active | TDELUKSKeySlotStatus::Last;
95 m_cryptKeyslotStatus.append(tde_keyslot_status);
100 void TDEStorageDevice::internalInitializeLUKSIfNeeded() {
101 #if defined(WITH_CRYPTSETUP) 104 if (m_diskType & TDEDiskDeviceType::LUKS) {
105 if (!m_cryptDevice) {
106 TQString node = deviceNode();
108 ret = crypt_init(&m_cryptDevice, node.ascii());
110 ret = crypt_load(m_cryptDevice, NULL, NULL);
113 #if defined(CRYPTSETUP_OLD_API) || !defined(HAVE_CRYPTSETUP_GET_TYPE) 114 kdWarning() <<
"TDEStorageDevice: The version of libcryptsetup that TDE was compiled against was too old! Most LUKS features will not function" <<
endl;
115 m_cryptDeviceType = TQString::null;
118 m_cryptDeviceType = crypt_get_type(m_cryptDevice);
119 keyslot_count = crypt_keyslot_max(m_cryptDeviceType.ascii());
121 if (keyslot_count < 0) {
122 m_cryptKeySlotCount = 0;
125 m_cryptKeySlotCount = keyslot_count;
127 internalGetLUKSKeySlotStatus();
131 m_cryptDevice = NULL;
138 crypt_free(m_cryptDevice);
139 m_cryptDevice = NULL;
145 void TDEStorageDevice::cryptSetOperationsUnlockPassword(TQByteArray password) {
146 #if defined(WITH_CRYPTSETUP) 147 crypt_memory_lock(NULL, 1);
148 m_cryptDevicePassword = password;
152 void TDEStorageDevice::cryptClearOperationsUnlockPassword() {
153 m_cryptDevicePassword.fill(0);
154 m_cryptDevicePassword.resize(0);
155 #if defined(WITH_CRYPTSETUP) 156 crypt_memory_lock(NULL, 0);
160 bool TDEStorageDevice::cryptOperationsUnlockPasswordSet() {
161 if (m_cryptDevicePassword.size() > 0) {
169 TDELUKSResult::TDELUKSResult TDEStorageDevice::cryptCheckKey(
unsigned int keyslot) {
170 #if defined(WITH_CRYPTSETUP) 174 if (keyslot < m_cryptKeySlotCount) {
175 ret = crypt_activate_by_passphrase(m_cryptDevice, NULL, keyslot, m_cryptDevicePassword.data(), m_cryptDevicePassword.size(), 0);
177 return TDELUKSResult::KeyslotOpFailed;
180 return TDELUKSResult::Success;
184 return TDELUKSResult::InvalidKeyslot;
188 return TDELUKSResult::LUKSNotFound;
191 return TDELUKSResult::LUKSNotSupported;
195 TDELUKSResult::TDELUKSResult TDEStorageDevice::cryptAddKey(
unsigned int keyslot, TQByteArray password) {
196 #if defined(WITH_CRYPTSETUP) 200 if (keyslot < m_cryptKeySlotCount) {
201 ret = crypt_keyslot_add_by_passphrase(m_cryptDevice, keyslot, m_cryptDevicePassword.data(), m_cryptDevicePassword.size(), password.data(), password.size());
203 return TDELUKSResult::KeyslotOpFailed;
206 internalGetLUKSKeySlotStatus();
207 return TDELUKSResult::Success;
211 return TDELUKSResult::InvalidKeyslot;
215 return TDELUKSResult::LUKSNotFound;
218 return TDELUKSResult::LUKSNotSupported;
222 TDELUKSResult::TDELUKSResult TDEStorageDevice::cryptDelKey(
unsigned int keyslot) {
223 #if defined(WITH_CRYPTSETUP) 227 if (keyslot < m_cryptKeySlotCount) {
228 ret = crypt_keyslot_destroy(m_cryptDevice, keyslot);
230 return TDELUKSResult::KeyslotOpFailed;
233 internalGetLUKSKeySlotStatus();
234 return TDELUKSResult::Success;
238 return TDELUKSResult::InvalidKeyslot;
242 return TDELUKSResult::LUKSNotFound;
245 return TDELUKSResult::LUKSNotSupported;
249 unsigned int TDEStorageDevice::cryptKeySlotCount() {
250 return m_cryptKeySlotCount;
253 TDELUKSKeySlotStatusList TDEStorageDevice::cryptKeySlotStatus() {
254 return m_cryptKeyslotStatus;
257 TQString TDEStorageDevice::cryptKeySlotFriendlyName(TDELUKSKeySlotStatus::TDELUKSKeySlotStatus status) {
258 if (status & TDELUKSKeySlotStatus::Inactive) {
259 return i18n(
"Inactive");
261 else if (status & TDELUKSKeySlotStatus::Active) {
262 return i18n(
"Active");
265 return i18n(
"Unknown");
269 void TDEStorageDevice::internalSetDeviceNode(TQString sn) {
270 TDEGenericDevice::internalSetDeviceNode(sn);
271 internalInitializeLUKSIfNeeded();
274 void TDEStorageDevice::internalSetDiskType(TDEDiskDeviceType::TDEDiskDeviceType dt) {
276 internalInitializeLUKSIfNeeded();
279 bool TDEStorageDevice::isDiskOfType(TDEDiskDeviceType::TDEDiskDeviceType tf) {
280 return ((m_diskType&tf)!=TDEDiskDeviceType::Null);
283 TDEDiskDeviceStatus::TDEDiskDeviceStatus TDEStorageDevice::diskStatus() {
287 void TDEStorageDevice::internalSetDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus st) {
291 bool TDEStorageDevice::checkDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus sf) {
292 return ((m_diskStatus&sf)!=(TDEDiskDeviceStatus::TDEDiskDeviceStatus)0);
295 bool TDEStorageDevice::lockDriveMedia(
bool lock) {
296 int fd =
open(deviceNode().ascii(), O_RDWR | O_NONBLOCK);
300 if (ioctl(fd, CDROM_LOCKDOOR, (lock)?1:0) != 0) {
310 bool TDEStorageDevice::ejectDrive() {
313 TQStringVariantMap ejectResult = UDisks2EjectDrive(
this);
314 if (ejectResult[
"result"].toBool()) {
318 printf(
"[tdehwlib] Failed to eject drive '%s' via udisks2, falling back to alternate mechanism\n", deviceNode().ascii());
325 TQStringVariantMap ejectResult = UDisksEjectDrive(
this);
326 if (ejectResult[
"result"].toBool()) {
330 printf(
"[tdehwlib] Failed to eject drive '%s' via udisks, falling back to alternate mechanism\n", deviceNode().ascii());
337 TQString command = TQString(
"eject -v '%1' 2>&1").arg(deviceNode());
339 FILE *exepipe = popen(command.ascii(),
"r");
341 TQString eject_output;
342 TQTextStream ts(exepipe, IO_ReadOnly);
343 eject_output = ts.read();
344 int retcode = pclose(exepipe);
349 printf(
"[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii());
356 bool TDEStorageDevice::ejectDriveMedia() {
357 int fd =
open(deviceNode().ascii(), O_RDWR | O_NONBLOCK);
361 if (ioctl(fd, CDROMEJECT) != 0) {
371 TQString TDEStorageDevice::diskLabel() {
375 void TDEStorageDevice::internalSetDiskLabel(TQString dn) {
379 bool TDEStorageDevice::mediaInserted() {
380 return m_mediaInserted;
383 void TDEStorageDevice::internalSetMediaInserted(
bool inserted) {
384 m_mediaInserted = inserted;
387 TQString TDEStorageDevice::fileSystemName() {
388 return m_fileSystemName;
391 void TDEStorageDevice::internalSetFileSystemName(TQString fn) {
392 m_fileSystemName = fn;
395 TQString TDEStorageDevice::fileSystemUsage() {
396 return m_fileSystemUsage;
399 void TDEStorageDevice::internalSetFileSystemUsage(TQString fu) {
400 m_fileSystemUsage = fu;
403 TQString TDEStorageDevice::diskUUID() {
407 void TDEStorageDevice::internalSetDiskUUID(TQString
id) {
411 TQStringList TDEStorageDevice::holdingDevices() {
412 return m_holdingDevices;
415 void TDEStorageDevice::internalSetHoldingDevices(TQStringList hd) {
416 m_holdingDevices = hd;
419 TQStringList TDEStorageDevice::slaveDevices() {
420 return m_slaveDevices;
423 void TDEStorageDevice::internalSetSlaveDevices(TQStringList sd) {
427 TQString decodeHexEncoding(TQString str) {
428 TQRegExp hexEncRegExp(
"\\\\x[0-9A-Fa-f]{1,2}");
429 hexEncRegExp.setMinimal(
false);
430 hexEncRegExp.setCaseSensitive(
true);
433 while((s = hexEncRegExp.search(str, s+1))>=0){
434 str.replace(s, hexEncRegExp.cap(0).length(), TQChar((
char)strtol(hexEncRegExp.cap(0).mid(2).ascii(), NULL, 16)));
440 TQString TDEStorageDevice::friendlyName() {
442 TQString devicevendorid = vendorEncoded();
443 TQString devicemodelid = modelEncoded();
445 devicevendorid = decodeHexEncoding(devicevendorid);
446 devicemodelid = decodeHexEncoding(devicemodelid);
448 devicevendorid = devicevendorid.stripWhiteSpace();
449 devicemodelid = devicemodelid.stripWhiteSpace();
450 devicevendorid = devicevendorid.simplifyWhiteSpace();
451 devicemodelid = devicemodelid.simplifyWhiteSpace();
453 TQString devicename = devicevendorid +
" " + devicemodelid;
455 devicename = devicename.stripWhiteSpace();
456 devicename = devicename.simplifyWhiteSpace();
458 if (devicename !=
"") {
462 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
463 return TDEGenericDevice::friendlyName();
466 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
467 return friendlyDeviceType();
470 TQString
label = diskLabel();
471 if (label.isNull()) {
472 if (deviceSize() > 0) {
473 if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
474 label = i18n(
"%1 Removable Device").arg(deviceFriendlySize());
477 label = i18n(
"%1 Fixed Storage Device").arg(deviceFriendlySize());
482 if (!label.isNull()) {
486 return friendlyDeviceType();
489 TQString TDEStorageDevice::detailedFriendlyName() {
490 return TQString(
"%1 [%2]").arg(friendlyName()).arg(deviceNode());
493 TQString TDEStorageDevice::friendlyDeviceType() {
494 TQString ret = i18n(
"Hard Disk Drive");
497 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
498 ret = i18n(
"Floppy Drive");
500 if (isDiskOfType(TDEDiskDeviceType::Optical)) {
501 ret = i18n(
"Optical Drive");
503 if (isDiskOfType(TDEDiskDeviceType::CDROM)) {
504 ret = i18n(
"CDROM Drive");
506 if (isDiskOfType(TDEDiskDeviceType::CDRW)) {
507 ret = i18n(
"CDRW Drive");
509 if (isDiskOfType(TDEDiskDeviceType::DVDROM)) {
510 ret = i18n(
"DVD Drive");
512 if (isDiskOfType(TDEDiskDeviceType::DVDRW)) {
513 ret = i18n(
"DVDRW Drive");
515 if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) {
516 ret = i18n(
"DVDRAM Drive");
518 if (isDiskOfType(TDEDiskDeviceType::Zip)) {
519 ret = i18n(
"Zip Drive");
521 if (isDiskOfType(TDEDiskDeviceType::Tape)) {
522 ret = i18n(
"Tape Drive");
524 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
525 ret = i18n(
"Digital Camera");
528 if (isDiskOfType(TDEDiskDeviceType::HDD)) {
529 ret = i18n(
"Hard Disk Drive");
530 if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
531 ret = i18n(
"Removable Storage");
533 if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) {
534 ret = i18n(
"Compact Flash");
536 if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) {
537 ret = i18n(
"Memory Stick");
539 if (isDiskOfType(TDEDiskDeviceType::SmartMedia)) {
540 ret = i18n(
"Smart Media");
542 if (isDiskOfType(TDEDiskDeviceType::SDMMC)) {
543 ret = i18n(
"Secure Digital");
547 if (isDiskOfType(TDEDiskDeviceType::RAM)) {
548 ret = i18n(
"Random Access Memory");
550 if (isDiskOfType(TDEDiskDeviceType::Loop)) {
551 ret = i18n(
"Loop Device");
558 TQString mountString;
559 if (mountPath() != TQString::null) {
560 mountString =
"-mounted";
563 mountString =
"-unmounted";
566 TQPixmap ret = DesktopIcon(
"drive-harddisk" + mountString, size);
568 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
569 ret = DesktopIcon(
"media-floppy-3_5" + mountString, size);
571 if (isDiskOfType(TDEDiskDeviceType::Optical)) {
572 ret = DesktopIcon(
"media-optical-cdrom" + mountString, size);
574 if (isDiskOfType(TDEDiskDeviceType::CDROM)) {
575 ret = DesktopIcon(
"media-optical-cdrom" + mountString, size);
577 if (isDiskOfType(TDEDiskDeviceType::CDRW)) {
578 ret = DesktopIcon(
"cd-rw" + mountString, size);
580 if (isDiskOfType(TDEDiskDeviceType::DVDROM)) {
581 ret = DesktopIcon(
"media-optical-dvd" + mountString, size);
583 if (isDiskOfType(TDEDiskDeviceType::DVDRW)) {
584 ret = DesktopIcon(
"media-optical-dvd" + mountString, size);
586 if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) {
587 ret = DesktopIcon(
"media-optical-dvd" + mountString, size);
589 if (isDiskOfType(TDEDiskDeviceType::Zip)) {
590 ret = DesktopIcon(
"media-floppy-zip" + mountString, size);
592 if (isDiskOfType(TDEDiskDeviceType::Tape)) {
593 ret = DesktopIcon(
"media-tape" + mountString, size);
595 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
596 ret = DesktopIcon(
"camera" + mountString, size);
599 if (isDiskOfType(TDEDiskDeviceType::HDD)) {
600 ret = DesktopIcon(
"drive-harddisk" + mountString, size);
601 if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
602 ret = DesktopIcon(
"media-flash-usb" + mountString, size);
604 if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) {
605 ret = DesktopIcon(
"media-flash-compact_flash" + mountString, size);
607 if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) {
608 ret = DesktopIcon(
"media-flash-memory_stick" + mountString, size);
610 if (isDiskOfType(TDEDiskDeviceType::SmartMedia)) {
611 ret = DesktopIcon(
"media-flash-smart_media" + mountString, size);
613 if (isDiskOfType(TDEDiskDeviceType::SDMMC)) {
614 ret = DesktopIcon(
"media-flash-sd_mmc" + mountString, size);
618 if (isDiskOfType(TDEDiskDeviceType::RAM)) {
619 ret = DesktopIcon(
"memory", size);
621 if (isDiskOfType(TDEDiskDeviceType::Loop)) {
622 ret = DesktopIcon(
"blockdevice", size);
628 unsigned long long TDEStorageDevice::deviceSize() {
629 TQString bsnodename = systemPath();
632 TQString blocksize =
"512";
634 TQString dsnodename = systemPath();
635 dsnodename.append(
"/size");
636 TQFile dsfile( dsnodename );
638 if ( dsfile.open( IO_ReadOnly ) ) {
639 TQTextStream stream( &dsfile );
640 devicesize = stream.readLine();
644 return ((
unsigned long long)blocksize.toULong()*(
unsigned long long)devicesize.toULong());
647 TQString TDEStorageDevice::deviceFriendlySize() {
648 return TDEHardwareDevices::bytesToFriendlySizeString(deviceSize());
651 TQString TDEStorageDevice::mountPath() {
660 TDEGlobal::hardwareDevices()->rescanDeviceInformation(
this);
662 TQString dmnodename = systemPath();
663 dmnodename.append(
"/dm/name");
664 TQFile namefile( dmnodename );
666 if ( namefile.open( IO_ReadOnly ) ) {
667 TQTextStream stream( &namefile );
668 dmaltname = stream.readLine();
671 if (!dmaltname.isNull()) {
672 dmaltname.prepend(
"/dev/mapper/");
676 TQFile file(
"/proc/mounts" );
677 if ( file.open( IO_ReadOnly ) ) {
678 TQTextStream stream( &file );
680 while ( !stream.atEnd() ) {
681 line = stream.readLine();
682 TQStringList mountInfo = TQStringList::split(
" ", line,
true);
683 TQString testNode = *mountInfo.at(0);
685 if ((testNode == deviceNode()) || (testNode == dmaltname) || (testNode == (
"/dev/disk/by-uuid/" + diskUUID()))) {
686 TQString ret = *mountInfo.at(1);
687 ret.replace(
"\\040",
" ");
697 TQStringList slaveDeviceList = holdingDevices();
698 for ( TQStringList::Iterator slavedevit = slaveDeviceList.begin(); slavedevit != slaveDeviceList.end(); ++slavedevit ) {
700 TDEHardwareDevices *hwdevices = TDEGlobal::hardwareDevices();
701 TDEGenericDevice *hwdevice = hwdevices->findBySystemPath(*slavedevit);
702 if ((hwdevice) && (hwdevice->type() == TDEGenericDeviceType::Disk)) {
703 TDEStorageDevice* sdevice =
static_cast<TDEStorageDevice*
>(hwdevice);
704 return sdevice->mountPath();
708 return TQString::null;
711 TQStringVariantMap TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOptions mountOptions) {
712 TQStringVariantMap result;
715 TQString mountpath = mountPath();
716 if (!mountpath.isEmpty()) {
717 result[
"mountPath"] = mountpath;
718 result[
"result"] =
true;
722 TQString devNode = deviceNode();
723 devNode.replace(
"'",
"'\\''");
724 mediaName.replace(
"'",
"'\\''");
725 TQString command = TQString::null;
727 #if defined(WITH_UDISKS2) || defined(WITH_UDISKS) || defined(WITH_UDEVIL) 729 TQStringList udisksOptions;
730 if (mountOptions[
"ro"] ==
"true") {
731 udisksOptions.append(
"ro");
734 if (mountOptions[
"atime"] !=
"true") {
735 udisksOptions.append(
"noatime");
738 if (mountOptions[
"sync"] ==
"true") {
739 udisksOptions.append(
"sync");
742 if ((mountOptions[
"filesystem"] ==
"fat") || (mountOptions[
"filesystem"] ==
"vfat") ||
743 (mountOptions[
"filesystem"] ==
"msdos") || (mountOptions[
"filesystem"] ==
"umsdos")) {
744 if (mountOptions.contains(
"shortname")) {
745 udisksOptions.append(TQString(
"shortname=%1").arg(mountOptions[
"shortname"]));
749 if ((mountOptions[
"filesystem"] ==
"jfs")) {
750 if (mountOptions[
"utf8"] ==
"true") {
756 if ((mountOptions[
"filesystem"] ==
"ntfs-3g")) {
757 if (mountOptions.contains(
"locale")) {
758 udisksOptions.append(TQString(
"locale=%1").arg(mountOptions[
"locale"]));
762 if ((mountOptions[
"filesystem"] ==
"ext3") || (mountOptions[
"filesystem"] ==
"ext4")) {
763 if (mountOptions.contains(
"journaling")) {
769 TQString optionString;
770 for (TQStringList::Iterator it = udisksOptions.begin(); it != udisksOptions.end(); ++it) {
771 optionString.append(
",");
772 optionString.append(*it);
775 if (!optionString.isEmpty()) {
776 optionString.remove(0, 1);
779 TQString fileSystemType;
780 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
781 fileSystemType = mountOptions[
"filesystem"];
784 TQStringVariantMap mountResult;
787 #if defined(WITH_UDISKS2) 789 mountResult = UDisks2MountDrive(devNode, fileSystemType, optionString);
790 if (mountResult[
"result"].toBool()) {
792 TDEGlobal::hardwareDevices()->processModifiedMounts();
793 result[
"mountPath"] = mountPath();
794 result[
"result"] =
true;
797 else if (mountResult[
"retcode"].toInt() == -1) {
799 TDEGlobal::hardwareDevices()->processModifiedMounts();
800 result[
"errStr"] = mountResult[
"errStr"];
801 result[
"result"] =
false;
806 #if defined(WITH_UDISKS) 809 mountResult = UDisksMountDrive(devNode, fileSystemType, udisksOptions);
810 if (mountResult[
"result"].toBool()) {
812 TDEGlobal::hardwareDevices()->processModifiedMounts();
813 result[
"mountPath"] = mountPath();
814 result[
"result"] =
true;
817 else if (mountResult[
"retcode"].toInt() == -1) {
819 TDEGlobal::hardwareDevices()->processModifiedMounts();
820 result[
"errStr"] = mountResult[
"errStr"];
821 result[
"result"] =
false;
826 #if defined(WITH_UDEVIL) 830 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
831 fileSystemType = TQString(
"-t %1").arg(mountOptions[
"filesystem"]);
834 if (mountOptions.contains(
"mountpoint") && !mountOptions[
"mountpoint"].isEmpty() &&
835 (mountOptions[
"mountpoint"] !=
"/media/")) {
836 mountpoint = mountOptions[
"mountpoint"];
837 mountpoint.replace(
"'",
"'\\''");
840 mountpoint = TQString(
"/media/%1").arg(mediaName);
842 command = TQString(
"udevil mount %1 -o '%2' '%3' '%4' 2>&1")
843 .arg(fileSystemType).arg(optionString).arg(devNode).arg(mountpoint);
848 if(command.isEmpty()) {
851 KTempFile passwordFile(TQString::null,
"tmp", 0600);
852 passwordFile.setAutoDelete(
true);
854 TQString optionString;
855 if (mountOptions[
"ro"] ==
"true") {
856 optionString.append(
" -r");
859 if (mountOptions[
"atime"] !=
"true") {
860 optionString.append(
" -A");
863 if (mountOptions[
"utf8"] ==
"true") {
864 optionString.append(
" -c utf8");
867 if (mountOptions[
"sync"] ==
"true") {
868 optionString.append(
" -s");
871 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
872 optionString.append(TQString(
" -t %1").arg(mountOptions[
"filesystem"]));
875 if (mountOptions.contains(
"locale")) {
876 optionString.append(TQString(
" -c %1").arg(mountOptions[
"locale"]));
880 if (mountOptions.contains(
"mountpoint") && !mountOptions[
"mountpoint"].isEmpty() &&
881 (mountOptions[
"mountpoint"] !=
"/media/")) {
882 mountpoint = mountOptions[
"mountpoint"];
883 mountpoint.replace(
"'",
"'\\''");
886 mountpoint = mediaName;
889 TQString passFileName = passwordFile.name();
890 passFileName.replace(
"'",
"'\\''");
892 command = TQString(
"pmount -p '%1' %2 '%3' '%4' 2>&1")
893 .arg(passFileName).arg(optionString).arg(devNode).arg(mountpoint);
897 if(command.isEmpty()) {
898 result[
"errStr"] = i18n(
"No supported mounting methods were detected on your system");
899 result[
"result"] =
false;
903 FILE *exepipe = popen(command.local8Bit(),
"r");
905 TQTextStream* ts =
new TQTextStream(exepipe, IO_ReadOnly);
906 TQString mount_output = ts->read();
908 int retcode = pclose(exepipe);
909 result[
"errStr"] = mount_output;
910 result[
"retCode"] = retcode;
914 TDEGlobal::hardwareDevices()->processModifiedMounts();
915 result[
"mountPath"] = mountPath();
916 result[
"result"] = !mountPath().isEmpty();
920 TQStringVariantMap TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName,
921 TDEStorageMountOptions mountOptions) {
922 TQStringVariantMap result;
925 TQString mountpath = mountPath();
926 if (!mountpath.isEmpty()) {
927 result[
"mountPath"] = mountpath;
928 result[
"result"] =
true;
933 KTempFile passwordFile(TQString::null,
"tmp", 0600);
934 passwordFile.setAutoDelete(
true);
935 TQFile* pwFile = passwordFile.file();
937 result[
"errStr"] = i18n(
"Cannot create temporary password file");
938 result[
"result"] =
false;
942 pwFile->writeBlock(passphrase.ascii(), passphrase.length());
945 TQString optionString;
946 if (mountOptions[
"ro"] ==
"true") {
947 optionString.append(
" -r");
950 if (mountOptions[
"atime"] !=
"true") {
951 optionString.append(
" -A");
954 if (mountOptions[
"utf8"] ==
"true") {
955 optionString.append(
" -c utf8");
958 if (mountOptions[
"sync"] ==
"true") {
959 optionString.append(
" -s");
962 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
963 optionString.append(TQString(
" -t %1").arg(mountOptions[
"filesystem"]));
966 if (mountOptions.contains(
"locale")) {
967 optionString.append(TQString(
" -c %1").arg(mountOptions[
"locale"]));
970 TQString passFileName = passwordFile.name();
971 TQString devNode = deviceNode();
972 passFileName.replace(
"'",
"'\\''");
973 devNode.replace(
"'",
"'\\''");
974 mediaName.replace(
"'",
"'\\''");
975 TQString command = TQString(
"pmount -p '%1' %2 '%3' '%4' 2>&1")
976 .arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
978 FILE *exepipe = popen(command.local8Bit(),
"r");
980 TQTextStream* ts =
new TQTextStream(exepipe, IO_ReadOnly);
981 TQString mount_output = ts->read();
983 int retcode = pclose(exepipe);
984 result[
"errStr"] = mount_output;
985 result[
"retCode"] = retcode;
989 TDEGlobal::hardwareDevices()->processModifiedMounts();
990 result[
"mountPath"] = mountPath();
991 result[
"result"] = !mountPath().isEmpty();
995 TQStringVariantMap TDEStorageDevice::unmountDevice() {
996 TQStringVariantMap result;
999 TQString mountpoint = mountPath();
1000 if (mountpoint.isEmpty()) {
1001 result[
"result"] =
true;
1005 mountpoint.replace(
"'",
"'\\''");
1006 TQString devNode = deviceNode();
1007 TQString command = TQString::null;
1008 TQStringVariantMap unmountResult;
1010 #if defined(WITH_UDISKS2) 1012 unmountResult = UDisks2UnmountDrive(devNode, TQString::null);
1013 if (unmountResult[
"result"].toBool()) {
1015 TDEGlobal::hardwareDevices()->processModifiedMounts();
1016 result[
"result"] =
true;
1019 else if (unmountResult[
"retcode"].toInt() == -1) {
1021 TDEGlobal::hardwareDevices()->processModifiedMounts();
1022 result[
"errStr"] = unmountResult[
"errStr"];
1023 result[
"result"] =
false;
1028 #if defined(WITH_UDISKS) 1031 unmountResult = UDisksUnmountDrive(devNode, TQStringList());
1032 if (unmountResult[
"result"].toBool()) {
1034 TDEGlobal::hardwareDevices()->processModifiedMounts();
1035 result[
"result"] =
true;
1038 else if (unmountResult[
"retcode"].toInt() == -1) {
1040 TDEGlobal::hardwareDevices()->processModifiedMounts();
1041 result[
"errStr"] = unmountResult[
"errStr"];
1042 result[
"result"] =
false;
1047 #if defined(WITH_UDEVIL) 1051 command = TQString(
"udevil umount '%1' 2>&1").arg(mountpoint);
1057 command = TQString(
"pumount '%1' 2>&1").arg(mountpoint);
1060 if(command.isEmpty()) {
1061 result[
"errStr"] = i18n(
"No supported unmounting methods were detected on your system");
1062 result[
"result"] =
false;
1066 FILE *exepipe = popen(command.local8Bit(),
"r");
1068 TQTextStream* ts =
new TQTextStream(exepipe, IO_ReadOnly);
1069 TQString umount_output = ts->read();
1071 int retcode = pclose(exepipe);
1074 TDEGlobal::hardwareDevices()->processModifiedMounts();
1075 result[
"result"] =
true;
1079 result[
"errStr"] = umount_output;
1080 result[
"retCode"] = retcode;
1085 TDEGlobal::hardwareDevices()->processModifiedMounts();
1086 result[
"result"] =
false;
1090 TQString TDEStorageDevice::determineFileSystemType(TQString path) {
1091 TQStringList mountTable;
1092 TQString prevPath = path;
1095 struct stat directory_info;
1096 if (path.startsWith(
"/")) {
1097 stat(path.local8Bit(), &directory_info);
1098 prevDev = directory_info.st_dev;
1101 while (path !=
"/") {
1102 pos = path.findRev(
"/", -1,
true);
1106 path = path.mid(0, pos);
1110 stat(path.local8Bit(), &directory_info);
1111 if (directory_info.st_dev != prevDev) {
1115 prevDev = directory_info.st_dev;
1121 TQFile file(
"/proc/mounts" );
1122 if ( file.open( IO_ReadOnly ) ) {
1123 TQTextStream stream( &file );
1124 while ( !stream.atEnd() ) {
1125 mountTable.append(stream.readLine());
1131 TQStringList::Iterator it;
1132 for ( it = mountTable.begin(); it != mountTable.end(); ++it ) {
1133 TQStringList mountInfo = TQStringList::split(
" ", (*it),
true);
1134 if ((*mountInfo.at(1)) == prevPath) {
1135 return (*mountInfo.at(2));
1140 return TQString::null;
1143 #include "tdestoragedevice.moc" const TDEShortcut & open()
Open file.
static TDEStandardDirs * dirs()
Returns the application standard dirs object.
StdSizes
These are the standard sizes for icons.
static TQString findExe(const TQString &appname, const TQString &pathstr=TQString::null, bool ignoreExecBit=false)
Finds the executable in the system path.
const TDEShortcut & close()
Close current document.
The KTempFile class creates and opens a unique file for temporary use.
kndbgstream & endl(kndbgstream &s)
Does nothing.
TQString label(StdAccel id)
Returns a localized label for user-visible display.