mirror of
https://github.com/veracrypt/VeraCrypt
synced 2024-11-27 21:43:29 +01:00
Merge pull request #243 from gv5470/patch-233-pr
Linux: autodetect host drive name using sysfs (closes #233)
This commit is contained in:
commit
c5e48c56c9
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user