synchronized(blockCache) { byte[] bitmapBlock = getBlock(gdesc.getBlockBitmap());    synchronized( bitmapBlock ) { result=BlockBitmap.findFreeBlocks( bitmapBlock, metadataLength );    if(result.isSuccessful()) { writeBlock(groupDescriptors[group].getBlockBitmap(), bitmapBlock, true);  modifyFreeBlocksCount( group, -1-result.getPreallocCount() ); } } }  if(result.isSuccessful()) { result.setBlock( group*getSuperblock().getBlocksPerGroup() + superblock.getFirstDataBlock() + result.getBlock() ); result.setFreeBlocksCount(gdesc.getFreeBlocksCount()); }  return result; }
BlockReservation result;     synchronized (blockCache) { byte[] bitmapBlock = getBlock(gdesc.getBlockBitmap());      synchronized (bitmapBlock) { result = BlockBitmap .findFreeBlocks(bitmapBlock, metadataLength);     if (result.isSuccessful()) { writeBlock(groupDescriptors[group].getBlockBitmap(), bitmapBlock, true);  modifyFreeBlocksCount(group, -1 - result.getPreallocCount()); } } }  if (result.isSuccessful()) { result.setBlock(group * getSuperblock().getBlocksPerGroup() + superblock.getFirstDataBlock() + result.getBlock()); result.setFreeBlocksCount(gdesc.getFreeBlocksCount()); }  return result; }
	public BlockReservation findFreeBlocks(int group, long threshold) throws IOException{		GroupDescriptor gdesc = groupDescriptors[group];		//see if it's worth to check the block group at all		if( gdesc.getFreeBlocksCount() < threshold)			return new BlockReservation(false, -1, -1, gdesc.getFreeBlocksCount());				/* 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);		int  metadataLength  = (int)(firstNonMetadataBlock - 								(superblock.getFirstDataBlock() + group*superblock.getBlocksPerGroup()));		log.debug("group["+group+"].getInodeTable()="+iNodeTableBlock+", iNodeTable.getSizeInBlocks()="+INodeTable.getSizeInBlocks(this));		log.debug("metadata length for block group("+group+"): "+metadataLength); 		BlockReservation result;		//synchronize to the blockCache to avoid flushing the block between reading it		//and synchronizing to it		synchronized(blockCache) {					byte[] bitmapBlock = getBlock(gdesc.getBlockBitmap());					//at any time, only one copy of the Block exists in the cache, so it is			//safe to synchronize to the bitmapBlock object (it's part of Block)			synchronized( bitmapBlock ) {				result=BlockBitmap.findFreeBlocks( bitmapBlock, metadataLength );							//if the reservation was successful, write the bitmap data to disk				//within the same synchronized block				if(result.isSuccessful()) {					writeBlock(groupDescriptors[group].getBlockBitmap(), bitmapBlock, true);					//gdesc.setFreeBlocksCount(gdesc.getFreeBlocksCount()-1-result.getPreallocCount());					modifyFreeBlocksCount( group, -1-result.getPreallocCount() );				}			}		}					if(result.isSuccessful()) {			result.setBlock( group*getSuperblock().getBlocksPerGroup() + 							 superblock.getFirstDataBlock() + 							 result.getBlock() );			result.setFreeBlocksCount(gdesc.getFreeBlocksCount());		}				return result;	}