* DiscImageChef.Devices/Device/Constructor.cs:

Added support for USB on Linux.

	* DiscImageChef/Commands/DeviceInfo.cs:
	* DiscImageChef.Devices/Device/Variables.cs:
	  Added support for USB detection and metadata.

	* DiscImageChef.Devices/Linux/Extern.cs:
	* DiscImageChef.Devices/Linux/Command.cs:
	  Added readlink(3) support, for getting symlink destinations.
This commit is contained in:
2015-12-31 16:12:22 +00:00
parent da29ec63eb
commit eac5aae66c
7 changed files with 255 additions and 0 deletions

View File

@@ -328,6 +328,34 @@ namespace DiscImageChef.Devices.Linux
return error;
}
public static string ReadLink(string path)
{
IntPtr buf = Marshal.AllocHGlobal(int.MaxValue);
int resultSize;
if (Interop.DetectOS.Is64Bit())
{
long result64 = Extern.readlink64(path, buf, (long)int.MaxValue);
if (result64 <= 0)
return null;
resultSize = (int)result64;
}
else
{
int result = Extern.readlink(path, buf, int.MaxValue);
if (result <= 0)
return null;
resultSize = result;
}
byte[] resultString = new byte[resultSize];
Marshal.Copy(buf, resultString, 0, resultSize);
Marshal.FreeHGlobal(buf);
return System.Text.Encoding.ASCII.GetString(resultString);
}
}
}

View File

@@ -56,6 +56,12 @@ namespace DiscImageChef.Devices.Linux
[DllImport("libc", EntryPoint="ioctl", SetLastError = true)]
internal static extern int ioctlSg(int fd, LinuxIoctl request, ref sg_io_hdr_t value);
[DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)]
internal static extern int readlink(string path, System.IntPtr buf, int bufsize);
[DllImport("libc", CharSet = CharSet.Ansi, EntryPoint="readlink", SetLastError = true)]
internal static extern long readlink64(string path, System.IntPtr buf, long bufsize);
}
}