2017-08-08 21:15:14 +01:00
|
|
|
|
// /***************************************************************************
|
|
|
|
|
|
// The Disc Image Chef
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// Filename : BlockTape.cs
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
2017-08-08 21:15:14 +01:00
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Component : Core algorithms.
|
2017-08-08 21:15:14 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ Description ] ----------------------------------------------------------
|
|
|
|
|
|
//
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Contains logic to create sidecar from a block tape media dump.
|
2017-08-08 21:15:14 +01:00
|
|
|
|
//
|
|
|
|
|
|
// --[ License ] --------------------------------------------------------------
|
|
|
|
|
|
//
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
|
// it under the terms of the GNU General Public License as
|
|
|
|
|
|
// 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
|
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
|
//
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
//
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
2017-12-19 03:50:57 +00:00
|
|
|
|
// Copyright © 2011-2018 Natalia Portillo
|
2017-08-08 21:15:14 +01:00
|
|
|
|
// ****************************************************************************/
|
|
|
|
|
|
|
2017-12-19 03:50:57 +00:00
|
|
|
|
using System.Collections.Generic;
|
2017-08-08 21:15:14 +01:00
|
|
|
|
using System.IO;
|
2017-12-19 19:33:46 +00:00
|
|
|
|
using Schemas;
|
2017-08-08 21:15:14 +01:00
|
|
|
|
|
|
|
|
|
|
namespace DiscImageChef.Core
|
|
|
|
|
|
{
|
|
|
|
|
|
public static partial class Sidecar
|
|
|
|
|
|
{
|
2017-12-23 01:46:08 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Creates a metadata sidecar for a block tape (e.g. scsi streaming)
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="files">List of files</param>
|
|
|
|
|
|
/// <param name="folderName">Dump path</param>
|
|
|
|
|
|
/// <param name="blockSize">Expected block size in bytes</param>
|
2017-08-08 21:15:14 +01:00
|
|
|
|
public static CICMMetadataType Create(string folderName, List<string> files, int blockSize)
|
|
|
|
|
|
{
|
|
|
|
|
|
CICMMetadataType sidecar = new CICMMetadataType
|
|
|
|
|
|
{
|
|
|
|
|
|
BlockMedia = new[]
|
2017-12-19 20:33:03 +00:00
|
|
|
|
{
|
|
|
|
|
|
new BlockMediaType
|
|
|
|
|
|
{
|
|
|
|
|
|
Image = new ImageType {format = "Directory", offsetSpecified = false, Value = folderName},
|
|
|
|
|
|
Sequence = new SequenceType {MediaTitle = folderName, MediaSequence = 1, TotalMedia = 1},
|
2017-12-21 14:30:38 +00:00
|
|
|
|
PhysicalBlockSize = blockSize,
|
|
|
|
|
|
LogicalBlockSize = blockSize,
|
2017-12-19 20:33:03 +00:00
|
|
|
|
TapeInformation = new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
new TapePartitionType
|
|
|
|
|
|
{
|
|
|
|
|
|
Image = new ImageType
|
|
|
|
|
|
{
|
|
|
|
|
|
format = "Directory",
|
|
|
|
|
|
offsetSpecified = false,
|
|
|
|
|
|
Value = folderName
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-08-08 21:15:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
long currentBlock = 0;
|
|
|
|
|
|
long totalSize = 0;
|
|
|
|
|
|
Checksum tapeWorker = new Checksum();
|
|
|
|
|
|
List<TapeFileType> tapeFiles = new List<TapeFileType>();
|
|
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < files.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
FileStream fs = new FileStream(files[i], FileMode.Open, FileAccess.Read);
|
|
|
|
|
|
Checksum fileWorker = new Checksum();
|
|
|
|
|
|
TapeFileType tapeFile = new TapeFileType
|
|
|
|
|
|
{
|
|
|
|
|
|
Image = new ImageType
|
|
|
|
|
|
{
|
|
|
|
|
|
format = "Raw disk image (sector by sector copy)",
|
|
|
|
|
|
offset = 0,
|
|
|
|
|
|
Value = Path.GetFileName(files[i])
|
|
|
|
|
|
},
|
|
|
|
|
|
Size = fs.Length,
|
|
|
|
|
|
BlockSize = blockSize,
|
|
|
|
|
|
StartBlock = currentBlock,
|
|
|
|
|
|
Sequence = i
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-12-21 23:00:30 +00:00
|
|
|
|
const uint SECTORS_TO_READ = 512;
|
2017-08-08 21:15:14 +01:00
|
|
|
|
long sectors = fs.Length / blockSize;
|
|
|
|
|
|
long doneSectors = 0;
|
|
|
|
|
|
|
|
|
|
|
|
InitProgress2();
|
|
|
|
|
|
while(doneSectors < sectors)
|
|
|
|
|
|
{
|
|
|
|
|
|
byte[] sector;
|
|
|
|
|
|
|
2017-12-21 23:00:30 +00:00
|
|
|
|
if(sectors - doneSectors >= SECTORS_TO_READ)
|
2017-08-08 21:15:14 +01:00
|
|
|
|
{
|
2017-12-21 23:00:30 +00:00
|
|
|
|
sector = new byte[SECTORS_TO_READ * blockSize];
|
2017-08-08 21:15:14 +01:00
|
|
|
|
fs.Read(sector, 0, sector.Length);
|
2017-12-21 17:58:51 +00:00
|
|
|
|
UpdateProgress2($"Hashing block {doneSectors} of {sectors} on file {i + 1} of {files.Count}",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
doneSectors, sectors);
|
2017-12-21 23:00:30 +00:00
|
|
|
|
doneSectors += SECTORS_TO_READ;
|
2017-08-08 21:15:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sector = new byte[(uint)(sectors - doneSectors) * blockSize];
|
|
|
|
|
|
fs.Read(sector, 0, sector.Length);
|
2017-12-21 17:58:51 +00:00
|
|
|
|
UpdateProgress2($"Hashing block {doneSectors} of {sectors} on file {i + 1} of {files.Count}",
|
2017-12-19 20:33:03 +00:00
|
|
|
|
doneSectors, sectors);
|
2017-12-20 17:26:28 +00:00
|
|
|
|
doneSectors += sectors - doneSectors;
|
2017-08-08 21:15:14 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fileWorker.Update(sector);
|
|
|
|
|
|
tapeWorker.Update(sector);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-20 17:26:28 +00:00
|
|
|
|
tapeFile.EndBlock = tapeFile.StartBlock + sectors - 1;
|
2017-08-08 21:15:14 +01:00
|
|
|
|
currentBlock += sectors;
|
|
|
|
|
|
totalSize += fs.Length;
|
|
|
|
|
|
tapeFile.Checksums = fileWorker.End().ToArray();
|
|
|
|
|
|
tapeFiles.Add(tapeFile);
|
|
|
|
|
|
|
|
|
|
|
|
EndProgress2();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sidecar.BlockMedia[0].Checksums = tapeWorker.End().ToArray();
|
|
|
|
|
|
sidecar.BlockMedia[0].ContentChecksums = sidecar.BlockMedia[0].Checksums;
|
|
|
|
|
|
sidecar.BlockMedia[0].Size = totalSize;
|
|
|
|
|
|
sidecar.BlockMedia[0].LogicalBlocks = currentBlock;
|
|
|
|
|
|
sidecar.BlockMedia[0].TapeInformation[0].EndBlock = currentBlock - 1;
|
|
|
|
|
|
sidecar.BlockMedia[0].TapeInformation[0].Size = totalSize;
|
|
|
|
|
|
sidecar.BlockMedia[0].TapeInformation[0].Checksums = sidecar.BlockMedia[0].Checksums;
|
|
|
|
|
|
sidecar.BlockMedia[0].TapeInformation[0].File = tapeFiles.ToArray();
|
|
|
|
|
|
|
|
|
|
|
|
// This is purely for convenience, as typically these kind of data represents QIC tapes
|
|
|
|
|
|
if(blockSize == 512)
|
|
|
|
|
|
{
|
|
|
|
|
|
sidecar.BlockMedia[0].DiskType = "Quarter-inch cartridge";
|
|
|
|
|
|
|
2017-12-19 20:33:03 +00:00
|
|
|
|
if(totalSize <= 20 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-11";
|
|
|
|
|
|
else if(totalSize <= 40 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-40";
|
|
|
|
|
|
else if(totalSize <= 60 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-24";
|
|
|
|
|
|
else if(totalSize <= 80 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-80";
|
|
|
|
|
|
else if(totalSize <= 120 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-120";
|
|
|
|
|
|
else if(totalSize <= 150 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-150";
|
|
|
|
|
|
else if(totalSize <= 320 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-320";
|
|
|
|
|
|
else if(totalSize <= 340 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-3010";
|
|
|
|
|
|
else if(totalSize <= 525 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-525";
|
|
|
|
|
|
else if(totalSize <= 670 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-3020";
|
|
|
|
|
|
else if(totalSize <= 1200 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-3080";
|
|
|
|
|
|
else if(totalSize <= 1350 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-1350";
|
|
|
|
|
|
else if(totalSize <= (long)4000 * 1048576) sidecar.BlockMedia[0].DiskSubType = "QIC-3095";
|
2017-08-08 21:15:14 +01:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sidecar.BlockMedia[0].DiskType = "Unknown tape";
|
|
|
|
|
|
sidecar.BlockMedia[0].DiskSubType = "Unknown tape";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
sidecar.BlockMedia[0].DiskType = "Unknown tape";
|
|
|
|
|
|
sidecar.BlockMedia[0].DiskSubType = "Unknown tape";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sidecar;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-12-19 20:33:03 +00:00
|
|
|
|
}
|