/// <summary> /// High level format a disk /// </summary> public void FormatDisk() { // Create Empty Disk byte fillByte = 0xe5; byte[] buffer; if (!(DiskImage is PhysicalDisk)) { buffer = new byte[this.LogicalTracks * this.LogicalHeads * this.LogicalSectors * this.LogicalSectorSize].Initialize(fillByte); this.WriteLSNs(0, buffer); } else { buffer = new byte[this.LogicalSectors * this.LogicalSectorSize].Initialize(fillByte); FormatDiskForm fdf = new FormatDiskForm(); ((PhysicalDisk)DiskImage).FormatChanged += new FormatChangedEventHandler(fdf.Update); for (int track = 0; track < this.LogicalTracks; track++) { for (int head = 0; head < this.LogicalHeads; head++) { ((PhysicalDisk)DiskImage).WriteTrack(track, head, buffer); } } fdf.Close(); } // Create LSN0 this.lsn0 = new LSN0(); this.lsn0.TotalSectors = this.LogicalTracks * this.LogicalHeads * this.LogicalSectors; this.lsn0.TrackSize = (byte)this.LogicalSectors; this.lsn0.MapBytes = (ushort)((this.lsn0.TotalSectors + 7) / 8); this.lsn0.ClusterSize = 1; this.lsn0.Owner = 0; this.lsn0.Attributes = 0xff; Random rnd = new Random(DateTime.Now.Second); this.lsn0.DiskID = (ushort)rnd.Next(0xffff); if (this.DiskImage is PartitionedVHDImage || this.DiskImage is VHDImage) { this.lsn0.DiskFormat = 0x82; } else { this.lsn0.DiskFormat = (byte)(0x02 + (this.LogicalHeads - 1)); } this.lsn0.BootStrap = 0; this.lsn0.BootStrapSize = 0; this.lsn0.CreatedDate = DateTime.Now; this.lsn0.VolumeName = string.Empty; this.lsn0.SectorSize = (ushort)this.LogicalSectorSize; this.lsn0.RootDirectory = 1 + ((this.lsn0.MapBytes + (this.LogicalSectorSize - 1)) / this.LogicalSectorSize); this.lsn0.PathDescriptor.DeviceType = 0x01; this.lsn0.PathDescriptor.DriveNumber = 0x00; this.lsn0.PathDescriptor.DeviceType = 0x20; this.lsn0.PathDescriptor.Density = 0x01; this.lsn0.PathDescriptor.Cylinders = (ushort)this.DiskImage.PhysicalTracks; this.lsn0.PathDescriptor.Sides = (byte)this.DiskImage.PhysicalHeads; this.lsn0.PathDescriptor.SectorsPerTrack = (ushort)this.DiskImage.PhysicalSectors; this.lsn0.PathDescriptor.SectorsPerTrack0 = this.lsn0.PathDescriptor.SectorsPerTrack; this.lsn0.PathDescriptor.Interleave = (byte)this.DiskImage.Interleave; if (this.DiskImage is PartitionedVHDImage || this.DiskImage is VHDImage) { this.lsn0.PathDescriptor.SegmentAllocationSize = 0x20; } else { this.lsn0.PathDescriptor.SegmentAllocationSize = 8; } this.WriteLSN(0, (byte[])this.lsn0); // Create Allocation Bitmap int bitmapBits = this.LogicalTracks * this.LogicalHeads * this.LogicalSectors; int bitmapLSNs = ((bitmapBits / 8) + this.LogicalSectorSize - 1) / this.LogicalSectorSize; int allocatedSectors = 1 + bitmapLSNs + 8; byte[] bitmap = new byte[bitmapLSNs * this.LogicalSectorSize].Initialize(0xff); for (int i = 0; i < this.lsn0.TotalSectors; i++) { this.DeallocateLSN(i, bitmap); } for (int i = 0; i < allocatedSectors; i++) { this.AllocateLSN(i, bitmap); } this.WriteLSNs(0, bitmap); // Create root directory file descriptor FileDescriptor rootDescriptor = new FileDescriptor(0xbf, 0, this.lsn0.PackedCreationDate, 2, 0x40, Util.CreatedDateBytes(this.lsn0.CreatedDate)); rootDescriptor.SegmentList = new FileSegment[48]; rootDescriptor.SegmentList[0] = new FileSegment(this.lsn0.RootDirectory + 1, 7); this.WriteLSN(this.lsn0.RootDirectory, (byte[])rootDescriptor); // Create root directory buffer = new byte[7 * this.LogicalSectorSize]; Directory rootDirectory = new Directory(); rootDirectory.FormatType = DiskFormatType.OS9Format; rootDirectory.Add(new DirectoryEntry("..", this.lsn0.RootDirectory)); rootDirectory.Add(new DirectoryEntry(".", this.lsn0.RootDirectory)); Array.Copy((byte[])rootDirectory, 0, buffer, 0, 0x40); this.WriteLSNs(this.lsn0.RootDirectory + 1, buffer); }
/// <summary> /// Initializes a new instance of the <see cref="DirectoryEntry"/> class /// from an Array of bytes. /// OS9 Specific. /// </summary> /// <param name="directoryEntryBytes">Array of bytes containing directory entry information</param> /// <param name="descriptor">File Descriptor</param> public DirectoryEntry(byte[] directoryEntryBytes, FileDescriptor descriptor) : this(directoryEntryBytes, DiskFormatType.OS9Format) { this.Descriptor = descriptor; }