示例#1
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");
            }
        }
示例#2
0
        /// <summary>
        /// Read a primary volume descriptor
        /// </summary>
        /// <param name="stream">The stream to read</param>
        private PrimaryVolumeDescriptor ReadPrimaryVolumeDescriptor(CBinaryReader stream)
        {
            PrimaryVolumeDescriptor descriptor;

            try
            {
                byte version = stream.ReadByte();

                descriptor = new PrimaryVolumeDescriptor(version);

                descriptor.Unused1  = stream.ReadByte();
                descriptor.SystemId = stream.ReadAsciiString(32);
                descriptor.VolumeId = stream.ReadAsciiString(32);
                descriptor.Unused2  = stream.ReadBytes(8);

                descriptor.VolumeSpaceSize = stream.ReadUInt32();
                if (descriptor.VolumeSpaceSize != stream.ReadUInt32BE())
                {
                    throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : VolumeSpaceSize is not valid");
                }

                descriptor.Unused3 = stream.ReadBytes(32);

                descriptor.VolumeSetSize = stream.ReadUInt16();
                if (descriptor.VolumeSetSize != stream.ReadUInt16BE())
                {
                    throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : VolumeSetSize is not valid");
                }

                descriptor.VolumeSequenceNumber = stream.ReadUInt16();
                if (descriptor.VolumeSequenceNumber != stream.ReadUInt16BE())
                {
                    throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : VolumeSequenceNumber  is not valid");
                }

                descriptor.LogicalBlockSize = stream.ReadUInt16();
                if (descriptor.LogicalBlockSize != stream.ReadUInt16BE())
                {
                    throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : LogicalBlockSize  is not valid");
                }

                descriptor.PathTableSize = stream.ReadUInt32();
                if (descriptor.PathTableSize != stream.ReadUInt32BE())
                {
                    throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : PathTableSize  is not valid");
                }

                descriptor.TypeLPathTableLBA    = stream.ReadUInt32();
                descriptor.OptTypeLPathTableLBA = stream.ReadUInt32();
                descriptor.TypeMPathTableLBA    = stream.ReadUInt32BE();
                descriptor.OptTypeMPathTableLBA = stream.ReadUInt32BE();

                if (descriptor.OptTypeLPathTableLBA != 0 || descriptor.OptTypeMPathTableLBA != 0)
                {
                    _hasOptionalPathTable = true;
                }

                descriptor.RootDirectoryEntry = ReadDirectoryEntry(stream);

                // TODO : cas des fichiers
                descriptor.VolumeSetId         = stream.ReadAsciiString(128);
                descriptor.PublisherId         = stream.ReadAsciiString(128);
                descriptor.PreparerId          = stream.ReadAsciiString(128);
                descriptor.ApplicationId       = stream.ReadAsciiString(128);
                descriptor.CopyrightFileId     = stream.ReadAsciiString(38);
                descriptor.AbstractFileId      = stream.ReadAsciiString(36);
                descriptor.BibliographicFileId = stream.ReadAsciiString(37);
                //

                descriptor.CreationDate         = VolumeDescriptor.ToDateTime(stream.ReadBytes(17));
                descriptor.ModificationDate     = VolumeDescriptor.ToDateTime(stream.ReadBytes(17));
                descriptor.ExpirationDate       = VolumeDescriptor.ToDateTime(stream.ReadBytes(17));
                descriptor.EffectiveDate        = VolumeDescriptor.ToDateTime(stream.ReadBytes(17));
                descriptor.FileStructureVersion = stream.ReadByte();
                descriptor.Unused4         = stream.ReadByte();
                descriptor.ApplicationData = stream.ReadBytes(512);
                descriptor.Reserved        = stream.ReadBytes(653);

                // if the disk is CDROM/XA (and then contains an XaEntry in his DirectoryEntries),
                // "CD-XA001" can be read at offset 0x400 of the pvd (actually offset 0x8D of ApplicationData field)
                if (CBuffer.ReadAsciiString(descriptor.ApplicationData, 0x8D, 8) == VolumeDescriptor.VOLUME_XA)
                {
                    _isXa = true;
                }
            }
            catch (FrameworkException ex)
            {
                throw ex;
            }
            catch (Exception)
            {
                throw new FrameworkException("Error while reading PrimaryVolumeDescriptor : PrimaryVolumeDescriptor is not valid");
            }

            return(descriptor);
        }