Click here to Skip to main content
15,886,018 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 145.3K   8.1K   146  
Ever wonder how programs like Nero work? They make their own SCSI libraries... like this!
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Helper;

namespace Scsi.Multimedia
{
	[StructLayout(LayoutKind.Sequential, Pack = 1)]
	public class ProgramMemoryArea : TocPmaAtipResponseData
	{
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private static readonly IntPtr PMA_DESCRIPTORS_OFFSET = Marshal.OffsetOf(typeof(ProgramMemoryArea), "_PmaDescriptors");

		public ProgramMemoryArea() : base() { }

		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 1)]
		private ProgramMemoryAreaDescriptor[] _PmaDescriptors;
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.RootHidden)]
		public ProgramMemoryAreaDescriptor[] PmaDescriptors { get { return this._PmaDescriptors; } set { this._PmaDescriptors = value; } }

		protected override void MarshalFrom(BufferWithSize buffer)
		{
			base.MarshalFrom(buffer);
			this._PmaDescriptors = new ProgramMemoryAreaDescriptor[(this.DataLength + sizeof(ushort) - base.MarshaledSize) / Marshaler.DefaultSizeOf<ProgramMemoryAreaDescriptor>()];
			for (int i = 0; i < this._PmaDescriptors.Length; i++)
			{ this._PmaDescriptors[i] = Marshaler.PtrToStructure<ProgramMemoryAreaDescriptor>(buffer.ExtractSegment((int)PMA_DESCRIPTORS_OFFSET + i * Marshaler.DefaultSizeOf<ProgramMemoryAreaDescriptor>(), Marshaler.DefaultSizeOf<ProgramMemoryAreaDescriptor>())); }
		}

		protected override void MarshalTo(BufferWithSize buffer)
		{
			base.MarshalTo(buffer);
			for (int i = 0; i < this._PmaDescriptors.Length; i++)
			{ Marshaler.StructureToPtr(this._PmaDescriptors[i], buffer.ExtractSegment((int)PMA_DESCRIPTORS_OFFSET + i * Marshaler.DefaultSizeOf<ProgramMemoryAreaDescriptor>(), Marshaler.SizeOf(this._PmaDescriptors[i]))); }
		}

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		protected override int MarshaledSize { get { return Marshaler.DefaultSizeOf<ProgramMemoryArea>(); } }
	}

	public struct ProgramMemoryAreaDescriptor
	{
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		private byte _SessionNumber;
		public byte SessionNumber { get { return this._SessionNumber; } set { this._SessionNumber = value; } }
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private byte _AddressControl;
		public CDControl Control { get { return unchecked((CDControl)(this._AddressControl & 0xF0)); } private set { this._AddressControl = (byte)((this._AddressControl & ~0xF0) | ((byte)value & 0xF0)); } }
		public CDAddress Address { get { return unchecked((CDAddress)(this._AddressControl & 0x0F)); } private set { this._AddressControl = (byte)((this._AddressControl & ~0x0F) | ((byte)value & 0x0F)); } }
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		private byte _TrackNumber;
		public byte TrackNumber { get { return this._TrackNumber; } set { this._TrackNumber = value; } }
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		private byte _Point;
		public byte Point { get { return this._Point; } set { this._Point = value; } }
		//Do not use the Msf structure, since sometimes these values don't actually represent time
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		private byte _Minute;
		public byte Minute { get { return this._Minute; } set { this._Minute = value; } }
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		private byte _Second;
		public byte Second { get { return this._Second; } set { this._Second = value; } }
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		private byte _Frame;
		public byte Frame { get { return this._Frame; } set { this._Frame = value; } }
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		private byte _HourPHour;
		public byte HourPHour { get { return this._HourPHour; } set { this._HourPHour = value; } }
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		private byte _PMinute;
		public byte PMinute { get { return this._PMinute; } set { this._PMinute = value; } }
		[DebuggerBrowsableAttribute(DebuggerBrowsableState.Never)]
		private byte _PSecond;
		public byte PSecond { get { return this._PSecond; } set { this._PSecond = value; } }
	}
}

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