mirror of
https://github.com/veracrypt/VeraCrypt.git
synced 2026-05-22 12:31:31 +00:00
macOS: stabilize FUSE-T SMB mount metadata
Make /aux-device-info readable for SMB, verify that FUSE records hdiutil device info after mount and recover missing virtual devices from hdiutil before dismounting auxiliary mounts.
This commit is contained in:
committed by
Mounir IDRASSI
parent
4271b8e6f5
commit
deb7f55bfb
@@ -75,6 +75,14 @@ namespace VeraCrypt
|
||||
statData->st_blocks = fuse_service_ceil_div ((uint64) statData->st_size, VC_FUSE_STAT_BLOCK_SIZE);
|
||||
}
|
||||
|
||||
static shared_ptr <Buffer> fuse_service_get_control_info (struct fuse_file_info *fi)
|
||||
{
|
||||
if (fi && fi->fh)
|
||||
return *reinterpret_cast <shared_ptr <Buffer> *> (fi->fh);
|
||||
|
||||
return FuseService::GetVolumeInfo();
|
||||
}
|
||||
|
||||
static int fuse_service_fill_dir_entry (void *buf, fuse_fill_dir_t filler, const char *name, mode_t mode, ino_t ino, off_t nextOff)
|
||||
{
|
||||
struct stat st;
|
||||
@@ -200,7 +208,7 @@ namespace VeraCrypt
|
||||
|
||||
if (strcmp (path, FuseService::GetAuxDeviceInfoPath()) == 0)
|
||||
{
|
||||
statData->st_mode = S_IFREG | 0200;
|
||||
statData->st_mode = S_IFREG | 0600;
|
||||
statData->st_nlink = 1;
|
||||
statData->st_size = VC_FUSE_BLOCK_SIZE;
|
||||
statData->st_ino = VC_FUSE_INODE_AUX_DEVICE_INFO;
|
||||
@@ -218,7 +226,7 @@ namespace VeraCrypt
|
||||
{
|
||||
statData->st_mode = S_IFREG | 0600;
|
||||
statData->st_nlink = 1;
|
||||
statData->st_size = FuseService::GetVolumeInfo()->Size();
|
||||
statData->st_size = VC_FUSE_BLOCK_SIZE;
|
||||
statData->st_ino = VC_FUSE_INODE_CONTROL;
|
||||
fuse_service_set_stat_blocks (statData);
|
||||
}
|
||||
@@ -314,6 +322,7 @@ namespace VeraCrypt
|
||||
|
||||
if (strcmp (path, FuseService::GetControlPath()) == 0)
|
||||
{
|
||||
fi->fh = reinterpret_cast <uint64> (new shared_ptr <Buffer> (FuseService::GetVolumeInfo()));
|
||||
fi->direct_io = 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -372,7 +381,22 @@ namespace VeraCrypt
|
||||
|
||||
if (strcmp (path, FuseService::GetControlPath()) == 0)
|
||||
{
|
||||
shared_ptr <Buffer> infoBuf = FuseService::GetVolumeInfo();
|
||||
shared_ptr <Buffer> infoBuf = fuse_service_get_control_info (fi);
|
||||
BufferPtr outBuf ((uint8 *)buf, size);
|
||||
|
||||
if (offset >= (off_t) infoBuf->Size())
|
||||
return 0;
|
||||
|
||||
if (offset + size > infoBuf->Size())
|
||||
size = infoBuf->Size () - offset;
|
||||
|
||||
outBuf.CopyFrom (infoBuf->GetRange (offset, size));
|
||||
return size;
|
||||
}
|
||||
|
||||
if (strcmp (path, FuseService::GetAuxDeviceInfoPath()) == 0)
|
||||
{
|
||||
shared_ptr <Buffer> infoBuf = FuseService::GetAuxDeviceInfo();
|
||||
BufferPtr outBuf ((uint8 *)buf, size);
|
||||
|
||||
if (offset >= (off_t) infoBuf->Size())
|
||||
@@ -393,6 +417,24 @@ namespace VeraCrypt
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static int fuse_service_release (const char *path, struct fuse_file_info *fi)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (strcmp (path, FuseService::GetControlPath()) == 0 && fi && fi->fh)
|
||||
{
|
||||
delete reinterpret_cast <shared_ptr <Buffer> *> (fi->fh);
|
||||
fi->fh = 0;
|
||||
}
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
return FuseService::ExceptionToErrorCode();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int fuse_service_readdir_impl (const char *path, void *buf, fuse_fill_dir_t filler, struct fuse_file_info *fi)
|
||||
{
|
||||
(void) fi;
|
||||
@@ -413,7 +455,7 @@ namespace VeraCrypt
|
||||
return 0;
|
||||
if (fuse_service_fill_dir_entry (buf, filler, FuseService::GetControlPath() + 1, S_IFREG | 0600, VC_FUSE_INODE_CONTROL, 0) != 0)
|
||||
return 0;
|
||||
if (fuse_service_fill_dir_entry (buf, filler, FuseService::GetAuxDeviceInfoPath() + 1, S_IFREG | 0200, VC_FUSE_INODE_AUX_DEVICE_INFO, 0) != 0)
|
||||
if (fuse_service_fill_dir_entry (buf, filler, FuseService::GetAuxDeviceInfoPath() + 1, S_IFREG | 0600, VC_FUSE_INODE_AUX_DEVICE_INFO, 0) != 0)
|
||||
return 0;
|
||||
}
|
||||
catch (...)
|
||||
@@ -548,6 +590,25 @@ namespace VeraCrypt
|
||||
}
|
||||
}
|
||||
|
||||
shared_ptr <Buffer> FuseService::GetAuxDeviceInfo ()
|
||||
{
|
||||
shared_ptr <Stream> stream (new MemoryStream);
|
||||
Serializer sr (stream);
|
||||
|
||||
{
|
||||
ScopeLock lock (OpenVolumeInfoMutex);
|
||||
|
||||
sr.Serialize ("VirtualDevice", string (OpenVolumeInfo.VirtualDevice));
|
||||
sr.Serialize ("LoopDevice", string (OpenVolumeInfo.LoopDevice));
|
||||
}
|
||||
|
||||
ConstBufferPtr infoBuf = dynamic_cast <MemoryStream&> (*stream);
|
||||
shared_ptr <Buffer> outBuf (new Buffer (infoBuf.Size()));
|
||||
outBuf->CopyFrom (infoBuf);
|
||||
|
||||
return outBuf;
|
||||
}
|
||||
|
||||
shared_ptr <Buffer> FuseService::GetVolumeInfo ()
|
||||
{
|
||||
shared_ptr <Stream> stream (new MemoryStream);
|
||||
@@ -666,6 +727,7 @@ namespace VeraCrypt
|
||||
sr.Serialize ("VirtualDevice", string (virtualDevice));
|
||||
sr.Serialize ("LoopDevice", string (loopDevice));
|
||||
fuseServiceControl.Write (dynamic_cast <MemoryStream&> (*stream));
|
||||
fuseServiceControl.Close();
|
||||
}
|
||||
|
||||
void FuseService::WriteVolumeSectors (const ConstBufferPtr &buffer, uint64 byteOffset)
|
||||
@@ -728,6 +790,7 @@ namespace VeraCrypt
|
||||
fuse_service_oper.opendir = fuse_service_opendir;
|
||||
fuse_service_oper.read = fuse_service_read;
|
||||
fuse_service_oper.readdir = fuse_service_readdir;
|
||||
fuse_service_oper.release = fuse_service_release;
|
||||
fuse_service_oper.statfs = fuse_service_statfs;
|
||||
fuse_service_oper.write = fuse_service_write;
|
||||
|
||||
|
||||
@@ -51,6 +51,7 @@ namespace VeraCrypt
|
||||
static string GetDeviceType () { return "veracrypt"; }
|
||||
static gid_t GetGroupId () { return GroupId; }
|
||||
static uid_t GetUserId () { return UserId; }
|
||||
static shared_ptr <Buffer> GetAuxDeviceInfo ();
|
||||
static shared_ptr <Buffer> GetVolumeInfo ();
|
||||
static uint64 GetVolumeSize ();
|
||||
static uint64 GetVolumeSectorSize () { return MountedVolume->GetSectorSize(); }
|
||||
|
||||
Reference in New Issue
Block a user