Пример #1
0
        /// <summary>
        /// Writes the specified byte[] array to the specified block and number of blocks
        /// </summary>
        /// <param name="aBlockNo">Starting block number</param>
        /// <param name="aBlockCount">Number of blocks to write to</param>
        /// <param name="aData">Byte[] array containing data to be written</param>
        public override void WriteBlock(ulong aBlockNo, ulong aBlockCount, ref byte[] aData)
        {
            UInt64 HostBlockNumber = StartingSector + aBlockNo;

            CheckBlockNo(HostBlockNumber, aBlockCount);
            HostDevice.WriteBlock(HostBlockNumber, aBlockCount, ref aData);
        }
Пример #2
0
        /// <summary>
        /// Writes a number a buffer down to the current partition
        /// </summary>
        /// <param name="aBlockNo">Start block number</param>
        /// <param name="aBlockCount">Number of blocks</param>
        /// <param name="aData">Buffer to read from</param>
        public override void WriteBlock(UInt64 aBlockNo, UInt32 aBlockCount, byte[] aData)
        {
            UInt64 xHostBlockNo = mStartingSector + aBlockNo;

            CheckBlockNo(xHostBlockNo, aBlockCount);
            mHost.WriteBlock(xHostBlockNo, aBlockCount, aData);
        }
Пример #3
0
        public override void WriteBlock(ulong blockNo, ulong blockCount, ref byte[] data)
        {
            CheckDataSize(data, blockCount);
            var hostBlockNo = StartingSector + blockNo;

            CheckBlockNo(hostBlockNo, blockCount);
            Host.WriteBlock(hostBlockNo, blockCount, ref data);
        }
Пример #4
0
        private void BlockWriteOffsetByte(long offset, byte b)
        {
            var block = offset / BlockDevice.BlockSize;

            if (_readBufferOffset != block)
            {
                _readBuffer       = BlockDevice.ReadBlock(block);
                _readBufferOffset = block;
            }

            var localOffset = offset - (block * BlockDevice.BlockSize);

            _readBuffer[localOffset] = b;

            BlockDevice.WriteBlock(block, _readBuffer);
        }
Пример #5
0
        private void BlockWriteOffsetBytes(long offset, byte[] b)
        {
            var block = offset / BlockDevice.BlockSize;

            if (_readBufferOffset != block)
            {
                _readBuffer       = BlockDevice.ReadBlock(block);
                _readBufferOffset = block;
            }

            var localOffset = offset - (block * BlockDevice.BlockSize);

            foreach (var b1 in b)
            {
                _readBuffer[localOffset++] = b1;
            }

            BlockDevice.WriteBlock(block, _readBuffer);
        }
Пример #6
0
        /// <summary>
        /// Create Partition.
        /// </summary>
        /// <param name="size">Size in MB.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if start / end is smaller then 0.</exception>
        /// <exception cref="ArgumentException">Thrown if end is smaller or equal to start.</exception>
        /// <exception cref="NotImplementedException">Thrown if partition type is GPT.</exception>
        public void CreatePartition(int size)
        {
            if (size == 0 | size < 0)
            {
                throw new ArgumentException("size");
            }
            if (GPT.IsGPTPartition(Host))
            {
                throw new Exception("Creating partitions with GPT style not yet supported!");
            }

            int  location;
            int  startingSector  = 63;
            uint amountOfSectors = (uint)(size * 1024 * 1024 / 512);

            //TODO: Check if partition is too big

            if (Partitions.Count == 0)
            {
                location       = 446;
                startingSector = 63;
            }
            else if (Partitions.Count == 1)
            {
                location       = 462;
                startingSector = (int)(Partitions[0].Host.BlockSize + Partitions[0].Host.BlockCount);
            }
            else if (Partitions.Count == 2)
            {
                location = 478;
            }
            else if (Partitions.Count == 3)
            {
                location = 494;
            }
            else
            {
                throw new NotImplementedException("Extended partitons not yet supported.");
            }

            //Create MBR
            var mbrData = new byte[512];

            Host.ReadBlock(0, 1, ref mbrData);
            mbrData[location + 0] = 0x80; //bootable
            mbrData[location + 1] = 0x1;  //starting head
            mbrData[location + 2] = 0;    //Starting sector
            mbrData[location + 3] = 0x0;  //Starting Cylinder
            mbrData[location + 4] = 83;   //normal partition
            mbrData[location + 5] = 0xFE; //ending head
            mbrData[location + 6] = 0x3F; //Ending Sector
            mbrData[location + 7] = 0x40; //Ending Cylinder

            //Starting Sector
            byte[] startingSectorBytes = BitConverter.GetBytes(startingSector);
            mbrData[location + 8]  = startingSectorBytes[0];
            mbrData[location + 9]  = startingSectorBytes[1];
            mbrData[location + 10] = startingSectorBytes[2];
            mbrData[location + 11] = startingSectorBytes[3];

            //Total Sectors in partition
            byte[] total = BitConverter.GetBytes(amountOfSectors);
            mbrData[location + 12] = total[0];
            mbrData[location + 13] = total[1];
            mbrData[location + 14] = total[2];
            mbrData[location + 15] = total[3];

            //Boot flag
            byte[] boot = BitConverter.GetBytes((ushort)0xAA55);
            mbrData[510] = boot[0];
            mbrData[511] = boot[1];

            //Save the data
            Host.WriteBlock(0, 1, ref mbrData);
        }
Пример #7
0
 public override void WriteBlock(ulong aBlock, byte[] aContents)
 {
     blockDev.WriteBlock(aBlock + Start, aContents);
 }
 /// <summary>
 /// Writes a number a buffer down to the current device
 /// </summary>
 /// <param name="aBlockNo">Start block number</param>
 /// <param name="aBlockCount">Number of blocks</param>
 /// <param name="aData">Buffer to read from</param>
 public void WriteBlock(ulong aBlockNo, uint aBlockCount, byte[] aData)
 {
     blockDevice.WriteBlock(aBlockNo, aBlockCount, aData);
 }
Пример #9
0
        public bool WriteAllBytes(string filePath, byte[] data)
        {
            if (filePath.Length > 16320)
            {
                return(false);
            }

            FileEntry fileEntry = null;

            //file names must be guid
            foreach (var entry in IndexAria)
            {
                if (entry is FileEntry fe)
                {
                    if (fe.Name == filePath)
                    {
                        fileEntry = fe;
                        break;
                    }
                }
            }

            if (fileEntry == null)
            {
                fileEntry = new FileEntry
                {
                    StartingBlock = SuperBlock.DataSizeInBlocks + SuperBlock.TotalReservedBlocks,
                    EndingBlock   = (SuperBlock.DataSizeInBlocks + SuperBlock.TotalReservedBlocks) +
                                    (data.Length / BlockDevice.BlockSize) + 1,
                    Length    = data.Length,
                    Name      = filePath,
                    TimeStamp = 0
                };

                SuperBlock.DataSizeInBlocks += fileEntry.EndingBlock - fileEntry.StartingBlock;

                //add it
                IndexAria.Insert(IndexAria.Count - 1, fileEntry);
            }

            //write data
            var bl = fileEntry.EndingBlock - fileEntry.StartingBlock;

            var buf = new byte[BlockDevice.BlockSize];

            long c = 0;

            for (int i = 0; i < bl - 1; i++)
            {
                Array.Copy(data, i * BlockDevice.BlockSize, buf, 0, BlockDevice.BlockSize);
                c += BlockDevice.BlockSize;
                BlockDevice.WriteBlock(fileEntry.StartingBlock + i, buf);
            }


            Array.Copy(data, c, buf, 0, data.Length - c);
            BlockDevice.WriteBlock(fileEntry.StartingBlock + (bl - 1), buf);

            Save();
            return(true);
        }
Пример #10
0
        public void WriteCluster(UInt64 aCluster, byte[] aData)
        {
            UInt64 xSector = DataSector + ((aCluster - 2) * SectorsPerCluster);

            mDevice.WriteBlock(xSector, SectorsPerCluster, aData);
        }
Пример #11
0
 public override void WriteBlock(ulong aBlock, byte[] aContents)
 {
     mBackend.WriteBlock(GetActualBlock(aBlock), aContents);
 }
Пример #12
0
 public void Write(ulong aBlockNo, ulong aBlockCount, byte *aData)
 {
     host.WriteBlock(aBlockNo, aBlockCount, aData);
 }