/// <summary> /// Writes three volume descriptors speciffic to the ISO 9660 Joliet: /// 1. Primary volume descriptor; /// 2. Suplementary volume descriptor; /// 3. Volume descriptor set terminator. /// </summary> /// <param name="writer">A binary writer to write the data.</param> /// <param name="volumeName">A normal string representing the desired name of the volume. /// (the maximum standard length for this string is 16 for Joliet, so if the name is larger /// than 16 characters, it is truncated.)</param> /// <param name="root">The root IsoDirectory, representing the root directory for the volume.</param> /// <param name="volumeSpaceSize">The ISO total space size IN SECTORS. /// (For example, if the ISO space size is 1,427,456 bytes, then the volumeSpaceSize will be 697)</param> /// <param name="pathTableSize1">The first path table size (for the primary volume) IN BYTES.</param> /// <param name="pathTableSize2">The second path table size (for the suplementary volume) IN BYTES.</param> /// <param name="typeLPathTable1">The location (sector) of the first LITTLE ENDIAN path table.</param> /// <param name="typeMPathTable1">The location (sector) of the first BIG ENDIAN path table.</param> /// <param name="typeLPathTable2">The location (sector) of the second LITTLE ENDIAN path table.</param> /// <param name="typeMPathTable2">The location (sector) of the second BIG ENDIAN path table.</param> private void WriteVolumeDescriptors(BinaryWriter writer, string volumeName, IsoDirectory root, UInt32 volumeSpaceSize, UInt32 pathTableSize1, UInt32 pathTableSize2, UInt32 typeLPathTable1, UInt32 typeMPathTable1, UInt32 typeLPathTable2, UInt32 typeMPathTable2) { // Throughout this program I have respected the convention of refering to the root as "."; // However, one should not confuse the root with the current directory, also known as "." (along with the parent directory, ".."). // Primary Volume Descriptor: // Create a Directory Record of the root and the volume descriptor. DirectoryRecordWrapper rootRecord = new DirectoryRecordWrapper(root.Extent1, root.Size1, root.Date, root.IsDirectory, "."); VolumeDescriptorWrapper volumeDescriptor = new VolumeDescriptorWrapper(volumeName, volumeSpaceSize, pathTableSize1, typeLPathTable1, typeMPathTable1, rootRecord, DateTime.Now, DateTime.Now, 8); volumeDescriptor.VolumeDescriptorType = VolumeType.Primary; volumeDescriptor.Write(writer); // Suplementary volume descriptor: rootRecord = new DirectoryRecordWrapper(root.Extent2, root.Size2, root.Date, root.IsDirectory, "."); volumeDescriptor = new VolumeDescriptorWrapper(volumeName, volumeSpaceSize, pathTableSize2, typeLPathTable2, typeMPathTable2, rootRecord, DateTime.Now, DateTime.Now, 8); volumeDescriptor.VolumeDescriptorType = VolumeType.Suplementary; volumeDescriptor.Write(writer); // Volume descriptor set terminator: volumeDescriptor.VolumeDescriptorType = VolumeType.SetTerminator; volumeDescriptor.Write(writer); }
public void Write(BinaryWriter writer, VolumeType type) { DirectoryRecordWrapper record; UInt32 extent = (type == VolumeType.Primary) ? Extent1 : Extent2; UInt32 size = (type == VolumeType.Primary) ? Size1 : Size2; UInt32 parentExtent = (type == VolumeType.Primary) ? Parent.Extent1 : Parent.Extent2; UInt32 parentSize = (type == VolumeType.Primary) ? Parent.Size1 : Parent.Size2; // First write the current directory and the parent. ("." and "..") record = new DirectoryRecordWrapper(extent, size, Date, IsDirectory, "."); record.Write(writer); record = new DirectoryRecordWrapper(parentExtent, parentSize, Parent.Date, Parent.IsDirectory, ".."); record.Write(writer); // Everything else is written after the first two sectors (current dir and parent). int position = 2 * IsoAlgorithm.DefaultDirectoryRecordLength; foreach (IsoFolderElement child in Children) { UInt32 childExtent = (type == VolumeType.Primary) ? child.Extent1 : child.Extent2; UInt32 childSize = (type == VolumeType.Primary) ? child.Size1 : child.Size2; string childName = (type == VolumeType.Primary) ? child.ShortName : child.LongName; record = new DirectoryRecordWrapper(childExtent, childSize, child.Date, child.IsDirectory, childName) { VolumeDescriptorType = type }; if (record.Length + position > IsoAlgorithm.SectorSize) { writer.Write(new byte[IsoAlgorithm.SectorSize - position]); position = 0; } position += record.Write(writer); } writer.Write(new byte[IsoAlgorithm.SectorSize - position]); }
public void WriteDemoImage(BinaryWriter writer) { int currentSector; for (currentSector = 0; currentSector < 16; currentSector++) { IsoAlgorithm.WriteEmptySector(writer); } DirectoryRecordWrapper rootDir = new DirectoryRecordWrapper(19, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); VolumeDescriptorWrapper volumeDescriptor = new VolumeDescriptorWrapper("EPURASU", 28, 26, 21, 22, rootDir, DateTime.Now, DateTime.Now.Subtract(TimeSpan.FromDays(2)), 8); //rootDir.SetDirectoryRecord( 19, ISO9660.SectorSize, DateTime.Now, true, "." ); // [ Sect 16 ] Primary volume descriptor volumeDescriptor.VolumeDescriptorType = VolumeType.Primary; // volumeDescriptor.SetVolumeDescriptor( "EPURASU", 28, 26, 21, 22, rootDir, DateTime.Now, DateTime.Now.Subtract( TimeSpan.FromDays( 2 ) ), 8 ); volumeDescriptor.Write(writer); // [ Sect 17 ] Suplementary volume descriptor (in care scriem cu unicode) rootDir.SetDirectoryRecord(23, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); volumeDescriptor.VolumeDescriptorType = VolumeType.Suplementary; volumeDescriptor.SetVolumeDescriptor("Epurasu", 28, 38, 25, 26, rootDir, DateTime.Now, DateTime.Now.Subtract(TimeSpan.FromDays(2)), 8); volumeDescriptor.Write(writer); // [ Sect 18 ] Volume descriptor set termnator volumeDescriptor.VolumeDescriptorType = VolumeType.SetTerminator; volumeDescriptor.Write(writer); // [ Sect 19 ] Continutul directorului radacina: // Directorul curent: "." rootDir.SetDirectoryRecord(19, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); rootDir.Write(writer); // Directorul parinte: "..". Fiind vorba de radacina, directorul parinte e o referinta la directorul curent. rootDir.SetDirectoryRecord(19, IsoAlgorithm.SectorSize, DateTime.Now, true, ".."); rootDir.Write(writer); // Director copil: "Director" DirectoryRecordWrapper childDir = new DirectoryRecordWrapper(20, IsoAlgorithm.SectorSize, DateTime.Now, true, "DIRECTOR"); //childDir.SetDirectoryRecord( 20, ISO9660.SectorSize, DateTime.Now, true, "DIRECTOR" ); int bytesWritten = childDir.Write(writer); writer.Write(new byte[2048 - 34 - 34 - bytesWritten]); // [ Sect 20 ] Continutul directorului "Director" childDir.SetDirectoryRecord(20, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); childDir.Write(writer); childDir.SetDirectoryRecord(19, IsoAlgorithm.SectorSize, DateTime.Now, true, ".."); childDir.Write(writer); childDir.SetDirectoryRecord(27, 45, DateTime.Now, false, "NUMELEFI.TXT"); bytesWritten = childDir.Write(writer); writer.Write(new byte[2048 - 34 - 34 - bytesWritten]); // [ Sect 21 ] Pathtable pt little endian // Root: PathTableRecordWrapper record = new PathTableRecordWrapper(); record.Endian = Endian.LittleEndian; record.SetPathTableRecord(19, 1, "."); bytesWritten = record.Write(writer); // "Director": record.SetPathTableRecord(20, 1, "DIRECTOR"); bytesWritten += record.Write(writer); writer.Write(new byte[2048 - bytesWritten]); // [ Sect 22 ] Pathtable pt big endian // Root: record = new PathTableRecordWrapper(); record.Endian = Endian.BigEndian; record.SetPathTableRecord(19, 1, "."); record.Write(writer); // "Director": record.SetPathTableRecord(20, 1, "DIRECTOR"); record.Write(writer); writer.Write(new byte[2048 - bytesWritten]); // [ Sect 23 ] Continutul directorului radacina: rootDir.VolumeDescriptorType = VolumeType.Suplementary; // Directorul curent: "." rootDir.SetDirectoryRecord(23, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); rootDir.Write(writer); // Directorul parinte: "..". Fiind vorba de radacina, directorul parinte e o referinta la directorul curent. rootDir.SetDirectoryRecord(23, IsoAlgorithm.SectorSize, DateTime.Now, true, ".."); rootDir.Write(writer); // Director copil: "Director" childDir = new DirectoryRecordWrapper(24, IsoAlgorithm.SectorSize, DateTime.Now, true, "Directorul"); //childDir.SetDirectoryRecord( 24, ISO9660.SectorSize, DateTime.Now, true, "Directorul" ); childDir.VolumeDescriptorType = VolumeType.Suplementary; bytesWritten = childDir.Write(writer); writer.Write(new byte[2048 - 34 - 34 - bytesWritten]); // [ Sect 24 ] Continutul directorului "Director" childDir.SetDirectoryRecord(24, IsoAlgorithm.SectorSize, DateTime.Now, true, "."); childDir.Write(writer); childDir.SetDirectoryRecord(23, IsoAlgorithm.SectorSize, DateTime.Now, true, ".."); childDir.Write(writer); childDir.SetDirectoryRecord(27, 45, DateTime.Now, false, "numeleFisierului.txt"); bytesWritten = childDir.Write(writer); writer.Write(new byte[2048 - 34 - 34 - bytesWritten]); // [ Sect 25 ] Pathtable pt little endian // Root: record = new PathTableRecordWrapper(); record.Endian = Endian.LittleEndian; record.VolumeDescriptorType = VolumeType.Suplementary; record.SetPathTableRecord(23, 1, "."); bytesWritten = record.Write(writer); // "Director": record.SetPathTableRecord(24, 1, "Directorul"); bytesWritten += record.Write(writer); writer.Write(new byte[2048 - bytesWritten]); // [ Sect 26 ] Pathtable pt big endian // Root: record = new PathTableRecordWrapper(); record.Endian = Endian.BigEndian; record.VolumeDescriptorType = VolumeType.Suplementary; record.SetPathTableRecord(23, 1, "."); record.Write(writer); // "Director": record.SetPathTableRecord(24, 1, "Directorul"); record.Write(writer); writer.Write(new byte[2048 - bytesWritten]); // [ Sect 27 ] Continutul fisierului (45 B): writer.Write(IsoAlgorithm.StringToByteArray("Catelus cu parul cretz fura ratza din cotetz.")); writer.Write(new byte[2048 - 45]); }