diff --git a/DiscImageChef.Devices/ChangeLog b/DiscImageChef.Devices/ChangeLog index 84f4a516..bbd27297 100644 --- a/DiscImageChef.Devices/ChangeLog +++ b/DiscImageChef.Devices/ChangeLog @@ -1,3 +1,13 @@ +2015-10-06 Natalia Portillo + + * Linux/Enums.cs: + * Linux/Extern.cs: + * Linux/Structs.cs: + Filled Linux enums. + + * Windows/Enums.cs: + Typo + 2015-10-06 Natalia Portillo * Windows/Extern.cs: diff --git a/DiscImageChef.Devices/Linux/Enums.cs b/DiscImageChef.Devices/Linux/Enums.cs index d9e7bb67..31b7f895 100644 --- a/DiscImageChef.Devices/Linux/Enums.cs +++ b/DiscImageChef.Devices/Linux/Enums.cs @@ -2,19 +2,151 @@ namespace DiscImageChef.Devices.Linux { - static class Enums + [Flags] + enum FileFlags : int { - internal const int O_RDONLY = 0; - internal const int O_RDWR = 2; + /// + /// O_RDONLY + /// + Readonly = 00000000, + /// + /// O_WRONLY + /// + Writeonly = 00000001, + /// + /// O_RDWR + /// + ReadWrite = 00000002, + /// + /// O_CREAT + /// + OpenOrCreate = 00000100, + /// + /// O_EXCL + /// + CreateNew = 00000200, + /// + /// O_NOCTTY + /// + NoControlTTY = 00000400, + /// + /// O_TRUNC + /// + Truncate = 00001000, + /// + /// O_APPEND + /// + Append = 00002000, + /// + /// O_NONBLOCK + /// + NonBlocking = 00004000, + /// + /// O_DSYNC + /// + Synchronous = 00010000, + /// + /// O_ASYNC + /// + Async = 00020000, + /// + /// O_DIRECT + /// + Direct = 00040000, + /// + /// O_LARGEFILE + /// + LargeFile = 00100000, + /// + /// O_DIRECTORY + /// + Directory = 00200000, + /// + /// O_NOFOLLOW + /// + NoFollowSymlink = 00400000, + /// + /// O_NOATIME + /// + NoAccessTime = 01000000, + /// + /// O_CLOEXEC + /// + CloseOnExec = 02000000 + } - internal const ulong SG_GET_VERSION_NUM = 0x2282; - internal const ulong SG_IO = 0x2285; + /// + /// Direction of SCSI transfer + /// + enum ScsiIoctlDirection : int + { + /// + /// No data transfer happens + /// SG_DXFER_NONE + /// + None = -1, + /// + /// From host to device + /// SG_DXFER_TO_DEV + /// + Out = -2, + /// + /// From device to host + /// SG_DXFER_FROM_DEV + /// + In = -3, + /// + /// Bidirectional device/host + /// SG_DXFER_TO_FROM_DEV + /// + Unspecified = -4, + /// + /// Unspecified + /// SG_DXFER_UNKNOWN + /// + Unknown = -5 + } - internal const int SG_DXFER_FROM_DEV = -3; + enum LinuxIoctl : ulong + { + SG_EMULATED_HOST = 0x2203, + SG_GET_VERSION_NUM = 0x2282, + SG_IO = 0x2285, + SG_GET_SCSI_ID = 0x2276, + } - internal const uint SG_INFO_OK_MASK = 0x1; - internal const uint SG_INFO_OK = 0x0; /* no sense, host nor driver "noise" */ - internal const uint SG_INFO_CHECK = 0x1; + [Flags] + enum SgInfo : uint + { + /// + /// Mask to check OK + /// + OkMask = 0x01, + /// + /// No sense or driver noise + /// + Ok = 0x00, + /// + /// Check Condition + /// + CheckCondition = 0x01, + + /// + /// Direct I/O mask + /// + DirectIoMask = 0x06, + /// + /// Transfer via kernel buffers (or no transfer) + /// + IndirectIo = 0x00, + /// + /// Direct I/O performed + /// + DirectIo = 0x02, + /// + /// Partial direct and partial indirect I/O + /// + MixedIo = 0x04 } } diff --git a/DiscImageChef.Devices/Linux/Extern.cs b/DiscImageChef.Devices/Linux/Extern.cs index 8aeb659f..19f21f6e 100644 --- a/DiscImageChef.Devices/Linux/Extern.cs +++ b/DiscImageChef.Devices/Linux/Extern.cs @@ -5,7 +5,10 @@ namespace DiscImageChef.Devices.Linux static class Extern { [DllImport("libc", CharSet = CharSet.Ansi, SetLastError = true)] - internal static extern int open(string pathname, int flags); + internal static extern int open( + string pathname, + [MarshalAs(UnmanagedType.U4)] + FileFlags flags); [DllImport("libc")] internal static extern int close(int fd); @@ -14,7 +17,7 @@ namespace DiscImageChef.Devices.Linux internal static extern int ioctlInt(int fd, ulong request, out int value); [DllImport("libc", EntryPoint="ioctl", SetLastError = true)] - internal static extern int ioctlSg(int fd, ulong request, ref Structs.sg_io_hdr_t value); + internal static extern int ioctlSg(int fd, ulong request, ref sg_io_hdr_t value); } } diff --git a/DiscImageChef.Devices/Linux/Structs.cs b/DiscImageChef.Devices/Linux/Structs.cs index f98d18d1..bc9d223a 100644 --- a/DiscImageChef.Devices/Linux/Structs.cs +++ b/DiscImageChef.Devices/Linux/Structs.cs @@ -3,37 +3,34 @@ using System.Runtime.InteropServices; namespace DiscImageChef.Devices.Linux { - static class Structs + [StructLayout(LayoutKind.Sequential)] + struct sg_io_hdr_t { - [StructLayout(LayoutKind.Sequential)] - internal struct sg_io_hdr_t - { - /// - /// Always 'S' for SG v3 - /// - public int interface_id; /* [i] 'S' (required) */ - public int dxfer_direction; /* [i] */ - public byte cmd_len; /* [i] */ - public byte mx_sb_len; /* [i] */ - public ushort iovec_count; /* [i] */ - public uint dxfer_len; /* [i] */ - public IntPtr dxferp; /* [i], [*io] */ - public IntPtr cmdp; /* [i], [*i] */ - public IntPtr sbp; /* [i], [*o] */ - public uint timeout; /* [i] unit: millisecs */ - public uint flags; /* [i] */ - public int pack_id; /* [i->o] */ - public IntPtr usr_ptr; /* [i->o] */ - public byte status; /* [o] */ - public byte masked_status;/* [o] */ - public byte msg_status; /* [o] */ - public byte sb_len_wr; /* [o] */ - public ushort host_status; /* [o] */ - public ushort driver_status;/* [o] */ - public int resid; /* [o] */ - public uint duration; /* [o] */ - public uint info; /* [o] */ - } + /// + /// Always 'S' for SG v3 + /// + public int interface_id; /* [i] 'S' (required) */ + public int dxfer_direction; /* [i] */ + public byte cmd_len; /* [i] */ + public byte mx_sb_len; /* [i] */ + public ushort iovec_count; /* [i] */ + public ScsiIoctlDirection dxfer_len; /* [i] */ + public IntPtr dxferp; /* [i], [*io] */ + public IntPtr cmdp; /* [i], [*i] */ + public IntPtr sbp; /* [i], [*o] */ + public uint timeout; /* [i] unit: millisecs */ + public uint flags; /* [i] */ + public int pack_id; /* [i->o] */ + public IntPtr usr_ptr; /* [i->o] */ + public byte status; /* [o] */ + public byte masked_status;/* [o] */ + public byte msg_status; /* [o] */ + public byte sb_len_wr; /* [o] */ + public ushort host_status; /* [o] */ + public ushort driver_status;/* [o] */ + public int resid; /* [o] */ + public uint duration; /* [o] */ + public SgInfo info; /* [o] */ } } diff --git a/DiscImageChef.Devices/Windows/Enums.cs b/DiscImageChef.Devices/Windows/Enums.cs index 5a33ef0c..00e1f09f 100644 --- a/DiscImageChef.Devices/Windows/Enums.cs +++ b/DiscImageChef.Devices/Windows/Enums.cs @@ -236,8 +236,5 @@ namespace DiscImageChef.Devices.Windows /// IOCTL_SCSI_GET_ADDRESS = 0x41018 } - /// - /// AAAAA - /// }