Example #1
0
        /// <summary>
        /// Write out the directory entry
        /// </summary>
        private void WriteDirectoryEntry(DataTrackIndexEntry entry)
        {
            SeekSector(entry.Lba);

            int size       = (int)entry.Size;
            int sectorSize = GetSectorDataSize(_defaultSectorMode);

            byte[] data = new byte[size];

            using (var stream = new CBinaryWriter(data))
            {
                // First directory entry of a directory entry is the directory itself
                stream.Write(GetDirectoryEntryBuffer(entry.DirectoryEntry, true, false));

                // Second directory entry is the parent directory entry.
                if (entry.ParentEntry != null)
                {
                    stream.Write(GetDirectoryEntryBuffer(entry.ParentEntry.DirectoryEntry, false, true));
                }
                else
                {
                    stream.Write(GetDirectoryEntryBuffer(entry.DirectoryEntry, false, true));
                }

                foreach (var subEntry in entry.SubEntries)
                {
                    // DirectoryEntry cannot be "splitted" on two sectors
                    if ((stream.Position - (stream.Position / sectorSize) * sectorSize) + subEntry.Length >= sectorSize)
                    {
                        stream.Position = ((stream.Position / sectorSize) + 1) * sectorSize;
                    }

                    if (stream.Position + subEntry.DirectoryEntry.Length < size)
                    {
                        stream.Write(GetDirectoryEntryBuffer(subEntry.DirectoryEntry));
                    }
                    else
                    {
                        throw new FrameworkException("Error while finalizing disk : directory \"{0}\" is too small", entry.FullPath);
                    }
                }
            }

            for (int i = 0; i < size; i += sectorSize)
            {
                WriteSector
                (
                    CBuffer.Create(data, i, sectorSize),
                    _defaultSectorMode,
                    (i + sectorSize >= size) ? XaSubHeader.EndOfFile : XaSubHeader.Basic
                );
            }
        }
Example #2
0
        /// <summary>
        /// Write out path table
        /// </summary>
        /// <param name="lba"></param>
        /// <param name="data"></param>
        private void WritePathTable(uint lba, byte[] data)
        {
            SeekSector(lba);
            int sectorSize = GetSectorDataSize(_defaultSectorMode);

            for (int i = 0; i < data.Length; i += sectorSize)
            {
                WriteSector
                (
                    CBuffer.Create(data, i, sectorSize),
                    _defaultSectorMode,
                    (i + sectorSize >= data.Length) ? XaSubHeader.EndOfFile : XaSubHeader.Basic
                );
            }
        }