Files
Aaru/Aaru.Filesystems/FFS/Structs.cs

306 lines
13 KiB
C#
Raw Normal View History

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