20 #include "tdestoragedevice.h" 25 #include <sys/ioctl.h> 26 #include <linux/cdrom.h> 33 #include "tdeglobal.h" 34 #include "kiconloader.h" 35 #include "tdetempfile.h" 36 #include "kstandarddirs.h" 38 #include "tdehardwaredevices.h" 43 #if defined(WITH_UDISKS) || defined(WITH_UDISKS2) 44 #include <tqdbusdata.h> 45 #include <tqdbusmessage.h> 46 #include <tqdbusproxy.h> 47 #include <tqdbusvariant.h> 48 #include <tqdbusconnection.h> 49 #include <tqdbuserror.h> 50 #include <tqdbusdatamap.h> 51 #include <tqdbusobjectpath.h> 52 #endif // defined(WITH_UDISKS) || defined(WITH_UDISKS2) 53 #if defined(WITH_UDISKS) 54 #include "tqdbusdatalist.h" 55 #endif // ddefined(WITH_UDISKS) 57 #if defined(WITH_UDISKS) || defined(WITH_UDISKS2) 59 TQT_DBusData convertDBUSDataToVariantData(TQT_DBusData);
60 #endif // defined(WITH_UDISKS) || defined(WITH_UDISKS2) 62 TDEStorageDevice::TDEStorageDevice(TDEGenericDeviceType::TDEGenericDeviceType dt, TQString dn) : TDEGenericDevice(dt, dn), m_mediaInserted(true) {
63 m_diskType = TDEDiskDeviceType::Null;
64 m_diskStatus = TDEDiskDeviceStatus::Null;
67 TDEStorageDevice::~TDEStorageDevice() {
70 TDEDiskDeviceType::TDEDiskDeviceType TDEStorageDevice::diskType() {
74 void TDEStorageDevice::internalSetDiskType(TDEDiskDeviceType::TDEDiskDeviceType dt) {
78 bool TDEStorageDevice::isDiskOfType(TDEDiskDeviceType::TDEDiskDeviceType tf) {
79 return ((m_diskType&tf)!=TDEDiskDeviceType::Null);
82 TDEDiskDeviceStatus::TDEDiskDeviceStatus TDEStorageDevice::diskStatus() {
86 void TDEStorageDevice::internalSetDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus st) {
90 bool TDEStorageDevice::checkDiskStatus(TDEDiskDeviceStatus::TDEDiskDeviceStatus sf) {
91 return ((m_diskStatus&sf)!=(TDEDiskDeviceStatus::TDEDiskDeviceStatus)0);
94 bool TDEStorageDevice::lockDriveMedia(
bool lock) {
95 int fd =
open(deviceNode().ascii(), O_RDWR | O_NONBLOCK);
99 if (ioctl(fd, CDROM_LOCKDOOR, (lock)?1:0) != 0) {
109 bool ejectDriveUDisks(TDEStorageDevice* sdevice) {
111 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
112 if (dbusConn.isConnected()) {
113 TQString blockDeviceString = sdevice->deviceNode();
114 blockDeviceString.replace(
"/dev/",
"");
115 blockDeviceString =
"/org/freedesktop/UDisks/devices/" + blockDeviceString;
119 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks", blockDeviceString,
"org.freedesktop.UDisks.Device", dbusConn);
120 if (driveControl.canSend()) {
121 TQValueList<TQT_DBusData> params;
122 TQT_DBusDataList options;
123 params << TQT_DBusData::fromList(options);
124 TQT_DBusMessage reply = driveControl.sendWithReply(
"DriveEject", params, &error);
125 if (error.isValid()) {
127 printf(
"[ERROR][tdehwlib] ejectDriveUDisks: %s\n", error.name().ascii()); fflush(stdout);
135 #endif // WITH_UDISKS 139 bool ejectDriveUDisks2(TDEStorageDevice* sdevice) {
141 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
142 if (dbusConn.isConnected()) {
143 TQString blockDeviceString = sdevice->deviceNode();
144 blockDeviceString.replace(
"/dev/",
"");
145 blockDeviceString =
"/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
146 TQT_DBusProxy hardwareControl(
"org.freedesktop.UDisks2", blockDeviceString,
"org.freedesktop.DBus.Properties", dbusConn);
147 if (hardwareControl.canSend()) {
150 TQValueList<TQT_DBusData> params;
151 params << TQT_DBusData::fromString(
"org.freedesktop.UDisks2.Block") << TQT_DBusData::fromString(
"Drive");
152 TQT_DBusMessage reply = hardwareControl.sendWithReply(
"Get", params, &error);
153 if (error.isValid()) {
155 printf(
"[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
159 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
160 TQT_DBusObjectPath driveObjectPath = reply[0].toVariant().value.toObjectPath();
161 if (!driveObjectPath.isValid()) {
165 error = TQT_DBusError();
166 TQT_DBusProxy driveInformation(
"org.freedesktop.UDisks2", driveObjectPath,
"org.freedesktop.DBus.Properties", dbusConn);
168 TQValueList<TQT_DBusData> params;
169 params << TQT_DBusData::fromString(
"org.freedesktop.UDisks2.Drive") << TQT_DBusData::fromString(
"Ejectable");
170 TQT_DBusMessage reply = driveInformation.sendWithReply(
"Get", params, &error);
171 if (error.isValid()) {
173 printf(
"[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
176 if (reply.type() == TQT_DBusMessage::ReplyMessage && reply.count() == 1) {
177 bool ejectable = reply[0].toVariant().value.toBool();
183 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks2", driveObjectPath,
"org.freedesktop.UDisks2.Drive", dbusConn);
184 TQValueList<TQT_DBusData> params;
185 TQT_DBusDataMap<TQString> options(TQT_DBusData::Variant);
186 params << TQT_DBusData::fromStringKeyMap(options);
187 TQT_DBusMessage reply = driveControl.sendWithReply(
"Eject", params, &error);
188 if (error.isValid()) {
190 printf(
"[ERROR][tdehwlib] ejectDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
201 #endif // WITH_UDISKS2 205 int mountDriveUDisks(TQString deviceNode, TQString fileSystemType, TQStringList mountOptions, TQString* errStr = NULL) {
207 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
208 if (dbusConn.isConnected()) {
209 TQString blockDeviceString = deviceNode;
210 blockDeviceString.replace(
"/dev/",
"");
211 blockDeviceString =
"/org/freedesktop/UDisks/devices/" + blockDeviceString;
215 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks", blockDeviceString,
"org.freedesktop.UDisks.Device", dbusConn);
216 if (driveControl.canSend()) {
217 TQValueList<TQT_DBusData> params;
218 params << TQT_DBusData::fromString(fileSystemType);
219 params << TQT_DBusData::fromList(TQT_DBusDataList(mountOptions));
220 TQT_DBusMessage reply = driveControl.sendWithReply(
"FilesystemMount", params, &error);
221 if (error.isValid()) {
223 if (error.name() ==
"org.freedesktop.DBus.Error.ServiceUnknown") {
228 *errStr = error.name() +
": " + error.message();
231 printf(
"[ERROR][tdehwlib] mountDriveUDisks: %s\n", error.name().ascii()); fflush(stdout);
243 #endif // WITH_UDISKS 247 int mountDriveUDisks2(TQString deviceNode, TQString fileSystemType, TQString mountOptions, TQString* errStr = NULL) {
249 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
250 if (dbusConn.isConnected()) {
251 TQString blockDeviceString = deviceNode;
252 blockDeviceString.replace(
"/dev/",
"");
253 blockDeviceString =
"/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
257 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks2", blockDeviceString,
"org.freedesktop.UDisks2.Filesystem", dbusConn);
258 if (driveControl.canSend()) {
259 TQValueList<TQT_DBusData> params;
260 TQMap<TQString, TQT_DBusData> optionsMap;
261 if (fileSystemType !=
"") {
262 optionsMap[
"fstype"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(fileSystemType));
264 optionsMap[
"options"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(mountOptions));
265 params << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap<TQString>(optionsMap));
266 TQT_DBusMessage reply = driveControl.sendWithReply(
"Mount", params, &error);
267 if (error.isValid()) {
269 if (error.name() ==
"org.freedesktop.DBus.Error.ServiceUnknown") {
274 *errStr = error.name() +
": " + error.message();
277 printf(
"[ERROR][tdehwlib] mountDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
289 #endif // WITH_UDISKS2 293 int unMountDriveUDisks(TQString deviceNode, TQStringList unMountOptions, TQString* errStr = NULL) {
295 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
296 if (dbusConn.isConnected()) {
297 TQString blockDeviceString = deviceNode;
298 blockDeviceString.replace(
"/dev/",
"");
299 blockDeviceString =
"/org/freedesktop/UDisks/devices/" + blockDeviceString;
303 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks", blockDeviceString,
"org.freedesktop.UDisks.Device", dbusConn);
304 if (driveControl.canSend()) {
305 TQValueList<TQT_DBusData> params;
306 params << TQT_DBusData::fromList(TQT_DBusDataList(unMountOptions));
307 TQT_DBusMessage reply = driveControl.sendWithReply(
"FilesystemUnmount", params, &error);
308 if (error.isValid()) {
310 if (error.name() ==
"org.freedesktop.DBus.Error.ServiceUnknown") {
315 *errStr = error.name() +
": " + error.message();
318 printf(
"[ERROR][tdehwlib] unMountDriveUDisks: %s\n", error.name().ascii()); fflush(stdout);
330 #endif // WITH_UDISKS 334 int unMountDriveUDisks2(TQString deviceNode, TQString unMountOptions, TQString* errStr = NULL) {
336 TQT_DBusConnection dbusConn = TQT_DBusConnection::addConnection(TQT_DBusConnection::SystemBus);
337 if (dbusConn.isConnected()) {
338 TQString blockDeviceString = deviceNode;
339 blockDeviceString.replace(
"/dev/",
"");
340 blockDeviceString =
"/org/freedesktop/UDisks2/block_devices/" + blockDeviceString;
344 TQT_DBusProxy driveControl(
"org.freedesktop.UDisks2", blockDeviceString,
"org.freedesktop.UDisks2.Filesystem", dbusConn);
345 if (driveControl.canSend()) {
346 TQValueList<TQT_DBusData> params;
347 TQMap<TQString, TQT_DBusData> optionsMap;
348 optionsMap[
"options"] = convertDBUSDataToVariantData(TQT_DBusData::fromString(unMountOptions));
349 params << TQT_DBusData::fromStringKeyMap(TQT_DBusDataMap<TQString>(optionsMap));
350 TQT_DBusMessage reply = driveControl.sendWithReply(
"Unmount", params, &error);
351 if (error.isValid()) {
353 if (error.name() ==
"org.freedesktop.DBus.Error.ServiceUnknown") {
358 *errStr = error.name() +
": " + error.message();
361 printf(
"[ERROR][tdehwlib] unMountDriveUDisks2: %s\n", error.name().ascii()); fflush(stdout);
373 #endif // WITH_UDISKS2 377 bool TDEStorageDevice::ejectDrive() {
380 if (ejectDriveUDisks2(
this)) {
384 printf(
"[tdehwlib] Failed to eject drive '%s' via udisks2, falling back to alternate mechanism\n", deviceNode().ascii());
388 #endif // WITH_UDISKS2 392 if (ejectDriveUDisks(
this)) {
396 printf(
"[tdehwlib] Failed to eject drive '%s' via udisks, falling back to alternate mechanism\n", deviceNode().ascii());
400 #endif // WITH_UDISKS 403 TQString command = TQString(
"eject -v '%1' 2>&1").arg(deviceNode());
405 FILE *exepipe = popen(command.ascii(),
"r");
407 TQString eject_output;
408 TQTextStream ts(exepipe, IO_ReadOnly);
409 eject_output = ts.read();
410 int retcode = pclose(exepipe);
415 printf(
"[tdehwlib] Failed to eject drive '%s' via 'eject' command\n", deviceNode().ascii());
422 bool TDEStorageDevice::ejectDriveMedia() {
423 int fd =
open(deviceNode().ascii(), O_RDWR | O_NONBLOCK);
427 if (ioctl(fd, CDROMEJECT) != 0) {
437 TQString TDEStorageDevice::diskLabel() {
441 void TDEStorageDevice::internalSetDiskLabel(TQString dn) {
445 bool TDEStorageDevice::mediaInserted() {
446 return m_mediaInserted;
449 void TDEStorageDevice::internalSetMediaInserted(
bool inserted) {
450 m_mediaInserted = inserted;
453 TQString TDEStorageDevice::fileSystemName() {
454 return m_fileSystemName;
457 void TDEStorageDevice::internalSetFileSystemName(TQString fn) {
458 m_fileSystemName = fn;
461 TQString TDEStorageDevice::fileSystemUsage() {
462 return m_fileSystemUsage;
465 void TDEStorageDevice::internalSetFileSystemUsage(TQString fu) {
466 m_fileSystemUsage = fu;
469 TQString TDEStorageDevice::diskUUID() {
473 void TDEStorageDevice::internalSetDiskUUID(TQString
id) {
477 TQStringList TDEStorageDevice::holdingDevices() {
478 return m_holdingDevices;
481 void TDEStorageDevice::internalSetHoldingDevices(TQStringList hd) {
482 m_holdingDevices = hd;
485 TQStringList TDEStorageDevice::slaveDevices() {
486 return m_slaveDevices;
489 void TDEStorageDevice::internalSetSlaveDevices(TQStringList sd) {
493 TQString decodeHexEncoding(TQString str) {
494 TQRegExp hexEncRegExp(
"\\\\x[0-9A-Fa-f]{1,2}");
495 hexEncRegExp.setMinimal(
false);
496 hexEncRegExp.setCaseSensitive(
true);
499 while((s = hexEncRegExp.search(str, s+1))>=0){
500 str.replace(s, hexEncRegExp.cap(0).length(), TQChar((
char)strtol(hexEncRegExp.cap(0).mid(2).ascii(), NULL, 16)));
506 TQString TDEStorageDevice::friendlyName() {
508 TQString devicevendorid = vendorEncoded();
509 TQString devicemodelid = modelEncoded();
511 devicevendorid = decodeHexEncoding(devicevendorid);
512 devicemodelid = decodeHexEncoding(devicemodelid);
514 devicevendorid = devicevendorid.stripWhiteSpace();
515 devicemodelid = devicemodelid.stripWhiteSpace();
516 devicevendorid = devicevendorid.simplifyWhiteSpace();
517 devicemodelid = devicemodelid.simplifyWhiteSpace();
519 TQString devicename = devicevendorid +
" " + devicemodelid;
521 devicename = devicename.stripWhiteSpace();
522 devicename = devicename.simplifyWhiteSpace();
524 if (devicename !=
"") {
528 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
529 return TDEGenericDevice::friendlyName();
532 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
533 return friendlyDeviceType();
536 TQString
label = diskLabel();
537 if (label.isNull()) {
538 if (deviceSize() > 0) {
539 if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
540 label = i18n(
"%1 Removable Device").arg(deviceFriendlySize());
543 label = i18n(
"%1 Fixed Storage Device").arg(deviceFriendlySize());
548 if (!label.isNull()) {
552 return friendlyDeviceType();
555 TQString TDEStorageDevice::detailedFriendlyName() {
556 return TQString(
"%1 [%2]").arg(friendlyName()).arg(deviceNode());
559 TQString TDEStorageDevice::friendlyDeviceType() {
560 TQString ret = i18n(
"Hard Disk Drive");
563 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
564 ret = i18n(
"Floppy Drive");
566 if (isDiskOfType(TDEDiskDeviceType::Optical)) {
567 ret = i18n(
"Optical Drive");
569 if (isDiskOfType(TDEDiskDeviceType::CDROM)) {
570 ret = i18n(
"CDROM Drive");
572 if (isDiskOfType(TDEDiskDeviceType::CDRW)) {
573 ret = i18n(
"CDRW Drive");
575 if (isDiskOfType(TDEDiskDeviceType::DVDROM)) {
576 ret = i18n(
"DVD Drive");
578 if (isDiskOfType(TDEDiskDeviceType::DVDRW)) {
579 ret = i18n(
"DVDRW Drive");
581 if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) {
582 ret = i18n(
"DVDRAM Drive");
584 if (isDiskOfType(TDEDiskDeviceType::Zip)) {
585 ret = i18n(
"Zip Drive");
587 if (isDiskOfType(TDEDiskDeviceType::Tape)) {
588 ret = i18n(
"Tape Drive");
590 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
591 ret = i18n(
"Digital Camera");
594 if (isDiskOfType(TDEDiskDeviceType::HDD)) {
595 ret = i18n(
"Hard Disk Drive");
596 if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
597 ret = i18n(
"Removable Storage");
599 if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) {
600 ret = i18n(
"Compact Flash");
602 if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) {
603 ret = i18n(
"Memory Stick");
605 if (isDiskOfType(TDEDiskDeviceType::SmartMedia)) {
606 ret = i18n(
"Smart Media");
608 if (isDiskOfType(TDEDiskDeviceType::SDMMC)) {
609 ret = i18n(
"Secure Digital");
613 if (isDiskOfType(TDEDiskDeviceType::RAM)) {
614 ret = i18n(
"Random Access Memory");
616 if (isDiskOfType(TDEDiskDeviceType::Loop)) {
617 ret = i18n(
"Loop Device");
624 TQString mountString;
625 if (mountPath() != TQString::null) {
626 mountString =
"-mounted";
629 TQPixmap ret = DesktopIcon(
"drive-harddisk" + mountString, size);
631 if (isDiskOfType(TDEDiskDeviceType::Floppy)) {
632 ret = DesktopIcon(
"media-floppy-3_5" + mountString, size);
634 if (isDiskOfType(TDEDiskDeviceType::Optical)) {
635 ret = DesktopIcon(
"media-optical-cdrom" + mountString, size);
637 if (isDiskOfType(TDEDiskDeviceType::CDROM)) {
638 ret = DesktopIcon(
"media-optical-cdrom" + mountString, size);
640 if (isDiskOfType(TDEDiskDeviceType::CDRW)) {
641 ret = DesktopIcon(
"media-optical-cdwriter" + mountString, size);
643 if (isDiskOfType(TDEDiskDeviceType::DVDROM)) {
644 ret = DesktopIcon(
"media-optical-dvd" + mountString, size);
646 if (isDiskOfType(TDEDiskDeviceType::DVDRW)) {
647 ret = DesktopIcon(
"media-optical-dvd" + mountString, size);
649 if (isDiskOfType(TDEDiskDeviceType::DVDRAM)) {
650 ret = DesktopIcon(
"media-optical-dvd" + mountString, size);
652 if (isDiskOfType(TDEDiskDeviceType::Zip)) {
653 ret = DesktopIcon(
"media-floppy-zip" + mountString, size);
655 if (isDiskOfType(TDEDiskDeviceType::Tape)) {
656 ret = DesktopIcon(
"media-tape" + mountString, size);
658 if (isDiskOfType(TDEDiskDeviceType::Camera)) {
659 ret = DesktopIcon(
"camera" + TQString((mountPath() != TQString::null) ?
"_mount" :
"_umount"), size);
662 if (isDiskOfType(TDEDiskDeviceType::HDD)) {
663 ret = DesktopIcon(
"drive-harddisk" + mountString, size);
664 if (checkDiskStatus(TDEDiskDeviceStatus::Hotpluggable)) {
665 ret = DesktopIcon(
"media-flash-usb" + mountString, size);
667 if (isDiskOfType(TDEDiskDeviceType::CompactFlash)) {
668 ret = DesktopIcon(
"media-flash-compact_flash" + mountString, size);
670 if (isDiskOfType(TDEDiskDeviceType::MemoryStick)) {
671 ret = DesktopIcon(
"media-flash-memory_stick" + mountString, size);
673 if (isDiskOfType(TDEDiskDeviceType::SmartMedia)) {
674 ret = DesktopIcon(
"media-flash-smart_media" + mountString, size);
676 if (isDiskOfType(TDEDiskDeviceType::SDMMC)) {
677 ret = DesktopIcon(
"media-flash-sd_mmc" + mountString, size);
681 if (isDiskOfType(TDEDiskDeviceType::RAM)) {
682 ret = DesktopIcon(
"memory" + mountString, size);
684 if (isDiskOfType(TDEDiskDeviceType::Loop)) {
685 ret = DesktopIcon(
"blockdevice" + mountString, size);
691 unsigned long long TDEStorageDevice::deviceSize() {
692 TQString bsnodename = systemPath();
695 TQString blocksize =
"512";
697 TQString dsnodename = systemPath();
698 dsnodename.append(
"/size");
699 TQFile dsfile( dsnodename );
701 if ( dsfile.open( IO_ReadOnly ) ) {
702 TQTextStream stream( &dsfile );
703 devicesize = stream.readLine();
707 return ((
unsigned long long)blocksize.toULong()*(
unsigned long long)devicesize.toULong());
710 TQString TDEStorageDevice::deviceFriendlySize() {
711 return TDEHardwareDevices::bytesToFriendlySizeString(deviceSize());
714 TQString TDEStorageDevice::mountPath() {
725 TQString dmnodename = systemPath();
726 dmnodename.append(
"/dm/name");
727 TQFile namefile( dmnodename );
729 if ( namefile.open( IO_ReadOnly ) ) {
730 TQTextStream stream( &namefile );
731 dmaltname = stream.readLine();
734 if (!dmaltname.isNull()) {
735 dmaltname.prepend(
"/dev/mapper/");
739 TQFile file(
"/proc/mounts" );
740 if ( file.open( IO_ReadOnly ) ) {
741 TQTextStream stream( &file );
743 while ( !stream.atEnd() ) {
744 line = stream.readLine();
745 TQStringList mountInfo = TQStringList::split(
" ", line,
true);
746 TQString testNode = *mountInfo.at(0);
748 if ((testNode == deviceNode()) || (testNode == dmaltname) || (testNode == (
"/dev/disk/by-uuid/" + diskUUID()))) {
749 TQString ret = *mountInfo.at(1);
750 ret.replace(
"\\040",
" ");
760 TQStringList slaveDeviceList = holdingDevices();
761 for ( TQStringList::Iterator slavedevit = slaveDeviceList.begin(); slavedevit != slaveDeviceList.end(); ++slavedevit ) {
764 TDEGenericDevice *hwdevice = hwdevices->findBySystemPath(*slavedevit);
765 if ((hwdevice) && (hwdevice->type() == TDEGenericDeviceType::Disk)) {
766 TDEStorageDevice* sdevice =
static_cast<TDEStorageDevice*
>(hwdevice);
767 return sdevice->mountPath();
771 return TQString::null;
774 TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet,
int* retcode) {
775 int internal_retcode;
777 retcode = &internal_retcode;
780 TQString ret = mountPath();
788 TQString devNode = deviceNode();
789 devNode.replace(
"'",
"'\\''");
790 mediaName.replace(
"'",
"'\\''");
792 #if defined(WITH_UDISKS2) || defined(WITH_UDISKS) 794 TQStringList udisksOptions;
795 TQString optionString;
797 if (mountOptions[
"ro"] ==
"true") {
798 udisksOptions.append(
"ro");
801 if (mountOptions[
"atime"] !=
"true") {
802 udisksOptions.append(
"noatime");
805 if (mountOptions[
"sync"] ==
"true") {
806 udisksOptions.append(
"sync");
809 if( (mountOptions[
"filesystem"] ==
"fat")
810 || (mountOptions[
"filesystem"] ==
"vfat")
811 || (mountOptions[
"filesystem"] ==
"msdos")
812 || (mountOptions[
"filesystem"] ==
"umsdos")
814 if (mountOptions.contains(
"shortname")) {
815 udisksOptions.append(TQString(
"shortname=%1").arg(mountOptions[
"shortname"]));
819 if( (mountOptions[
"filesystem"] ==
"jfs")) {
820 if (mountOptions[
"utf8"] ==
"true") {
826 if( (mountOptions[
"filesystem"] ==
"ntfs-3g") ) {
827 if (mountOptions.contains(
"locale")) {
828 udisksOptions.append(TQString(
"locale=%1").arg(mountOptions[
"locale"]));
832 if( (mountOptions[
"filesystem"] ==
"ext3")
833 || (mountOptions[
"filesystem"] ==
"ext4")
835 if (mountOptions.contains(
"journaling")) {
841 for (TQStringList::Iterator it = udisksOptions.begin(); it != udisksOptions.end(); ++it) {
842 optionString.append(
",");
843 optionString.append(*it);
846 if (!optionString.isEmpty()) {
847 optionString.remove(0, 1);
849 #endif // defined(WITH_UDISKS2) || defined(WITH_UDISKS) 852 if(command.isEmpty()) {
854 TQString errorString;
855 TQString fileSystemType;
857 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
858 fileSystemType = mountOptions[
"filesystem"];
861 int uDisks2Ret = mountDriveUDisks2(devNode, fileSystemType, optionString, &errorString);
862 if (uDisks2Ret == 0) {
869 else if (uDisks2Ret == -1) {
871 *errRet = errorString;
882 command = TQString::null;
885 #endif // WITH_UDISKS2 888 if(command.isEmpty()) {
890 TQString errorString;
891 TQString fileSystemType;
893 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
894 fileSystemType = mountOptions[
"filesystem"];
897 int uDisksRet = mountDriveUDisks(devNode, fileSystemType, udisksOptions, &errorString);
898 if (uDisksRet == 0) {
905 else if (uDisksRet == -1) {
907 *errRet = errorString;
918 command = TQString::null;
921 #endif // WITH_UDISKS 923 if(command.isEmpty()) {
926 if (!pmountProg.isEmpty()) {
928 KTempFile passwordFile(TQString::null,
"tmp", 0600);
929 passwordFile.setAutoDelete(
true);
931 TQString optionString;
932 if (mountOptions[
"ro"] ==
"true") {
933 optionString.append(
" -r");
936 if (mountOptions[
"atime"] !=
"true") {
937 optionString.append(
" -A");
940 if (mountOptions[
"utf8"] ==
"true") {
941 optionString.append(
" -c utf8");
944 if (mountOptions[
"sync"] ==
"true") {
945 optionString.append(
" -s");
948 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
949 optionString.append(TQString(
" -t %1").arg(mountOptions[
"filesystem"]));
952 if (mountOptions.contains(
"locale")) {
953 optionString.append(TQString(
" -c %1").arg(mountOptions[
"locale"]));
957 if (mountOptions.contains(
"mountpoint")
958 && !mountOptions[
"mountpoint"].isEmpty()
959 && (mountOptions[
"mountpoint"] !=
"/media/")) {
960 mountpoint = mountOptions[
"mountpoint"];
961 mountpoint.replace(
"'",
"'\\''");
964 mountpoint = mediaName;
967 TQString passFileName = passwordFile.name();
968 passFileName.replace(
"'",
"'\\''");
970 command = TQString(
"pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mountpoint);
974 if(command.isEmpty()) {
976 *errRet = i18n(
"No supported mounting methods were detected on your system");
981 FILE *exepipe = popen(command.local8Bit(),
"r");
983 TQString mount_output;
984 TQTextStream* ts =
new TQTextStream(exepipe, IO_ReadOnly);
985 mount_output = ts->read();
987 *retcode = pclose(exepipe);
989 *errRet = mount_output;
1001 TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString mediaName, TDEStorageMountOptions mountOptions, TQString* errRet,
int* retcode) {
1002 int internal_retcode;
1004 retcode = &internal_retcode;
1007 TQString ret = mountPath();
1009 if (!ret.isNull()) {
1014 KTempFile passwordFile(TQString::null,
"tmp", 0600);
1015 passwordFile.setAutoDelete(
true);
1016 TQFile* pwFile = passwordFile.file();
1018 return TQString::null;
1021 pwFile->writeBlock(passphrase.ascii(), passphrase.length());
1024 TQString optionString;
1025 if (mountOptions[
"ro"] ==
"true") {
1026 optionString.append(
" -r");
1029 if (mountOptions[
"atime"] !=
"true") {
1030 optionString.append(
" -A");
1033 if (mountOptions[
"utf8"] ==
"true") {
1034 optionString.append(
" -c utf8");
1037 if (mountOptions[
"sync"] ==
"true") {
1038 optionString.append(
" -s");
1041 if (mountOptions.contains(
"filesystem") && !mountOptions[
"filesystem"].isEmpty()) {
1042 optionString.append(TQString(
" -t %1").arg(mountOptions[
"filesystem"]));
1045 if (mountOptions.contains(
"locale")) {
1046 optionString.append(TQString(
" -c %1").arg(mountOptions[
"locale"]));
1049 TQString passFileName = passwordFile.name();
1050 TQString devNode = deviceNode();
1051 passFileName.replace(
"'",
"'\\''");
1052 devNode.replace(
"'",
"'\\''");
1053 mediaName.replace(
"'",
"'\\''");
1054 TQString command = TQString(
"pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
1056 FILE *exepipe = popen(command.local8Bit(),
"r");
1058 TQString mount_output;
1059 TQTextStream* ts =
new TQTextStream(exepipe, IO_ReadOnly);
1060 mount_output = ts->read();
1062 *retcode = pclose(exepipe);
1064 *errRet = mount_output;
1076 bool TDEStorageDevice::unmountDevice(TQString* errRet,
int* retcode) {
1077 int internal_retcode;
1079 retcode = &internal_retcode;
1082 TQString mountpoint = mountPath();
1083 TQString devNode = deviceNode();
1085 if (mountpoint.isNull()) {
1089 mountpoint.replace(
"'",
"'\\''");
1094 if(command.isEmpty()) {
1096 TQString errorString;
1097 int unMountUDisks2Ret = unMountDriveUDisks2(devNode, TQString::null, &errorString);
1098 if (unMountUDisks2Ret == 0) {
1104 else if (unMountUDisks2Ret == -1) {
1106 *errRet = errorString;
1116 command = TQString::null;
1119 #endif // WITH_UDISKS2 1121 if(command.isEmpty()) {
1123 TQString errorString;
1124 int unMountUDisksRet = unMountDriveUDisks(devNode, TQStringList(), &errorString);
1125 if (unMountUDisksRet == 0) {
1131 else if (unMountUDisksRet == -1) {
1133 *errRet = errorString;
1143 command = TQString::null;
1146 #endif // WITH_UDISKS 1147 if(command.isEmpty() &&
1149 command = TQString(
"pumount '%1' 2>&1").arg(mountpoint);
1152 if(command.isEmpty()) {
1154 *errRet = i18n(
"No supported unmounting methods were detected on your system");
1159 FILE *exepipe = popen(command.local8Bit(),
"r");
1161 TQString umount_output;
1162 TQTextStream* ts =
new TQTextStream(exepipe, IO_ReadOnly);
1163 umount_output = ts->read();
1165 *retcode = pclose(exepipe);
1166 if (*retcode == 0) {
1174 *errRet = umount_output;
1185 TQString TDEStorageDevice::determineFileSystemType(TQString path) {
1186 TQStringList mountTable;
1187 TQString prevPath = path;
1190 struct stat directory_info;
1191 if (path.startsWith(
"/")) {
1192 stat(path.local8Bit(), &directory_info);
1193 prevDev = directory_info.st_dev;
1196 while (path !=
"/") {
1197 pos = path.findRev(
"/", -1, TRUE);
1201 path = path.mid(0, pos);
1205 stat(path.local8Bit(), &directory_info);
1206 if (directory_info.st_dev != prevDev) {
1210 prevDev = directory_info.st_dev;
1216 TQFile file(
"/proc/mounts" );
1217 if ( file.open( IO_ReadOnly ) ) {
1218 TQTextStream stream( &file );
1219 while ( !stream.atEnd() ) {
1220 mountTable.append(stream.readLine());
1226 TQStringList::Iterator it;
1227 for ( it = mountTable.begin(); it != mountTable.end(); ++it ) {
1228 TQStringList mountInfo = TQStringList::split(
" ", (*it),
true);
1229 if ((*mountInfo.at(1)) == prevPath) {
1230 return (*mountInfo.at(2));
1235 return TQString::null;
1238 #include "tdestoragedevice.moc" const TDEShortcut & open()
Open file.
static TDEHardwareDevices * hardwareDevices()
Returns a TDEHardwareDevices object.
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.
TQString label(StdAccel id)
Returns a localized label for user-visible display.