// // 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 represents the list of format parameters that are presented to /// the device when performing a FormatUnit() operation. /// public class FormatParameterList { /// /// See SCSI MMC-4 specification /// public enum UnitFormatType : byte { /// /// See SCSI MMC-4 specification /// FullFormat = 0, /// /// See SCSI MMC-4 specification /// SpareAreaExpansion = 1, /// /// See SCSI MMC-4 specification /// ZoneReformat = 4, /// /// See SCSI MMC-4 specification /// ZoneFormat = 5, /// /// See SCSI MMC-4 specification /// CD_DVD_RW_FullFormat = 0x10, /// /// See SCSI MMC-4 specification /// CD_DVD_RW_GrowSession = 0x11, /// /// See SCSI MMC-4 specification /// CD_DVD_RW_AddSession = 0x12, /// /// See SCSI MMC-4 specification /// DVD_RW_QuickGrowLastSession = 0x13, /// /// See SCSI MMC-4 specification /// DVD_RW_QuickAddSession = 0x14, /// /// See SCSI MMC-4 specification /// DVD_RW_QuickFormat = 0x15, /// /// See SCSI MMC-4 specification /// MRW_FullFormat = 0x24, // CD-RW NumberOfBlocks = 0xffffffff // DVD+RW NumberOfBlocks = 0xffffffff /// /// See SCSI MMC-4 specification /// DVD_Plus_RW_BasicFormat = 0x25, // NumberOfBlock = 0xffffffff /// /// Basic format for DVD+RW (either SL or DL), see SCSI MMC-6 /// DVD_Plus_RW_BasicFormat_DL_SL = 0x26, /// /// Format with spare areas for BluRay-RE /// BDRE_Format_With_Spare_Areas = 0x30, /// /// Format without spare areas for BlueRay-RE /// BDRE_Format_Without_Spare_Areas = 0x31, /// /// Format a BD-R disk with spare area /// BDR_Format_With_Spare_Areas = 0x32 } ; private byte m_flags; /// /// The initializaion pattern for this format operation (not yet supported) /// public InitializationPattern IP; /// /// The format type for this format operation /// public UnitFormatType FormatType; /// /// The subtype for the format /// public byte FormatSubType; /// /// The number of blocks for the format operation /// public uint NumberOfBlocks; /// /// The format type dependent parameter /// public uint Parameter; /// /// Constructor for the parameter list object /// public FormatParameterList() { m_flags = 0; IP = null; } /// /// The size of the format parameters list in bytes, as it will exist in /// the command to the SCSI unit. /// public uint Size { get { return 4 + 8; } } #region public flags /// /// See SCSI MMC-4 specification /// public byte FOV { get { return (byte)((m_flags >> 7) & 0x01); } set { if (value != 0) m_flags |= 0x80; else m_flags &= 0x7f; } } /// /// See SCSI MMC-4 specification /// public byte DPRY { get { return (byte)((m_flags >> 6) & 0x01); } set { if (value != 0) m_flags |= 0x40; else m_flags &= 0xbf; } } /// /// See SCSI MMC-4 specification /// public byte DCRT { get { return (byte)((m_flags >> 5) & 0x01); } set { if (value != 0) m_flags |= 0x20; else m_flags &= 0xdf; } } /// /// See SCSI MMC-4 specification /// public byte STPF { get { return (byte)((m_flags >> 4) & 0x01); } set { if (value != 0) m_flags |= 0x10; else m_flags &= 0xEF; } } /// /// See SCSI MMC-4 specification /// public byte TRYOUT { get { return (byte)((m_flags >> 2) & 0x01); } set { if (value != 0) m_flags |= 0x04; else m_flags &= 0xFB; } } /// /// See SCSI MMC-4 specification /// public byte IMMED { get { return (byte)((m_flags >> 1) & 0x01); } set { if (value != 0) m_flags |= 0x02; else m_flags &= 0xFD; } } /// /// See SCSI MMC-4 specification /// public byte VS { get { return (byte)((m_flags >> 0) & 0x01); } set { if (value != 0) m_flags |= 0x01; else m_flags &= 0xFE; } } #endregion /// /// Format the parameter list to the memory block to be sent down to the device. /// The result should be a format parameter block as seen in the SCSI MMC specs. /// /// public void FormatToMemory(IntPtr dest) { byte v; int offset; Marshal.WriteByte(dest, 0, 0); // Byte 0 - reserved v = m_flags; if (IP != null) v |= 0x08; Marshal.WriteByte(dest, 1, v); // Byte 1 - flags Marshal.WriteByte(dest, 2, 0); Marshal.WriteByte(dest, 3, 8); // Format descriptor length = 8 offset = 4 ; if (IP != null) { // If the initialization pattern exists, it goes here throw new Exception("Not supported yet"); } // Write the # of blocks Marshal.WriteByte(dest, offset++, (byte)((NumberOfBlocks >> 24) & 0xff)); Marshal.WriteByte(dest, offset++, (byte)((NumberOfBlocks >> 16) & 0xff)); Marshal.WriteByte(dest, offset++, (byte)((NumberOfBlocks >> 8) & 0xff)); Marshal.WriteByte(dest, offset++, (byte)((NumberOfBlocks >> 0) & 0xff)); byte b = (byte)(((byte)FormatType << 2) | FormatSubType) ; Marshal.WriteByte(dest, offset++, b) ; Marshal.WriteByte(dest, offset++, (byte)((Parameter >> 16) & 0xff)); Marshal.WriteByte(dest, offset++, (byte)((Parameter >> 8) & 0xff)); Marshal.WriteByte(dest, offset++, (byte)((Parameter >> 0) & 0xff)); } } }