diff --git a/src/Zio/FileSystems/MountFileSystem.cs b/src/Zio/FileSystems/MountFileSystem.cs index e3c3222..93fead1 100644 --- a/src/Zio/FileSystems/MountFileSystem.cs +++ b/src/Zio/FileSystems/MountFileSystem.cs @@ -184,6 +184,64 @@ public IFileSystem Unmount(UPath name) return mountFileSystem; } + /// + /// Attempts to find information about the mount that a given path maps to. + /// + /// The path to search for. + /// The mount name that the belongs to. + /// The mounted filesystem that the is located in. + /// The path inside of that refers to the file at . + /// True if the was found in a mounted filesystem. + /// The must not be null. + /// The must be absolute. + public bool TryGetMount(UPath path, out UPath name, out IFileSystem fileSystem, out UPath fileSystemPath) + { + path.AssertNotNull(); + path.AssertAbsolute(); + + var fs = TryGetMountOrNext(ref path, out name); + + if (fs == null || name.IsNull) + { + name = null; + fileSystem = null; + fileSystemPath = null; + return false; + } + + fileSystem = fs; + fileSystemPath = path; + return true; + } + + /// + /// Attempts to find the mount name that a filesystem has been mounted to + /// + /// The mounted filesystem to search for. + /// The mount name that the is mounted with. + /// True if the is mounted. + /// The must not be null. + public bool TryGetMountName(IFileSystem fileSystem, out UPath name) + { + if (fileSystem == null) + throw new ArgumentNullException(nameof(fileSystem)); + + lock (_mounts) + { + foreach (var mount in _mounts) + { + if (mount.Value != fileSystem) + continue; + + name = mount.Key; + return true; + } + } + + name = null; + return false; + } + /// protected override void CreateDirectoryImpl(UPath path) {