mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2025-11-11 11:08:02 -06:00
Make system devices work under FreeBSD (#777)
We query the kern.geom.conftxt sysctl for the GEOM configuration to find the partition offset. Technically speaking it would probably be better to link against libgeom but this is less overall intrusive. Also includes a small fix to find the parent device of an encrypted partition when it is a GPT partition rather than a BSD slice.
This commit is contained in:
@@ -38,6 +38,10 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#ifdef TC_FREEBSD
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "Platform/File.h"
|
#include "Platform/File.h"
|
||||||
#include "Platform/TextReader.h"
|
#include "Platform/TextReader.h"
|
||||||
|
|
||||||
@@ -157,6 +161,31 @@ namespace VeraCrypt
|
|||||||
throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBASE, &offset) == -1, wstring (Path));
|
throw_sys_sub_if (ioctl (FileHandle, DKIOCGETBASE, &offset) == -1, wstring (Path));
|
||||||
return offset;
|
return offset;
|
||||||
|
|
||||||
|
#elif defined (TC_FREEBSD)
|
||||||
|
// Get the kernel GEOM configuration
|
||||||
|
size_t sysctlDataLen, mibLen;
|
||||||
|
int mib[4];
|
||||||
|
mibLen = 4;
|
||||||
|
throw_sys_sub_if (sysctlnametomib ("kern.geom.conftxt", mib, &mibLen), wstring (Path));
|
||||||
|
throw_sys_sub_if (sysctl (mib, mibLen, NULL, &sysctlDataLen, NULL, 0), wstring (Path));
|
||||||
|
vector<char> conftxt(sysctlDataLen);
|
||||||
|
throw_sys_sub_if (sysctl (mib, mibLen, (void *)conftxt.data(), &sysctlDataLen, NULL, 0), wstring (Path));
|
||||||
|
|
||||||
|
// Find the slice/partition data
|
||||||
|
string conftxtStr (conftxt.begin(), conftxt.end());
|
||||||
|
size_t confLoc = conftxtStr.find (Path.ToBaseName());
|
||||||
|
throw_sys_sub_if (confLoc == string::npos, wstring (Path));
|
||||||
|
|
||||||
|
// Skip to the ninth column
|
||||||
|
for (int i = 0; i < 6;i++) {
|
||||||
|
confLoc = conftxtStr.find (" ", confLoc + 1);
|
||||||
|
throw_sys_sub_if (confLoc == string::npos, wstring (Path));
|
||||||
|
}
|
||||||
|
confLoc++;
|
||||||
|
size_t end = conftxtStr.find (" ", confLoc);
|
||||||
|
throw_sys_sub_if (end == string::npos, wstring (Path));
|
||||||
|
return StringConverter::ToUInt64 (conftxtStr.substr (confLoc, end - confLoc));
|
||||||
|
|
||||||
#elif defined (TC_SOLARIS)
|
#elif defined (TC_SOLARIS)
|
||||||
|
|
||||||
struct extpart_info partInfo;
|
struct extpart_info partInfo;
|
||||||
|
|||||||
@@ -107,8 +107,11 @@ namespace VeraCrypt
|
|||||||
|
|
||||||
string pathStr = StringConverter::ToSingle (Path);
|
string pathStr = StringConverter::ToSingle (Path);
|
||||||
size_t p = pathStr.rfind ("s");
|
size_t p = pathStr.rfind ("s");
|
||||||
if (p == string::npos)
|
if (p == string::npos) {
|
||||||
throw PartitionDeviceRequired (SRC_POS);
|
p = pathStr.rfind ("p");
|
||||||
|
if (p == string::npos)
|
||||||
|
throw PartitionDeviceRequired (SRC_POS);
|
||||||
|
}
|
||||||
path = pathStr.substr (0, p);
|
path = pathStr.substr (0, p);
|
||||||
|
|
||||||
#elif defined (TC_SOLARIS)
|
#elif defined (TC_SOLARIS)
|
||||||
|
|||||||
Reference in New Issue
Block a user