Esempio n. 1
0
        public static BFSTOC FromSector(byte[] buff)
        {
            GCHandle handle = GCHandle.Alloc(buff, GCHandleType.Pinned);
            BFSTOC   s      = (BFSTOC)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(BFSTOC));

            handle.Free();
            return(s);
        }
Esempio n. 2
0
        public static Boolean IsBFS(string drive)
        {
            Boolean test = true;

            //Check if first Partition is BFS
            byte[] first;
            first = llda.ReadSector(drive, 0, 4096 * 5);
            if (first != null)
            {
                gpt  = GPT.FromSectors(first);
                test = test && (gpt.gptPartitionTable.partitions[0].BFSParitionType == new Guid("53525542-4354-494F-4E46-494C45535953"));
                //Check if BFSTOC v1 exists
                bfsTOC = BFSTOC.FromSector(llda.ReadSector(drive, 5, 4096));
                byte[] version = Encoding.ASCII.GetBytes("BFS1");
                test = test && bfsTOC.version.SequenceEqual(version);
                return(test);
            }
            return(false);
        }
Esempio n. 3
0
        public static BFSTOC emptyToc(UInt64 totalSectors, UInt32 bytesPerSector, Boolean gpt)
        {
            BFSTOC s = new BFSTOC
            {
                version   = Encoding.ASCII.GetBytes("BFS1"),
                diskspace = (((totalSectors * bytesPerSector / 4096) - 3) / 64 / 64) * 64 * 64,
            };

            s.plotFiles = new BFSPlotFile[72];
            if (gpt)
            {
                s.plotFiles[0].startPos = 6;
            }
            else
            {
                s.plotFiles[0].startPos = 2;
            }
            s.UpdateCRC32();
            return(s);
        }
Esempio n. 4
0
        public static void FormatDriveGPT(string drive, UInt64 totalSectors, UInt32 bytesPerSector, UInt64 id)
        {
            //create GPT
            GPT gpt = new GPT(totalSectors, bytesPerSector);

            byte[] test = gpt.ToByteArray();
            //create BFSTOC
            BFSTOC bfsTOC = BFSTOC.emptyToc(totalSectors, bytesPerSector, true);

            bfsTOC.id = id;
            //write GPT
            llda.WriteSector(drive, 0, 4096, gpt.ToByteArray());
            //write MirrorGPT
            gpt.ToggleMirror();
            llda.WriteSector(drive, (Int64)totalSectors - 40, 512, gpt.ToGPTMirrorByteArray());
            //write  BFSTOC
            llda.WriteSector(drive, 5, 4096, bfsTOC.ToByteArray());
            //write mirror BFSTOC
            llda.WriteSector(drive, 6 + (Int64)bfsTOC.diskspace, 4096, bfsTOC.ToByteArray());
            //trigger OS partition table re-read
            llda.refreshDrive(drive);
        }
Esempio n. 5
0
 public static void LoadBFSTOC(string drive)
 {
     bfsTOC = BFSTOC.FromSector(llda.ReadSector(drive, 5, 4096));
 }