Android Open Source - libaums Master Boot Record






From Project

Back to project page libaums.

License

The source code is released under:

Apache License

If you think the Android project libaums listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * (C) Copyright 2014 mjahnen <jahnen@in.tum.de>
 */*from w  w  w  .j av  a 2 s.c o  m*/
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package com.github.mjdev.libaums.partition.mbr;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import android.util.Log;

import com.github.mjdev.libaums.partition.PartitionTable;
import com.github.mjdev.libaums.partition.PartitionTableEntry;

/**
 * This class represents the Master Boot Record (MBR), which is a partition
 * table used by most block devices coming from Windows or Unix.
 * 
 * @author mjahnen
 * 
 */
public class MasterBootRecord implements PartitionTable {

  private static final String TAG = MasterBootRecord.class.getSimpleName();
  private static final int TABLE_OFFSET = 446;
  private static final int TABLE_ENTRY_SIZE = 16;

  public List<PartitionTableEntry> partitions = new ArrayList<PartitionTableEntry>();

  private MasterBootRecord() {

  }

  /**
   * Reads and parses the MBR located in the buffer.
   * 
   * @param buffer
   *            The data which shall be examined.
   * @return A new {@link #MasterBootRecord()} or null if the data does not
   *         seem to be a MBR.
   */
  public static MasterBootRecord read(ByteBuffer buffer) {
    MasterBootRecord result = new MasterBootRecord();
    buffer.order(ByteOrder.LITTLE_ENDIAN);

    // test if it is a valid master boot record
    if (buffer.get(510) != (byte) 0x55 || buffer.get(511) != (byte) 0xaa) {
      Log.i(TAG, "not a valid mbr partition table!");
      return null;
    }

    for (int i = 0; i < 4; i++) {
      int offset = TABLE_OFFSET + i * TABLE_ENTRY_SIZE;
      byte partitionType = buffer.get(offset + 4);
      // unused partition
      if (partitionType == 0)
        continue;
      if (partitionType == 0x05 || partitionType == 0x0f) {
        Log.w(TAG, "extended partitions are currently unsupported!");
        continue;
      }

      PartitionTableEntry entry = new PartitionTableEntry(partitionType,
          buffer.getInt(offset + 8), buffer.getInt(offset + 12));

      result.partitions.add(entry);
    }

    return result;
  }

  @Override
  public int getSize() {
    return 512;
  }

  @Override
  public Collection<PartitionTableEntry> getPartitionTableEntries() {
    return partitions;
  }
}




Java Source Code List

com.github.mjdev.libaums.UsbCommunication.java
com.github.mjdev.libaums.UsbMassStorageDevice.java
com.github.mjdev.libaums.driver.BlockDeviceDriverFactory.java
com.github.mjdev.libaums.driver.BlockDeviceDriver.java
com.github.mjdev.libaums.driver.scsi.ScsiBlockDevice.java
com.github.mjdev.libaums.driver.scsi.commands.CommandBlockWrapper.java
com.github.mjdev.libaums.driver.scsi.commands.CommandStatusWrapper.java
com.github.mjdev.libaums.driver.scsi.commands.ScsiInquiryResponse.java
com.github.mjdev.libaums.driver.scsi.commands.ScsiInquiry.java
com.github.mjdev.libaums.driver.scsi.commands.ScsiRead10.java
com.github.mjdev.libaums.driver.scsi.commands.ScsiReadCapacityResponse.java
com.github.mjdev.libaums.driver.scsi.commands.ScsiReadCapacity.java
com.github.mjdev.libaums.driver.scsi.commands.ScsiRequestSense.java
com.github.mjdev.libaums.driver.scsi.commands.ScsiTestUnitReady.java
com.github.mjdev.libaums.driver.scsi.commands.ScsiWrite10.java
com.github.mjdev.libaums.fs.FileSystemFactory.java
com.github.mjdev.libaums.fs.FileSystem.java
com.github.mjdev.libaums.fs.UsbFile.java
com.github.mjdev.libaums.fs.fat32.ClusterChain.java
com.github.mjdev.libaums.fs.fat32.FAT.java
com.github.mjdev.libaums.fs.fat32.Fat32BootSector.java
com.github.mjdev.libaums.fs.fat32.Fat32FileSystem.java
com.github.mjdev.libaums.fs.fat32.FatDirectoryEntry.java
com.github.mjdev.libaums.fs.fat32.FatDirectory.java
com.github.mjdev.libaums.fs.fat32.FatFile.java
com.github.mjdev.libaums.fs.fat32.FatLfnDirectoryEntry.java
com.github.mjdev.libaums.fs.fat32.FsInfoStructure.java
com.github.mjdev.libaums.fs.fat32.ShortNameGenerator.java
com.github.mjdev.libaums.fs.fat32.ShortName.java
com.github.mjdev.libaums.partition.PartitionTableEntry.java
com.github.mjdev.libaums.partition.PartitionTableFactory.java
com.github.mjdev.libaums.partition.PartitionTable.java
com.github.mjdev.libaums.partition.Partition.java
com.github.mjdev.libaums.partition.mbr.MasterBootRecord.java
com.github.mjdev.libaums.usbfileman.MainActivity.java
com.github.mjdev.libaums.usbfileman.MoveClipboard.java
com.github.mjdev.libaums.usbfileman.UsbFileListAdapter.java