// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : Structs.cs // Author(s) : Natalia Portillo // // Component : Common structures. // // --[ Description ] ---------------------------------------------------------- // // Contains enumerations and structures of common usage by filesystem // plugins. // // --[ 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-2022 Natalia Portillo // ****************************************************************************/ using System; using System.Runtime.InteropServices; using Newtonsoft.Json; namespace Aaru.CommonTypes.Structs { /// File attributes. [Flags] public enum FileAttributes : ulong { /// File has no attributes None = 0, /// File is an alias (Mac OS) Alias = 0x01, /// Indicates that the file can only be writable appended AppendOnly = 0x02, /// File is candidate for archival/backup Archive = 0x04, /// File is a block device BlockDevice = 0x08, /// File is stored on filesystem block units instead of device sectors BlockUnits = 0x10, /// Directory is a bundle or file contains a BNDL resource Bundle = 0x20, /// File is a char device CharDevice = 0x40, /// File is compressed Compressed = 0x80, /// File is compressed and should not be uncompressed on read CompressedRaw = 0x100, /// File has compression errors CompressionError = 0x200, /// Compressed file is dirty CompressionDirty = 0x400, /// File is a device Device = 0x800, /// File is a directory Directory = 0x1000, /// File is encrypted Encrypted = 0x2000, /// File is stored on disk using extents Extents = 0x4000, /// File is a FIFO FIFO = 0x8000, /// File is a normal file File = 0x10000, /// File is a Mac OS file containing desktop databases that has already been added to the desktop database HasBeenInited = 0x20000, /// File contains an icon resource / EA HasCustomIcon = 0x40000, /// File is a Mac OS extension or control panel lacking INIT resources HasNoINITs = 0x80000, /// File is hidden/invisible Hidden = 0x100000, /// File cannot be written, deleted, modified or linked to Immutable = 0x200000, /// Directory is indexed using hashed trees IndexedDirectory = 0x400000, /// File contents are stored alongside its inode (or equivalent) Inline = 0x800000, /// File contains integrity checks IntegrityStream = 0x1000000, /// File is on desktop IsOnDesk = 0x2000000, /// File changes are written to filesystem journal before being written to file itself Journaled = 0x4000000, /// Access time will not be modified NoAccessTime = 0x8000000, /// File will not be subject to copy-on-write NoCopyOnWrite = 0x10000000, /// File will not be backed up NoDump = 0x20000000, /// File contents should not be scrubbed NoScrub = 0x40000000, /// File contents should not be indexed NotIndexed = 0x80000000, /// File is offline Offline = 0x100000000, /// File is password protected, but contents are not encrypted on disk Password = 0x200000000, /// File is read-only ReadOnly = 0x400000000, /// File is a reparse point ReparsePoint = 0x800000000, /// When file is removed its content will be overwritten with zeroes Secured = 0x1000000000, /// File contents are sparse Sparse = 0x2000000000, /// File is a shadow (OS/2) Shadow = 0x4000000000, /// File is shared Shared = 0x8000000000, /// File is a stationery Stationery = 0x10000000000, /// File is a symbolic link Symlink = 0x20000000000, /// File writes are synchronously written to disk Sync = 0x40000000000, /// File belongs to the operating system System = 0x80000000000, /// If file end is a partial block its content will be merged with other files TailMerged = 0x100000000000, /// File is temporary Temporary = 0x200000000000, /// Subdirectories inside of this directory are not related and should be allocated elsewhere TopDirectory = 0x400000000000, /// If file is deleted, contents should be stored, for a possible future undeletion Undeletable = 0x800000000000, /// File is a pipe Pipe = 0x1000000000000, /// File is a socket Socket = 0x2000000000000 } /// Information about a file entry public class FileEntryInfo { /// File attributes public FileAttributes Attributes { get; set; } /// File length in blocks public long Blocks { get; set; } /// File block size in bytes public long BlockSize { get; set; } /// If file points to a device, device number. Null if the underlying filesystem does not support them. public ulong? DeviceNo { get; set; } /// POSIX group ID. Null if the underlying filesystem does not support them. public ulong? GID { get; set; } /// inode number for this file (or other unique identifier for the volume) public ulong Inode { get; set; } /// File length in bytes public long Length { get; set; } /// Number of hard links pointing to this file (. and .. entries count as hard links) public ulong Links { get; set; } /// POSIX permissions/mode for this file. Null if the underlying filesystem does not support them. public uint? Mode { get; set; } /// POSIX owner ID. Null if the underlying filesystem does not support them. public ulong? UID { get; set; } /// File creation date in UTC. Null if the underlying filesystem does not support them. public DateTime? CreationTimeUtc { get; set; } /// File last access date in UTC. Null if the underlying filesystem does not support them. public DateTime? AccessTimeUtc { get; set; } /// File attributes change date in UTC. Null if the underlying filesystem does not support them. public DateTime? StatusChangeTimeUtc { get; set; } /// File last backup date in UTC. Null if the underlying filesystem does not support them. public DateTime? BackupTimeUtc { get; set; } /// File last modification date in UTC. Null if the underlying filesystem does not support them. public DateTime? LastWriteTimeUtc { get; set; } /// File creation date. Null if the underlying filesystem does not support them. [JsonIgnore] public DateTime? CreationTime { get => CreationTimeUtc?.ToLocalTime(); set => CreationTimeUtc = value?.ToUniversalTime(); } /// File last access date. Null if the underlying filesystem does not support them. [JsonIgnore] public DateTime? AccessTime { get => AccessTimeUtc?.ToLocalTime(); set => AccessTimeUtc = value?.ToUniversalTime(); } /// File attributes change date. Null if the underlying filesystem does not support them. [JsonIgnore] public DateTime? StatusChangeTime { get => StatusChangeTimeUtc?.ToLocalTime(); set => StatusChangeTimeUtc = value?.ToUniversalTime(); } /// File last backup date. Null if the underlying filesystem does not support them. [JsonIgnore] public DateTime? BackupTime { get => BackupTimeUtc?.ToLocalTime(); set => BackupTimeUtc = value?.ToUniversalTime(); } /// File last modification date. Null if the underlying filesystem does not support them. [JsonIgnore] public DateTime? LastWriteTime { get => LastWriteTimeUtc?.ToLocalTime(); set => LastWriteTimeUtc = value?.ToUniversalTime(); } } /// Information about a volume public class FileSystemInfo { /// Blocks for this filesystem public ulong Blocks; /// Maximum length of filenames on this filesystem public ushort FilenameLength; /// Files on this filesystem public ulong Files; /// Blocks free on this filesystem public ulong FreeBlocks; /// Free inodes on this filesystem public ulong FreeFiles; /// Filesystem ID public FileSystemId Id; /// ID of plugin for this file public Guid PluginId; /// Filesystem type public string Type; /// Initializes an empty instance of this structure public FileSystemInfo() => Id = new FileSystemId(); /// Gets a clone of this structure /// Clone of this structure public FileSystemInfo ShallowCopy() => (FileSystemInfo)MemberwiseClone(); } /// Stores a filesystem volume unique identifier or serial number [StructLayout(LayoutKind.Explicit)] public struct FileSystemId { /// Set to true if the identifier is a 32-bit integer [FieldOffset(0)] public bool IsInt; /// Set to true if the identifier is a 64-bit integer [FieldOffset(1)] public bool IsLong; /// Set to true if the identifier is a GUID [FieldOffset(2)] public bool IsGuid; /// Identifier as a 32-bit integer [FieldOffset(3)] public uint Serial32; /// Identifier as a 64-bit integer [FieldOffset(3)] public ulong Serial64; /// Identifier as a GUID [FieldOffset(3)] public Guid uuid; } }