//
// BwgBurn - CD-R/CD-RW/DVD-R/DVD-RW burning program for Windows XP
//
// Copyright (C) 2006 by Jack W. Griffin (butchg@comcast.net)
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the
//
// Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330,
// Boston, MA 02111-1307 USA
//
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices ;
namespace Bwg.Scsi
{
///
/// This class is used to buffer data to the SCSI device when
/// writing large amounts of data to the SCSI device.
///
public class WriteBuffer : IDisposable
{
[DllImport("ntdll.dll")]
internal static extern void RtlZeroMemory(IntPtr dest, int size);
[DllImport("ntdll.dll")]
internal static extern void RtlFillMemory(IntPtr dest, int size, byte value);
#region public data members
///
/// The size of the buffer associated with this object (in sectors)
///
public int BufferSize;
///
/// The amount of data stored in the buffer (in sectors)
///
public int DataSize;
///
/// The size of a sector of data stored in this buffer page
///
public int SectorSize;
///
/// This contains the logical block address for this block of data
///
public long LogicalBlockAddress;
///
/// The source of this buffer, used only for debugging
///
public string SourceString;
#endregion
#region private data members
///
/// The actual buffer memory
///
private IntPtr m_buffer_ptr;
#endregion
#region public properties
///
/// Returns a buffer pointer to the internal buffer.
///
public IntPtr BufferPtr
{
get
{
return m_buffer_ptr;
}
}
#endregion
#region constructors
///
/// Create a new buffer object
///
/// the size of the buffer
public WriteBuffer(int size)
{
m_buffer_ptr = Marshal.AllocHGlobal((int)size);
BufferSize = size;
LogicalBlockAddress = long.MaxValue;
}
#endregion
#region public methods
///
/// Free the memory associated with this buffer object
///
public void Dispose()
{
Marshal.FreeHGlobal(m_buffer_ptr);
}
///
/// Fill the buffer with all zeros
///
public void Zero()
{
RtlZeroMemory(m_buffer_ptr, BufferSize) ;
}
///
/// Fill the buffer with data of a specific byte.
///
///
public void Fill(byte b)
{
RtlFillMemory(m_buffer_ptr, BufferSize, b);
}
#endregion
}
}