Exemple #1
0
        public Ext( Device device, MBRPartitionEntry mbr_entry )
        {
            partition = new Partition( device, mbr_entry );
            Byte[] sector = new Byte[ device.SectorSize ];
            partition.Read( sector, 1024, device.SectorSize );

            if ( sector[ 56 ] != 0x53 || sector[ 57 ] != 0xef ) throw new Exception( "Partition is not Ext2/3/4" );

            Utils.LoadLE32( out inode_count,            sector, 0 );
            Utils.LoadLE32( out total_block_count,      sector, 4 );
            Utils.LoadLE32( out reserved_block_count,   sector, 8 );
            Utils.LoadLE32( out free_block_count,       sector, 12 );
            Utils.LoadLE32( out free_inode_count,       sector, 16 );
            Utils.LoadLE32( out first_data_block,       sector, 20 );
            Utils.LoadLE32( out block_size_pow,         sector, 24 );
            Utils.LoadLE32( out blocks_per_group,       sector, 32 );
            Utils.LoadLE32( out inodes_per_group,       sector, 40 );
            Utils.LoadLE16( out minor_revision,         sector, 62 );
            Utils.LoadLE32( out revision,               sector, 76 );
            Utils.LoadLE32( out first_useable_inode,    sector, 84 );
            Utils.LoadLE16( out inode_size,             sector, 88 );
            Utils.LoadLE32( out features_compatible,    sector, 92 );
            Utils.LoadLE32( out features_incompatible,  sector, 96 );
            Utils.LoadLE32( out features_ro_compatible, sector, 100 );
            Utils.LoadLE32( out volume_id[0],           sector, 104 );
            Utils.LoadLE32( out volume_id[1],           sector, 108 );
            Utils.LoadLE32( out volume_id[2],           sector, 112 );
            Utils.LoadLE32( out volume_id[3],           sector, 116 );
            Utils.LoadString( out volume_name, 16,      sector, 120 );
            prealloc_file   = sector[204];
            prealloc_dir    = sector[205];
            Utils.LoadString( out journal_uuid, 16,     sector, 208 );
            Utils.LoadLE32( out journal_inode,          sector, 224 );
            Utils.LoadLE32( out journal_last_orphan,    sector, 232 );
            Utils.LoadLE32( out hash_seed[0],           sector, 236 );
            Utils.LoadLE32( out hash_seed[1],           sector, 240 );
            Utils.LoadLE32( out hash_seed[2],           sector, 244 );
            Utils.LoadLE32( out hash_seed[3],           sector, 248 );
            hash_version    = sector[252];
            Utils.LoadLE32( out first_meta_block_group, sector, 260 );

            ext4 =  ( ( features_ro_compatible & 0x0008 ) != 0 ) ||
                    ( ( features_ro_compatible & 0x0010 ) != 0 ) ||
                    ( ( features_ro_compatible & 0x0020 ) != 0 ) ||
                    ( ( features_ro_compatible & 0x0040 ) != 0 ) ||
                    ( ( features_incompatible & 0x0040 ) != 0 ) ||
                    ( ( features_incompatible & 0x0080 ) != 0 ) ||
                    ( ( features_incompatible & 0x0100 ) != 0 ) ||
                    ( ( features_incompatible & 0x0200 ) != 0 ) ||
                    ( ( features_incompatible & 0x0400 ) != 0 ) ||
                    ( ( features_incompatible & 0x1000 ) != 0 );

            uint block_group_count = ( total_block_count + blocks_per_group-1 )/blocks_per_group;
            for ( uint i=0; i<block_group_count; ++i )
            {
                bg_descriptors.Add( GetGroupDescriptor( i ) );
            }
        }
        public void TestMBRPartitionEntryStructure()
        {
            var mbrPartitionStructure = new MBRPartitionEntry();
            var realSize = Marshal.SizeOf(mbrPartitionStructure);
            var expected = 16;
            var message  = String.Format("Expected: {0}, found: {1}", expected, realSize);

            Assert.AreEqual(expected, realSize, message);
        }
Exemple #3
0
        public Ext(Device device, MBRPartitionEntry mbr_entry)
        {
            partition = new Partition(device, mbr_entry);
            Byte[] sector = new Byte[device.SectorSize];
            partition.Read(sector, 1024, device.SectorSize);

            if (sector[56] != 0x53 || sector[57] != 0xef)
            {
                throw new Exception("Partition is not Ext2/3/4");
            }

            Utils.LoadLE32(out inode_count, sector, 0);
            Utils.LoadLE32(out total_block_count, sector, 4);
            Utils.LoadLE32(out reserved_block_count, sector, 8);
            Utils.LoadLE32(out free_block_count, sector, 12);
            Utils.LoadLE32(out free_inode_count, sector, 16);
            Utils.LoadLE32(out first_data_block, sector, 20);
            Utils.LoadLE32(out block_size_pow, sector, 24);
            Utils.LoadLE32(out blocks_per_group, sector, 32);
            Utils.LoadLE32(out inodes_per_group, sector, 40);
            Utils.LoadLE16(out minor_revision, sector, 62);
            Utils.LoadLE32(out revision, sector, 76);
            Utils.LoadLE32(out first_useable_inode, sector, 84);
            Utils.LoadLE16(out inode_size, sector, 88);
            Utils.LoadLE32(out features_compatible, sector, 92);
            Utils.LoadLE32(out features_incompatible, sector, 96);
            Utils.LoadLE32(out features_ro_compatible, sector, 100);
            Utils.LoadLE32(out volume_id[0], sector, 104);
            Utils.LoadLE32(out volume_id[1], sector, 108);
            Utils.LoadLE32(out volume_id[2], sector, 112);
            Utils.LoadLE32(out volume_id[3], sector, 116);
            Utils.LoadString(out volume_name, 16, sector, 120);
            prealloc_file = sector[204];
            prealloc_dir  = sector[205];
            Utils.LoadString(out journal_uuid, 16, sector, 208);
            Utils.LoadLE32(out journal_inode, sector, 224);
            Utils.LoadLE32(out journal_last_orphan, sector, 232);
            Utils.LoadLE32(out hash_seed[0], sector, 236);
            Utils.LoadLE32(out hash_seed[1], sector, 240);
            Utils.LoadLE32(out hash_seed[2], sector, 244);
            Utils.LoadLE32(out hash_seed[3], sector, 248);
            hash_version = sector[252];
            Utils.LoadLE32(out first_meta_block_group, sector, 260);

            ext4 = ((features_ro_compatible & 0x0008) != 0) ||
                   ((features_ro_compatible & 0x0010) != 0) ||
                   ((features_ro_compatible & 0x0020) != 0) ||
                   ((features_ro_compatible & 0x0040) != 0) ||
                   ((features_incompatible & 0x0040) != 0) ||
                   ((features_incompatible & 0x0080) != 0) ||
                   ((features_incompatible & 0x0100) != 0) ||
                   ((features_incompatible & 0x0200) != 0) ||
                   ((features_incompatible & 0x0400) != 0) ||
                   ((features_incompatible & 0x1000) != 0);

            uint block_group_count = (total_block_count + blocks_per_group - 1) / blocks_per_group;

            for (uint i = 0; i < block_group_count; ++i)
            {
                bg_descriptors.Add(GetGroupDescriptor(i));
            }
        }