Esempio n. 1
0
        public bool Identify(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);

            if (stream.Length < Marshal.SizeOf <FdiHeader>())
            {
                return(false);
            }

            byte[] hdrB = new byte[Marshal.SizeOf <FdiHeader>()];
            stream.Read(hdrB, 0, hdrB.Length);
            FdiHeader hdr = Marshal.ByteArrayToStructureLittleEndian <FdiHeader>(hdrB);

            return(hdr.magic.SequenceEqual(_signature));
        }
Esempio n. 2
0
        public bool Identify(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);

            FdiHeader hdr = new FdiHeader();

            if (stream.Length < Marshal.SizeOf(hdr))
            {
                return(false);
            }

            byte[] hdrB = new byte[Marshal.SizeOf(hdr)];
            stream.Read(hdrB, 0, hdrB.Length);

            GCHandle handle = GCHandle.Alloc(hdrB, GCHandleType.Pinned);

            hdr = (FdiHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(FdiHeader));
            handle.Free();

            return(hdr.magic.SequenceEqual(signature));
        }
Esempio n. 3
0
        public bool Open(IFilter imageFilter)
        {
            Stream stream = imageFilter.GetDataForkStream();

            stream.Seek(0, SeekOrigin.Begin);

            FdiHeader hdr = new FdiHeader();

            if (stream.Length < Marshal.SizeOf(hdr))
            {
                return(false);
            }

            byte[] hdrB = new byte[Marshal.SizeOf(hdr)];
            stream.Read(hdrB, 0, hdrB.Length);

            GCHandle handle = GCHandle.Alloc(hdrB, GCHandleType.Pinned);

            hdr = (FdiHeader)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(FdiHeader));
            handle.Free();

            DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.addInfoLen = {0}", hdr.addInfoLen);
            DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.cylinders = {0}", hdr.cylinders);
            DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.dataOff = {0}", hdr.dataOff);
            DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.descOff = {0}", hdr.descOff);
            DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.flags = {0}", hdr.flags);
            DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.heads = {0}", hdr.heads);

            stream.Seek(hdr.descOff, SeekOrigin.Begin);
            byte[] description = new byte[hdr.dataOff - hdr.descOff];
            stream.Read(description, 0, description.Length);
            imageInfo.Comments = StringHandlers.CToString(description);

            DicConsole.DebugWriteLine("UkvFdi plugin", "hdr.description = \"{0}\"", imageInfo.Comments);

            stream.Seek(0xE + hdr.addInfoLen, SeekOrigin.Begin);

            long spt = long.MaxValue;

            uint[][][] sectorsOff = new uint[hdr.cylinders][][];
            sectorsData = new byte[hdr.cylinders][][][];

            imageInfo.Cylinders = hdr.cylinders;
            imageInfo.Heads     = hdr.heads;

            // Read track descriptors
            for (ushort cyl = 0; cyl < hdr.cylinders; cyl++)
            {
                sectorsOff[cyl]  = new uint[hdr.heads][];
                sectorsData[cyl] = new byte[hdr.heads][][];

                for (ushort head = 0; head < hdr.heads; head++)
                {
                    byte[] sctB = new byte[4];
                    stream.Read(sctB, 0, 4);
                    stream.Seek(2, SeekOrigin.Current);
                    byte sectors = (byte)stream.ReadByte();
                    uint trkOff  = BitConverter.ToUInt32(sctB, 0);

                    DicConsole.DebugWriteLine("UkvFdi plugin", "trkhdr.c = {0}", cyl);
                    DicConsole.DebugWriteLine("UkvFdi plugin", "trkhdr.h = {0}", head);
                    DicConsole.DebugWriteLine("UkvFdi plugin", "trkhdr.sectors = {0}", sectors);
                    DicConsole.DebugWriteLine("UkvFdi plugin", "trkhdr.off = {0}", trkOff);

                    sectorsOff[cyl][head]  = new uint[sectors];
                    sectorsData[cyl][head] = new byte[sectors][];

                    if (sectors < spt && sectors > 0)
                    {
                        spt = sectors;
                    }

                    for (ushort sec = 0; sec < sectors; sec++)
                    {
                        byte        c    = (byte)stream.ReadByte();
                        byte        h    = (byte)stream.ReadByte();
                        byte        r    = (byte)stream.ReadByte();
                        byte        n    = (byte)stream.ReadByte();
                        SectorFlags f    = (SectorFlags)stream.ReadByte();
                        byte[]      offB = new byte[2];
                        stream.Read(offB, 0, 2);
                        ushort secOff = BitConverter.ToUInt16(offB, 0);

                        DicConsole.DebugWriteLine("UkvFdi plugin", "sechdr.c = {0}", c);
                        DicConsole.DebugWriteLine("UkvFdi plugin", "sechdr.h = {0}", h);
                        DicConsole.DebugWriteLine("UkvFdi plugin", "sechdr.r = {0}", r);
                        DicConsole.DebugWriteLine("UkvFdi plugin", "sechdr.n = {0} ({1})", n, 128 << n);
                        DicConsole.DebugWriteLine("UkvFdi plugin", "sechdr.f = {0}", f);
                        DicConsole.DebugWriteLine("UkvFdi plugin", "sechdr.off = {0} ({1})", secOff,
                                                  secOff + trkOff + hdr.dataOff);

                        // TODO: This assumes sequential sectors.
                        sectorsOff[cyl][head][sec]  = secOff + trkOff + hdr.dataOff;
                        sectorsData[cyl][head][sec] = new byte[128 << n];

                        if (128 << n > imageInfo.SectorSize)
                        {
                            imageInfo.SectorSize = (uint)(128 << n);
                        }
                    }
                }
            }

            // Read sectors
            for (ushort cyl = 0; cyl < hdr.cylinders; cyl++)
            {
                bool emptyCyl = false;

                for (ushort head = 0; head < hdr.heads; head++)
                {
                    for (ushort sec = 0; sec < sectorsOff[cyl][head].Length; sec++)
                    {
                        stream.Seek(sectorsOff[cyl][head][sec], SeekOrigin.Begin);
                        stream.Read(sectorsData[cyl][head][sec], 0, sectorsData[cyl][head][sec].Length);
                    }

                    // For empty cylinders
                    if (sectorsOff[cyl][head].Length != 0)
                    {
                        continue;
                    }

                    if (cyl + 1 == hdr.cylinders ||
                        // Next cylinder is also empty
                        sectorsOff[cyl + 1][head].Length == 0)
                    {
                        emptyCyl = true;
                    }
                    // Create empty sectors
                    else
                    {
                        sectorsData[cyl][head] = new byte[spt][];
                        for (int i = 0; i < spt; i++)
                        {
                            sectorsData[cyl][head][i] = new byte[imageInfo.SectorSize];
                        }
                    }
                }

                if (emptyCyl)
                {
                    imageInfo.Cylinders--;
                }
            }

            // TODO: What about double sided, half track pitch compact floppies?
            imageInfo.MediaType            = MediaType.CompactFloppy;
            imageInfo.ImageSize            = (ulong)stream.Length - hdr.dataOff;
            imageInfo.CreationTime         = imageFilter.GetCreationTime();
            imageInfo.LastModificationTime = imageFilter.GetLastWriteTime();
            imageInfo.MediaTitle           = Path.GetFileNameWithoutExtension(imageFilter.GetFilename());
            imageInfo.SectorsPerTrack      = (uint)spt;
            imageInfo.Sectors      = imageInfo.Cylinders * imageInfo.Heads * imageInfo.SectorsPerTrack;
            imageInfo.XmlMediaType = XmlMediaType.BlockMedia;

            return(true);
        }