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

import com.github.mjdev.libaums.fs.FileSystem;
import com.github.mjdev.libaums.fs.UsbFile;

import org.jnode.driver.ApiNotFoundException;
import org.jnode.driver.block.FSBlockDeviceAPI;

import java.io.IOException;

/**
 * Created by magnusja on 3/1/17.
 */

public class FileSystemWrapper implements FileSystem {

    private org.jnode.fs.FileSystem wrappedFs;

    public FileSystemWrapper(org.jnode.fs.FileSystem wrappedFs) {
        this.wrappedFs = wrappedFs;
    }

    @Override
    public UsbFile getRootDirectory() {
        return null;
    }

    @Override
    public String getVolumeLabel() {
        try {
            return wrappedFs.getVolumeName();
        } catch (IOException e) {
            return "";
        }
    }

    @Override
    public long getCapacity() {
        try {
            return wrappedFs.getTotalSpace();
        } catch (IOException e) {
            return 0;
        }
    }

    @Override
    public long getOccupiedSpace() {
        try {
            return wrappedFs.getTotalSpace() - wrappedFs.getFreeSpace();
        } catch (IOException e) {
            return 0;
        }
    }

    @Override
    public long getFreeSpace() {
        try {
            return wrappedFs.getFreeSpace();
        } catch (IOException e) {
            return 0;
        }
    }

    @Override
    public int getChunkSize() {
        try {
            return wrappedFs.getDevice().getAPI(FSBlockDeviceAPI.class).getSectorSize();
        } catch (IOException e) {
            return 4096;
        } catch (ApiNotFoundException e) {
            return 4096;
        }
    }
}

@@ -46,16 +46,42 @@
 apper;%0A%0A
+import android.util.Log;%0A%0A
 import c
@@ -387,16 +387,96 @@
 stem %7B%0A%0A
+    private static final String TAG = FileSystemWrapper.class.getSimpleName();%0A%0A
     priv
@@ -843,32 +843,89 @@
 OException e) %7B%0A
+            Log.e(TAG, %22error getting volume label%22, e);%0A
             retu
@@ -1080,32 +1080,85 @@
 OException e) %7B%0A
+            Log.e(TAG, %22error getting capacity%22, e);%0A
             retu
@@ -1344,32 +1344,95 @@
 OException e) %7B%0A
+            Log.e(TAG, %22error getting total - free space%22, e);%0A
             retu
@@ -1586,32 +1586,87 @@
 OException e) %7B%0A
+            Log.e(TAG, %22error getting free space%22, e);%0A
             retu
@@ -1740,32 +1740,66 @@
 %7B%0A        try %7B%0A
+            // TODO this is wrong%0A
             retu
@@ -1921,63 +1921,188 @@
     
-return 4096;%0A        %7D catch (ApiNotFoundException e) %7B
+Log.e(TAG, %22error getting sector size%22, e);%0A            return 4096;%0A        %7D catch (ApiNotFoundException e) %7B%0A            Log.e(TAG, %22api not found (this should not happen)%22, e);
 %0A   

add some logging