Click here to Skip to main content
15,884,473 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 FileSystems.Udf
{
	[StructLayout(LayoutKind.Sequential, Pack = 1, CharSet = CharSet.Ansi)]
	public class TerminatingExtendedAreaDescriptor : UdfVolumeStructureDescriptor
	{
		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		private static readonly IntPtr STRUCTURE_DATA_BP = (IntPtr)7; //Marshal.OffsetOf(typeof(TerminatingExtendedAreaDescriptor), "_StructureData");

		public TerminatingExtendedAreaDescriptor() : base("TEA01", 1) { }

		[DebuggerBrowsable(DebuggerBrowsableState.Never)]
		[MarshalAs(UnmanagedType.ByValArray, SizeConst = 2041)]
		private byte[] _StructureData = new byte[2041];
		public byte[] StructureData { get { return this._StructureData; } }

		protected override void MarshalFrom(BufferWithSize buffer)
		{
			base.MarshalFrom(buffer);
			this._StructureData = new byte[2041];
			buffer.CopyTo((int)STRUCTURE_DATA_BP, this._StructureData, 0, this._StructureData.Length);
		}

		protected override void MarshalTo(BufferWithSize buffer)
		{
			base.MarshalTo(buffer);
			if (this._StructureData.Length > 2041) { throw new OverflowException("Field is too large."); }
			buffer.CopyFrom((int)STRUCTURE_DATA_BP, this._StructureData, 0, this._StructureData.Length);
			buffer.Initialize((int)STRUCTURE_DATA_BP + this._StructureData.Length, 2041 - this._StructureData.Length);
		}

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

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