From: <ga...@us...> - 2012-02-14 16:05:46
|
Revision: 5886 http://jnode.svn.sourceforge.net/jnode/?rev=5886&view=rev Author: galatnm Date: 2012-02-14 16:05:35 +0000 (Tue, 14 Feb 2012) Log Message: ----------- HFS : Rewrite folder operations (in progress). Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.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/CatalogFolder.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java trunk/fs/src/test/org/jnode/fs/hfsplus/HfsPlusFileSystemTest.java Added Paths: ----------- trunk/fs/src/test/org/jnode/fs/hfsplus/catalog/CatalogFolderTest.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2012-02-08 11:49:43 UTC (rev 5885) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2012-02-14 16:05:35 UTC (rev 5886) @@ -35,6 +35,7 @@ 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.CatalogLeafNode; import org.jnode.fs.hfsplus.catalog.CatalogNodeId; import org.jnode.fs.hfsplus.tree.LeafRecord; import org.jnode.fs.spi.FSEntryTable; @@ -60,17 +61,16 @@ @Override public FSEntry addDirectory(String name) throws IOException { - log.debug("<<< BEGIN addDirectory " + name + " >>>"); if (getFileSystem().isReadOnly()) { throw new ReadOnlyFileSystemException(); } if (getEntry(name) != null) { - throw new IOException("File or Directory already exists" + name); + throw new IOException("File or Directory already exists : " + name); } FSEntry newEntry = createDirectoryEntry(name); setFreeEntry(newEntry); - log.debug("<<< END addDirectory " + name + " >>>"); + log.debug("Directory " + name + " added"); return newEntry; } @@ -231,16 +231,17 @@ } Catalog catalog = ((HfsPlusFileSystem) getFileSystem()).getCatalog(); SuperBlock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); - LeafRecord folderRecord = + CatalogLeafNode node = catalog.createNode(name, this.folder.getFolderId(), new CatalogNodeId(volumeHeader.getNextCatalogId()), CatalogFolder.RECORD_TYPE_FOLDER_THREAD); - folder.setValence(folder.getValence() + 1); + folder.incrementValence(); - HfsPlusEntry newEntry = new HfsPlusEntry((HfsPlusFileSystem) getFileSystem(), this, name, folderRecord); + HfsPlusEntry newEntry = new HfsPlusEntry((HfsPlusFileSystem) getFileSystem(), this, name, node.getNodeRecord(0)); newEntry.setDirty(); - volumeHeader.setFolderCount(volumeHeader.getFolderCount() + 1); + volumeHeader.incrementFolderCount(); log.debug("New volume header :\n" + volumeHeader.toString()); + volumeHeader.update(); return newEntry; } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java 2012-02-08 11:49:43 UTC (rev 5885) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java 2012-02-14 16:05:35 UTC (rev 5886) @@ -426,6 +426,11 @@ public final boolean isAttribute(final int maskBit) { return (((getAttributes() >> maskBit) & 0x1) != 0); } + + public void incrementFolderCount(){ + this.setFolderCount(this.getFolderCount() + 1); + } + public byte[] getBytes() { return data; Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2012-02-08 11:49:43 UTC (rev 5885) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2012-02-14 16:05:35 UTC (rev 5886) @@ -126,7 +126,7 @@ LeafRecord record = new LeafRecord(ck, folder.getBytes()); rootNode.addNodeRecord(record); // Second record (thread) - CatalogKey tck = new CatalogKey(CatalogNodeId.HFSPLUS_ROOT_CNID, name); + CatalogKey tck = new CatalogKey(CatalogNodeId.HFSPLUS_POR_CNID, name); CatalogThread ct = new CatalogThread(CatalogFolder.RECORD_TYPE_FOLDER_THREAD, CatalogNodeId.HFSPLUS_ROOT_CNID, new HfsUnicodeString("")); @@ -161,28 +161,40 @@ * @param nodeType * @return the new node instance */ - public LeafRecord createNode(String filename, CatalogNodeId parentId, CatalogNodeId nodeId, + public CatalogLeafNode createNode(String filename, CatalogNodeId parentId, CatalogNodeId nodeId, int nodeType) throws IOException { + CatalogLeafNode node; HfsUnicodeString name = new HfsUnicodeString(filename); LeafRecord record = this.getRecord(parentId, name); if (record == null) { NodeDescriptor nd = new NodeDescriptor(0, 0, NodeDescriptor.BT_LEAF_NODE, 1, 2); - CatalogLeafNode node = new CatalogLeafNode(nd, 8192); + node = new CatalogLeafNode(nd, 8192); + // Normal record CatalogKey key = new CatalogKey(parentId, name); - CatalogThread thread = new CatalogThread(nodeType, parentId, name); - record = new LeafRecord(key, thread.getBytes()); - node.addNodeRecord(record); if (nodeType == CatalogFolder.RECORD_TYPE_FOLDER) { - CatalogFolder folder = new CatalogFolder(0, nodeId); + CatalogFolder folder = new CatalogFolder(0, parentId); key = new CatalogKey(parentId, name); record = new LeafRecord(key, folder.getBytes()); + node.addNodeRecord(record); } else { - // TODO + // Catalog file } + // Thread record + key = new CatalogKey(parentId, name); + int threadType; + if (nodeType == CatalogFolder.RECORD_TYPE_FOLDER) { + threadType = CatalogFolder.RECORD_TYPE_FOLDER_THREAD; + } else { + threadType = CatalogFile.RECORD_TYPE_FILE_THREAD; + } + CatalogThread thread = new CatalogThread(threadType, nodeId, name); + record = new LeafRecord(key, thread.getBytes()); + node.addNodeRecord(record); + } else { - // TODO + throw new IOException("Leaf record for parent (" + parentId.getId() + ") doesn't exist."); } - return record; + return node; } /** Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java 2012-02-08 11:49:43 UTC (rev 5885) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java 2012-02-14 16:05:35 UTC (rev 5886) @@ -148,4 +148,8 @@ this.attrModDate = attrModDate; } + public void incrementValence(){ + this.setValence(this.getValence() + 1); + } + } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java 2012-02-08 11:49:43 UTC (rev 5885) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafRecord.java 2012-02-14 16:05:35 UTC (rev 5886) @@ -36,7 +36,7 @@ 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); + System.arraycopy(nodeData, offset + (key.getKeyLength()-2), this.recordData, 0, recordDataSize); type = BigEndian.getInt16(this.recordData, 0); } Modified: trunk/fs/src/test/org/jnode/fs/hfsplus/HfsPlusFileSystemTest.java =================================================================== --- trunk/fs/src/test/org/jnode/fs/hfsplus/HfsPlusFileSystemTest.java 2012-02-08 11:49:43 UTC (rev 5885) +++ trunk/fs/src/test/org/jnode/fs/hfsplus/HfsPlusFileSystemTest.java 2012-02-14 16:05:35 UTC (rev 5886) @@ -80,7 +80,16 @@ fs.read(); fs.createRootEntry(); FSDirectory root = fs.getRootEntry().getDirectory(); + assertFalse("Must be empty", root.iterator().hasNext()); root.addDirectory("test"); + fs.flush(); + fs.close(); + fs = new HfsPlusFileSystemType().create(device, false); + fs.read(); + assertEquals(1,fs.getVolumeHeader().getFolderCount()); + fs.createRootEntry(); + root = fs.getRootEntry().getDirectory(); + assertTrue("Must contains one directory", root.iterator().hasNext()); } private Device createTestDisk(boolean formatted) throws IOException { Added: trunk/fs/src/test/org/jnode/fs/hfsplus/catalog/CatalogFolderTest.java =================================================================== --- trunk/fs/src/test/org/jnode/fs/hfsplus/catalog/CatalogFolderTest.java (rev 0) +++ trunk/fs/src/test/org/jnode/fs/hfsplus/catalog/CatalogFolderTest.java 2012-02-14 16:05:35 UTC (rev 5886) @@ -0,0 +1,30 @@ +package org.jnode.fs.hfsplus.catalog; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class CatalogFolderTest { + + @Test + public void testCatalogFolderIntCatalogNodeId() { + CatalogFolder folder = new CatalogFolder(0,CatalogNodeId.HFSPLUS_ROOT_CNID); + assertNotNull(folder); + assertEquals(0, folder.getValence()); + assertEquals(2,folder.getFolderId().getId()); + folder = new CatalogFolder(folder.getBytes()); + assertNotNull(folder); + assertEquals(0, folder.getValence()); + assertEquals(2,folder.getFolderId().getId()); + + } + + @Test + public void testCatalogFolder(){ + CatalogFolder folder = new CatalogFolder(new byte[]{0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -53, 96, 7, 78, -53, 96, 7, 78, -53, 96, 7, 78, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 2, 0, 9, 0, 116, 0, 101, 0, 115, 0, 116, 0, 100, 0, 114, 0, 105, 0, 118, 0, 101, 0, 3}); + assertNotNull(folder); + assertEquals(0, folder.getValence()); + assertEquals(2,folder.getFolderId().getId()); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |