2017-05-19 20:28:49 +01:00
|
|
|
// /***************************************************************************
|
2016-10-07 00:41:59 +01:00
|
|
|
// The Disc Image Chef
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Filename : Super.cs
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
//
|
|
|
|
|
// Component : Apple DOS filesystem plugin.
|
|
|
|
|
//
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
//
|
|
|
|
|
// Handles mounting and umounting the Apple DOS filesystem.
|
|
|
|
|
//
|
|
|
|
|
// --[ 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-10-07 00:41:59 +01:00
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
2017-12-27 23:55:59 +00:00
|
|
|
using System.Collections.Generic;
|
2016-10-07 00:41:59 +01:00
|
|
|
using System.Runtime.InteropServices;
|
2017-12-26 06:05:12 +00:00
|
|
|
using Claunia.Encoding;
|
|
|
|
|
using DiscImageChef.CommonTypes;
|
2016-10-07 00:41:59 +01:00
|
|
|
using DiscImageChef.Console;
|
2017-12-26 06:05:12 +00:00
|
|
|
using DiscImageChef.DiscImages;
|
2017-12-21 14:30:38 +00:00
|
|
|
using Schemas;
|
2017-12-26 06:05:12 +00:00
|
|
|
using Encoding = System.Text.Encoding;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
|
|
|
|
namespace DiscImageChef.Filesystems.AppleDOS
|
|
|
|
|
{
|
2017-12-21 16:27:09 +00:00
|
|
|
public partial class AppleDOS
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
/// Mounts an Apple DOS filesystem
|
2016-10-07 00:41:59 +01:00
|
|
|
/// </summary>
|
2017-12-27 23:55:59 +00:00
|
|
|
public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
|
|
|
|
|
Dictionary<string, string> options)
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
2017-12-27 23:55:59 +00:00
|
|
|
device = imagePlugin;
|
|
|
|
|
start = partition.Start;
|
2017-12-26 18:52:21 +00:00
|
|
|
Encoding = encoding ?? new Apple2();
|
2017-12-26 08:01:40 +00:00
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
if(device.Info.Sectors != 455 && device.Info.Sectors != 560)
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("Apple DOS plugin", "Incorrect device size.");
|
|
|
|
|
return Errno.InOutError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(start > 0)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("Apple DOS plugin", "Partitions are not supported.");
|
|
|
|
|
return Errno.InOutError;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
if(device.Info.SectorSize != 256)
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("Apple DOS plugin", "Incorrect sector size.");
|
|
|
|
|
return Errno.InOutError;
|
|
|
|
|
}
|
|
|
|
|
|
2017-12-26 06:05:12 +00:00
|
|
|
sectorsPerTrack = device.Info.Sectors == 455 ? 13 : 16;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
|
|
|
|
// Read the VTOC
|
2017-12-27 23:55:59 +00:00
|
|
|
vtocBlocks = device.ReadSector((ulong)(17 * sectorsPerTrack));
|
|
|
|
|
vtoc = new Vtoc();
|
2016-10-07 00:41:59 +01:00
|
|
|
IntPtr vtocPtr = Marshal.AllocHGlobal(256);
|
2017-12-22 07:05:08 +00:00
|
|
|
Marshal.Copy(vtocBlocks, 0, vtocPtr, 256);
|
2017-12-20 17:15:26 +00:00
|
|
|
vtoc = (Vtoc)Marshal.PtrToStructure(vtocPtr, typeof(Vtoc));
|
2016-10-07 00:41:59 +01:00
|
|
|
Marshal.FreeHGlobal(vtocPtr);
|
|
|
|
|
|
|
|
|
|
track1UsedByFiles = false;
|
|
|
|
|
track2UsedByFiles = false;
|
2017-12-27 23:55:59 +00:00
|
|
|
usedSectors = 1;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2017-12-22 07:05:08 +00:00
|
|
|
Errno error = ReadCatalog();
|
2016-10-07 00:41:59 +01:00
|
|
|
if(error != Errno.NoError)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("Apple DOS plugin", "Unable to read catalog.");
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
error = CacheAllFiles();
|
|
|
|
|
if(error != Errno.NoError)
|
|
|
|
|
{
|
|
|
|
|
DicConsole.DebugWriteLine("Apple DOS plugin", "Unable cache all files.");
|
|
|
|
|
return error;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create XML metadata for mounted filesystem
|
2017-12-26 08:01:40 +00:00
|
|
|
XmlFsType = new FileSystemType
|
2017-12-22 07:05:08 +00:00
|
|
|
{
|
2017-12-27 23:55:59 +00:00
|
|
|
Bootable = true,
|
|
|
|
|
Clusters = (long)device.Info.Sectors,
|
|
|
|
|
ClusterSize = vtoc.bytesPerSector,
|
|
|
|
|
Files = catalogCache.Count,
|
|
|
|
|
FilesSpecified = true,
|
2017-12-22 07:05:08 +00:00
|
|
|
FreeClustersSpecified = true,
|
2017-12-27 23:55:59 +00:00
|
|
|
Type = "Apple DOS"
|
2017-12-22 07:05:08 +00:00
|
|
|
};
|
2017-12-26 08:01:40 +00:00
|
|
|
XmlFsType.FreeClusters = XmlFsType.Clusters - usedSectors;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
2017-12-27 23:55:59 +00:00
|
|
|
if(options == null) options = GetDefaultOptions();
|
|
|
|
|
if(options.TryGetValue("debug", out string debugString)) bool.TryParse(debugString, out debug);
|
2016-10-07 00:41:59 +01:00
|
|
|
mounted = true;
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
/// Umounts this DOS filesystem
|
2016-10-07 00:41:59 +01:00
|
|
|
/// </summary>
|
2017-12-26 07:28:40 +00:00
|
|
|
public Errno Unmount()
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
2017-12-27 23:55:59 +00:00
|
|
|
mounted = false;
|
|
|
|
|
extentCache = null;
|
|
|
|
|
fileCache = null;
|
|
|
|
|
catalogCache = null;
|
2016-10-07 00:41:59 +01:00
|
|
|
fileSizeCache = null;
|
|
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2017-12-24 02:37:41 +00:00
|
|
|
/// Gets information about the mounted volume.
|
2016-10-07 00:41:59 +01:00
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="stat">Information about the mounted volume.</param>
|
2017-12-26 08:17:28 +00:00
|
|
|
public Errno StatFs(out FileSystemInfo stat)
|
2016-10-07 00:41:59 +01:00
|
|
|
{
|
2017-12-22 07:05:08 +00:00
|
|
|
stat = new FileSystemInfo
|
|
|
|
|
{
|
2017-12-27 23:55:59 +00:00
|
|
|
Blocks = (long)device.Info.Sectors,
|
2017-12-22 07:05:08 +00:00
|
|
|
FilenameLength = 30,
|
2017-12-27 23:55:59 +00:00
|
|
|
Files = (ulong)catalogCache.Count,
|
|
|
|
|
PluginId = Id,
|
|
|
|
|
Type = "Apple DOS"
|
2017-12-22 07:05:08 +00:00
|
|
|
};
|
2017-12-27 23:55:59 +00:00
|
|
|
stat.FreeFiles = totalFileEntries - stat.Files;
|
|
|
|
|
stat.FreeBlocks = stat.Blocks - usedSectors;
|
2016-10-07 00:41:59 +01:00
|
|
|
|
|
|
|
|
return Errno.NoError;
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
}
|