2017-07-19 16:31:08 +01:00
|
|
|
|
// /***************************************************************************
|
2016-07-28 18:13:49 +01:00
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : extFS.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Linux extended filesystem plugin.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Identifies the Linux extended filesystem and shows information.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ 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/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 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-12-22 08:43:22 +00:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
2017-12-21 14:30:38 +00:00
|
|
|
|
using DiscImageChef.DiscImages;
|
|
|
|
|
|
using Schemas;
|
2012-08-03 01:45:38 +00:00
|
|
|
|
|
2016-07-21 16:15:39 +01:00
|
|
|
|
namespace DiscImageChef.Filesystems
|
2012-08-03 01:45:38 +00:00
|
|
|
|
{
|
2016-07-28 22:25:26 +01:00
|
|
|
|
// Information from the Linux kernel
|
2017-12-26 06:05:12 +00:00
|
|
|
|
public class extFS : IFilesystem
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2017-12-22 08:43:22 +00:00
|
|
|
|
const int SB_POS = 0x400;
|
2017-09-19 19:53:03 +01:00
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ext superblock magic
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
const ushort EXT_MAGIC = 0x137D;
|
|
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
public FileSystemType XmlFsType { get; private set; }
|
2018-06-22 08:08:38 +01:00
|
|
|
|
public string Name => "Linux extended Filesystem";
|
|
|
|
|
|
public Guid Id => new Guid("076CB3A2-08C2-4D69-BC8A-FCAA2E502BE2");
|
|
|
|
|
|
public Encoding Encoding { get; private set; }
|
2016-07-27 13:32:45 +01:00
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public bool Identify(IMediaImage imagePlugin, Partition partition)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return false;
|
2017-12-19 20:33:03 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ulong sbSectorOff = SB_POS / imagePlugin.Info.SectorSize;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
uint sbOff = SB_POS % imagePlugin.Info.SectorSize;
|
2017-09-19 19:53:03 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(sbSectorOff + partition.Start >= partition.End) return false;
|
2014-07-09 19:49:14 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] sbSector = imagePlugin.ReadSector(sbSectorOff + partition.Start);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
byte[] sb = new byte[512];
|
2017-12-22 08:43:22 +00:00
|
|
|
|
Array.Copy(sbSector, sbOff, sb, 0, 512);
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
2017-09-19 19:53:03 +01:00
|
|
|
|
ushort magic = BitConverter.ToUInt16(sb, 0x038);
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
return magic == EXT_MAGIC;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-26 07:28:40 +00:00
|
|
|
|
public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Encoding encoding)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Encoding = encoding ?? Encoding.GetEncoding("iso-8859-15");
|
2014-04-14 02:29:13 +00:00
|
|
|
|
information = "";
|
2016-04-19 02:11:47 +01:00
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
|
StringBuilder sb = new StringBuilder();
|
2012-08-03 01:45:38 +00:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
if(imagePlugin.Info.SectorSize < 512) return;
|
2017-09-28 15:44:48 +01:00
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
|
ulong sbSectorOff = SB_POS / imagePlugin.Info.SectorSize;
|
2018-06-22 08:08:38 +01:00
|
|
|
|
uint sbOff = SB_POS % imagePlugin.Info.SectorSize;
|
2017-09-19 19:53:03 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
if(sbSectorOff + partition.Start >= partition.End) return;
|
2017-09-19 19:53:03 +01:00
|
|
|
|
|
2018-06-22 08:08:38 +01:00
|
|
|
|
byte[] sblock = imagePlugin.ReadSector(sbSectorOff + partition.Start);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
byte[] sbSector = new byte[512];
|
|
|
|
|
|
Array.Copy(sblock, sbOff, sbSector, 0, 512);
|
2017-09-19 19:53:03 +01:00
|
|
|
|
|
2017-12-22 08:43:22 +00:00
|
|
|
|
extFSSuperBlock extSb = new extFSSuperBlock
|
|
|
|
|
|
{
|
2018-06-22 08:08:38 +01: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),
|
2017-12-22 08:43:22 +00:00
|
|
|
|
firstdatazone = BitConverter.ToUInt32(sbSector, 0x018),
|
2018-06-22 08:08:38 +01:00
|
|
|
|
logzonesize = BitConverter.ToUInt32(sbSector, 0x01C),
|
|
|
|
|
|
maxsize = BitConverter.ToUInt32(sbSector, 0x020)
|
2017-12-22 08:43:22 +00:00
|
|
|
|
};
|
2012-08-03 01:45:38 +00:00
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
|
sb.AppendLine("ext filesystem");
|
2018-06-22 08:08:38 +01:00
|
|
|
|
sb.AppendFormat("{0} zones on volume", extSb.zones);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
sb.AppendFormat("{0} free blocks ({1} bytes)", extSb.freecountblk, extSb.freecountblk * 1024);
|
|
|
|
|
|
sb.AppendFormat("{0} inodes on volume, {1} free ({2}%)", extSb.inodes, extSb.freecountind,
|
|
|
|
|
|
extSb.freecountind * 100 / extSb.inodes);
|
|
|
|
|
|
sb.AppendFormat("First free inode is {0}", extSb.firstfreeind);
|
|
|
|
|
|
sb.AppendFormat("First free block is {0}", extSb.firstfreeblk);
|
2018-06-22 08:08:38 +01:00
|
|
|
|
sb.AppendFormat("First data zone is {0}", extSb.firstdatazone);
|
|
|
|
|
|
sb.AppendFormat("Log zone size: {0}", extSb.logzonesize);
|
|
|
|
|
|
sb.AppendFormat("Max zone size: {0}", extSb.maxsize);
|
2017-12-22 08:43:22 +00:00
|
|
|
|
|
2017-12-26 08:01:40 +00:00
|
|
|
|
XmlFsType = new FileSystemType
|
2017-12-22 08:43:22 +00:00
|
|
|
|
{
|
2018-06-22 08:08:38 +01:00
|
|
|
|
Type = "ext",
|
|
|
|
|
|
FreeClusters = extSb.freecountblk,
|
2017-12-22 08:43:22 +00:00
|
|
|
|
FreeClustersSpecified = true,
|
2018-06-22 08:08:38 +01:00
|
|
|
|
ClusterSize = 1024,
|
|
|
|
|
|
Clusters =
|
|
|
|
|
|
(long)((partition.End - partition.Start + 1) * imagePlugin.Info.SectorSize / 1024)
|
2017-12-22 08:43:22 +00:00
|
|
|
|
};
|
2015-12-05 17:10:27 +00:00
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
|
information = sb.ToString();
|
|
|
|
|
|
}
|
2012-08-03 01:45:38 +00:00
|
|
|
|
|
2017-12-24 02:37:41 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ext superblock
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
|
|
|
|
|
struct extFSSuperBlock
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>0x000, inodes on volume</summary>
|
|
|
|
|
|
public uint inodes;
|
|
|
|
|
|
/// <summary>0x004, zones on volume</summary>
|
|
|
|
|
|
public uint zones;
|
|
|
|
|
|
/// <summary>0x008, first free block</summary>
|
|
|
|
|
|
public uint firstfreeblk;
|
|
|
|
|
|
/// <summary>0x00C, free blocks count</summary>
|
|
|
|
|
|
public uint freecountblk;
|
|
|
|
|
|
/// <summary>0x010, first free inode</summary>
|
|
|
|
|
|
public uint firstfreeind;
|
|
|
|
|
|
/// <summary>0x014, free inodes count</summary>
|
|
|
|
|
|
public uint freecountind;
|
|
|
|
|
|
/// <summary>0x018, first data zone</summary>
|
|
|
|
|
|
public uint firstdatazone;
|
|
|
|
|
|
/// <summary>0x01C, log zone size</summary>
|
|
|
|
|
|
public uint logzonesize;
|
|
|
|
|
|
/// <summary>0x020, max zone size</summary>
|
|
|
|
|
|
public uint maxsize;
|
|
|
|
|
|
/// <summary>0x024, reserved</summary>
|
|
|
|
|
|
public uint reserved1;
|
|
|
|
|
|
/// <summary>0x028, reserved</summary>
|
|
|
|
|
|
public uint reserved2;
|
|
|
|
|
|
/// <summary>0x02C, reserved</summary>
|
|
|
|
|
|
public uint reserved3;
|
|
|
|
|
|
/// <summary>0x030, reserved</summary>
|
|
|
|
|
|
public uint reserved4;
|
|
|
|
|
|
/// <summary>0x034, reserved</summary>
|
|
|
|
|
|
public uint reserved5;
|
|
|
|
|
|
/// <summary>0x038, 0x137D (little endian)</summary>
|
|
|
|
|
|
public ushort magic;
|
|
|
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|