2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2016-09-02 18:10:54 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
2022-12-07 13:07:31 +00:00
|
|
|
|
// Filename : Info.cs
|
2016-09-02 18:10:54 +01:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : F2FS filesystem plugin.
|
2016-09-02 18:10:54 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ 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-09-02 18:10:54 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2016-09-02 18:10:54 +01:00
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
using Aaru.CommonTypes.Enums;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Interfaces;
|
2020-07-20 15:43:52 +01:00
|
|
|
|
using Aaru.Helpers;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using Schemas;
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.Filesystems;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
/// <summary>Implements detection of the Flash-Friendly File System (F2FS)</summary>
|
|
|
|
|
|
[SuppressMessage("ReSharper", "UnusedMember.Local")]
|
2022-12-07 13:07:31 +00:00
|
|
|
|
public sealed partial class F2FS
|
2016-09-02 18:10:54 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
|
|
|
|
|
{
|
2022-03-16 11:47:00 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize is < F2FS_MIN_SECTOR or > F2FS_MAX_SECTOR)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
uint sbAddr = F2FS_SUPER_OFFSET / imagePlugin.Info.SectorSize;
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sbAddr == 0)
|
|
|
|
|
|
sbAddr = 1;
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0)
|
|
|
|
|
|
sbSize++;
|
2017-07-23 19:58:11 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(partition.Start + sbAddr + sbSize >= partition.End)
|
|
|
|
|
|
return false;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize, out byte[] sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return false;
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sector.Length < Marshal.SizeOf<Superblock>())
|
|
|
|
|
|
return false;
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Superblock sb = Marshal.ByteArrayToStructureLittleEndian<Superblock>(sector);
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return sb.magic == F2FS_MAGIC;
|
|
|
|
|
|
}
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-03-07 07:36:44 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information, Encoding encoding)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
{
|
|
|
|
|
|
Encoding = Encoding.Unicode;
|
|
|
|
|
|
information = "";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-16 11:47:00 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize is < F2FS_MIN_SECTOR or > F2FS_MAX_SECTOR)
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
uint sbAddr = F2FS_SUPER_OFFSET / imagePlugin.Info.SectorSize;
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sbAddr == 0)
|
|
|
|
|
|
sbAddr = 1;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
uint sbSize = (uint)(Marshal.SizeOf<Superblock>() / imagePlugin.Info.SectorSize);
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(Marshal.SizeOf<Superblock>() % imagePlugin.Info.SectorSize != 0)
|
|
|
|
|
|
sbSize++;
|
2021-09-19 21:16:47 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorNumber errno = imagePlugin.ReadSectors(partition.Start + sbAddr, sbSize, out byte[] sector);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(errno != ErrorNumber.NoError)
|
|
|
|
|
|
return;
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sector.Length < Marshal.SizeOf<Superblock>())
|
|
|
|
|
|
return;
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// ReSharper disable once InconsistentNaming
|
|
|
|
|
|
Superblock f2fsSb = Marshal.ByteArrayToStructureLittleEndian<Superblock>(sector);
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(f2fsSb.magic != F2FS_MAGIC)
|
|
|
|
|
|
return;
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var sb = new StringBuilder();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendLine(Localization.F2FS_filesystem);
|
|
|
|
|
|
sb.AppendFormat(Localization.Version_0_1, f2fsSb.major_ver, f2fsSb.minor_ver).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_bytes_per_sector, 1 << (int)f2fsSb.log_sectorsize).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_sectors_1_bytes_per_block, 1 << (int)f2fsSb.log_sectors_per_block,
|
|
|
|
|
|
1 << (int)f2fsSb.log_blocksize).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization._0_blocks_per_segment, f2fsSb.log_blocks_per_seg).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_blocks_in_volume, f2fsSb.block_count).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_segments_per_section, f2fsSb.segs_per_sec).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_sections_per_zone, f2fsSb.secs_per_zone).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_sections, f2fsSb.section_count).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization._0_segments, f2fsSb.segment_count).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Root_directory_resides_on_inode_0, f2fsSb.root_ino).AppendLine();
|
|
|
|
|
|
sb.AppendFormat(Localization.Volume_UUID_0, f2fsSb.uuid).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_name_0,
|
|
|
|
|
|
StringHandlers.CToString(f2fsSb.volume_name, Encoding.Unicode, true)).AppendLine();
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_last_mounted_on_kernel_version_0, StringHandlers.CToString(f2fsSb.version)).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AppendLine();
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-11-28 02:59:53 +00:00
|
|
|
|
sb.AppendFormat(Localization.Volume_created_on_kernel_version_0, StringHandlers.CToString(f2fsSb.init_version)).
|
2022-03-06 13:29:38 +00:00
|
|
|
|
AppendLine();
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
information = sb.ToString();
|
2016-09-02 18:10:54 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
2017-12-24 02:37:41 +00:00
|
|
|
|
{
|
2022-11-28 02:59:53 +00:00
|
|
|
|
Type = FS_TYPE,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
SystemIdentifier = Encoding.ASCII.GetString(f2fsSb.version),
|
|
|
|
|
|
Clusters = f2fsSb.block_count,
|
|
|
|
|
|
ClusterSize = (uint)(1 << (int)f2fsSb.log_blocksize),
|
|
|
|
|
|
DataPreparerIdentifier = Encoding.ASCII.GetString(f2fsSb.init_version),
|
|
|
|
|
|
VolumeName = StringHandlers.CToString(f2fsSb.volume_name, Encoding.Unicode, true),
|
|
|
|
|
|
VolumeSerial = f2fsSb.uuid.ToString()
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2016-09-02 18:10:54 +01:00
|
|
|
|
}
|