From: <ga...@us...> - 2013-02-20 08:18:19
|
Revision: 5964 http://jnode.svn.sourceforge.net/jnode/?rev=5964&view=rev Author: galatnm Date: 2013-02-20 08:18:08 +0000 (Wed, 20 Feb 2013) Log Message: ----------- Move attribute 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/DataRun.java trunk/fs/src/fs/org/jnode/fs/ntfs/FileNameAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/FileRecord.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/StandardInformationAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexAllocationAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/index/IndexRootAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/index/NTFSIndex.java Added Paths: ----------- trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/ trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttributeNonRes.java trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttributeRes.java trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListBlock.java trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListEntry.java trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/NTFSAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/NTFSNonResidentAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/NTFSResidentAttribute.java Removed Paths: ------------- trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttributeNonRes.java trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttributeRes.java trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListBlock.java trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListEntry.java trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSNonResidentAttribute.java trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSResidentAttribute.java Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttribute.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttribute.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -1,42 +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; - -/** - * Common interface for both resident and non-resident attribute list - * attributes. - * - * @author Daniel Noll (da...@no...) - */ -interface AttributeListAttribute { - - /** - * Gets an iterator over all the entries in the attribute list. - * - * @return an iterator of all attribute list entries. - * @throws IOException if there is an error reading the attribute's data. - */ - Iterator<AttributeListEntry> getAllEntries() throws IOException; - -} Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttributeNonRes.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttributeNonRes.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttributeNonRes.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -1,60 +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; - -/** - * $ATTRIBUTE_LIST attribute, non-resident version. - * - * XXX: Is there a sensible way we can merge this with the resident version? - * - * @author Daniel Noll (da...@no...) - */ -final class AttributeListAttributeNonRes extends NTFSNonResidentAttribute implements - AttributeListAttribute { - - /** - * @param fileRecord - * @param offset - */ - public AttributeListAttributeNonRes(FileRecord fileRecord, int offset) { - super(fileRecord, offset); - } - - /** - * Gets an iterator over all the entries in the attribute list. - * - * @return an iterator of all attribute list entries. - * @throws IOException if there is an error reading the attribute's data. - */ - public Iterator<AttributeListEntry> getAllEntries() throws IOException { - // Read the actual data from wherever it happens to be located. - // TODO: Consider handling multiple data runs separately instead - // of "glueing" them all together like this. - final int nrClusters = getNumberOfVCNs(); - final byte[] data = new byte[nrClusters * getFileRecord().getVolume().getClusterSize()]; - readVCN(getStartVCN(), data, 0, nrClusters); - AttributeListBlock listBlock = new AttributeListBlock(data, 0, getAttributeActualSize()); - return listBlock.getAllEntries(); - } -} Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttributeRes.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttributeRes.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListAttributeRes.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -1,57 +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; - -/** - * $ATTRIBUTE_LIST attribute, resident version. - * - * XXX: Is there a sensible way we can merge this with the non-resident version? - * - * @author Daniel Noll (da...@no...) - */ -final class AttributeListAttributeRes extends NTFSResidentAttribute implements - AttributeListAttribute { - - /** - * @param fileRecord - * @param offset - */ - public AttributeListAttributeRes(FileRecord fileRecord, int offset) { - super(fileRecord, offset); - } - - /** - * Gets an iterator over all the entries in the attribute list. - * - * @return an iterator of all attribute list entries. - * @throws IOException if there is an error reading the attribute's data. - */ - public Iterator<AttributeListEntry> getAllEntries() throws IOException { - final byte[] data = new byte[getAttributeLength()]; - getData(getAttributeOffset(), data, 0, data.length); - AttributeListBlock listBlock = new AttributeListBlock(data, 0, getAttributeLength()); - return listBlock.getAllEntries(); - } - -} Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListBlock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListBlock.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListBlock.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -1,116 +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; - -/** - * Data structure containing a list of {@link AttributeListEntry} entries. - * - * @author Daniel Noll (da...@no...) - */ -final class AttributeListBlock extends NTFSStructure { - - /** - * The length of the block. - */ - private long length; - - /** - * @param data binary data for the block. - * @param offset the offset into the binary data. - * @param length the length of the attribute list block, or 0 if unknown. - */ - public AttributeListBlock(byte[] data, int offset, long length) { - super(data, offset); - this.length = length; - } - - /** - * Gets an iterator over all the entries in the attribute list. - * - * @return an iterator of all attribute list entries. - */ - public Iterator<AttributeListEntry> getAllEntries() { - return new AttributeListEntryIterator(); - } - - /** - * Iteration of attribute list entries. - */ - private class AttributeListEntryIterator implements Iterator<AttributeListEntry> { - - /** - * The next element to return. - */ - private AttributeListEntry nextElement; - - /** - * Current offset being looked at. - */ - private int offset = 0; - - /** - * Returns {@code true} if there are more elements in the iteration. - * - * @return {@code true} if there are more elements in the iteration. - */ - public boolean hasNext() { - // Safety check in case hasNext is called twice without calling next. - if (nextElement != null) { - return true; - } - - // If the length is specified, use it to determine where the block ends. - if (offset + 4 > length) { - return false; - } - - int length = getUInt16(offset + 0x04); - nextElement = new AttributeListEntry(AttributeListBlock.this, offset); - offset += length; - return true; - } - - /** - * Gets the next entry from the iteration. - * - * @return the next entry from the iteration. - */ - public AttributeListEntry next() { - if (hasNext()) { - AttributeListEntry result = nextElement; - nextElement = null; - return result; - } else { - throw new NoSuchElementException("Iterator has no more entries"); - } - } - - /** - * @throws UnsupportedOperationException always. - */ - public void remove() { - throw new UnsupportedOperationException(); - } - } -} Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListEntry.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/AttributeListEntry.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -1,144 +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 Daniel Noll (da...@no...) - */ -final class AttributeListEntry extends NTFSStructure { - - /** - * Creates the entry. - * - * @param block the containing attribute list block. - * @param offset the offset of this attribute within the block. - */ - public AttributeListEntry(AttributeListBlock block, int offset) { - super(block, offset); - } - - /** - * Gets the type of the attribute. - * - * @return the type of the attribute. - */ - public int getType() { - return getUInt32AsInt(0x00); - } - - /** - * Gets the size of the attribute, in bytes. - * - * @return the size of the attribute, in bytes. - */ - public int getSize() { - return getUInt16(0x04); - } - - /** - * Gets the length of the name. Not so useful for callers, hence private. - * @return the name length. - */ - private int getNameLength() { - return getUInt8(0x06); - } - - /** - * Gets the offset of the name. Not so useful for callers, hence private. - * @return the name offset (from the front of the entry.) - */ - private int getNameOffset() { - return getUInt8(0x07); - } - - /** - * Gets the starting VCN of the attribute, zero if the attribute is resident. - * @return the starting VCN. - */ - public int getStartingVCN() { - return getUInt16(0x08); - } - - /** - * Gets the file reference number, which is the lowest 48 bits of the MFT - * reference. This may point to the same file record which contains the - * attribute list. - * - * @return the file reference number. - */ - public long getFileReferenceNumber() { - return getUInt48(0x10); - } - - /** - * Gets the file sequence number, which is the highest 16 bits of the MFT - * reference. - * - * @return the file sequence number. - */ - public long getFileSequenceNumber() { - return getUInt16(0x16); - } - - /** - * Gets the ID of the attribute. This ID is unique within all attributes. - * @return the attribute ID. - */ - public int getAttributeID() { - return getUInt16(0x18); - } - - /** - * Gets the name of the attribute. Some attributes don't have names, and the names - * on attributes are supposedly unique within a given attribute type. - * - * @return the name of the attribute referenced by this entry. Returns the empty string - * if the attribute has no name. - */ - public String getName() { - final int nameLength = getNameLength(); - if (nameLength == 0) { - return ""; - } else { - char[] name = new char[nameLength]; - for (int i = 0, off = getNameOffset(); i < nameLength; i++, off += 2) { - name[i] = getChar16(off); - } - return new String(name); - } - } - - @Override - public String toString() { - StringBuilder builder = new StringBuilder(super.toString()); - builder.append("[type=").append(getType()); - builder.append(",name=").append(getName()); - if (getStartingVCN() == 0) { - builder.append(",resident"); - } else { - builder.append(",ref=").append(getFileReferenceNumber()); - builder.append(",vcn=").append(getStartingVCN()); - } - builder.append(",id=").append(getAttributeID()).append("]"); - return builder.toString(); - } -} Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -29,7 +29,7 @@ /** * @author Daniel Noll (da...@no...) */ -final class CompressedDataRun implements DataRunInterface { +public final class CompressedDataRun implements DataRunInterface { /** * Size of a compressed block in NTFS. This is always the same even if the cluster size is not 4k. */ Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/DataRun.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/DataRun.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/DataRun.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -22,11 +22,12 @@ import java.io.IOException; import java.util.Arrays; +import org.jnode.fs.ntfs.attribute.NTFSNonResidentAttribute; /** * @author Ewout Prangsma (ep...@us...) */ -final class DataRun extends NTFSStructure implements DataRunInterface { +public final class DataRun extends NTFSStructure implements DataRunInterface { /** Type of this datarun */ private final int type; Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/FileNameAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/FileNameAttribute.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/FileNameAttribute.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -20,6 +20,8 @@ package org.jnode.fs.ntfs; +import org.jnode.fs.ntfs.attribute.NTFSResidentAttribute; + /** * @author Ewout Prangsma (ep...@us...) */ Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/FileRecord.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/FileRecord.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/FileRecord.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -25,6 +25,11 @@ import java.util.Iterator; import java.util.List; +import org.jnode.fs.ntfs.attribute.AttributeListAttribute; +import org.jnode.fs.ntfs.attribute.AttributeListEntry; +import org.jnode.fs.ntfs.attribute.NTFSAttribute; +import org.jnode.fs.ntfs.attribute.NTFSNonResidentAttribute; +import org.jnode.fs.ntfs.attribute.NTFSResidentAttribute; import org.jnode.util.NumberUtils; /** Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSAttribute.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSAttribute.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -1,200 +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 org.jnode.fs.ntfs.index.IndexAllocationAttribute; -import org.jnode.fs.ntfs.index.IndexRootAttribute; - -/** - * @author Chira - * @author Ewout Prangsma (ep...@us...) - */ -public abstract class NTFSAttribute extends NTFSStructure { - - public static final class Types { - - public static final int STANDARD_INFORMATION = 0x10; - - public static final int ATTRIBUTE_LIST = 0x20; - - public static final int FILE_NAME = 0x30; - - public static final int VOLUME_VERSION = 0x40; - - public static final int OBJECT_ID = 0x40; - - public static final int SECURITY_DESCRIPTOR = 0x50; - - public static final int VOLUME_NAME = 0x60; - - public static final int VOLUME_INFORMATION = 0x70; - - public static final int DATA = 0x80; - - public static final int INDEX_ROOT = 0x90; - - public static final int INDEX_ALLOCATION = 0xA0; - - public static final int BITMAP = 0xB0; - - public static final int SYMBOLIC_LINK = 0xC0; - - public static final int REPARSE_POINT = 0xC0; - - public static final int EA_INFORMATION = 0xD0; - - public static final int EA = 0xE0; - - public static final int PROPERTY_SET = 0xF0; - - public static final int LOGGED_UTILITY_STREAM = 0x100; - } - - private final int type; - - private final int flags; - - private final FileRecord fileRecord; - - /** - * Initialize this instance. - */ - public NTFSAttribute(FileRecord fileRecord, int offset) { - super(fileRecord, offset); - this.fileRecord = fileRecord; - this.type = getUInt32AsInt(0); - this.flags = getUInt16(0x0C); - } - - /** - * @return Returns the attributeType. - */ - public int getAttributeType() { - return type; - } - - /* - * Flag |Description ------------------- 0x0001 |Compressed 0x4000 - * |Encrypted 0x8000 |Sparse - */ - public int getFlags() { - return flags; - } - - /** - * @return Returns the nameLength. - */ - public int getNameLength() { - return getUInt8(0x09); - } - - /** - * @return Returns the nameOffset. - */ - public int getNameOffset() { - return getUInt16(0x0A); - } - - /** - * @return Returns the attributeID. - */ - public int getAttributeID() { - return getUInt16(0x0E); - } - - /** - * @return Returns the attributeName. - */ - public String getAttributeName() { - // if it is named fill the attribute name - final int nameLength = getNameLength(); - if (nameLength > 0) { - final char[] namebuf = new char[nameLength]; - final int nameOffset = getNameOffset(); - for (int i = 0; i < nameLength; i++) { - namebuf[i] = getChar16(nameOffset + (i * 2)); - } - return new String(namebuf); - } - return null; - } - - /** - * @return Returns the fileRecord. - */ - public FileRecord getFileRecord() { - return this.fileRecord; - } - - /** - * @return Returns the resident. - */ - public boolean isResident() { - return (getUInt8(0x08) == 0); - } - - /** - * Gets the length of this attribute in bytes. - * - * @return the length - */ - public int getSize() { - return getUInt32AsInt(4); - } - - /** - * Create an NTFSAttribute instance suitable for the given attribute data. - * - * @param fileRecord - * @param offset - * @return the attribute - */ - public static NTFSAttribute getAttribute(FileRecord fileRecord, int offset) { - final boolean resident = (fileRecord.getUInt8(offset + 0x08) == 0); - final int type = fileRecord.getUInt32AsInt(offset + 0x00); - - switch (type) { - case Types.STANDARD_INFORMATION: - return new StandardInformationAttribute(fileRecord, offset); - case Types.ATTRIBUTE_LIST: - if (resident) { - return new AttributeListAttributeRes(fileRecord, offset); - } else { - return new AttributeListAttributeNonRes(fileRecord, offset); - } - case Types.FILE_NAME: - return new FileNameAttribute(fileRecord, offset); - case Types.INDEX_ROOT: - return new IndexRootAttribute(fileRecord, offset); - case Types.INDEX_ALLOCATION: - return new IndexAllocationAttribute(fileRecord, offset); - } - - // check the resident flag - if (resident) { - // resident - return new NTFSResidentAttribute(fileRecord, offset); - } else { - // non resident - return new NTFSNonResidentAttribute(fileRecord, offset); - } - } -} Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFile.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFile.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFile.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -26,6 +26,9 @@ import org.jnode.fs.FSFile; import org.jnode.fs.FSFileSlackSpace; import org.jnode.fs.FileSystem; +import org.jnode.fs.ntfs.attribute.NTFSAttribute; +import org.jnode.fs.ntfs.attribute.NTFSNonResidentAttribute; +import org.jnode.fs.ntfs.attribute.NTFSResidentAttribute; 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-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSFileSystem.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -28,6 +28,8 @@ import org.jnode.fs.FSEntry; import org.jnode.fs.FSFile; import org.jnode.fs.FileSystemException; +import org.jnode.fs.ntfs.attribute.NTFSAttribute; +import org.jnode.fs.ntfs.attribute.NTFSResidentAttribute; import org.jnode.fs.spi.AbstractFileSystem; /** Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSNonResidentAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSNonResidentAttribute.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSNonResidentAttribute.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -1,220 +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.ArrayList; -import java.util.List; - -/** - * An NTFS file attribute that has its data stored outside the attribute. The attribute itself contains a runlist - * refering to the actual data. - * @author Chira - * @author Ewout Prangsma (ep...@us...) - * @author Daniel Noll (da...@no...) (compression support) - */ -public class NTFSNonResidentAttribute extends NTFSAttribute { - - private int numberOfVCNs = 0; - - private final List<DataRunInterface> dataRuns = new ArrayList<DataRunInterface>(); - - /** - * @param fileRecord - * @param offset - */ - public NTFSNonResidentAttribute(FileRecord fileRecord, int offset) { - super(fileRecord, offset); - /* - * process the dataruns...all non resident attributes have their data outside. can find where using data runs - */ - final int dataRunsOffset = getDataRunsOffset(); - if (dataRunsOffset > 0) { - readDataRuns(dataRunsOffset); - } - } - - /** - * @see org.jnode.fs.ntfs.NTFSAttribute#processAttributeData(byte[]) - */ - /* - * public void processAttributeData(byte[] buffer) { // TODO Auto-generated method stub } - */ - - /** - * @return Returns the startVCN. - */ - public long getStartVCN() { - return getUInt32(0x10); - } - - public long getLastVCN() { - return getUInt32(0x18); - } - - /** - * @return Returns the dataRunsOffset. - */ - public int getDataRunsOffset() { - return getUInt16(0x20); - } - - /** - * Gets the compression unit size. 2 to the power of this value is the number of clusters per compression unit. - * @return the compression unit size. - */ - public int getCompressionUnitSize() { - return getUInt16(0x22); - } - - /** - * Gets the size allocated to the attribute. May be larger than the actual size of the attribute data. - * @return the size allocated to the attribute. - */ - public long getAttributeAllocatedSize() { - return getUInt32(0x28); - } - - /** - * Gets the actual size taken up by the attribute data. - * @return the actual size taken up by the attribute data. - */ - public long getAttributeActualSize() { - return getUInt32(0x30); - } - - /** - * Read the dataruns. It is called only for non resident attributes. - */ - private void readDataRuns(int parentoffset) { - int offset = parentoffset; - - long previousLCN = 0; - final List<DataRunInterface> dataruns = getDataRuns(); - long vcn = 0; - - // If this attribute is compressed we will coalesce compressed/sparse - // data run pairs into a single data run object for convenience when reading. - boolean compressed = (getFlags() & 0x0001) != 0; - boolean expectingSparseRunNext = false; - int compUnitSize = 1 << getCompressionUnitSize(); - - while (getUInt8(offset) != 0x0) { - final DataRun dataRun = new DataRun(this, offset, vcn, previousLCN); - - if (compressed) { - if (dataRun.isSparse() && expectingSparseRunNext) { - // This is the sparse run which follows a compressed run. - // The number of runs it contains does not count towards the total - // as the compressed run reports holding all the runs for the pair. - // But we do need to move the offsets. Leaving this block open in case - // later it makes sense to put some logic in here. - } else if (dataRun.getLength() == compUnitSize) { - // Compressed/sparse pairs always add to the compression unit size. If - // the unit only compresses to 16, the system will store it uncompressed. - // So this whole unit is stored as-is, we'll leave it as a normal data run. - dataruns.add(dataRun); - this.numberOfVCNs += dataRun.getLength(); - vcn += dataRun.getLength(); - previousLCN = dataRun.getCluster(); - } else { - // TODO: Is it possible for the length to be GREATER than the unit size? - dataruns.add(new CompressedDataRun(dataRun, compUnitSize)); - if (dataRun.getLength() != compUnitSize) { - expectingSparseRunNext = true; - } - - this.numberOfVCNs += compUnitSize; - vcn += compUnitSize; - previousLCN = dataRun.getCluster(); - } - } else { - // map VCN-> datarun - dataruns.add(dataRun); - this.numberOfVCNs += dataRun.getLength(); - vcn += dataRun.getLength(); - previousLCN = dataRun.getCluster(); - } - - offset += dataRun.getSize(); - } - - // check the dataruns - final int clusterSize = getFileRecord().getVolume().getClusterSize(); - // Rounds up but won't work for 0, which shouldn't occur here. - final long allocatedVCNs = (getAttributeAllocatedSize() - 1) / clusterSize + 1; - if (this.numberOfVCNs != allocatedVCNs) { - // Probably not a problem, often multiple attributes make up one allocation. - log.debug("VCN mismatch between data runs and allocated size, possibly a composite attribute. " - + "data run VCNs = " + this.numberOfVCNs + ", allocated size = " + allocatedVCNs - + ", data run count = " + dataRuns.size()); - } - } - - /** - * @return Returns the data runs. - */ - public List<DataRunInterface> getDataRuns() { - return dataRuns; - } - - /** - * Read a number of clusters starting from a given virtual cluster number (vcn). - * @param vcn - * @param nrClusters - * @return The number of clusters read. - * @throws IOException - */ - public int readVCN(long vcn, byte[] dst, int dstOffset, int nrClusters) throws IOException { - final int flags = getFlags(); - if ((flags & 0x4000) != 0) { - throw new IOException("Reading encrypted files is not supported"); - } - - if (log.isDebugEnabled()) { - log.debug("readVCN: wants start " + vcn + " length " + nrClusters + ", we have start " + getStartVCN() - + " length " + getNumberOfVCNs()); - } - - final NTFSVolume volume = getFileRecord().getVolume(); - final int clusterSize = volume.getClusterSize(); - int readClusters = 0; - for(DataRunInterface dataRun : this.getDataRuns()) { - readClusters += dataRun.readClusters(vcn, dst, dstOffset, nrClusters, clusterSize, volume); - if (readClusters == nrClusters) { - break; - } - } - - if (log.isDebugEnabled()) { - log.debug("readVCN: read " + readClusters); - } - - return readClusters; - } - - /** - * @return Returns the numberOfVNCs. - */ - public int getNumberOfVCNs() { - return numberOfVCNs; - } -} Deleted: trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSResidentAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSResidentAttribute.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/NTFSResidentAttribute.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -1,58 +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; - -/** - * An NTFS file attribute that has its data stored inside the attribute. - * - * @author Chira - * @author Ewout Prangsma (ep...@us...) - */ -public class NTFSResidentAttribute extends NTFSAttribute { - - /** - * @param fileRecord - * @param offset - */ - public NTFSResidentAttribute(FileRecord fileRecord, int offset) { - super(fileRecord, offset); - } - - /** - * Gets the offset to the actual attribute. - * - * @return Returns the attributeOffset. - */ - public int getAttributeOffset() { - return getUInt16(0x14); - } - - /** - * @return Returns the indexedFlag. - */ - public int getIndexedFlag() { - return getUInt8(0x16); - } - - public int getAttributeLength() { - return (int) getUInt32(0x10); - } -} Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/StandardInformationAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/StandardInformationAttribute.java 2013-02-20 08:01:21 UTC (rev 5963) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/StandardInformationAttribute.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -20,6 +20,8 @@ package org.jnode.fs.ntfs; +import org.jnode.fs.ntfs.attribute.NTFSResidentAttribute; + /** * @author Daniel Noll (da...@no...) */ Added: trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttribute.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttribute.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -0,0 +1,42 @@ +/* + * $Id: header.txt 5714 2010-01-03 13:33:07Z lsantha $ + * + * 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.attribute; + +import java.io.IOException; +import java.util.Iterator; + +/** + * Common interface for both resident and non-resident attribute list + * attributes. + * + * @author Daniel Noll (da...@no...) + */ +public interface AttributeListAttribute { + + /** + * Gets an iterator over all the entries in the attribute list. + * + * @return an iterator of all attribute list entries. + * @throws IOException if there is an error reading the attribute's data. + */ + Iterator<AttributeListEntry> getAllEntries() throws IOException; + +} Added: trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttributeNonRes.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttributeNonRes.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttributeNonRes.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -0,0 +1,61 @@ +/* + * $Id: header.txt 5714 2010-01-03 13:33:07Z lsantha $ + * + * 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.attribute; + +import java.io.IOException; +import java.util.Iterator; +import org.jnode.fs.ntfs.FileRecord; + +/** + * $ATTRIBUTE_LIST attribute, non-resident version. + * + * XXX: Is there a sensible way we can merge this with the resident version? + * + * @author Daniel Noll (da...@no...) + */ +final class AttributeListAttributeNonRes extends NTFSNonResidentAttribute implements + AttributeListAttribute { + + /** + * @param fileRecord + * @param offset + */ + public AttributeListAttributeNonRes(FileRecord fileRecord, int offset) { + super(fileRecord, offset); + } + + /** + * Gets an iterator over all the entries in the attribute list. + * + * @return an iterator of all attribute list entries. + * @throws IOException if there is an error reading the attribute's data. + */ + public Iterator<AttributeListEntry> getAllEntries() throws IOException { + // Read the actual data from wherever it happens to be located. + // TODO: Consider handling multiple data runs separately instead + // of "glueing" them all together like this. + final int nrClusters = getNumberOfVCNs(); + final byte[] data = new byte[nrClusters * getFileRecord().getVolume().getClusterSize()]; + readVCN(getStartVCN(), data, 0, nrClusters); + AttributeListBlock listBlock = new AttributeListBlock(data, 0, getAttributeActualSize()); + return listBlock.getAllEntries(); + } +} Added: trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttributeRes.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttributeRes.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListAttributeRes.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -0,0 +1,58 @@ +/* + * $Id: header.txt 5714 2010-01-03 13:33:07Z lsantha $ + * + * 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.attribute; + +import java.io.IOException; +import java.util.Iterator; +import org.jnode.fs.ntfs.FileRecord; + +/** + * $ATTRIBUTE_LIST attribute, resident version. + * + * XXX: Is there a sensible way we can merge this with the non-resident version? + * + * @author Daniel Noll (da...@no...) + */ +final class AttributeListAttributeRes extends NTFSResidentAttribute implements + AttributeListAttribute { + + /** + * @param fileRecord + * @param offset + */ + public AttributeListAttributeRes(FileRecord fileRecord, int offset) { + super(fileRecord, offset); + } + + /** + * Gets an iterator over all the entries in the attribute list. + * + * @return an iterator of all attribute list entries. + * @throws IOException if there is an error reading the attribute's data. + */ + public Iterator<AttributeListEntry> getAllEntries() throws IOException { + final byte[] data = new byte[getAttributeLength()]; + getData(getAttributeOffset(), data, 0, data.length); + AttributeListBlock listBlock = new AttributeListBlock(data, 0, getAttributeLength()); + return listBlock.getAllEntries(); + } + +} Added: trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListBlock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListBlock.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListBlock.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -0,0 +1,117 @@ +/* + * $Id: header.txt 5714 2010-01-03 13:33:07Z lsantha $ + * + * 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.attribute; + +import java.util.Iterator; +import java.util.NoSuchElementException; +import org.jnode.fs.ntfs.NTFSStructure; + +/** + * Data structure containing a list of {@link AttributeListEntry} entries. + * + * @author Daniel Noll (da...@no...) + */ +final class AttributeListBlock extends NTFSStructure { + + /** + * The length of the block. + */ + private long length; + + /** + * @param data binary data for the block. + * @param offset the offset into the binary data. + * @param length the length of the attribute list block, or 0 if unknown. + */ + public AttributeListBlock(byte[] data, int offset, long length) { + super(data, offset); + this.length = length; + } + + /** + * Gets an iterator over all the entries in the attribute list. + * + * @return an iterator of all attribute list entries. + */ + public Iterator<AttributeListEntry> getAllEntries() { + return new AttributeListEntryIterator(); + } + + /** + * Iteration of attribute list entries. + */ + private class AttributeListEntryIterator implements Iterator<AttributeListEntry> { + + /** + * The next element to return. + */ + private AttributeListEntry nextElement; + + /** + * Current offset being looked at. + */ + private int offset = 0; + + /** + * Returns {@code true} if there are more elements in the iteration. + * + * @return {@code true} if there are more elements in the iteration. + */ + public boolean hasNext() { + // Safety check in case hasNext is called twice without calling next. + if (nextElement != null) { + return true; + } + + // If the length is specified, use it to determine where the block ends. + if (offset + 4 > length) { + return false; + } + + int length = getUInt16(offset + 0x04); + nextElement = new AttributeListEntry(AttributeListBlock.this, offset); + offset += length; + return true; + } + + /** + * Gets the next entry from the iteration. + * + * @return the next entry from the iteration. + */ + public AttributeListEntry next() { + if (hasNext()) { + AttributeListEntry result = nextElement; + nextElement = null; + return result; + } else { + throw new NoSuchElementException("Iterator has no more entries"); + } + } + + /** + * @throws UnsupportedOperationException always. + */ + public void remove() { + throw new UnsupportedOperationException(); + } + } +} Added: trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListEntry.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/AttributeListEntry.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -0,0 +1,146 @@ +/* + * $Id: header.txt 5714 2010-01-03 13:33:07Z lsantha $ + * + * 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.attribute; + + +import org.jnode.fs.ntfs.NTFSStructure; + +/** + * @author Daniel Noll (da...@no...) + */ +public final class AttributeListEntry extends NTFSStructure { + + /** + * Creates the entry. + * + * @param block the containing attribute list block. + * @param offset the offset of this attribute within the block. + */ + public AttributeListEntry(AttributeListBlock block, int offset) { + super(block, offset); + } + + /** + * Gets the type of the attribute. + * + * @return the type of the attribute. + */ + public int getType() { + return getUInt32AsInt(0x00); + } + + /** + * Gets the size of the attribute, in bytes. + * + * @return the size of the attribute, in bytes. + */ + public int getSize() { + return getUInt16(0x04); + } + + /** + * Gets the length of the name. Not so useful for callers, hence private. + * @return the name length. + */ + private int getNameLength() { + return getUInt8(0x06); + } + + /** + * Gets the offset of the name. Not so useful for callers, hence private. + * @return the name offset (from the front of the entry.) + */ + private int getNameOffset() { + return getUInt8(0x07); + } + + /** + * Gets the starting VCN of the attribute, zero if the attribute is resident. + * @return the starting VCN. + */ + public int getStartingVCN() { + return getUInt16(0x08); + } + + /** + * Gets the file reference number, which is the lowest 48 bits of the MFT + * reference. This may point to the same file record which contains the + * attribute list. + * + * @return the file reference number. + */ + public long getFileReferenceNumber() { + return getUInt48(0x10); + } + + /** + * Gets the file sequence number, which is the highest 16 bits of the MFT + * reference. + * + * @return the file sequence number. + */ + public long getFileSequenceNumber() { + return getUInt16(0x16); + } + + /** + * Gets the ID of the attribute. This ID is unique within all attributes. + * @return the attribute ID. + */ + public int getAttributeID() { + return getUInt16(0x18); + } + + /** + * Gets the name of the attribute. Some attributes don't have names, and the names + * on attributes are supposedly unique within a given attribute type. + * + * @return the name of the attribute referenced by this entry. Returns the empty string + * if the attribute has no name. + */ + public String getName() { + final int nameLength = getNameLength(); + if (nameLength == 0) { + return ""; + } else { + char[] name = new char[nameLength]; + for (int i = 0, off = getNameOffset(); i < nameLength; i++, off += 2) { + name[i] = getChar16(off); + } + return new String(name); + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(super.toString()); + builder.append("[type=").append(getType()); + builder.append(",name=").append(getName()); + if (getStartingVCN() == 0) { + builder.append(",resident"); + } else { + builder.append(",ref=").append(getFileReferenceNumber()); + builder.append(",vcn=").append(getStartingVCN()); + } + builder.append(",id=").append(getAttributeID()).append("]"); + return builder.toString(); + } +} Added: trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/NTFSAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/NTFSAttribute.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/NTFSAttribute.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -0,0 +1,204 @@ +/* + * $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.attribute; + +import org.jnode.fs.ntfs.FileNameAttribute; +import org.jnode.fs.ntfs.FileRecord; +import org.jnode.fs.ntfs.NTFSStructure; +import org.jnode.fs.ntfs.StandardInformationAttribute; +import org.jnode.fs.ntfs.index.IndexAllocationAttribute; +import org.jnode.fs.ntfs.index.IndexRootAttribute; + +/** + * @author Chira + * @author Ewout Prangsma (ep...@us...) + */ +public abstract class NTFSAttribute extends NTFSStructure { + + public static final class Types { + + public static final int STANDARD_INFORMATION = 0x10; + + public static final int ATTRIBUTE_LIST = 0x20; + + public static final int FILE_NAME = 0x30; + + public static final int VOLUME_VERSION = 0x40; + + public static final int OBJECT_ID = 0x40; + + public static final int SECURITY_DESCRIPTOR = 0x50; + + public static final int VOLUME_NAME = 0x60; + + public static final int VOLUME_INFORMATION = 0x70; + + public static final int DATA = 0x80; + + public static final int INDEX_ROOT = 0x90; + + public static final int INDEX_ALLOCATION = 0xA0; + + public static final int BITMAP = 0xB0; + + public static final int SYMBOLIC_LINK = 0xC0; + + public static final int REPARSE_POINT = 0xC0; + + public static final int EA_INFORMATION = 0xD0; + + public static final int EA = 0xE0; + + public static final int PROPERTY_SET = 0xF0; + + public static final int LOGGED_UTILITY_STREAM = 0x100; + } + + private final int type; + + private final int flags; + + private final FileRecord fileRecord; + + /** + * Initialize this instance. + */ + public NTFSAttribute(FileRecord fileRecord, int offset) { + super(fileRecord, offset); + this.fileRecord = fileRecord; + this.type = getUInt32AsInt(0); + this.flags = getUInt16(0x0C); + } + + /** + * @return Returns the attributeType. + */ + public int getAttributeType() { + return type; + } + + /* + * Flag |Description ------------------- 0x0001 |Compressed 0x4000 + * |Encrypted 0x8000 |Sparse + */ + public int getFlags() { + return flags; + } + + /** + * @return Returns the nameLength. + */ + public int getNameLength() { + return getUInt8(0x09); + } + + /** + * @return Returns the nameOffset. + */ + public int getNameOffset() { + return getUInt16(0x0A); + } + + /** + * @return Returns the attributeID. + */ + public int getAttributeID() { + return getUInt16(0x0E); + } + + /** + * @return Returns the attributeName. + */ + public String getAttributeName() { + // if it is named fill the attribute name + final int nameLength = getNameLength(); + if (nameLength > 0) { + final char[] namebuf = new char[nameLength]; + final int nameOffset = getNameOffset(); + for (int i = 0; i < nameLength; i++) { + namebuf[i] = getChar16(nameOffset + (i * 2)); + } + return new String(namebuf); + } + return null; + } + + /** + * @return Returns the fileRecord. + */ + public FileRecord getFileRecord() { + return this.fileRecord; + } + + /** + * @return Returns the resident. + */ + public boolean isResident() { + return (getUInt8(0x08) == 0); + } + + /** + * Gets the length of this attribute in bytes. + * + * @return the length + */ + public int getSize() { + return getUInt32AsInt(4); + } + + /** + * Create an NTFSAttribute instance suitable for the given attribute data. + * + * @param fileRecord + * @param offset + * @return the attribute + */ + public static NTFSAttribute getAttribute(FileRecord fileRecord, int offset) { + final boolean resident = (fileRecord.getUInt8(offset + 0x08) == 0); + final int type = fileRecord.getUInt32AsInt(offset + 0x00); + + switch (type) { + case Types.STANDARD_INFORMATION: + return new StandardInformationAttribute(fileRecord, offset); + case Types.ATTRIBUTE_LIST: + if (resident) { + return new AttributeListAttributeRes(fileRecord, offset); + } else { + return new AttributeListAttributeNonRes(fileRecord, offset); + } + case Types.FILE_NAME: + return new FileNameAttribute(fileRecord, offset); + case Types.INDEX_ROOT: + return new IndexRootAttribute(fileRecord, offset); + case Types.INDEX_ALLOCATION: + return new IndexAllocationAttribute(fileRecord, offset); + } + + // check the resident flag + if (resident) { + // resident + return new NTFSResidentAttribute(fileRecord, offset); + } else { + // non resident + return new NTFSNonResidentAttribute(fileRecord, offset); + } + } +} Added: trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/NTFSNonResidentAttribute.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/NTFSNonResidentAttribute.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/ntfs/attribute/NTFSNonResidentAttribute.java 2013-02-20 08:18:08 UTC (rev 5964) @@ -0,0 +1,235 @@ +/* + * $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 ... [truncated message content] |