// /*************************************************************************** // Aaru Data Preservation Suite // ---------------------------------------------------------------------------- // // Filename : Structs.cs // Author(s) : Natalia Portillo // // Component : BSD Fast File System plugin. // // --[ 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-2024 Natalia Portillo // ****************************************************************************/ using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; namespace Aaru.Filesystems; // Using information from Linux kernel headers /// /// Implements detection of BSD Fast File System (FFS, aka UNIX File System) [SuppressMessage("ReSharper", "InconsistentNaming")] public sealed partial class FFSPlugin { #region Nested type: Checksum [StructLayout(LayoutKind.Sequential, Pack = 1)] struct Checksum { /// number of directories public int cs_ndir; /// number of free blocks public int cs_nbfree; /// number of free inodes public int cs_nifree; /// number of free frags public int cs_nffree; } #endregion #region Nested type: csum_total [StructLayout(LayoutKind.Sequential, Pack = 1)] struct csum_total { /// number of directories public long cs_ndir; /// number of free blocks public long cs_nbfree; /// number of free inodes public long cs_nifree; /// number of free frags public long cs_nffree; /// number of free clusters public long cs_numclusters; /// future expansion [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public readonly long[] cs_spare; } #endregion #region Nested type: SuperBlock [StructLayout(LayoutKind.Sequential, Pack = 1)] struct SuperBlock { /// linked list of file systems public readonly uint fs_link; /// used for incore super blocks on Sun: uint fs_rolled; // logging only: fs fully rolled public readonly uint fs_rlink; /// addr of super-block in filesys public readonly int fs_sblkno; /// offset of cyl-block in filesys public readonly int fs_cblkno; /// offset of inode-blocks in filesys public readonly int fs_iblkno; /// offset of first data after cg public readonly int fs_dblkno; /// cylinder group offset in cylinder public readonly int fs_old_cgoffset; /// used to calc mod fs_ntrak public readonly int fs_old_cgmask; /// last time written public readonly int fs_old_time; /// number of blocks in fs public readonly int fs_old_size; /// number of data blocks in fs public readonly int fs_old_dsize; /// number of cylinder groups public readonly int fs_ncg; /// size of basic blocks in fs public readonly int fs_bsize; /// size of frag blocks in fs public readonly int fs_fsize; /// number of frags in a block in fs public readonly int fs_frag; /* these are configuration parameters */ /// minimum percentage of free blocks public readonly int fs_minfree; /// num of ms for optimal next block public readonly int fs_old_rotdelay; /// disk revolutions per second public readonly int fs_old_rps; /* these fields can be computed from the others */ /// ``blkoff'' calc of blk offsets public readonly int fs_bmask; /// ``fragoff'' calc of frag offsets public readonly int fs_fmask; /// ``lblkno'' calc of logical blkno public readonly int fs_bshift; /// ``numfrags'' calc number of frags public readonly int fs_fshift; /* these are configuration parameters */ /// max number of contiguous blks public readonly int fs_maxcontig; /// max number of blks per cyl group public readonly int fs_maxbpg; /* these fields can be computed from the others */ /// block to frag shift public readonly int fs_fragshift; /// fsbtodb and dbtofsb shift constant public readonly int fs_fsbtodb; /// actual size of super block public readonly int fs_sbsize; /// csum block offset public readonly int fs_csmask; /// csum block number public readonly int fs_csshift; /// value of NINDIR public readonly int fs_nindir; /// value of INOPB public readonly uint fs_inopb; /// value of NSPF public readonly int fs_old_nspf; /* yet another configuration parameter */ /// optimization preference, see below On SVR: int fs_state; // file system state public readonly int fs_optim; /// # sectors/track including spares public readonly int fs_old_npsect; /// hardware sector interleave public readonly int fs_old_interleave; /// sector 0 skew, per track On A/UX: int fs_state; // file system state public readonly int fs_old_trackskew; /// unique filesystem id On old: int fs_headswitch; // head switch time, usec public readonly int fs_id_1; /// unique filesystem id On old: int fs_trkseek; // track-to-track seek, usec public readonly int fs_id_2; /* sizes determined by number of cylinder groups and their sizes */ /// blk addr of cyl grp summary area public readonly int fs_old_csaddr; /// size of cyl grp summary area public readonly int fs_cssize; /// cylinder group size public readonly int fs_cgsize; /* these fields are derived from the hardware */ /// tracks per cylinder public readonly int fs_old_ntrak; /// sectors per track public readonly int fs_old_nsect; /// sectors per cylinder public readonly int fs_old_spc; /* this comes from the disk driver partitioning */ /// cylinders in filesystem public readonly int fs_old_ncyl; /* these fields can be computed from the others */ /// cylinders per group public readonly int fs_old_cpg; /// inodes per group public readonly int fs_ipg; /// blocks per group * fs_frag public readonly int fs_fpg; /* this data must be re-computed after crashes */ /// cylinder summary information public Checksum fs_old_cstotal; /* these fields are cleared at mount time */ /// super block modified flag public readonly sbyte fs_fmod; /// filesystem is clean flag public readonly sbyte fs_clean; /// mounted read-only flag public readonly sbyte fs_ronly; /// old FS_ flags public readonly sbyte fs_old_flags; /// name mounted on [MarshalAs(UnmanagedType.ByValArray, SizeConst = 468)] public readonly byte[] fs_fsmnt; /// volume name [MarshalAs(UnmanagedType.ByValArray, SizeConst = 32)] public readonly byte[] fs_volname; /// system-wide uid public readonly ulong fs_swuid; /// due to alignment of fs_swuid public readonly int fs_pad; /* these fields retain the current block allocation info */ /// last cg searched public readonly int fs_cgrotor; /// padding; was list of fs_cs buffers [MarshalAs(UnmanagedType.ByValArray, SizeConst = 28)] public readonly uint[] fs_ocsp; /// (u) # of contig. allocated dirs public readonly uint fs_contigdirs; /// (u) cg summary info buffer public readonly uint fs_csp; /// (u) max cluster in each cyl group public readonly uint fs_maxcluster; /// (u) used by snapshots to track fs public readonly uint fs_active; /// cyl per cycle in postbl public readonly int fs_old_cpc; /// maximum blocking factor permitted public readonly int fs_maxbsize; /// number of unreferenced inodes public readonly long fs_unrefs; /// size of underlying GEOM provider public readonly long fs_providersize; /// size of area reserved for metadata public readonly long fs_metaspace; /// old rotation block list head [MarshalAs(UnmanagedType.ByValArray, SizeConst = 14)] public readonly long[] fs_sparecon64; /// byte offset of standard superblock public readonly long fs_sblockloc; /// (u) cylinder summary information public csum_total fs_cstotal; /// last time written public readonly long fs_time; /// number of blocks in fs public readonly long fs_size; /// number of data blocks in fs public readonly long fs_dsize; /// blk addr of cyl grp summary area public readonly long fs_csaddr; /// (u) blocks being freed public readonly long fs_pendingblocks; /// (u) inodes being freed public readonly uint fs_pendinginodes; /// list of snapshot inode numbers [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)] public readonly uint[] fs_snapinum; /// expected average file size public readonly uint fs_avgfilesize; /// expected # of files per directory public readonly uint fs_avgfpdir; /// save real cg size to use fs_bsize public readonly int fs_save_cgsize; /// Last mount or fsck time. public readonly long fs_mtime; /// SUJ free list public readonly int fs_sujfree; /// reserved for future constants [MarshalAs(UnmanagedType.ByValArray, SizeConst = 23)] public readonly int[] fs_sparecon32; /// see FS_ flags below public readonly int fs_flags; /// size of cluster summary array public readonly int fs_contigsumsize; /// max length of an internal symlink public readonly int fs_maxsymlinklen; /// format of on-disk inodes public readonly int fs_old_inodefmt; /// maximum representable file size public readonly ulong fs_maxfilesize; /// ~fs_bmask for use with 64-bit size public readonly long fs_qbmask; /// ~fs_fmask for use with 64-bit size public readonly long fs_qfmask; /// validate fs_clean field public readonly int fs_state; /// format of positional layout tables public readonly int fs_old_postblformat; /// number of rotational positions public readonly int fs_old_nrpos; /// (short) rotation block list head public readonly int fs_old_postbloff; /// (uchar_t) blocks for each rotation public readonly int fs_old_rotbloff; /// magic number public readonly uint fs_magic; /// list of blocks for each rotation [MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)] public readonly byte[] fs_rotbl; } #endregion }