Exemple #1
0
        /// <summary>
        /// Refreshes the disk configuration
        /// </summary>
        public void GetDiskInfo()
        {
            this.PhysicalTracks     = 35;
            this.PhysicalHeads      = 1;
            this.PhysicalSectors    = 18;
            this.PhysicalSectorSize = 256;

            LSN0 lsn0         = new LSN0(ReadBytes(0, 256));
            int  totalSectors = lsn0.TotalSectors;

            this.PhysicalTracks  = lsn0.PathDescriptor.Cylinders;
            this.PhysicalHeads   = lsn0.PathDescriptor.Sides;
            this.PhysicalSectors = lsn0.PathDescriptor.SectorsPerTrack;
            if (this.PhysicalSectors == 0)
            {
                this.PhysicalSectors = lsn0.SectorsPerTrack;
            }

            if (this.PhysicalHeads == 0)
            {
                this.PhysicalHeads = ((lsn0.DiskFormat & 0x01) > 0) ? 2 : 1;
            }

            if (totalSectors == 0 || this.PhysicalSectors == 0 || this.PhysicalHeads == 0)
            {
                goto NotValid;
            }

            if (this.PhysicalTracks == 0)
            {
                this.PhysicalTracks = totalSectors / this.PhysicalSectors / this.PhysicalHeads;
            }

            if (totalSectors != this.PhysicalTracks * this.PhysicalHeads * this.PhysicalSectors)
            {
                goto NotValid;
            }

            this.IsValidImage = true;
            return;

NotValid:
            this.IsValidImage = false;
            this.Close();
        }
Exemple #2
0
        private void GetDiskInfo()
        {
            this.physicalTracks     = 35;
            this.physicalHeads      = 1;
            this.physicalSectors    = 18;
            this.physicalSectorSize = 256;
            this.partitions         = 0;
            this.currentPartition   = 0;
            this.firstPartitonSize  = 0;

            this.headerLength = (int)this.Length % 256;
            if (this.HeaderLength != 0)
            {
                goto NotValid;
            }

            LSN0 lsn0         = new LSN0(this.ReadSector(0, 0, 1));
            int  totalSectors = lsn0.DD_TOT;

            if (((this.Length - (totalSectors * this.PhysicalSectorSize)) % rsdospart) == 0)
            {
                firstPartitonSize = totalSectors * this.PhysicalSectorSize;
                partitions        = (((int)this.Length - firstPartitonSize) / rsdospart) + 1;
            }
            else
            {
                if (this.Length % rsdospart != 0)
                {
                    goto NotValid;
                }
                partitions = (int)this.Length / rsdospart;
            }

            this.isValidImage = true;
            return;

NotValid:
            this.isValidImage = false;
            this.Close();
        }
Exemple #3
0
        /// <summary>
        /// Validate the disk's data is a valid OS9 format
        /// </summary>
        /// <returns>A value specifying the validation was successful or not</returns>
        private bool ValidateOS9()
        {
            this.lsn0 = this.ReadLSN(0);

            if (this.lsn0.DiskFormat == 0x82)
            {
                this.LogicalHeads = 1;
            }
            else
            {
                this.LogicalHeads = ((this.lsn0.DiskFormat & 0x01) > 0) ? 2 : 1;
            }

            this.LogicalSectors    = this.lsn0.SectorsPerTrack;
            this.LogicalSectorSize = this.lsn0.SectorSize;
            if (this.LogicalSectorSize == 0)
            {
                this.LogicalSectorSize = 256;
            }

            if (this.lsn0.PathDescriptor.SegmentAllocationSize == 0)
            {
                this.lsn0.PathDescriptor.SegmentAllocationSize = 8;
            }

            if (this.lsn0.TotalSectors == 0 || this.LogicalSectors == 0)
            {
                return(false);
            }

            this.LogicalTracks = this.lsn0.TotalSectors / this.LogicalSectors / this.LogicalHeads;

            int bitmapLSNs = (this.lsn0.MapBytes + (this.LogicalSectorSize - 1)) / this.LogicalSectorSize;

            if (1 + bitmapLSNs > this.lsn0.RootDirectory)
            {
                return(false);
            }

            if (this.LogicalSectors != this.lsn0.TrackSize)
            {
                return(false);
            }

            if (this.LogicalSectors == 0)
            {
                return(false);
            }

            if (this.lsn0.TotalSectors % this.LogicalSectors > 0)
            {
                return(false);
            }

            byte[] bitmap = this.GetBitmap();

            for (int i = 0; i < bitmapLSNs; i++)
            {
                byte b    = bitmap[i / 8];
                byte mask = (byte)(1 << (7 - (i % 8)));
                if ((b & mask) == 0)
                {
                    return(false);
                }
            }

            if (this.lsn0.TotalSectors != this.LogicalTracks * this.LogicalHeads * this.LogicalSectors)
            {
                return(false);
            }

            return(true);
        }
Exemple #4
0
        /// <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);
        }
Exemple #5
0
        private bool ValidateOS9()
        {
            this.lsn0 = new LSN0(this.ReadLSN(0));

            if (this.lsn0.DD_FMT == 0x82)
            {
                this.LogicalHeads = 1;
            }
            else
            {
                this.LogicalHeads = ((this.lsn0.DD_FMT & 0x01) > 0) ? 2 : 1;
            }

            this.LogicalSectors    = this.lsn0.DD_SPT;
            this.LogicalSectorSize = this.lsn0.DD_LSNSize;
            if (this.LogicalSectorSize == 0)
            {
                this.LogicalSectorSize = 256;
            }

            if (this.lsn0.DD_TOT == 0 || this.LogicalSectors == 0)
            {
                return(false);
            }

            this.LogicalTracks = this.lsn0.DD_TOT / this.LogicalSectors / this.LogicalHeads;

            int bitmapLSNs = (this.lsn0.DD_MAP + (this.LogicalSectorSize - 1)) / this.LogicalSectorSize;

            if (1 + bitmapLSNs > this.lsn0.DD_DIR)
            {
                return(false);
            }

            if (this.LogicalSectors != this.lsn0.DD_TKS)
            {
                return(false);
            }

            if (this.LogicalSectors == 0)
            {
                return(false);
            }

            if (this.lsn0.DD_TOT % this.LogicalSectors > 0)
            {
                return(false);
            }

            byte[] bitmap = this.GetBitmap();

            for (int i = 0; i < bitmapLSNs; i++)
            {
                byte b    = bitmap[i / 8];
                byte mask = (byte)(1 << (7 - (i % 8)));
                if ((b & mask) == 0)
                {
                    return(false);
                }
            }

            if (this.lsn0.DD_TOT != this.LogicalTracks * this.LogicalHeads * this.LogicalSectors)
            {
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Refresh the disk's configuration
        /// </summary>
        public void GetDiskInfo()
        {
            this.PhysicalTracks       = 35;
            this.PhysicalHeads        = 1;
            this.PhysicalSectors      = 18;
            this.PhysicalSectorSize   = 256;
            this.Partitions           = 0;
            this.ImagePartitionOffset = 0;
            this.PartitionOffset      = 0;

            LSN0 lsn0         = new LSN0(this.ReadBytes(0, 256));
            int  totalSectors = lsn0.TotalSectors;

            this.PhysicalTracks  = lsn0.PathDescriptor.Cylinders;
            this.PhysicalHeads   = lsn0.PathDescriptor.Sides;
            this.PhysicalSectors = lsn0.PathDescriptor.SectorsPerTrack;
            if (this.PhysicalSectors == 0)
            {
                this.PhysicalSectors = lsn0.SectorsPerTrack;
            }

            if (this.PhysicalHeads == 0)
            {
                if (lsn0.DiskFormat == 0x82)
                {
                    this.PhysicalHeads = 1;
                }
                else
                {
                    this.PhysicalHeads = ((lsn0.DiskFormat & 0x01) > 0) ? 2 : 1;
                }
            }

            if (totalSectors == 0 || this.PhysicalSectors == 0 || this.PhysicalHeads == 0)
            {
                goto NoOS9;
            }

            if (this.PhysicalTracks == 0)
            {
                this.PhysicalTracks = totalSectors / this.PhysicalSectors / this.PhysicalHeads;
            }

            if (totalSectors != this.PhysicalTracks * this.PhysicalHeads * this.PhysicalSectors)
            {
                goto NoOS9;
            }

            this.Partitions           = 1;
            this.ImagePartitionOffset = totalSectors * this.PhysicalSectorSize;

NoOS9:
            if ((this.Length - this.ImagePartitionOffset) % 0x27600 != 0)
            {
                goto NotValid;
            }

            this.Partitions += (int)((this.Length - this.ImagePartitionOffset) / 0x27600);

            this.PartitionOffset = 0;

            this.IsValidImage = true;
            return;

NotValid:
            this.IsValidImage = false;
            this.Close();
        }