Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        public override void Write(byte[] buffer, int offset, int count)
        {
            while (count > 0)
            {
                if (m_buffer == null)
                {
                    m_buffer = m_pool.GetFreeBuffer();
                    m_index  = 0;
                }

                //
                // Write up to the end of this buffer
                //
                int remaining = m_sector_count * m_sector_size - m_index;

                if (remaining > count)
                {
                    remaining = count;
                }

                IntPtr dest = new IntPtr(m_buffer.BufferPtr.ToInt32() + m_index);
                Marshal.Copy(buffer, offset, dest, remaining);
                m_index  += remaining;
                m_length += remaining;
                count    -= remaining;
                offset   += remaining;

                if (m_index == m_sector_count * m_sector_size)
                {
                    m_buffer.DataSize            = m_index / m_sector_size;
                    m_buffer.SectorSize          = m_sector_size;
                    m_buffer.LogicalBlockAddress = m_lba;
                    m_buffer.SourceString        = "WriteBufferStream, Write method";
                    m_lba = long.MaxValue;
                    m_pool.SendBufferToDevice(m_buffer);
                    m_buffer = null;
                }
            }
        }
 /// <summary>
 /// This is a stream class that writes the data to the write buffer pool to be sent
 /// down to the CD/DVD device.
 /// </summary>
 /// <param name="pool">the buffer pool to get pages from and send data to</param>
 /// <param name="sector_size">the size of the sectors to buffer</param>
 /// <param name="lba">the logical block address for the first block from this stream</param>
 public WriteBufferStream(WriteBufferPool pool, int sector_size, long lba)
 {
     m_length = 0;
     m_pool = pool;
     m_buffer = null;
     m_index = 0;
     m_sector_size = sector_size;
     m_sector_count = m_pool.PageSize / m_sector_size;
     m_closing = false;
     m_lba = lba;
 }
 /// <summary>
 /// Add a buffer back to the free list to be used again
 /// </summary>
 /// <param name="buf">the buffer to add to the list</param>
 public void FreeWriteBuffer(WriteBuffer buf)
 {
     lock (m_free_list_lock)
     {
         m_free_list.Add(buf);
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="buffer"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        public override void Write(byte[] buffer, int offset, int count)
        {
            while (count > 0)
            {
                if (m_buffer == null)
                {
                    m_buffer = m_pool.GetFreeBuffer();
                    m_index = 0;
                }

                //
                // Write up to the end of this buffer
                //
                int remaining = m_sector_count * m_sector_size - m_index;

                if (remaining > count)
                    remaining = count;

                IntPtr dest = new IntPtr(m_buffer.BufferPtr.ToInt32() + m_index);
                Marshal.Copy(buffer, offset, dest, remaining);
                m_index += remaining;
                m_length += remaining;
                count -= remaining ;
                offset += remaining ;

                if (m_index == m_sector_count * m_sector_size)
                {
                    m_buffer.DataSize = m_index / m_sector_size;
                    m_buffer.SectorSize = m_sector_size;
                    m_buffer.LogicalBlockAddress = m_lba;
                    m_buffer.SourceString = "WriteBufferStream, Write method";
                    m_lba = long.MaxValue;
                    m_pool.SendBufferToDevice(m_buffer);
                    m_buffer = null;
                }
            }
        }
        /// <summary>
        /// Add a buffer to the list
        /// </summary>
        /// <param name="buf"></param>
        public void SendBufferToDevice(WriteBuffer buf)
        {
            lock (m_buffer_list_lock)
            {
                if (m_mult != 0 && ((buf.DataSize % m_mult) != 0))
                    System.Diagnostics.Debug.WriteLine("Added a block of " + buf.DataSize.ToString() + " blocks, not an event multiple") ;

                m_buffer_list.Add(buf);
                m_produced += (int)buf.DataSize;
            }
        }