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;
|
2016-07-21 17:16:08 +01:00
|
|
|
|
using System.Collections.Generic;
|
2017-07-19 16:31:08 +01:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
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-07-01 03:26:08 +01:00
|
|
|
|
public class extFS : Filesystem
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2017-09-19 19:53:03 +01:00
|
|
|
|
const int sbPos = 0x400;
|
|
|
|
|
|
|
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");
|
2017-06-06 21:23:20 +01:00
|
|
|
|
CurrentEncoding = Encoding.GetEncoding("iso-8859-15");
|
2012-08-03 01:45:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-12 23:54:02 +01:00
|
|
|
|
public extFS(Encoding encoding)
|
|
|
|
|
|
{
|
|
|
|
|
|
Name = "Linux extended Filesystem";
|
|
|
|
|
|
PluginUUID = new Guid("076CB3A2-08C2-4D69-BC8A-FCAA2E502BE2");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(encoding == null) CurrentEncoding = Encoding.GetEncoding("iso-8859-15");
|
|
|
|
|
|
else CurrentEncoding = encoding;
|
2017-10-12 23:54:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
public extFS(DiscImages.ImagePlugin imagePlugin, Partition partition, Encoding encoding)
|
2016-07-27 13:32:45 +01:00
|
|
|
|
{
|
|
|
|
|
|
Name = "Linux extended Filesystem";
|
|
|
|
|
|
PluginUUID = new Guid("076CB3A2-08C2-4D69-BC8A-FCAA2E502BE2");
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(encoding == null) CurrentEncoding = Encoding.GetEncoding("iso-8859-15");
|
|
|
|
|
|
else CurrentEncoding = encoding;
|
2016-07-27 13:32:45 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
public override bool Identify(DiscImages.ImagePlugin imagePlugin, Partition partition)
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(imagePlugin.GetSectorSize() < 512) return false;
|
|
|
|
|
|
|
2017-09-19 19:53:03 +01:00
|
|
|
|
ulong sbSector = sbPos / imagePlugin.GetSectorSize();
|
|
|
|
|
|
uint sbOff = sbPos % imagePlugin.GetSectorSize();
|
|
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
|
if(sbSector + partition.Start >= partition.End) return false;
|
2014-07-09 19:49:14 +01:00
|
|
|
|
|
2017-09-19 19:53:03 +01:00
|
|
|
|
byte[] sb_sector = imagePlugin.ReadSector(sbSector + partition.Start);
|
|
|
|
|
|
byte[] sb = new byte[512];
|
|
|
|
|
|
Array.Copy(sb_sector, 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
|
|
|
|
|
2014-04-14 02:29:13 +00:00
|
|
|
|
return magic == extFSMagic;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:15:26 +00:00
|
|
|
|
public override void GetInformation(DiscImages.ImagePlugin imagePlugin, Partition partition,
|
2017-12-19 20:33:03 +00:00
|
|
|
|
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
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(imagePlugin.GetSectorSize() < 512) return;
|
2017-09-28 15:44:48 +01:00
|
|
|
|
|
2017-09-19 19:53:03 +01:00
|
|
|
|
ulong sbSector = sbPos / imagePlugin.GetSectorSize();
|
|
|
|
|
|
uint sbOff = sbPos % imagePlugin.GetSectorSize();
|
|
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
|
if(sbSector + partition.Start >= partition.End) return;
|
2017-09-19 19:53:03 +01:00
|
|
|
|
|
|
|
|
|
|
byte[] sblock = imagePlugin.ReadSector(sbSector + partition.Start);
|
|
|
|
|
|
byte[] sb_sector = new byte[512];
|
|
|
|
|
|
Array.Copy(sblock, sbOff, sb_sector, 0, 512);
|
|
|
|
|
|
|
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);
|
2017-12-19 20:33:03 +00:00
|
|
|
|
sb.AppendFormat("{0} inodes on volume, {1} free ({2}%)", ext_sb.inodes, ext_sb.freecountind,
|
|
|
|
|
|
ext_sb.freecountind * 100 / ext_sb.inodes);
|
2014-04-14 02:29:13 +00:00
|
|
|
|
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;
|
2017-07-19 16:37:11 +01:00
|
|
|
|
xmlFSType.Clusters = (long)((partition.End - partition.Start + 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>
|
2017-12-20 02:08:37 +00:00
|
|
|
|
const ushort extFSMagic = 0x137D;
|
2012-08-03 01:45:38 +00:00
|
|
|
|
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// ext superblock
|
|
|
|
|
|
/// </summary>
|
2017-12-20 02:08:37 +00:00
|
|
|
|
struct extFSSuperBlock
|
2014-04-14 02:29:13 +00:00
|
|
|
|
{
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x000, inodes on volume</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint inodes;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x004, zones on volume</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint zones;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x008, first free block</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint firstfreeblk;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x00C, free blocks count</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint freecountblk;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x010, first free inode</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint firstfreeind;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x014, free inodes count</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint freecountind;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x018, first data zone</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint firstdatazone;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x01C, log zone size</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint logzonesize;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x020, max zone size</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint maxsize;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x024, reserved</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint reserved1;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x028, reserved</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint reserved2;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x02C, reserved</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint reserved3;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x030, reserved</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint reserved4;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x034, reserved</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public uint reserved5;
|
2015-12-06 07:18:36 +00:00
|
|
|
|
/// <summary>0x038, 0x137D (little endian)</summary>
|
2016-07-28 22:25:26 +01:00
|
|
|
|
public ushort magic;
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
2016-07-21 17:16:08 +01:00
|
|
|
|
|
|
|
|
|
|
public override Errno Mount()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-22 00:43:22 +01:00
|
|
|
|
public override Errno Mount(bool debug)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-07-21 17:16:08 +01:00
|
|
|
|
public override Errno Unmount()
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno MapBlock(string path, long fileBlock, ref long deviceBlock)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno GetAttributes(string path, ref FileAttributes attributes)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno ListXAttr(string path, ref List<string> xattrs)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno GetXattr(string path, string xattr, ref byte[] buf)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Read(string path, long offset, long size, ref byte[] buf)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno ReadDir(string path, ref List<string> contents)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno StatFs(ref FileSystemInfo stat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno Stat(string path, ref FileEntryInfo stat)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override Errno ReadLink(string path, ref string dest)
|
|
|
|
|
|
{
|
|
|
|
|
|
return Errno.NotImplemented;
|
|
|
|
|
|
}
|
2014-04-14 02:29:13 +00:00
|
|
|
|
}
|
2014-04-14 01:14:20 +00:00
|
|
|
|
}
|