// Path: src/jext2/exceptions/FileTooLarge.java
// public class FileTooLarge extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.EFBIG;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// Path: src/jext2/exceptions/IoError.java
// public class IoError extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected static final int ERRNO=Errno.EIO;
// 	public IoError(String msg) {
// 		super(msg);
// 	}
// 	public IoError() {
// 		super();
// 	}
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// Path: src/jext2/exceptions/JExt2Exception.java
// public class JExt2Exception extends Exception {
// 	protected static final int ERRNO = -1;
// 
// 	private static final long serialVersionUID = -7429088074385678308L;
// 
// 	Logger logger = Filesystem.getLogger();
// 
// 	public JExt2Exception() {
// 		log("");
// 	}
// 
// 	public JExt2Exception(String msg) {
// 		log(msg);
// 	}
// 
// 	private void log(String msg) {
// 		if (logger.isLoggable(Level.FINE)) {
// 			StackTraceElement[] stack = getStackTrace();
// 
// 			StringBuilder log = new StringBuilder();
// 			log.append("JEXT2 exception was raised: ");
// 			log.append(this.getClass().getSimpleName());
// 			log.append(" source=");
// 			log.append(stack[0].getClassName());
// 			log.append("->");
// 			log.append(stack[0].getMethodName());
// 			log.append(" msg=");
// 			log.append(msg);
// 			log.append(" errno=");
// 			log.append(getErrno());
// 
// 			logger.fine(log.toString());
// 		}
// 	}
// 
// 	public int getErrno() {
// 		throw new RuntimeException("This method should not be executed. " +
// 				"- The errno value defined here is meaningless");
// 	}
// }
// 
// Path: src/jext2/exceptions/NoSpaceLeftOnDevice.java
// public class NoSpaceLeftOnDevice extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.ENOSPC;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }


import jext2.annotations.MustReturnLock;
import jext2.annotations.NotThreadSafe;
import jext2.exceptions.FileTooLarge;
import jext2.exceptions.IoError;
import jext2.exceptions.JExt2Exception;
import jext2.exceptions.NoSpaceLeftOnDevice;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
		/* No such thing, so let's try location of indirect block */
		if (depth > 1)
			return blockNrs[depth-1];


		/* It is going to be refered from inode itself? OK just put i into
		 * the same cylinder group then
		 */
		long bgStart = BlockGroupDescriptor.firstBlock(inode.getBlockGroup());
		long colour = (Filesystem.getPID() % 16) *
				(superblock.getBlocksPerGroup() / 16);

		return bgStart + colour;

	}

	/** Allocate and set up a chain of blocks.
	 * @param  inode   owner
	 * @param  num     depth of the chain (number of blocks to allocate)
	 * @param  goal    gloal block
	 * @param  offsets offsets in the indirection chain
	 * @param  blockNrs    chain of allready allocated blocks
	 * @throws NoSpaceLeftOnDevice
	 *
	 * This function allocates num blocks, zeros out all but the last one, links
	 * them into a chain and writes them to disk.
	 */
	@NotThreadSafe(useLock=true)
	private LinkedList<Long> allocBranch(int num, long goal,
			int[] offsets, long[] blockNrs)
// Path: src/jext2/exceptions/FileTooLarge.java
// public class FileTooLarge extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.EFBIG;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// Path: src/jext2/exceptions/IoError.java
// public class IoError extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected static final int ERRNO=Errno.EIO;
// 	public IoError(String msg) {
// 		super(msg);
// 	}
// 	public IoError() {
// 		super();
// 	}
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// Path: src/jext2/exceptions/JExt2Exception.java
// public class JExt2Exception extends Exception {
// 	protected static final int ERRNO = -1;
// 
// 	private static final long serialVersionUID = -7429088074385678308L;
// 
// 	Logger logger = Filesystem.getLogger();
// 
// 	public JExt2Exception() {
// 		log("");
// 	}
// 
// 	public JExt2Exception(String msg) {
// 		log(msg);
// 	}
// 
// 	private void log(String msg) {
// 		if (logger.isLoggable(Level.FINE)) {
// 			StackTraceElement[] stack = getStackTrace();
// 
// 			StringBuilder log = new StringBuilder();
// 			log.append("JEXT2 exception was raised: ");
// 			log.append(this.getClass().getSimpleName());
// 			log.append(" source=");
// 			log.append(stack[0].getClassName());
// 			log.append("->");
// 			log.append(stack[0].getMethodName());
// 			log.append(" msg=");
// 			log.append(msg);
// 			log.append(" errno=");
// 			log.append(getErrno());
// 
// 			logger.fine(log.toString());
// 		}
// 	}
// 
// 	public int getErrno() {
// 		throw new RuntimeException("This method should not be executed. " +
// 				"- The errno value defined here is meaningless");
// 	}
// }
// 
// Path: src/jext2/exceptions/NoSpaceLeftOnDevice.java
// public class NoSpaceLeftOnDevice extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.ENOSPC;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }


// Path: src/jext2/DataBlockAccess.java
import jext2.annotations.MustReturnLock;
import jext2.annotations.NotThreadSafe;
import jext2.exceptions.FileTooLarge;
import jext2.exceptions.IoError;
import jext2.exceptions.JExt2Exception;
import jext2.exceptions.NoSpaceLeftOnDevice;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedList;
import java.util.Iterator;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

		/* No such thing, so let's try location of indirect block */
		if (depth > 1)
			return blockNrs[depth-1];


		/* It is going to be refered from inode itself? OK just put i into
		 * the same cylinder group then
		 */
		long bgStart = BlockGroupDescriptor.firstBlock(inode.getBlockGroup());
		long colour = (Filesystem.getPID() % 16) *
				(superblock.getBlocksPerGroup() / 16);

		return bgStart + colour;

	}

	/** Allocate and set up a chain of blocks.
	 * @param  inode   owner
	 * @param  num     depth of the chain (number of blocks to allocate)
	 * @param  goal    gloal block
	 * @param  offsets offsets in the indirection chain
	 * @param  blockNrs    chain of allready allocated blocks
	 * @throws NoSpaceLeftOnDevice
	 *
	 * This function allocates num blocks, zeros out all but the last one, links
	 * them into a chain and writes them to disk.
	 */
	@NotThreadSafe(useLock=true)
	private LinkedList<Long> allocBranch(int num, long goal,
			int[] offsets, long[] blockNrs)
					throws JExt2Exception, NoSpaceLeftOnDevice {