diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-08-26 10:32:41 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2013-08-26 10:32:41 -0500 |
commit | 9d76cb942d54c5e8edec59d90644326219b1c4a0 (patch) | |
tree | 5f4a5474c61c923e4bbffae76ed082ae4605c452 /tdecore/tdehw/tdestoragedevice.cpp | |
parent | cb9c3ed914b0b1578a3fcaea3e35add08cc0bdfb (diff) | |
download | tdelibs-9d76cb942d54c5e8edec59d90644326219b1c4a0.tar.gz tdelibs-9d76cb942d54c5e8edec59d90644326219b1c4a0.zip |
Disable suspend/hibernate if $HOME is a network file system
This resolves Bug 1615
Diffstat (limited to 'tdecore/tdehw/tdestoragedevice.cpp')
-rw-r--r-- | tdecore/tdehw/tdestoragedevice.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/tdecore/tdehw/tdestoragedevice.cpp b/tdecore/tdehw/tdestoragedevice.cpp index f13146b00..3824f488e 100644 --- a/tdecore/tdehw/tdestoragedevice.cpp +++ b/tdecore/tdehw/tdestoragedevice.cpp @@ -21,6 +21,7 @@ #include <unistd.h> #include <fcntl.h> +#include <sys/stat.h> #include <sys/ioctl.h> #include <linux/cdrom.h> @@ -769,4 +770,57 @@ bool TDEStorageDevice::unmountDevice(TQString* errRet, int* retcode) { return false; } +TQString TDEStorageDevice::determineFileSystemType(TQString path) { + TQStringList mountTable; + TQString prevPath = path; + dev_t prevDev = 0; + int pos; + struct stat directory_info; + if (path.startsWith("/")) { + stat(path.ascii(), &directory_info); + prevDev = directory_info.st_dev; + // Walk the directory tree up to the root, checking for any change in st_dev + // If a change is found, the previous value of path is the mount point itself + while (path != "/") { + pos = path.findRev("/", -1, TRUE); + if (pos < 0) { + break; + } + path = path.mid(0, pos); + if (path == "") { + path = "/"; + } + stat(path.ascii(), &directory_info); + if (directory_info.st_dev != prevDev) { + break; + } + prevPath = path; + prevDev = directory_info.st_dev; + } + } + + // Read in mount table + mountTable.clear(); + TQFile file( "/proc/mounts" ); + if ( file.open( IO_ReadOnly ) ) { + TQTextStream stream( &file ); + while ( !stream.atEnd() ) { + mountTable.append(stream.readLine()); + } + file.close(); + } + + // Parse mount table + TQStringList::Iterator it; + for ( it = mountTable.begin(); it != mountTable.end(); ++it ) { + TQStringList mountInfo = TQStringList::split(" ", (*it), true); + if ((*mountInfo.at(1)) == prevPath) { + return (*mountInfo.at(2)); + } + } + + // Unknown file system type + return TQString::null; +} + #include "tdestoragedevice.moc" |