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 Apple Universal Disk Image Format.
|
|
|
|
|
|
//
|
|
|
|
|
|
// --[ 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;
|
|
|
|
|
|
using System.Text;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.Checksums;
|
|
|
|
|
|
using Aaru.CommonTypes;
|
2022-12-15 22:21:07 +00:00
|
|
|
|
using Aaru.CommonTypes.AaruMetadata;
|
2020-02-27 00:33:26 +00:00
|
|
|
|
using Aaru.CommonTypes.Enums;
|
|
|
|
|
|
using Aaru.CommonTypes.Structs;
|
2020-07-20 15:43:52 +01:00
|
|
|
|
using Aaru.Helpers;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
using Claunia.PropertyList;
|
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 Udif
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2023-10-03 23:34:59 +01:00
|
|
|
|
#region IWritableImage Members
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool Create(string path, MediaType mediaType, Dictionary<string, string> options, ulong sectors,
|
2023-10-03 23:34:59 +01:00
|
|
|
|
uint sectorSize)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(sectorSize != 512)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Unsupported_sector_size;
|
2020-02-29 18:03:35 +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-02-29 18:03:35 +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-02-29 18:03:35 +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
|
|
|
|
_chunks = new Dictionary<ulong, BlockChunk>();
|
|
|
|
|
|
_currentChunk = new BlockChunk();
|
|
|
|
|
|
_currentSector = 0;
|
|
|
|
|
|
_dataForkChecksum = new Crc32Context();
|
|
|
|
|
|
_masterChecksum = new Crc32Context();
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
IsWriting = true;
|
|
|
|
|
|
ErrorMessage = null;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool WriteMediaTag(byte[] data, MediaTagType tag)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Writing_media_tags_is_not_supported;
|
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 WriteSector(byte[] data, ulong sectorAddress)
|
|
|
|
|
|
{
|
|
|
|
|
|
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-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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-02-29 18:03:35 +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-02-29 18:03:35 +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 < _currentSector)
|
|
|
|
|
|
{
|
2023-10-01 19:15:05 +01:00
|
|
|
|
ErrorMessage = Localization.Tried_to_rewind_this_format_not_supported;
|
2020-02-29 18:03:35 +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
|
|
|
|
_masterChecksum.Update(data);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
bool isEmpty = ArrayHelpers.ArrayIsNullOrEmpty(data);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
switch(_currentChunk.type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case CHUNK_TYPE_ZERO:
|
|
|
|
|
|
_currentChunk.type = isEmpty ? CHUNK_TYPE_NOCOPY : CHUNK_TYPE_COPY;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
case CHUNK_TYPE_NOCOPY when !isEmpty:
|
|
|
|
|
|
case CHUNK_TYPE_COPY when isEmpty:
|
|
|
|
|
|
_chunks.Add(_currentChunk.sector, _currentChunk);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_currentChunk = new BlockChunk
|
|
|
|
|
|
{
|
|
|
|
|
|
type = isEmpty ? CHUNK_TYPE_NOCOPY : CHUNK_TYPE_COPY,
|
|
|
|
|
|
sector = _currentSector,
|
|
|
|
|
|
offset = (ulong)(isEmpty ? 0 : _writingStream.Position)
|
|
|
|
|
|
};
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_currentChunk.sectors++;
|
|
|
|
|
|
_currentChunk.length += (ulong)(isEmpty ? 0 : 512);
|
|
|
|
|
|
_currentSector++;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(!isEmpty)
|
|
|
|
|
|
{
|
|
|
|
|
|
_dataForkChecksum.Update(data);
|
|
|
|
|
|
_writingStream.Write(data, 0, data.Length);
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorMessage = "";
|
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
|
|
|
|
// TODO: This can be optimized
|
|
|
|
|
|
/// <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-02-29 18:03:35 +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-02-29 18:03:35 +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-02-29 18:03:35 +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
|
|
|
|
// Ignore empty sectors
|
|
|
|
|
|
if(ArrayHelpers.ArrayIsNullOrEmpty(data))
|
|
|
|
|
|
{
|
|
|
|
|
|
if(_currentChunk.type == CHUNK_TYPE_COPY)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_chunks.Add(_currentChunk.sector, _currentChunk);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_currentChunk = new BlockChunk
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
type = CHUNK_TYPE_NOCOPY,
|
|
|
|
|
|
sector = _currentSector
|
|
|
|
|
|
};
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_currentChunk.sectors += (ulong)(data.Length / _imageInfo.SectorSize);
|
|
|
|
|
|
_currentSector += (ulong)(data.Length / _imageInfo.SectorSize);
|
|
|
|
|
|
_masterChecksum.Update(data);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
|
|
|
|
|
ErrorMessage = "";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2018-07-23 23:25:43 +01:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
for(uint i = 0; i < length; i++)
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2023-10-03 23:34:59 +01:00
|
|
|
|
var tmp = new byte[_imageInfo.SectorSize];
|
2022-03-06 13:29:38 +00:00
|
|
|
|
Array.Copy(data, i * _imageInfo.SectorSize, tmp, 0, _imageInfo.SectorSize);
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
if(!WriteSector(tmp, sectorAddress + i))
|
|
|
|
|
|
return false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
ErrorMessage = "";
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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;
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <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-02-29 18:03:35 +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(_currentChunk.type != CHUNK_TYPE_NOCOPY)
|
|
|
|
|
|
_currentChunk.length = _currentChunk.sectors * 512;
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_chunks.Add(_currentChunk.sector, _currentChunk);
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_chunks.Add(_imageInfo.Sectors, new BlockChunk
|
|
|
|
|
|
{
|
|
|
|
|
|
type = CHUNK_TYPE_END,
|
|
|
|
|
|
sector = _imageInfo.Sectors
|
|
|
|
|
|
});
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
var bHdr = new BlockHeader
|
|
|
|
|
|
{
|
|
|
|
|
|
signature = CHUNK_SIGNATURE,
|
|
|
|
|
|
version = 1,
|
|
|
|
|
|
sectorCount = _imageInfo.Sectors,
|
|
|
|
|
|
checksumType = UDIF_CHECKSUM_TYPE_CRC32,
|
|
|
|
|
|
checksumLen = 32,
|
|
|
|
|
|
checksum = BitConverter.ToUInt32(_dataForkChecksum.Final().Reverse().ToArray(), 0),
|
|
|
|
|
|
chunks = (uint)_chunks.Count
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var chunkMs = new MemoryStream();
|
2023-10-03 23:34:59 +01:00
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.signature), 0, 4);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.version), 0, 4);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.sectorStart), 0, 8);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.sectorCount), 0, 8);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.dataOffset), 0, 8);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.buffers), 0, 4);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.descriptor), 0, 4);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.reserved1), 0, 4);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.reserved2), 0, 4);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.reserved3), 0, 4);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.reserved4), 0, 4);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.reserved5), 0, 4);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.reserved6), 0, 4);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.checksumType), 0, 4);
|
2023-10-03 23:34:59 +01:00
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.checksumLen), 0, 4);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.checksum), 0, 4);
|
|
|
|
|
|
chunkMs.Write(new byte[124], 0, 124);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(bHdr.chunks), 0, 4);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
foreach(BlockChunk chunk in _chunks.Values)
|
|
|
|
|
|
{
|
2023-10-03 23:34:59 +01:00
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(chunk.type), 0, 4);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(chunk.comment), 0, 4);
|
2023-10-03 23:34:59 +01:00
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(chunk.sector), 0, 8);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(chunk.sectors), 0, 8);
|
2023-10-03 23:34:59 +01:00
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(chunk.offset), 0, 8);
|
|
|
|
|
|
chunkMs.Write(BigEndianBitConverter.GetBytes(chunk.length), 0, 8);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
byte[] plist = Encoding.UTF8.GetBytes(new NSDictionary
|
|
|
|
|
|
{
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
"resource-fork", new NSDictionary
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
|
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
"blkx", new NSArray
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2022-03-06 13:29:38 +00:00
|
|
|
|
new NSDictionary
|
2018-07-23 23:25:43 +01:00
|
|
|
|
{
|
2023-10-03 23:34:59 +01:00
|
|
|
|
{ "Attributes", "0x0050" },
|
|
|
|
|
|
{ "CFName", "whole disk (Aaru : 0)" },
|
|
|
|
|
|
{ "Data", chunkMs.ToArray() },
|
|
|
|
|
|
{ "ID", "0" },
|
|
|
|
|
|
{ "Name", "whole disk (Aaru : 0)" }
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2022-03-06 13:29:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
}.ToXmlPropertyList());
|
2020-02-29 18:03:35 +00:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_footer = new Footer
|
|
|
|
|
|
{
|
|
|
|
|
|
signature = UDIF_SIGNATURE,
|
|
|
|
|
|
version = 4,
|
|
|
|
|
|
headerSize = 512,
|
|
|
|
|
|
flags = 1,
|
|
|
|
|
|
dataForkLen = (ulong)_writingStream.Length,
|
|
|
|
|
|
segmentNumber = 1,
|
|
|
|
|
|
segmentCount = 1,
|
|
|
|
|
|
segmentId = Guid.NewGuid(),
|
|
|
|
|
|
dataForkChkType = UDIF_CHECKSUM_TYPE_CRC32,
|
|
|
|
|
|
dataForkChkLen = 32,
|
|
|
|
|
|
dataForkChk = BitConverter.ToUInt32(_dataForkChecksum.Final().Reverse().ToArray(), 0),
|
|
|
|
|
|
plistOff = (ulong)_writingStream.Length,
|
|
|
|
|
|
plistLen = (ulong)plist.Length,
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: Find how is this calculated
|
|
|
|
|
|
/*masterChkType = 2,
|
|
|
|
|
|
masterChkLen = 32,
|
|
|
|
|
|
masterChk = BitConverter.ToUInt32(masterChecksum.Final().Reverse().ToArray(), 0),*/
|
|
|
|
|
|
imageVariant = 2,
|
|
|
|
|
|
sectorCount = _imageInfo.Sectors
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
_writingStream.Seek(0, SeekOrigin.End);
|
2023-10-03 23:34:59 +01:00
|
|
|
|
_writingStream.Write(plist, 0, plist.Length);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.signature), 0, 4);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.version), 0, 4);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.headerSize), 0, 4);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.flags), 0, 4);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.runningDataForkOff), 0, 8);
|
2023-10-03 23:34:59 +01:00
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.dataForkOff), 0, 8);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.dataForkLen), 0, 8);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.rsrcForkOff), 0, 8);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.rsrcForkLen), 0, 8);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.segmentNumber), 0, 4);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.segmentCount), 0, 4);
|
|
|
|
|
|
_writingStream.Write(_footer.segmentId.ToByteArray(), 0, 16);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.dataForkChkType), 0, 4);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.dataForkChkLen), 0, 4);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.dataForkChk), 0, 4);
|
|
|
|
|
|
_writingStream.Write(new byte[124], 0, 124);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.plistOff), 0, 8);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.plistLen), 0, 8);
|
|
|
|
|
|
_writingStream.Write(new byte[120], 0, 120);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.masterChkType), 0, 4);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.masterChkLen), 0, 4);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.masterChk), 0, 4);
|
|
|
|
|
|
_writingStream.Write(new byte[124], 0, 124);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.imageVariant), 0, 4);
|
|
|
|
|
|
_writingStream.Write(BigEndianBitConverter.GetBytes(_footer.sectorCount), 0, 8);
|
|
|
|
|
|
_writingStream.Write(new byte[12], 0, 12);
|
2022-03-06 13:29:38 +00:00
|
|
|
|
|
|
|
|
|
|
_writingStream.Flush();
|
|
|
|
|
|
_writingStream.Close();
|
|
|
|
|
|
|
|
|
|
|
|
IsWriting = false;
|
|
|
|
|
|
ErrorMessage = "";
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
// TODO: Comments
|
|
|
|
|
|
/// <inheritdoc />
|
2022-12-15 22:21:07 +00:00
|
|
|
|
public bool SetImageInfo(ImageInfo imageInfo) => 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) => true;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public bool WriteSectorTag(byte[] data, ulong sectorAddress, SectorTagType tag)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
2020-02-29 18:03:35 +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 WriteSectorsTag(byte[] data, ulong sectorAddress, uint length, SectorTagType tag)
|
|
|
|
|
|
{
|
2022-11-29 02:10:37 +00:00
|
|
|
|
ErrorMessage = Localization.Writing_sectors_with_tags_is_not_supported;
|
2020-02-29 18:03:35 +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 />
|
2022-12-15 22:21:07 +00:00
|
|
|
|
public bool SetDumpHardware(List<DumpHardware> dumpHardware) => false;
|
2018-07-23 23:25:43 +01:00
|
|
|
|
|
2022-03-06 13:29:38 +00:00
|
|
|
|
/// <inheritdoc />
|
2022-12-15 22:21:07 +00:00
|
|
|
|
public bool SetMetadata(Metadata metadata) => false;
|
2023-10-03 23:34:59 +01:00
|
|
|
|
|
|
|
|
|
|
#endregion
|
2018-07-23 23:25:43 +01:00
|
|
|
|
}
|