Implemente remote Get PCMCIA Data packet.

This commit is contained in:
2019-10-19 01:10:06 +01:00
parent b7f6170a1f
commit a8f3fc912d
2 changed files with 109 additions and 34 deletions

View File

@@ -656,51 +656,62 @@ namespace DiscImageChef.Devices
#region PCMCIA
if (PlatformId == PlatformID.Linux)
if(remote is null)
{
if (devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
if (PlatformId == PlatformID.Linux)
{
var devPath = devicePath.Substring(5);
if (Directory.Exists("/sys/block/" + devPath))
if (devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/sr", StringComparison.Ordinal) ||
devicePath.StartsWith("/dev/st", StringComparison.Ordinal))
{
var resolvedLink = Linux.Command.ReadLink("/sys/block/" + devPath);
resolvedLink = "/sys" + resolvedLink.Substring(2);
if (!string.IsNullOrEmpty(resolvedLink))
while (resolvedLink.Contains("/sys/devices"))
{
resolvedLink = Path.GetDirectoryName(resolvedLink);
if (!Directory.Exists(resolvedLink + "/pcmcia_socket")) continue;
var devPath = devicePath.Substring(5);
if (Directory.Exists("/sys/block/" + devPath))
{
var resolvedLink = Linux.Command.ReadLink("/sys/block/" + devPath);
resolvedLink = "/sys" + resolvedLink.Substring(2);
if (!string.IsNullOrEmpty(resolvedLink))
while (resolvedLink.Contains("/sys/devices"))
{
resolvedLink = Path.GetDirectoryName(resolvedLink);
if (!Directory.Exists(resolvedLink + "/pcmcia_socket")) continue;
var subdirs = Directory.GetDirectories(resolvedLink + "/pcmcia_socket",
"pcmcia_socket*",
SearchOption.TopDirectoryOnly);
var subdirs = Directory.GetDirectories(resolvedLink + "/pcmcia_socket",
"pcmcia_socket*",
SearchOption.TopDirectoryOnly);
if (subdirs.Length <= 0) continue;
if (subdirs.Length <= 0) continue;
var possibleDir = Path.Combine(resolvedLink, "pcmcia_socket", subdirs[0]);
if (!File.Exists(possibleDir + "/card_type") || !File.Exists(possibleDir + "/cis"))
continue;
var possibleDir = Path.Combine(resolvedLink, "pcmcia_socket", subdirs[0]);
if (!File.Exists(possibleDir + "/card_type") || !File.Exists(possibleDir + "/cis"))
continue;
var cisFs = new FileStream(possibleDir + "/cis", System.IO.FileMode.Open,
System.IO.FileAccess.Read);
var cisBuf = new byte[65536];
var cisCount = cisFs.Read(cisBuf, 0, 65536);
Cis = new byte[cisCount];
Array.Copy(cisBuf, 0, Cis, 0, cisCount);
cisFs.Close();
var cisFs = new FileStream(possibleDir + "/cis", System.IO.FileMode.Open,
System.IO.FileAccess.Read);
var cisBuf = new byte[65536];
var cisCount = cisFs.Read(cisBuf, 0, 65536);
Cis = new byte[cisCount];
Array.Copy(cisBuf, 0, Cis, 0, cisCount);
cisFs.Close();
IsPcmcia = true;
break;
}
IsPcmcia = true;
break;
}
}
}
}
// TODO: Implement for other operating systems
else
{
IsPcmcia = false;
}
}
// TODO: Implement for other operating systems
else
{
IsPcmcia = false;
if (remote.GetPcmciaData(out var cisBuf))
{
IsPcmcia = true;
Cis = cisBuf;
}
}
#endregion PCMCIA

View File

@@ -751,7 +751,7 @@ namespace DiscImageChef.Devices.Remote
return false;
}
if (hdr.packetType != DicPacketType.ResponseGetUsbData)
if (hdr.packetType != DicPacketType.ResponseGetFireWireData)
{
DicConsole.ErrorWriteLine("Expected FireWire Data Response Packet, got packet type {0}...",
hdr.packetType);
@@ -783,7 +783,71 @@ namespace DiscImageChef.Devices.Remote
public bool GetPcmciaData(out byte[] cis)
{
throw new NotImplementedException("Getting PCMCIA data not yet implemented...");
cis = null;
var cmdPkt = new DicPacketCmdGetPcmciaData()
{
hdr = new DicPacketHeader
{
id = Consts.PacketId,
len = (uint) Marshal.SizeOf<DicPacketCmdGetPcmciaData>(),
version = Consts.PacketVersion,
packetType = DicPacketType.CommandGetPcmciaData
}
};
var buf = Marshal.StructureToByteArrayLittleEndian(cmdPkt);
var len = _socket.Send(buf, SocketFlags.None);
if (len != buf.Length)
{
DicConsole.ErrorWriteLine("Could not write to the network...");
return false;
}
var hdrBuf = new byte[Marshal.SizeOf<DicPacketHeader>()];
len = _socket.Receive(hdrBuf, hdrBuf.Length, SocketFlags.Peek);
if (len < hdrBuf.Length)
{
DicConsole.ErrorWriteLine("Could not read from the network...");
return false;
}
var hdr = Marshal.ByteArrayToStructureLittleEndian<DicPacketHeader>(hdrBuf);
if (hdr.id != Consts.PacketId)
{
DicConsole.ErrorWriteLine("Received data is not a DIC Remote Packet...");
return false;
}
if (hdr.packetType != DicPacketType.ResponseGetPcmciaData)
{
DicConsole.ErrorWriteLine("Expected PCMCIA Data Response Packet, got packet type {0}...",
hdr.packetType);
return false;
}
buf = new byte[hdr.len];
len = _socket.Receive(buf, buf.Length, SocketFlags.None);
if (len < buf.Length)
{
DicConsole.ErrorWriteLine("Could not read from the network...");
return false;
}
var res = Marshal.ByteArrayToStructureLittleEndian<DicPacketResGetPcmciaData>(buf);
if (!res.isPcmcia)
return false;
cis = res.cis;
return true;
}
}
}