2018-07-23 23:25:43 +01:00
|
|
|
|
// /***************************************************************************
|
2020-02-27 12:31:25 +00:00
|
|
|
|
// Aaru Data Preservation Suite
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : Write.cs
|
|
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
|
|
|
|
|
//
|
|
|
|
|
|
// Component : Disk image plugins.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Writes RS-IDE disk images.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ 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
|
2018-07-23 23:25:43 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes;
|
|
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
|
|
|
|
|
using Aaru.CommonTypes.Structs.Devices.ATA;
|
|
|
|
|
|
using Aaru.Helpers;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
using Schemas;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Version = Aaru.CommonTypes.Interop.Version;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
namespace Aaru.DiscImages;
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
public sealed partial class RsIde
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
|
|
|
|
|
|
uint sectorSize)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sectorSize != 256 &&
|
|
|
|
|
|
sectorSize != 512)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Unsupported_sector_size;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sectors > 63 * 16 * 1024)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Too_many_sectors;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(!SupportedMediaTypes.Contains(mediaType))
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = string.Format(Localization.Unsupported_media_format_0, mediaType);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_imageInfo = new ImageInfo
|
|
|
|
|
|
{
|
|
|
|
|
|
MediaType = mediaType,
|
|
|
|
|
|
SectorSize = sectorSize,
|
|
|
|
|
|
Sectors = sectors
|
|
|
|
|
|
};
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
_writingStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch(IOException e)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = string.Format(Localization.Could_not_create_new_image_file_exception_0, e.Message);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IsWriting = true;
|
|
|
|
|
|
ErrorMessage = null;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool WriteMediaTag(byte[] data, MediaTagType tag)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(tag != MediaTagType.ATA_IDENTIFY)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = string.Format(Localization.Unsupported_media_tag_0, tag);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(!IsWriting)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Tried_to_write_on_a_non_writable_image;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_identify = new byte[106];
|
|
|
|
|
|
Array.Copy(data, 0, _identify, 0, 106);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool WriteSector(byte[] data, ulong sectorAddress)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!IsWriting)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Tried_to_write_on_a_non_writable_image;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(data.Length != _imageInfo.SectorSize)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Incorrect_data_size;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sectorAddress >= _imageInfo.Sectors)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Tried_to_write_past_image_size;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
_writingStream.Seek((long)((ulong)Marshal.SizeOf<Header>() + (sectorAddress * _imageInfo.SectorSize)),
|
2022-03-06 13:29:38 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_writingStream.Write(data, 0, data.Length);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorMessage = "";
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool WriteSectors(byte[] data, ulong sectorAddress, uint length)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!IsWriting)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Tried_to_write_on_a_non_writable_image;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(data.Length % _imageInfo.SectorSize != 0)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Incorrect_data_size;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sectorAddress + length > _imageInfo.Sectors)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Tried_to_write_past_image_size;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
_writingStream.Seek((long)((ulong)Marshal.SizeOf<Header>() + (sectorAddress * _imageInfo.SectorSize)),
|
2022-03-06 13:29:38 +00:00
|
|
|
|
SeekOrigin.Begin);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_writingStream.Write(data, 0, data.Length);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorMessage = "";
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool WriteSectorLong(byte[] data, ulong sectorAddress)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool WriteSectorsLong(byte[] data, ulong sectorAddress, uint length)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Close()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!IsWriting)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Image_is_not_opened_for_writing;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(_imageInfo.Cylinders == 0)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_imageInfo.Cylinders = (uint)(_imageInfo.Sectors / 16 / 63);
|
|
|
|
|
|
_imageInfo.Heads = 16;
|
|
|
|
|
|
_imageInfo.SectorsPerTrack = 63;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
while(_imageInfo.Cylinders == 0)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_imageInfo.Heads--;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(_imageInfo.Heads == 0)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_imageInfo.SectorsPerTrack--;
|
|
|
|
|
|
_imageInfo.Heads = 16;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_imageInfo.Cylinders = (uint)(_imageInfo.Sectors / _imageInfo.Heads / _imageInfo.SectorsPerTrack);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
if(_imageInfo.Cylinders == 0 &&
|
|
|
|
|
|
_imageInfo is { Heads: 0, SectorsPerTrack: 0 })
|
2022-03-06 13:29:38 +00:00
|
|
|
|
break;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var header = new Header
|
|
|
|
|
|
{
|
|
|
|
|
|
magic = _signature,
|
|
|
|
|
|
identify = new byte[106],
|
|
|
|
|
|
dataOff = (ushort)Marshal.SizeOf<Header>(),
|
|
|
|
|
|
revision = 1,
|
|
|
|
|
|
reserved = new byte[11]
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
if(_imageInfo.SectorSize == 256)
|
|
|
|
|
|
header.flags = RsIdeFlags.HalfSectors;
|
|
|
|
|
|
|
|
|
|
|
|
if(_identify == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
var ataId = new Identify.IdentifyDevice
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-07 07:36:44 +00:00
|
|
|
|
GeneralConfiguration = CommonTypes.Structs.Devices.ATA.Identify.GeneralConfigurationBit.UltraFastIDE |
|
|
|
|
|
|
CommonTypes.Structs.Devices.ATA.Identify.GeneralConfigurationBit.Fixed |
|
|
|
|
|
|
CommonTypes.Structs.Devices.ATA.Identify.GeneralConfigurationBit.NotMFM |
|
|
|
|
|
|
CommonTypes.Structs.Devices.ATA.Identify.GeneralConfigurationBit.SoftSector,
|
|
|
|
|
|
Cylinders = (ushort)_imageInfo.Cylinders,
|
|
|
|
|
|
Heads = (ushort)_imageInfo.Heads,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
SectorsPerTrack = (ushort)_imageInfo.SectorsPerTrack,
|
2022-03-07 07:36:44 +00:00
|
|
|
|
VendorWord47 = 0x80,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Capabilities = CommonTypes.Structs.Devices.ATA.Identify.CapabilitiesBit.DMASupport |
|
2022-03-07 07:36:44 +00:00
|
|
|
|
CommonTypes.Structs.Devices.ATA.Identify.CapabilitiesBit.IORDY |
|
|
|
|
|
|
CommonTypes.Structs.Devices.ATA.Identify.CapabilitiesBit.LBASupport,
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ExtendedIdentify = CommonTypes.Structs.Devices.ATA.Identify.ExtendedIdentifyBit.Words54to58Valid,
|
|
|
|
|
|
CurrentCylinders = (ushort)_imageInfo.Cylinders,
|
|
|
|
|
|
CurrentHeads = (ushort)_imageInfo.Heads,
|
|
|
|
|
|
CurrentSectorsPerTrack = (ushort)_imageInfo.SectorsPerTrack,
|
|
|
|
|
|
CurrentSectors = (uint)_imageInfo.Sectors,
|
|
|
|
|
|
LBASectors = (uint)_imageInfo.Sectors,
|
|
|
|
|
|
DMASupported = CommonTypes.Structs.Devices.ATA.Identify.TransferMode.Mode0,
|
|
|
|
|
|
DMAActive = CommonTypes.Structs.Devices.ATA.Identify.TransferMode.Mode0
|
2018-07-23 23:25:43 +01:00
|
|
|
|
};
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(string.IsNullOrEmpty(_imageInfo.DriveManufacturer))
|
|
|
|
|
|
_imageInfo.DriveManufacturer = "Aaru";
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(string.IsNullOrEmpty(_imageInfo.DriveModel))
|
|
|
|
|
|
_imageInfo.DriveModel = "";
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(string.IsNullOrEmpty(_imageInfo.DriveFirmwareRevision))
|
|
|
|
|
|
Version.GetVersion();
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(string.IsNullOrEmpty(_imageInfo.DriveSerialNumber))
|
|
|
|
|
|
_imageInfo.DriveSerialNumber = $"{new Random().NextDouble():16X}";
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
byte[] ataIdBytes = new byte[Marshal.SizeOf<Identify.IdentifyDevice>()];
|
|
|
|
|
|
nint ptr = System.Runtime.InteropServices.Marshal.AllocHGlobal(512);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
System.Runtime.InteropServices.Marshal.StructureToPtr(ataId, ptr, true);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
|
System.Runtime.InteropServices.Marshal.Copy(ptr, ataIdBytes, 0, Marshal.SizeOf<Identify.IdentifyDevice>());
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
System.Runtime.InteropServices.Marshal.FreeHGlobal(ptr);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-07 07:36:44 +00:00
|
|
|
|
Array.Copy(ScrambleAtaString(_imageInfo.DriveManufacturer + " " + _imageInfo.DriveModel, 40), 0, ataIdBytes,
|
|
|
|
|
|
27 * 2, 40);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Array.Copy(ScrambleAtaString(_imageInfo.DriveFirmwareRevision, 8), 0, ataIdBytes, 23 * 2, 8);
|
|
|
|
|
|
Array.Copy(ScrambleAtaString(_imageInfo.DriveSerialNumber, 20), 0, ataIdBytes, 10 * 2, 20);
|
|
|
|
|
|
Array.Copy(ataIdBytes, 0, header.identify, 0, 106);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
else
|
|
|
|
|
|
Array.Copy(_identify, 0, header.identify, 0, 106);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-11-15 15:58:43 +00:00
|
|
|
|
byte[] hdr = new byte[Marshal.SizeOf<Header>()];
|
|
|
|
|
|
nint hdrPtr = System.Runtime.InteropServices.Marshal.AllocHGlobal(Marshal.SizeOf<Header>());
|
2022-03-06 13:29:38 +00:00
|
|
|
|
System.Runtime.InteropServices.Marshal.StructureToPtr(header, hdrPtr, true);
|
|
|
|
|
|
System.Runtime.InteropServices.Marshal.Copy(hdrPtr, hdr, 0, hdr.Length);
|
|
|
|
|
|
System.Runtime.InteropServices.Marshal.FreeHGlobal(hdrPtr);
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_writingStream.Seek(0, SeekOrigin.Begin);
|
|
|
|
|
|
_writingStream.Write(hdr, 0, hdr.Length);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_writingStream.Flush();
|
|
|
|
|
|
_writingStream.Close();
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
IsWriting = false;
|
|
|
|
|
|
ErrorMessage = "";
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool SetMetadata(ImageInfo metadata)
|
|
|
|
|
|
{
|
|
|
|
|
|
_imageInfo.DriveManufacturer = metadata.DriveManufacturer;
|
|
|
|
|
|
_imageInfo.DriveModel = metadata.DriveModel;
|
|
|
|
|
|
_imageInfo.DriveFirmwareRevision = metadata.DriveFirmwareRevision;
|
|
|
|
|
|
_imageInfo.DriveSerialNumber = metadata.DriveSerialNumber;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool SetGeometry(uint cylinders, uint heads, uint sectorsPerTrack)
|
|
|
|
|
|
{
|
|
|
|
|
|
if(cylinders > ushort.MaxValue)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Too_many_cylinders;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
return false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(heads > ushort.MaxValue)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Too_many_heads;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sectorsPerTrack > ushort.MaxValue)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Too_many_sectors_per_track;
|
2020-01-11 20:55:54 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_imageInfo.SectorsPerTrack = sectorsPerTrack;
|
|
|
|
|
|
_imageInfo.Heads = heads;
|
|
|
|
|
|
_imageInfo.Cylinders = cylinders;
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Unsupported_feature;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Unsupported_feature;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool SetDumpHardware(List<DumpHardwareType> dumpHardware) => false;
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool SetCicmMetadata(CICMMetadataType metadata) => false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|