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