for(int i=-15; i<0; i++) { reservation = getExt2FileSystem().testAndSetBlock(lastBlock+i); if( reservation.isSuccessful() ) { desc.setPreallocBlock( reservation.getBlock()+1 ); desc.setPreallocCount( reservation.getPreallocCount() );  long prealloc512 = (1+reservation.getPreallocCount()) * (fs.getBlockSize()/512); setBlocks( getBlocks()+prealloc512 );  return lastBlock+i; } } }    reservation = getExt2FileSystem().findFreeBlocks( desc.getGroup(), 1 ); if( reservation.isSuccessful() ) { desc.setPreallocBlock( reservation.getBlock()+1 ); desc.setPreallocCount( reservation.getPreallocCount() );
if (desc.getPreallocCount() > 0) { return desc.usePreallocBlock(); }
	private long findFreeBlock(long index) throws IOException, FileSystemException{		//long newBlock;		long lastBlock = -1;		BlockReservation reservation;				//first, see if preallocated blocks exist		if( desc.getPreallocCount() > 0 ) {			return desc.usePreallocBlock();		}				//no preallocated blocks:		//check around the last allocated block		if(index>0)			lastBlock = getDataBlockNr(index-1);				if( lastBlock!=-1 ) {			for(int i=1; i<16; i++) {				reservation = getExt2FileSystem().testAndSetBlock(lastBlock+i);				if( reservation.isSuccessful() ) {					desc.setPreallocBlock( reservation.getBlock()+1 );					desc.setPreallocCount( reservation.getPreallocCount() );										long prealloc512 = (1+reservation.getPreallocCount()) * (fs.getBlockSize()/512);					setBlocks( getBlocks()+prealloc512 );										return lastBlock+i;				}			}			for(int i=-15; i<0; i++) {				reservation = getExt2FileSystem().testAndSetBlock(lastBlock+i);				if( reservation.isSuccessful() ) {					desc.setPreallocBlock( reservation.getBlock()+1 );					desc.setPreallocCount( reservation.getPreallocCount() );															long prealloc512 = (1+reservation.getPreallocCount()) * (fs.getBlockSize()/512);					setBlocks( getBlocks()+prealloc512 );										return lastBlock+i;				}			}		}				//then check the current block group from the beginning 		//(threshold=1 means: find is successul if at least one free block is found)		reservation = getExt2FileSystem().findFreeBlocks( desc.getGroup(), 1 );		if( reservation.isSuccessful() ) {			desc.setPreallocBlock( reservation.getBlock()+1 );			desc.setPreallocCount( reservation.getPreallocCount() );								long prealloc512 = (1+reservation.getPreallocCount()) * (fs.getBlockSize()/512);			setBlocks( getBlocks()+prealloc512 );						return reservation.getBlock();		}		//then check the other block groups, first those that have "more" free space,		//but take a note if a non-full group is found		long nonfullBlockGroup = -1;		for(int i=0; i<getExt2FileSystem().getGroupCount(); i++) {			if(i==desc.getGroup()) 				continue;							long threshold = (long)Math.ceil( 	getExt2FileSystem().getSuperblock().getBlocksPerGroup() * 												Ext2Constants.EXT2_BLOCK_THRESHOLD_RATIO );			reservation = getExt2FileSystem().findFreeBlocks( i, threshold);			if(reservation.isSuccessful()) {				desc.setPreallocBlock( reservation.getBlock()+1 );				desc.setPreallocCount( reservation.getPreallocCount() );									long prealloc512 = (1+reservation.getPreallocCount()) * (fs.getBlockSize()/512);				setBlocks( getBlocks()+prealloc512 );							return reservation.getBlock();			}						if(reservation.getFreeBlocksCount()>0)				nonfullBlockGroup = i;		}				//if no block group with at least the threshold number of free blocks is found,		//then check if there was any nonfull group		if(nonfullBlockGroup!=-1) {			reservation = getExt2FileSystem().findFreeBlocks( desc.getGroup(), 1 );			if( reservation.isSuccessful() ) {				desc.setPreallocBlock( reservation.getBlock()+1 );				desc.setPreallocCount( reservation.getPreallocCount() );												long prealloc512 = (1+reservation.getPreallocCount()) * (fs.getBlockSize()/512);				setBlocks( getBlocks()+prealloc512 );							return reservation.getBlock();			}		}							throw new IOException("No free blocks: disk full!");	}