Click here to Skip to main content
15,897,273 members
Articles / Programming Languages / C#

SCSI Library in C# - Burn CDs and DVDs, Access Hard Disks, etc.

Rate me:
Please Sign up or sign in to vote.
4.77/5 (48 votes)
19 Jun 2017Ms-PL6 min read 146.4K   8.1K   146  
Ever wonder how programs like Nero work? They make their own SCSI libraries... like this!
using System.Diagnostics;
using System.Runtime.InteropServices;
using Helper;

namespace Scsi
{
	[StructLayout(LayoutKind.Sequential, Pack = 1)]
	public class ReadBufferCommand : FixedLengthScsiCommand
	{
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private const byte MODE_MASK = 0x1F;
		public ReadBufferCommand() : base(ScsiCommandCode.ReadBuffer) { }
		public ReadBufferCommand(byte bufferId, uint offset) : this() { this.BufferId = bufferId; this.BufferOffset = offset; }
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private byte byte1;
		public ReadBufferMode Mode
		{
			get { return (ReadBufferMode)Bits.GetValueMask(this.byte1, 0, MODE_MASK); }
			set { this.byte1 = Bits.PutValueMask(this.byte1, (byte)value, 0, MODE_MASK); }
		}
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private byte _BufferId;
		public byte BufferId { get { return this._BufferId; } set { this._BufferId = value; } }
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private byte _byte3; //MSB
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private byte _byte4;
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private byte _byte5; //LSB
		public uint BufferOffset
		{
			get { unchecked { return (uint)this._byte5 | ((uint)this._byte4 << 8) | ((uint)this._byte3 << 16); } }
			set { unchecked { this._byte5 = (byte)(value >> 0); this._byte4 = (byte)(value >> 8); this._byte3 = (byte)(value >> 16); } }
		}
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private byte _byte6; //MSB
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private byte _byte7;
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private byte _byte8; //LSB
		/// <summary>Do not use this value unless you are responsible for calling the <see cref="IScsiPassThrough.ExecuteCommand"/> method directly.</summary>
		public uint AllocationLength
		{
			get { unchecked { return (uint)this._byte8 | ((uint)this._byte7 << 8) | ((uint)this._byte6 << 16); } }
			set { unchecked { this._byte8 = (byte)(value >> 0); this._byte7 = (byte)(value >> 8); this._byte6 = (byte)(value >> 16); } }
		}
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private CommandControl _Control;
		public override CommandControl Control { get { return this._Control; } set { this._Control = value; } }

		public override ScsiTimeoutGroup TimeoutGroup { get { return ScsiTimeoutGroup.Group1; } }
	}

	public enum ReadBufferMode : byte
	{
		CombinedHeaderAndData = 0x00,
		VendorSpecific = 0x01,
		Data = 0x02,
		Descriptor = 0x03,
		ReadDataFromEchoBuffer = 0x0A,
		EchoBufferDescriptor = 0x0B,
		EnableExpansionCommunicationsProtocolAndEchoBuffer = 0x1A,
		ErrorHistory = 0x1C,
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions