|
Lines 32-37
Link Here
|
| 32 |
#include "tdeglobal.h" |
32 |
#include "tdeglobal.h" |
| 33 |
#include "kiconloader.h" |
33 |
#include "kiconloader.h" |
| 34 |
#include "tdetempfile.h" |
34 |
#include "tdetempfile.h" |
|
|
35 |
#include "kstandarddirs.h" |
| 35 |
|
36 |
|
| 36 |
#include "tdehardwaredevices.h" |
37 |
#include "tdehardwaredevices.h" |
| 37 |
|
38 |
|
|
Lines 601-661
TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
Link Here
|
| 601 |
|
602 |
|
| 602 |
TQString ret = mountPath(); |
603 |
TQString ret = mountPath(); |
| 603 |
|
604 |
|
|
|
605 |
// Device is already mounted |
| 604 |
if (!ret.isNull()) { |
606 |
if (!ret.isNull()) { |
| 605 |
return ret; |
607 |
return ret; |
| 606 |
} |
608 |
} |
| 607 |
|
609 |
|
| 608 |
// Create dummy password file |
610 |
TQString command; |
| 609 |
KTempFile passwordFile(TQString::null, "tmp", 0600); |
611 |
TQString devNode = deviceNode(); |
| 610 |
passwordFile.setAutoDelete(true); |
612 |
devNode.replace("'", "'\\''"); |
|
|
613 |
mediaName.replace("'", "'\\''"); |
| 611 |
|
614 |
|
|
|
615 |
#if defined(WITH_UDISKS2) || defined(WITH_UDISKS) |
| 616 |
// Prepare filesystem options for mount |
| 612 |
TQString optionString; |
617 |
TQString optionString; |
|
|
618 |
|
| 613 |
if (mountOptions["ro"] == "true") { |
619 |
if (mountOptions["ro"] == "true") { |
| 614 |
optionString.append(" -r"); |
620 |
optionString.append(",ro"); |
| 615 |
} |
621 |
} |
| 616 |
|
622 |
|
| 617 |
if (mountOptions["atime"] != "true") { |
623 |
if (mountOptions["atime"] != "true") { |
| 618 |
optionString.append(" -A"); |
624 |
optionString.append(",noatime"); |
| 619 |
} |
|
|
| 620 |
|
| 621 |
if (mountOptions["utf8"] == "true") { |
| 622 |
optionString.append(" -c utf8"); |
| 623 |
} |
625 |
} |
| 624 |
|
626 |
|
| 625 |
if (mountOptions["sync"] == "true") { |
627 |
if (mountOptions["sync"] == "true") { |
| 626 |
optionString.append(" -s"); |
628 |
optionString.append(",sync"); |
| 627 |
} |
629 |
} |
| 628 |
|
630 |
|
| 629 |
if (mountOptions.contains("filesystem")) { |
631 |
if( (mountOptions["filesystem"] == "fat") |
| 630 |
optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"])); |
632 |
|| (mountOptions["filesystem"] == "vfat") |
|
|
633 |
|| (mountOptions["filesystem"] == "msdos") |
| 634 |
|| (mountOptions["filesystem"] == "umsdos") |
| 635 |
) { |
| 636 |
/* VFAT and UTF-8 need special care, see Debian bug #443514 and mount(1) */ |
| 637 |
if (mountOptions["utf8"] == "true") { |
| 638 |
optionString.append(",utf8,iocharset=iso8859-1"); |
| 639 |
} |
| 640 |
|
| 641 |
if (mountOptions.contains("shortname")) { |
| 642 |
optionString.append(TQString(",shortname=%1").arg(mountOptions["shortname"])); |
| 643 |
} |
| 631 |
} |
644 |
} |
| 632 |
|
645 |
|
| 633 |
if (mountOptions.contains("locale")) { |
646 |
if( (mountOptions["filesystem"] == "iso9660") |
| 634 |
optionString.append(TQString(" -c %1").arg(mountOptions["locale"])); |
647 |
|| (mountOptions["filesystem"] == "ntfs") |
|
|
648 |
|| (mountOptions["filesystem"] == "jfs") |
| 649 |
) { |
| 650 |
if (mountOptions["utf8"] == "true") { |
| 651 |
optionString.append(",iocharset=utf8"); |
| 652 |
} |
| 635 |
} |
653 |
} |
| 636 |
|
654 |
|
| 637 |
TQString passFileName = passwordFile.name(); |
655 |
if( (mountOptions["filesystem"] == "ntfs-3g") ) { |
| 638 |
TQString devNode = deviceNode(); |
656 |
if (mountOptions.contains("locale")) { |
| 639 |
passFileName.replace("'", "'\\''"); |
657 |
optionString.append(TQString(",locale=%1").arg(mountOptions["locale"])); |
| 640 |
devNode.replace("'", "'\\''"); |
658 |
} |
| 641 |
mediaName.replace("'", "'\\''"); |
659 |
} |
| 642 |
TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName); |
|
|
| 643 |
|
660 |
|
| 644 |
FILE *exepipe = popen(command.ascii(), "r"); |
661 |
if( (mountOptions["filesystem"] == "ext3") |
| 645 |
if (exepipe) { |
662 |
|| (mountOptions["filesystem"] == "ext4") |
| 646 |
TQString pmount_output; |
663 |
) { |
| 647 |
char buffer[8092]; |
664 |
if (mountOptions.contains("journaling")) { |
| 648 |
pmount_output = fgets(buffer, sizeof(buffer), exepipe); |
665 |
optionString.append(TQString(",data=%1").arg(mountOptions["journaling"])); |
| 649 |
*retcode = pclose(exepipe); |
|
|
| 650 |
if (errRet) { |
| 651 |
*errRet = pmount_output; |
| 652 |
} |
666 |
} |
| 653 |
} |
667 |
} |
| 654 |
|
668 |
|
| 655 |
// Update internal mount data |
669 |
if (!optionString.isEmpty()) { |
| 656 |
TDEGlobal::hardwareDevices()->processModifiedMounts(); |
670 |
optionString.remove(0, 1); |
|
|
671 |
} |
| 672 |
#endif // defined(WITH_UDISKS2) || defined(WITH_UDISKS) |
| 657 |
|
673 |
|
| 658 |
ret = mountPath(); |
674 |
#ifdef WITH_UDISKS2 |
|
|
675 |
if(command.isEmpty()) { |
| 676 |
// Use 'udisksctl' command (from UDISKS2), if available |
| 677 |
TQString udisksctlProg = TDEGlobal::dirs()->findExe("udisksctl"); |
| 678 |
if (!udisksctlProg.isEmpty()) { |
| 679 |
|
| 680 |
if(!optionString.isEmpty()) { |
| 681 |
optionString.insert(0, "-o "); |
| 682 |
} |
| 683 |
|
| 684 |
if (mountOptions.contains("filesystem")) { |
| 685 |
optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"])); |
| 686 |
} |
| 687 |
|
| 688 |
command = TQString("udisksctl mount -b '%1' %2 2>&1").arg(devNode).arg(optionString); |
| 689 |
} |
| 690 |
} |
| 691 |
#endif // WITH_UDISKS2 |
| 692 |
|
| 693 |
#ifdef WITH_UDISKS |
| 694 |
if(command.isEmpty()) { |
| 695 |
// Use 'udisks' command (from UDISKS1), if available |
| 696 |
TQString udisksProg = TDEGlobal::dirs()->findExe("udisks"); |
| 697 |
if (!udisksProg.isEmpty()) { |
| 698 |
TQString optionString; |
| 699 |
|
| 700 |
if(!optionString.isEmpty()) { |
| 701 |
optionString.insert(0, "--mount-options "); |
| 702 |
} |
| 703 |
|
| 704 |
if (mountOptions.contains("filesystem")) { |
| 705 |
optionString.append(TQString(" --mount-fstype %1").arg(mountOptions["filesystem"])); |
| 706 |
} |
| 707 |
|
| 708 |
command = TQString("udisks --mount '%1' %2 2>&1").arg(devNode).arg(optionString); |
| 709 |
} |
| 710 |
} |
| 711 |
#endif // WITH_UDISKS |
| 712 |
|
| 713 |
if(command.isEmpty()) { |
| 714 |
// Use 'pmount' command, if available |
| 715 |
TQString pmountProg = TDEGlobal::dirs()->findExe("pmount"); |
| 716 |
if (!pmountProg.isEmpty()) { |
| 717 |
// Create dummy password file |
| 718 |
KTempFile passwordFile(TQString::null, "tmp", 0600); |
| 719 |
passwordFile.setAutoDelete(true); |
| 720 |
|
| 721 |
TQString optionString; |
| 722 |
if (mountOptions["ro"] == "true") { |
| 723 |
optionString.append(" -r"); |
| 724 |
} |
| 725 |
|
| 726 |
if (mountOptions["atime"] != "true") { |
| 727 |
optionString.append(" -A"); |
| 728 |
} |
| 729 |
|
| 730 |
if (mountOptions["utf8"] == "true") { |
| 731 |
optionString.append(" -c utf8"); |
| 732 |
} |
| 733 |
|
| 734 |
if (mountOptions["sync"] == "true") { |
| 735 |
optionString.append(" -s"); |
| 736 |
} |
| 737 |
|
| 738 |
if (mountOptions.contains("filesystem")) { |
| 739 |
optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"])); |
| 740 |
} |
| 741 |
|
| 742 |
if (mountOptions.contains("locale")) { |
| 743 |
optionString.append(TQString(" -c %1").arg(mountOptions["locale"])); |
| 744 |
} |
| 745 |
|
| 746 |
TQString passFileName = passwordFile.name(); |
| 747 |
passFileName.replace("'", "'\\''"); |
| 748 |
|
| 749 |
command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName); |
| 750 |
} |
| 751 |
} |
| 752 |
|
| 753 |
if(!command.isEmpty()) { |
| 754 |
FILE *exepipe = popen(command.local8Bit(), "r"); |
| 755 |
if (exepipe) { |
| 756 |
TQString pmount_output; |
| 757 |
char buffer[8092]; |
| 758 |
pmount_output = fgets(buffer, sizeof(buffer), exepipe); |
| 759 |
*retcode = pclose(exepipe); |
| 760 |
if (errRet) { |
| 761 |
*errRet = pmount_output; |
| 762 |
} |
| 763 |
} |
| 764 |
|
| 765 |
// Update internal mount data |
| 766 |
TDEGlobal::hardwareDevices()->processModifiedMounts(); |
| 767 |
|
| 768 |
ret = mountPath(); |
| 769 |
} |
| 659 |
|
770 |
|
| 660 |
return ret; |
771 |
return ret; |
| 661 |
} |
772 |
} |
|
Lines 715-721
TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString me
Link Here
|
| 715 |
mediaName.replace("'", "'\\''"); |
826 |
mediaName.replace("'", "'\\''"); |
| 716 |
TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName); |
827 |
TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName); |
| 717 |
|
828 |
|
| 718 |
FILE *exepipe = popen(command.ascii(), "r"); |
829 |
FILE *exepipe = popen(command.local8Bit(), "r"); |
| 719 |
if (exepipe) { |
830 |
if (exepipe) { |
| 720 |
TQString pmount_output; |
831 |
TQString pmount_output; |
| 721 |
char buffer[8092]; |
832 |
char buffer[8092]; |
|
Lines 741-771
bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) {
Link Here
|
| 741 |
} |
852 |
} |
| 742 |
|
853 |
|
| 743 |
TQString mountpoint = mountPath(); |
854 |
TQString mountpoint = mountPath(); |
|
|
855 |
TQString devNode = deviceNode(); |
| 744 |
|
856 |
|
| 745 |
if (mountpoint.isNull()) { |
857 |
if (mountpoint.isNull()) { |
| 746 |
return true; |
858 |
return true; |
| 747 |
} |
859 |
} |
| 748 |
|
860 |
|
| 749 |
mountpoint.replace("'", "'\\''"); |
861 |
mountpoint.replace("'", "'\\''"); |
| 750 |
TQString command = TQString("pumount '%1' 2>&1").arg(mountpoint); |
862 |
|
| 751 |
FILE *exepipe = popen(command.ascii(), "r"); |
863 |
TQString command; |
| 752 |
if (exepipe) { |
864 |
|
| 753 |
TQString pmount_output; |
865 |
#ifdef WITH_UDISKS2 |
| 754 |
char buffer[8092]; |
866 |
if(command.isEmpty() && |
| 755 |
pmount_output = fgets(buffer, sizeof(buffer), exepipe); |
867 |
!(TDEGlobal::dirs()->findExe("udisksctl").isEmpty())) { |
| 756 |
*retcode = pclose(exepipe); |
868 |
command = TQString("udisksctl unmount -b '%1' 2>&1").arg(devNode); |
| 757 |
if (*retcode == 0) { |
869 |
} |
| 758 |
return true; |
870 |
#endif // WITH_UDISKS2 |
| 759 |
} |
871 |
#ifdef WITH_UDISKS |
| 760 |
else { |
872 |
if(command.isEmpty() && |
| 761 |
if (errRet) { |
873 |
!(TDEGlobal::dirs()->findExe("udisks").isEmpty()) ) { |
| 762 |
*errRet = pmount_output; |
874 |
command = TQString("udisks --unmount '%1' 2>&1").arg(devNode); |
|
|
875 |
} |
| 876 |
#endif // WITH_UDISKS |
| 877 |
if(command.isEmpty() && |
| 878 |
!(TDEGlobal::dirs()->findExe("pumount").isEmpty())) { |
| 879 |
command = TQString("pumount '%1' 2>&1").arg(mountpoint); |
| 880 |
} |
| 881 |
|
| 882 |
if(!command.isEmpty()) { |
| 883 |
FILE *exepipe = popen(command.local8Bit(), "r"); |
| 884 |
if (exepipe) { |
| 885 |
TQString pmount_output; |
| 886 |
char buffer[8092]; |
| 887 |
pmount_output = fgets(buffer, sizeof(buffer), exepipe); |
| 888 |
*retcode = pclose(exepipe); |
| 889 |
if (*retcode == 0) { |
| 890 |
return true; |
| 891 |
} |
| 892 |
else { |
| 893 |
if (errRet) { |
| 894 |
*errRet = pmount_output; |
| 895 |
} |
| 763 |
} |
896 |
} |
| 764 |
} |
897 |
} |
| 765 |
} |
|
|
| 766 |
|
898 |
|
| 767 |
// Update internal mount data |
899 |
// Update internal mount data |
| 768 |
TDEGlobal::hardwareDevices()->processModifiedMounts(); |
900 |
TDEGlobal::hardwareDevices()->processModifiedMounts(); |
|
|
901 |
} |
| 769 |
|
902 |
|
| 770 |
return false; |
903 |
return false; |
| 771 |
} |
904 |
} |