// /*************************************************************************** // 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 ] -------------------------------------------------------------- // // This library is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as // published by the Free Software Foundation; either version 2.1 of the // License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, see . // // ---------------------------------------------------------------------------- // Copyright © 2011-2018 Natalia Portillo // ****************************************************************************/ using System; using System.Runtime.InteropServices; namespace DiscImageChef.Filesystems { /// /// File attributes. /// [Flags] public enum FileAttributes : ulong { /// 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 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 { return CreationTimeUtc.ToLocalTime(); } set { CreationTimeUtc = value.ToUniversalTime(); } } /// File last access date public DateTime AccessTime { get { return AccessTimeUtc.ToLocalTime(); } set { AccessTimeUtc = value.ToUniversalTime(); } } /// File attributes change date public DateTime StatusChangeTime { get { return StatusChangeTimeUtc.ToLocalTime(); } set { StatusChangeTimeUtc = value.ToUniversalTime(); } } /// File last backup date public DateTime BackupTime { get { return BackupTimeUtc.ToLocalTime(); } set { BackupTimeUtc = value.ToUniversalTime(); } } /// File last modification date public DateTime LastWriteTime { get { return LastWriteTimeUtc.ToLocalTime(); } set { LastWriteTimeUtc = value.ToUniversalTime(); } } /// inode number for this file public ulong Inode; /// POSIX permissions/mode for this file public uint Mode; /// Number of hard links pointing to this file public ulong Links; /// POSIX owner ID public ulong UID; /// POSIX group ID public ulong GID; /// If file points to a device, device number public ulong DeviceNo; /// File length in bytes public long Length; /// File block size in bytes public long BlockSize; /// File length in blocks public long Blocks; } public class FileSystemInfo { public FileSystemInfo() { Id = new FileSystemId(); } /// Filesystem type public string Type; /// ID of plugin for this file public Guid PluginId; /// Blocks for this filesystem public long Blocks; /// Blocks free on this filesystem public long FreeBlocks; /// Files on this filesystem public ulong Files; /// Free inodes on this filesystem public ulong FreeFiles; /// Maximum length of filenames on this filesystem public ushort FilenameLength; /// Filesystem ID public FileSystemId Id; } [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 } }