|
From: <ga...@us...> - 2013-02-20 08:01:34
|
Revision: 5963
http://jnode.svn.sourceforge.net/jnode/?rev=5963&view=rev
Author: galatnm
Date: 2013-02-20 08:01:21 +0000 (Wed, 20 Feb 2013)
Log Message:
-----------
Move index related classes into a sub-package. (Luke Quinane)
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java
trunk/fs/src/fs/org/jnode/fs/ntfs/DirectoryEntryIterator.java
trunk/fs/src/fs/org/jnode/fs/ntfs/FileRecord.java
trunk/fs/src/fs/org/jnode/fs/ntfs/MasterFileTable.java
trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSAttribute.java
trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSDirectory.java
trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSEntry.java
trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFile.java
trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystem.java
trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSStructure.java
trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSVolume.java
Added Paths:
-----------
trunk/fs/src/fs/org/jnode/fs/ntfs/index/
trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexAllocationAttribute.java
trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexBlock.java
trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexEntry.java
trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexEntryIterator.java
trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexHeader.java
trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexRoot.java
trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexRootAttribute.java
trunk/fs/src/fs/org/jnode/fs/ntfs/index/NTFSIndex.java
Removed Paths:
-------------
trunk/fs/src/fs/org/jnode/fs/ntfs/IndexAllocationAttribute.java
trunk/fs/src/fs/org/jnode/fs/ntfs/IndexBlock.java
trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntry.java
trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntryIterator.java
trunk/fs/src/fs/org/jnode/fs/ntfs/IndexHeader.java
trunk/fs/src/fs/org/jnode/fs/ntfs/IndexRoot.java
trunk/fs/src/fs/org/jnode/fs/ntfs/IndexRootAttribute.java
trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSIndex.java
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.util.Arrays;
+
import org.apache.log4j.Logger;
import org.jnode.util.LittleEndian;
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/DirectoryEntryIterator.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/DirectoryEntryIterator.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/DirectoryEntryIterator.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -23,6 +23,8 @@
import java.util.Iterator;
import org.jnode.fs.FSEntry;
+import org.jnode.fs.ntfs.index.IndexEntry;
+import org.jnode.fs.ntfs.index.NTFSIndex;
/**
* Iterator for FSEntry's.
@@ -51,8 +53,6 @@
/**
* Are there more entries.
- *
- * @see org.jnode.fs.FSEntryIterator#hasNext()
*/
public boolean hasNext() {
return (nextEntry != null);
@@ -60,8 +60,6 @@
/**
* Get the next entry.
- *
- * @see org.jnode.fs.FSEntryIterator#next()
*/
public FSEntry next() {
final NTFSEntry result = nextEntry;
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/FileRecord.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/FileRecord.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/FileRecord.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -24,6 +24,7 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+
import org.jnode.util.NumberUtils;
/**
@@ -32,7 +33,7 @@
* @author Ewout Prangsma (ep...@us...)
* @author Daniel Noll (da...@no...) (new attribute iteration support)
*/
-class FileRecord extends NTFSRecord {
+public class FileRecord extends NTFSRecord {
/**
* Sequence number of the file within the MFT.
Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/IndexAllocationAttribute.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/IndexAllocationAttribute.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/IndexAllocationAttribute.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -1,82 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2003-2013 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.fs.ntfs;
-
-import java.io.IOException;
-
-/**
- * @author Ewout Prangsma (ep...@us...)
- */
-final class IndexAllocationAttribute extends NTFSNonResidentAttribute {
-
- /**
- * Creates the index allocation attribute.
- *
- * @param fileRecord the file record.
- * @param offset the offset of this attribute into the file record.
- */
- public IndexAllocationAttribute(FileRecord fileRecord, int offset) {
- super(fileRecord, offset);
- }
-
- /**
- * Gets the magic value of this record.
- *
- * @return the magic value.
- */
- public int getMagic() {
- return getUInt32AsInt(0x00);
- }
-
- /**
- * Read an index block starting at a given vcn.
- *
- * @param indexRoot
- * @param vcn
- * @return
- * @throws IOException
- */
- public IndexBlock getIndexBlock(IndexRoot indexRoot, long vcn) throws IOException {
- log.debug("getIndexBlock(..," + vcn + ")");
- final FileRecord fileRecord = getFileRecord();
-
- // VCN passed in is relative to the size of index clusters, not filesystem clusters.
- // Calculate the actual offset we need in terms of filesystem clusters,
- // and how many actual clusters we will need to read.
-
- final int indexBlockSize = indexRoot.getIndexBlockSize();
- final int indexClusterSize = indexBlockSize / indexRoot.getClustersPerIndexBlock();
- final int fsClusterSize = fileRecord.getVolume().getClusterSize();
- final long fsVcn = vcn * indexClusterSize / fsClusterSize;
- final int fsNrClusters = (indexBlockSize - 1) / fsClusterSize + 1;
- final int offsetIntoVcn = (int) ((vcn * indexClusterSize) % fsClusterSize);
-
- final byte[] data = new byte[fsNrClusters * fsClusterSize];
- final int readClusters = readVCN(fsVcn, data, 0, fsNrClusters);
- if (readClusters != fsNrClusters) {
- // If we don't throw an error now, it just fails more mysteriously later!
- throw new IOException("Number of clusters read was not the number requested (requested " +
- fsNrClusters + ", read " + readClusters + ")");
- }
-
- return new IndexBlock(fileRecord, data, offsetIntoVcn);
- }
-}
Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/IndexBlock.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/IndexBlock.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/IndexBlock.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -1,96 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2003-2013 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.fs.ntfs;
-
-import java.io.IOException;
-import java.util.Iterator;
-
-/**
- * @author Ewout Prangsma (ep...@us...)
- */
-final class IndexBlock extends NTFSRecord {
-
- /** Cached header instance */
- private IndexHeader header;
-
- /** Parent file */
- private final FileRecord parentFileRecord;
-
- /**
- * @param buffer
- * @param offset
- */
- public IndexBlock(FileRecord parentFileRecord, byte[] buffer, int offset) throws IOException {
- super(parentFileRecord.getVolume(), buffer, offset);
- this.parentFileRecord = parentFileRecord;
- }
-
- /**
- * $LogFile sequence number of the last modification of this index block.
- *
- * @return
- */
- public long getLogFileSequenceNumber() {
- return getInt64(0x08);
- }
-
- /**
- * Virtual cluster number of the index block. If the cluster_size on the
- * volume is <= the index_block_size of the directory, index_block_vcn
- * counts in units of clusters, and in units of sectors otherwise.
- *
- * @return
- */
- public long getIndexBlockVCN() {
- return getUInt32(0x10);
- }
-
- /**
- * Describes the following index entries.
- *
- * @return
- */
- public IndexHeader getHeader() {
- if (header == null) {
- header = new IndexHeader(this, 0x18);
- }
- return header;
- }
-
- /**
- * Gets the parent file record.
- *
- * @return
- */
- public FileRecord getParentFileRecord() {
- return parentFileRecord;
- }
-
- /**
- * Gets an iterator to iterate over all IndexEntry's in this block.
- *
- * @return
- */
- public Iterator<IndexEntry> iterator() {
- return new IndexEntryIterator(parentFileRecord, this,
- getHeader().getFirstEntryOffset() + 0x18);
- }
-}
Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntry.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntry.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -1,138 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2003-2013 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.fs.ntfs;
-
-import java.io.UnsupportedEncodingException;
-
-/**
- * Structure accessor of an Index Entry.
- * @author vali
- * @author Ewout Prangsma (ep...@us...)
- */
-public final class IndexEntry extends NTFSStructure {
-
- private final FileRecord parentFileRecord;
-
- /**
- * Initialize this instance.
- * @param parentFileRecord
- * @param buffer
- * @param offset
- */
- public IndexEntry(FileRecord parentFileRecord, byte[] buffer, int offset) {
- super(buffer, offset);
- this.parentFileRecord = parentFileRecord;
- }
-
- /**
- * Initialize this instance.
- * @param parentFileRecord
- * @param parent
- * @param offset
- */
- public IndexEntry(FileRecord parentFileRecord, NTFSStructure parent, int offset) {
- super(parent, offset);
- this.parentFileRecord = parentFileRecord;
- }
-
- public boolean hasSubNodes() {
- return (getIndexFlags() & 0x01) != 0;
- }
-
- /**
- * Gets the length of this index entry in bytes.
- * @return
- */
- public int getSize() {
- return getUInt16(0x08);
- }
-
- /**
- * Gets the flags of this index entry.
- * @return
- */
- public int getIndexFlags() {
- return getUInt8(0x0C);
- }
-
- public boolean isLastIndexEntryInSubnode() {
- return (getIndexFlags() & 0x02) != 0;
- }
-
- /**
- * Gets the filename namespace.
- * @see FileNameAttribute.NameSpace
- * @return
- */
- public int getNameSpace() {
- return getUInt8(0x51);
- }
-
- public boolean isDirectory() {
- return (getFileFlags() & 0x10000000L) != 0;
- }
-
- public String getFileName() {
- try {
- // XXX: For Java 6, should use the version that accepts a Charset.
- return new String(this.getFileNameAsByteArray(), "UTF-16LE");
- } catch (UnsupportedEncodingException e) {
- throw new IllegalStateException("UTF-16LE charset missing from JRE", e);
- }
- }
-
- public long getFileReferenceNumber() {
- return getUInt48(0x00);
- }
-
- public long getFileFlags() {
- return getInt64(0x48);
- }
-
- public long getRealFileSize() {
- return getInt64(0x40);
- }
-
- /**
- * @return Returns the parentFileRecord.
- */
- public FileRecord getParentFileRecord() {
- return parentFileRecord;
- }
-
- public long getSubnodeVCN() {
- return getInt64(getSize() - 8); // TODO: getUInt64AsInt
- // return getUInt32(getSize() - 8);
- }
-
- private byte[] getFileNameAsByteArray() {
- final int len = getUInt8(0x50);
- final byte[] bytes = new byte[len * 2];
- getData(0x52, bytes, 0, bytes.length);
- return bytes;
- }
-
- @Override
- public String toString() {
- return super.toString() + "[fileName=" + getFileName() + ",indexFlags=" + getIndexFlags() + ",fileFlags="
- + getFileFlags() + "]";
- }
-}
Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntryIterator.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntryIterator.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/IndexEntryIterator.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -1,94 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2003-2013 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.fs.ntfs;
-
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-/**
- * Iterator used to iterate over all IndexEntry's in an index block or index_root attribute.
- * @author Ewout Prangsma (ep...@us...)
- */
-public final class IndexEntryIterator implements Iterator<IndexEntry> {
- private int offset;
- private IndexEntry nextEntry;
- private final NTFSStructure parent;
- private final FileRecord parentFileRecord;
-
- /**
- * Initialize this instance.
- */
- public IndexEntryIterator(FileRecord parentFileRecord, NTFSStructure parent, int firstOffset) {
- this.offset = firstOffset;
- this.parentFileRecord = parentFileRecord;
- this.parent = parent;
- readNext();
- }
-
- /**
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext() {
- if (nextEntry == null) {
- return false;
- }
- return !nextEntry.isLastIndexEntryInSubnode() || nextEntry.hasSubNodes();
- }
-
- /**
- * @see java.util.Iterator#next()
- */
- public IndexEntry next() {
- if (nextEntry == null) {
- throw new NoSuchElementException();
- } else {
- final IndexEntry result = nextEntry;
- final int size = nextEntry.getSize();
-
- // Prevents an infinite loop. Seen on images where the size of the index entry has been zeroed out.
- if (size <= 0) {
- throw new IllegalStateException(String.format(
- "Index entry size is 0, filesystem is corrupt. Parent directory: '%s', reference number '%d'",
- nextEntry.getParentFileRecord().getFileName(),
- nextEntry.getParentFileRecord().getReferenceNumber()));
- }
-
- offset += size;
- // Now read the next next entry
- readNext();
- return result;
- }
- }
-
- /**
- * @see java.util.Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- private void readNext() {
- nextEntry = new IndexEntry(parentFileRecord, parent, offset);
- if (nextEntry.isLastIndexEntryInSubnode() && !nextEntry.hasSubNodes()) {
- nextEntry = null;
- }
- }
-}
Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/IndexHeader.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/IndexHeader.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/IndexHeader.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -1,92 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2003-2013 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.fs.ntfs;
-
-
-/**
- * @author Ewout Prangsma (ep...@us...)
- */
-final class IndexHeader extends NTFSStructure {
-
- /** Size of this structure index bytes */
- public static final int SIZE = 0x10;
-
- public static final class Flags {
- public static final int LARGE_INDEX = 0x01;
- }
-
- /**
- * Initialize this instance.
- * @param attr
- */
- public IndexHeader(IndexRootAttribute attr) {
- super(attr, attr.getAttributeOffset() + 0x10);
- }
-
- /**
- * Initialize this instance.
- * @param indexBlock
- * @param offset
- */
- public IndexHeader(IndexBlock indexBlock, int offset) {
- super(indexBlock, offset);
- }
-
- /**
- * Gets the offset of the first index entry.
- * @return
- */
- public int getFirstEntryOffset() {
- return getUInt32AsInt(0x00);
- }
-
- /**
- * Gets the total size of the index entries (in bytes???).
- * @return
- */
- public int getIndexEntriesSize() {
- return getUInt32AsInt(0x04);
- }
-
- /**
- * Gets the allocated size of the index entries (in bytes???).
- * @return
- */
- public int getAllocatedIndexEntriesSize() {
- return getUInt32AsInt(0x08);
- }
-
- /**
- * Gets the flags.
- * @return
- */
- public int getFlags() {
- return getUInt8(0x0C);
- }
-
- /**
- * Is an index allocation needed.
- * @return
- */
- public boolean isLargeIndex() {
- return ((getFlags() & Flags.LARGE_INDEX) != 0);
- }
-}
Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/IndexRoot.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/IndexRoot.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/IndexRoot.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -1,75 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2003-2013 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.fs.ntfs;
-
-
-/**
- * @author Ewout Prangsma (ep...@us...)
- */
-final class IndexRoot extends NTFSStructure {
-
- public static final int SIZE = 0x10;
-
- /**
- * Initialize this instance.
- * @param attr
- */
- public IndexRoot(IndexRootAttribute attr) {
- super(attr, attr.getAttributeOffset());
- }
-
- /**
- * Gets the attribute type.
- * @return
- */
- public int getAttributeType() {
- return getUInt32AsInt(0x00);
- }
-
- /**
- * Gets the collation rule.
- * @return
- */
- public int getCollationRule() {
- return getUInt32AsInt(0x04);
- }
-
- /**
- * Size of each index block in bytes (in the index allocation attribute).
- * @return
- */
- public int getIndexBlockSize() {
- return getUInt32AsInt(0x08);
- }
-
- /**
- * Gets the number of clusters per index record.
- * @return
- */
- public int getClustersPerIndexBlock() {
- final int v = getInt8(0x0C);
- if (v < 0) {
- return 1;
- } else {
- return v;
- }
- }
-}
Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/IndexRootAttribute.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/IndexRootAttribute.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/IndexRootAttribute.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -1,72 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2003-2013 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.fs.ntfs;
-
-import java.util.Iterator;
-
-/**
- * @author Ewout Prangsma (ep...@us...)
- */
-public final class IndexRootAttribute extends NTFSResidentAttribute {
-
- private IndexRoot root;
-
- private IndexHeader header;
-
- /**
- * @param fileRecord
- * @param offset
- */
- public IndexRootAttribute(FileRecord fileRecord, int offset) {
- super(fileRecord, offset);
- }
-
- /**
- * Gets the index root structure.
- * @return
- */
- public IndexRoot getRoot() {
- if (root == null) {
- root = new IndexRoot(this);
- }
- return root;
- }
-
- /**
- * Gets the index header structure.
- * @return
- */
- public IndexHeader getHeader() {
- if (header == null) {
- header = new IndexHeader(this);
- }
- return header;
- }
-
- /**
- * Gets an iterator to iterate over all IndexEntry's in this index_root attribute.
- * @return
- */
- public Iterator<IndexEntry> iterator() {
- final int headerOffset = getAttributeOffset() + IndexRoot.SIZE;
- return new IndexEntryIterator(getFileRecord(), this, headerOffset + getHeader().getFirstEntryOffset());
- }
-}
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/MasterFileTable.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/MasterFileTable.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/MasterFileTable.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -22,6 +22,8 @@
import java.io.IOException;
+import org.jnode.fs.ntfs.index.IndexEntry;
+
/**
* @author Ewout Prangsma (ep...@us...)
*/
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSAttribute.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSAttribute.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSAttribute.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -20,6 +20,9 @@
package org.jnode.fs.ntfs;
+import org.jnode.fs.ntfs.index.IndexAllocationAttribute;
+import org.jnode.fs.ntfs.index.IndexRootAttribute;
+
/**
* @author Chira
* @author Ewout Prangsma (ep...@us...)
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSDirectory.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSDirectory.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSDirectory.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -28,6 +28,7 @@
import org.jnode.fs.FSEntry;
import org.jnode.fs.FileSystem;
import org.jnode.fs.ReadOnlyFileSystemException;
+import org.jnode.fs.ntfs.index.NTFSIndex;
/**
* @author vali
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSEntry.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSEntry.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -21,6 +21,7 @@
package org.jnode.fs.ntfs;
import java.io.IOException;
+
import org.jnode.fs.FSAccessRights;
import org.jnode.fs.FSDirectory;
import org.jnode.fs.FSEntry;
@@ -30,6 +31,7 @@
import org.jnode.fs.FSFile;
import org.jnode.fs.FSObject;
import org.jnode.fs.FileSystem;
+import org.jnode.fs.ntfs.index.IndexEntry;
/**
* @author vali
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFile.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFile.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFile.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -22,9 +22,11 @@
import java.io.IOException;
import java.nio.ByteBuffer;
+
import org.jnode.fs.FSFile;
import org.jnode.fs.FSFileSlackSpace;
import org.jnode.fs.FileSystem;
+import org.jnode.fs.ntfs.index.IndexEntry;
import org.jnode.util.ByteBufferUtils;
/**
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystem.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystem.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
+
import org.jnode.driver.Device;
import org.jnode.fs.FSDirectory;
import org.jnode.fs.FSEntry;
Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSIndex.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSIndex.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSIndex.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -1,174 +0,0 @@
-/*
- * $Id$
- *
- * Copyright (C) 2003-2013 JNode.org
- *
- * This library is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published
- * by the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
- * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
- * License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this library; If not, write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-package org.jnode.fs.ntfs;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import org.apache.log4j.Logger;
-import org.jnode.util.Queue;
-
-/**
- * @author Chira
- * @author Ewout Prangsma (ep...@us...)
- */
-final class NTFSIndex {
-
- private final FileRecord fileRecord;
-
- private IndexRootAttribute indexRootAttribute;
-
- private IndexAllocationAttribute indexAllocationAttribute;
-
- static final Logger log = Logger.getLogger(NTFSIndex.class);
-
- /**
- * Initialize this instance.
- *
- * @param fileRecord
- */
- public NTFSIndex(FileRecord fileRecord) throws IOException {
- this.fileRecord = fileRecord;
- if (!fileRecord.isDirectory()) {
- throw new IOException("fileRecord is not a directory");
- }
- }
-
- /**
- * Gets the index root attribute.
- *
- * @return
- */
- public IndexRootAttribute getIndexRootAttribute() {
- if (indexRootAttribute == null) {
- indexRootAttribute = (IndexRootAttribute)
- fileRecord.findAttributeByType(NTFSAttribute.Types.INDEX_ROOT);
- log.debug("getIndexRootAttribute: " + indexRootAttribute);
- }
- return indexRootAttribute;
- }
-
- /**
- * Gets the index allocation attribute, if any.
- *
- * @return
- */
- public IndexAllocationAttribute getIndexAllocationAttribute() {
- if (indexAllocationAttribute == null) {
- indexAllocationAttribute = (IndexAllocationAttribute)
- fileRecord.findAttributeByType(NTFSAttribute.Types.INDEX_ALLOCATION);
- }
- return indexAllocationAttribute;
- }
-
- public Iterator<IndexEntry> iterator() {
- log.debug("iterator");
- return new FullIndexEntryIterator();
- }
-
- class FullIndexEntryIterator implements Iterator<IndexEntry> {
-
- /**
- * List of those IndexEntry's that have a subnode and the subnode has
- * not been visited.
- */
- private final Queue<IndexEntry> subNodeEntries = new Queue<IndexEntry>();
-
- /** Iterator of current part of the index */
- private Iterator<IndexEntry> currentIterator;
-
- private IndexEntry nextEntry;
-
- /**
- * Initialize this instance.
- */
- public FullIndexEntryIterator() {
- log.debug("FullIndexEntryIterator");
- currentIterator = getIndexRootAttribute().iterator();
- log.debug("currentIterator=" + currentIterator);
- readNextEntry();
- }
-
- /**
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext() {
- return (nextEntry != null);
- }
-
- /**
- * @see java.util.Iterator#next()
- */
- public IndexEntry next() {
- final IndexEntry result = nextEntry;
- if (result == null) {
- throw new NoSuchElementException();
- }
- readNextEntry();
- return result;
- }
-
- /**
- * @see java.util.Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- private void readNextEntry() {
- while (true) {
- if (currentIterator.hasNext()) {
- // Read it
- nextEntry = currentIterator.next();
- if (nextEntry.hasSubNodes()) {
- log.debug("next has subnode");
- subNodeEntries.add(nextEntry);
- }
- if (!nextEntry.isLastIndexEntryInSubnode()) {
- return;
- }
- }
- nextEntry = null;
-
- // Do we have subnodes to iterate over?
- if (subNodeEntries.isEmpty()) {
- // No, we're done
- log.debug("end of list");
- return;
- }
-
- log.debug("hasNext: read next indexblock");
- final IndexEntry entry = subNodeEntries.get();
- final IndexRoot indexRoot = getIndexRootAttribute().getRoot();
- final IndexBlock indexBlock;
- try {
- indexBlock = getIndexAllocationAttribute().getIndexBlock(
- indexRoot, entry.getSubnodeVCN());
- } catch (IOException ex) {
- log.error("Cannot read next index block", ex);
- return;
- }
- currentIterator = indexBlock.iterator();
- }
- }
- }
-}
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSStructure.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSStructure.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSStructure.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -26,7 +26,7 @@
/**
* @author Ewout Prangsma (ep...@us...)
*/
-abstract class NTFSStructure {
+public abstract class NTFSStructure {
/** My logger */
protected static final Logger log = Logger.getLogger(NTFSStructure.class);
@@ -39,7 +39,7 @@
* @param buffer
* @param offset
*/
- NTFSStructure(byte[] buffer, int offset) {
+ public NTFSStructure(byte[] buffer, int offset) {
this.buffer = buffer;
this.offset = offset;
}
@@ -49,7 +49,7 @@
* @param parent
* @param offset
*/
- NTFSStructure(NTFSStructure parent, int offset) {
+ public NTFSStructure(NTFSStructure parent, int offset) {
this.buffer = parent.buffer;
this.offset = parent.offset + offset;
}
@@ -79,7 +79,7 @@
* @param offset
* @return
*/
- final int getUInt8(int offset) {
+ public final int getUInt8(int offset) {
return LittleEndian.getUInt8(buffer, this.offset + offset);
}
@@ -88,7 +88,7 @@
* @param offset
* @return
*/
- final int getUInt16(int offset) {
+ public final int getUInt16(int offset) {
return LittleEndian.getUInt16(buffer, this.offset + offset);
}
@@ -97,7 +97,7 @@
* @param offset
* @return
*/
- final int getUInt24(int offset) {
+ public final int getUInt24(int offset) {
return LittleEndian.getUInt24(buffer, this.offset + offset);
}
@@ -106,7 +106,7 @@
* @param offset
* @return
*/
- final long getUInt32(int offset) {
+ public final long getUInt32(int offset) {
return LittleEndian.getUInt32(buffer, this.offset + offset);
}
@@ -115,7 +115,7 @@
* @param offset
* @return
*/
- final int getUInt32AsInt(int offset) {
+ public final int getUInt32AsInt(int offset) {
return (int) LittleEndian.getUInt32(buffer, this.offset + offset);
}
@@ -124,7 +124,7 @@
* @param offset
* @return
*/
- final long getUInt48(int offset) {
+ public final long getUInt48(int offset) {
return LittleEndian.getUInt48(buffer, this.offset + offset);
}
@@ -133,7 +133,7 @@
* @param offset
* @return
*/
- final int getInt8(int offset) {
+ public final int getInt8(int offset) {
return LittleEndian.getInt8(buffer, this.offset + offset);
}
@@ -142,7 +142,7 @@
* @param offset
* @return
*/
- final int getInt16(int offset) {
+ public final int getInt16(int offset) {
return LittleEndian.getInt16(buffer, this.offset + offset);
}
@@ -151,7 +151,7 @@
* @param offset
* @return
*/
- final int getInt24(int offset) {
+ public final int getInt24(int offset) {
return LittleEndian.getInt24(buffer, this.offset + offset);
}
@@ -160,7 +160,7 @@
* @param offset
* @return
*/
- final int getInt32(int offset) {
+ public final int getInt32(int offset) {
return LittleEndian.getInt32(buffer, this.offset + offset);
}
@@ -169,7 +169,7 @@
* @param offset
* @return
*/
- final long getInt64(int offset) {
+ public final long getInt64(int offset) {
return LittleEndian.getInt64(buffer, this.offset + offset);
}
@@ -189,7 +189,7 @@
* @param offset
* @return
*/
- final char getChar16(int offset) {
+ public final char getChar16(int offset) {
final int v0 = buffer[this.offset + offset] & 0xFF;
final int v1 = buffer[this.offset + offset + 1] & 0xFF;
return (char) ((v1 << 8) | v0);
@@ -199,7 +199,7 @@
* Write an unsigned 16-bit integer to a given offset.
* @param offset
*/
- final void setUInt16(int offset, int value) {
+ public final void setUInt16(int offset, int value) {
LittleEndian.setInt16(buffer, this.offset + offset, value);
}
Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSVolume.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSVolume.java 2013-02-19 16:26:07 UTC (rev 5962)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSVolume.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
+
import org.apache.log4j.Logger;
import org.jnode.driver.block.BlockDeviceAPI;
Added: trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexAllocationAttribute.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexAllocationAttribute.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexAllocationAttribute.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -0,0 +1,85 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2012 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.fs.ntfs.index;
+
+import java.io.IOException;
+
+import org.jnode.fs.ntfs.FileRecord;
+import org.jnode.fs.ntfs.NTFSNonResidentAttribute;
+
+/**
+ * @author Ewout Prangsma (ep...@us...)
+ */
+public final class IndexAllocationAttribute extends NTFSNonResidentAttribute {
+
+ /**
+ * Creates the index allocation attribute.
+ *
+ * @param fileRecord the file record.
+ * @param offset the offset of this attribute into the file record.
+ */
+ public IndexAllocationAttribute(FileRecord fileRecord, int offset) {
+ super(fileRecord, offset);
+ }
+
+ /**
+ * Gets the magic value of this record.
+ *
+ * @return the magic value.
+ */
+ public int getMagic() {
+ return getUInt32AsInt(0x00);
+ }
+
+ /**
+ * Read an index block starting at a given vcn.
+ *
+ * @param indexRoot
+ * @param vcn
+ * @return
+ * @throws IOException
+ */
+ public IndexBlock getIndexBlock(IndexRoot indexRoot, long vcn) throws IOException {
+ log.debug("getIndexBlock(..," + vcn + ")");
+ final FileRecord fileRecord = getFileRecord();
+
+ // VCN passed in is relative to the size of index clusters, not filesystem clusters.
+ // Calculate the actual offset we need in terms of filesystem clusters,
+ // and how many actual clusters we will need to read.
+
+ final int indexBlockSize = indexRoot.getIndexBlockSize();
+ final int indexClusterSize = indexBlockSize / indexRoot.getClustersPerIndexBlock();
+ final int fsClusterSize = fileRecord.getVolume().getClusterSize();
+ final long fsVcn = vcn * indexClusterSize / fsClusterSize;
+ final int fsNrClusters = (indexBlockSize - 1) / fsClusterSize + 1;
+ final int offsetIntoVcn = (int) ((vcn * indexClusterSize) % fsClusterSize);
+
+ final byte[] data = new byte[fsNrClusters * fsClusterSize];
+ final int readClusters = readVCN(fsVcn, data, 0, fsNrClusters);
+ if (readClusters != fsNrClusters) {
+ // If we don't throw an error now, it just fails more mysteriously later!
+ throw new IOException("Number of clusters read was not the number requested (requested " +
+ fsNrClusters + ", read " + readClusters + ")");
+ }
+
+ return new IndexBlock(fileRecord, data, offsetIntoVcn);
+ }
+}
Added: trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexBlock.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexBlock.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexBlock.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -0,0 +1,99 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2012 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.fs.ntfs.index;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+import org.jnode.fs.ntfs.FileRecord;
+import org.jnode.fs.ntfs.NTFSRecord;
+
+/**
+ * @author Ewout Prangsma (ep...@us...)
+ */
+final class IndexBlock extends NTFSRecord {
+
+ /** Cached header instance */
+ private IndexHeader header;
+
+ /** Parent file */
+ private final FileRecord parentFileRecord;
+
+ /**
+ * @param buffer
+ * @param offset
+ */
+ public IndexBlock(FileRecord parentFileRecord, byte[] buffer, int offset) throws IOException {
+ super(parentFileRecord.getVolume(), buffer, offset);
+ this.parentFileRecord = parentFileRecord;
+ }
+
+ /**
+ * $LogFile sequence number of the last modification of this index block.
+ *
+ * @return
+ */
+ public long getLogFileSequenceNumber() {
+ return getInt64(0x08);
+ }
+
+ /**
+ * Virtual cluster number of the index block. If the cluster_size on the
+ * volume is <= the index_block_size of the directory, index_block_vcn
+ * counts in units of clusters, and in units of sectors otherwise.
+ *
+ * @return
+ */
+ public long getIndexBlockVCN() {
+ return getUInt32(0x10);
+ }
+
+ /**
+ * Describes the following index entries.
+ *
+ * @return
+ */
+ public IndexHeader getHeader() {
+ if (header == null) {
+ header = new IndexHeader(this, 0x18);
+ }
+ return header;
+ }
+
+ /**
+ * Gets the parent file record.
+ *
+ * @return
+ */
+ public FileRecord getParentFileRecord() {
+ return parentFileRecord;
+ }
+
+ /**
+ * Gets an iterator to iterate over all IndexEntry's in this block.
+ *
+ * @return
+ */
+ public Iterator<IndexEntry> iterator() {
+ return new IndexEntryIterator(parentFileRecord, this,
+ getHeader().getFirstEntryOffset() + 0x18);
+ }
+}
Added: trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexEntry.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexEntry.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -0,0 +1,144 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2012 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.fs.ntfs.index;
+
+import java.io.UnsupportedEncodingException;
+
+import org.jnode.fs.ntfs.FileRecord;
+import org.jnode.fs.ntfs.NTFSStructure;
+
+/**
+ * Structure accessor of an Index Entry.
+ *
+ * @author vali
+ * @author Ewout Prangsma (ep...@us...)
+ */
+public final class IndexEntry extends NTFSStructure {
+
+ private final FileRecord parentFileRecord;
+
+ /**
+ * Initialize this instance.
+ * @param parentFileRecord
+ * @param buffer
+ * @param offset
+ */
+ public IndexEntry(FileRecord parentFileRecord, byte[] buffer, int offset) {
+ super(buffer, offset);
+ this.parentFileRecord = parentFileRecord;
+ }
+
+ /**
+ * Initialize this instance.
+ * @param parentFileRecord
+ * @param parent
+ * @param offset
+ */
+ public IndexEntry(FileRecord parentFileRecord, NTFSStructure parent, int offset) {
+ super(parent, offset);
+ this.parentFileRecord = parentFileRecord;
+ }
+
+ public boolean hasSubNodes() {
+ return (getIndexFlags() & 0x01) != 0;
+ }
+
+ /**
+ * Gets the length of this index entry in bytes.
+ * @return
+ */
+ public int getSize() {
+ return getUInt16(0x08);
+ }
+
+ /**
+ * Gets the flags of this index entry.
+ * @return
+ */
+ public int getIndexFlags() {
+ return getUInt8(0x0C);
+ }
+
+ public boolean isLastIndexEntryInSubnode() {
+ return (getIndexFlags() & 0x02) != 0;
+ }
+
+ /**
+ * Gets the filename namespace.
+ * @see org.jnode.fs.ntfs.FileNameAttribute.NameSpace
+ * @return
+ */
+ public int getNameSpace() {
+ return getUInt8(0x51);
+ }
+
+ public boolean isDirectory() {
+ return (getFileFlags() & 0x10000000L) != 0;
+ }
+
+ public String getFileName() {
+ try {
+ //XXX: For Java 6, should use the version that accepts a Charset.
+ return new String(this.getFileNameAsByteArray(), "UTF-16LE");
+ } catch (UnsupportedEncodingException e) {
+ throw new IllegalStateException("UTF-16LE charset missing from JRE", e);
+ }
+ }
+
+ public long getFileReferenceNumber() {
+ return getUInt48(0x00);
+ }
+
+ public long getFileFlags() {
+ return getInt64(0x48);
+ }
+
+ public long getRealFileSize() {
+ return getInt64(0x40);
+ }
+
+ /**
+ * @return Returns the parentFileRecord.
+ */
+ public FileRecord getParentFileRecord() {
+ return parentFileRecord;
+ }
+
+ public long getSubnodeVCN() {
+ return getInt64(getSize() - 8); // TODO: getUInt64AsInt
+ //return getUInt32(getSize() - 8);
+ }
+
+ private byte[] getFileNameAsByteArray() {
+ final int len = getUInt8(0x50);
+ final byte[] bytes = new byte[len * 2];
+ getData(0x52, bytes, 0, bytes.length);
+ return bytes;
+ }
+
+ @Override
+ public String toString() {
+ return super.toString() +
+ "[fileName=" + getFileName() +
+ ",indexFlags=" + getIndexFlags() +
+ ",fileFlags=" + getFileFlags() + "]";
+ }
+}
Added: trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexEntryIterator.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexEntryIterator.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexEntryIterator.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -0,0 +1,100 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2012 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.fs.ntfs.index;
+
+import java.util.Iterator;
+import java.util.NoSuchElementException;
+
+import org.jnode.fs.ntfs.FileRecord;
+import org.jnode.fs.ntfs.NTFSStructure;
+
+
+/**
+ * Iterator used to iterate over all IndexEntry's in an index block
+ * or index_root attribute.
+ *
+ * @author Ewout Prangsma (ep...@us...)
+ */
+public final class IndexEntryIterator implements Iterator<IndexEntry> {
+ private int offset;
+ private IndexEntry nextEntry;
+ private final NTFSStructure parent;
+ private final FileRecord parentFileRecord;
+
+ /**
+ * Initialize this instance.
+ */
+ public IndexEntryIterator(FileRecord parentFileRecord, NTFSStructure parent, int firstOffset) {
+ this.offset = firstOffset;
+ this.parentFileRecord = parentFileRecord;
+ this.parent = parent;
+ readNext();
+ }
+
+ /**
+ * @see java.util.Iterator#hasNext()
+ */
+ public boolean hasNext() {
+ if (nextEntry == null) {
+ return false;
+ }
+ return !nextEntry.isLastIndexEntryInSubnode() || nextEntry.hasSubNodes();
+ }
+
+ /**
+ * @see java.util.Iterator#next()
+ */
+ public IndexEntry next() {
+ if (nextEntry == null) {
+ throw new NoSuchElementException();
+ } else {
+ final IndexEntry result = nextEntry;
+ final int size = nextEntry.getSize();
+
+ // Prevents an infinite loop. Seen on images where the size of the index entry has been zeroed out.
+ if (size <= 0) {
+ throw new IllegalStateException(String.format(
+ "Index entry size is 0, filesystem is corrupt. Parent directory: '%s', reference number '%d'",
+ nextEntry.getParentFileRecord().getFileName(),
+ nextEntry.getParentFileRecord().getReferenceNumber()));
+ }
+
+ offset += size;
+ // Now read the next next entry
+ readNext();
+ return result;
+ }
+ }
+
+ /**
+ * @see java.util.Iterator#remove()
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ private void readNext() {
+ nextEntry = new IndexEntry(parentFileRecord, parent, offset);
+ if (nextEntry.isLastIndexEntryInSubnode() && !nextEntry.hasSubNodes()) {
+ nextEntry = null;
+ }
+ }
+}
Added: trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexHeader.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexHeader.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexHeader.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -0,0 +1,95 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2012 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.fs.ntfs.index;
+
+import org.jnode.fs.ntfs.NTFSStructure;
+
+
+
+/**
+ * @author Ewout Prangsma (ep...@us...)
+ */
+final class IndexHeader extends NTFSStructure {
+
+ /** Size of this structure index bytes */
+ public static final int SIZE = 0x10;
+
+ public static final class Flags {
+ public static final int LARGE_INDEX = 0x01;
+ }
+
+ /**
+ * Initialize this instance.
+ * @param attr
+ */
+ public IndexHeader(IndexRootAttribute attr) {
+ super(attr, attr.getAttributeOffset() + 0x10);
+ }
+
+ /**
+ * Initialize this instance.
+ * @param indexBlock
+ * @param offset
+ */
+ public IndexHeader(IndexBlock indexBlock, int offset) {
+ super(indexBlock, offset);
+ }
+
+ /**
+ * Gets the offset of the first index entry.
+ * @return
+ */
+ public int getFirstEntryOffset() {
+ return getUInt32AsInt(0x00);
+ }
+
+ /**
+ * Gets the total size of the index entries (in bytes???).
+ * @return
+ */
+ public int getIndexEntriesSize() {
+ return getUInt32AsInt(0x04);
+ }
+
+ /**
+ * Gets the allocated size of the index entries (in bytes???).
+ * @return
+ */
+ public int getAllocatedIndexEntriesSize() {
+ return getUInt32AsInt(0x08);
+ }
+
+ /**
+ * Gets the flags.
+ * @return
+ */
+ public int getFlags() {
+ return getUInt8(0x0C);
+ }
+
+ /**
+ * Is an index allocation needed.
+ * @return
+ */
+ public boolean isLargeIndex() {
+ return ((getFlags() & Flags.LARGE_INDEX) != 0);
+ }
+}
Added: trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexRoot.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexRoot.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexRoot.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -0,0 +1,78 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2012 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.fs.ntfs.index;
+
+import org.jnode.fs.ntfs.NTFSStructure;
+
+
+
+/**
+ * @author Ewout Prangsma (ep...@us...)
+ */
+final class IndexRoot extends NTFSStructure {
+
+ public static final int SIZE = 0x10;
+
+ /**
+ * Initialize this instance.
+ * @param attr
+ */
+ public IndexRoot(IndexRootAttribute attr) {
+ super(attr, attr.getAttributeOffset());
+ }
+
+ /**
+ * Gets the attribute type.
+ * @return
+ */
+ public int getAttributeType() {
+ return getUInt32AsInt(0x00);
+ }
+
+ /**
+ * Gets the collation rule.
+ * @return
+ */
+ public int getCollationRule() {
+ return getUInt32AsInt(0x04);
+ }
+
+ /**
+ * Size of each index block in bytes (in the index allocation attribute).
+ * @return
+ */
+ public int getIndexBlockSize() {
+ return getUInt32AsInt(0x08);
+ }
+
+ /**
+ * Gets the number of clusters per index record.
+ * @return
+ */
+ public int getClustersPerIndexBlock() {
+ final int v = getInt8(0x0C);
+ if (v < 0) {
+ return 1;
+ } else {
+ return v;
+ }
+ }
+}
Added: trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexRootAttribute.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexRootAttribute.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexRootAttribute.java 2013-02-20 08:01:21 UTC (rev 5963)
@@ -0,0 +1,80 @@
+/*
+ * $Id$
+ *
+ * Copyright (C) 2003-2012 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; If not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+package org.jnode.fs.ntfs.index;
+
+import java.util.Iterator;
+
+import org.jnode.fs.ntfs.FileRecord;
+import org.jnode.fs.ntfs.NTFSResidentAttribute;
+
+/**
+ * @author Ewout Prangsma (ep...@us...)
+ */
+public final class IndexRootAttribute extends NTFSResidentAttribute {
+
+ private IndexRoot root;
+
+ private IndexHeader header;
+
+ /**
+ * @param fileRecord
+ * @param offset
+ */
+ public IndexRootAttribute(FileRecord fileRecord, int offset) {
+ super(fileRecord, offset);
+ }
+
+ /**
+ * Gets the index root structure.
+ *
+ * @return
+ */
+ public IndexRoot getRoot() {
+ if (root == null) {
+ root = new IndexRoot(this);
+ }
+ return root;
+ }
+
+ /**
+ * Gets the index header structure.
+ *
+ * @return
+ */
+ public IndexHeader getHeader() {
+ if (header == null) {
+ header = new IndexHeader(this);
+ }
+ return header;
+ }
+
+ /**...
[truncated message content] |