@Override public ByteBuffer getBlock(int index) { int dataBlock = getOrUpdateDataBlockIndex(index, EMPTY_ADDRESS, Mode.GET); return blockByteBufferCopy.getByteBuffer(dataBlock); }
@Override public ByteBuffer allocateBlock(int blockNum) { int dataBlock = getOrUpdateDataBlockIndex(blockNum, EMPTY_ADDRESS, Mode.ALLOCATE); return blockByteBufferCopy.getByteBuffer(dataBlock); } }
@Override public ByteBuffer getBlock(int index) { int dataBlock = getOrUpdateDataBlockIndex(index, EMPTY_ADDRESS, Mode.GET); return blockByteBufferCopy.getByteBuffer(dataBlock); }
@Override public ByteBuffer allocateBlock(int blockNum) { int dataBlock = getOrUpdateDataBlockIndex(blockNum, EMPTY_ADDRESS, Mode.ALLOCATE); return blockByteBufferCopy.getByteBuffer(dataBlock); } }
@Override public ByteBuffer allocateBlock(int blockNum) { int dataBlock = getOrUpdateDataBlockIndex(blockNum, EMPTY_ADDRESS, Mode.ALLOCATE); return blockByteBufferCopy.getByteBuffer(dataBlock); } }
@Override public ByteBuffer getBlock(int index) { int dataBlock = getOrUpdateDataBlockIndex(index, EMPTY_ADDRESS, Mode.GET); return blockByteBufferCopy.getByteBuffer(dataBlock); }
private ByteBuffer updateIndirectBlockInfo(ByteBuffer buf, int index, int position, int cutOff, int value, Mode mode) { int sib_index = buf.getInt(position); if (index == cutOff) { if (mode == Mode.ALLOCATE) { sib_index = nextBlock(buf, false); buf.putInt(position, sib_index); } else if (mode == Mode.UPDATE && value == EMPTY_ADDRESS) { freeDataBlock(sib_index); return null; } } return blockByteBufferCopy.getByteBuffer(sib_index); }
private boolean freeIndirectBlock(int indirectIndexBlock) { ByteBuffer bb = blockByteBufferCopy.getByteBuffer(indirectIndexBlock); boolean freedAll = freeBlock(bb.position(), bb, ADDRESSES_PER_BLOCK, true); freeDataBlock(indirectIndexBlock); return freedAll; }
private ByteBuffer updateIndirectBlockInfo(ByteBuffer buf, int index, int position, int cutOff, int value, Mode mode) { int sib_index = buf.getInt(position); if (index == cutOff) { if (mode == Mode.ALLOCATE) { sib_index = nextBlock(buf, false); buf.putInt(position, sib_index); } else if (mode == Mode.UPDATE && value == EMPTY_ADDRESS) { freeDataBlock(sib_index); return null; } } return blockByteBufferCopy.getByteBuffer(sib_index); }
private boolean freeIndirectBlock(int indirectIndexBlock) { ByteBuffer bb = blockByteBufferCopy.getByteBuffer(indirectIndexBlock); boolean freedAll = freeBlock(bb.position(), bb, ADDRESSES_PER_BLOCK, true); freeDataBlock(indirectIndexBlock); return freedAll; }
private boolean freeIndirectBlock(int indirectIndexBlock) { ByteBuffer bb = blockByteBufferCopy.getByteBuffer(indirectIndexBlock); boolean freedAll = freeBlock(bb.position(), bb, ADDRESSES_PER_BLOCK, true); freeDataBlock(indirectIndexBlock); return freedAll; }
private ByteBuffer updateIndirectBlockInfo(ByteBuffer buf, int index, int position, int cutOff, int value, Mode mode) { int sib_index = buf.getInt(position); if (index == cutOff) { if (mode == Mode.ALLOCATE) { sib_index = nextBlock(buf, false); buf.putInt(position, sib_index); } else if (mode == Mode.UPDATE && value == EMPTY_ADDRESS) { freeDataBlock(sib_index); return null; } } return blockByteBufferCopy.getByteBuffer(sib_index); }
private ByteBuffer getInodeBlock() { if (inodeBuffer == null) { if (inode == EMPTY_ADDRESS) { this.inode = inodesInuse.getAndSetNextClearBit(); if (this.inode == -1) { throw new AssertionError("Out of inodes"); //$NON-NLS-1$ } if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Allocating inode", this.inode, "to", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$ } ByteBuffer bb = getInodeBlock(); bb.putInt(EMPTY_ADDRESS); } inodeBuffer = inodeByteBufferCopy.getByteBuffer(inode).slice(); } return inodeBuffer; }
private ByteBuffer getInodeBlock() { if (inodeBuffer == null) { if (inode == EMPTY_ADDRESS) { this.inode = inodesInuse.getAndSetNextClearBit(); if (this.inode == EMPTY_ADDRESS) { throw new AssertionError("Out of inodes"); //$NON-NLS-1$ } if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Allocating inode", this.inode, "to", gid, oid, "; total inodes", getInodesInUse()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } ByteBuffer bb = getInodeBlock(); bb.putInt(EMPTY_ADDRESS); } inodeBuffer = inodeByteBufferCopy.getByteBuffer(inode).slice(); } return inodeBuffer; }
private ByteBuffer getInodeBlock() { if (inodeBuffer == null) { if (inode == EMPTY_ADDRESS) { this.inode = inodesInuse.getAndSetNextClearBit(); if (this.inode == EMPTY_ADDRESS) { throw new AssertionError("Out of inodes"); //$NON-NLS-1$ } if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "Allocating inode", this.inode, "to", gid, oid, "; total inodes", getInodesInUse()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } ByteBuffer bb = getInodeBlock(); bb.putInt(EMPTY_ADDRESS); } inodeBuffer = inodeByteBufferCopy.getByteBuffer(inode).slice(); } return inodeBuffer; }
@Override public int free(boolean acquire) { if (this.inode == EMPTY_ADDRESS) { return EMPTY_ADDRESS; } ByteBuffer bb = getInodeBlock(); int dataBlockToAcquire = bb.getInt(0); int indirectIndexBlock = bb.getInt(BYTES_PER_BLOCK_ADDRESS*DIRECT_POINTERS); int doublyIndirectIndexBlock = bb.getInt(BYTES_PER_BLOCK_ADDRESS*(DIRECT_POINTERS+1)); boolean freedAll = freeBlock(acquire?BYTES_PER_BLOCK_ADDRESS:0, bb, DIRECT_POINTERS-(acquire?1:0), true); if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "freeing inode", inode, "for", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$ } inodesInuse.clear(inode); if (!freedAll || indirectIndexBlock == EMPTY_ADDRESS) { return acquire?dataBlockToAcquire:FREED; } freedAll = freeIndirectBlock(indirectIndexBlock); if (!freedAll || doublyIndirectIndexBlock == EMPTY_ADDRESS) { return acquire?dataBlockToAcquire:FREED; } bb = blockByteBufferCopy.getByteBuffer(doublyIndirectIndexBlock).slice(); freeBlock(0, bb, ADDRESSES_PER_BLOCK, false); freeDataBlock(doublyIndirectIndexBlock); return acquire?dataBlockToAcquire:FREED; }
@Override public int free(boolean acquire) { if (this.inode == EMPTY_ADDRESS) { return EMPTY_ADDRESS; } ByteBuffer bb = getInodeBlock(); int dataBlockToAcquire = bb.getInt(0); int indirectIndexBlock = bb.getInt(BYTES_PER_BLOCK_ADDRESS*DIRECT_POINTERS); int doublyIndirectIndexBlock = bb.getInt(BYTES_PER_BLOCK_ADDRESS*(DIRECT_POINTERS+1)); boolean freedAll = freeBlock(acquire?BYTES_PER_BLOCK_ADDRESS:0, bb, DIRECT_POINTERS-(acquire?1:0), true); if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "freeing inode", inode, "for", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$ } inodesInuse.clear(inode); if (!freedAll || indirectIndexBlock == EMPTY_ADDRESS) { return acquire?dataBlockToAcquire:FREED; } freedAll = freeIndirectBlock(indirectIndexBlock); if (!freedAll || doublyIndirectIndexBlock == EMPTY_ADDRESS) { return acquire?dataBlockToAcquire:FREED; } bb = blockByteBufferCopy.getByteBuffer(doublyIndirectIndexBlock).slice(); freeBlock(0, bb, ADDRESSES_PER_BLOCK, false); freeDataBlock(doublyIndirectIndexBlock); return acquire?dataBlockToAcquire:FREED; }
@Override public int free(boolean acquire) { if (this.inode == EMPTY_ADDRESS) { return EMPTY_ADDRESS; } ByteBuffer bb = getInodeBlock(); int dataBlockToAcquire = bb.getInt(0); int indirectIndexBlock = bb.getInt(BYTES_PER_BLOCK_ADDRESS*DIRECT_POINTERS); int doublyIndirectIndexBlock = bb.getInt(BYTES_PER_BLOCK_ADDRESS*(DIRECT_POINTERS+1)); boolean freedAll = freeBlock(acquire?BYTES_PER_BLOCK_ADDRESS:0, bb, DIRECT_POINTERS-(acquire?1:0), true); if (LogManager.isMessageToBeRecorded(LogConstants.CTX_BUFFER_MGR, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_BUFFER_MGR, "freeing inode", inode, "for", gid, oid); //$NON-NLS-1$ //$NON-NLS-2$ } inodesInuse.clear(inode); if (!freedAll || indirectIndexBlock == EMPTY_ADDRESS) { return acquire?dataBlockToAcquire:FREED; } freedAll = freeIndirectBlock(indirectIndexBlock); if (!freedAll || doublyIndirectIndexBlock == EMPTY_ADDRESS) { return acquire?dataBlockToAcquire:FREED; } bb = blockByteBufferCopy.getByteBuffer(doublyIndirectIndexBlock).slice(); freeBlock(0, bb, ADDRESSES_PER_BLOCK, false); freeDataBlock(doublyIndirectIndexBlock); return acquire?dataBlockToAcquire:FREED; }
@Test public void testBufferSizing() { BlockByteBuffer bbb = new BlockByteBuffer(4, 100, 4, false); bbb.getByteBuffer(1); }