Implement GetVolumeInfo in winfsp.

This commit is contained in:
2020-09-03 00:14:11 +01:00
parent ab91dbe6cd
commit 9703a2210b
3 changed files with 33 additions and 6 deletions

View File

@@ -25,11 +25,12 @@ namespace RomRepoMgr.Core.Filesystem
readonly ConcurrentDictionary<long, ConcurrentDictionary<string, CachedMachine>> _machinesStatCache;
readonly ConcurrentDictionary<long, RomSet> _romSetsCache;
readonly ConcurrentDictionary<long, Stream> _streamsCache;
readonly Vfs _vfs;
long _lastHandle;
ConcurrentDictionary<string, long> _rootDirectoryCache;
string _umountToken;
public Fuse()
public Fuse(Vfs vfs)
{
_directoryCache = new ConcurrentDictionary<long, List<DirectoryEntry>>();
_lastHandle = 0;
@@ -40,6 +41,7 @@ namespace RomRepoMgr.Core.Filesystem
_streamsCache = new ConcurrentDictionary<long, Stream>();
_fileStatHandleCache = new ConcurrentDictionary<long, Stat>();
Name = "romrepombgrfs";
_vfs = vfs;
}
public static bool IsAvailable
@@ -457,15 +459,15 @@ namespace RomRepoMgr.Core.Filesystem
protected override Errno OnGetFileSystemStatus(string path, out Statvfs buf)
{
using var ctx = Context.Create(Settings.Settings.Current.DatabasePath);
_vfs.GetInfo(out ulong files, out ulong totalSize);
buf = new Statvfs
{
f_bsize = 512,
f_frsize = 512,
f_blocks = (ulong)(ctx.Files.Where(f => f.IsInRepo).Sum(f => (double)f.Size) / 512),
f_blocks = totalSize / 512,
f_bavail = 0,
f_files = (ulong)ctx.Files.Count(f => f.IsInRepo),
f_files = files,
f_ffree = 0,
f_favail = 0,
f_fsid = 0xFFFFFFFF,

View File

@@ -1,5 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using RomRepoMgr.Database;
namespace RomRepoMgr.Core.Filesystem
{
@@ -18,7 +20,7 @@ namespace RomRepoMgr.Core.Filesystem
{
if(Fuse.IsAvailable)
{
_fuse = new Fuse
_fuse = new Fuse(this)
{
MountPoint = mountPoint
};
@@ -32,7 +34,7 @@ namespace RomRepoMgr.Core.Filesystem
}
else if(Winfsp.IsAvailable)
{
_winfsp = new Winfsp();
_winfsp = new Winfsp(this);
bool ret = _winfsp.Mount(mountPoint);
if(ret)
@@ -54,5 +56,13 @@ namespace RomRepoMgr.Core.Filesystem
Umounted?.Invoke(this, System.EventArgs.Empty);
}
internal void GetInfo(out ulong files, out ulong totalSize)
{
using var ctx = Context.Create(Settings.Settings.Current.DatabasePath);
totalSize = (ulong)ctx.Files.Where(f => f.IsInRepo).Sum(f => (double)f.Size);
files = (ulong)ctx.Files.Count(f => f.IsInRepo);
}
}
}

View File

@@ -6,8 +6,11 @@ namespace RomRepoMgr.Core.Filesystem
{
public class Winfsp : FileSystemBase
{
readonly Vfs _vfs;
FileSystemHost _host;
public Winfsp(Vfs vfs) => _vfs = vfs;
public static bool IsAvailable
{
get
@@ -102,5 +105,17 @@ namespace RomRepoMgr.Core.Filesystem
public override int Rename(object fileNode, object fileDesc, string fileName, string newFileName,
bool replaceIfExists) => STATUS_MEDIA_WRITE_PROTECTED;
public override int GetVolumeInfo(out VolumeInfo volumeInfo)
{
volumeInfo = new VolumeInfo();
_vfs.GetInfo(out _, out ulong totalSize);
volumeInfo.FreeSize = 0;
volumeInfo.TotalSize = totalSize;
return base.GetVolumeInfo(out volumeInfo);
}
}
}