Android Open Source - drive-mount Master Boot Record






From Project

Back to project page drive-mount.

License

The source code is released under:

Apache License

If you think the Android project drive-mount 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

/**
 * Copyright  2014 Jan Seeger//w  w w.  ja v a 2s .c  om
 *
 * 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 net.alphadev.usbstorage.partition;

import net.alphadev.usbstorage.api.device.BlockDevice;
import net.alphadev.usbstorage.util.BitStitching;

import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashSet;

/**
 * @author Jan Seeger <jan@alphadev.net>
 */
public class MasterBootRecord {
    private static final int SIGNATURE_OFFSET = 0x01FE;
    private static final int PARTITION_DATA_OFFSET = 0x1BE;
    private static final int PARTITION_DATA_LENGTH = 16;

    private final HashSet<Partition> mPartitions;

    public MasterBootRecord(BlockDevice device) {
        mPartitions = new HashSet<>();
        ByteBuffer buffer = ByteBuffer.allocate(512);

        try {
            device.read(0, buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }

        if ((buffer.get(SIGNATURE_OFFSET) & 0xff) != 0x55 ||
                (buffer.get(SIGNATURE_OFFSET + 1) & 0xff) != 0xaa) {
            System.out.println(BitStitching.convertByteBufferToHex(buffer));
            throw new IllegalArgumentException("no mbr signature found!");
        }

        for (byte entry = 0; entry < 4; entry++) {
            byte[] data = new byte[PARTITION_DATA_LENGTH];
            int offset = PARTITION_DATA_OFFSET + entry * PARTITION_DATA_LENGTH;
            buffer.position(offset);
            buffer.get(data);

            PartitionParameters param = new PartitionParameters(data, entry);
            if (param.getDescriptor() != FileSystemDescriptor.UNUSED) {
                Partition partition = new Partition(device, param);
                mPartitions.add(partition);
            }
        }
    }

    public Iterable<Partition> getPartitions() {
        return mPartitions;
    }
}




Java Source Code List

net.alphadev.fat32wrapper.Fat32Provider.java
net.alphadev.fat32wrapper.FatBlockDeviceWrapper.java
net.alphadev.fat32wrapper.FatStorage.java
net.alphadev.fat32wrapper.ReadingFileHandle.java
net.alphadev.usbstorage.DeviceManager.java
net.alphadev.usbstorage.DocumentProviderImpl.java
net.alphadev.usbstorage.StorageManager.java
net.alphadev.usbstorage.UsbBulkDevice.java
net.alphadev.usbstorage.api.Identifiable.java
net.alphadev.usbstorage.api.device.BlockDevice.java
net.alphadev.usbstorage.api.device.BulkDevice.java
net.alphadev.usbstorage.api.device.ReadOnlyException.java
net.alphadev.usbstorage.api.filesystem.FileAttribute.java
net.alphadev.usbstorage.api.filesystem.FileHandle.java
net.alphadev.usbstorage.api.filesystem.FileSystemProvider.java
net.alphadev.usbstorage.api.filesystem.Path.java
net.alphadev.usbstorage.api.filesystem.StorageDevice.java
net.alphadev.usbstorage.api.scsi.ScsiTransferable.java
net.alphadev.usbstorage.api.scsi.Transmittable.java
net.alphadev.usbstorage.bbb.BulkBlockDevice.java
net.alphadev.usbstorage.partition.FileSystemDescriptor.java
net.alphadev.usbstorage.partition.MasterBootRecord.java
net.alphadev.usbstorage.partition.PartitionParameters.java
net.alphadev.usbstorage.partition.Partition.java
net.alphadev.usbstorage.scsi.CommandBlockWrapper.java
net.alphadev.usbstorage.scsi.CommandStatusWrapper.java
net.alphadev.usbstorage.scsi.answer.ModeSenseResponse.java
net.alphadev.usbstorage.scsi.answer.ReadCapacityResponse.java
net.alphadev.usbstorage.scsi.answer.ReadFormatCapacitiesEntry.java
net.alphadev.usbstorage.scsi.answer.ReadFormatCapacitiesHeader.java
net.alphadev.usbstorage.scsi.answer.RequestSenseResponse.java
net.alphadev.usbstorage.scsi.answer.StandardInquiryAnswer.java
net.alphadev.usbstorage.scsi.command.Inquiry.java
net.alphadev.usbstorage.scsi.command.ModeSense.java
net.alphadev.usbstorage.scsi.command.Read10.java
net.alphadev.usbstorage.scsi.command.ReadCapacity.java
net.alphadev.usbstorage.scsi.command.ReadFormatCapacities.java
net.alphadev.usbstorage.scsi.command.RequestSense.java
net.alphadev.usbstorage.scsi.command.ScsiCommand.java
net.alphadev.usbstorage.scsi.command.TestUnitReady.java
net.alphadev.usbstorage.util.BitStitching.java
net.alphadev.usbstorage.util.ParcelFileDescriptorUtil.java