2014-04-17 19:58:14 +00:00
|
|
|
/***************************************************************************
|
2014-06-15 23:39:34 +01:00
|
|
|
The Disc Image Chef
|
2014-04-17 19:58:14 +00:00
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Filename : extFS.cs
|
|
|
|
|
Version : 1.0
|
|
|
|
|
Author(s) : Natalia Portillo
|
|
|
|
|
|
|
|
|
|
Component : Filesystem plugins
|
|
|
|
|
|
|
|
|
|
Revision : $Revision$
|
|
|
|
|
Last change by : $Author$
|
|
|
|
|
Date : $Date$
|
|
|
|
|
|
|
|
|
|
--[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
Identifies Linux extended filesystem and shows information.
|
|
|
|
|
|
|
|
|
|
--[ License ] --------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
2014-04-19 18:23:00 +01:00
|
|
|
it under the terms of the GNU General Public License as
|
2014-04-17 19:58:14 +00:00
|
|
|
published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program 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
|
2014-04-19 18:23:00 +01:00
|
|
|
GNU General Public License for more details.
|
2014-04-17 19:58:14 +00:00
|
|
|
|
2014-04-19 18:23:00 +01:00
|
|
|
You should have received a copy of the GNU General Public License
|
2014-04-17 19:58:14 +00:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
----------------------------------------------------------------------------
|
|
|
|
|
Copyright (C) 2011-2014 Claunia.com
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
//$Id$
|
|
|
|
|
|
2012-08-03 01:45:38 +00:00
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
2014-06-15 23:39:34 +01:00
|
|
|
using DiscImageChef;
|
2012-08-03 01:45:38 +00:00
|
|
|
|
2014-04-17 19:58:14 +00:00
|
|
|
// Information from the Linux kernel
|
2014-06-15 23:39:34 +01:00
|
|
|
namespace DiscImageChef.Plugins
|
2012-08-03 01:45:38 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
class extFS : Plugin
|
|
|
|
|
{
|
2015-10-05 20:04:05 +01:00
|
|
|
public extFS()
|
2012-08-03 01:45:38 +00:00
|
|
|
{
|
2014-04-14 02:29:13 +00:00
|
|
|
Name = "Linux extended Filesystem";
|
|
|
|
|
PluginUUID = new Guid("076CB3A2-08C2-4D69-BC8A-FCAA2E502BE2");
|
2012-08-03 01:45:38 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-20 05:09:46 +01:00
|
|
|
public override bool Identify(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd)
|
2014-04-14 02:29:13 +00:00
|
|
|
{
|
2016-04-19 02:11:47 +01:00
|
|
|
if((2 + partitionStart) >= imagePlugin.GetSectors())
|
2014-07-09 19:49:14 +01:00
|
|
|
return false;
|
|
|
|
|
|
2015-04-20 05:09:46 +01:00
|
|
|
byte[] sb_sector = imagePlugin.ReadSector(2 + partitionStart); // Superblock resides at 0x400
|
2014-04-14 02:29:13 +00:00
|
|
|
|
|
|
|
|
UInt16 magic = BitConverter.ToUInt16(sb_sector, 0x038); // Here should reside magic number
|
2016-04-19 02:11:47 +01:00
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
return magic == extFSMagic;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-20 05:09:46 +01:00
|
|
|
public override void GetInformation(ImagePlugins.ImagePlugin imagePlugin, ulong partitionStart, ulong partitionEnd, out string information)
|
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
|
|
|
|
2015-04-20 05:09:46 +01:00
|
|
|
byte[] sb_sector = imagePlugin.ReadSector(2 + partitionStart); // Superblock resides at 0x400
|
2014-04-14 02:29:13 +00:00
|
|
|
extFSSuperBlock ext_sb = new extFSSuperBlock();
|
2012-08-03 01:45:38 +00:00
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
ext_sb.inodes = BitConverter.ToUInt32(sb_sector, 0x000);
|
|
|
|
|
ext_sb.zones = BitConverter.ToUInt32(sb_sector, 0x004);
|
|
|
|
|
ext_sb.firstfreeblk = BitConverter.ToUInt32(sb_sector, 0x008);
|
|
|
|
|
ext_sb.freecountblk = BitConverter.ToUInt32(sb_sector, 0x00C);
|
|
|
|
|
ext_sb.firstfreeind = BitConverter.ToUInt32(sb_sector, 0x010);
|
|
|
|
|
ext_sb.freecountind = BitConverter.ToUInt32(sb_sector, 0x014);
|
|
|
|
|
ext_sb.firstdatazone = BitConverter.ToUInt32(sb_sector, 0x018);
|
|
|
|
|
ext_sb.logzonesize = BitConverter.ToUInt32(sb_sector, 0x01C);
|
|
|
|
|
ext_sb.maxsize = BitConverter.ToUInt32(sb_sector, 0x020);
|
2012-08-03 01:45:38 +00:00
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
sb.AppendLine("ext filesystem");
|
|
|
|
|
sb.AppendFormat("{0} zones on volume", ext_sb.zones);
|
|
|
|
|
sb.AppendFormat("{0} free blocks ({1} bytes)", ext_sb.freecountblk, ext_sb.freecountblk * 1024);
|
|
|
|
|
sb.AppendFormat("{0} inodes on volume, {1} free ({2}%)", ext_sb.inodes, ext_sb.freecountind, ext_sb.freecountind * 100 / ext_sb.inodes);
|
|
|
|
|
sb.AppendFormat("First free inode is {0}", ext_sb.firstfreeind);
|
|
|
|
|
sb.AppendFormat("First free block is {0}", ext_sb.firstfreeblk);
|
|
|
|
|
sb.AppendFormat("First data zone is {0}", ext_sb.firstdatazone);
|
|
|
|
|
sb.AppendFormat("Log zone size: {0}", ext_sb.logzonesize);
|
|
|
|
|
sb.AppendFormat("Max zone size: {0}", ext_sb.maxsize);
|
2012-08-03 01:45:38 +00:00
|
|
|
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType = new Schemas.FileSystemType();
|
|
|
|
|
xmlFSType.Type = "ext";
|
|
|
|
|
xmlFSType.FreeClusters = ext_sb.freecountblk;
|
2015-12-06 05:09:31 +00:00
|
|
|
xmlFSType.FreeClustersSpecified = true;
|
2015-12-05 17:10:27 +00:00
|
|
|
xmlFSType.ClusterSize = 1024;
|
2015-12-06 05:09:31 +00:00
|
|
|
xmlFSType.Clusters = (long)((partitionEnd - partitionStart + 1) * imagePlugin.GetSectorSize() / 1024);
|
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
|
|
|
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// ext superblock magic
|
|
|
|
|
/// </summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public const UInt16 extFSMagic = 0x137D;
|
2012-08-03 01:45:38 +00:00
|
|
|
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>
|
|
|
|
|
/// ext superblock
|
|
|
|
|
/// </summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public struct extFSSuperBlock
|
|
|
|
|
{
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x000, inodes on volume</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 inodes;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x004, zones on volume</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 zones;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x008, first free block</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 firstfreeblk;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x00C, free blocks count</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 freecountblk;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x010, first free inode</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 firstfreeind;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x014, free inodes count</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 freecountind;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x018, first data zone</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 firstdatazone;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x01C, log zone size</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 logzonesize;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x020, max zone size</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 maxsize;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x024, reserved</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 reserved1;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x028, reserved</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 reserved2;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x02C, reserved</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 reserved3;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x030, reserved</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 reserved4;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x034, reserved</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt32 reserved5;
|
2015-12-06 07:18:36 +00:00
|
|
|
/// <summary>0x038, 0x137D (little endian)</summary>
|
2014-04-14 02:29:13 +00:00
|
|
|
public UInt16 magic;
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
}
|