diff options
author | gv5470 <gv5470@orange.fr> | 2017-11-28 19:03:07 +0100 |
---|---|---|
committer | gv5470 <gv5470@orange.fr> | 2017-11-28 19:03:07 +0100 |
commit | 49f9516c9e7976d78eefc8f4230bb1ebd330e71d (patch) | |
tree | 4dc54a7bf23499f49ac4ee4e35a23fba3744a300 /src/Platform/Unix/FilesystemPath.cpp | |
parent | f53eb8e260d174153bb3fc24ff1fff7966dcfbee (diff) | |
download | VeraCrypt-49f9516c9e7976d78eefc8f4230bb1ebd330e71d.tar.gz VeraCrypt-49f9516c9e7976d78eefc8f4230bb1ebd330e71d.zip |
Linux: autodetect host drive name using sysfs (closes #233)
Diffstat (limited to 'src/Platform/Unix/FilesystemPath.cpp')
-rw-r--r-- | src/Platform/Unix/FilesystemPath.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/Platform/Unix/FilesystemPath.cpp b/src/Platform/Unix/FilesystemPath.cpp index c7bfece9..5841edf4 100644 --- a/src/Platform/Unix/FilesystemPath.cpp +++ b/src/Platform/Unix/FilesystemPath.cpp @@ -72,6 +72,29 @@ namespace VeraCrypt path = StringConverter::StripTrailingNumber (StringConverter::ToSingle (Path)); + // If simply removing trailing number didn't produce a valid drive name, try to use sysfs to get the right one + if (!path.IsDevice()) { + struct stat st; + + if(stat (StringConverter::ToSingle (Path).c_str (), &st) == 0) { + const long maxPathLength = pathconf ("/", _PC_PATH_MAX); + + if(maxPathLength != -1) { + string linkPathName ("/sys/dev/block/"); + linkPathName += StringConverter::ToSingle (major (st.st_rdev)) + string (":") + StringConverter::ToSingle (minor (st.st_rdev)); + + char linkTargetPath[maxPathLength+1] = ""; + + if(readlink(linkPathName.c_str (), linkTargetPath, sizeof (linkTargetPath)) != -1) { + const string targetPathStr (linkTargetPath); + const size_t lastSlashPos = targetPathStr.find_last_of ('/'); + const size_t secondLastSlashPos = targetPathStr.find_last_of ('/', lastSlashPos-1); + path = string ("/dev/") + targetPathStr.substr (secondLastSlashPos+1, lastSlashPos-secondLastSlashPos-1); + } + } + } + } + #elif defined (TC_MACOSX) string pathStr = StringConverter::StripTrailingNumber (StringConverter::ToSingle (Path)); |