// /*************************************************************************** // The Disc Image Chef // ---------------------------------------------------------------------------- // // Filename : Structs.cs // Author(s) : Natalia Portillo // // Component : DiscImageChef filesystem plugins. // // --[ 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-2019 Natalia Portillo // ****************************************************************************/ using System; using System.Runtime.InteropServices; namespace DiscImageChef.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 } /// /// Information about a file entry /// public class FileEntryInfo { /// File attributes public FileAttributes Attributes; /// File length in blocks public long Blocks; /// File block size in bytes public long BlockSize; /// If file points to a device, device number public ulong DeviceNo; /// POSIX group ID public ulong GID; /// inode number for this file public ulong Inode; /// File length in bytes public long Length; /// Number of hard links pointing to this file public ulong Links; /// POSIX permissions/mode for this file public uint Mode; /// POSIX owner ID public ulong UID; /// File creation date in UTC public DateTime CreationTimeUtc { get; set; } /// File last access date in UTC public DateTime AccessTimeUtc { get; set; } /// File attributes change date in UTC public DateTime StatusChangeTimeUtc { get; set; } /// File last backup date in UTC public DateTime BackupTimeUtc { get; set; } /// File last modification date in UTC public DateTime LastWriteTimeUtc { get; set; } /// File creation date public DateTime CreationTime { get => CreationTimeUtc.ToLocalTime(); set => CreationTimeUtc = value.ToUniversalTime(); } /// File last access date public DateTime AccessTime { get => AccessTimeUtc.ToLocalTime(); set => AccessTimeUtc = value.ToUniversalTime(); } /// File attributes change date public DateTime StatusChangeTime { get => StatusChangeTimeUtc.ToLocalTime(); set => StatusChangeTimeUtc = value.ToUniversalTime(); } /// File last backup date public DateTime BackupTime { get => BackupTimeUtc.ToLocalTime(); set => BackupTimeUtc = value.ToUniversalTime(); } /// File last modification date public DateTime LastWriteTime { get => LastWriteTimeUtc.ToLocalTime(); set => LastWriteTimeUtc = value.ToUniversalTime(); } } public class FileSystemInfo { /// Blocks for this filesystem public long Blocks; /// Maximum length of filenames on this filesystem public ushort FilenameLength; /// Files on this filesystem public ulong Files; /// Blocks free on this filesystem public long 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; public FileSystemInfo() { Id = new FileSystemId(); } } [StructLayout(LayoutKind.Explicit)] public struct FileSystemId { [FieldOffset(0)] public bool IsInt; [FieldOffset(1)] public bool IsLong; [FieldOffset(2)] public bool IsGuid; [FieldOffset(3)] public uint Serial32; [FieldOffset(3)] public ulong Serial64; [FieldOffset(3)] public Guid uuid; } /// /// Errors /// public enum Errno { /// No error happened NoError = 0, /// Access denied AccessDenied = -13, /// Busy, cannot complete Busy = -16, /// File is too large FileTooLarge = -27, /// Invalid argument InvalidArgument = -22, /// I/O error InOutError = -5, /// Is a directory (e.g.: trying to Read() a dir) IsDirectory = -21, /// Name is too long NameTooLong = -36, /// There is no data available NoData = 61, /// There is no such attribute NoSuchExtendedAttribute = NoData, /// No such device NoSuchDevice = -19, /// No such file or directory NoSuchFile = -2, /// Is not a directory (e.g.: trying to ReadDir() a file) NotDirectory = -20, /// Not implemented NotImplemented = -38, /// Not supported NotSupported = -252, /// Link is severed SeveredLink = -67, /// Access denied EACCES = AccessDenied, /// Busy, cannot complete EBUSY = Busy, /// File is too large EFBIG = FileTooLarge, /// Invalid argument EINVAL = InvalidArgument, /// I/O error EIO = InOutError, /// Is a directory (e.g.: trying to Read() a dir) EISDIR = IsDirectory, /// Name is too long ENAMETOOLONG = NameTooLong, /// There is no such attribute ENOATTR = NoSuchExtendedAttribute, /// There is no data available ENODATA = NoData, /// No such device ENODEV = NoSuchDevice, /// No such file or directory ENOENT = NoSuchFile, /// Link is severed ENOLINK = SeveredLink, /// Not implemented ENOSYS = NotImplemented, /// Is not a directory (e.g.: trying to ReadDir() a file) ENOTDIR = NotDirectory, /// Not supported ENOTSUP = NotSupported } }