From: <ga...@us...> - 2009-03-19 14:10:52
|
Revision: 5117 http://jnode.svn.sourceforge.net/jnode/?rev=5117&view=rev Author: galatnm Date: 2009-03-19 14:10:46 +0000 (Thu, 19 Mar 2009) Log Message: ----------- Rewrite and javadocs. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusEntry.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/Extent.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/BTHeaderRecord.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexRecord.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/NodeDescriptor.java Removed Paths: ------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusConstants.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -30,6 +30,7 @@ import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; import org.jnode.fs.ReadOnlyFileSystemException; +import org.jnode.fs.hfsplus.catalog.CatalogFile; import org.jnode.fs.hfsplus.catalog.CatalogFolder; import org.jnode.fs.hfsplus.catalog.CatalogKey; import org.jnode.fs.hfsplus.catalog.CatalogNodeId; @@ -184,8 +185,8 @@ if (fs.getVolumeHeader().getFolderCount() > 0) { LeafRecord[] records = fs.getCatalog().getRecords(folder.getFolderId()); for (LeafRecord rec : records) { - if (rec.getType() == HfsPlusConstants.RECORD_TYPE_FOLDER || - rec.getType() == HfsPlusConstants.RECORD_TYPE_FILE) { + if (rec.getType() == CatalogFolder.RECORD_TYPE_FOLDER || + rec.getType() == CatalogFile.RECORD_TYPE_FILE) { String name = ((CatalogKey) rec.getKey()).getNodeName().getUnicodeString(); HFSPlusEntry e = new HFSPlusEntry(fs, this, name, rec); pathList.add(e); @@ -213,10 +214,9 @@ Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); HFSUnicodeString dirName = new HFSUnicodeString(name); CatalogThread thread = - new CatalogThread(HfsPlusConstants.RECORD_TYPE_FOLDER_THREAD, this.folder + new CatalogThread(CatalogFolder.RECORD_TYPE_FOLDER_THREAD, this.folder .getFolderId(), dirName); - CatalogFolder newFolder = - new CatalogFolder(0, new CatalogNodeId(volumeHeader.getNextCatalogId())); + CatalogFolder newFolder = new CatalogFolder(0, new CatalogNodeId(volumeHeader.getNextCatalogId())); log.debug("New catalog folder :\n" + newFolder.toString()); CatalogKey key = new CatalogKey(this.folder.getFolderId(), dirName); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusEntry.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusEntry.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -27,6 +27,8 @@ import org.jnode.fs.FSEntry; import org.jnode.fs.FSFile; import org.jnode.fs.FileSystem; +import org.jnode.fs.hfsplus.catalog.CatalogFile; +import org.jnode.fs.hfsplus.catalog.CatalogFolder; import org.jnode.fs.hfsplus.tree.LeafRecord; import org.jnode.fs.spi.AbstractFSEntry; import org.jnode.fs.spi.UnixFSAccessRights; @@ -66,9 +68,9 @@ int mode = record.getType(); if ("/".equals(name)) { return AbstractFSEntry.ROOT_ENTRY; - } else if (mode == HfsPlusConstants.RECORD_TYPE_FOLDER) { + } else if (mode == CatalogFolder.RECORD_TYPE_FOLDER) { return AbstractFSEntry.DIR_ENTRY; - } else if (mode == HfsPlusConstants.RECORD_TYPE_FILE) { + } else if (mode == CatalogFile.RECORD_TYPE_FILE) { return AbstractFSEntry.FILE_ENTRY; } else { return AbstractFSEntry.OTHER_ENTRY; Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusConstants.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusConstants.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusConstants.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -1,57 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2003-2009 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.hfsplus; - -public class HfsPlusConstants { - public static final int HFSPLUS_SUPER_MAGIC = 0x482b; - - public static final int HFSPLUS_MIN_VERSION = 0x0004; /* HFS+ */ - public static final int HFSPLUS_CURRENT_VERSION = 5; /* HFSX */ - - /* HFS+ volume attributes */ - public static final int HFSPLUS_VOL_UNMNT_BIT = 8; - public static final int HFSPLUS_VOL_SPARE_BLK_BIT = 9; - public static final int HFSPLUS_VOL_NOCACHE_BIT = 10; - public static final int HFSPLUS_VOL_INCNSTNT_BIT = 11; - public static final int HFSPLUS_VOL_NODEID_REUSED_BIT = 12; - public static final int HFSPLUS_VOL_JOURNALED_BIT = 13; - public static final int HFSPLUS_VOL_SOFTLOCK_BIT = 15; - - public static final int BT_LEAF_NODE = -1; - public static final int BT_INDEX_NODE = 0; - public static final int BT_HEADER_NODE = 1; - public static final int BT_MAP_NODE = 2; - - /* Types */ - public static final int RECORD_TYPE_FOLDER = 0x0001; - public static final int RECORD_TYPE_FILE = 0x0002; - public static final int RECORD_TYPE_FOLDER_THREAD = 0x0003; - public static final int RECORD_TYPE_FILE_THREAD = 0x0004; - - public static final byte EK_DATA_FORK = (byte) 0x00; - public static final byte EK_RESOURCE_FORK = (byte) 0xFF; - - public static final int BYTES_PER_SECTOR = 512; - public static final int BITS_PER_SECTOR = 4096; - - - -} Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -63,18 +63,18 @@ public final void read() throws FileSystemException { sb = new Superblock(this, false); - if (!sb.isAttribute(HfsPlusConstants.HFSPLUS_VOL_UNMNT_BIT)) { + if (!sb.isAttribute(Superblock.HFSPLUS_VOL_UNMNT_BIT)) { log .info(getDevice().getId() + " Filesystem has not been cleanly unmounted, mounting it readonly"); setReadOnly(true); } - if (sb.isAttribute(HfsPlusConstants.HFSPLUS_VOL_SOFTLOCK_BIT)) { + if (sb.isAttribute(Superblock.HFSPLUS_VOL_SOFTLOCK_BIT)) { log.info(getDevice().getId() + " Filesystem is marked locked, mounting it readonly"); setReadOnly(true); } - if (sb.isAttribute(HfsPlusConstants.HFSPLUS_VOL_JOURNALED_BIT)) { + if (sb.isAttribute(Superblock.HFSPLUS_VOL_JOURNALED_BIT)) { log .info(getDevice().getId() + " Filesystem is journaled, write access is not supported. Mounting it readonly"); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -62,7 +62,7 @@ return false; } int magicNumber = BigEndian.getInt16(magic.array(), 0); - return (magicNumber == HfsPlusConstants.HFSPLUS_SUPER_MAGIC); + return (magicNumber == Superblock.HFSPLUS_SUPER_MAGIC); } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -20,11 +20,6 @@ package org.jnode.fs.hfsplus; -import static org.jnode.fs.hfsplus.HfsPlusConstants.HFSPLUS_SUPER_MAGIC; -import static org.jnode.fs.hfsplus.HfsPlusConstants.HFSPLUS_VOL_INCNSTNT_BIT; -import static org.jnode.fs.hfsplus.HfsPlusConstants.HFSPLUS_VOL_JOURNALED_BIT; -import static org.jnode.fs.hfsplus.HfsPlusConstants.HFSPLUS_VOL_UNMNT_BIT; - import java.io.IOException; import java.nio.ByteBuffer; import java.util.Calendar; @@ -46,6 +41,21 @@ * */ public class Superblock extends HFSPlusObject { + + public static final int HFSPLUS_SUPER_MAGIC = 0x482b; + + public static final int HFSPLUS_MIN_VERSION = 0x0004; /* HFS+ */ + public static final int HFSPLUS_CURRENT_VERSION = 5; /* HFSX */ + + /* HFS+ volume attributes */ + public static final int HFSPLUS_VOL_UNMNT_BIT = 8; + public static final int HFSPLUS_VOL_SPARE_BLK_BIT = 9; + public static final int HFSPLUS_VOL_NOCACHE_BIT = 10; + public static final int HFSPLUS_VOL_INCNSTNT_BIT = 11; + public static final int HFSPLUS_VOL_NODEID_REUSED_BIT = 12; + public static final int HFSPLUS_VOL_JOURNALED_BIT = 13; + public static final int HFSPLUS_VOL_SOFTLOCK_BIT = 15; + private final Logger log = Logger.getLogger(getClass()); /** Volume header data length */ @@ -109,8 +119,8 @@ } // Populate volume header. - this.setMagic(HfsPlusConstants.HFSPLUS_SUPER_MAGIC); - this.setVersion(HfsPlusConstants.HFSPLUS_MIN_VERSION); + this.setMagic(HFSPLUS_SUPER_MAGIC); + this.setVersion(HFSPLUS_MIN_VERSION); // Set attributes. this.setAttribute(HFSPLUS_VOL_UNMNT_BIT); this.setLastMountedVersion(0x446534a); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -28,7 +28,6 @@ import org.apache.log4j.Logger; import org.jnode.fs.hfsplus.HFSPlusParams; import org.jnode.fs.hfsplus.HFSUnicodeString; -import org.jnode.fs.hfsplus.HfsPlusConstants; import org.jnode.fs.hfsplus.HfsPlusFileSystem; import org.jnode.fs.hfsplus.Superblock; import org.jnode.fs.hfsplus.extent.ExtentDescriptor; @@ -69,13 +68,13 @@ catalogHeaderNodeOffset = firstExtent.getStartBlock() * sb.getBlockSize(); if (firstExtent.getStartBlock() != 0 && firstExtent.getBlockCount() != 0) { buffer = - ByteBuffer.allocate(NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH + + ByteBuffer.allocate(NodeDescriptor.BT_HEADER_NODE + BTHeaderRecord.BT_HEADER_RECORD_LENGTH); fs.getApi().read(catalogHeaderNodeOffset, buffer); buffer.rewind(); byte[] data = ByteBufferUtils.toArray(buffer); btnd = new NodeDescriptor(data, 0); - bthr = new BTHeaderRecord(data, NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); + bthr = new BTHeaderRecord(data, BTHeaderRecord.BT_HEADER_RECORD_LENGTH); } } @@ -91,11 +90,8 @@ int nodeSize = params.getCatalogNodeSize(); int bufferLength = 0; - btnd = new NodeDescriptor(); - btnd.setKind(HfsPlusConstants.BT_HEADER_NODE); - btnd.setHeight(0); - btnd.setRecordCount(3); - bufferLength += NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH; + btnd = new NodeDescriptor(0, 0, NodeDescriptor.BT_HEADER_NODE, 0, 3); + bufferLength += NodeDescriptor.BT_HEADER_NODE; // int leafRecords = params.isJournaled() ? 6 : 2; int totalNodes = params.getCatalogClumpSize() / params.getCatalogNodeSize(); @@ -109,12 +105,10 @@ int rootNodePosition = bthr.getRootNode() * nodeSize; bufferLength += (rootNodePosition - bufferLength); // Create node descriptor - NodeDescriptor nd = new NodeDescriptor(); - nd.setKind(HfsPlusConstants.BT_LEAF_NODE); - nd.setHeight(1); - nd.setRecordCount(params.isJournaled() ? 6 : 2); + int numRecords = params.isJournaled() ? 6 : 2; + NodeDescriptor nd = new NodeDescriptor(0, 0, NodeDescriptor.BT_LEAF_NODE, 1, numRecords); CatalogNode rootNode = new CatalogNode(nd, nodeSize); - int offset = NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH; + int offset = NodeDescriptor.BT_HEADER_NODE; // First record (folder) HFSUnicodeString name = new HFSUnicodeString(params.getVolumeName()); CatalogKey ck = new CatalogKey(CatalogNodeId.HFSPLUS_POR_CNID, name); @@ -126,7 +120,7 @@ offset = offset + ck.getKeyLength() + CatalogFolder.CATALOG_FOLDER_SIZE; CatalogKey tck = new CatalogKey(CatalogNodeId.HFSPLUS_ROOT_CNID, name); CatalogThread ct = - new CatalogThread(HfsPlusConstants.RECORD_TYPE_FOLDER_THREAD, + new CatalogThread(CatalogFolder.RECORD_TYPE_FOLDER_THREAD, CatalogNodeId.HFSPLUS_ROOT_CNID, new HFSUnicodeString("")); record = new LeafRecord(tck, ct.getBytes()); rootNode.addNodeRecord(1, record, offset); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -25,7 +25,6 @@ import org.jnode.fs.hfsplus.HFSPlusBSDInfo; import org.jnode.fs.hfsplus.HFSPlusForkData; import org.jnode.fs.hfsplus.HFSUtils; -import org.jnode.fs.hfsplus.HfsPlusConstants; import org.jnode.util.BigEndian; /** @@ -36,6 +35,9 @@ * */ public class CatalogFile { + + public static final int RECORD_TYPE_FILE = 0x0002; + public static final int RECORD_TYPE_FILE_THREAD = 0x0004; public static final int CATALOG_FILE_SIZE = 248; /** catalog record type, always RECORD_TYPE_FILE */ @@ -95,7 +97,7 @@ * @param resources */ public CatalogFile(int flags, CatalogNodeId fileId, HFSPlusForkData datas, HFSPlusForkData resources) { - this.recordType = HfsPlusConstants.RECORD_TYPE_FILE; + this.recordType = RECORD_TYPE_FILE; this.flags = flags; this.fileId = fileId; this.createDate = HFSUtils.getNow(); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -21,10 +21,12 @@ package org.jnode.fs.hfsplus.catalog; import org.jnode.fs.hfsplus.HFSUtils; -import org.jnode.fs.hfsplus.HfsPlusConstants; import org.jnode.util.BigEndian; public class CatalogFolder { + /* Types */ + public static final int RECORD_TYPE_FOLDER = 0x0001; + public static final int RECORD_TYPE_FOLDER_THREAD = 0x0003; public static final int CATALOG_FOLDER_SIZE = 88; @@ -56,7 +58,7 @@ * @param folderID */ public CatalogFolder(int valence, CatalogNodeId folderID) { - this.recordType = HfsPlusConstants.RECORD_TYPE_FOLDER; + this.recordType = RECORD_TYPE_FOLDER; this.valence = valence; this.folderId = folderID; this.createDate = HFSUtils.getNow(); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/Extent.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/Extent.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/Extent.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -21,7 +21,6 @@ package org.jnode.fs.hfsplus.extent; import org.jnode.fs.hfsplus.HFSPlusParams; -import org.jnode.fs.hfsplus.HfsPlusConstants; import org.jnode.fs.hfsplus.tree.BTHeaderRecord; import org.jnode.fs.hfsplus.tree.NodeDescriptor; @@ -30,10 +29,7 @@ private BTHeaderRecord bthr; public Extent(HFSPlusParams params) { - btnd = new NodeDescriptor(); - btnd.setKind(HfsPlusConstants.BT_HEADER_NODE); - btnd.setHeight(0); - btnd.setRecordCount(3); + btnd = new NodeDescriptor(0, 0, NodeDescriptor.BT_HEADER_NODE, 0, 3); // int totalNodes = params.getExtentClumpSize() / params.getExtentNodeSize(); int freeNodes = totalNodes - 1; Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -20,7 +20,6 @@ package org.jnode.fs.hfsplus.tree; -import org.jnode.fs.hfsplus.HfsPlusConstants; import org.jnode.util.BigEndian; public abstract class AbstractNode implements Node { @@ -34,11 +33,11 @@ } public boolean isIndexNode() { - return this.getNodeDescriptor().getKind() == HfsPlusConstants.BT_INDEX_NODE; + return this.getNodeDescriptor().getKind() == NodeDescriptor.BT_INDEX_NODE; } public boolean isLeafNode() { - return this.getNodeDescriptor().getKind() == HfsPlusConstants.BT_LEAF_NODE; + return this.getNodeDescriptor().getKind() == NodeDescriptor.BT_LEAF_NODE; } @Override Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/BTHeaderRecord.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/BTHeaderRecord.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/BTHeaderRecord.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -107,7 +107,7 @@ BigEndian.setInt32(data, 39, attributes); return data; } - + public final String toString() { return ("Root node: " + getRootNode() + "\n" + "First leaf: " + getFirstLeafNode() + "\n" + "Last leaf: " + getLastLeafNode() + "\n" + "node size: " + getNodeSize() + "\n"); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexRecord.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexRecord.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexRecord.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -23,6 +23,8 @@ import org.jnode.util.BigEndian; public class IndexRecord extends AbstractNodeRecord { + /** A node number that represent a child node of the index node. */ + private int index; /** * @@ -34,10 +36,11 @@ this.key = key; this.recordData = new byte[4]; System.arraycopy(nodeData, offset + key.getKeyLength(), recordData, 0, 4); + index = BigEndian.getInt32(recordData, 0); } public final int getIndex() { - return BigEndian.getInt32(recordData, 0); + return index; } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -24,24 +24,28 @@ public class LeafRecord extends AbstractNodeRecord { + private int type; + public LeafRecord(final Key key, final byte[] recordData) { this.key = key; this.recordData = new byte[recordData.length]; System.arraycopy(recordData, 0, this.recordData, 0, recordData.length); + type = BigEndian.getInt16(this.recordData, 0); } public LeafRecord(final Key key, final byte[] nodeData, final int offset, final int recordDataSize) { this.key = key; this.recordData = new byte[recordDataSize]; System.arraycopy(nodeData, offset + key.getKeyLength(), this.recordData, 0, recordDataSize); + type = BigEndian.getInt16(this.recordData, 0); } public final int getType() { - return BigEndian.getInt16(this.recordData, 0); + return type; } public final String toString() { - return "Type : " + getType() + "\nKey : " + getKey().toString() + "\n"; + return "Type : " + type + "\nKey : " + getKey().toString() + "\n"; } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/NodeDescriptor.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/NodeDescriptor.java 2009-03-18 22:53:16 UTC (rev 5116) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/NodeDescriptor.java 2009-03-19 14:10:46 UTC (rev 5117) @@ -17,70 +17,99 @@ * 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.hfsplus.tree; import org.jnode.util.BigEndian; public class NodeDescriptor { + public static final int BT_LEAF_NODE = -1; + public static final int BT_INDEX_NODE = 0; + public static final int BT_HEADER_NODE = 1; + public static final int BT_MAP_NODE = 2; + /** The size of the node descriptor. */ public static final int BT_NODE_DESCRIPTOR_LENGTH = 14; - private byte[] data; + /** The number of the next node. */ + private int fLink; + /** The number of the previous node. */ + private int bLink; + /** The type of the node. */ + private int kind; + /** The depth of this node in the B-Tree. */ + private int height; + /** The number of records in this node. */ + private int numRecords; - public NodeDescriptor() { - data = new byte[BT_NODE_DESCRIPTOR_LENGTH]; + /** + * Creates a new node descriptor. + * + * @param fLink + * @param bLink + * @param kind + * @param height + * @param numRecords + */ + public NodeDescriptor(int fLink, int bLink, int kind, int height, int numRecords) { + this.fLink = fLink; + this.bLink = bLink; + this.kind = kind; + this.height = height; + this.numRecords = numRecords; } + /** + * Creates node descriptor from existing data. + * + * @param src byte array contains node descriptor data. + * @param offset start of node descriptor data. + */ public NodeDescriptor(final byte[] src, int offset) { - data = new byte[BT_NODE_DESCRIPTOR_LENGTH]; + byte[] data = new byte[BT_NODE_DESCRIPTOR_LENGTH]; System.arraycopy(src, offset, data, 0, BT_NODE_DESCRIPTOR_LENGTH); + fLink = BigEndian.getInt32(data, 0); + bLink = BigEndian.getInt32(data, 4); + kind = BigEndian.getInt8(data, 8); + height = BigEndian.getInt8(data, 9); + numRecords = BigEndian.getInt16(data, 10); } - public final int getFLink() { - return BigEndian.getInt32(data, 0); + /** + * + * @return + */ + public byte[] getBytes() { + byte[] data = new byte[BT_NODE_DESCRIPTOR_LENGTH]; + BigEndian.setInt32(data, 0, fLink); + BigEndian.setInt32(data, 4, bLink); + BigEndian.setInt8(data, 8, kind); + BigEndian.setInt8(data, 9, height); + BigEndian.setInt16(data, 10, numRecords); + return data; } - - public void setFLink(int link) { - BigEndian.setInt32(data, 0, link); - } - public final int getBLink() { - return BigEndian.getInt32(data, 4); + public final String toString() { + return ("FLink: " + getFLink() + "\n" + "BLink: " + getBLink() + "\n" + "Kind: " + + getKind() + "\n" + "height: " + getHeight() + "\n" + "#rec: " + getNumRecords() + "\n"); } - - public void setBLink(int link) { - BigEndian.setInt32(data, 4, link); - } - public final int getKind() { - return BigEndian.getInt8(data, 8); + public int getFLink() { + return fLink; } - public void setKind(int kind) { - BigEndian.setInt8(data, 8, kind); + public int getBLink() { + return bLink; } - public final int getHeight() { - return BigEndian.getInt8(data, 9); + public int getKind() { + return kind; } - public void setHeight(int height) { - BigEndian.setInt8(data, 9, height); + public int getHeight() { + return height; } - public final int getNumRecords() { - return BigEndian.getInt16(data, 10); + public int getNumRecords() { + return numRecords; } - public void setRecordCount(int count) { - BigEndian.setInt16(data, 10, count); - } - - public byte[] getBytes() { - return data; - } - - public final String toString() { - return ("FLink: " + getFLink() + "\n" + "BLink: " + getBLink() + "\n" + "Kind: " + getKind() + "\n" - + "height: " + getHeight() + "\n" + "#rec: " + getNumRecords() + "\n"); - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |