Beispiel #1
0
        public bool Identify(IMediaImage imagePlugin, Partition partition)
        {
            if (imagePlugin.Info.Sectors != 455 && imagePlugin.Info.Sectors != 560)
            {
                return(false);
            }

            if (partition.Start > 0 || imagePlugin.Info.SectorSize != 256)
            {
                return(false);
            }

            int spt = imagePlugin.Info.Sectors == 455 ? 13 : 16;

            byte[] vtocB = imagePlugin.ReadSector((ulong)(17 * spt));
            vtoc = new Vtoc();
            IntPtr vtocPtr = Marshal.AllocHGlobal(256);

            Marshal.Copy(vtocB, 0, vtocPtr, 256);
            vtoc = (Vtoc)Marshal.PtrToStructure(vtocPtr, typeof(Vtoc));
            Marshal.FreeHGlobal(vtocPtr);

            return(vtoc.catalogSector < spt && vtoc.maxTrackSectorPairsPerSector <= 122 &&
                   vtoc.sectorsPerTrack == spt && vtoc.bytesPerSector == 256);
        }
Beispiel #2
0
        public void GetInformation(IMediaImage imagePlugin, Partition partition, out string information,
                                   Encoding encoding)
        {
            Encoding    = encoding ?? new Apple2();
            information = "";
            StringBuilder sb = new StringBuilder();

            int spt;

            spt = imagePlugin.Info.Sectors == 455 ? 13 : 16;

            byte[] vtocB = imagePlugin.ReadSector((ulong)(17 * spt));
            vtoc = new Vtoc();
            IntPtr vtocPtr = Marshal.AllocHGlobal(256);

            Marshal.Copy(vtocB, 0, vtocPtr, 256);
            vtoc = (Vtoc)Marshal.PtrToStructure(vtocPtr, typeof(Vtoc));
            Marshal.FreeHGlobal(vtocPtr);

            sb.AppendLine("Apple DOS File System");
            sb.AppendLine();
            sb.AppendFormat("Catalog starts at sector {0} of track {1}", vtoc.catalogSector, vtoc.catalogTrack)
            .AppendLine();
            sb.AppendFormat("File system initialized by DOS release {0}", vtoc.dosRelease).AppendLine();
            sb.AppendFormat("Disk volume number {0}", vtoc.volumeNumber).AppendLine();
            sb.AppendFormat("Sectors allocated at most in track {0}", vtoc.lastAllocatedSector).AppendLine();
            sb.AppendFormat("{0} tracks in volume", vtoc.tracks).AppendLine();
            sb.AppendFormat("{0} sectors per track", vtoc.sectorsPerTrack).AppendLine();
            sb.AppendFormat("{0} bytes per sector", vtoc.bytesPerSector).AppendLine();
            sb.AppendFormat("Track allocation is {0}", vtoc.allocationDirection > 0 ? "forward" : "reverse")
            .AppendLine();

            information = sb.ToString();

            XmlFsType = new FileSystemType
            {
                Bootable    = true,
                Clusters    = (long)imagePlugin.Info.Sectors,
                ClusterSize = (int)imagePlugin.Info.SectorSize,
                Type        = "Apple DOS"
            };
        }
Beispiel #3
0
        /// <summary>
        ///     Mounts an Apple DOS filesystem
        /// </summary>
        public Errno Mount(IMediaImage imagePlugin, Partition partition, Encoding encoding,
                           Dictionary <string, string> options)
        {
            device   = imagePlugin;
            start    = partition.Start;
            Encoding = encoding ?? new Apple2();

            if (device.Info.Sectors != 455 && device.Info.Sectors != 560)
            {
                DicConsole.DebugWriteLine("Apple DOS plugin", "Incorrect device size.");
                return(Errno.InOutError);
            }

            if (start > 0)
            {
                DicConsole.DebugWriteLine("Apple DOS plugin", "Partitions are not supported.");
                return(Errno.InOutError);
            }

            if (device.Info.SectorSize != 256)
            {
                DicConsole.DebugWriteLine("Apple DOS plugin", "Incorrect sector size.");
                return(Errno.InOutError);
            }

            sectorsPerTrack = device.Info.Sectors == 455 ? 13 : 16;

            // Read the VTOC
            vtocBlocks = device.ReadSector((ulong)(17 * sectorsPerTrack));
            vtoc       = new Vtoc();
            IntPtr vtocPtr = Marshal.AllocHGlobal(256);

            Marshal.Copy(vtocBlocks, 0, vtocPtr, 256);
            vtoc = (Vtoc)Marshal.PtrToStructure(vtocPtr, typeof(Vtoc));
            Marshal.FreeHGlobal(vtocPtr);

            track1UsedByFiles = false;
            track2UsedByFiles = false;
            usedSectors       = 1;

            Errno error = ReadCatalog();

            if (error != Errno.NoError)
            {
                DicConsole.DebugWriteLine("Apple DOS plugin", "Unable to read catalog.");
                return(error);
            }

            error = CacheAllFiles();
            if (error != Errno.NoError)
            {
                DicConsole.DebugWriteLine("Apple DOS plugin", "Unable cache all files.");
                return(error);
            }

            // Create XML metadata for mounted filesystem
            XmlFsType = new FileSystemType
            {
                Bootable              = true,
                Clusters              = (long)device.Info.Sectors,
                ClusterSize           = vtoc.bytesPerSector,
                Files                 = catalogCache.Count,
                FilesSpecified        = true,
                FreeClustersSpecified = true,
                Type = "Apple DOS"
            };
            XmlFsType.FreeClusters = XmlFsType.Clusters - usedSectors;

            if (options == null)
            {
                options = GetDefaultOptions();
            }
            if (options.TryGetValue("debug", out string debugString))
            {
                bool.TryParse(debugString, out debug);
            }
            mounted = true;
            return(Errno.NoError);
        }