Пример #1
0
 public Partition(BlockDevice host, ulong startingSector, ulong sectorCount)
 {
     Host           = host;
     StartingSector = startingSector;
     BlockCount     = sectorCount;
     BlockSize      = host.BlockSize;
 }
Пример #2
0
 public MBTPartition(BlockDevice aBackend, uint aBlockStart, uint aBlockCount, string aName)
 {
     mBlockStart = aBlockStart;
     mBlockCount = aBlockCount;
     mBackend    = aBackend;
     mName       = aName;
 }
Пример #3
0
 public void Setup(BlockDevice host, ulong offset, ulong size, uint id)
 {
     this.host   = host;
     this.offset = offset;
     this.size   = size;
     this.id     = id;
 }
Пример #4
0
 public MBRPartition(IBMPartitionInformation info, MBR mbr)
 {
     Mbr        = mbr;
     Start      = info.StartLBA;
     Length     = info.LengthLBA;
     Identifier = info.PartitionType;
     blockDev   = mbr.blockdevice;
 }
Пример #5
0
        protected Volume (BlockDevice parent, Hal.Manager manager, Hal.Device device) : base (manager, device)
        {
            this.parent = parent ?? BlockDevice.Resolve<IBlockDevice> (manager, device.Parent);
            dk_disk = DkDisk.FindByDevice (DeviceNode);

            method_names = HalDevice.PropertyExists (method_names_property)
                ? device.GetPropertyStringList (method_names_property)
                : new string[0];
        }
Пример #6
0
 /// <summary>
 /// Constructor for a primary partition
 /// </summary>
 /// <param name="aHost"></param>
 /// <param name="aStartingSector"></param>
 /// <param name="aSectorCount"></param>
 /// <param name="info"></param>
 public PrimaryPartition(BlockDevice aHost, ulong aStartingSector, ulong aSectorCount, PartitionInfo info)
     : base(aHost, aStartingSector, aSectorCount)
 {
     HostDevice     = aHost;
     StartingSector = aStartingSector;
     mBlockCount    = aSectorCount;
     mBlockSize     = aHost.BlockSize;
     _infos         = info;
 }
Пример #7
0
 /// <summary>
 /// Initializes a new MBR object getting the content of the first block of the disk
 /// </summary>
 /// <param name="aMBR">Byte rapresentation of the first disk block</param>
 public MBR(byte[] aMBR, BlockDevice device)
 {
     this.blockDevice = device;
     Utilities.CopyByteToByte(aMBR, 0, Bootable, 0, 440);
     Signature = BitConverter.ToUInt32(aMBR, 440);
     ParsePartition(aMBR, 446);
     ParsePartition(aMBR, 462);
     ParsePartition(aMBR, 478);
     ParsePartition(aMBR, 494);
 }
Пример #8
0
 public Disk(BlockDevice mainBlockDevice)
 {
     Host = mainBlockDevice;
     foreach (var part in Partition.Partitions)
     {
         if (part.Host == mainBlockDevice)
         {
             parts.Add(new ManagedPartition(part));
         }
     }
     Size = (int)(mainBlockDevice.BlockCount * mainBlockDevice.BlockSize);
 }
Пример #9
0
        private static void DetectFilesystem(BlockDevice aDevice)
        {
            #region Ext2
            if (Ext2.BlockDeviceContainsExt2(aDevice))
            {
                aDevice.Used = true;
                var xFS = new Ext2(aDevice);
                mFilesystems.Add(xFS);
            }

            #endregion
        }
Пример #10
0
 public static bool BlockDeviceContainsExt2(BlockDevice aDevice)
 {
     if (aDevice.BlockCount > 3)
     {
         byte[] xBuffer = new byte[aDevice.BlockSize];
         // todo: implement better detection
         aDevice.ReadBlock(2,
                           xBuffer);
         bool xResult = (xBuffer[56] == 0x53 && xBuffer[57] == 0xEF);
         return(xResult);
     }
     return(false);
 }
Пример #11
0
        private byte BlockReadByte(long offset)
        {
            var block = offset / BlockDevice.BlockSize;

            if (_bufferOffset != block)
            {
                _buffer       = BlockDevice.ReadBlock(block);
                _bufferOffset = block;
            }

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

            return(_buffer[localOffset]);
        }
 public FlowFS()
 {
     if (BlockDevice.Devices.Count > 0)
     {
         for (int i = 0; i < BlockDevice.Devices.Count; i++)
         {
             BlockDevice Device = BlockDevice.Devices[i];
             if (Device is Partition)
             {
                 new FlowFS((Partition)Device);
             }
         }
     }
 }
Пример #13
0
        private static List <Device> getPartitions(BlockDevice xBlockDev)
        {
            if (xBlockDev == null)
            {
                return(default(List <Device>));
            }

            List <Device> partitionList  = new List <Device>();
            int           xContentsIndex = 0x1BE;

            //DebugUtil.SendMessage("MBT", "Found Device");
            byte[] xBlockContents = new byte[xBlockDev.BlockSize];
            xBlockDev.ReadBlock(0, xBlockContents);
            // detecting whether MBT or not
            //DebugUtil.SendNumber("MBT", "xBlockDev.BlockSize", xBlockDev.BlockSize, 32);

            //DebugUtil.SendDoubleNumber("MBT", "Last bytes of block", xBlockContents[510], 8, xBlockContents[511], 8);
            if (!(xBlockContents[xBlockDev.BlockSize - 2] == 0x55 && xBlockContents[xBlockDev.BlockSize - 1] == 0xAA))
            {
                //DebugUtil.SendMessage("MBT", "Does not contain MBR");
                //Hardware.DebugUtil.SendATA_BlockReceived(255, 255, 0, xBlockContents);
                return(default(List <Device>));
            }

            for (byte j = 0; j < 4; j++)
            {
                //DebugUtil.SendNumber("MBT", "Partition Status", xBlockContents[xContentsIndex], 8);
                if (!(xBlockContents[xContentsIndex] == 0x80 || xBlockContents[xContentsIndex] == 0))
                {
                    xContentsIndex += 16;
                    continue;
                }
                xContentsIndex += 8;
                uint xStart = BitConverter.ToUInt32(xBlockContents, xContentsIndex);
                xContentsIndex += 4;
                uint xLength = BitConverter.ToUInt32(xBlockContents, xContentsIndex);
                xContentsIndex += 4;
                if (xStart > 0 && xLength > 0)
                {
                    //DebugUtil.SendDoubleNumber("MBT", "Entry Found. Start, Length in blocks", xStart, 32, xLength, 32);
                    xStart += 2;
                    Console.WriteLine("Add Partition to Device list");
                    partitionList.Add(new MBTPartition(xBlockDev, xStart, xLength, "Partition")); //Causes System Fault on the HTC Shift!
                    //DebugUtil.SendMessage("MBT", "FoundPartition");
                }
            }

            return(partitionList);
        }
Пример #14
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);
        }
Пример #15
0
        public static Volume Resolve (BlockDevice parent, Hal.Manager manager, Hal.Device device)
        {
            if (!device.IsVolume) {
                return null;
            }

            try {
                Volume volume = (parent is ICdromDevice || (parent == null && device.QueryCapability ("volume.disc")))
                    ? DiscVolume.Resolve (parent, manager, device)
                    : new Volume (parent, manager, device);

                return CheckVolumeMounted (volume) ? volume : null;
            } catch (Exception e) {
                Hyena.Log.Exception (e);
            }

            return null;
        }
Пример #16
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);
        }
Пример #17
0
    static void InitAta(BlockDevice.Ata.ControllerIdEnum aControllerID, BlockDevice.Ata.BusPositionEnum aBusPosition) {
      var xIO = aControllerID == BlockDevice.Ata.ControllerIdEnum.Primary ? Cosmos.Core.Global.BaseIOGroups.ATA1 : Cosmos.Core.Global.BaseIOGroups.ATA2;
      var xATA = new BlockDevice.AtaPio(xIO, aControllerID, aBusPosition);
      if (xATA.DriveType != BlockDevice.AtaPio.SpecLevel.Null) {
        BlockDevice.BlockDevice.Devices.Add(xATA);        
          var xMbrData = new byte[512];
          xATA.ReadBlock(0UL, 1U, xMbrData);
          var xMBR = new BlockDevice.MBR(xMbrData);

          if (xMBR.EBRLocation != 0)
          {
              //EBR Detected
              var xEbrData = new byte[512];
              xATA.ReadBlock(xMBR.EBRLocation, 1U, xEbrData);
              var xEBR = new BlockDevice.EBR(xEbrData);

              for (int i = 0; i < xEBR.Partitions.Count; i++)
              {
                  //var xPart = xEBR.Partitions[i];
                  //var xPartDevice = new BlockDevice.Partition(xATA, xPart.StartSector, xPart.SectorCount);
                  //BlockDevice.BlockDevice.Devices.Add(xPartDevice);
              }
          }

          // TODO Change this to foreach when foreach is supported
          Console.WriteLine("Number of MBR partitions found:  " + xMBR.Partitions.Count);
          for (int i = 0; i < xMBR.Partitions.Count; i++)
          {
              var xPart = xMBR.Partitions[i];
              if (xPart == null)
              {
                  Console.WriteLine("Null partition found at idx " + i);
              }
              else
              {
                  var xPartDevice = new BlockDevice.Partition(xATA, xPart.StartSector, xPart.SectorCount);
                  BlockDevice.BlockDevice.Devices.Add(xPartDevice);
                  Console.WriteLine("Found partition at idx " + i);
              }
          }
      }
    }
Пример #18
0
        public FatFileSystem(BlockDevice aDevice)
        {
            mDevice = aDevice;
            byte[] xBPB = mDevice.NewBlockArray(1);

            mDevice.ReadBlock(0UL, 1U, xBPB);

            UInt16 xSig = xBPB.ToUInt16(510);

            if (xSig != 0xAA55)
            {
                throw new Exception("FAT signature not found.");
            }

            BytesPerSector      = xBPB.ToUInt16(11);
            SectorsPerCluster   = xBPB[13];
            BytesPerCluster     = BytesPerSector * SectorsPerCluster;
            ReservedSectorCount = xBPB.ToUInt16(14);
            NumberOfFATs        = xBPB[16];
            RootEntryCount      = xBPB.ToUInt16(17);

            TotalSectorCount = xBPB.ToUInt16(19);
            if (TotalSectorCount == 0)
            {
                TotalSectorCount = xBPB.ToUInt32(32);
            }

            // FATSz
            FatSectorCount = xBPB.ToUInt16(22);
            if (FatSectorCount == 0)
            {
                FatSectorCount = xBPB.ToUInt32(36);
            }
            //Global.Dbg.Send("FAT Sector Count: " + FatSectorCount);

            DataSectorCount = TotalSectorCount - (ReservedSectorCount + (NumberOfFATs * FatSectorCount) + ReservedSectorCount);

            // Computation rounds down.
            ClusterCount = DataSectorCount / SectorsPerCluster;
            // Determine the FAT type. Do not use another method - this IS the official and
            // proper way to determine FAT type.
            // Comparisons are purposefully < and not <=
            // FAT16 starts at 4085, FAT32 starts at 65525
            if (ClusterCount < 4085)
            {
                FatType = FatTypeEnum.Fat12;
            }
            else if (ClusterCount < 65525)
            {
                FatType = FatTypeEnum.Fat16;
            }
            else
            {
                FatType = FatTypeEnum.Fat32;
            }

            if (FatType == FatTypeEnum.Fat32)
            {
                RootCluster = xBPB.ToUInt32(44);
            }
            else
            {
                RootSector      = ReservedSectorCount + (NumberOfFATs * FatSectorCount);
                RootSectorCount = (RootEntryCount * 32 + (BytesPerSector - 1)) / BytesPerSector;
            }
            DataSector = ReservedSectorCount + (NumberOfFATs * FatSectorCount) + RootSectorCount;
        }
Пример #19
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);
        }
Пример #20
0
 /// <summary>
 /// Constructor for the class instance, used for IO
 /// </summary>
 /// <param name="Device"></param>
 public IDE(ATA_PIO Device)
 {
     this.blockDevice = Device;
 }
Пример #21
0
 private DiscVolume (BlockDevice parent, Hal.Manager manager, Hal.Device device) : base (parent, manager, device)
 {
 }
Пример #22
0
 public new static DiscVolume Resolve (BlockDevice parent, Hal.Manager manager, Hal.Device device)
 {
     return device.QueryCapability ("volume.disc") ? new DiscVolume (parent, manager, device) : null;
 }
Пример #23
0
 public Ext2(BlockDevice aBackend)
 {
     mBackend = aBackend;
     Initialize();
 }
 /// <summary>
 /// Creates a new IDE object based on the blockdevice
 /// </summary>
 /// <param name="blockDevice">The blockdevice to use</param>
 public IDE(BlockDevice blockDevice)
 {
     this.blockDevice = blockDevice;
 }
 /// <summary>
 /// Creates a new IDE object based on the blockdevice
 /// </summary>
 /// <param name="blockDevice">The blockdevice to use</param>
 public IDE(AtaPio blockDevice)
 {
     this.blockDevice = blockDevice;
 }
Пример #26
0
 public FatFileSystem(BlockDevice aDevice)
 {
     this.IDevice  = aDevice;
     this.mIsValid = IsFAT();
 }