summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tdecore/tdehw/tdestoragedevice.cpp181
-rw-r--r--tdeioslave/file/file.cc88
2 files changed, 224 insertions, 45 deletions
diff --git a/tdecore/tdehw/tdestoragedevice.cpp b/tdecore/tdehw/tdestoragedevice.cpp
index 8dc279f67..3b194bcfe 100644
--- a/tdecore/tdehw/tdestoragedevice.cpp
+++ b/tdecore/tdehw/tdestoragedevice.cpp
@@ -32,6 +32,7 @@
#include "tdeglobal.h"
#include "kiconloader.h"
#include "tdetempfile.h"
+#include "kstandarddirs.h"
#include "tdehardwaredevices.h"
@@ -601,47 +602,151 @@ TQString TDEStorageDevice::mountDevice(TQString mediaName, TDEStorageMountOption
TQString ret = mountPath();
+ // Device is already mounted
if (!ret.isNull()) {
return ret;
}
- // Create dummy password file
- KTempFile passwordFile(TQString::null, "tmp", 0600);
- passwordFile.setAutoDelete(true);
+ TQString command;
+ TQString devNode = deviceNode();
+ devNode.replace("'", "'\\''");
+ mediaName.replace("'", "'\\''");
+#if defined(WITH_UDISKS2) || defined(WITH_UDISKS)
+ // Prepare filesystem options for mount
TQString optionString;
+
if (mountOptions["ro"] == "true") {
- optionString.append(" -r");
+ optionString.append(",ro");
}
-
+
if (mountOptions["atime"] != "true") {
- optionString.append(" -A");
+ optionString.append(",noatime");
}
-
- if (mountOptions["utf8"] == "true") {
- optionString.append(" -c utf8");
- }
-
+
if (mountOptions["sync"] == "true") {
- optionString.append(" -s");
+ optionString.append(",sync");
}
- if (mountOptions.contains("filesystem")) {
- optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"]));
+ if( (mountOptions["filesystem"] == "fat")
+ || (mountOptions["filesystem"] == "vfat")
+ || (mountOptions["filesystem"] == "msdos")
+ || (mountOptions["filesystem"] == "umsdos")
+ ) {
+ if (mountOptions.contains("shortname")) {
+ optionString.append(TQString(",shortname=%1").arg(mountOptions["shortname"]));
+ }
}
- if (mountOptions.contains("locale")) {
- optionString.append(TQString(" -c %1").arg(mountOptions["locale"]));
+ if( (mountOptions["filesystem"] == "jfs")) {
+ if (mountOptions["utf8"] == "true") {
+ optionString.append(",iocharset=utf8");
+ }
}
- TQString passFileName = passwordFile.name();
- TQString devNode = deviceNode();
- passFileName.replace("'", "'\\''");
- devNode.replace("'", "'\\''");
- mediaName.replace("'", "'\\''");
- TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
+ if( (mountOptions["filesystem"] == "ntfs-3g") ) {
+ if (mountOptions.contains("locale")) {
+ optionString.append(TQString(",locale=%1").arg(mountOptions["locale"]));
+ }
+ }
+
+ if( (mountOptions["filesystem"] == "ext3")
+ || (mountOptions["filesystem"] == "ext4")
+ ) {
+ if (mountOptions.contains("journaling")) {
+ optionString.append(TQString(",data=%1").arg(mountOptions["journaling"]));
+ }
+ }
+
+ if (!optionString.isEmpty()) {
+ optionString.remove(0, 1);
+ }
+#endif // defined(WITH_UDISKS2) || defined(WITH_UDISKS)
- FILE *exepipe = popen(command.ascii(), "r");
+#ifdef WITH_UDISKS2
+ if(command.isEmpty()) {
+ // Use 'udisksctl' command (from UDISKS2), if available
+ TQString udisksctlProg = TDEGlobal::dirs()->findExe("udisksctl");
+ if (!udisksctlProg.isEmpty()) {
+
+ if(!optionString.isEmpty()) {
+ optionString.insert(0, "-o ");
+ }
+
+ if (mountOptions.contains("filesystem")) {
+ optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"]));
+ }
+
+ command = TQString("udisksctl mount -b '%1' %2 2>&1").arg(devNode).arg(optionString);
+ }
+ }
+#endif // WITH_UDISKS2
+
+#ifdef WITH_UDISKS
+ if(command.isEmpty()) {
+ // Use 'udisks' command (from UDISKS1), if available
+ TQString udisksProg = TDEGlobal::dirs()->findExe("udisks");
+ if (!udisksProg.isEmpty()) {
+ TQString optionString;
+
+ if(!optionString.isEmpty()) {
+ optionString.insert(0, "--mount-options ");
+ }
+
+ if (mountOptions.contains("filesystem")) {
+ optionString.append(TQString(" --mount-fstype %1").arg(mountOptions["filesystem"]));
+ }
+
+ command = TQString("udisks --mount '%1' %2 2>&1").arg(devNode).arg(optionString);
+ }
+ }
+#endif // WITH_UDISKS
+
+ if(command.isEmpty()) {
+ // Use 'pmount' command, if available
+ TQString pmountProg = TDEGlobal::dirs()->findExe("pmount");
+ if (!pmountProg.isEmpty()) {
+ // Create dummy password file
+ KTempFile passwordFile(TQString::null, "tmp", 0600);
+ passwordFile.setAutoDelete(true);
+
+ TQString optionString;
+ if (mountOptions["ro"] == "true") {
+ optionString.append(" -r");
+ }
+
+ if (mountOptions["atime"] != "true") {
+ optionString.append(" -A");
+ }
+
+ if (mountOptions["utf8"] == "true") {
+ optionString.append(" -c utf8");
+ }
+
+ if (mountOptions["sync"] == "true") {
+ optionString.append(" -s");
+ }
+
+ if (mountOptions.contains("filesystem")) {
+ optionString.append(TQString(" -t %1").arg(mountOptions["filesystem"]));
+ }
+
+ if (mountOptions.contains("locale")) {
+ optionString.append(TQString(" -c %1").arg(mountOptions["locale"]));
+ }
+
+ TQString passFileName = passwordFile.name();
+ passFileName.replace("'", "'\\''");
+
+ command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
+ }
+ }
+
+ if(command.isEmpty()) {
+ return ret;
+ }
+
+ FILE *exepipe = popen(command.local8Bit(), "r");
if (exepipe) {
TQString pmount_output;
char buffer[8092];
@@ -715,7 +820,7 @@ TQString TDEStorageDevice::mountEncryptedDevice(TQString passphrase, TQString me
mediaName.replace("'", "'\\''");
TQString command = TQString("pmount -p '%1' %2 '%3' '%4' 2>&1").arg(passFileName).arg(optionString).arg(devNode).arg(mediaName);
- FILE *exepipe = popen(command.ascii(), "r");
+ FILE *exepipe = popen(command.local8Bit(), "r");
if (exepipe) {
TQString pmount_output;
char buffer[8092];
@@ -741,14 +846,38 @@ bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) {
}
TQString mountpoint = mountPath();
+ TQString devNode = deviceNode();
if (mountpoint.isNull()) {
return true;
}
mountpoint.replace("'", "'\\''");
- TQString command = TQString("pumount '%1' 2>&1").arg(mountpoint);
- FILE *exepipe = popen(command.ascii(), "r");
+
+ TQString command;
+
+#ifdef WITH_UDISKS2
+ if(command.isEmpty() &&
+ !(TDEGlobal::dirs()->findExe("udisksctl").isEmpty())) {
+ command = TQString("udisksctl unmount -b '%1' 2>&1").arg(devNode);
+ }
+#endif // WITH_UDISKS2
+#ifdef WITH_UDISKS
+ if(command.isEmpty() &&
+ !(TDEGlobal::dirs()->findExe("udisks").isEmpty()) ) {
+ command = TQString("udisks --unmount '%1' 2>&1").arg(devNode);
+ }
+#endif // WITH_UDISKS
+ if(command.isEmpty() &&
+ !(TDEGlobal::dirs()->findExe("pumount").isEmpty())) {
+ command = TQString("pumount '%1' 2>&1").arg(mountpoint);
+ }
+
+ if(command.isEmpty()) {
+ return true;
+ }
+
+ FILE *exepipe = popen(command.local8Bit(), "r");
if (exepipe) {
TQString pmount_output;
char buffer[8092];
diff --git a/tdeioslave/file/file.cc b/tdeioslave/file/file.cc
index 75b3b17a1..b13357fe6 100644
--- a/tdeioslave/file/file.cc
+++ b/tdeioslave/file/file.cc
@@ -1658,18 +1658,43 @@ void FileProtocol::unmount( const TQString& _point )
bool FileProtocol::pmount(const TQString &dev)
{
- TQString epath = getenv("PATH");
- TQString path = TQString::fromLatin1("/sbin:/bin");
- if (!epath.isEmpty())
- path += ":" + epath;
- TQString pmountProg = TDEGlobal::dirs()->findExe("pmount", path);
+ TQString mountProg;
+ TQCString buffer;
- if (pmountProg.isEmpty())
- return false;
+#ifdef WITH_UDISKS2
+ // Use 'udisksctl' (UDISKS2) if available
+ if (mountProg.isEmpty()) {
+ mountProg = TDEGlobal::dirs()->findExe("udisksctl");
+ if (!mountProg.isEmpty()) {
+ buffer.sprintf( "%s mount -b %s", TQFile::encodeName(mountProg).data(),
+ TQFile::encodeName(TDEProcess::quote(dev)).data() );
+ }
+ }
+#endif // WITH_UDISKS2
- TQCString buffer;
- buffer.sprintf( "%s %s", TQFile::encodeName(pmountProg).data(),
- TQFile::encodeName(TDEProcess::quote(dev)).data() );
+#ifdef WITH_UDISKS
+ // Use 'udisks' (UDISKS1) if available
+ if (mountProg.isEmpty()) {
+ mountProg = TDEGlobal::dirs()->findExe("udisks");
+ if (!mountProg.isEmpty()) {
+ buffer.sprintf( "%s --mount %s", TQFile::encodeName(mountProg).data(),
+ TQFile::encodeName(TDEProcess::quote(dev)).data() );
+ }
+ }
+#endif // WITH_UDISKS
+
+ // Use 'pmount', if available
+ if (mountProg.isEmpty()) {
+ mountProg = TDEGlobal::dirs()->findExe("pmount");
+ if (!mountProg.isEmpty()) {
+ buffer.sprintf( "%s %s", TQFile::encodeName(mountProg).data(),
+ TQFile::encodeName(TDEProcess::quote(dev)).data() );
+ }
+ }
+
+ if (mountProg.isEmpty()) {
+ return false;
+ }
int res = system( buffer.data() );
@@ -1700,18 +1725,43 @@ bool FileProtocol::pumount(const TQString &point)
if (dev.isEmpty()) return false;
if (dev.endsWith("/")) dev.truncate(dev.length()-1);
- TQString epath = getenv("PATH");
- TQString path = TQString::fromLatin1("/sbin:/bin");
- if (!epath.isEmpty())
- path += ":" + epath;
- TQString pumountProg = TDEGlobal::dirs()->findExe("pumount", path);
+ TQString umountProg;
+ TQCString buffer;
- if (pumountProg.isEmpty())
- return false;
+#ifdef WITH_UDISKS2
+ // Use 'udisksctl' (UDISKS2), if available
+ if (umountProg.isEmpty()) {
+ umountProg = TDEGlobal::dirs()->findExe("udisksctl");
+ if (!umountProg.isEmpty()) {
+ buffer.sprintf( "%s unmount -b %s", TQFile::encodeName(umountProg).data(),
+ TQFile::encodeName(TDEProcess::quote(dev)).data() );
+ }
+ }
+#endif // WITH_UDISKS2
- TQCString buffer;
- buffer.sprintf( "%s %s", TQFile::encodeName(pumountProg).data(),
+#ifdef WITH_UDISKS
+ // Use 'udisks' (UDISKS1), if available
+ if (umountProg.isEmpty()) {
+ umountProg = TDEGlobal::dirs()->findExe("udisks");
+ if (!umountProg.isEmpty()) {
+ buffer.sprintf( "%s --unmount %s", TQFile::encodeName(umountProg).data(),
TQFile::encodeName(TDEProcess::quote(dev)).data() );
+ }
+ }
+#endif // WITH_UDISKS
+
+ // Use 'pumount', if available
+ if (umountProg.isEmpty()) {
+ umountProg = TDEGlobal::dirs()->findExe("pumount");
+ if (!umountProg.isEmpty()) {
+ buffer.sprintf( "%s %s", TQFile::encodeName(umountProg).data(),
+ TQFile::encodeName(TDEProcess::quote(dev)).data() );
+ }
+ }
+
+ if (umountProg.isEmpty()) {
+ return false;
+ }
int res = system( buffer.data() );