2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// Filename : Info.cs
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Linux extended filesystem 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2022-12-03 16:07:10 +00:00
|
|
|
|
// Copyright © 2011-2023 Natalia Portillo
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// ****************************************************************************/
|
2014-04-17 19:58:14 +00:00
|
|
|
|
|
2012-08-03 01:45:38 +00:00
|
|
|
|
using System;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using System.Text;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Aaru.CommonTypes.AaruMetadata;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Partition = Aaru.CommonTypes.Partition;
|
2012-08-03 01:45:38 +00:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// Information from the Linux kernel
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements detection of the Linux extended filesystem</summary>
|
2022-11-15 15:58:43 +00:00
|
|
|
|
|
2022-03-15 01:37:37 +00:00
|
|
|
|
// ReSharper disable once InconsistentNaming
|
2022-12-07 13:07:31 +00:00
|
|
|
|
public sealed partial class extFS
|
2012-08-03 01:45:38 +00:00
|
|
|
|
{
|
2023-10-03 23:22:08 +01:00
|
|
|
|
#region IFilesystem Members
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
ulong sbSectorOff = SB_POS / imagePlugin.Info.SectorSize;
|
|
|
|
|
|
uint sbOff = SB_POS % imagePlugin.Info.SectorSize;
|
|
|
|
|
|
|
|
|
|
|
|
if(sbSectorOff + partition.Start >= partition.End)
|
|
|
|
|
|
return false;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(sbSectorOff + partition.Start, out byte[] sbSector);
|
2017-09-19 19:53:03 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2014-07-09 19:49:14 +01:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
var sb = new byte[512];
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sbOff + 512 > sbSector.Length)
|
|
|
|
|
|
return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Array.Copy(sbSector, sbOff, sb, 0, 512);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
var magic = BitConverter.ToUInt16(sb, 0x038);
|
2019-05-06 20:09:25 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return magic == EXT_MAGIC;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2022-12-17 22:41:56 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, Encoding encoding, out string information,
|
|
|
|
|
|
out FileSystem metadata)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
information = "";
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem();
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
|
|
if(imagePlugin.Info.SectorSize < 512)
|
|
|
|
|
|
return;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ulong sbSectorOff = SB_POS / imagePlugin.Info.SectorSize;
|
|
|
|
|
|
uint sbOff = SB_POS % imagePlugin.Info.SectorSize;
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sbSectorOff + partition.Start >= partition.End)
|
|
|
|
|
|
return;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSector(sbSectorOff + partition.Start, out byte[] sblock);
|
|
|
|
|
|
|
|
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-10-03 23:22:08 +01:00
|
|
|
|
var sbSector = new byte[512];
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Array.Copy(sblock, sbOff, sbSector, 0, 512);
|
|
|
|
|
|
|
|
|
|
|
|
var extSb = new SuperBlock
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
inodes = BitConverter.ToUInt32(sbSector, 0x000),
|
|
|
|
|
|
zones = BitConverter.ToUInt32(sbSector, 0x004),
|
|
|
|
|
|
firstfreeblk = BitConverter.ToUInt32(sbSector, 0x008),
|
|
|
|
|
|
freecountblk = BitConverter.ToUInt32(sbSector, 0x00C),
|
|
|
|
|
|
firstfreeind = BitConverter.ToUInt32(sbSector, 0x010),
|
|
|
|
|
|
freecountind = BitConverter.ToUInt32(sbSector, 0x014),
|
|
|
|
|
|
firstdatazone = BitConverter.ToUInt32(sbSector, 0x018),
|
|
|
|
|
|
logzonesize = BitConverter.ToUInt32(sbSector, 0x01C),
|
|
|
|
|
|
maxsize = BitConverter.ToUInt32(sbSector, 0x020)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.ext_filesystem);
|
2023-10-03 23:22:08 +01:00
|
|
|
|
sb.AppendFormat(Localization._0_zones_in_volume, extSb.zones);
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_free_blocks_1_bytes, extSb.freecountblk, extSb.freecountblk * 1024);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2023-10-01 04:00:02 +01:00
|
|
|
|
sb.AppendFormat(Localization._0_inodes_in_volume_1_free_2, extSb.inodes, extSb.freecountind,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
extSb.freecountind * 100 / extSb.inodes);
|
|
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.First_free_inode_is_0, extSb.firstfreeind);
|
|
|
|
|
|
sb.AppendFormat(Localization.First_free_block_is_0, extSb.firstfreeblk);
|
2023-10-03 23:22:08 +01:00
|
|
|
|
sb.AppendFormat(Localization.First_data_zone_is_0, extSb.firstdatazone);
|
|
|
|
|
|
sb.AppendFormat(Localization.Log_zone_size_0, extSb.logzonesize);
|
|
|
|
|
|
sb.AppendFormat(Localization.Max_zone_size_0, extSb.maxsize);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
2022-12-17 22:41:56 +00:00
|
|
|
|
metadata = new FileSystem
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2022-12-15 22:21:07 +00:00
|
|
|
|
Type = FS_TYPE,
|
|
|
|
|
|
FreeClusters = extSb.freecountblk,
|
|
|
|
|
|
ClusterSize = 1024,
|
|
|
|
|
|
Clusters = (partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / 1024
|
2022-03-06 13:29:38 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
}
|
2023-10-03 23:22:08 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|