// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : IReadOnlyFilesystem.cs // Author(s) : Natalia Portillo // // Component : Filesystem plugins. // // --[ Description ] ---------------------------------------------------------- // // Interface for filesystem plugins that offer read-only support of their // contents. // // --[ License ] -------------------------------------------------------------- // // Permission is hereby granted, free of charge, to any person obtaining a // copy of this software and associated documentation files (the // "Software"), to deal in the Software without restriction, including // without limitation the rights to use, copy, modify, merge, publish, // distribute, sublicense, and/or sell copies of the Software, and to // permit persons to whom the Software is furnished to do so, subject to // the following conditions: // // The above copyright notice and this permission notice shall be included // in all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // // ---------------------------------------------------------------------------- // Copyright © 2011-2025 Natalia Portillo // ****************************************************************************/ using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Text; using Aaru.CommonTypes.AaruMetadata; using Aaru.CommonTypes.Enums; using Aaru.CommonTypes.Structs; using FileAttributes = Aaru.CommonTypes.Structs.FileAttributes; using FileSystemInfo = Aaru.CommonTypes.Structs.FileSystemInfo; namespace Aaru.CommonTypes.Interfaces; /// /// Defines the interface to implement reading the contents of a filesystem [SuppressMessage("ReSharper", "UnusedMember.Global")] [SuppressMessage("ReSharper", "UnusedMethodReturnValue.Global")] [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global")] public interface IReadOnlyFilesystem : IFilesystem { /// Information about the filesystem as expected by Aaru Metadata FileSystem Metadata { get; } /// Retrieves a list of options supported by the filesystem, with name, type and description IEnumerable<(string name, Type type, string description)> SupportedOptions { get; } /// Supported namespaces Dictionary Namespaces { get; } /// /// Initializes whatever internal structures the filesystem plugin needs to be able to read files and directories /// from the filesystem. /// /// The image plugin containing the filesystem. /// The partition containing the filesystem. /// Which encoding to use for this filesystem. /// Dictionary of key=value pairs containing options to pass to the filesystem /// Filename namespace ErrorNumber Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding, Dictionary options, string @namespace); /// Frees all internal structures created by ErrorNumber Unmount(); /// Gets the attributes of a file or directory /// Error number. /// File path. /// File attributes. ErrorNumber GetAttributes(string path, out FileAttributes attributes); /// Lists all extended attributes, alternate data streams and forks of the given file. /// Error number. /// Path. /// List of extended attributes, alternate data streams and forks. ErrorNumber ListXAttr(string path, out List xattrs); /// Reads an extended attribute, alternate data stream or fork from the given file. /// Error number. /// File path. /// Extended attribute, alternate data stream or fork name. /// Buffer. ErrorNumber GetXattr(string path, string xattr, ref byte[] buf); /// Gets information about the mounted volume. /// Information about the mounted volume. /// Error number. ErrorNumber StatFs(out FileSystemInfo stat); /// Gets information about a file or directory. /// File path. /// File information. /// Error number. ErrorNumber Stat(string path, out FileEntryInfo stat); /// Solves a symbolic link. /// Link path. /// Link destination. /// Error number. ErrorNumber ReadLink(string path, out string dest); /// Opens a file for reading. /// Path to the file. /// Represents the opened file and is needed for other file-related operations. /// Error number ErrorNumber OpenFile(string path, out IFileNode node); /// Closes a file, freeing any private data allocated on opening. /// The file node. /// Error number. ErrorNumber CloseFile(IFileNode node); /// Move the file node position pointer to the specified position with the specified origin /// The file node. /// Desired position. /// From where in the file to move the position pointer to. /// Error number. ErrorNumber Seek(IFileNode node, long position, SeekOrigin origin) { if(node is null) return ErrorNumber.InvalidArgument; long desiredPosition = origin switch { SeekOrigin.Begin => position, SeekOrigin.End => node.Length + position, _ => node.Offset + position }; if(desiredPosition < 0) return ErrorNumber.InvalidArgument; if(desiredPosition >= node.Length) return ErrorNumber.InvalidArgument; node.Offset = desiredPosition; return ErrorNumber.NoError; } /// Reads data from a file (main/only data stream or data fork). /// File node. /// Bytes to read. /// Buffer. Must exist and be of size equal or bigger than /// How many bytes were read into the buffer /// Error number. ErrorNumber ReadFile(IFileNode node, long length, byte[] buffer, out long read); /// Opens a directory for listing. /// Path to the directory. /// Represents the opened directory and is needed for other directory-related operations. /// Error number ErrorNumber OpenDir(string path, out IDirNode node); /// Closes a directory, freeing any private data allocated on opening. /// The directory node. /// Error number. ErrorNumber CloseDir(IDirNode node); /// Reads the next entry in the directory. /// Represent an opened directory. /// /// The next entry name. /// null /// if there are no more entries. /// /// Error number. ErrorNumber ReadDir(IDirNode node, out string filename); } /// Represents an opened file from a filesystem [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global")] public interface IFileNode { /// Path to the file string Path { get; } /// File length long Length { get; } /// Current position in file long Offset { get; set; } } /// Represents an opened directory from a filesystem [SuppressMessage("ReSharper", "UnusedMemberInSuper.Global")] public interface IDirNode { /// Path to the directory string Path { get; } }