diff --git a/RomRepoMgr.Core/Filesystem/Fuse.cs b/RomRepoMgr.Core/Filesystem/Fuse.cs index a0e3405..719bb4a 100644 --- a/RomRepoMgr.Core/Filesystem/Fuse.cs +++ b/RomRepoMgr.Core/Filesystem/Fuse.cs @@ -25,11 +25,12 @@ namespace RomRepoMgr.Core.Filesystem readonly ConcurrentDictionary> _machinesStatCache; readonly ConcurrentDictionary _romSetsCache; readonly ConcurrentDictionary _streamsCache; + readonly Vfs _vfs; long _lastHandle; ConcurrentDictionary _rootDirectoryCache; string _umountToken; - public Fuse() + public Fuse(Vfs vfs) { _directoryCache = new ConcurrentDictionary>(); _lastHandle = 0; @@ -40,6 +41,7 @@ namespace RomRepoMgr.Core.Filesystem _streamsCache = new ConcurrentDictionary(); _fileStatHandleCache = new ConcurrentDictionary(); 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, diff --git a/RomRepoMgr.Core/Filesystem/Vfs.cs b/RomRepoMgr.Core/Filesystem/Vfs.cs index b563739..75e060c 100644 --- a/RomRepoMgr.Core/Filesystem/Vfs.cs +++ b/RomRepoMgr.Core/Filesystem/Vfs.cs @@ -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); + } } } \ No newline at end of file diff --git a/RomRepoMgr.Core/Filesystem/Winfsp.cs b/RomRepoMgr.Core/Filesystem/Winfsp.cs index fafbadb..552b565 100644 --- a/RomRepoMgr.Core/Filesystem/Winfsp.cs +++ b/RomRepoMgr.Core/Filesystem/Winfsp.cs @@ -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); + } } } \ No newline at end of file