// Path: src/jext2/exceptions/DirectoryNotEmpty.java
// public class DirectoryNotEmpty extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.ENOTEMPTY;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// Path: src/jext2/exceptions/FileExists.java
// public class FileExists extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.EEXIST;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// Path: src/jext2/exceptions/FileNameTooLong.java
// public class FileNameTooLong extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.ENAMETOOLONG;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// 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/exceptions/NoSuchFileOrDirectory.java
// public class NoSuchFileOrDirectory extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected static final int ERRNO = Errno.ENOENT;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// Path: src/jext2/exceptions/TooManyLinks.java
// public class TooManyLinks extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.EMLINK;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }


import jext2.exceptions.FileTooLarge;
import jext2.exceptions.IoError;
import jext2.exceptions.JExt2Exception;
import jext2.exceptions.NoSpaceLeftOnDevice;
import jext2.exceptions.NoSuchFileOrDirectory;
import jext2.exceptions.TooManyLinks;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;
import jext2.annotations.NotThreadSafe;
import jext2.exceptions.DirectoryNotEmpty;
import jext2.exceptions.FileExists;
import jext2.exceptions.FileNameTooLong;

		return sb.toString();
	}

	protected DirectoryInode(long blockNr, int offset) {
		super(blockNr, offset);
	}

	public static DirectoryInode fromByteBuffer(ByteBuffer buf, int offset) throws IoError {
		DirectoryInode inode = new DirectoryInode(-1, offset);
		inode.read(buf);
		return inode;
	}

	public void addDotLinks(DirectoryInode parent)
			throws JExt2Exception, FileExists, NoSpaceLeftOnDevice, TooManyLinks, FileTooLarge {
		try {
			addLink(this, ".");
			addLink(parent, "..");
		} catch (FileNameTooLong e) {
			throw new RuntimeException("should not happen");
		}
	}

	/**
	 * Remove "." and ".." entry from the directory. Should be called before
	 * a unlink on a directory.
	 * @throws NoSuchFileOrDirectory
	 * @praram parent parent inode. Used to resolve the ".." link
	 */
// Path: src/jext2/exceptions/DirectoryNotEmpty.java
// public class DirectoryNotEmpty extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.ENOTEMPTY;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// Path: src/jext2/exceptions/FileExists.java
// public class FileExists extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.EEXIST;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// Path: src/jext2/exceptions/FileNameTooLong.java
// public class FileNameTooLong extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.ENAMETOOLONG;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// 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/exceptions/NoSuchFileOrDirectory.java
// public class NoSuchFileOrDirectory extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected static final int ERRNO = Errno.ENOENT;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }
// 
// Path: src/jext2/exceptions/TooManyLinks.java
// public class TooManyLinks extends JExt2Exception {
// 	static final long serialVersionUID = 42;
// 	protected final static int ERRNO = Errno.EMLINK;
// 
// 	public int getErrno() {
// 		return ERRNO;
// 	}
// }


// Path: src/jext2/DirectoryInode.java
import jext2.exceptions.FileTooLarge;
import jext2.exceptions.IoError;
import jext2.exceptions.JExt2Exception;
import jext2.exceptions.NoSpaceLeftOnDevice;
import jext2.exceptions.NoSuchFileOrDirectory;
import jext2.exceptions.TooManyLinks;
import java.nio.ByteBuffer;
import java.util.Date;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.logging.Logger;
import jext2.annotations.NotThreadSafe;
import jext2.exceptions.DirectoryNotEmpty;
import jext2.exceptions.FileExists;
import jext2.exceptions.FileNameTooLong;


		return sb.toString();
	}

	protected DirectoryInode(long blockNr, int offset) {
		super(blockNr, offset);
	}

	public static DirectoryInode fromByteBuffer(ByteBuffer buf, int offset) throws IoError {
		DirectoryInode inode = new DirectoryInode(-1, offset);
		inode.read(buf);
		return inode;
	}

	public void addDotLinks(DirectoryInode parent)
			throws JExt2Exception, FileExists, NoSpaceLeftOnDevice, TooManyLinks, FileTooLarge {
		try {
			addLink(this, ".");
			addLink(parent, "..");
		} catch (FileNameTooLong e) {
			throw new RuntimeException("should not happen");
		}
	}

	/**
	 * Remove "." and ".." entry from the directory. Should be called before
	 * a unlink on a directory.
	 * @throws NoSuchFileOrDirectory
	 * @praram parent parent inode. Used to resolve the ".." link
	 */
	public void removeDotLinks(DirectoryInode parent) throws IoError, NoSuchFileOrDirectory {