}
synchronized (blockCache) { byte[] bitmap = getBlock(groupDescriptors[group].getBlockBitmap()); synchronized (bitmap) { BlockReservation result = BlockBitmap.testAndSetBlock(bitmap, index);  if (result.isSuccessful()) { writeBlock(groupDescriptors[group].getBlockBitmap(), bitmap, false); modifyFreeBlocksCount(group, -1 - result.getPreallocCount());   result.setBlock(blockNr); } return result; } }  }
	public BlockReservation testAndSetBlock(long blockNr) throws IOException{		if(blockNr<superblock.getFirstDataBlock() || blockNr>=superblock.getBlocksCount())			return new BlockReservation(false, -1, -1);		int group = translateToGroup(blockNr);		int index = translateToIndex(blockNr);		/* Return false if the block is not a data block but a filesystem		 * metadata block, as the beginning of each block group is filesystem		 * metadata:		 * superblock copy (if present)		 * block bitmap		 * inode bitmap		 * inode table		 * Free blocks begin after the inode table.		 */		long iNodeTableBlock = 	groupDescriptors[group].getInodeTable();		long firstNonMetadataBlock = iNodeTableBlock + INodeTable.getSizeInBlocks(this);		 		if(blockNr<firstNonMetadataBlock)			return new BlockReservation(false, -1, -1);		//synchronize to the blockCache to avoid flushing the block between reading it		//and synchronizing to it		synchronized(blockCache) {			byte[] bitmap= getBlock(groupDescriptors[group].getBlockBitmap()); 			synchronized( bitmap) {				BlockReservation result = BlockBitmap.testAndSetBlock( bitmap, index );				//update the block bitmap				if(result.isSuccessful()) {					writeBlock(groupDescriptors[group].getBlockBitmap(), bitmap, false);					modifyFreeBlocksCount(group, -1-result.getPreallocCount());					//result.setBlock( result.getBlock()+superblock.getFirstDataBlock() );					result.setBlock(blockNr);				}				return result;			}		}	}