From: <ga...@us...> - 2009-02-01 15:11:36
|
Revision: 4957 http://jnode.svn.sourceforge.net/jnode/?rev=4957&view=rev Author: galatnm Date: 2009-02-01 15:11:23 +0000 (Sun, 01 Feb 2009) Log Message: ----------- Filesystem creation done. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUnicodeString.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractKey.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNodeRecord.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexRecord.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-02-01 14:49:39 UTC (rev 4956) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-02-01 15:11:23 UTC (rev 4957) @@ -9,6 +9,7 @@ import org.apache.log4j.Logger; import org.jnode.fs.FSEntry; import org.jnode.fs.ReadOnlyFileSystemException; +import org.jnode.fs.hfsplus.catalog.Catalog; import org.jnode.fs.hfsplus.catalog.CatalogFolder; import org.jnode.fs.hfsplus.catalog.CatalogKey; import org.jnode.fs.hfsplus.catalog.CatalogNodeId; @@ -91,19 +92,21 @@ @Override protected final FSEntryTable readEntries() throws IOException { List<FSEntry> pathList = new LinkedList<FSEntry>(); - LeafRecord[] records = ((HfsPlusFileSystem) getFileSystem()) - .getCatalog().getRecords(folder.getFolderId()); - for (LeafRecord rec : records) { - if (rec.getType() == HfsPlusConstants.RECORD_TYPE_FOLDER - || rec.getType() == HfsPlusConstants.RECORD_TYPE_FILE) { - String name = ((CatalogKey) rec.getKey()).getNodeName() + HfsPlusFileSystem fs = (HfsPlusFileSystem)getFileSystem(); + 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) { + String name = ((CatalogKey) rec.getKey()).getNodeName() .getUnicodeString(); - HFSPlusEntry e = new HFSPlusEntry( - (HfsPlusFileSystem) getFileSystem(), null, this, name, - rec); - pathList.add(e); + HFSPlusEntry e = new HFSPlusEntry( + (HfsPlusFileSystem) getFileSystem(), null, this, name, + rec); + pathList.add(e); + } + } } - } return new FSEntryTable(((HfsPlusFileSystem) getFileSystem()), pathList); } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUnicodeString.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUnicodeString.java 2009-02-01 14:49:39 UTC (rev 4956) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUnicodeString.java 2009-02-01 15:11:23 UTC (rev 4957) @@ -15,7 +15,7 @@ */ public HFSUnicodeString(final byte[] src, final int offset) { length = BigEndian.getInt16(src, offset); - byte[] data = new byte[2 + length * 2]; + byte[] data = new byte[2 + (length * 2)]; System.arraycopy(src, offset, data, 0, 2); length = BigEndian.getInt16(data, 0); data = new byte[length * 2]; @@ -45,7 +45,16 @@ } public final byte[] getBytes() { - return (length + "" + string).getBytes(); + char[] result = new char[length]; + string.getChars(0, length, result, 0); + byte[] name = new byte[length * 2]; + for (int i = 0; i < length; ++i) { + BigEndian.setChar(name, i * 2, result[i]); + } + byte[] data = new byte[(length * 2) + 2]; + BigEndian.setInt16(data, 0, length); + System.arraycopy(name, 0, data, 2, name.length); + return data; } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-02-01 14:49:39 UTC (rev 4956) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-02-01 15:11:23 UTC (rev 4957) @@ -43,7 +43,6 @@ public final void read() throws FileSystemException { sb = new Superblock(this, false); - log.debug("Superblock informations:\n" + sb.toString()); if (!sb.isAttribute(HfsPlusConstants.HFSPLUS_VOL_UNMNT_BIT)) { log .info(getDevice().getId() @@ -149,7 +148,6 @@ Catalog catalog = new Catalog(params); this.getApi().write(offset, catalog.getBytes()); log.debug("Write volume header to disk."); - log.debug(sb.toString()); this.getApi().write(1024, ByteBuffer.wrap(sb.getBytes())); flush(); } catch (IOException e) { Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2009-02-01 14:49:39 UTC (rev 4956) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2009-02-01 15:11:23 UTC (rev 4957) @@ -89,14 +89,14 @@ // TODO initialize attributes, max key length and key comparaison type. bufferLength += BTHeaderRecord.BT_HEADER_RECORD_LENGTH; // Create root node - int rootNodePosition = bthr.getRootNode() * bthr.getNodeSize(); + 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); - CatalogNode rootNode = new CatalogNode(nd, bthr.getNodeSize()); + CatalogNode rootNode = new CatalogNode(nd, nodeSize); int offset = NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH; // First record (folder) HFSUnicodeString name = new HFSUnicodeString(params.getVolumeName()); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java 2009-02-01 14:49:39 UTC (rev 4956) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java 2009-02-01 15:11:23 UTC (rev 4957) @@ -6,11 +6,10 @@ import org.jnode.util.BigEndian; public class CatalogKey extends AbstractKey { - + + public static final int MINIMUM_KEY_LENGTH = 6; public static final int MAXIMUM_KEY_LENGTH = 516; - private int keyLength; - private CatalogNodeId parentID; private HFSUnicodeString nodeName; /** @@ -19,14 +18,17 @@ * @param offset */ public CatalogKey(final byte[] src, final int offset) { + int currentOffset = offset; byte[] ck = new byte[2]; - System.arraycopy(src, offset, ck, 0, 2); + System.arraycopy(src, currentOffset, ck, 0, 2); keyLength = BigEndian.getInt16(ck, 0); + currentOffset += 2; ck = new byte[4]; - System.arraycopy(src, offset + 2, ck, 0, 4); + System.arraycopy(src, currentOffset, ck, 0, 4); parentID = new CatalogNodeId(ck, 0); - if (keyLength > 6) { - nodeName = new HFSUnicodeString(src, offset + 6); + currentOffset += 4; + if (keyLength > MINIMUM_KEY_LENGTH) { + nodeName = new HFSUnicodeString(src, currentOffset); } } @@ -38,7 +40,7 @@ public CatalogKey(final CatalogNodeId parentID, final HFSUnicodeString name) { this.parentID = parentID; this.nodeName = name; - this.keyLength = 6 + name.getLength(); + this.keyLength = MINIMUM_KEY_LENGTH + name.getLength(); } public final int getKeyLength() { @@ -79,12 +81,8 @@ public final String toString() { StringBuffer s = new StringBuffer(); - s.append("Key length: ").append(getKeyLength()).append(" "); - s.append("Parent ID: ").append(getParentId().getId()).append(" "); - s.append("Node name: ") - .append( - (getNodeName() != null) ? getNodeName() - .getUnicodeString() : ""); + s.append("[length, Parent ID, Node name]:").append(getKeyLength()).append(",").append(getParentId().getId()) + .append(",").append((getNodeName() != null) ? getNodeName().getUnicodeString() : ""); return s.toString(); } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractKey.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractKey.java 2009-02-01 14:49:39 UTC (rev 4956) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractKey.java 2009-02-01 15:11:23 UTC (rev 4957) @@ -1,7 +1,12 @@ package org.jnode.fs.hfsplus.tree; +import org.jnode.fs.hfsplus.catalog.CatalogNodeId; + public abstract class AbstractKey implements Key { + protected int keyLength; + protected CatalogNodeId parentID; + public abstract int getKeyLength(); public abstract byte[] getBytes(); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNodeRecord.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNodeRecord.java 2009-02-01 14:49:39 UTC (rev 4956) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNodeRecord.java 2009-02-01 15:11:23 UTC (rev 4957) @@ -17,5 +17,10 @@ return key.getKeyLength() + recordData.length; } - public abstract byte[] getBytes(); + public byte[] getBytes() { + byte[] data = new byte[key.getKeyLength() + this.recordData.length]; + System.arraycopy(data, 0, key.getBytes(), 0, key.getKeyLength()); + System.arraycopy(data, key.getKeyLength(), this.recordData, 0, this.recordData.length); + return data; + } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexRecord.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexRecord.java 2009-02-01 14:49:39 UTC (rev 4956) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexRecord.java 2009-02-01 15:11:23 UTC (rev 4957) @@ -13,14 +13,8 @@ public IndexRecord(final Key key, final byte[] nodeData, final int offset) { this.key = key; this.recordData = new byte[4]; - System.arraycopy(nodeData, offset + key.getKeyLength() + 2, recordData, 0, 4); + System.arraycopy(nodeData, offset + key.getKeyLength(), recordData, 0, 4); } - - @Override - public byte[] getBytes() { - // TODO Auto-generated method stub - return null; - } public final int getIndex() { return BigEndian.getInt32(recordData, 0); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java 2009-02-01 14:49:39 UTC (rev 4956) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java 2009-02-01 15:11:23 UTC (rev 4957) @@ -20,14 +20,6 @@ return BigEndian.getInt16(this.recordData, 0); } - @Override - public byte[] getBytes() { - byte[] data = new byte[key.getKeyLength() + this.recordData.length]; - System.arraycopy(data, 0, key.getBytes(), 0, key.getKeyLength()); - System.arraycopy(data, key.getKeyLength(), this.recordData, 0, this.recordData.length); - return data; - } - public final String toString() { return "Type : " + getType() + "\nKey : " + getKey().toString() + "\n"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |