|
From: <ga...@us...> - 2012-08-10 07:28:43
|
Revision: 5926
http://jnode.svn.sourceforge.net/jnode/?rev=5926&view=rev
Author: galatnm
Date: 2012-08-10 07:28:37 +0000 (Fri, 10 Aug 2012)
Log Message:
-----------
Ext4 code review changes
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Constants.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java
trunk/fs/src/fs/org/jnode/fs/ext2/INode.java
Added Paths:
-----------
trunk/fs/src/fs/org/jnode/fs/ext4/
trunk/fs/src/fs/org/jnode/fs/ext4/Extent.java
trunk/fs/src/fs/org/jnode/fs/ext4/ExtentHeader.java
trunk/fs/src/fs/org/jnode/fs/ext4/ExtentIndex.java
Removed Paths:
-------------
trunk/fs/src/fs/org/jnode/fs/ext2/Extent.java
trunk/fs/src/fs/org/jnode/fs/ext2/ExtentHeader.java
trunk/fs/src/fs/org/jnode/fs/ext2/ExtentIndex.java
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Constants.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Constants.java 2012-08-10 07:26:22 UTC (rev 5925)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2Constants.java 2012-08-10 07:28:37 UTC (rev 5926)
@@ -94,10 +94,10 @@
public static final long EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER = 0x0001;
public static final long EXT2_FEATURE_RO_COMPAT_LARGE_FILE = 0x0002;
public static final long EXT2_FEATURE_RO_COMPAT_BTREE_DIR = 0x0004;
- public static final long EXT4_FEATURE_ROCOMPAT_HUGE_FILE = 0x0008;
- public static final long EXT4_FEATURE_ROCOMPAT_GDT_CSUM = 0x0010;
- public static final long EXT4_FEATURE_ROCOMPAT_DIR_NLINK = 0x0020;
- public static final long EXT4_FEATURE_ROCOMPAT_EXTRA_ISIZE = 0x0040;
+ public static final long EXT4_FEATURE_RO_COMPAT_HUGE_FILE = 0x0008;
+ public static final long EXT4_FEATURE_RO_COMPAT_GDT_CSUM = 0x0010;
+ public static final long EXT4_FEATURE_RO_COMPAT_DIR_NLINK = 0x0020;
+ public static final long EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE = 0x0040;
// S_FEATURE_INCOMPAT constants
public static final long EXT2_FEATURE_INCOMPAT_COMPRESSION = 0x0001;
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java 2012-08-10 07:26:22 UTC (rev 5925)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java 2012-08-10 07:28:37 UTC (rev 5926)
@@ -151,19 +151,19 @@
log.info(getDevice().getId() + " Unsupported filesystem feature (BTREE_DIR) forces readonly mode");
setReadOnly(true);
}
- if (hasROFeature(Ext2Constants.EXT4_FEATURE_ROCOMPAT_HUGE_FILE)) {
+ if (hasROFeature(Ext2Constants.EXT4_FEATURE_RO_COMPAT_HUGE_FILE)) {
log.info(getDevice().getId() + " Unsupported filesystem feature (HUGE_FILE) forces readonly mode");
setReadOnly(true);
}
- if (hasROFeature(Ext2Constants.EXT4_FEATURE_ROCOMPAT_GDT_CSUM)) {
+ if (hasROFeature(Ext2Constants.EXT4_FEATURE_RO_COMPAT_GDT_CSUM)) {
log.info(getDevice().getId() + " Unsupported filesystem feature (GDT_CSUM) forces readonly mode");
setReadOnly(true);
}
- if (hasROFeature(Ext2Constants.EXT4_FEATURE_ROCOMPAT_DIR_NLINK)) {
+ if (hasROFeature(Ext2Constants.EXT4_FEATURE_RO_COMPAT_DIR_NLINK)) {
log.info(getDevice().getId() + " Unsupported filesystem feature (DIR_NLINK) forces readonly mode");
setReadOnly(true);
}
- if (hasROFeature(Ext2Constants.EXT4_FEATURE_ROCOMPAT_EXTRA_ISIZE)) {
+ if (hasROFeature(Ext2Constants.EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE)) {
log.info(getDevice().getId() + " Unsupported filesystem feature (EXTRA_ISIZE) forces readonly mode");
setReadOnly(true);
}
@@ -348,7 +348,7 @@
*
* @return data block nr
*/
- protected byte[] getBlock(long nr) throws IOException {
+ public byte[] getBlock(long nr) throws IOException {
if (isClosed())
throw new IOException("FS closed (fs instance: " + this + ")");
// log.debug("blockCache size: "+blockCache.size());
Deleted: trunk/fs/src/fs/org/jnode/fs/ext2/Extent.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Extent.java 2012-08-10 07:26:22 UTC (rev 5925)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Extent.java 2012-08-10 07:28:37 UTC (rev 5926)
@@ -1,55 +0,0 @@
-package org.jnode.fs.ext2;
-
-/**
- * An ext4 extent object.
- *
- * @author Luke Quinane
- */
-public class Extent {
- /**
- * The length of an extent.
- */
- public static final int EXTENT_LENGTH = 12;
-
- /**
- * The data for the extent.
- */
- private byte[] data;
-
- /**
- * Create an extent object.
- *
- * @param data the data for the extent.
- */
- public Extent(byte[] data) {
- this.data = new byte[EXTENT_LENGTH];
- System.arraycopy(data, 0, this.data, 0, EXTENT_LENGTH);
-
- // Safety check
- if (getStartHigh() != 0) {
- throw new UnsupportedOperationException("Extents that use the high bits aren't supported yet");
- }
- }
-
- public long getBlockIndex() {
- return Ext2Utils.get32(data, 0);
- }
-
- public int getBlockCount() {
- return Ext2Utils.get16(data, 4);
- }
-
- public long getStartLow() {
- return Ext2Utils.get32(data, 8);
- }
-
- public int getStartHigh() {
- return Ext2Utils.get16(data, 6);
- }
-
- @Override
- public String toString() {
- return String.format("Extent: blockindex:%d count:%d start(low:%d high:%d)", getBlockIndex(), getBlockCount(),
- getStartLow(), getStartHigh());
- }
-}
Deleted: trunk/fs/src/fs/org/jnode/fs/ext2/ExtentHeader.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/ExtentHeader.java 2012-08-10 07:26:22 UTC (rev 5925)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/ExtentHeader.java 2012-08-10 07:28:37 UTC (rev 5926)
@@ -1,180 +0,0 @@
-package org.jnode.fs.ext2;
-
-import java.io.IOException;
-
-/**
- * An ext4 extent header.
- *
- * @author Luke Quinane
- */
-public class ExtentHeader {
- /**
- * The length of an extent header.
- */
- public static final int EXTENT_HEADER_LENGTH = 12;
-
- /**
- * The magic number for an extent header.
- */
- public static final int MAGIC = 0xf30a;
-
- /**
- * The data for the header.
- */
- private byte[] data;
-
- /**
- * The cache copy of the index entries.
- */
- private ExtentIndex[] indexEntries;
-
- /**
- * The cache copy of the extent entries.
- */
- private Extent[] extentEntries;
-
- /**
- * Create an extent header object.
- */
- public ExtentHeader(byte[] data) throws IOException {
- this.data = new byte[data.length];
- System.arraycopy(data, 0, this.data, 0, data.length);
-
- if (getMagic() != ExtentHeader.MAGIC) {
- throw new IOException("Extent had the wrong magic: " + getMagic());
- }
- }
-
- public int getMagic() {
- return Ext2Utils.get16(data, 0);
- }
-
- public int getEntryCount() {
- return Ext2Utils.get16(data, 2);
- }
-
- public int getMaximumEntryCount() {
- return Ext2Utils.get16(data, 4);
- }
-
- public int getDepth() {
- return Ext2Utils.get16(data, 6);
- }
-
- public ExtentIndex[] getIndexEntries() {
- if (getDepth() == 0) {
- throw new IllegalStateException("Trying to read index entries from a leaf.");
- }
-
- if (indexEntries == null) {
- indexEntries = new ExtentIndex[getEntryCount()];
- int offset = EXTENT_HEADER_LENGTH;
-
- for (int i = 0; i < getEntryCount(); i++) {
- byte[] indexBuffer = new byte[ExtentIndex.EXTENT_INDEX_LENGTH];
- System.arraycopy(data, offset, indexBuffer, 0, indexBuffer.length);
-
- indexEntries[i] = new ExtentIndex(indexBuffer);
- offset += ExtentIndex.EXTENT_INDEX_LENGTH;
- }
- }
-
- return indexEntries;
- }
-
- public Extent[] getExtentEntries() {
- if (getDepth() != 0) {
- throw new IllegalStateException("Trying to read extent entries from a non-leaf.");
- }
-
- if (extentEntries == null) {
- extentEntries = new Extent[getEntryCount()];
- int offset = EXTENT_HEADER_LENGTH;
-
- for (int i = 0; i < getEntryCount(); i++) {
- byte[] indexBuffer = new byte[Extent.EXTENT_LENGTH];
- System.arraycopy(data, offset, indexBuffer, 0, indexBuffer.length);
-
- extentEntries[i] = new Extent(indexBuffer);
- offset += Extent.EXTENT_LENGTH;
- }
- }
-
- return extentEntries;
- }
-
- public long getBlockNumber(Ext2FileSystem fs, long index) throws IOException {
- if (getDepth() > 0) {
- ExtentIndex extentIndex = binarySearchIndexes(index, getIndexEntries());
- byte[] indexData = fs.getBlock(extentIndex.getLeafLow());
-
- ExtentHeader indexHeader = new ExtentHeader(indexData);
- return indexHeader.getBlockNumber(fs, index);
- }
- else {
- Extent extent = binarySearchExtents(index, getExtentEntries());
- return index - extent.getBlockIndex() + extent.getStartLow();
- }
- }
-
- /**
- * Performs a binary search in the extent indexes.
- *
- * @param index the index of the block to match.
- * @param indexes the indexes to search in.
- * @return the matching index.
- */
- private ExtentIndex binarySearchIndexes(long index, ExtentIndex[] indexes)
- {
- int lowIndex = 0;
- int highIndex = indexes.length - 1;
- ExtentIndex extentIndex = null;
-
- while (lowIndex <= highIndex) {
- int middle = lowIndex + (highIndex - lowIndex) / 2;
- extentIndex = indexes[middle];
-
- if (index < extentIndex.getBlockIndex()) {
- highIndex = middle - 1;
- }
- else {
- lowIndex = middle + 1;
- }
- }
-
- return indexes[Math.max(0, lowIndex - 1)];
- }
-
- /**
- * Performs a binary search in the extents.
- *
- * @param index the index of the block to match.
- * @param extents the extents to search in.
- * @return the matching extent.
- */
- private Extent binarySearchExtents(long index, Extent[] extents)
- {
- int lowIndex = 0;
- int highIndex = extents.length - 1;
- Extent extent = null;
-
- while (lowIndex <= highIndex) {
- int middle = lowIndex + (highIndex - lowIndex) / 2;
- extent = extents[middle];
-
- if (index < extent.getBlockIndex()) {
- highIndex = middle - 1;
- }
- else {
- lowIndex = middle + 1;
- }
- }
-
- return extents[Math.max(0, lowIndex - 1)];
- }
-
- @Override
- public String toString() {
- return String.format("ExtentHeader: depth:%d entries:%d/%d", getDepth(), getEntryCount(), getMaximumEntryCount());
- }
-}
Deleted: trunk/fs/src/fs/org/jnode/fs/ext2/ExtentIndex.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/ExtentIndex.java 2012-08-10 07:26:22 UTC (rev 5925)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/ExtentIndex.java 2012-08-10 07:28:37 UTC (rev 5926)
@@ -1,51 +0,0 @@
-package org.jnode.fs.ext2;
-
-/**
- * An ext4 extent index.
- *
- * @author Luke Quinane
- */
-public class ExtentIndex {
- /**
- * The length of an extent index.
- */
- public static final int EXTENT_INDEX_LENGTH = 12;
-
- /**
- * The data for the index.
- */
- private byte[] data;
-
- /**
- * Create an extent index object.
- *
- * @param data the data for the index.
- */
- public ExtentIndex(byte[] data) {
- this.data = new byte[EXTENT_INDEX_LENGTH];
- System.arraycopy(data, 0, this.data, 0, EXTENT_INDEX_LENGTH);
-
- // Safety check
- if (getLeafHigh() != 0) {
- throw new UnsupportedOperationException("Extent indexes that use the high bits aren't supported yet");
- }
- }
-
- public long getBlockIndex() {
- return Ext2Utils.get32(data, 0);
- }
-
- public long getLeafLow() {
- return Ext2Utils.get32(data, 4);
- }
-
- public int getLeafHigh() {
- return Ext2Utils.get16(data, 8);
- }
-
- @Override
- public String toString() {
- return String.format("ExtentIndex: blockindex:%d leaf(low:%d high:%d)", getBlockIndex(), getLeafLow(),
- getLeafHigh());
- }
-}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/INode.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/INode.java 2012-08-10 07:26:22 UTC (rev 5925)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/INode.java 2012-08-10 07:28:37 UTC (rev 5926)
@@ -26,6 +26,7 @@
import org.apache.log4j.Logger;
import org.jnode.fs.FileSystemException;
import org.jnode.fs.ext2.exception.UnallocatedBlockException;
+import org.jnode.fs.ext4.ExtentHeader;
/**
* This class represents an inode. Once they are allocated, inodes are read and
Added: trunk/fs/src/fs/org/jnode/fs/ext4/Extent.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext4/Extent.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/ext4/Extent.java 2012-08-10 07:28:37 UTC (rev 5926)
@@ -0,0 +1,57 @@
+package org.jnode.fs.ext4;
+
+import org.jnode.fs.ext2.Ext2Utils;
+
+/**
+ * An ext4 extent object.
+ *
+ * @author Luke Quinane
+ */
+public class Extent {
+ /**
+ * The length of an extent.
+ */
+ public static final int EXTENT_LENGTH = 12;
+
+ /**
+ * The data for the extent.
+ */
+ private byte[] data;
+
+ /**
+ * Create an extent object.
+ *
+ * @param data the data for the extent.
+ */
+ public Extent(byte[] data) {
+ this.data = new byte[EXTENT_LENGTH];
+ System.arraycopy(data, 0, this.data, 0, EXTENT_LENGTH);
+
+ // Safety check
+ if (getStartHigh() != 0) {
+ throw new UnsupportedOperationException("Extents that use the high bits aren't supported yet");
+ }
+ }
+
+ public long getBlockIndex() {
+ return Ext2Utils.get32(data, 0);
+ }
+
+ public int getBlockCount() {
+ return Ext2Utils.get16(data, 4);
+ }
+
+ public long getStartLow() {
+ return Ext2Utils.get32(data, 8);
+ }
+
+ public int getStartHigh() {
+ return Ext2Utils.get16(data, 6);
+ }
+
+ @Override
+ public String toString() {
+ return String.format("Extent: blockindex:%d count:%d start(low:%d high:%d)", getBlockIndex(), getBlockCount(),
+ getStartLow(), getStartHigh());
+ }
+}
Added: trunk/fs/src/fs/org/jnode/fs/ext4/ExtentHeader.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext4/ExtentHeader.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/ext4/ExtentHeader.java 2012-08-10 07:28:37 UTC (rev 5926)
@@ -0,0 +1,182 @@
+package org.jnode.fs.ext4;
+
+import java.io.IOException;
+import org.jnode.fs.ext2.Ext2FileSystem;
+import org.jnode.fs.ext2.Ext2Utils;
+
+/**
+ * An ext4 extent header.
+ *
+ * @author Luke Quinane
+ */
+public class ExtentHeader {
+ /**
+ * The length of an extent header.
+ */
+ public static final int EXTENT_HEADER_LENGTH = 12;
+
+ /**
+ * The magic number for an extent header.
+ */
+ public static final int MAGIC = 0xf30a;
+
+ /**
+ * The data for the header.
+ */
+ private final byte[] data;
+
+ /**
+ * The cache copy of the index entries.
+ */
+ private ExtentIndex[] indexEntries;
+
+ /**
+ * The cache copy of the extent entries.
+ */
+ private Extent[] extentEntries;
+
+ /**
+ * Create an extent header object.
+ */
+ public ExtentHeader(byte[] data) throws IOException {
+ this.data = new byte[data.length];
+ System.arraycopy(data, 0, this.data, 0, data.length);
+
+ if (getMagic() != ExtentHeader.MAGIC) {
+ throw new IOException("Extent had the wrong magic: " + getMagic());
+ }
+ }
+
+ public int getMagic() {
+ return Ext2Utils.get16(data, 0);
+ }
+
+ public int getEntryCount() {
+ return Ext2Utils.get16(data, 2);
+ }
+
+ public int getMaximumEntryCount() {
+ return Ext2Utils.get16(data, 4);
+ }
+
+ public int getDepth() {
+ return Ext2Utils.get16(data, 6);
+ }
+
+ public ExtentIndex[] getIndexEntries() {
+ if (getDepth() == 0) {
+ throw new IllegalStateException("Trying to read index entries from a leaf.");
+ }
+
+ if (indexEntries == null) {
+ indexEntries = new ExtentIndex[getEntryCount()];
+ int offset = EXTENT_HEADER_LENGTH;
+
+ for (int i = 0; i < getEntryCount(); i++) {
+ byte[] indexBuffer = new byte[ExtentIndex.EXTENT_INDEX_LENGTH];
+ System.arraycopy(data, offset, indexBuffer, 0, indexBuffer.length);
+
+ indexEntries[i] = new ExtentIndex(indexBuffer);
+ offset += ExtentIndex.EXTENT_INDEX_LENGTH;
+ }
+ }
+
+ return indexEntries;
+ }
+
+ public Extent[] getExtentEntries() {
+ if (getDepth() != 0) {
+ throw new IllegalStateException("Trying to read extent entries from a non-leaf.");
+ }
+
+ if (extentEntries == null) {
+ extentEntries = new Extent[getEntryCount()];
+ int offset = EXTENT_HEADER_LENGTH;
+
+ for (int i = 0; i < getEntryCount(); i++) {
+ byte[] indexBuffer = new byte[Extent.EXTENT_LENGTH];
+ System.arraycopy(data, offset, indexBuffer, 0, indexBuffer.length);
+
+ extentEntries[i] = new Extent(indexBuffer);
+ offset += Extent.EXTENT_LENGTH;
+ }
+ }
+
+ return extentEntries;
+ }
+
+ public long getBlockNumber(Ext2FileSystem fs, long index) throws IOException {
+ if (getDepth() > 0) {
+ ExtentIndex extentIndex = binarySearchIndexes(index, getIndexEntries());
+ byte[] indexData = fs.getBlock(extentIndex.getLeafLow());
+
+ ExtentHeader indexHeader = new ExtentHeader(indexData);
+ return indexHeader.getBlockNumber(fs, index);
+ }
+ else {
+ Extent extent = binarySearchExtents(index, getExtentEntries());
+ return index - extent.getBlockIndex() + extent.getStartLow();
+ }
+ }
+
+ /**
+ * Performs a binary search in the extent indexes.
+ *
+ * @param index the index of the block to match.
+ * @param indexes the indexes to search in.
+ * @return the matching index.
+ */
+ private ExtentIndex binarySearchIndexes(long index, ExtentIndex[] indexes)
+ {
+ int lowIndex = 0;
+ int highIndex = indexes.length - 1;
+ ExtentIndex extentIndex = null;
+
+ while (lowIndex <= highIndex) {
+ int middle = lowIndex + (highIndex - lowIndex) / 2;
+ extentIndex = indexes[middle];
+
+ if (index < extentIndex.getBlockIndex()) {
+ highIndex = middle - 1;
+ }
+ else {
+ lowIndex = middle + 1;
+ }
+ }
+
+ return indexes[Math.max(0, lowIndex - 1)];
+ }
+
+ /**
+ * Performs a binary search in the extents.
+ *
+ * @param index the index of the block to match.
+ * @param extents the extents to search in.
+ * @return the matching extent.
+ */
+ private Extent binarySearchExtents(long index, Extent[] extents)
+ {
+ int lowIndex = 0;
+ int highIndex = extents.length - 1;
+ Extent extent = null;
+
+ while (lowIndex <= highIndex) {
+ int middle = lowIndex + (highIndex - lowIndex) / 2;
+ extent = extents[middle];
+
+ if (index < extent.getBlockIndex()) {
+ highIndex = middle - 1;
+ }
+ else {
+ lowIndex = middle + 1;
+ }
+ }
+
+ return extents[Math.max(0, lowIndex - 1)];
+ }
+
+ @Override
+ public String toString() {
+ return String.format("ExtentHeader: depth:%d entries:%d/%d", getDepth(), getEntryCount(), getMaximumEntryCount());
+ }
+}
Added: trunk/fs/src/fs/org/jnode/fs/ext4/ExtentIndex.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext4/ExtentIndex.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/ext4/ExtentIndex.java 2012-08-10 07:28:37 UTC (rev 5926)
@@ -0,0 +1,53 @@
+package org.jnode.fs.ext4;
+
+import org.jnode.fs.ext2.Ext2Utils;
+
+/**
+ * An ext4 extent index.
+ *
+ * @author Luke Quinane
+ */
+public class ExtentIndex {
+ /**
+ * The length of an extent index.
+ */
+ public static final int EXTENT_INDEX_LENGTH = 12;
+
+ /**
+ * The data for the index.
+ */
+ private final byte[] data;
+
+ /**
+ * Create an extent index object.
+ *
+ * @param data the data for the index.
+ */
+ public ExtentIndex(byte[] data) {
+ this.data = new byte[EXTENT_INDEX_LENGTH];
+ System.arraycopy(data, 0, this.data, 0, EXTENT_INDEX_LENGTH);
+
+ // Safety check
+ if (getLeafHigh() != 0) {
+ throw new UnsupportedOperationException("Extent indexes that use the high bits aren't supported yet");
+ }
+ }
+
+ public long getBlockIndex() {
+ return Ext2Utils.get32(data, 0);
+ }
+
+ public long getLeafLow() {
+ return Ext2Utils.get32(data, 4);
+ }
+
+ public int getLeafHigh() {
+ return Ext2Utils.get16(data, 8);
+ }
+
+ @Override
+ public String toString() {
+ return String.format("ExtentIndex: blockindex:%d leaf(low:%d high:%d)", getBlockIndex(), getLeafLow(),
+ getLeafHigh());
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|