示例#1
0
 public Boolean ReadScoop(int scoop, long totalNonces, long startNonce, Scoop target, int limit)
 {
     _lPosition = scoop * (64 * totalNonces) + startNonce * 64;
     try {
         _fs.Seek(_lPosition, SeekOrigin.Begin);
     }
     catch (Exception e)
     {
         MessageBox.Show("Scoop: " + scoop.ToString() + " " + e.Message, "I/O Error - Seek to read", MessageBoxButtons.OK);
         return(false);
     }
     try {
         //interrupt avoider 1mb read 64*16384
         for (int i = 0; i < limit * 64; i += (64 * 16384))
         {
             _fs.Read(target.byteArrayField, i, Math.Min(64 * 16384, limit * 64 - i));
         }
     }
     catch (Exception e)
     {
         MessageBox.Show("Scoop: " + scoop.ToString() + " " + e.Message, "I/O Error - Read", MessageBoxButtons.OK);
         return(false);
     }
     _lPosition += limit * 64;
     return(true);
 }
示例#2
0
 public Boolean WriteScoop(int scoop, long totalNonces, long startNonce, Scoop source, int limit, Int64 offset)
 {
     _lPosition = scoop * (64 * totalNonces) + startNonce * 64 + offset;
     try
     {
         llda.Seek(_lPosition);
     }
     catch (Exception e)
     {
         MessageBox.Show("Scoop: " + scoop.ToString() + " " + e.Message, "I/O Error - Seek to write", MessageBoxButtons.OK);
         return(false);
     }
     try
     {
         //interrupt avoider 1mb write 64*16384
         //for (int i = 0; i < limit * 64; i += (8 * 16384))
         //  llda.Write(source.byteArrayField, i, Math.Min(8 * 16384, limit * 64 - i));
         //Justwrite
         llda.Write(source.byteArrayField, 0, limit * 64);
     }
     catch (Exception e)
     {
         MessageBox.Show("Scoop: " + scoop.ToString() + " " + e.Message, "I/O Error - Write", MessageBoxButtons.OK);
         return(false);
     }
     _lPosition += limit * 64;
     return(true);
 }
示例#3
0
文件: Form1.cs 项目: brmmm3/BFSTool
 //Convert Poc1>Poc2 and vice versa
 private static void Poc1poc2shuffle(Scoop scoop1, Scoop scoop2, int limit)
 {
     byte[] buffer = new byte[32];
     for (int i = 0; i < limit; i++)
     {
         Buffer.BlockCopy(scoop1.byteArrayField, 64 * i + 32, buffer, 0, 32);
         Buffer.BlockCopy(scoop2.byteArrayField, 64 * i + 32, scoop1.byteArrayField, 64 * i + 32, 32);
         Buffer.BlockCopy(buffer, 0, scoop2.byteArrayField, 64 * i + 32, 32);
     }
 }
示例#4
0
文件: Form1.cs 项目: brmmm3/BFSTool
        //upload a file to a BFS formatted drive
        private void btn_upload_Click(object sender, EventArgs e)
        {
            String drive           = drivesView.SelectedItems[0].SubItems[1].Text;
            Int32  PbytesPerSector = (Int32.Parse(drivesView.SelectedItems[0].SubItems[4].Text));

            halt1 = false;
            halt2 = false;
            Boolean  shuffle = false;
            PlotFile temp;
            //Let user select plotfile
            string filter = "PoC2 plot files | " + tb_id.Text + "_*_*.*| PoC1 plot files|" + tb_id.Text + "_*_*_*.*";

            openFileDialog.Filter = filter;
            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //Parse Flotfilename
                temp = ParsePlotFileName(openFileDialog.FileName);
            }
            else
            {
                return;
            }

            //only support optimized files
            if (temp.stagger > 0 && temp.stagger != temp.nonces)
            {
                return;
            }

            //always convert PoC1 files
            if (temp.stagger == temp.nonces)
            {
                shuffle = true;
            }

            //check ID
            if (temp.id.ToString() != tb_id.Text)
            {
                return;
            }

            //calc startoffset and endoffset for 64 nonces alignment
            UInt64 startNonceR   = temp.startNonce / 64 * 64;
            UInt64 startOffset64 = startNonceR < temp.startNonce ? startNonceR + 64 - temp.startNonce : 0;
            UInt32 endOffset64   = temp.nonces - (UInt32)startOffset64 - (temp.nonces - (UInt32)startOffset64) / 64 * 64;

            //check last file and offer to insert dummy file
            //Todo



            //Create file in bfsTOC
            int file = BFS.AddPlotFile(drive, temp.startNonce + startOffset64, temp.nonces - (UInt32)startOffset64 - endOffset64, 2, 0);

            if (file > -1)
            {
                FillBFSView(drive);
            }
            else
            {
                return;
            }

            //Get offsets
            startOffset = BFS.bfsTOC.plotFiles[file].startPos;
            scoopOffset = BFS.bfsTOC.diskspace / 4096;

            //transfer file
            //open source handle
            ScoopReadWriter reader;

            reader = new ScoopReadWriter(openFileDialog.FileName);
            reader.OpenR(true);

            ScoopReadWriter writer;

            writer = new ScoopReadWriter(drive);
            writer.OpenW();

            //Allocate memory
            int   limit  = 4096 * 4096 / 1024;                             //Write cache, 1MB
            Scoop scoop1 = new Scoop(Math.Min((Int32)temp.nonces, limit)); //space needed for one partial scoop
            Scoop scoop2 = new Scoop(Math.Min((Int32)temp.nonces, limit)); //space needed for one partial scoop
            Scoop scoop3 = new Scoop(Math.Min((Int32)temp.nonces, limit)); //space needed for one partial scoop
            Scoop scoop4 = new Scoop(Math.Min((Int32)temp.nonces, limit)); //space needed for one partial scoop


            //create masterplan
            int loops = (int)Math.Ceiling((double)(temp.nonces) / limit);

            TaskInfo[] masterplan = new TaskInfo[2048 * loops];

            for (int y = 0; y < 2048; y++)
            {
                int zz = 0;
                //loop partial scoop
                for (int z = (int)startOffset64; (ulong)z < temp.nonces - endOffset64; z += limit)
                {
                    masterplan[y * loops + zz]               = new TaskInfo();
                    masterplan[y * loops + zz].reader        = reader;
                    masterplan[y * loops + zz].writer        = writer;
                    masterplan[y * loops + zz].drive         = drive;
                    masterplan[y * loops + zz].file          = file;
                    masterplan[y * loops + zz].y             = y;
                    masterplan[y * loops + zz].z             = z;
                    masterplan[y * loops + zz].x             = y * loops + zz;
                    masterplan[y * loops + zz].limit         = limit;
                    masterplan[y * loops + zz].src           = temp;
                    masterplan[y * loops + zz].tar           = BFS.bfsTOC.plotFiles[file];
                    masterplan[y * loops + zz].scoop1        = scoop1;
                    masterplan[y * loops + zz].scoop2        = scoop2;
                    masterplan[y * loops + zz].scoop3        = scoop3;
                    masterplan[y * loops + zz].scoop4        = scoop4;
                    masterplan[y * loops + zz].shuffle       = shuffle;
                    masterplan[y * loops + zz].end           = masterplan.LongLength;
                    masterplan[y * loops + zz].startOffset64 = (int)startOffset64;
                    masterplan[y * loops + zz].endOffset64   = (int)endOffset64;

                    zz += 1;
                }
            }

            //enable stats
            tbl_x.Visible        = true;
            tbl_status.Visible   = true;
            tbl_progress.Visible = true;
            tbl_progress.Maximum = 2048;
            var task1 = Task.Factory.StartNew(() => Th_copy(masterplan));
        }