Skip to content

Commit

Permalink
File size clean ups
Browse files Browse the repository at this point in the history
Address some issues raised in #71
  • Loading branch information
marschall committed Feb 3, 2016
1 parent f58c3a3 commit d6f915a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,15 @@ final class MemoryInode {
private static final int ARRAY_HEADER = 8 + 8 + 4;

static final int BLOCK_SIZE = 4096 - ARRAY_HEADER; //make sure it fits into a 4k memory region
static final int NUMBER_OF_BLOCKS = BLOCK_SIZE;

// lazily allocated, most files probably won't need this
private LockSet lockSet;

/**
* To store the contents efficiently we store the first {@value #BLOCK_SIZE}
* bytes in a {@value #BLOCK_SIZE} direct {@code byte[]}. The next
* {@value #BLOCK_SIZE} * {@value #BLOCK_SIZE} bytes go into a indirect
* {@value #NUMBER_OF_BLOCKS} * {@value #BLOCK_SIZE} bytes go into a indirect
* {@code byte[][]} that is lazily allocated.
*/
private byte[] directBlock;
Expand Down Expand Up @@ -350,14 +351,14 @@ private void ensureCapacity(long capacity) {

// lazily allocate indirect blocks
if (this.indirectBlocks == null) {
this.indirectBlocks = new byte[BLOCK_SIZE][];
this.indirectBlocks = new byte[NUMBER_OF_BLOCKS][];
}

int blocksRequired = (int) ((capacity - 1L)/ BLOCK_SIZE); // consider already present direct block, don't add + 1

if (blocksRequired > BLOCK_SIZE) {
if (blocksRequired > NUMBER_OF_BLOCKS) {
// FIXME implement double indirect addressing
throw new AssertionError("files bigger than 16GB not yet supported");
throw new AssertionError("files bigger than 16MB not yet supported");
}

if (blocksRequired > this.indirectBlocksAllocated) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void directBlock() {

@Test
public void indirectBlock() {
byte[][] array = new byte[MemoryInode.BLOCK_SIZE][];
byte[][] array = new byte[MemoryInode.NUMBER_OF_BLOCKS][];
assertThat(VMSupport.sizeOf(array), lessThanOrEqualTo(16384));
}

Expand Down

0 comments on commit d6f915a

Please sign in to comment.