public Partition( Device device, MBRPartitionEntry entry ) { this.device = device; partition_id = entry.id; partition_start = ( Int64 ) entry.start_lba * ( Int64 ) device.SectorSize; partition_length = ( Int64 ) entry.size_lba * ( Int64 ) device.SectorSize; }
public static FileSystem GetFileSystem( Device device, MBRPartitionEntry entry ) { return new Ext( device, entry ); }
public List <FileSystem> GetFileSystems() { List <FileSystem> filesystems = new List <FileSystem>(); if (stream == null || !stream.CanRead) { return(filesystems); } Byte[] sector = new Byte[sector_size]; stream.Read(sector, 0, (int)sector_size); if (sector[510] != 0x55 || sector[511] != 0xaa) { return(filesystems); // mbr magic number missing } List <MBRPartitionEntry> mbr_partitions = new List <MBRPartitionEntry>(); MBRPartitionEntry current_partition; int partition_id = 0; for (UInt32 i = 0; i < 4; i++) { current_partition = new MBRPartitionEntry(); current_partition.Parse(sector, 446 + i * 16); if (known_partition_types.Contains(current_partition.type)) // known { current_partition.id = partition_id; mbr_partitions.Add(current_partition); ++partition_id; } else if (current_partition.type == PartitionType.Extended) // extended partition: contains others { Byte[] extended_sector = new Byte[sector_size]; MBRPartitionEntry extended_entry = new MBRPartitionEntry(); MBRPartitionEntry extended_next = new MBRPartitionEntry(); do { stream.Seek((( Int64 )current_partition.start_lba + ( Int64 )extended_next.start_lba) * ( Int64 )sector_size, SeekOrigin.Begin); stream.Read(extended_sector, 0, (int)sector_size); extended_entry.Parse(extended_sector, 446); extended_entry.start_lba += current_partition.start_lba + extended_next.start_lba; extended_next.Parse(extended_sector, 446 + 16); if (known_partition_types.Contains(extended_entry.type)) { extended_entry.id = partition_id; mbr_partitions.Add(extended_entry); extended_entry = new MBRPartitionEntry(); } ++partition_id; } while (extended_next.size_lba != 0); } else // unknown { ++partition_id; } } foreach (MBRPartitionEntry mbr_entry in mbr_partitions) { FileSystem fs = null; switch (mbr_entry.type) { case PartitionType.Ext: { FileSystem temp = null; try { temp = new Ext(this, mbr_entry); fs = temp; } catch (Exception) {} break; } } if (fs != null) { filesystems.Add(fs); } } return(filesystems); }
public List<FileSystem> GetFileSystems() { List< FileSystem > filesystems = new List< FileSystem >(); if ( stream == null || !stream.CanRead ) return filesystems; Byte[] sector = new Byte[ sector_size ]; stream.Read( sector, 0, (int)sector_size ); if ( sector[ 510 ] != 0x55 || sector[ 511 ] != 0xaa ) return filesystems; // mbr magic number missing List< MBRPartitionEntry > mbr_partitions = new List< MBRPartitionEntry >(); MBRPartitionEntry current_partition; int partition_id = 0; for ( UInt32 i=0; i<4; i++ ) { current_partition = new MBRPartitionEntry(); current_partition.Parse( sector, 446 + i*16 ); if ( known_partition_types.Contains( current_partition.type ) ) // known { current_partition.id = partition_id; mbr_partitions.Add( current_partition ); ++partition_id; } else if ( current_partition.type == PartitionType.Extended ) // extended partition: contains others { Byte[] extended_sector = new Byte[ sector_size ]; MBRPartitionEntry extended_entry = new MBRPartitionEntry(); MBRPartitionEntry extended_next = new MBRPartitionEntry(); do { stream.Seek( ( ( Int64 ) current_partition.start_lba + ( Int64 ) extended_next.start_lba ) * ( Int64 ) sector_size, SeekOrigin.Begin ); stream.Read( extended_sector, 0, (int)sector_size ); extended_entry.Parse( extended_sector, 446 ); extended_entry.start_lba += current_partition.start_lba + extended_next.start_lba; extended_next.Parse( extended_sector, 446 + 16 ); if ( known_partition_types.Contains( extended_entry.type ) ) { extended_entry.id = partition_id; mbr_partitions.Add( extended_entry ); extended_entry = new MBRPartitionEntry(); } ++partition_id; } while ( extended_next.size_lba != 0 ); } else // unknown { ++partition_id; } } foreach ( MBRPartitionEntry mbr_entry in mbr_partitions ) { FileSystem fs = null; switch ( mbr_entry.type ) { case PartitionType.Ext: { FileSystem temp = null; try { temp = new Ext( this, mbr_entry ); fs = temp; } catch ( Exception ) {} break; } } if ( fs != null ) filesystems.Add( fs ); } return filesystems; }