package com.github.magnusja.libaums.javafs.wrapper.device;

import com.github.mjdev.libaums.driver.BlockDeviceDriver;

import org.jnode.driver.block.FSBlockDeviceAPI;
import org.jnode.partitions.PartitionTable;
import org.jnode.partitions.PartitionTableEntry;

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

/**
 * Created by magnusja on 2/28/17.
 */

public class FSBlockDeviceWrapper implements FSBlockDeviceAPI {

    private BlockDeviceDriver blockDevice;
    private com.github.mjdev.libaums.partition.PartitionTableEntry partitionTableEntry;

    public FSBlockDeviceWrapper(BlockDeviceDriver blockDevice, com.github.mjdev.libaums.partition.PartitionTableEntry partitionTableEntry) {
        this.blockDevice = blockDevice;
        this.partitionTableEntry = partitionTableEntry;
    }

    @Override
    public int getSectorSize() throws IOException {
        return blockDevice.getBlockSize();
    }

    @Override
    public PartitionTableEntry getPartitionTableEntry() {
        return new PartitionTableEntry() {
            @Override
            public boolean isValid() {
                return true;
            }

            @Override
            public boolean hasChildPartitionTable() {
                return false;
            }

            @Override
            public PartitionTable<?> getChildPartitionTable() {
                return null;
            }
        };
    }

    @Override
    public long getLength() throws IOException {
        return partitionTableEntry.getTotalNumberOfSectors() * blockDevice.getBlockSize();
    }

    @Override
    public void read(long l, ByteBuffer byteBuffer) throws IOException {
        blockDevice.read(l, byteBuffer);
    }

    @Override
    public void write(long l, ByteBuffer byteBuffer) throws IOException {
        blockDevice.write(l, byteBuffer);
    }

    @Override
    public void flush() throws IOException {

    }
}

@@ -53,16 +53,42 @@
 evice;%0A%0A
+import android.util.Log;%0A%0A
 import c
@@ -442,24 +442,106 @@
 eviceAPI %7B%0A%0A
+    private static final String TAG = FSBlockDeviceWrapper.class.getSimpleName();%0A
     private 
@@ -1748,32 +1748,112 @@
 s IOException %7B%0A
+        Log.d(TAG, %22reading at %22 + l + %22 with size %22 + byteBuffer.remaining());%0A
         blockDev

Add some log