Exemplo n.º 1
0
        /// <summary>
        /// Get a path table entry's data
        /// </summary>
        /// <param name="entry">The entry</param>
        /// <param name="type">The type of the entry (little endian or big endian)</param>
        private byte[] GetPathTableEntryBuffer(DirectoryEntry entry, PathTableType type, ushort parentNumber)
        {
            int entrySize = 8 + entry.Name.Length + (entry.Name.Length % 2 != 0 ? 1 : 0);

            byte[] buffer = new byte[entrySize];

            using (var stream = new CBinaryWriter(buffer))
            {
                stream.Write((byte)entry.Name.Length);
                stream.Write(entry.ExtendedAttributeRecordlength);

                if (type == PathTableType.LE)
                {
                    stream.Write(entry.ExtentLba);
                    stream.Write(parentNumber);
                }
                else
                {
                    stream.WriteBE(entry.ExtentLba);
                    stream.WriteBE(parentNumber);
                }

                stream.WriteAsciiString(entry.Name);

                if (entry.Name.Length % 2 != 0)
                {
                    stream.Write((byte)0);
                }
            }

            return(buffer);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Get a directory entry's data
        /// </summary>
        /// <param name="entry">The entry</param>
        /// <param name="selfRef">Is a self reference</param>
        /// <param name="parentRef">Is a parent reference</param>
        private byte[] GetDirectoryEntryBuffer(DirectoryEntry entry, bool selfRef = false, bool parentRef = false)
        {
            byte entryLength = entry.Length;

            // If parent or self reference, name is replaced by 0x00 for self or 0x01 for parent
            if (selfRef || parentRef)
            {
                entryLength -= (byte)(entry.Name.Length - 1);
                entryLength -= (byte)(entry.Name.Length % 2 == 0 ? 1 : 0);
            }

            byte[] buffer = new byte[entryLength];
            try
            {
                using (var stream = new CBinaryWriter(buffer))
                {
                    stream.Write(entryLength);
                    stream.Write(entry.ExtendedAttributeRecordlength);

                    stream.Write(entry.ExtentLba);
                    stream.WriteBE(entry.ExtentLba);

                    stream.Write(entry.ExtentSize);
                    stream.WriteBE(entry.ExtentSize);

                    byte[] dateBuffer = new byte[7];
                    dateBuffer[0] = (byte)(entry.Date.Year - 1900);
                    dateBuffer[1] = (byte)(entry.Date.Month);
                    dateBuffer[2] = (byte)(entry.Date.Day);
                    dateBuffer[3] = (byte)(entry.Date.Hour);
                    dateBuffer[4] = (byte)(entry.Date.Minute);
                    dateBuffer[5] = (byte)(entry.Date.Second);
                    stream.Write(dateBuffer);

                    stream.Write(entry.Flags);
                    stream.Write(entry.FileUnitSize);
                    stream.Write(entry.Interleave);

                    stream.Write(entry.VolumeSequenceNumber);
                    stream.WriteBE(entry.VolumeSequenceNumber);

                    if (!(selfRef || parentRef))
                    {
                        stream.Write((byte)entry.Name.Length);
                        stream.WriteAsciiString(entry.Name);

                        if (entry.Name.Length % 2 == 0)
                        {
                            stream.Write((byte)0);
                        }
                    }
                    else
                    {
                        stream.Write((byte)1);
                        stream.Write((byte)(selfRef ? 0 : 1));
                    }

                    if (entry.HasXa)
                    {
                        stream.WriteBE(entry.XaEntry.GroupId);
                        stream.WriteBE(entry.XaEntry.UserId);
                        stream.WriteBE(entry.XaEntry.Attributes);
                        stream.WriteAsciiString(entry.XaEntry.Signature);
                        stream.Write(entry.XaEntry.FileNumber);
                        stream.Write(entry.XaEntry.Unused);
                    }
                }

                return(buffer);
            }
            catch (Exception)
            {
                throw new FrameworkException("Error while writing DirectoryEntry : unable to write the entry");
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get a primary volume descriptor data
        /// </summary>
        /// <param name="m_primaryVolumeDescriptor">The primary volume descriptor</param>
        private byte[] GetPrimaryVolumeDescriptorBuffer()
        {
            byte[] buffer = new byte[GetSectorDataSize(_defaultSectorMode)];
            try
            {
                using (var stream = new CBinaryWriter(buffer))
                {
                    stream.Write((byte)_primaryVolumeDescriptor.Type);
                    stream.WriteAsciiString(_primaryVolumeDescriptor.Id);
                    stream.Write(_primaryVolumeDescriptor.Version);
                    stream.Write(_primaryVolumeDescriptor.Unused1);
                    stream.WriteAsciiString(_primaryVolumeDescriptor.SystemId, 32, " ");
                    stream.WriteAsciiString(_primaryVolumeDescriptor.VolumeId, 32, " ");
                    stream.Write(_primaryVolumeDescriptor.Unused2);

                    stream.Write(_primaryVolumeDescriptor.VolumeSpaceSize);
                    stream.WriteBE(_primaryVolumeDescriptor.VolumeSpaceSize);

                    stream.Write(_primaryVolumeDescriptor.Unused3);

                    stream.Write(_primaryVolumeDescriptor.VolumeSetSize);
                    stream.WriteBE(_primaryVolumeDescriptor.VolumeSetSize);

                    stream.Write(_primaryVolumeDescriptor.VolumeSequenceNumber);
                    stream.WriteBE(_primaryVolumeDescriptor.VolumeSequenceNumber);

                    stream.Write(_primaryVolumeDescriptor.LogicalBlockSize);
                    stream.WriteBE(_primaryVolumeDescriptor.LogicalBlockSize);

                    stream.Write(_primaryVolumeDescriptor.PathTableSize);
                    stream.WriteBE(_primaryVolumeDescriptor.PathTableSize);

                    stream.Write(_primaryVolumeDescriptor.TypeLPathTableLBA);
                    stream.Write(_primaryVolumeDescriptor.OptTypeLPathTableLBA);
                    stream.WriteBE(_primaryVolumeDescriptor.TypeMPathTableLBA);
                    stream.WriteBE(_primaryVolumeDescriptor.OptTypeMPathTableLBA);
                    stream.Write(GetDirectoryEntryBuffer(_primaryVolumeDescriptor.RootDirectoryEntry));

                    // TODO : cas des fichiers
                    stream.WriteAsciiString(_primaryVolumeDescriptor.VolumeSetId, 128, " ");
                    stream.WriteAsciiString(_primaryVolumeDescriptor.PublisherId, 128, " ");
                    stream.WriteAsciiString(_primaryVolumeDescriptor.PreparerId, 128, " ");
                    stream.WriteAsciiString(_primaryVolumeDescriptor.ApplicationId, 128, " ");
                    stream.WriteAsciiString(_primaryVolumeDescriptor.CopyrightFileId, 38, " ");
                    stream.WriteAsciiString(_primaryVolumeDescriptor.AbstractFileId, 36, " ");
                    stream.WriteAsciiString(_primaryVolumeDescriptor.BibliographicFileId, 37, " ");
                    //

                    stream.Write(VolumeDescriptor.FromDateTime(_primaryVolumeDescriptor.CreationDate));
                    stream.Write(VolumeDescriptor.FromDateTime(_primaryVolumeDescriptor.ModificationDate));
                    stream.Write(VolumeDescriptor.FromDateTime(_primaryVolumeDescriptor.ExpirationDate));
                    stream.Write(VolumeDescriptor.FromDateTime(_primaryVolumeDescriptor.EffectiveDate));
                    stream.Write(_primaryVolumeDescriptor.FileStructureVersion);
                    stream.Write(_primaryVolumeDescriptor.Unused4);

                    if (_isXa)
                    {
                        using (CBinaryWriter appDataStream = new CBinaryWriter(_primaryVolumeDescriptor.ApplicationData))
                        {
                            appDataStream.Position = 0x8D;
                            appDataStream.WriteAsciiString(VolumeDescriptor.VOLUME_XA);
                        }
                    }

                    stream.Write(_primaryVolumeDescriptor.ApplicationData);
                    stream.Write(_primaryVolumeDescriptor.Reserved);
                }

                return(buffer);
            }
            catch (Exception)
            {
                throw new FrameworkException("Error while writing PrimaryVolumeDescriptor : unable to write the descriptor");
            }
        }