Esempio n. 1
0
        internal static byte[] GetBytes(FileStream streamToRead, Superblock superblock, uint offset)
        {
            // Derive Length of Inode Table from superblock values
            uint length = superblock.InodesPerGroup * Inode.EXT4_INODE_SIZE;

            // Get Inode Table bytes
            return(NativeMethods.readDrive(streamToRead, offset, length));
        }
Esempio n. 2
0
        public byte[] GetBytes(string volume)
        {
            IntPtr hDevice = NativeMethods.getHandle(volume);

            using (FileStream streamToRead = NativeMethods.getFileStream(hDevice))
            {
                Superblock sb = new Superblock(Superblock.GetBytes(streamToRead, 0));
                return(NativeMethods.readDrive(streamToRead, (sb.BlockSize * this.StartBlock), (sb.BlockSize * this.BlockCount)));
            }
        }
        internal static byte[] GetBytes(FileStream streamToRead, uint superblockOffset, Superblock superBlock, uint group)
        {
            // Derive the location and length of the Block Group Descriptor Table
            uint bgdtOffset  = (superblockOffset * NativeMethods.BYTES_PER_SECTOR) + ((superBlock.FirstDataBlock + 1) * superBlock.BlockSize);
            uint bgdtEntries = (superBlock.TotalBlockCount / superBlock.BlocksPerGroup) + 1;
            uint bgdtLength  = bgdtEntries * BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH;

            // Determine the offset from the beginning of the BGDT to the desired group
            uint groupOffset = group * BLOCK_GROUP_DESCRIPTOR_LENGTH;

            // Determine what Sector contains the raw bytes
            uint groupSectorOffset = groupOffset / NativeMethods.BYTES_PER_SECTOR;

            // Read the sector that the desired block resides within
            byte[] SectorBytes = NativeMethods.readDrive(streamToRead, bgdtOffset + (groupSectorOffset * NativeMethods.BYTES_PER_SECTOR), NativeMethods.BYTES_PER_SECTOR);

            // Get Block Group Descriptor offset into Sector
            uint sectorOffset = (group % BLOCK_GROUPS_PER_SECTOR) * BLOCK_GROUP_DESCRIPTOR_LENGTH;

            // Create byte[] containing only bytes for the requested Block Group Descriptor
            return(NativeMethods.GetSubArray(SectorBytes, sectorOffset, BLOCK_GROUP_DESCRIPTOR_LENGTH));
        }
        internal static byte[] GetBytes(FileStream streamToRead, uint superblockOffset, Superblock superBlock)
        {
            // Derive the location and length of the Block Group Descriptor Table
            uint offset      = (superblockOffset * NativeMethods.BYTES_PER_SECTOR) + ((superBlock.FirstDataBlock + 1) * superBlock.BlockSize);
            uint bgdtEntries = (superBlock.TotalBlockCount / superBlock.BlocksPerGroup) + 1;
            uint length      = bgdtEntries * BlockGroupDescriptor.BLOCK_GROUP_DESCRIPTOR_LENGTH;

            // Ensure the bgdtLength value is a multiple of 512 (minimum value for reading bytes from disk)
            if ((length % NativeMethods.BYTES_PER_SECTOR) != 0)
            {
                length += (NativeMethods.BYTES_PER_SECTOR - (length % NativeMethods.BYTES_PER_SECTOR));
            }

            // Get BlockGroupDescriptor bytes
            return(NativeMethods.readDrive(streamToRead, offset, length));
        }