From: <cr...@us...> - 2009-03-26 11:51:03
|
Revision: 5156 http://jnode.svn.sourceforge.net/jnode/?rev=5156&view=rev Author: crawley Date: 2009-03-26 11:50:49 +0000 (Thu, 26 Mar 2009) Log Message: ----------- Javadoc fixes (and minor de-uglification) Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUtils.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/CatalogNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogThread.java trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/NodeDescriptor.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java 2009-03-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -61,7 +61,7 @@ * * @param totalSize * @param clumpSize - * @param totalBock + * @param totalBlock */ public HFSPlusForkData(long totalSize, int clumpSize, int totalBlock) { this.totalSize = totalSize; @@ -85,11 +85,6 @@ return dest; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ public final String toString() { StringBuffer s = new StringBuffer(); s.append("Total size : ").append(totalSize).append("\n"); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUtils.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUtils.java 2009-03-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUtils.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -30,27 +30,27 @@ * Difference in second between 01/01/1970 00:00:00 (java reference time) * and 01/01/1904 00:00:00 (HFS reference time). */ - public static final long MAC_DATE_CONVERTION = 2082844800L; + public static final long MAC_DATE_CONVERSION = 2082844800L; /** * Convert time from/to java time to/from mac time. * * @param time in seconds since reference date. - * @param encode if set to true, convert from java to mac. If set to false, - * convert from mac to java. + * @param encode if {code true}, convert from java to mac, otherwise + * convert from mac to java. * - * @return + * @return the converted time */ public static long getDate(long time, boolean encode) { - time = (encode) ? time + MAC_DATE_CONVERTION : time - MAC_DATE_CONVERTION; + time = (encode) ? time + MAC_DATE_CONVERSION : time - MAC_DATE_CONVERSION; return time; } /** * - * @param time - * @param dateFormat - * @return + * @param time a date/time in seconds since the UNIX epoch. + * @param dateFormat the date/time format string + * @return the date/time formatted as a String */ public static String printDate(final long time, final String dateFormat) { Calendar cal = Calendar.getInstance(); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-03-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -200,9 +200,7 @@ * Calculate the number of blocks needed for bitmap. * * @param totalBlocks Total of blocks found in the device. - * - * @return long - Number of blocks. - * + * @return the number of blocks. * @throws IOException */ private long getClumpSize(long totalBlocks) throws IOException { @@ -418,7 +416,7 @@ /** * Get string representation of attribute. * - * @return + * @return the string representation */ public final String getAttributesAsString() { return ((isAttribute(HFSPLUS_VOL_UNMNT_BIT)) ? " kHFSVolumeUnmountedBit" : "") + @@ -431,7 +429,7 @@ * * @param maskBit Bit position of the attribute. See constants. * - * @return true if attribute is set. + * @return {@code true} if attribute is set. */ public final boolean isAttribute(final int maskBit) { return (((getAttributes() >> maskBit) & 0x1) != 0); @@ -441,11 +439,6 @@ return data; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ public final String toString() { StringBuffer buffer = new StringBuffer(); buffer.append("Magic: 0x").append(NumberUtils.hex(getMagic(), 4)).append("\n"); 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-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -41,17 +41,19 @@ private final Logger log = Logger.getLogger(getClass()); private HfsPlusFileSystem fs; + /** * B-Tree node descriptor */ private NodeDescriptor btnd; + /** * B-Tree Header record */ private BTHeaderRecord bthr; - /** */ + private int catalogHeaderNodeOffset; - /** */ + private ByteBuffer buffer; /** @@ -143,7 +145,7 @@ /** * @param parentID - * @return + * @return the leaf record, or possibly {code null}. * @throws IOException */ public final LeafRecord getRecord(final CatalogNodeId parentID) throws IOException { @@ -186,7 +188,7 @@ /** * Find leaf records corresponding to parentID. The search begin at the node - * correspding to the index passed as parameter. + * corresponding to the index passed as parameter. * * @param parentID Parent node id * @param nodeNumber Index of node where the search begin. @@ -202,7 +204,7 @@ fs.getApi().read(catalogHeaderNodeOffset + (currentNodeNumber * nodeSize), nodeData); CatalogNode node = new CatalogNode(nodeData.array(), nodeSize); if (node.isIndexNode()) { - IndexRecord[] records = (IndexRecord[]) node.findChilds(parentID); + IndexRecord[] records = (IndexRecord[]) node.findChildren(parentID); List<LeafRecord> lfList = new LinkedList<LeafRecord>(); for (IndexRecord rec : records) { LeafRecord[] lfr = getRecords(parentID, rec.getIndex()); @@ -226,7 +228,7 @@ /** * @param parentID * @param nodeName - * @return + * @return the leaf node or {@code null} * @throws IOException */ public final LeafRecord getRecord(final CatalogNodeId parentID, final HFSUnicodeString nodeName) 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-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -90,9 +90,6 @@ * * @param flags * @param fileId - * @param createDate - * @param contentModDate - * @param attrModDate * @param datas * @param resources */ @@ -109,17 +106,12 @@ /** * - * @return + * @return a serious case of nothing much at all */ public byte[] getBytes() { return null; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#toString() - */ public final String toString() { StringBuffer s = new StringBuffer(); s.append("Record type:").append(recordType).append("\t"); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-03-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -60,7 +60,7 @@ /** * @param parentId - * @return + * @return a NodeRecord or {@code null} */ public final NodeRecord find(final CatalogNodeId parentId) { for (int index = 0; index < this.getNodeDescriptor().getNumRecords(); index++) { @@ -77,7 +77,7 @@ /** * @param key - * @return + * @return a NodeRecord or {@code null} */ public NodeRecord find(final CatalogKey key) { NodeRecord largestMatchingRecord = null; @@ -93,9 +93,9 @@ /** * @param parentId - * @return + * @return an array of NodeRecords */ - public final NodeRecord[] findChilds(final CatalogNodeId parentId) { + public final NodeRecord[] findChildren(final CatalogNodeId parentId) { LinkedList<NodeRecord> result = new LinkedList<NodeRecord>(); NodeRecord largestMatchingRecord = null; CatalogKey largestMatchingKey = null; @@ -119,7 +119,7 @@ /** * @param parentId - * @return + * @return an array of NodeRecords */ public final NodeRecord[] findAll(final CatalogNodeId parentId) { List<NodeRecord> list = new LinkedList<NodeRecord>(); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogThread.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogThread.java 2009-03-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogThread.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -26,13 +26,16 @@ public class CatalogThread { public static final int CATALOG_THREAD_SIZE = 512; + /** The catalog thread record type. Can be a file or a folder. */ private int recordType; + /** * the catalog node id of the file or folder referenced by the thread * record. */ private CatalogNodeId parentId; + /** the name of the file or folder reference by the thread record. */ private HFSUnicodeString nodeName; @@ -66,7 +69,7 @@ /** * - * @return + * @return the thread encoded as data */ public byte[] getBytes() { byte[] data = new byte[512]; Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java 2009-03-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -25,8 +25,10 @@ public class ExtentDescriptor { /** The size of the extent descriptor. */ public static final int EXTENT_DESCRIPTOR_LENGTH = 8; + /** The first allocation block. */ private int startBlock; + /** The length in allocation blocks of the extent. */ private int blockCount; @@ -60,8 +62,7 @@ } /** - * - * @return + * @return the extent encoded as data */ public final byte[] getBytes() { byte[] data = new byte[EXTENT_DESCRIPTOR_LENGTH]; Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexNode.java 2009-03-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexNode.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -24,7 +24,6 @@ /** * - * @param descriptor * @param nodeData * @param nodeSize */ Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafNode.java 2009-03-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafNode.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -25,7 +25,6 @@ /** * - * @param descriptor * @param nodeData * @param nodeSize */ 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-26 09:28:30 UTC (rev 5155) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/NodeDescriptor.java 2009-03-26 11:50:49 UTC (rev 5156) @@ -27,16 +27,22 @@ 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; + /** 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; @@ -75,7 +81,7 @@ /** * - * @return + * @return the descriptor rendered as bytes */ public byte[] getBytes() { byte[] data = new byte[BT_NODE_DESCRIPTOR_LENGTH]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2009-03-26 15:27:09
|
Revision: 5159 http://jnode.svn.sourceforge.net/jnode/?rev=5159&view=rev Author: galatnm Date: 2009-03-26 15:27:01 +0000 (Thu, 26 Mar 2009) Log Message: ----------- Rewrite Node class and sub-classes 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/CatalogNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNodeId.java trunk/fs/src/fs/org/jnode/fs/hfsplus/command/FormatHfsPlusCommand.java trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java Removed Paths: ------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafNode.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-03-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -30,12 +30,14 @@ import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; import org.jnode.fs.ReadOnlyFileSystemException; +import org.jnode.fs.hfsplus.catalog.Catalog; 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; import org.jnode.fs.hfsplus.catalog.CatalogThread; import org.jnode.fs.hfsplus.tree.LeafRecord; +import org.jnode.fs.hfsplus.tree.NodeDescriptor; import org.jnode.fs.spi.FSEntryTable; public class HFSPlusDirectory extends HFSPlusEntry implements FSDirectory { @@ -211,22 +213,11 @@ if (fs.isReadOnly()) { throw new ReadOnlyFileSystemException(); } - + Catalog catalog = fs.getCatalog(); Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); - HFSUnicodeString dirName = new HFSUnicodeString(name); - CatalogThread thread = - new CatalogThread(CatalogFolder.RECORD_TYPE_FOLDER_THREAD, this.folder - .getFolderId(), dirName); - 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); - log.debug("New catalog key :\n" + key.toString()); - - LeafRecord folderRecord = new LeafRecord(key, newFolder.getBytes()); - log.debug("New record folder :\n" + folderRecord.toString()); - + LeafRecord folderRecord = catalog.createNode(name, this.folder + .getFolderId(), new CatalogNodeId(volumeHeader.getNextCatalogId()), CatalogFolder.RECORD_TYPE_FOLDER_THREAD); + HFSPlusEntry newEntry = new HFSPlusDirectory(fs, this, name, folderRecord); volumeHeader.setFolderCount(volumeHeader.getFolderCount() + 1); log.debug("New volume header :\n" + volumeHeader.toString()); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-03-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -134,11 +134,8 @@ int macDate = HFSUtils.getNow(); this.setCreateDate(macDate); this.setModifyDate(macDate); - this.setBackupDate(0); this.setCheckedDate(macDate); // --- - this.setFileCount(0); - this.setFolderCount(0); this.setBlockSize(blockSize); this.setTotalBlocks((int) params.getBlockCount()); this.setFreeBlocks((int) params.getBlockCount()); 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-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -84,7 +84,7 @@ } } - + /** * Create new Catalog * @@ -111,7 +111,7 @@ BTHeaderRecord.BT_BIG_KEYS_MASK); log.debug(bthr.toString()); bufferLength += BTHeaderRecord.BT_HEADER_RECORD_LENGTH; - // Create root node + log.info("Create root node."); int rootNodePosition = bthr.getRootNode() * nodeSize; bufferLength += (rootNodePosition - bufferLength); // Create node descriptor @@ -119,22 +119,21 @@ new NodeDescriptor(0, 0, NodeDescriptor.BT_LEAF_NODE, 1, params .getInitializeNumRecords()); CatalogNode rootNode = new CatalogNode(nd, nodeSize); - int offset = NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH; // First record (folder) HFSUnicodeString name = new HFSUnicodeString(params.getVolumeName()); CatalogKey ck = new CatalogKey(CatalogNodeId.HFSPLUS_POR_CNID, name); CatalogFolder folder = new CatalogFolder(params.isJournaled() ? 2 : 0, CatalogNodeId.HFSPLUS_ROOT_CNID); LeafRecord record = new LeafRecord(ck, folder.getBytes()); - rootNode.addNodeRecord(0, record, offset); + rootNode.addNodeRecord(record); // Second record (thread) - offset = offset + ck.getKeyLength() + CatalogFolder.CATALOG_FOLDER_SIZE; CatalogKey tck = new CatalogKey(CatalogNodeId.HFSPLUS_ROOT_CNID, name); CatalogThread ct = new CatalogThread(CatalogFolder.RECORD_TYPE_FOLDER_THREAD, CatalogNodeId.HFSPLUS_ROOT_CNID, new HFSUnicodeString("")); record = new LeafRecord(tck, ct.getBytes()); - rootNode.addNodeRecord(1, record, offset); + rootNode.addNodeRecord(record); + log.debug(rootNode.toString()); buffer = ByteBuffer.allocate(bufferLength + bthr.getNodeSize()); buffer.put(btnd.getBytes()); buffer.put(bthr.getBytes()); @@ -144,6 +143,38 @@ } /** + * + * @param filename + * @param parentId + * @param nodeId + * @param nodeType + * @return + */ + public LeafRecord createNode(String filename, CatalogNodeId parentId, CatalogNodeId nodeId, int nodeType) throws IOException { + 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); + CatalogNode node = new CatalogNode(nd, 4096); + 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_THREAD){ + CatalogFolder newFolder = new CatalogFolder(0, nodeId); + key = new CatalogKey(parentId, name); + record = new LeafRecord(key, newFolder.getBytes()); + } else { + //TODO + } + } else { + //TODO + } + return record; + } + + /** * @param parentID * @return the leaf record, or possibly {code null}. * @throws IOException Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-03-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -20,6 +20,7 @@ package org.jnode.fs.hfsplus.catalog; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -29,33 +30,43 @@ import org.jnode.fs.hfsplus.tree.LeafRecord; import org.jnode.fs.hfsplus.tree.NodeDescriptor; import org.jnode.fs.hfsplus.tree.NodeRecord; +import org.jnode.util.BigEndian; public class CatalogNode extends AbstractNode { - + + /** + * Create a new node. + * @param descriptor + * @param nodeSize + */ public CatalogNode(NodeDescriptor descriptor, final int nodeSize) { + this.descriptor = descriptor; this.size = nodeSize; - this.datas = new byte[nodeSize]; - System.arraycopy(descriptor.getBytes(), 0, datas, 0, NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); + this.records = new ArrayList<NodeRecord>(this.descriptor.getNumRecords()); + this.offsets = new ArrayList<Integer>(this.descriptor.getNumRecords() + 1); + this.offsets.add(Integer.valueOf(NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH)); } + /** + * Create node from existing data. + * @param nodeData + * @param nodeSize + */ public CatalogNode(final byte[] nodeData, final int nodeSize) { + this.descriptor = new NodeDescriptor(nodeData, 0); this.size = nodeSize; - this.datas = nodeData; + this.records = new ArrayList<NodeRecord>(this.descriptor.getNumRecords()); + this.offsets = new ArrayList<Integer>(this.descriptor.getNumRecords() + 1); + for(int i = 0; i < this.descriptor.getNumRecords(); i++){ + offsets.add(BigEndian.getInt16(nodeData, size - ((i + 1) * 2))); + //TODO Get record data. + } + } @Override public NodeRecord getNodeRecord(int index) { - int offset = this.getRecordOffset(index); - int offset2 = this.getRecordOffset(index + 1); - int recordSize = offset2 - offset; - NodeRecord record = null; - Key key = new CatalogKey(datas, offset); - if (isIndexNode()) { - record = new IndexRecord(key, datas, offset); - } else { - record = new LeafRecord(key, datas, offset, recordSize); - } - return record; + return records.get(index); } /** @@ -63,8 +74,7 @@ * @return a NodeRecord or {@code null} */ public final NodeRecord find(final CatalogNodeId parentId) { - for (int index = 0; index < this.getNodeDescriptor().getNumRecords(); index++) { - NodeRecord record = this.getNodeRecord(index); + for (NodeRecord record : records) { Key key = record.getKey(); if (key instanceof CatalogKey) { if (((CatalogKey) key).getParentId().getId() == parentId.getId()) { Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNodeId.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNodeId.java 2009-03-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNodeId.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -22,7 +22,7 @@ import org.jnode.util.BigEndian; -public class CatalogNodeId implements Comparable { +public class CatalogNodeId implements Comparable<CatalogNodeId> { private byte[] cnid; public CatalogNodeId(final byte[] src, final int offset) { @@ -65,9 +65,9 @@ } @Override - public int compareTo(Object o) { + public int compareTo(CatalogNodeId o) { Integer currentId = Integer.valueOf(this.getId()); - Integer compareId = Integer.valueOf(((CatalogNodeId) o).getId()); + Integer compareId = Integer.valueOf(o.getId()); return currentId.compareTo(compareId); } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/command/FormatHfsPlusCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/command/FormatHfsPlusCommand.java 2009-03-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/command/FormatHfsPlusCommand.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -47,9 +47,9 @@ protected Formatter<HfsPlusFileSystem> getFormatter() { HFSPlusParams params = new HFSPlusParams(); params.setVolumeName((ARG_VOLUME_NAME.isSet()) ? ARG_VOLUME_NAME.getValue() : "untitled"); - params.setBlockSize(params.OPTIMAL_BLOCK_SIZE); + params.setBlockSize(HFSPlusParams.OPTIMAL_BLOCK_SIZE); params.setJournaled(false); - params.setJournalSize(params.DEFAULT_JOURNAL_SIZE); + params.setJournalSize(HFSPlusParams.DEFAULT_JOURNAL_SIZE); return new HfsPlusFileSystemFormatter(params); } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentNode.java 2009-03-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentNode.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -27,14 +27,13 @@ public class ExtentNode extends AbstractNode { public ExtentNode(NodeDescriptor descriptor, final int nodeSize) { + this.descriptor = descriptor; this.size = nodeSize; - this.datas = new byte[nodeSize]; - System.arraycopy(descriptor.getBytes(), 0, datas, 0, NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); } public ExtentNode(final byte[] nodeData, final int nodeSize) { + this.descriptor = new NodeDescriptor(nodeData, 0); this.size = nodeSize; - this.datas = nodeData; } @Override 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-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -20,16 +20,19 @@ package org.jnode.fs.hfsplus.tree; +import java.util.List; + import org.jnode.util.BigEndian; public abstract class AbstractNode implements Node { - - protected byte[] datas; + protected NodeDescriptor descriptor; + protected List<NodeRecord> records; + protected List<Integer> offsets; protected int size; @Override public NodeDescriptor getNodeDescriptor() { - return new NodeDescriptor(datas, 0); + return descriptor; } public boolean isIndexNode() { @@ -42,26 +45,30 @@ @Override public int getRecordOffset(int index) { - return BigEndian.getInt16(datas, size - ((index + 1) * 2)); + return offsets.get(index); } @Override public abstract NodeRecord getNodeRecord(int index); @Override - public void addNodeRecord(int index, NodeRecord record, int offset) { - BigEndian.setInt16(datas, size - ((index + 1) * 2), offset); - System.arraycopy(record.getBytes(), 0, datas, offset, record.getSize()); + public void addNodeRecord(NodeRecord record) { + Integer lastOffset = offsets.get(offsets.size() - 1); + Integer newOffset = lastOffset + record.getSize(); + offsets.add(newOffset); + records.add(record); } public byte[] getBytes() { + byte[] datas = new byte[size]; return datas; } public String toString() { StringBuffer b = new StringBuffer(); b.append((this.isLeafNode()) ? "Leaf node" : "Index node").append("\n"); - b.append(this.getNodeDescriptor().toString()); + b.append(this.getNodeDescriptor().toString()).append("\n"); + b.append("Offsets : ").append(offsets.toString()); return b.toString(); } Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexNode.java 2009-03-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexNode.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -1,39 +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.tree; - -public class IndexNode extends AbstractNode { - - /** - * - * @param nodeData - * @param nodeSize - */ - public IndexNode(final byte[] nodeData, final int nodeSize) { - this.size = nodeSize; - this.datas = nodeData; - } - - @Override - public NodeRecord getNodeRecord(int index) { - return null; - } -} Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafNode.java 2009-03-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/LeafNode.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -1,50 +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.tree; - - -public class LeafNode extends AbstractNode { - - /** - * - * @param nodeData - * @param nodeSize - */ - public LeafNode(final byte[] nodeData, final int nodeSize) { - this.size = nodeSize; - this.datas = nodeData; - } - - /** - * - * @param descriptor - * @param nodeSize - */ - public LeafNode(final NodeDescriptor descriptor, int nodeSize) { - this.size = nodeSize; - } - - @Override - public NodeRecord getNodeRecord(int index) { - return null; - } - -} Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java 2009-03-26 13:46:39 UTC (rev 5158) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java 2009-03-26 15:27:01 UTC (rev 5159) @@ -28,5 +28,5 @@ public boolean isLeafNode(); public int getRecordOffset(int index); public NodeRecord getNodeRecord(int index); - public void addNodeRecord(int index, NodeRecord record, int offset); + public void addNodeRecord(NodeRecord record); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2009-03-26 15:31:07
|
Revision: 5160 http://jnode.svn.sourceforge.net/jnode/?rev=5160&view=rev Author: galatnm Date: 2009-03-26 15:30:57 +0000 (Thu, 26 Mar 2009) Log Message: ----------- Organize imports. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-03-26 15:27:01 UTC (rev 5159) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-03-26 15:30:57 UTC (rev 5160) @@ -35,9 +35,7 @@ import org.jnode.fs.hfsplus.catalog.CatalogFolder; import org.jnode.fs.hfsplus.catalog.CatalogKey; import org.jnode.fs.hfsplus.catalog.CatalogNodeId; -import org.jnode.fs.hfsplus.catalog.CatalogThread; import org.jnode.fs.hfsplus.tree.LeafRecord; -import org.jnode.fs.hfsplus.tree.NodeDescriptor; import org.jnode.fs.spi.FSEntryTable; public class HFSPlusDirectory extends HFSPlusEntry implements FSDirectory { Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-03-26 15:27:01 UTC (rev 5159) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-03-26 15:30:57 UTC (rev 5160) @@ -25,9 +25,7 @@ import java.util.List; import org.jnode.fs.hfsplus.tree.AbstractNode; -import org.jnode.fs.hfsplus.tree.IndexRecord; import org.jnode.fs.hfsplus.tree.Key; -import org.jnode.fs.hfsplus.tree.LeafRecord; import org.jnode.fs.hfsplus.tree.NodeDescriptor; import org.jnode.fs.hfsplus.tree.NodeRecord; import org.jnode.util.BigEndian; 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-26 15:27:01 UTC (rev 5159) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-03-26 15:30:57 UTC (rev 5160) @@ -22,8 +22,6 @@ import java.util.List; -import org.jnode.util.BigEndian; - public abstract class AbstractNode implements Node { protected NodeDescriptor descriptor; protected List<NodeRecord> records; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2009-03-27 10:16:07
|
Revision: 5161 http://jnode.svn.sourceforge.net/jnode/?rev=5161&view=rev Author: galatnm Date: 2009-03-27 10:15:56 +0000 (Fri, 27 Mar 2009) Log Message: ----------- Correct writing of node records. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexRecord.java 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-26 15:30:57 UTC (rev 5160) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2009-03-27 10:15:56 UTC (rev 5161) @@ -143,6 +143,7 @@ } /** + * Create a new node in the catalog B-Tree. * * @param filename * @param parentId @@ -150,26 +151,26 @@ * @param nodeType * @return */ - public LeafRecord createNode(String filename, CatalogNodeId parentId, CatalogNodeId nodeId, int nodeType) throws IOException { + public LeafRecord createNode(String filename, CatalogNodeId parentId, CatalogNodeId nodeId, + int nodeType) throws IOException { HFSUnicodeString name = new HFSUnicodeString(filename); LeafRecord record = this.getRecord(parentId, name); - if(record == null){ + if (record == null) { NodeDescriptor nd = new NodeDescriptor(0, 0, NodeDescriptor.BT_LEAF_NODE, 1, 2); - CatalogNode node = new CatalogNode(nd, 4096); + CatalogNode node = new CatalogNode(nd, 8192); CatalogKey key = new CatalogKey(parentId, name); - CatalogThread thread = - new CatalogThread(nodeType, parentId, name); + CatalogThread thread = new CatalogThread(nodeType, parentId, name); record = new LeafRecord(key, thread.getBytes()); node.addNodeRecord(record); - if(nodeType == CatalogFolder.RECORD_TYPE_FOLDER_THREAD){ - CatalogFolder newFolder = new CatalogFolder(0, nodeId); - key = new CatalogKey(parentId, name); - record = new LeafRecord(key, newFolder.getBytes()); + if (nodeType == CatalogFolder.RECORD_TYPE_FOLDER) { + CatalogFolder folder = new CatalogFolder(0, nodeId); + key = new CatalogKey(parentId, name); + record = new LeafRecord(key, folder.getBytes()); } else { - //TODO + // TODO } } else { - //TODO + // TODO } return record; } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-03-26 15:30:57 UTC (rev 5160) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-03-27 10:15:56 UTC (rev 5161) @@ -25,7 +25,9 @@ import java.util.List; import org.jnode.fs.hfsplus.tree.AbstractNode; +import org.jnode.fs.hfsplus.tree.IndexRecord; import org.jnode.fs.hfsplus.tree.Key; +import org.jnode.fs.hfsplus.tree.LeafRecord; import org.jnode.fs.hfsplus.tree.NodeDescriptor; import org.jnode.fs.hfsplus.tree.NodeRecord; import org.jnode.util.BigEndian; @@ -55,9 +57,21 @@ this.size = nodeSize; this.records = new ArrayList<NodeRecord>(this.descriptor.getNumRecords()); this.offsets = new ArrayList<Integer>(this.descriptor.getNumRecords() + 1); + int offset; + for(int i = 0; i < this.descriptor.getNumRecords() + 1; i++){ + offset = BigEndian.getInt16(nodeData, size - ((i + 1) * 2)); + offsets.add(Integer.valueOf(offset)); + } + CatalogKey key; for(int i = 0; i < this.descriptor.getNumRecords(); i++){ - offsets.add(BigEndian.getInt16(nodeData, size - ((i + 1) * 2))); - //TODO Get record data. + offset = offsets.get(i); + key = new CatalogKey(nodeData, offset); + if(isIndexNode()){ + records.add(new IndexRecord(key,nodeData, offset)); + } else { + int recordSize = offsets.get(i+1) - offset; + records.add(new LeafRecord(key,nodeData, offset, recordSize)); + } } } @@ -107,8 +121,7 @@ LinkedList<NodeRecord> result = new LinkedList<NodeRecord>(); NodeRecord largestMatchingRecord = null; CatalogKey largestMatchingKey = null; - for (int index = 0; index < this.getNodeDescriptor().getNumRecords(); index++) { - NodeRecord record = this.getNodeRecord(index); + for (NodeRecord record : records) { CatalogKey key = (CatalogKey) record.getKey(); if (key.getParentId().getId() < parentId.getId() && (largestMatchingKey == null || key.compareTo(largestMatchingKey) > 0)) { 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-26 15:30:57 UTC (rev 5160) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-03-27 10:15:56 UTC (rev 5161) @@ -22,6 +22,8 @@ import java.util.List; +import org.jnode.util.BigEndian; + public abstract class AbstractNode implements Node { protected NodeDescriptor descriptor; protected List<NodeRecord> records; @@ -59,6 +61,17 @@ public byte[] getBytes() { byte[] datas = new byte[size]; + System.arraycopy(descriptor.getBytes(), 0, datas, 0, NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); + int offsetIndex = 0; + int offset; + for(NodeRecord record : records){ + offset = offsets.get(offsetIndex); + System.arraycopy(record.getBytes(), 0, datas, offset, record.getSize()); + BigEndian.setInt16(datas, size - ((offsetIndex + 1) * 2), offset); + offsetIndex++; + } + offset = offsets.get(offsets.size() - 1); + BigEndian.setInt16(datas, size - ((offsetIndex + 1) * 2), offset); return datas; } 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-26 15:30:57 UTC (rev 5160) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/IndexRecord.java 2009-03-27 10:15:56 UTC (rev 5161) @@ -26,6 +26,12 @@ /** A node number that represent a child node of the index node. */ private int index; + public IndexRecord(final byte[] nodeData, final int offset) { + this.recordData = new byte[4]; + System.arraycopy(nodeData, offset + key.getKeyLength(), recordData, 0, 4); + index = BigEndian.getInt32(recordData, 0); + } + /** * * @param key This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2009-04-01 04:35:36
|
Revision: 5203 http://jnode.svn.sourceforge.net/jnode/?rev=5203&view=rev Author: chrisboertien Date: 2009-04-01 04:35:32 +0000 (Wed, 01 Apr 2009) Log Message: ----------- checkstyle fixes Signed-off-by: Chris Boertien <chr...@gm...> Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-04-01 04:23:57 UTC (rev 5202) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-04-01 04:35:32 UTC (rev 5203) @@ -213,8 +213,8 @@ } Catalog catalog = fs.getCatalog(); Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); - LeafRecord folderRecord = catalog.createNode(name, this.folder - .getFolderId(), new CatalogNodeId(volumeHeader.getNextCatalogId()), CatalogFolder.RECORD_TYPE_FOLDER_THREAD); + LeafRecord folderRecord = catalog.createNode(name, this.folder.getFolderId(), + new CatalogNodeId(volumeHeader.getNextCatalogId()), CatalogFolder.RECORD_TYPE_FOLDER_THREAD); HFSPlusEntry newEntry = new HFSPlusDirectory(fs, this, name, folderRecord); volumeHeader.setFolderCount(volumeHeader.getFolderCount() + 1); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-04-01 04:23:57 UTC (rev 5202) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-04-01 04:35:32 UTC (rev 5203) @@ -58,22 +58,21 @@ this.records = new ArrayList<NodeRecord>(this.descriptor.getNumRecords()); this.offsets = new ArrayList<Integer>(this.descriptor.getNumRecords() + 1); int offset; - for(int i = 0; i < this.descriptor.getNumRecords() + 1; i++){ + for (int i = 0; i < this.descriptor.getNumRecords() + 1; i++) { offset = BigEndian.getInt16(nodeData, size - ((i + 1) * 2)); offsets.add(Integer.valueOf(offset)); } CatalogKey key; - for(int i = 0; i < this.descriptor.getNumRecords(); i++){ + for (int i = 0; i < this.descriptor.getNumRecords(); i++) { offset = offsets.get(i); key = new CatalogKey(nodeData, offset); - if(isIndexNode()){ - records.add(new IndexRecord(key,nodeData, offset)); + if (isIndexNode()) { + records.add(new IndexRecord(key, nodeData, offset)); } else { - int recordSize = offsets.get(i+1) - offset; - records.add(new LeafRecord(key,nodeData, offset, recordSize)); + int recordSize = offsets.get(i + 1) - offset; + records.add(new LeafRecord(key, nodeData, offset, recordSize)); } } - } @Override Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-04-01 04:23:57 UTC (rev 5202) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-04-01 04:35:32 UTC (rev 5203) @@ -64,7 +64,7 @@ System.arraycopy(descriptor.getBytes(), 0, datas, 0, NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); int offsetIndex = 0; int offset; - for(NodeRecord record : records){ + for (NodeRecord record : records) { offset = offsets.get(offsetIndex); System.arraycopy(record.getBytes(), 0, datas, offset, record.getSize()); BigEndian.setInt16(datas, size - ((offsetIndex + 1) * 2), offset); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2009-04-28 08:39:31
|
Revision: 5355 http://jnode.svn.sourceforge.net/jnode/?rev=5355&view=rev Author: galatnm Date: 2009-04-28 08:39:26 +0000 (Tue, 28 Apr 2009) Log Message: ----------- Renaming Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.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/catalog/CatalogKey.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogThread.java Added Paths: ----------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusBSDInfo.java 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/HfsPlusFile.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusForkData.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusObject.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusSystemChecker.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsUnicodeString.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsUtils.java Removed Paths: ------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusBSDInfo.java 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/HFSPlusFile.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusObject.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUnicodeString.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUtils.java Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusBSDInfo.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusBSDInfo.java 2009-04-28 07:28:05 UTC (rev 5354) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusBSDInfo.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -1,5 +0,0 @@ -package org.jnode.fs.hfsplus; - -public class HFSPlusBSDInfo { - -} Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-04-28 07:28:05 UTC (rev 5354) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -1,255 +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; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; - -import org.apache.log4j.Logger; -import org.jnode.fs.FSDirectory; -import org.jnode.fs.FSEntry; -import org.jnode.fs.ReadOnlyFileSystemException; -import org.jnode.fs.hfsplus.catalog.Catalog; -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; -import org.jnode.fs.hfsplus.tree.LeafRecord; -import org.jnode.fs.spi.FSEntryTable; - -public class HFSPlusDirectory extends HFSPlusEntry implements FSDirectory { - - private static final Logger log = Logger.getLogger(HFSPlusDirectory.class); - - /** Table of entries of our parent */ - private FSEntryTable entries; - - private CatalogFolder folder; - - public HFSPlusDirectory(HfsPlusFileSystem fs, HFSPlusDirectory parent, String name, - LeafRecord record) { - super(fs, parent, name, record); - this.folder = new CatalogFolder(record.getData()); - this.entries = FSEntryTable.EMPTY_TABLE; - } - - @Override - public FSEntry addDirectory(String name) throws IOException { - log.debug("<<< BEGIN addDirectory " + name + " >>>"); - if (fs.isReadOnly()) { - throw new ReadOnlyFileSystemException(); - } - - if (getEntry(name) != null) { - throw new IOException("File or Directory already exists" + name); - } - FSEntry newEntry = createDirectoryEntry(name); - setFreeEntry(newEntry); - log.debug("<<< END addDirectory " + name + " >>>"); - return newEntry; - } - - @Override - public FSEntry addFile(String name) throws IOException { - log.debug("<<< BEGIN addFile " + name + " >>>"); - if (fs.isReadOnly()) { - throw new ReadOnlyFileSystemException(); - } - if (getEntry(name) != null) { - throw new IOException("File or directory already exists: " + name); - } - FSEntry newEntry = createFileEntry(name); - setFreeEntry(newEntry); - - log.debug("<<< END addFile " + name + " >>>"); - return newEntry; - } - - private final FSEntry createFileEntry(final String name) throws IOException { - /*if (fs.isReadOnly()) { - throw new ReadOnlyFileSystemException(); - } - Catalog catalog = fs.getCatalog(); - Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); - LeafRecord fileRecord = catalog.createNode(name, this.folder - .getFolderId(), new CatalogNodeId(volumeHeader.getNextCatalogId()), CatalogFile.RECORD_TYPE_FILE); - - HFSPlusEntry newEntry = new HFSPlusFile(fs, this, name, folderRecord); - newEntry.setDirty(); - volumeHeader.setFileCount(volumeHeader.getFileCount() + 1); - log.debug("New volume header :\n" + volumeHeader.toString());*/ - - return null; - } - - @Override - public void flush() throws IOException { - log.debug("<<< BEGIN flush >>>"); - if (fs.isReadOnly()) { - throw new ReadOnlyFileSystemException(); - } - boolean flushEntries = isEntriesLoaded() && entries.isDirty(); - if (isDirty() || flushEntries) { - writeEntries(entries); - // entries.resetDirty(); - resetDirty(); - } - log.debug("<<< END flush >>>"); - } - - @Override - public FSEntry getEntry(String name) throws IOException { - checkEntriesLoaded(); - return entries.get(name); - } - - @Override - public Iterator<? extends FSEntry> iterator() throws IOException { - return entries.iterator(); - } - - public int rename(String oldName, String newName) { - return entries.rename(oldName, newName); - } - - @Override - public void remove(String name) throws IOException { - if (fs.isReadOnly()) { - throw new ReadOnlyFileSystemException(); - } - if (entries.remove(name) >= 0) { - setDirty(); - flush(); - return; - } else { - throw new FileNotFoundException(name); - } - } - - // Helper methods - - /** - * BE CAREFULL : don't call this method from the constructor of this class - * because it call the method readEntries of the child classes that are not - * yet initialized (constructed). - */ - protected final void checkEntriesLoaded() { - if (!isEntriesLoaded()) { - log.debug("checkEntriesLoaded : loading"); - try { - if (rights.canRead()) { - entries = readEntries(); - } else { - // the next time, we will call checkEntriesLoaded() - // we will retry to load entries - entries = FSEntryTable.EMPTY_TABLE; - log.debug("checkEntriesLoaded : can't read, using EMPTY_TABLE"); - } - resetDirty(); - } catch (IOException e) { - log.fatal("unable to read directory entries", e); - // the next time, we will call checkEntriesLoaded() - // we will retry to load entries - entries = FSEntryTable.EMPTY_TABLE; - } - } - log.debug("<<< END checkEntriesLoaded >>>"); - } - - /** - * Have we already loaded our entries from device ? - * - * @return if the entries are already loaded from the device - */ - private final boolean isEntriesLoaded() { - return (entries != FSEntryTable.EMPTY_TABLE); - } - - /** - * - * @return - * @throws IOException - */ - private final FSEntryTable readEntries() throws IOException { - List<FSEntry> pathList = new LinkedList<FSEntry>(); - HfsPlusFileSystem fs = (HfsPlusFileSystem) getFileSystem(); - if (fs.getVolumeHeader().getFolderCount() > 0) { - LeafRecord[] records = fs.getCatalog().getRecords(folder.getFolderId()); - for (LeafRecord rec : records) { - if (rec.getType() == CatalogFolder.RECORD_TYPE_FOLDER || - rec.getType() == CatalogFile.RECORD_TYPE_FILE) { - String name = ((CatalogKey) rec.getKey()).getNodeName().getUnicodeString(); - HFSPlusEntry e = new HFSPlusDirectory(fs, this, name, rec); - pathList.add(e); - } - } - } - return new FSEntryTable(((HfsPlusFileSystem) getFileSystem()), pathList); - } - - private void writeEntries(final FSEntryTable entries) throws IOException { - // TODO Auto-generated method stub - } - - /** - * - * @param name - * @return - * @throws IOException - */ - private final FSEntry createDirectoryEntry(final String name) throws IOException { - if (fs.isReadOnly()) { - throw new ReadOnlyFileSystemException(); - } - Catalog catalog = fs.getCatalog(); - Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); - LeafRecord folderRecord = catalog.createNode(name, this.folder.getFolderId(), - new CatalogNodeId(volumeHeader.getNextCatalogId()), CatalogFolder.RECORD_TYPE_FOLDER_THREAD); - folder.setValence(folder.getValence() + 1); - - HFSPlusEntry newEntry = new HFSPlusDirectory(fs, this, name, folderRecord); - newEntry.setDirty(); - volumeHeader.setFolderCount(volumeHeader.getFolderCount() + 1); - log.debug("New volume header :\n" + volumeHeader.toString()); - - return newEntry; - } - - /** - * Find a free entry and set it with the given entry - * - * @param newEntry - * @throws IOException - */ - private final void setFreeEntry(FSEntry newEntry) throws IOException { - checkEntriesLoaded(); - if (entries.setFreeEntry(newEntry) >= 0) { - log.debug("setFreeEntry: free entry found !"); - setDirty(); - flush(); - return; - } - } - -} Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusEntry.java 2009-04-28 07:28:05 UTC (rev 5354) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusEntry.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -1,167 +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; - -import java.io.IOException; - -import org.jnode.fs.FSAccessRights; -import org.jnode.fs.FSDirectory; -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; - -public class HFSPlusEntry implements FSEntry { - - protected HfsPlusFileSystem fs; - protected HFSPlusDirectory parent; - protected String name; - protected LeafRecord record; - private int type; - - protected boolean valid; - protected boolean dirty; - protected FSAccessRights rights; - private long lastModified; - - /** - * - * @param fs - * @param parent - * @param name - * @param record - */ - public HFSPlusEntry(HfsPlusFileSystem fs, HFSPlusDirectory parent, String name, - LeafRecord record) { - this.fs = fs; - this.parent = parent; - this.name = name; - this.record = record; - this.type = getFSEntryType(); - this.rights = new UnixFSAccessRights(fs); - this.lastModified = System.currentTimeMillis(); - } - - private int getFSEntryType() { - int mode = record.getType(); - if ("/".equals(name)) { - return AbstractFSEntry.ROOT_ENTRY; - } else if (mode == CatalogFolder.RECORD_TYPE_FOLDER) { - return AbstractFSEntry.DIR_ENTRY; - } else if (mode == CatalogFile.RECORD_TYPE_FILE) { - return AbstractFSEntry.FILE_ENTRY; - } else { - return AbstractFSEntry.OTHER_ENTRY; - } - } - - @Override - public FSAccessRights getAccessRights() throws IOException { - return rights; - } - - @Override - public FSDirectory getDirectory() throws IOException { - if (!isDirectory()) { - throw new IOException("It is not a Directory"); - } - return (HFSPlusDirectory) this; - } - - @Override - public FSFile getFile() throws IOException { - if (!isFile()) { - throw new IOException("It is not a file"); - } - return (HFSPlusFile) this; - } - - @Override - public long getLastModified() throws IOException { - // TODO Auto-generated method stub - return lastModified; - } - - @Override - public String getName() { - return name; - } - - @Override - public FSDirectory getParent() { - return parent; - } - - @Override - public boolean isDirectory() { - return (type == AbstractFSEntry.DIR_ENTRY || type == AbstractFSEntry.ROOT_ENTRY); - } - - @Override - public boolean isDirty() throws IOException { - return dirty; - } - - public void setDirty() { - dirty = true; - } - - public void resetDirty() { - dirty = false; - } - - @Override - public boolean isFile() { - return (type == AbstractFSEntry.FILE_ENTRY); - } - - @Override - public void setLastModified(long lastModified) throws IOException { - this.lastModified = lastModified; - } - - @Override - public void setName(String newName) throws IOException { - if (type == AbstractFSEntry.ROOT_ENTRY) { - throw new IOException("Cannot change name of root directory"); - } - if (parent.rename(name, newName) < 0) { - throw new IOException("Cannot change name"); - } - - this.name = newName; - } - - @Override - public FileSystem<?> getFileSystem() { - return fs; - } - - @Override - public boolean isValid() { - return valid; - } - -} Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusFile.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusFile.java 2009-04-28 07:28:05 UTC (rev 5354) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusFile.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -1,72 +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; - -import java.io.IOException; -import java.nio.ByteBuffer; - -import org.jnode.fs.FSFile; -import org.jnode.fs.hfsplus.catalog.CatalogFile; -import org.jnode.fs.hfsplus.extent.ExtentDescriptor; -import org.jnode.fs.hfsplus.tree.LeafRecord; - -public class HFSPlusFile extends HFSPlusEntry implements FSFile { - - private CatalogFile file; - - public HFSPlusFile(HfsPlusFileSystem fs, HFSPlusDirectory parent, String name, LeafRecord record) { - super(fs, parent, name, record); - this.file = new CatalogFile(record.getData()); - } - - @Override - public void flush() throws IOException { - - } - - @Override - public final long getLength() { - return file.getDatas().getTotalSize(); - } - - @Override - public final void read(final long fileOffset, final ByteBuffer dest) throws IOException { - HfsPlusFileSystem fs = (HfsPlusFileSystem) getFileSystem(); - for (ExtentDescriptor d : file.getDatas().getExtents()) { - if (!d.isEmpty()) { - long firstOffset = d.getStartOffset(fs.getVolumeHeader().getBlockSize()); - fs.getApi().read(firstOffset, dest); - } - } - } - - @Override - public void write(final long fileOffset, final ByteBuffer src) throws IOException { - // TODO Auto-generated method stub - - } - - public void setLength(final long length) throws IOException { - // TODO Auto-generated method stub - - } - -} Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java 2009-04-28 07:28:05 UTC (rev 5354) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -1,128 +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; - -import org.jnode.fs.hfsplus.extent.ExtentDescriptor; -import org.jnode.util.BigEndian; - -public class HFSPlusForkData { - public static final int FORK_DATA_LENGTH = 80; - private static final int EXTENT_OFFSET = 16; - /** The size in bytes of the valid data in the fork. */ - private long totalSize; - /** */ - private int clumpSize; - /** The total of allocation blocks use by the extents in the fork. */ - private int totalBlock; - /** The first eight extent descriptors for the fork. */ - private ExtentDescriptor[] extents; - - /** - * Create fork data from existing informations. - * - * @param src - * @param offset - */ - public HFSPlusForkData(final byte[] src, final int offset) { - byte[] data = new byte[FORK_DATA_LENGTH]; - System.arraycopy(src, offset, data, 0, FORK_DATA_LENGTH); - totalSize = BigEndian.getInt64(data, 0); - clumpSize = BigEndian.getInt32(data, 8); - totalBlock = BigEndian.getInt32(data, 12); - extents = new ExtentDescriptor[8]; - for (int i = 0; i < 8; i++) { - extents[i] = - new ExtentDescriptor(data, EXTENT_OFFSET + - (i * ExtentDescriptor.EXTENT_DESCRIPTOR_LENGTH)); - } - } - - /** - * - * Create a new empty fork data object. - * - * @param totalSize - * @param clumpSize - * @param totalBlock - */ - public HFSPlusForkData(long totalSize, int clumpSize, int totalBlock) { - this.totalSize = totalSize; - this.clumpSize = clumpSize; - this.totalBlock = totalBlock; - this.extents = new ExtentDescriptor[8]; - for (int i = 0; i < extents.length; i++) { - extents[i] = new ExtentDescriptor(); - } - } - - public byte[] write(byte[] dest, int destOffSet) { - byte[] data = new byte[FORK_DATA_LENGTH]; - BigEndian.setInt64(data, 0, totalSize); - BigEndian.setInt32(data, 8, clumpSize); - BigEndian.setInt32(data, 12, totalBlock); - for (int i = 0; i < extents.length; i++) { - extents[i].write(data, EXTENT_OFFSET + (i * ExtentDescriptor.EXTENT_DESCRIPTOR_LENGTH)); - } - System.arraycopy(data, 0, dest, destOffSet, FORK_DATA_LENGTH); - return dest; - } - - public final String toString() { - StringBuffer s = new StringBuffer(); - s.append("Total size : ").append(totalSize).append("\n"); - s.append("Clump size : ").append(clumpSize).append("\n"); - s.append("Total Blocks : ").append(totalBlock).append("\n"); - for (int i = 0; i < extents.length; i++) { - s.append("Extent[" + i + "]: " + extents[i].toString()); - } - return s.toString(); - } - - public long getTotalSize() { - return totalSize; - } - - public int getClumpSize() { - return clumpSize; - } - - public int getTotalBlocks() { - return totalBlock; - } - - public ExtentDescriptor getExtent(int index) { - return extents[index]; - } - - /** - * - * @param index - * @param desc - */ - public final void addDescriptor(int index, ExtentDescriptor desc) { - extents[index] = desc; - } - - public ExtentDescriptor[] getExtents() { - return extents; - } - -} Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusObject.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusObject.java 2009-04-28 07:28:05 UTC (rev 5354) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusObject.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -1,39 +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; - -import org.jnode.fs.FSObject; - -public class HFSPlusObject implements FSObject { - protected HfsPlusFileSystem fs; - - public HFSPlusObject(final HfsPlusFileSystem fileSystem) { - this.fs = fileSystem; - } - - public final HfsPlusFileSystem getFileSystem() { - return fs; - } - - public final boolean isValid() { - return false; - } -} Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java 2009-04-28 07:28:05 UTC (rev 5354) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -20,6 +20,9 @@ package org.jnode.fs.hfsplus; +import java.io.IOException; + +import org.jnode.driver.ApiNotFoundException; import org.jnode.fs.FileSystemException; public class HFSPlusParams { @@ -66,82 +69,85 @@ } /** + * Initialize default sizes (allocation, catalog node, etc...) * - * @param blockDeviceSize - * @param sectorSize - * + * @param fs * @throws FileSystemException - * + * @throws IOException */ - public void initializeDefaultsValues(long blockDeviceSize, long sectorSize) - throws FileSystemException { - long clumpSize = 0; - this.blockDeviceSize = blockDeviceSize; - if (resourceClumpBlocks == 0) { - if (blockSize > DEFAULT_BLOCK_SIZE) { - clumpSize = round(RESOURCE_CLUMP_FACTOR * DEFAULT_BLOCK_SIZE, blockSize); + public void initializeDefaultsValues(HfsPlusFileSystem fs) + throws FileSystemException, IOException { + try { + long clumpSize = 0; + this.blockDeviceSize = fs.getApi().getLength(); + if (resourceClumpBlocks == 0) { + if (blockSize > DEFAULT_BLOCK_SIZE) { + clumpSize = round(RESOURCE_CLUMP_FACTOR * DEFAULT_BLOCK_SIZE, blockSize); + } else { + clumpSize = RESOURCE_CLUMP_FACTOR * blockSize; + } } else { - clumpSize = RESOURCE_CLUMP_FACTOR * blockSize; + clumpSize = clumpSizeCalculation(resourceClumpBlocks); } - } else { - clumpSize = clumpSizeCalculation(resourceClumpBlocks); - } - resourceClumpSize = (int) clumpSize; - if (dataClumpBlocks == 0) { - if (blockSize > DEFAULT_BLOCK_SIZE) { - clumpSize = round(DATA_CLUMP_FACTOR * DEFAULT_BLOCK_SIZE, blockSize); + resourceClumpSize = (int) clumpSize; + if (dataClumpBlocks == 0) { + if (blockSize > DEFAULT_BLOCK_SIZE) { + clumpSize = round(DATA_CLUMP_FACTOR * DEFAULT_BLOCK_SIZE, blockSize); + } else { + clumpSize = DATA_CLUMP_FACTOR * blockSize; + } } else { - clumpSize = DATA_CLUMP_FACTOR * blockSize; + clumpSize = clumpSizeCalculation(dataClumpBlocks); } - } else { - clumpSize = clumpSizeCalculation(dataClumpBlocks); - } - if (blockSize < OPTIMAL_BLOCK_SIZE || blockDeviceSize < 0x40000000) { - catalogNodeSize = 4096; - } - long sectorCount = blockDeviceSize / sectorSize; - if (catalogClumpBlocks == 0) { - clumpSize = getBTreeClumpSize(blockSize, catalogNodeSize, sectorCount, true); - } else { - clumpSize = clumpSizeCalculation(catalogClumpBlocks); - if (clumpSize % catalogNodeSize != 0) { - throw new FileSystemException("clump size is not a multiple of node size"); + if (blockSize < OPTIMAL_BLOCK_SIZE || blockDeviceSize < 0x40000000) { + catalogNodeSize = 4096; } - } - catalogClumpSize = (int) clumpSize; - if (extentClumpBlocks == 0) { - clumpSize = getBTreeClumpSize(blockSize, extentNodeSize, sectorCount, false); - } else { - clumpSize = clumpSizeCalculation(extentClumpBlocks); - } - extentClumpSize = (int) clumpSize; + long sectorCount = blockDeviceSize / fs.getFSApi().getSectorSize(); + if (catalogClumpBlocks == 0) { + clumpSize = getBTreeClumpSize(blockSize, catalogNodeSize, sectorCount, true); + } else { + clumpSize = clumpSizeCalculation(catalogClumpBlocks); + if (clumpSize % catalogNodeSize != 0) { + throw new FileSystemException("clump size is not a multiple of node size"); + } + } + catalogClumpSize = (int) clumpSize; + if (extentClumpBlocks == 0) { + clumpSize = getBTreeClumpSize(blockSize, extentNodeSize, sectorCount, false); + } else { + clumpSize = clumpSizeCalculation(extentClumpBlocks); + } + extentClumpSize = (int) clumpSize; - if (attributeClumpBlocks == 0) { - clumpSize = 0; - } else { - clumpSize = clumpSizeCalculation(attributeClumpBlocks); - if (clumpSize % attributeNodeSize != 0) { - throw new FileSystemException("clump size is not a multiple of attribute node size"); + if (attributeClumpBlocks == 0) { + clumpSize = 0; + } else { + clumpSize = clumpSizeCalculation(attributeClumpBlocks); + if (clumpSize % attributeNodeSize != 0) { + throw new FileSystemException( + "clump size is not a multiple of attribute node size"); + } } - } - attributeClumpSize = (int) clumpSize; + attributeClumpSize = (int) clumpSize; - long totalBlocks = this.getBlockCount(); - long minClumpSize = this.getBlockCount() >> 3; - if ((totalBlocks & 7) == 0) { - ++minClumpSize; - } - if (bitmapClumpBlocks == 0) { - clumpSize = minClumpSize; - } else { - clumpSize = clumpSizeCalculation(bitmapClumpBlocks); - if (clumpSize < minClumpSize) { - throw new FileSystemException("bitmap clump size is too small."); + long totalBlocks = this.getBlockCount(); + long minClumpSize = this.getBlockCount() >> 3; + if ((totalBlocks & 7) == 0) { + ++minClumpSize; } + if (bitmapClumpBlocks == 0) { + clumpSize = minClumpSize; + } else { + clumpSize = clumpSizeCalculation(bitmapClumpBlocks); + if (clumpSize < minClumpSize) { + throw new FileSystemException("bitmap clump size is too small."); + } + } + allocationClumpSize = (int) clumpSize; + } catch (ApiNotFoundException e) { + throw new FileSystemException("Unable initialize default values.", e); } - allocationClumpSize = (int) clumpSize; - } private int[] extentClumpTable = new int[] {4, 4, 4, 5, 5, 6, 7, 8, 9, 11, 14, 16, 20, 25, 32}; @@ -151,13 +157,13 @@ /** * Get the file clump size for Extent and catalog B-Tree files. * - * @param blockSize - * @param nodeSize - * @param sectors + * @param blockSize Size of a block. + * @param nodeSize Size of a node. + * @param sectors Number of sector for the device. * @param catalog If true, calculate catalog clump size. In the other case, * calculate extent clump size. * - * @return + * @return B-Tree clump size. */ private long getBTreeClumpSize(int blockSize, int nodeSize, long sectors, boolean catalog) { int size = Math.max(blockSize, nodeSize); Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUnicodeString.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUnicodeString.java 2009-04-28 07:28:05 UTC (rev 5354) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUnicodeString.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -1,81 +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; - -import org.jnode.util.BigEndian; - -public class HFSUnicodeString { - /** Length of string in characters. */ - private int length; - - private String string; - - /** - * Create HFSUnicodeString from existing data. - * - * @param src byte array contains data. - * @param offset start of data in the array. - */ - public HFSUnicodeString(final byte[] src, final int offset) { - length = BigEndian.getInt16(src, offset); - byte[] data = new byte[2 + (length * 2)]; - System.arraycopy(src, offset, data, 0, 2); - length = BigEndian.getInt16(data, 0); - data = new byte[length * 2]; - System.arraycopy(src, offset + 2, data, 0, length * 2); - char[] result = new char[length]; - for (int i = 0; i < length; ++i) { - result[i] = BigEndian.getChar(data, i * 2); - } - string = new String(result); - } - - /** - * - * @param string - */ - public HFSUnicodeString(String string) { - this.string = string; - this.length = string.length(); - } - - public final int getLength() { - return length; - } - - public final String getUnicodeString() { - return string; - } - - public final byte[] 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; - } - -} Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUtils.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUtils.java 2009-04-28 07:28:05 UTC (rev 5354) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSUtils.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -1,72 +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; - -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; - -public class HFSUtils { - - /** - * Difference in second between 01/01/1970 00:00:00 (java reference time) - * and 01/01/1904 00:00:00 (HFS reference time). - */ - public static final long MAC_DATE_CONVERSION = 2082844800L; - - /** - * Convert time from/to java time to/from mac time. - * - * @param time in seconds since reference date. - * @param encode if {code true}, convert from java to mac, otherwise - * convert from mac to java. - * - * @return the converted time - */ - public static long getDate(long time, boolean encode) { - time = (encode) ? time + MAC_DATE_CONVERSION : time - MAC_DATE_CONVERSION; - return time; - } - - /** - * - * @param time a date/time in seconds since the UNIX epoch. - * @param dateFormat the date/time format string - * @return the date/time formatted as a String - */ - public static String printDate(final long time, final String dateFormat) { - Calendar cal = Calendar.getInstance(); - cal.setTimeInMillis(getDate(time, false) * 1000); - SimpleDateFormat sdf = new SimpleDateFormat(dateFormat); - return sdf.format(cal.getTime()); - } - - /** - * Returns current date and time in mac format. - * - * @return current date and time. - */ - public static int getNow() { - Calendar now = Calendar.getInstance(); - now.setTime(new Date()); - return (int) HFSUtils.getDate(now.getTimeInMillis() / 1000, true); - } -} Copied: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusBSDInfo.java (from rev 5353, trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusBSDInfo.java) =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusBSDInfo.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusBSDInfo.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -0,0 +1,5 @@ +package org.jnode.fs.hfsplus; + +public class HfsPlusBSDInfo { + +} Copied: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java (from rev 5353, trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java) =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -0,0 +1,255 @@ +/* + * $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; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.apache.log4j.Logger; +import org.jnode.fs.FSDirectory; +import org.jnode.fs.FSEntry; +import org.jnode.fs.ReadOnlyFileSystemException; +import org.jnode.fs.hfsplus.catalog.Catalog; +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; +import org.jnode.fs.hfsplus.tree.LeafRecord; +import org.jnode.fs.spi.FSEntryTable; + +public class HfsPlusDirectory extends HfsPlusEntry implements FSDirectory { + + private static final Logger log = Logger.getLogger(HfsPlusDirectory.class); + + /** Table of entries of our parent */ + private FSEntryTable entries; + + private CatalogFolder folder; + + public HfsPlusDirectory(HfsPlusFileSystem fs, HfsPlusDirectory parent, String name, + LeafRecord record) { + super(fs, parent, name, record); + this.folder = new CatalogFolder(record.getData()); + this.entries = FSEntryTable.EMPTY_TABLE; + } + + @Override + public FSEntry addDirectory(String name) throws IOException { + log.debug("<<< BEGIN addDirectory " + name + " >>>"); + if (fs.isReadOnly()) { + throw new ReadOnlyFileSystemException(); + } + + if (getEntry(name) != null) { + throw new IOException("File or Directory already exists" + name); + } + FSEntry newEntry = createDirectoryEntry(name); + setFreeEntry(newEntry); + log.debug("<<< END addDirectory " + name + " >>>"); + return newEntry; + } + + @Override + public FSEntry addFile(String name) throws IOException { + log.debug("<<< BEGIN addFile " + name + " >>>"); + if (fs.isReadOnly()) { + throw new ReadOnlyFileSystemException(); + } + if (getEntry(name) != null) { + throw new IOException("File or directory already exists: " + name); + } + FSEntry newEntry = createFileEntry(name); + setFreeEntry(newEntry); + + log.debug("<<< END addFile " + name + " >>>"); + return newEntry; + } + + private final FSEntry createFileEntry(final String name) throws IOException { + /*if (fs.isReadOnly()) { + throw new ReadOnlyFileSystemException(); + } + Catalog catalog = fs.getCatalog(); + Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); + LeafRecord fileRecord = catalog.createNode(name, this.folder + .getFolderId(), new CatalogNodeId(volumeHeader.getNextCatalogId()), CatalogFile.RECORD_TYPE_FILE); + + HFSPlusEntry newEntry = new HFSPlusFile(fs, this, name, folderRecord); + newEntry.setDirty(); + volumeHeader.setFileCount(volumeHeader.getFileCount() + 1); + log.debug("New volume header :\n" + volumeHeader.toString());*/ + + return null; + } + + @Override + public void flush() throws IOException { + log.debug("<<< BEGIN flush >>>"); + if (fs.isReadOnly()) { + throw new ReadOnlyFileSystemException(); + } + boolean flushEntries = isEntriesLoaded() && entries.isDirty(); + if (isDirty() || flushEntries) { + writeEntries(entries); + // entries.resetDirty(); + resetDirty(); + } + log.debug("<<< END flush >>>"); + } + + @Override + public FSEntry getEntry(String name) throws IOException { + checkEntriesLoaded(); + return entries.get(name); + } + + @Override + public Iterator<? extends FSEntry> iterator() throws IOException { + return entries.iterator(); + } + + public int rename(String oldName, String newName) { + return entries.rename(oldName, newName); + } + + @Override + public void remove(String name) throws IOException { + if (fs.isReadOnly()) { + throw new ReadOnlyFileSystemException(); + } + if (entries.remove(name) >= 0) { + setDirty(); + flush(); + return; + } else { + throw new FileNotFoundException(name); + } + } + + // Helper methods + + /** + * BE CAREFULL : don't call this method from the constructor of this class + * because it call the method readEntries of the child classes that are not + * yet initialized (constructed). + */ + protected final void checkEntriesLoaded() { + if (!isEntriesLoaded()) { + log.debug("checkEntriesLoaded : loading"); + try { + if (rights.canRead()) { + entries = readEntries(); + } else { + // the next time, we will call checkEntriesLoaded() + // we will retry to load entries + entries = FSEntryTable.EMPTY_TABLE; + log.debug("checkEntriesLoaded : can't read, using EMPTY_TABLE"); + } + resetDirty(); + } catch (IOException e) { + log.fatal("unable to read directory entries", e); + // the next time, we will call checkEntriesLoaded() + // we will retry to load entries + entries = FSEntryTable.EMPTY_TABLE; + } + } + log.debug("<<< END checkEntriesLoaded >>>"); + } + + /** + * Have we already loaded our entries from device ? + * + * @return if the entries are already loaded from the device + */ + private final boolean isEntriesLoaded() { + return (entries != FSEntryTable.EMPTY_TABLE); + } + + /** + * + * @return + * @throws IOException + */ + private final FSEntryTable readEntries() throws IOException { + List<FSEntry> pathList = new LinkedList<FSEntry>(); + HfsPlusFileSystem fs = (HfsPlusFileSystem) getFileSystem(); + if (fs.getVolumeHeader().getFolderCount() > 0) { + LeafRecord[] records = fs.getCatalog().getRecords(folder.getFolderId()); + for (LeafRecord rec : records) { + if (rec.getType() == CatalogFolder.RECORD_TYPE_FOLDER || + rec.getType() == CatalogFile.RECORD_TYPE_FILE) { + String name = ((CatalogKey) rec.getKey()).getNodeName().getUnicodeString(); + HfsPlusEntry e = new HfsPlusDirectory(fs, this, name, rec); + pathList.add(e); + } + } + } + return new FSEntryTable(((HfsPlusFileSystem) getFileSystem()), pathList); + } + + private void writeEntries(final FSEntryTable entries) throws IOException { + // TODO Auto-generated method stub + } + + /** + * + * @param name + * @return + * @throws IOException + */ + private final FSEntry createDirectoryEntry(final String name) throws IOException { + if (fs.isReadOnly()) { + throw new ReadOnlyFileSystemException(); + } + Catalog catalog = fs.getCatalog(); + Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); + LeafRecord folderRecord = catalog.createNode(name, this.folder.getFolderId(), + new CatalogNodeId(volumeHeader.getNextCatalogId()), CatalogFolder.RECORD_TYPE_FOLDER_THREAD); + folder.setValence(folder.getValence() + 1); + + HfsPlusEntry newEntry = new HfsPlusDirectory(fs, this, name, folderRecord); + newEntry.setDirty(); + volumeHeader.setFolderCount(volumeHeader.getFolderCount() + 1); + log.debug("New volume header :\n" + volumeHeader.toString()); + + return newEntry; + } + + /** + * Find a free entry and set it with the given entry + * + * @param newEntry + * @throws IOException + */ + private final void setFreeEntry(FSEntry newEntry) throws IOException { + checkEntriesLoaded(); + if (entries.setFreeEntry(newEntry) >= 0) { + log.debug("setFreeEntry: free entry found !"); + setDirty(); + flush(); + return; + } + } + +} Copied: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusEntry.java (from rev 5353, trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusEntry.java) =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusEntry.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusEntry.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -0,0 +1,167 @@ +/* + * $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; + +import java.io.IOException; + +import org.jnode.fs.FSAccessRights; +import org.jnode.fs.FSDirectory; +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; + +public class HfsPlusEntry implements FSEntry { + + protected HfsPlusFileSystem fs; + protected HfsPlusDirectory parent; + protected String name; + protected LeafRecord record; + private int type; + + protected boolean valid; + protected boolean dirty; + protected FSAccessRights rights; + private long lastModified; + + /** + * + * @param fs + * @param parent + * @param name + * @param record + */ + public HfsPlusEntry(HfsPlusFileSystem fs, HfsPlusDirectory parent, String name, + LeafRecord record) { + this.fs = fs; + this.parent = parent; + this.name = name; + this.record = record; + this.type = getFSEntryType(); + this.rights = new UnixFSAccessRights(fs); + this.lastModified = System.currentTimeMillis(); + } + + private int getFSEntryType() { + int mode = record.getType(); + if ("/".equals(name)) { + return AbstractFSEntry.ROOT_ENTRY; + } else if (mode == CatalogFolder.RECORD_TYPE_FOLDER) { + return AbstractFSEntry.DIR_ENTRY; + } else if (mode == CatalogFile.RECORD_TYPE_FILE) { + return AbstractFSEntry.FILE_ENTRY; + } else { + return AbstractFSEntry.OTHER_ENTRY; + } + } + + @Override + public FSAccessRights getAccessRights() throws IOException { + return rights; + } + + @Override + public FSDirectory getDirectory() throws IOException { + if (!isDirectory()) { + throw new IOException("It is not a Directory"); + } + return (HfsPlusDirectory) this; + } + + @Override + public FSFile getFile() throws IOException { + if (!isFile()) { + throw new IOException("It is not a file"); + } + return (HfsPlusFile) this; + } + + @Override + public long getLastModified() throws IOException { + // TODO Auto-generated method stub + return lastModified; + } + + @Override + public String getName() { + return name; + } + + @Override + public FSDirectory getParent() { + return parent; + } + + @Override + public boolean isDirectory() { + return (type == AbstractFSEntry.DIR_ENTRY || type == AbstractFSEntry.ROOT_ENTRY); + } + + @Override + public boolean isDirty() throws IOException { + return dirty; + } + + public void setDirty() { + dirty = true; + } + + public void resetDirty() { + dirty = false; + } + + @Override + public boolean isFile() { + return (type == AbstractFSEntry.FILE_ENTRY); + } + + @Override + public void setLastModified(long lastModified) throws IOException { + this.lastModified = lastModified; + } + + @Override + public void setName(String newName) throws IOException { + if (type == AbstractFSEntry.ROOT_ENTRY) { + throw new IOException("Cannot change name of root directory"); + } + if (parent.rename(name, newName) < 0) { + throw new IOException("Cannot change name"); + } + + this.name = newName; + } + + @Override + public FileSystem<?> getFileSystem() { + return fs; + } + + @Override + public boolean isValid() { + return valid; + } + +} Copied: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFile.java (from rev 5353, trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusFile.java) =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFile.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFile.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -0,0 +1,72 @@ +/* + * $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; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jnode.fs.FSFile; +import org.jnode.fs.hfsplus.catalog.CatalogFile; +import org.jnode.fs.hfsplus.extent.ExtentDescriptor; +import org.jnode.fs.hfsplus.tree.LeafRecord; + +public class HfsPlusFile extends HfsPlusEntry implements FSFile { + + private CatalogFile file; + + public HfsPlusFile(HfsPlusFileSystem fs, HfsPlusDirectory parent, String name, LeafRecord record) { + super(fs, parent, name, record); + this.file = new CatalogFile(record.getData()); + } + + @Override + public void flush() throws IOException { + + } + + @Override + public final long getLength() { + return file.getDatas().getTotalSize(); + } + + @Override + public final void read(final long fileOffset, final ByteBuffer dest) throws IOException { + HfsPlusFileSystem fs = (HfsPlusFileSystem) getFileSystem(); + for (ExtentDescriptor d : file.getDatas().getExtents()) { + if (!d.isEmpty()) { + long firstOffset = d.getStartOffset(fs.getVolumeHeader().getBlockSize()); + fs.getApi().read(firstOffset, dest); + } + } + } + + @Override + public void write(final long fileOffset, final ByteBuffer src) throws IOException { + // TODO Auto-generated method stub + + } + + public void setLength(final long length) throws IOException { + // TODO Auto-generated method stub + + } + +} Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-04-28 07:28:05 UTC (rev 5354) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-04-28 08:39:26 UTC (rev 5355) @@ -21,7 +21,6 @@ package org.jnode.fs.hfsplus; import java.io.IOException; -import java.nio.ByteBuffer; import org.apache.log4j.Logger; import org.jnode.driver.ApiNotFoundException; @@ -35,11 +34,11 @@ import org.jnode.fs.hfsplus.tree.LeafRecord; import org.jnode.fs.spi.AbstractFileSystem; -public class HfsPlusFileSystem extends AbstractFileSystem<HFSPlusEntry> { +public class HfsPlusFileSystem extends AbstractFileSystem<HfsPlusEntry> { private final Logger log = Logger.getLogger(getClass()); /** HFS volume header */ - private Superblock sb; + private Superblock volumeHeader; /** Catalog special file for this instance */ private Catalog catalog; @@ -61,18 +60,18 @@ * @throws FileSystemException */ public final void read() throws FileSystemException { - sb = new Superblock(this, false); - log.debug(sb.toString()); - if (!sb.isAttribute(Superblock.HFSPLUS_VOL_UNMNT_BIT)) { + volumeHeader = new Superblock(this, false); + log.debug(volumeHeader.toString()); + if (!volumeHeader.isAttribute(Superblock.HFSPLUS_VOL_UNMNT_BIT)) { log.info(getDevice().getId() + " Filesystem has not been cleanly unmounted, mounting it readonly"); setReadOnly(true); } - if (sb.isAttribute(Superblock.HFSPLUS_VOL_SOFTLOCK_BIT)) { + if (volumeHeader.isAttribute(Superblock.HFSPLUS_VOL_SOFTLOCK_BIT)) { log.info(getDevice().getId() + " Filesystem is marked locked, mounting it readonly"); setReadOnly(true); } - if (sb.isAttribute(Superblock.HFSPLUS_VOL_JOURNALED_BIT)) { + if (volumeHeader.isAttribute(Superblock.HFSPLUS_VOL_JOURNALED_BIT)) { log .info(getDevice().getId() + " Filesystem is journaled, write access is not supported. Mounting it readonly"); @@ -96,11 +95,11 @@ } @Override - protected final HFSPlusEntry createRootEntry() throws IOException { + protected final HfsPlusEntry createRootEntry() throws IOException { log.info("Create root entry."); LeafRecord record = catalog.getRecord(CatalogNodeId.HFSPLUS_POR_CNID); if (record != null) { - return new HFSPlusDirectory(this, null, "/", record); + return new HfsPlusDirectory(this, null, "/", record); } log.error("Root entry : No record found."); return null; @@ -112,7 +111,7 @@ * @see org.jnode.fs.FileSystem#getFreeSpace() */ public final long getFreeSpace() { - return sb.getFreeBlocks() * sb.getBlockSize(); + return volumeHeader.getFreeBlocks() * volumeHeader.getBlockSize(); } /* @@ -121,7 +120,7 @@ * @see org.jnode.fs.FileSystem#getTotalSpace() */ public final long getTotalSpace() { - return sb.getTotalBlocks() * sb.getBlockSize(); + return volumeHeader.getTotalBlocks() * volumeHeader.getBlockSize(); } /* @@ -138,41 +137,36 @@ } public final Superblock getVolumeHeader() { - return sb; + return volumeHeader; } /** + * Create a new HFS+ file system. * - * @param params + * @param params creation parameters * * @throws FileSystemException */ public void create(HFSPlusParams params) throws FileSystemException { - sb = new Superblock(this, true); + volumeHeader = new Superblock(this, true); try { - params.initializeDefaultsValues(this.getApi().getLength(), this.getFSApi() - .getSectorSize()); - sb.create(params); - log.debug(sb.toString()); - // --... [truncated message content] |
From: <ga...@us...> - 2009-07-22 13:28:55
|
Revision: 5617 http://jnode.svn.sourceforge.net/jnode/?rev=5617&view=rev Author: galatnm Date: 2009-07-22 13:28:52 +0000 (Wed, 22 Jul 2009) Log Message: ----------- Check remaining space when insert a record in a node. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-07-22 10:07:29 UTC (rev 5616) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2009-07-22 13:28:52 UTC (rev 5617) @@ -42,8 +42,8 @@ public CatalogNode(NodeDescriptor descriptor, final int nodeSize) { this.descriptor = descriptor; this.size = nodeSize; - this.records = new ArrayList<NodeRecord>(this.descriptor.getNumRecords()); - this.offsets = new ArrayList<Integer>(this.descriptor.getNumRecords() + 1); + this.records = new ArrayList<NodeRecord>(descriptor.getNumRecords()); + this.offsets = new ArrayList<Integer>(descriptor.getNumRecords() + 1); this.offsets.add(Integer.valueOf(NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH)); } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-07-22 10:07:29 UTC (rev 5616) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-07-22 13:28:52 UTC (rev 5617) @@ -52,13 +52,40 @@ public abstract NodeRecord getNodeRecord(int index); @Override - public void addNodeRecord(NodeRecord record) { + public boolean addNodeRecord(NodeRecord record) { + int freeSpace = getFreeSize(); + if(freeSpace < record.getSize() + 2){ + return false; + } Integer lastOffset = offsets.get(offsets.size() - 1); Integer newOffset = lastOffset + record.getSize(); offsets.add(newOffset); records.add(record); + return true; } - + + public boolean check(int treeHeigth){ + // Node type is correct. + if(this.getNodeDescriptor().getKind() < NodeDescriptor.BT_LEAF_NODE || this.getNodeDescriptor().getKind() > NodeDescriptor.BT_MAP_NODE){ + return false; + } + + if(this.getNodeDescriptor().getHeight() > treeHeigth){ + return false; + } + return true; + } + + /** + * Return amount of free space remaining. + * @return remaining free space. + */ + protected int getFreeSize(){ + int freeOffset = offsets.get(offsets.size() - 1); + int freeSize = size - freeOffset - (descriptor.getNumRecords() << 1) - OFFSET_SIZE; + return freeSize; + } + public byte[] getBytes() { byte[] datas = new byte[size]; System.arraycopy(descriptor.getBytes(), 0, datas, 0, NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java 2009-07-22 10:07:29 UTC (rev 5616) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java 2009-07-22 13:28:52 UTC (rev 5617) @@ -17,16 +17,29 @@ * 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; +public interface Node { + public final static int OFFSET_SIZE = 2; -public interface Node { public NodeDescriptor getNodeDescriptor(); + public boolean isIndexNode(); + public boolean isLeafNode(); + public int getRecordOffset(int index); + public NodeRecord getNodeRecord(int index); - public void addNodeRecord(NodeRecord record); + + /** + * Insert a record in the node. + * + * @param record The record to insert. + * @return True if record is correctly inserted, false if there is not + * enough place to insert the record. + */ + public boolean addNodeRecord(NodeRecord record); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2009-08-10 21:17:50
|
Revision: 5636 http://jnode.svn.sourceforge.net/jnode/?rev=5636&view=rev Author: galatnm Date: 2009-08-10 21:17:38 +0000 (Mon, 10 Aug 2009) Log Message: ----------- CheckStyle. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemFormatter.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusObject.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsUnicodeString.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsUtils.java trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -159,7 +159,7 @@ * * @param blockSize Size of a block. * @param nodeSize Size of a node. - * @param sectors Number of sector for the device. + * @param sectors Number of sector for the device. * @param catalog If true, calculate catalog clump size. In the other case, * calculate extent clump size. * Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -87,18 +87,19 @@ } private final FSEntry createFileEntry(final String name) throws IOException { - /*if (fs.isReadOnly()) { - throw new ReadOnlyFileSystemException(); - } - Catalog catalog = fs.getCatalog(); - Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); - LeafRecord fileRecord = catalog.createNode(name, this.folder - .getFolderId(), new CatalogNodeId(volumeHeader.getNextCatalogId()), CatalogFile.RECORD_TYPE_FILE); - - HFSPlusEntry newEntry = new HFSPlusFile(fs, this, name, folderRecord); - newEntry.setDirty(); - volumeHeader.setFileCount(volumeHeader.getFileCount() + 1); - log.debug("New volume header :\n" + volumeHeader.toString());*/ + /* + * if (fs.isReadOnly()) { throw new ReadOnlyFileSystemException(); } + * Catalog catalog = fs.getCatalog(); Superblock volumeHeader = + * ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); LeafRecord + * fileRecord = catalog.createNode(name, this.folder .getFolderId(), new + * CatalogNodeId(volumeHeader.getNextCatalogId()), + * CatalogFile.RECORD_TYPE_FILE); + * + * HFSPlusEntry newEntry = new HFSPlusFile(fs, this, name, + * folderRecord); newEntry.setDirty(); + * volumeHeader.setFileCount(volumeHeader.getFileCount() + 1); + * log.debug("New volume header :\n" + volumeHeader.toString()); + */ return null; } @@ -224,10 +225,11 @@ } Catalog catalog = fs.getCatalog(); Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); - LeafRecord folderRecord = catalog.createNode(name, this.folder.getFolderId(), - new CatalogNodeId(volumeHeader.getNextCatalogId()), CatalogFolder.RECORD_TYPE_FOLDER_THREAD); + LeafRecord folderRecord = + catalog.createNode(name, this.folder.getFolderId(), new CatalogNodeId(volumeHeader + .getNextCatalogId()), CatalogFolder.RECORD_TYPE_FOLDER_THREAD); folder.setValence(folder.getValence() + 1); - + HfsPlusEntry newEntry = new HfsPlusDirectory(fs, this, name, folderRecord); newEntry.setDirty(); volumeHeader.setFolderCount(volumeHeader.getFolderCount() + 1); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -153,8 +153,8 @@ volumeHeader.create(params); log.debug("Volume header : \n" + volumeHeader.toString()); long volumeBlockUsed = - volumeHeader.getTotalBlocks() - volumeHeader.getFreeBlocks() - ((volumeHeader.getBlockSize() == 512) ? - 2 : 1); + volumeHeader.getTotalBlocks() - volumeHeader.getFreeBlocks() - + ((volumeHeader.getBlockSize() == 512) ? 2 : 1); // --- log.debug("Write allocation bitmap bits to disk."); writeAllocationFile((int) volumeBlockUsed); @@ -166,7 +166,7 @@ flush(); } catch (IOException e) { throw new FileSystemException("Unable to create HFS+ filesystem", e); - } + } } private void writeAllocationFile(int blockUsed) { Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemFormatter.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemFormatter.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemFormatter.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -17,7 +17,7 @@ * 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; import javax.naming.NameNotFoundException; @@ -29,9 +29,9 @@ import org.jnode.naming.InitialNaming; public class HfsPlusFileSystemFormatter extends Formatter<HfsPlusFileSystem> { - + private HFSPlusParams params; - + public HfsPlusFileSystemFormatter(HFSPlusParams params) { super(new HfsPlusFileSystemType()); this.params = params; Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -17,7 +17,7 @@ * 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; import java.io.IOException; @@ -35,7 +35,8 @@ public class HfsPlusFileSystemType implements BlockDeviceFileSystemType<HfsPlusFileSystem> { public static final Class<HfsPlusFileSystemType> ID = HfsPlusFileSystemType.class; - public final HfsPlusFileSystem create(final Device device, final boolean readOnly) throws FileSystemException { + public final HfsPlusFileSystem create(final Device device, final boolean readOnly) + throws FileSystemException { HfsPlusFileSystem fs = new HfsPlusFileSystem(device, readOnly, this); fs.read(); return fs; @@ -45,7 +46,7 @@ return "HFS+"; } - public final boolean supports(final PartitionTableEntry pte, final byte[] firstSector, + public final boolean supports(final PartitionTableEntry pte, final byte[] firstSector, final FSBlockDeviceAPI devApi) { if (pte != null) { if (pte instanceof IBMPartitionTableEntry) { Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusObject.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusObject.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusObject.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -17,7 +17,7 @@ * 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; import org.jnode.fs.FSObject; Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsUnicodeString.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsUnicodeString.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsUnicodeString.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -17,7 +17,7 @@ * 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; import org.jnode.util.BigEndian; Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsUtils.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsUtils.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsUtils.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -36,8 +36,8 @@ * Convert time from/to java time to/from mac time. * * @param time in seconds since reference date. - * @param encode if {code true}, convert from java to mac, otherwise - * convert from mac to java. + * @param encode if {code true}, convert from java to mac, otherwise convert + * from mac to java. * * @return the converted time */ Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -27,6 +27,7 @@ import org.apache.log4j.Level; import org.apache.log4j.Logger; +import org.jnode.driver.ApiNotFoundException; import org.jnode.fs.FileSystemException; import org.jnode.fs.hfsplus.catalog.CatalogNodeId; import org.jnode.fs.hfsplus.extent.ExtentDescriptor; @@ -105,8 +106,7 @@ * @throws ApiNotFoundException * @throws FileSystemException */ - public void create(HFSPlusParams params) - throws IOException { + public void create(HFSPlusParams params) throws IOException { log.info("Create new HFS+ volume header (" + params.getVolumeName() + ") with block size of " + params.getBlockSize() + " bytes."); int burnedBlocksBeforeVH = 0; @@ -434,7 +434,7 @@ public byte[] getBytes() { return data; } - + public void update() throws IOException { fs.getApi().write(1024, ByteBuffer.wrap(data)); } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -17,7 +17,7 @@ * 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 java.util.List; @@ -54,7 +54,7 @@ @Override public boolean addNodeRecord(NodeRecord record) { int freeSpace = getFreeSize(); - if(freeSpace < record.getSize() + 2){ + if (freeSpace < record.getSize() + 2) { return false; } Integer lastOffset = offsets.get(offsets.size() - 1); @@ -63,32 +63,35 @@ records.add(record); return true; } - - public boolean check(int treeHeigth){ + + public boolean check(int treeHeigth) { // Node type is correct. - if(this.getNodeDescriptor().getKind() < NodeDescriptor.BT_LEAF_NODE || this.getNodeDescriptor().getKind() > NodeDescriptor.BT_MAP_NODE){ + if (this.getNodeDescriptor().getKind() < NodeDescriptor.BT_LEAF_NODE || + this.getNodeDescriptor().getKind() > NodeDescriptor.BT_MAP_NODE) { return false; } - - if(this.getNodeDescriptor().getHeight() > treeHeigth){ + + if (this.getNodeDescriptor().getHeight() > treeHeigth) { return false; } return true; } - + /** * Return amount of free space remaining. + * * @return remaining free space. */ - protected int getFreeSize(){ + protected int getFreeSize() { int freeOffset = offsets.get(offsets.size() - 1); int freeSize = size - freeOffset - (descriptor.getNumRecords() << 1) - OFFSET_SIZE; return freeSize; } - + public byte[] getBytes() { byte[] datas = new byte[size]; - System.arraycopy(descriptor.getBytes(), 0, datas, 0, NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); + System.arraycopy(descriptor.getBytes(), 0, datas, 0, + NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH); int offsetIndex = 0; int offset; for (NodeRecord record : records) { @@ -101,13 +104,13 @@ BigEndian.setInt16(datas, size - ((offsetIndex + 1) * 2), offset); return datas; } - + public String toString() { StringBuffer b = new StringBuffer(); b.append((this.isLeafNode()) ? "Leaf node" : "Index node").append("\n"); b.append(this.getNodeDescriptor().toString()).append("\n"); b.append("Offsets : ").append(offsets.toString()); return b.toString(); - + } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java 2009-08-09 19:03:40 UTC (rev 5635) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java 2009-08-10 21:17:38 UTC (rev 5636) @@ -22,7 +22,7 @@ public interface Node { - public final static int OFFSET_SIZE = 2; + public static final int OFFSET_SIZE = 2; public NodeDescriptor getNodeDescriptor(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2011-08-04 12:57:54
|
Revision: 5843 http://jnode.svn.sourceforge.net/jnode/?rev=5843&view=rev Author: galatnm Date: 2011-08-04 12:57:47 +0000 (Thu, 04 Aug 2011) Log Message: ----------- Fix HFS+ cast exception. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/NodeDescriptor.java Added Paths: ----------- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogIndexNode.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogLeafNode.java Removed Paths: ------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2011-08-02 20:04:52 UTC (rev 5842) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2011-08-04 12:57:47 UTC (rev 5843) @@ -17,7 +17,7 @@ * 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; import java.io.FileNotFoundException; @@ -127,6 +127,7 @@ @Override public Iterator<? extends FSEntry> iterator() throws IOException { + checkEntriesLoaded(); return entries.iterator(); } @@ -161,6 +162,7 @@ try { if (rights.canRead()) { entries = readEntries(); + log.debug("Load " + entries.size() + " entrie(s)."); } else { // the next time, we will call checkEntriesLoaded() // we will retry to load entries @@ -226,8 +228,9 @@ Catalog catalog = fs.getCatalog(); Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); LeafRecord folderRecord = - catalog.createNode(name, this.folder.getFolderId(), new CatalogNodeId(volumeHeader - .getNextCatalogId()), CatalogFolder.RECORD_TYPE_FOLDER_THREAD); + catalog.createNode(name, this.folder.getFolderId(), + new CatalogNodeId(volumeHeader.getNextCatalogId()), + CatalogFolder.RECORD_TYPE_FOLDER_THREAD); folder.setValence(folder.getValence() + 1); HfsPlusEntry newEntry = new HfsPlusDirectory(fs, this, name, folderRecord); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2011-08-02 20:04:52 UTC (rev 5842) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2011-08-04 12:57:47 UTC (rev 5843) @@ -17,7 +17,7 @@ * 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.catalog; import java.io.IOException; @@ -27,8 +27,8 @@ import org.apache.log4j.Logger; import org.jnode.fs.hfsplus.HFSPlusParams; +import org.jnode.fs.hfsplus.HfsPlusFileSystem; import org.jnode.fs.hfsplus.HfsUnicodeString; -import org.jnode.fs.hfsplus.HfsPlusFileSystem; import org.jnode.fs.hfsplus.Superblock; import org.jnode.fs.hfsplus.extent.ExtentDescriptor; import org.jnode.fs.hfsplus.tree.BTHeaderRecord; @@ -41,19 +41,19 @@ private final Logger log = Logger.getLogger(getClass()); private HfsPlusFileSystem fs; - + /** * B-Tree node descriptor */ private NodeDescriptor btnd; - + /** * B-Tree Header record */ private BTHeaderRecord bthr; - + private int catalogHeaderNodeOffset; - + private ByteBuffer buffer; /** @@ -84,7 +84,7 @@ } } - + /** * Create new Catalog * @@ -105,8 +105,8 @@ log.info("Create catalog header record."); bthr = new BTHeaderRecord(1, 1, params.getInitializeNumRecords(), 1, 1, nodeSize, - CatalogKey.MAXIMUM_KEY_LENGTH, totalNodes, freeNodes, params - .getCatalogClumpSize(), BTHeaderRecord.BT_TYPE_HFS, + CatalogKey.MAXIMUM_KEY_LENGTH, totalNodes, freeNodes, + params.getCatalogClumpSize(), BTHeaderRecord.BT_TYPE_HFS, BTHeaderRecord.KEY_COMPARE_TYPE_CASE_FOLDING, BTHeaderRecord.BT_VARIABLE_INDEX_KEYS_MASK + BTHeaderRecord.BT_BIG_KEYS_MASK); @@ -117,9 +117,9 @@ bufferLength += (rootNodePosition - bufferLength); // Create node descriptor NodeDescriptor nd = - new NodeDescriptor(0, 0, NodeDescriptor.BT_LEAF_NODE, 1, params - .getInitializeNumRecords()); - CatalogNode rootNode = new CatalogNode(nd, nodeSize); + new NodeDescriptor(0, 0, NodeDescriptor.BT_LEAF_NODE, 1, + params.getInitializeNumRecords()); + CatalogLeafNode rootNode = new CatalogLeafNode(nd, nodeSize); // First record (folder) HfsUnicodeString name = new HfsUnicodeString(params.getVolumeName()); CatalogKey ck = new CatalogKey(CatalogNodeId.HFSPLUS_POR_CNID, name); @@ -142,6 +142,7 @@ buffer.put(rootNode.getBytes()); buffer.rewind(); } + /** * Save catalog file to disk. * @@ -168,7 +169,7 @@ LeafRecord record = this.getRecord(parentId, name); if (record == null) { NodeDescriptor nd = new NodeDescriptor(0, 0, NodeDescriptor.BT_LEAF_NODE, 1, 2); - CatalogNode node = new CatalogNode(nd, 8192); + CatalogLeafNode node = new CatalogLeafNode(nd, 8192); CatalogKey key = new CatalogKey(parentId, name); CatalogThread thread = new CatalogThread(nodeType, parentId, name); record = new LeafRecord(key, thread.getBytes()); @@ -185,7 +186,7 @@ } return record; } - + /** * @param parentID * @return the leaf record, or possibly {code null}. @@ -200,18 +201,21 @@ nodeData); nodeData.rewind(); byte[] data = ByteBufferUtils.toArray(nodeData); - CatalogNode node = new CatalogNode(data, nodeSize); - while (node.isIndexNode()) { + NodeDescriptor nd = new NodeDescriptor(nodeData.array(), 0); + + while (nd.isIndexNode()) { + CatalogIndexNode node = new CatalogIndexNode(data, nodeSize); IndexRecord record = (IndexRecord) node.find(parentID); currentOffset = catalogHeaderNodeOffset + (record.getIndex() * nodeSize); nodeData = ByteBuffer.allocate(nodeSize); fs.getApi().read(currentOffset, nodeData); nodeData.rewind(); data = ByteBufferUtils.toArray(nodeData); - node = new CatalogNode(data, nodeSize); + nd = new NodeDescriptor(nodeData.array(), 0); } - if (node.isLeafNode()) { + if (nd.isLeafNode()) { + CatalogLeafNode node = new CatalogLeafNode(data, nodeSize); lr = (LeafRecord) node.find(parentID); } return lr; @@ -245,9 +249,10 @@ int nodeSize = getBTHeaderRecord().getNodeSize(); ByteBuffer nodeData = ByteBuffer.allocate(nodeSize); fs.getApi().read(catalogHeaderNodeOffset + (currentNodeNumber * nodeSize), nodeData); - CatalogNode node = new CatalogNode(nodeData.array(), nodeSize); - if (node.isIndexNode()) { - IndexRecord[] records = (IndexRecord[]) node.findChildren(parentID); + NodeDescriptor nd = new NodeDescriptor(nodeData.array(), 0); + if (nd.isIndexNode()) { + CatalogIndexNode node = new CatalogIndexNode(nodeData.array(), nodeSize); + IndexRecord[] records = (IndexRecord[]) node.findAll(parentID); List<LeafRecord> lfList = new LinkedList<LeafRecord>(); for (IndexRecord rec : records) { LeafRecord[] lfr = getRecords(parentID, rec.getIndex()); @@ -256,7 +261,8 @@ } } return lfList.toArray(new LeafRecord[lfList.size()]); - } else if (node.isLeafNode()) { + } else if (nd.isLeafNode()) { + CatalogLeafNode node = new CatalogLeafNode(nodeData.array(), nodeSize); return (LeafRecord[]) node.findAll(parentID); } else { return null; @@ -280,19 +286,21 @@ int nodeSize = getBTHeaderRecord().getNodeSize(); ByteBuffer nodeData = ByteBuffer.allocate(nodeSize); fs.getApi().read(catalogHeaderNodeOffset + (currentNodeNumber * nodeSize), nodeData); - CatalogNode node = new CatalogNode(nodeData.array(), nodeSize); + NodeDescriptor nd = new NodeDescriptor(nodeData.array(), 0); int currentOffset = 0; CatalogKey cKey = new CatalogKey(parentID, nodeName); - while (node.isIndexNode()) { + while (nd.isIndexNode()) { + CatalogIndexNode node = new CatalogIndexNode(nodeData.array(), nodeSize); IndexRecord record = (IndexRecord) node.find(cKey); currentNodeNumber = record.getIndex(); currentOffset = catalogHeaderNodeOffset + record.getIndex() * nodeSize; nodeData = ByteBuffer.allocate(nodeSize); fs.getApi().read(currentOffset, buffer); - node = new CatalogNode(nodeData.array(), nodeSize); + node = new CatalogIndexNode(nodeData.array(), nodeSize); } LeafRecord lr = null; - if (node.isLeafNode()) { + if (nd.isLeafNode()) { + CatalogLeafNode node = new CatalogLeafNode(nodeData.array(), nodeSize); lr = (LeafRecord) node.find(parentID); } return lr; Copied: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogIndexNode.java (from rev 5842, trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java) =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogIndexNode.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogIndexNode.java 2011-08-04 12:57:47 UTC (rev 5843) @@ -0,0 +1,125 @@ +/* + * $Id$ + * + * Copyright (C) 2003-2010 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.catalog; + +import java.util.LinkedList; + +import org.jnode.fs.hfsplus.tree.AbstractNode; +import org.jnode.fs.hfsplus.tree.IndexRecord; +import org.jnode.fs.hfsplus.tree.Key; +import org.jnode.fs.hfsplus.tree.NodeDescriptor; + +public class CatalogIndexNode extends AbstractNode<IndexRecord> { + + /** + * Create a new node. + * + * @param descriptor + * @param nodeSize + */ + public CatalogIndexNode(NodeDescriptor descriptor, final int nodeSize) { + super(descriptor, nodeSize); + } + + /** + * Create node from existing data. + * + * @param nodeData + * @param nodeSize + */ + public CatalogIndexNode(final byte[] nodeData, final int nodeSize) { + super(nodeData, nodeSize); + + } + + @Override + protected void loadRecords(final byte[] nodeData) { + CatalogKey key; + int offset; + for (int i = 0; i < this.descriptor.getNumRecords(); i++) { + offset = offsets.get(i); + key = new CatalogKey(nodeData, offset); + records.add(new IndexRecord(key, nodeData, offset)); + } + } + + /** + * @param parentId + * @return a NodeRecord or {@code null} + */ + public final IndexRecord find(final CatalogNodeId parentId) { + for (IndexRecord record : records) { + Key key = record.getKey(); + if (key instanceof CatalogKey) { + if (((CatalogKey) key).getParentId().getId() == parentId.getId()) { + return record; + } + } + } + return null; + } + + /** + * Find node record based on it's key. + * + * @param key The key to search. + * @return a NodeRecord or {@code null} + */ + public IndexRecord find(final CatalogKey key) { + IndexRecord largestMatchingRecord = null; + for (int index = 0; index < this.getNodeDescriptor().getNumRecords(); index++) { + IndexRecord record = this.getNodeRecord(index); + if ((record.getKey().compareTo(key) <= 0)) { + if (largestMatchingRecord != null && + record.getKey().compareTo(largestMatchingRecord.getKey()) > 0) { + largestMatchingRecord = record; + } + } + } + return largestMatchingRecord; + } + + /** + * @param parentId + * @return an array of NodeRecords + */ + public final IndexRecord[] findAll(final CatalogNodeId parentId) { + LinkedList<IndexRecord> result = new LinkedList<IndexRecord>(); + IndexRecord largestMatchingRecord = null; + CatalogKey largestMatchingKey = null; + for (IndexRecord record : records) { + CatalogKey key = (CatalogKey) record.getKey(); + if (key.getParentId().getId() < parentId.getId() && + (largestMatchingKey == null || key.compareTo(largestMatchingKey) > 0)) { + largestMatchingKey = key; + largestMatchingRecord = record; + } else if (key.getParentId().getId() == parentId.getId()) { + result.addLast(record); + } + } + + if (largestMatchingKey != null) { + result.addFirst(largestMatchingRecord); + } + return result.toArray(new IndexRecord[result.size()]); + } + +} Added: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogLeafNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogLeafNode.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogLeafNode.java 2011-08-04 12:57:47 UTC (rev 5843) @@ -0,0 +1,79 @@ +package org.jnode.fs.hfsplus.catalog; + +import java.util.LinkedList; +import java.util.List; + +import org.jnode.fs.hfsplus.tree.AbstractNode; +import org.jnode.fs.hfsplus.tree.Key; +import org.jnode.fs.hfsplus.tree.LeafRecord; +import org.jnode.fs.hfsplus.tree.NodeDescriptor; +import org.jnode.fs.hfsplus.tree.NodeRecord; + +public class CatalogLeafNode extends AbstractNode<LeafRecord> { + /** + * Create a new node. + * + * @param descriptor + * @param nodeSize + */ + public CatalogLeafNode(NodeDescriptor descriptor, final int nodeSize) { + super(descriptor, nodeSize); + } + + /** + * Create node from existing data. + * + * @param nodeData + * @param nodeSize + */ + public CatalogLeafNode(final byte[] nodeData, final int nodeSize) { + super(nodeData, nodeSize); + + } + + @Override + protected void loadRecords(byte[] nodeData) { + CatalogKey key; + int offset; + for (int i = 0; i < this.descriptor.getNumRecords(); i++) { + offset = offsets.get(i); + key = new CatalogKey(nodeData, offset); + int recordSize = offsets.get(i + 1) - offset; + records.add(new LeafRecord(key, nodeData, offset, recordSize)); + } + } + + /** + * @param parentId + * @return a NodeRecord or {@code null} + */ + public final LeafRecord find(final CatalogNodeId parentId) { + for (LeafRecord record : records) { + Key key = record.getKey(); + if (key instanceof CatalogKey) { + if (((CatalogKey) key).getParentId().getId() == parentId.getId()) { + return record; + } + } + } + return null; + } + + /** + * @param parentId + * @return an array of NodeRecords + */ + public final LeafRecord[] findAll(final CatalogNodeId parentId) { + List<NodeRecord> list = new LinkedList<NodeRecord>(); + for (int index = 0; index < this.getNodeDescriptor().getNumRecords(); index++) { + NodeRecord record = this.getNodeRecord(index); + Key key = record.getKey(); + if (key instanceof CatalogKey && + ((CatalogKey) key).getParentId().getId() == parentId.getId()) { + list.add(record); + } + } + return list.toArray(new LeafRecord[list.size()]); + } + +} Property changes on: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogLeafNode.java ___________________________________________________________________ Added: svn:mime-type + text/plain Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2011-08-02 20:04:52 UTC (rev 5842) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogNode.java 2011-08-04 12:57:47 UTC (rev 5843) @@ -1,160 +0,0 @@ -/* - * $Id$ - * - * Copyright (C) 2003-2010 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.catalog; - -import java.util.ArrayList; -import java.util.LinkedList; -import java.util.List; - -import org.jnode.fs.hfsplus.tree.AbstractNode; -import org.jnode.fs.hfsplus.tree.IndexRecord; -import org.jnode.fs.hfsplus.tree.Key; -import org.jnode.fs.hfsplus.tree.LeafRecord; -import org.jnode.fs.hfsplus.tree.NodeDescriptor; -import org.jnode.fs.hfsplus.tree.NodeRecord; -import org.jnode.util.BigEndian; - -public class CatalogNode extends AbstractNode { - - /** - * Create a new node. - * @param descriptor - * @param nodeSize - */ - public CatalogNode(NodeDescriptor descriptor, final int nodeSize) { - this.descriptor = descriptor; - this.size = nodeSize; - this.records = new ArrayList<NodeRecord>(descriptor.getNumRecords()); - this.offsets = new ArrayList<Integer>(descriptor.getNumRecords() + 1); - this.offsets.add(Integer.valueOf(NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH)); - } - - /** - * Create node from existing data. - * @param nodeData - * @param nodeSize - */ - public CatalogNode(final byte[] nodeData, final int nodeSize) { - this.descriptor = new NodeDescriptor(nodeData, 0); - this.size = nodeSize; - this.records = new ArrayList<NodeRecord>(this.descriptor.getNumRecords()); - this.offsets = new ArrayList<Integer>(this.descriptor.getNumRecords() + 1); - int offset; - for (int i = 0; i < this.descriptor.getNumRecords() + 1; i++) { - offset = BigEndian.getInt16(nodeData, size - ((i + 1) * 2)); - offsets.add(Integer.valueOf(offset)); - } - CatalogKey key; - for (int i = 0; i < this.descriptor.getNumRecords(); i++) { - offset = offsets.get(i); - key = new CatalogKey(nodeData, offset); - if (isIndexNode()) { - records.add(new IndexRecord(key, nodeData, offset)); - } else { - int recordSize = offsets.get(i + 1) - offset; - records.add(new LeafRecord(key, nodeData, offset, recordSize)); - } - } - } - - @Override - public NodeRecord getNodeRecord(int index) { - return records.get(index); - } - - /** - * @param parentId - * @return a NodeRecord or {@code null} - */ - public final NodeRecord find(final CatalogNodeId parentId) { - for (NodeRecord record : records) { - Key key = record.getKey(); - if (key instanceof CatalogKey) { - if (((CatalogKey) key).getParentId().getId() == parentId.getId()) { - return record; - } - } - } - return null; - } - - /** - * Find node record based on it's key. - * - * @param key The key to search. - * @return a NodeRecord or {@code null} - */ - public NodeRecord find(final CatalogKey key) { - NodeRecord largestMatchingRecord = null; - for (int index = 0; index < this.getNodeDescriptor().getNumRecords(); index++) { - NodeRecord record = this.getNodeRecord(index); - if ((record.getKey().compareTo(key) <= 0)) { - if (largestMatchingRecord != null && - record.getKey().compareTo(largestMatchingRecord.getKey()) > 0) { - largestMatchingRecord = record; - } - } - } - return largestMatchingRecord; - } - - /** - * @param parentId - * @return an array of NodeRecords - */ - public final NodeRecord[] findChildren(final CatalogNodeId parentId) { - LinkedList<NodeRecord> result = new LinkedList<NodeRecord>(); - NodeRecord largestMatchingRecord = null; - CatalogKey largestMatchingKey = null; - for (NodeRecord record : records) { - CatalogKey key = (CatalogKey) record.getKey(); - if (key.getParentId().getId() < parentId.getId() - && (largestMatchingKey == null || key.compareTo(largestMatchingKey) > 0)) { - largestMatchingKey = key; - largestMatchingRecord = record; - } else if (key.getParentId().getId() == parentId.getId()) { - result.addLast(record); - } - } - - if (largestMatchingKey != null) { - result.addFirst(largestMatchingRecord); - } - return result.toArray(new NodeRecord[result.size()]); - } - - /** - * @param parentId - * @return an array of NodeRecords - */ - public final NodeRecord[] findAll(final CatalogNodeId parentId) { - List<NodeRecord> list = new LinkedList<NodeRecord>(); - for (int index = 0; index < this.getNodeDescriptor().getNumRecords(); index++) { - NodeRecord record = this.getNodeRecord(index); - Key key = record.getKey(); - if (key instanceof CatalogKey && ((CatalogKey) key).getParentId().getId() == parentId.getId()) { - list.add(record); - } - } - return list.toArray(new NodeRecord[list.size()]); - } - -} Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentNode.java 2011-08-02 20:04:52 UTC (rev 5842) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentNode.java 2011-08-04 12:57:47 UTC (rev 5843) @@ -17,29 +17,33 @@ * 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.extent; import org.jnode.fs.hfsplus.tree.AbstractNode; +import org.jnode.fs.hfsplus.tree.IndexRecord; import org.jnode.fs.hfsplus.tree.NodeDescriptor; -import org.jnode.fs.hfsplus.tree.NodeRecord; -public class ExtentNode extends AbstractNode { - +public class ExtentNode extends AbstractNode<IndexRecord> { + public ExtentNode(NodeDescriptor descriptor, final int nodeSize) { - this.descriptor = descriptor; - this.size = nodeSize; + super(descriptor, nodeSize); } - + public ExtentNode(final byte[] nodeData, final int nodeSize) { - this.descriptor = new NodeDescriptor(nodeData, 0); - this.size = nodeSize; + super(nodeData, nodeSize); } @Override - public NodeRecord getNodeRecord(int index) { + public IndexRecord getNodeRecord(int index) { // TODO Auto-generated method stub return null; } + @Override + protected void loadRecords(byte[] nodeData) { + // TODO Auto-generated method stub + + } + } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2011-08-02 20:04:52 UTC (rev 5842) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractNode.java 2011-08-04 12:57:47 UTC (rev 5843) @@ -17,30 +17,46 @@ * 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 java.util.ArrayList; import java.util.List; import org.jnode.util.BigEndian; -public abstract class AbstractNode implements Node { +public abstract class AbstractNode<T extends NodeRecord> implements Node<T> { protected NodeDescriptor descriptor; - protected List<NodeRecord> records; + protected List<T> records; protected List<Integer> offsets; protected int size; - @Override - public NodeDescriptor getNodeDescriptor() { - return descriptor; + public AbstractNode(NodeDescriptor descriptor, final int nodeSize) { + this.descriptor = descriptor; + this.size = nodeSize; + this.records = new ArrayList<T>(descriptor.getNumRecords()); + this.offsets = new ArrayList<Integer>(descriptor.getNumRecords() + 1); + this.offsets.add(Integer.valueOf(NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH)); } - public boolean isIndexNode() { - return this.getNodeDescriptor().getKind() == NodeDescriptor.BT_INDEX_NODE; + public AbstractNode(final byte[] nodeData, final int nodeSize) { + this.descriptor = new NodeDescriptor(nodeData, 0); + this.size = nodeSize; + this.records = new ArrayList<T>(this.descriptor.getNumRecords()); + this.offsets = new ArrayList<Integer>(this.descriptor.getNumRecords() + 1); + int offset; + for (int i = 0; i < this.descriptor.getNumRecords() + 1; i++) { + offset = BigEndian.getInt16(nodeData, size - ((i + 1) * 2)); + offsets.add(Integer.valueOf(offset)); + } + loadRecords(nodeData); } - public boolean isLeafNode() { - return this.getNodeDescriptor().getKind() == NodeDescriptor.BT_LEAF_NODE; + protected abstract void loadRecords(final byte[] nodeData); + + @Override + public NodeDescriptor getNodeDescriptor() { + return descriptor; } @Override @@ -49,10 +65,12 @@ } @Override - public abstract NodeRecord getNodeRecord(int index); + public T getNodeRecord(int index) { + return records.get(index); + } @Override - public boolean addNodeRecord(NodeRecord record) { + public boolean addNodeRecord(T record) { int freeSpace = getFreeSize(); if (freeSpace < record.getSize() + 2) { return false; @@ -107,7 +125,7 @@ public String toString() { StringBuffer b = new StringBuffer(); - b.append((this.isLeafNode()) ? "Leaf node" : "Index node").append("\n"); + b.append((this.getNodeDescriptor().isLeafNode()) ? "Leaf node" : "Index node").append("\n"); b.append(this.getNodeDescriptor().toString()).append("\n"); b.append("Offsets : ").append(offsets.toString()); return b.toString(); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java 2011-08-02 20:04:52 UTC (rev 5842) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/Node.java 2011-08-04 12:57:47 UTC (rev 5843) @@ -17,22 +17,18 @@ * 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; -public interface Node { +public interface Node<T extends NodeRecord> { public static final int OFFSET_SIZE = 2; public NodeDescriptor getNodeDescriptor(); - public boolean isIndexNode(); - - public boolean isLeafNode(); - public int getRecordOffset(int index); - public NodeRecord getNodeRecord(int index); + public T getNodeRecord(int index); /** * Insert a record in the node. @@ -41,5 +37,5 @@ * @return True if record is correctly inserted, false if there is not * enough place to insert the record. */ - public boolean addNodeRecord(NodeRecord record); + public boolean addNodeRecord(T record); } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/NodeDescriptor.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/NodeDescriptor.java 2011-08-02 20:04:52 UTC (rev 5842) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/NodeDescriptor.java 2011-08-04 12:57:47 UTC (rev 5843) @@ -17,7 +17,7 @@ * 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; @@ -27,22 +27,22 @@ 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; - + /** 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; @@ -118,4 +118,16 @@ return numRecords; } + public boolean isIndexNode() { + return kind == NodeDescriptor.BT_INDEX_NODE; + } + + public boolean isLeafNode() { + return kind == NodeDescriptor.BT_LEAF_NODE; + } + + public boolean isMapNode() { + return kind == NodeDescriptor.BT_MAP_NODE; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2012-01-25 15:46:41
|
Revision: 5882 http://jnode.svn.sourceforge.net/jnode/?rev=5882&view=rev Author: galatnm Date: 2012-01-25 15:46:30 +0000 (Wed, 25 Jan 2012) Log Message: ----------- Fixes from luke concerning HFS+ extends management. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFile.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusForkData.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/BTHeaderRecord.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFile.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFile.java 2011-12-22 15:30:32 UTC (rev 5881) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFile.java 2012-01-25 15:46:30 UTC (rev 5882) @@ -22,11 +22,9 @@ import java.io.IOException; import java.nio.ByteBuffer; - import org.jnode.fs.FSFile; import org.jnode.fs.FileSystem; import org.jnode.fs.hfsplus.catalog.CatalogFile; -import org.jnode.fs.hfsplus.extent.ExtentDescriptor; public class HfsPlusFile implements FSFile { @@ -57,12 +55,7 @@ @Override public final void read(final long fileOffset, final ByteBuffer dest) throws IOException { HfsPlusFileSystem fs = (HfsPlusFileSystem) getFileSystem(); - for (ExtentDescriptor d : file.getDatas().getExtents()) { - if (!d.isEmpty()) { - long firstOffset = (long) d.getStartOffset(fs.getVolumeHeader().getBlockSize()); - fs.getApi().read(firstOffset, dest); - } - } + file.getDatas().read(fs,fileOffset,dest); } @Override Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusForkData.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusForkData.java 2011-12-22 15:30:32 UTC (rev 5881) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusForkData.java 2012-01-25 15:46:30 UTC (rev 5882) @@ -20,6 +20,8 @@ package org.jnode.fs.hfsplus; +import java.io.IOException; +import java.nio.ByteBuffer; import org.jnode.fs.hfsplus.extent.ExtentDescriptor; import org.jnode.util.BigEndian; @@ -111,7 +113,32 @@ public ExtentDescriptor getExtent(int index) { return extents[index]; } + /** + * Read a block of data + * + * @param fileSystem the associated file system. + * @param offset the offset to read from. + * @param buffer the buffer to read into. + * @throws java.io.IOException if an error occurs. + */ + public void read(HfsPlusFileSystem fileSystem, long offset, ByteBuffer buffer) throws IOException { + for (ExtentDescriptor extentDescriptor : extents) { + if (buffer.remaining() > 0 && !extentDescriptor.isEmpty()) { + long length = extentDescriptor.getSize(fileSystem.getVolumeHeader().getBlockSize()); + if (offset != 0 && length < offset) { + offset -= length; + } else { + + long firstOffset = extentDescriptor.getStartOffset(fileSystem.getVolumeHeader().getBlockSize()); + fileSystem.getApi().read(firstOffset + offset, buffer); + + offset = 0; + } + } + } + } + /** * * @param index Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2011-12-22 15:30:32 UTC (rev 5881) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2012-01-25 15:46:30 UTC (rev 5882) @@ -24,13 +24,12 @@ import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.List; - import org.apache.log4j.Logger; import org.jnode.fs.hfsplus.HFSPlusParams; import org.jnode.fs.hfsplus.HfsPlusFileSystem; +import org.jnode.fs.hfsplus.HfsPlusForkData; import org.jnode.fs.hfsplus.HfsUnicodeString; import org.jnode.fs.hfsplus.SuperBlock; -import org.jnode.fs.hfsplus.extent.ExtentDescriptor; import org.jnode.fs.hfsplus.tree.BTHeaderRecord; import org.jnode.fs.hfsplus.tree.IndexRecord; import org.jnode.fs.hfsplus.tree.LeafRecord; @@ -52,7 +51,7 @@ */ private BTHeaderRecord bthr; - private int catalogHeaderNodeOffset; + private HfsPlusForkData catalogFile; private ByteBuffer buffer; @@ -66,13 +65,12 @@ log.info("Load B-Tree catalog file."); this.fs = fs; SuperBlock sb = fs.getVolumeHeader(); - ExtentDescriptor firstExtent = sb.getCatalogFile().getExtent(0); - catalogHeaderNodeOffset = firstExtent.getStartOffset(sb.getBlockSize()); - if (!firstExtent.isEmpty()) { - buffer = - ByteBuffer.allocate(NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH + + catalogFile = sb.getCatalogFile(); + + if(!catalogFile.getExtent(0).isEmpty()) { + buffer = ByteBuffer.allocate(NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH + BTHeaderRecord.BT_HEADER_RECORD_LENGTH); - fs.getApi().read(catalogHeaderNodeOffset, buffer); + catalogFile.read(fs, 0, buffer); buffer.rewind(); byte[] data = ByteBufferUtils.toArray(buffer); log.info("Load catalog node descriptor."); @@ -150,7 +148,7 @@ */ public void update() throws IOException { SuperBlock vh = fs.getVolumeHeader(); - int offset = vh.getCatalogFile().getExtent(0).getStartOffset(vh.getBlockSize()); + long offset = vh.getCatalogFile().getExtent(0).getStartOffset(vh.getBlockSize()); fs.getApi().write(offset, this.getBytes()); } @@ -197,8 +195,7 @@ LeafRecord lr = null; int nodeSize = bthr.getNodeSize(); ByteBuffer nodeData = ByteBuffer.allocate(nodeSize); - fs.getApi().read(catalogHeaderNodeOffset + (getBTHeaderRecord().getRootNode() * nodeSize), - nodeData); + catalogFile.read(fs, (bthr.getRootNode()*nodeSize), nodeData); nodeData.rewind(); byte[] data = ByteBufferUtils.toArray(nodeData); NodeDescriptor nd = new NodeDescriptor(nodeData.array(), 0); @@ -206,9 +203,9 @@ while (nd.isIndexNode()) { CatalogIndexNode node = new CatalogIndexNode(data, nodeSize); IndexRecord record = (IndexRecord) node.find(parentID); - currentOffset = catalogHeaderNodeOffset + (record.getIndex() * nodeSize); + currentOffset = record.getIndex() * nodeSize; nodeData = ByteBuffer.allocate(nodeSize); - fs.getApi().read(currentOffset, nodeData); + catalogFile.read(fs, currentOffset, nodeData); nodeData.rewind(); data = ByteBufferUtils.toArray(nodeData); nd = new NodeDescriptor(nodeData.array(), 0); @@ -248,7 +245,7 @@ int currentNodeNumber = nodeNumber; int nodeSize = getBTHeaderRecord().getNodeSize(); ByteBuffer nodeData = ByteBuffer.allocate(nodeSize); - fs.getApi().read(catalogHeaderNodeOffset + (currentNodeNumber * nodeSize), nodeData); + catalogFile.read(fs, (currentNodeNumber * nodeSize), nodeData); byte[] datas = nodeData.array(); NodeDescriptor nd = new NodeDescriptor(datas, 0); if (nd.isIndexNode()) { @@ -286,7 +283,7 @@ int currentNodeNumber = getBTHeaderRecord().getRootNode(); int nodeSize = getBTHeaderRecord().getNodeSize(); ByteBuffer nodeData = ByteBuffer.allocate(nodeSize); - fs.getApi().read(catalogHeaderNodeOffset + (currentNodeNumber * nodeSize), nodeData); + catalogFile.read(fs, (currentNodeNumber * nodeSize), nodeData); NodeDescriptor nd = new NodeDescriptor(nodeData.array(), 0); int currentOffset = 0; CatalogKey cKey = new CatalogKey(parentID, nodeName); @@ -294,9 +291,9 @@ CatalogIndexNode node = new CatalogIndexNode(nodeData.array(), nodeSize); IndexRecord record = node.find(cKey); currentNodeNumber = record.getIndex(); - currentOffset = catalogHeaderNodeOffset + record.getIndex() * nodeSize; + currentOffset = record.getIndex() * nodeSize; nodeData = ByteBuffer.allocate(nodeSize); - fs.getApi().read(currentOffset, buffer); + catalogFile.read(fs, currentOffset, buffer); node = new CatalogIndexNode(nodeData.array(), nodeSize); } LeafRecord lr = null; Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java 2011-12-22 15:30:32 UTC (rev 5881) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java 2012-01-25 15:46:30 UTC (rev 5882) @@ -89,8 +89,8 @@ * @param nodeSize the size of a node. * @return offset of the extent. */ - public int getStartOffset(int nodeSize) { - return startBlock * nodeSize; + public long getStartOffset(int nodeSize) { + return (long)startBlock * nodeSize; } /** @@ -108,8 +108,8 @@ * @param nodeSize the size of a node. * @return size of the extent. */ - public int getSize(int nodeSize) { - return blockCount * nodeSize; + public long getSize(int nodeSize) { + return (long)blockCount * nodeSize; } /** Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/BTHeaderRecord.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/BTHeaderRecord.java 2011-12-22 15:30:32 UTC (rev 5881) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/BTHeaderRecord.java 2012-01-25 15:46:30 UTC (rev 5882) @@ -93,12 +93,12 @@ lastLeafNode = BigEndian.getInt32(data, 14); nodeSize = BigEndian.getInt16(data, 18); maxKeyLength = BigEndian.getInt16(data, 20); - totalNodes = BigEndian.getInt16(data, 24); - freeNodes = BigEndian.getInt16(data, 28); - clumpSize = BigEndian.getInt16(data, 32); - treeType = BigEndian.getInt16(data, 36); - keyCompareType = BigEndian.getInt16(data, 37); - attributes = BigEndian.getInt32(data, 39); + totalNodes = BigEndian.getInt32(data, 22); + freeNodes = BigEndian.getInt32(data, 26); + clumpSize = BigEndian.getInt32(data, 32); + treeType = BigEndian.getInt8(data,36); + keyCompareType = BigEndian.getInt8(data,36); + attributes = BigEndian.getInt32(data, 38); } public byte[] getBytes() { @@ -114,8 +114,8 @@ BigEndian.setInt32(data, 26, freeNodes); BigEndian.setInt32(data, 32, clumpSize); BigEndian.setInt8(data, 36, treeType); - BigEndian.setInt8(data, 38, keyCompareType); - BigEndian.setInt32(data, 39, attributes); + BigEndian.setInt8(data, 37, keyCompareType); + BigEndian.setInt32(data, 38, attributes); return data; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2012-02-15 16:36:28
|
Revision: 5887 http://jnode.svn.sourceforge.net/jnode/?rev=5887&view=rev Author: galatnm Date: 2012-02-15 16:36:17 +0000 (Wed, 15 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/catalog/Catalog.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2012-02-14 16:05:35 UTC (rev 5886) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2012-02-15 16:36:17 UTC (rev 5887) @@ -76,7 +76,6 @@ @Override public FSEntry addFile(String name) throws IOException { - log.debug("<<< BEGIN addFile " + name + " >>>"); if (getFileSystem().isReadOnly()) { throw new ReadOnlyFileSystemException(); } @@ -86,7 +85,6 @@ FSEntry newEntry = createFileEntry(name); setFreeEntry(newEntry); - log.debug("<<< END addFile " + name + " >>>"); return newEntry; } @@ -111,7 +109,6 @@ @Override public void flush() throws IOException { - log.debug("<<< BEGIN flush >>>"); if (getFileSystem().isReadOnly()) { throw new ReadOnlyFileSystemException(); } @@ -121,7 +118,7 @@ // entries.resetDirty(); entry.resetDirty(); } - log.debug("<<< END flush >>>"); + log.debug("Directory flushed."); } @Override @@ -181,7 +178,6 @@ entries = FSEntryTable.EMPTY_TABLE; } } - log.debug("<<< END checkEntriesLoaded >>>"); } /** 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-14 16:05:35 UTC (rev 5886) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2012-02-15 16:36:17 UTC (rev 5887) @@ -110,11 +110,33 @@ BTHeaderRecord.BT_BIG_KEYS_MASK); log.debug(bthr.toString()); bufferLength += BTHeaderRecord.BT_HEADER_RECORD_LENGTH; + log.info("Create root node."); int rootNodePosition = bthr.getRootNode() * nodeSize; bufferLength += (rootNodePosition - bufferLength); - // Create node descriptor - NodeDescriptor nd = + CatalogLeafNode rootNode = createRootNode(params); + buffer = ByteBuffer.allocate(bufferLength + bthr.getNodeSize()); + buffer.put(btnd.getBytes()); + buffer.put(bthr.getBytes()); + buffer.position(rootNodePosition); + buffer.put(rootNode.getBytes()); + buffer.rewind(); + } + + /** + * Save catalog file to disk. + * + * @throws IOException + */ + public void update() throws IOException { + SuperBlock vh = fs.getVolumeHeader(); + long offset = vh.getCatalogFile().getExtent(0).getStartOffset(vh.getBlockSize()); + fs.getApi().write(offset, this.getBytes()); + } + + private CatalogLeafNode createRootNode(HFSPlusParams params){ + int nodeSize = params.getCatalogNodeSize(); + NodeDescriptor nd = new NodeDescriptor(0, 0, NodeDescriptor.BT_LEAF_NODE, 1, params.getInitializeNumRecords()); CatalogLeafNode rootNode = new CatalogLeafNode(nd, nodeSize); @@ -133,26 +155,10 @@ record = new LeafRecord(tck, ct.getBytes()); rootNode.addNodeRecord(record); log.debug(rootNode.toString()); - buffer = ByteBuffer.allocate(bufferLength + bthr.getNodeSize()); - buffer.put(btnd.getBytes()); - buffer.put(bthr.getBytes()); - buffer.position(rootNodePosition); - buffer.put(rootNode.getBytes()); - buffer.rewind(); + return rootNode; } /** - * Save catalog file to disk. - * - * @throws IOException - */ - public void update() throws IOException { - SuperBlock vh = fs.getVolumeHeader(); - long offset = vh.getCatalogFile().getExtent(0).getStartOffset(vh.getBlockSize()); - fs.getApi().write(offset, this.getBytes()); - } - - /** * Create a new node in the catalog B-Tree. * * @param filename @@ -165,6 +171,7 @@ int nodeType) throws IOException { CatalogLeafNode node; HfsUnicodeString name = new HfsUnicodeString(filename); + // find parent leaf record. LeafRecord record = this.getRecord(parentId, name); if (record == null) { NodeDescriptor nd = new NodeDescriptor(0, 0, NodeDescriptor.BT_LEAF_NODE, 1, 2); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2012-08-09 11:04:54
|
Revision: 5901 http://jnode.svn.sourceforge.net/jnode/?rev=5901&view=rev Author: galatnm Date: 2012-08-09 11:04:47 +0000 (Thu, 09 Aug 2012) Log Message: ----------- Add initial support for HFSX file systems (patch from L. Quinane) Modified Paths: -------------- 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/extent/ExtentDescriptor.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java 2012-07-09 08:15:39 UTC (rev 5900) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java 2012-08-09 11:04:47 UTC (rev 5901) @@ -22,14 +22,11 @@ import java.io.IOException; import java.nio.ByteBuffer; - import org.jnode.driver.Device; import org.jnode.driver.block.FSBlockDeviceAPI; import org.jnode.fs.BlockDeviceFileSystemType; import org.jnode.fs.FileSystemException; import org.jnode.partitions.PartitionTableEntry; -import org.jnode.partitions.ibm.IBMPartitionTableEntry; -import org.jnode.partitions.ibm.IBMPartitionTypes; import org.jnode.util.BigEndian; public class HfsPlusFileSystemType implements BlockDeviceFileSystemType<HfsPlusFileSystem> { @@ -48,13 +45,13 @@ public final boolean supports(final PartitionTableEntry pte, final byte[] firstSector, final FSBlockDeviceAPI devApi) { - if (pte != null) { + /*if (pte != null) { if (pte instanceof IBMPartitionTableEntry) { if (((IBMPartitionTableEntry) pte).getSystemIndicator() != IBMPartitionTypes.PARTTYPE_LINUXNATIVE) { return false; } } - } + } */ // need to check the magic ByteBuffer magic = ByteBuffer.allocate(2); try { @@ -63,7 +60,7 @@ return false; } int magicNumber = BigEndian.getInt16(magic.array(), 0); - return (magicNumber == SuperBlock.HFSPLUS_SUPER_MAGIC); + return (magicNumber == SuperBlock.HFSPLUS_SUPER_MAGIC || magicNumber == SuperBlock.HFSX_SUPER_MAGIC); } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java 2012-07-09 08:15:39 UTC (rev 5900) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java 2012-08-09 11:04:47 UTC (rev 5901) @@ -41,7 +41,8 @@ */ public class SuperBlock extends HfsPlusObject { - public static final int HFSPLUS_SUPER_MAGIC = 0x482b; + public static final int HFSPLUS_SUPER_MAGIC = 0x482b; // H+ + public static final int HFSX_SUPER_MAGIC = 0x4858; // HX public static final int HFSPLUS_MIN_VERSION = 0x0004; /* HFS+ */ public static final int HFSPLUS_CURRENT_VERSION = 5; /* HFSX */ @@ -85,7 +86,7 @@ fs.getApi().read(1024, b); data = new byte[SUPERBLOCK_LENGTH]; System.arraycopy(b.array(), 0, data, 0, SUPERBLOCK_LENGTH); - if (getMagic() != HFSPLUS_SUPER_MAGIC) { + if (getMagic() != HFSPLUS_SUPER_MAGIC && getMagic() != HFSX_SUPER_MAGIC) { throw new FileSystemException("Not hfs+ volume header (" + getMagic() + ": bad magic)"); } @@ -151,7 +152,7 @@ forkdata.addDescriptor(0, desc); forkdata.write(data, 112); // Journal creation - int nextBlock = 0; + long nextBlock = 0; if (params.isJournaled()) { this.setFileCount(2); this.setAttribute(HFSPLUS_VOL_JOURNALED_BIT); @@ -248,8 +249,8 @@ return BigEndian.getInt32(data, 12); } - public final void setJournalInfoBlock(final int value) { - BigEndian.setInt32(data, 12, value); + public final void setJournalInfoBlock(final long value) { + BigEndian.setInt32(data, 12, (int) value); } // Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java 2012-07-09 08:15:39 UTC (rev 5900) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java 2012-08-09 11:04:47 UTC (rev 5901) @@ -27,10 +27,10 @@ public static final int EXTENT_DESCRIPTOR_LENGTH = 8; /** The first allocation block. */ - private int startBlock; + private long startBlock; /** The length in allocation blocks of the extent. */ - private int blockCount; + private long blockCount; public ExtentDescriptor() { this.startBlock = 0; @@ -43,7 +43,7 @@ * @param startBlock first allocation block. * @param blockCount number of blocks in the extent. */ - public ExtentDescriptor(int startBlock, int blockCount) { + public ExtentDescriptor(long startBlock, long blockCount) { this.startBlock = startBlock; this.blockCount = blockCount; } @@ -57,8 +57,8 @@ public ExtentDescriptor(final byte[] src, final int offset) { byte[] data = new byte[EXTENT_DESCRIPTOR_LENGTH]; System.arraycopy(src, offset, data, 0, EXTENT_DESCRIPTOR_LENGTH); - startBlock = BigEndian.getInt32(data, 0); - blockCount = BigEndian.getInt32(data, 4); + startBlock = BigEndian.getUInt32(data, 0); + blockCount = BigEndian.getUInt32(data, 4); } /** @@ -66,15 +66,15 @@ */ public final byte[] getBytes() { byte[] data = new byte[EXTENT_DESCRIPTOR_LENGTH]; - BigEndian.setInt32(data, 0, startBlock); - BigEndian.setInt32(data, 4, blockCount); + BigEndian.setInt32(data, 0, (int) startBlock); + BigEndian.setInt32(data, 4, (int) blockCount); return data; } public byte[] write(byte[] dest, int destOffSet) { byte[] data = new byte[EXTENT_DESCRIPTOR_LENGTH]; - BigEndian.setInt32(data, 0, startBlock); - BigEndian.setInt32(data, 4, blockCount); + BigEndian.setInt32(data, 0, (int) startBlock); + BigEndian.setInt32(data, 4, (int) blockCount); System.arraycopy(data, 0, dest, destOffSet, EXTENT_DESCRIPTOR_LENGTH); return dest; } @@ -90,7 +90,7 @@ * @return offset of the extent. */ public long getStartOffset(int nodeSize) { - return (long)startBlock * nodeSize; + return startBlock * nodeSize; } /** @@ -98,7 +98,7 @@ * * @return block number of the next extent. */ - public int getNext() { + public long getNext() { return startBlock + blockCount; } @@ -109,7 +109,7 @@ * @return size of the extent. */ public long getSize(int nodeSize) { - return (long)blockCount * nodeSize; + return blockCount * nodeSize; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2012-08-10 06:44:33
|
Revision: 5914 http://jnode.svn.sourceforge.net/jnode/?rev=5914&view=rev Author: galatnm Date: 2012-08-10 06:44:27 +0000 (Fri, 10 Aug 2012) Log Message: ----------- Improve HFS+ date extraction Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusEntry.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusEntry.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusEntry.java 2012-08-10 06:41:36 UTC (rev 5913) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusEntry.java 2012-08-10 06:44:27 UTC (rev 5914) @@ -17,11 +17,10 @@ * 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; import java.io.IOException; - import org.jnode.fs.FSAccessRights; import org.jnode.fs.FSDirectory; import org.jnode.fs.FSEntry; @@ -44,10 +43,9 @@ protected boolean valid; protected boolean dirty; protected FSAccessRights rights; - private long lastModified; /** - * + * * @param fs * @param parent * @param name @@ -61,7 +59,6 @@ this.record = record; this.type = getFSEntryType(); this.rights = new UnixFSAccessRights(fs); - this.lastModified = System.currentTimeMillis(); } private int getFSEntryType() { @@ -100,8 +97,14 @@ @Override public long getLastModified() throws IOException { - // TODO Auto-generated method stub - return lastModified; + if (isFile()) { + CatalogFile catalogFile = new CatalogFile(getData()); + return catalogFile.getContentModDate(); + } + else { + CatalogFolder catalogFolder = new CatalogFolder(getData()); + return catalogFolder.getContentModDate(); + } } @Override @@ -139,7 +142,15 @@ @Override public void setLastModified(long lastModified) throws IOException { - this.lastModified = lastModified; + if (isFile()) { + CatalogFile catalogFile = new CatalogFile(getData()); + // catalogFile.setContentModDate(); + throw new UnsupportedOperationException("Not implemented yet."); + } + else { + CatalogFolder catalogFolder = new CatalogFolder(getData()); + catalogFolder.setContentModDate(lastModified); + } } @Override @@ -168,4 +179,14 @@ return this.record.getData(); } + public long getCreated() throws IOException { + if (isFile()) { + CatalogFile catalogFile = new CatalogFile(getData()); + return catalogFile.getCreateDate(); + } + else { + CatalogFolder catalogFolder = new CatalogFolder(getData()); + return catalogFolder.getCreateDate(); + } + } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java 2012-08-10 06:41:36 UTC (rev 5913) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java 2012-08-10 06:44:27 UTC (rev 5914) @@ -137,12 +137,12 @@ return fileId; } - public int getCreateDate() { - return createDate; + public long getCreateDate() { + return HfsUtils.getDate(createDate & 0xffffffffL, false) * 1000L; } - public int getContentModDate() { - return contentModDate; + public long getContentModDate() { + return HfsUtils.getDate(contentModDate & 0xffffffffL, false) * 1000L; } public int getAttrModDate() { Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java 2012-08-10 06:41:36 UTC (rev 5913) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java 2012-08-10 06:44:27 UTC (rev 5914) @@ -112,12 +112,12 @@ return folderId; } - public int getCreateDate() { - return createDate; + public long getCreateDate() { + return HfsUtils.getDate(createDate & 0xffffffffL, false) * 1000L; } - public int getContentModDate() { - return contentModDate; + public long getContentModDate() { + return HfsUtils.getDate(contentModDate & 0xffffffffL, false) * 1000L; } public int getAttrModDate() { @@ -136,12 +136,12 @@ this.folderId = folderId; } - public void setCreateDate(int createDate) { - this.createDate = createDate; + public void setCreateDate(long createDate) { + this.createDate = (int) HfsUtils.getDate(createDate / 1000L, true); } - public void setContentModDate(int contentModDate) { - this.contentModDate = contentModDate; + public void setContentModDate(long contentModDate) { + this.contentModDate = (int) HfsUtils.getDate(contentModDate / 1000L, true); } public void setAttrModDate(int attrModDate) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2012-08-10 07:20:31
|
Revision: 5922 http://jnode.svn.sourceforge.net/jnode/?rev=5922&view=rev Author: galatnm Date: 2012-08-10 07:20:25 +0000 (Fri, 10 Aug 2012) Log Message: ----------- Add HFS+ file info and BSD info fields Extract out some more dates Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/FileInfo.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusBSDInfo.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/FileInfo.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/FileInfo.java 2012-08-10 07:18:21 UTC (rev 5921) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/FileInfo.java 2012-08-10 07:20:25 UTC (rev 5922) @@ -17,9 +17,31 @@ * 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; +import org.jnode.util.BigEndian; + public class FileInfo { + private int fileType; + private int fileCreator; + private int finderFlags; + public FileInfo(byte[] data, int offset) { + fileType = BigEndian.getInt32(data, offset); + fileCreator = BigEndian.getInt32(data, offset + 4); + finderFlags = BigEndian.getInt16(data, offset + 8); + } + + public int getFileType() { + return fileType; + } + + public int getFileCreator() { + return fileCreator; + } + + public int getFinderFlags() { + return finderFlags; + } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusBSDInfo.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusBSDInfo.java 2012-08-10 07:18:21 UTC (rev 5921) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusBSDInfo.java 2012-08-10 07:20:25 UTC (rev 5922) @@ -20,6 +20,46 @@ package org.jnode.fs.hfsplus; +import org.jnode.util.BigEndian; + public class HfsPlusBSDInfo { + private int ownerID; + private int groupID; + private int adminFlags; + private int ownerFlags; + private int fileMode; + private int special; + public HfsPlusBSDInfo(byte[] data, int offset) { + ownerID = BigEndian.getInt32(data, offset); + groupID = BigEndian.getInt32(data, offset + 4); + adminFlags = data[offset + 8]; + ownerFlags = data[offset + 9]; + fileMode = BigEndian.getInt16(data, offset + 10); + special = BigEndian.getInt32(data, offset + 12); + } + + public int getOwnerID() { + return ownerID; + } + + public int getGroupID() { + return groupID; + } + + public int getAdminFlags() { + return adminFlags; + } + + public int getOwnerFlags() { + return ownerFlags; + } + + public int getFileMode() { + return fileMode; + } + + public int getSpecial() { + return special; + } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java 2012-08-10 07:18:21 UTC (rev 5921) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFile.java 2012-08-10 07:20:25 UTC (rev 5922) @@ -82,6 +82,10 @@ createDate = BigEndian.getInt32(data, 12); contentModDate = BigEndian.getInt32(data, 16); attrModDate = BigEndian.getInt32(data, 20); + accessDate = BigEndian.getInt32(data, 24); + backupDate = BigEndian.getInt32(data, 28); + permissions = new HfsPlusBSDInfo(data, 32); + userInfo = new FileInfo(data, 48); datas = new HfsPlusForkData(data, 88); resources = new HfsPlusForkData(data, 168); } @@ -145,8 +149,8 @@ return HfsUtils.getDate(contentModDate & 0xffffffffL, false) * 1000L; } - public int getAttrModDate() { - return attrModDate; + public long getAttrModDate() { + return HfsUtils.getDate(attrModDate & 0xffffffffL, false) * 1000L; } public HfsPlusForkData getDatas() { @@ -157,12 +161,12 @@ return resources; } - public int getAccessDate() { - return accessDate; + public long getAccessDate() { + return HfsUtils.getDate(accessDate & 0xffffffffL, false) * 1000L; } - public int getBackupDate() { - return backupDate; + public long getBackupDate() { + return HfsUtils.getDate(backupDate & 0xffffffffL, false) * 1000L; } public HfsPlusBSDInfo getPermissions() { Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java 2012-08-10 07:18:21 UTC (rev 5921) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java 2012-08-10 07:20:25 UTC (rev 5922) @@ -20,6 +20,7 @@ package org.jnode.fs.hfsplus.catalog; +import org.jnode.fs.hfsplus.HfsPlusBSDInfo; import org.jnode.fs.hfsplus.HfsUtils; import org.jnode.util.BigEndian; @@ -36,6 +37,9 @@ private int createDate; private int contentModDate; private int attrModDate; + private int accessDate; + private int backupDate; + private HfsPlusBSDInfo permissions; /** * @@ -50,6 +54,9 @@ createDate = BigEndian.getInt32(data, 12); contentModDate = BigEndian.getInt32(data, 16); attrModDate = BigEndian.getInt32(data, 20); + accessDate = BigEndian.getInt32(data, 24); + backupDate = BigEndian.getInt32(data, 28); + permissions = new HfsPlusBSDInfo(data, 32); } /** @@ -120,10 +127,22 @@ return HfsUtils.getDate(contentModDate & 0xffffffffL, false) * 1000L; } - public int getAttrModDate() { - return attrModDate; + public long getAttrModDate() { + return HfsUtils.getDate(attrModDate & 0xffffffffL, false) * 1000L; } + public long getAccessDate() { + return HfsUtils.getDate(accessDate & 0xffffffffL, false) * 1000L; + } + + public long getBackupDate() { + return HfsUtils.getDate(backupDate & 0xffffffffL, false) * 1000L; + } + + public HfsPlusBSDInfo getPermissions() { + return permissions; + } + public void setRecordType(int recordType) { this.recordType = recordType; } @@ -144,8 +163,8 @@ this.contentModDate = (int) HfsUtils.getDate(contentModDate / 1000L, true); } - public void setAttrModDate(int attrModDate) { - this.attrModDate = attrModDate; + public void setAttrModDate(long attrModDate) { + this.attrModDate = (int) HfsUtils.getDate(attrModDate / 1000L, true); } public void incrementValence(){ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |