Exemple #1
0
        /// <summary>
        /// This method flushes any existing data to the device.
        /// </summary>
        public override void Flush()
        {
            if (m_buffer != null)
            {
                //
                // In general using flush, except when closing the device can be very
                // dangerous.  This method catches those cases where the result sent to
                // the device would be incorrect and asserts accordingly.  Basically we
                // always send data down to the device in sectors.  When we flush we send
                // down whatever data is left in the buffer.  If we are closing, this has
                // the effect of rounding the last bit of data to a sector boundary.  If
                // we are not closing, it can have the effect of inserting data in the
                // middle of the data stream.  Flusing only works correctly if we are sitting
                // on the boundary of a sector.  Therefore, if this assert has fired it means
                // we are not closing and not sitting on the boundary of a sector.
                //
                Debug.Assert(m_closing || (m_index % m_sector_size) == 0);

                m_buffer.DataSize = m_index / m_sector_size;
                if ((m_index % m_sector_size) != 0)
                {
                    m_buffer.DataSize++;
                }
                m_buffer.SectorSize = m_sector_size;

                m_buffer.SourceString        = "WriteBufferStream, Flush method";
                m_buffer.LogicalBlockAddress = m_lba;
                m_lba = long.MaxValue;
                m_pool.SendBufferToDevice(m_buffer);
            }
        }
Exemple #2
0
        /// <summary>
        /// This function reads data from the file and sends it to the
        /// buffer stream to be sent to the burner.  This function does not
        /// return until all of the data from the file is read.
        /// </summary>
        /// <returns></returns>
        public bool ReadData(int sector_size, long lba)
        {
            bool shortbuf = false;
            int  NumberRead;
            int  num_sectors;
            bool first = true;

            // This is the number of whole sectors that will fit into the buffer.
            num_sectors = m_buffer_stream.PageSize / sector_size;

            while (true)
            {
                WriteBuffer buf;

                buf = m_buffer_stream.GetFreeBuffer();
                if (!m_reader.ReadData(buf.BufferPtr, num_sectors * sector_size, out NumberRead))
                {
                    return(false);
                }

                // If the read succeeded, but read zero bytes, we have reached the
                // end of the file.
                if (NumberRead == 0)
                {
                    return(true);
                }

                if (shortbuf)
                {
                    throw new Exception("read two short packets");
                }

                // Mark the buffer with the amount of data that has
                // been read from the file
                int sectors = NumberRead / sector_size;
                if ((NumberRead % sector_size) != 0)
                {
                    shortbuf = true;
                    sectors++;
                }

                if (first)
                {
                    buf.SourceString        = "First block from FileReader";
                    buf.LogicalBlockAddress = lba;
                    first = false;
                }
                else
                {
                    buf.SourceString        = "Not first block from FileReader";
                    buf.LogicalBlockAddress = long.MaxValue;
                }

                buf.SectorSize = sector_size;
                buf.DataSize   = sectors;

                // Send the buffer to the device
                m_buffer_stream.SendBufferToDevice(buf);
            }
        }