mirror of
https://github.com/aaru-dps/Aaru.git
synced 2025-12-16 19:24:25 +00:00
On Linux try to open in read/write and exclusive mode, if not retry in readonly.
This commit is contained in:
@@ -72,7 +72,8 @@ namespace DiscImageChef.Devices
|
||||
case PlatformID.Win32NT:
|
||||
{
|
||||
FileHandle = Extern.CreateFile(devicePath, FileAccess.GenericRead | FileAccess.GenericWrite,
|
||||
FileShare.Read | FileShare.Write, IntPtr.Zero, FileMode.OpenExisting,
|
||||
FileShare.Read | FileShare.Write, IntPtr.Zero,
|
||||
FileMode.OpenExisting,
|
||||
FileAttributes.Normal, IntPtr.Zero);
|
||||
|
||||
if(((SafeFileHandle)FileHandle).IsInvalid)
|
||||
@@ -85,13 +86,27 @@ namespace DiscImageChef.Devices
|
||||
}
|
||||
case PlatformID.Linux:
|
||||
{
|
||||
FileHandle = Linux.Extern.open(devicePath, FileFlags.Readonly | FileFlags.NonBlocking);
|
||||
FileHandle =
|
||||
Linux.Extern.open(devicePath,
|
||||
FileFlags.ReadWrite | FileFlags.NonBlocking | FileFlags.CreateNew);
|
||||
|
||||
if((int)FileHandle < 0)
|
||||
{
|
||||
LastError = Marshal.GetLastWin32Error();
|
||||
|
||||
if(LastError == 13) // EACCES
|
||||
{
|
||||
FileHandle = Linux.Extern.open(devicePath, FileFlags.Readonly | FileFlags.NonBlocking);
|
||||
if((int)FileHandle < 0)
|
||||
{
|
||||
Error = true;
|
||||
LastError = Marshal.GetLastWin32Error();
|
||||
}
|
||||
}
|
||||
else Error = true;
|
||||
|
||||
LastError = Marshal.GetLastWin32Error();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -224,6 +239,7 @@ namespace DiscImageChef.Devices
|
||||
if(ataid.HasValue) scsiSense = ScsiInquiry(out inqBuf, out _);
|
||||
}
|
||||
else Manufacturer = "ATA";
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -311,6 +327,7 @@ namespace DiscImageChef.Devices
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case PlatformID.Linux:
|
||||
if(devicePath.StartsWith("/dev/sd", StringComparison.Ordinal) ||
|
||||
@@ -323,25 +340,33 @@ namespace DiscImageChef.Devices
|
||||
string devPath = devicePath.Substring(5);
|
||||
if(File.Exists("/sys/block/" + devPath + "/device/csd"))
|
||||
{
|
||||
int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/csd", out cachedCsd);
|
||||
int len =
|
||||
ConvertFromHexAscii("/sys/block/" + devPath + "/device/csd", out cachedCsd);
|
||||
if(len == 0) cachedCsd = null;
|
||||
}
|
||||
|
||||
if(File.Exists("/sys/block/" + devPath + "/device/cid"))
|
||||
{
|
||||
int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/cid", out cachedCid);
|
||||
int len =
|
||||
ConvertFromHexAscii("/sys/block/" + devPath + "/device/cid", out cachedCid);
|
||||
if(len == 0) cachedCid = null;
|
||||
}
|
||||
|
||||
if(File.Exists("/sys/block/" + devPath + "/device/scr"))
|
||||
{
|
||||
int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/scr", out cachedScr);
|
||||
int len =
|
||||
ConvertFromHexAscii("/sys/block/" + devPath + "/device/scr", out cachedScr);
|
||||
if(len == 0) cachedScr = null;
|
||||
}
|
||||
|
||||
if(File.Exists("/sys/block/" + devPath + "/device/ocr"))
|
||||
{
|
||||
int len = ConvertFromHexAscii("/sys/block/" + devPath + "/device/ocr", out cachedOcr);
|
||||
int len =
|
||||
ConvertFromHexAscii("/sys/block/" + devPath + "/device/ocr", out cachedOcr);
|
||||
if(len == 0) cachedOcr = null;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
scsiSense = ScsiInquiry(out inqBuf, out _);
|
||||
@@ -466,6 +491,7 @@ namespace DiscImageChef.Devices
|
||||
UsbSerialString =
|
||||
usbDevice.SerialNumber; // This is incorrect filled by Windows with SCSI/ATA serial number
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
IsUsb = false;
|
||||
@@ -663,7 +689,9 @@ namespace DiscImageChef.Devices
|
||||
if(string.IsNullOrEmpty(Manufacturer)) Manufacturer = UsbManufacturerString;
|
||||
if(string.IsNullOrEmpty(Model)) Model = UsbProductString;
|
||||
if(string.IsNullOrEmpty(Serial)) Serial = UsbSerialString;
|
||||
else foreach(char c in Serial.Where(char.IsControl)) Serial = UsbSerialString;
|
||||
else
|
||||
foreach(char c in Serial.Where(char.IsControl))
|
||||
Serial = UsbSerialString;
|
||||
}
|
||||
|
||||
if(!IsFireWire) return;
|
||||
@@ -671,7 +699,9 @@ namespace DiscImageChef.Devices
|
||||
if(string.IsNullOrEmpty(Manufacturer)) Manufacturer = FireWireVendorName;
|
||||
if(string.IsNullOrEmpty(Model)) Model = FireWireModelName;
|
||||
if(string.IsNullOrEmpty(Serial)) Serial = $"{firewireGuid:X16}";
|
||||
else foreach(char c in Serial.Where(char.IsControl)) Serial = $"{firewireGuid:X16}";
|
||||
else
|
||||
foreach(char c in Serial.Where(char.IsControl))
|
||||
Serial = $"{firewireGuid:X16}";
|
||||
}
|
||||
|
||||
static int ConvertFromHexAscii(string file, out byte[] outBuf)
|
||||
|
||||
Reference in New Issue
Block a user