From: <ga...@us...> - 2009-03-13 19:35:56
|
Revision: 5097 http://jnode.svn.sourceforge.net/jnode/?rev=5097&view=rev Author: galatnm Date: 2009-03-13 19:35:50 +0000 (Fri, 13 Mar 2009) Log Message: ----------- Rewrite and update javadocs. Modified Paths: -------------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.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/HfsPlusConstants.java trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java trunk/fs/src/fs/org/jnode/fs/hfsplus/JournalInfoBlock.java trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.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/extent/ExtentKey.java trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractKey.java Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusDirectory.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -176,11 +176,9 @@ new CatalogThread(HfsPlusConstants.RECORD_TYPE_FOLDER_THREAD, this.folder .getFolderId(), dirName); - CatalogFolder newFolder = new CatalogFolder(); - newFolder.setFolderId(new CatalogNodeId(volumeHeader.getNextCatalogId())); - newFolder.setCreateDate(macDate); - newFolder.setContentModDate(macDate); - newFolder.setAttrModDate(macDate); + CatalogFolder newFolder = + new CatalogFolder(0, new CatalogNodeId(volumeHeader.getNextCatalogId()), macDate, + macDate, macDate); log.debug("New catalog folder :\n" + newFolder.toString()); CatalogKey key = new CatalogKey(this.folder.getFolderId(), dirName); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusFile.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusFile.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusFile.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -51,7 +51,7 @@ public final void read(final long fileOffset, final ByteBuffer dest) throws IOException { HfsPlusFileSystem fs = (HfsPlusFileSystem) getFileSystem(); for (ExtentDescriptor d : file.getDataFork().getExtents()) { - if (d.getStartBlock() != 0 && d.getBlockCount() != 0) { + if (!d.isEmpty()) { long firstOffset = d.getStartBlock() * fs.getVolumeHeader().getBlockSize(); fs.getApi().read(firstOffset, dest); } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusForkData.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -26,17 +26,31 @@ 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; - private byte[] data; - /** + * Create fork data from existing informations. * * @param src * @param offset */ public HFSPlusForkData(final byte[] src, final int offset) { - data = new byte[FORK_DATA_LENGTH]; + 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)); + } } /** @@ -47,60 +61,65 @@ * @param clumpSize * @param totalBock */ - public HFSPlusForkData() { - data = new byte[FORK_DATA_LENGTH]; + public HFSPlusForkData(long totalSize, int clumpSize, int totalBlock) { + this.totalSize = totalSize; + this.clumpSize = clumpSize; + this.totalBlock = totalBlock; + this.extents = new ExtentDescriptor[8]; + } + + public byte[] getBytes() { + byte[] data = new byte[FORK_DATA_LENGTH]; + BigEndian.setInt64(data, 0, totalSize); + BigEndian.setInt32(data, 8, clumpSize); + BigEndian.setInt32(data, 12, totalBlock); + return data; } - - public final long getTotalSize() { - return BigEndian.getInt64(data, 0); + + + + /* + * (non-Javadoc) + * @see java.lang.Object#toString() + */ + 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 final void setTotalSize(long totalSize) { - BigEndian.setInt64(data, 0, totalSize); - } + public long getTotalSize() { + return totalSize; + } - public final int getClumpSize() { - return BigEndian.getInt32(data, 8); - } + public int getClumpSize() { + return clumpSize; + } - public final void setClumpSize(int clumpSize) { - BigEndian.setInt32(data, 8, 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 final int getTotalBlocks() { - return BigEndian.getInt32(data, 12); + public ExtentDescriptor[] getExtents(){ + return extents; } - public final void setTotalBlocks(int totalBlock) { - BigEndian.setInt32(data, 12, totalBlock); - } - - public final ExtentDescriptor[] getExtents() { - ExtentDescriptor[] list = new ExtentDescriptor[8]; - for (int i = 0; i < 8; i++) { - list[i] = new ExtentDescriptor(data, EXTENT_OFFSET + (i * ExtentDescriptor.EXTENT_DESCRIPTOR_LENGTH)); - } - return list; - } - - public final void setExtentDescriptor(int position, ExtentDescriptor desc) { - int offset = EXTENT_OFFSET + (position * ExtentDescriptor.EXTENT_DESCRIPTOR_LENGTH); - System.arraycopy(desc.getBytes(), 0, data, offset, ExtentDescriptor.EXTENT_DESCRIPTOR_LENGTH); - } - - public byte[] getBytes() { - return data; - } - - public final String toString() { - StringBuffer s = new StringBuffer(); - s.append("Total size : ").append(getTotalSize()).append("\n"); - s.append("Clump size : ").append(getClumpSize()).append("\n"); - s.append("Total Blocks : ").append(getTotalBlocks()).append("\n"); - ExtentDescriptor[] list = getExtents(); - for (int i = 0; i < list.length; i++) { - s.append("Extent[" + i + "]: " + list[i].toString()); - } - return s.toString(); - } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusConstants.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusConstants.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusConstants.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -46,10 +46,6 @@ public static final int RECORD_TYPE_FOLDER_THREAD = 0x0003; public static final int RECORD_TYPE_FILE_THREAD = 0x0004; - public static final int kJIJournalInFSMask = 0x00000001; - public static final int kJIJournalOnOtherDeviceMask = 0x00000002; - public static final int kJIJournalNeedInitMask = 0x00000004; - public static final byte EK_DATA_FORK = (byte) 0x00; public static final byte EK_RESOURCE_FORK = (byte) 0xFF; Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -163,7 +163,7 @@ writeAllocationFile((int) volumeBlockUsed); // --- log.debug("Write Catalog to disk."); - long offset = sb.getCatalogFile().getExtents()[0].getStartBlock() * sb.getBlockSize(); + long offset = sb.getCatalogFile().getExtent(0).getStartBlock() * sb.getBlockSize(); Catalog catalog = new Catalog(params); this.getApi().write(offset, catalog.getBytes()); log.debug("Write volume header to disk."); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/JournalInfoBlock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/JournalInfoBlock.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/JournalInfoBlock.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -17,32 +17,56 @@ * 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 JournalInfoBlock { - private byte[] data; + /** Flag indicate that the journal is located in the volume itself. */ + public static final int IN_FS_MASK = 0x00000001; + /** + * Flag indicate that the journal located in an other device. This flag is + * not currently supported. + */ + public static final int ION_OTHER_DEVICE_MASK = 0x00000002; + /** Flag indicate that the journal header is invalid and must be initialize. */ + public static final int NEED_INITIALIZATION = 0x00000004; + /** One-bits flag. See constants */ + private int flag; + /** Device where the journal is located if it is not in the volume itself. */ + private int deviceSignature; + /** journal start position on the volume */ + private long offset; + /** Size of the journal included header and buffer. */ + private long size; - public JournalInfoBlock(final byte[] src) { - data = new byte[180]; - System.arraycopy(src, 0, data, 0, 180); - } + public JournalInfoBlock(final byte[] src) { + byte[] data = new byte[180]; + System.arraycopy(src, 0, data, 0, 180); + flag = BigEndian.getInt32(data, 0); + deviceSignature = BigEndian.getInt32(data, 4); + offset = BigEndian.getInt64(data, 36); + size = BigEndian.getInt64(data, 44); + } - public final int getFlag() { - return BigEndian.getInt32(data, 0); - } + public final String toString() { + return "Journal : " + offset + "::" + size; + } - public final long getOffset() { - return BigEndian.getInt64(data, 36); - } + public int getFlag() { + return flag; + } - public final long getSize() { - return BigEndian.getInt64(data, 44); - } + public int getDeviceSignature() { + return deviceSignature; + } - public final String toString() { - return "Journal : " + getOffset() + "::" + getSize(); - } + public long getOffset() { + return offset; + } + + public long getSize() { + return size; + } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -133,18 +133,16 @@ long allocationClumpSize = getClumpSize(params.getBlockCount()); long bitmapBlocks = allocationClumpSize / blockSize; long blockUsed = 2 + burnedBlocksBeforeVH + burnedBlocksAfterAltVH + bitmapBlocks; - HFSPlusForkData forkdata = new HFSPlusForkData(); - forkdata.setTotalSize(allocationClumpSize); - forkdata.setClumpSize((int) allocationClumpSize); - forkdata.setTotalBlocks((int) bitmapBlocks); - ExtentDescriptor desc = new ExtentDescriptor(); - desc.setStartBlock(1 + burnedBlocksBeforeVH); - desc.setBlockCount((int) bitmapBlocks); - forkdata.setExtentDescriptor(0, desc); - System.arraycopy(forkdata.getBytes(), 0, data, 112, forkdata.FORK_DATA_LENGTH); + + int startBlock = 1 + burnedBlocksBeforeVH; + int blockCount = (int) bitmapBlocks; + + HFSPlusForkData forkdata = new HFSPlusForkData(allocationClumpSize, (int)allocationClumpSize,(int) bitmapBlocks); + ExtentDescriptor desc = new ExtentDescriptor(startBlock, blockCount); + forkdata.addDescriptor(0, desc); + System.arraycopy(forkdata.getBytes(), 0, data, 112, HFSPlusForkData.FORK_DATA_LENGTH); // Journal creation int nextBlock = 0; - if (params.isJournaled()) { this.setFileCount(2); this.setAttribute(HFSPLUS_VOL_JOURNALED_BIT); @@ -156,27 +154,18 @@ nextBlock = desc.getStartBlock() + desc.getBlockCount(); } // Extent B-Tree initialization - forkdata = new HFSPlusForkData(); - forkdata.setTotalSize(params.getExtentClumpSize()); - forkdata.setClumpSize(params.getExtentClumpSize()); - forkdata.setTotalBlocks((params.getExtentClumpSize() / blockSize)); - desc = new ExtentDescriptor(); - desc.setStartBlock(nextBlock); - desc.setBlockCount(forkdata.getTotalBlocks()); - forkdata.setExtentDescriptor(0, desc); - System.arraycopy(forkdata.getBytes(), 0, data, 192, forkdata.FORK_DATA_LENGTH); + forkdata = new HFSPlusForkData(params.getExtentClumpSize(),params.getExtentClumpSize(),(params.getExtentClumpSize() / blockSize)); + desc = new ExtentDescriptor(nextBlock, forkdata.getTotalBlocks()); + forkdata.addDescriptor(0, desc); + System.arraycopy(forkdata.getBytes(), 0, data, 192, HFSPlusForkData.FORK_DATA_LENGTH); blockUsed += forkdata.getTotalBlocks(); // Catalog B-Tree initialization - forkdata = new HFSPlusForkData(); - forkdata.setTotalSize(params.getCatalogClumpSize()); - forkdata.setClumpSize(params.getCatalogClumpSize()); - forkdata.setTotalBlocks(params.getCatalogClumpSize() / blockSize); - desc = new ExtentDescriptor(); - desc.setStartBlock(this.getExtentsFile().getExtents()[0].getStartBlock() - + this.getExtentsFile().getExtents()[0].getBlockCount()); - desc.setBlockCount(forkdata.getTotalBlocks()); - forkdata.setExtentDescriptor(0, desc); - System.arraycopy(forkdata.getBytes(), 0, data, 272, forkdata.FORK_DATA_LENGTH); + forkdata = new HFSPlusForkData(params.getCatalogClumpSize(),params.getCatalogClumpSize(),(params.getCatalogClumpSize() / blockSize)); + startBlock = this.getExtentsFile().getExtent(0).getStartBlock() + this.getExtentsFile().getExtent(0).getBlockCount(); + blockCount = forkdata.getTotalBlocks(); + desc = new ExtentDescriptor(startBlock, blockCount); + forkdata.addDescriptor(0, desc); + System.arraycopy(forkdata.getBytes(), 0, data, 272, HFSPlusForkData.FORK_DATA_LENGTH); blockUsed += forkdata.getTotalBlocks(); this.setFreeBlocks(this.getFreeBlocks() - (int) blockUsed); 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-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -22,12 +22,15 @@ import java.io.IOException; import java.nio.ByteBuffer; +import java.util.Calendar; +import java.util.Date; import java.util.LinkedList; import java.util.List; import org.apache.log4j.Logger; import org.jnode.fs.hfsplus.HFSPlusParams; import org.jnode.fs.hfsplus.HFSUnicodeString; +import org.jnode.fs.hfsplus.HFSUtils; import org.jnode.fs.hfsplus.HfsPlusConstants; import org.jnode.fs.hfsplus.HfsPlusFileSystem; import org.jnode.fs.hfsplus.Superblock; @@ -65,7 +68,7 @@ log.debug("Load B-Tree catalog file.\n"); this.fs = fs; Superblock sb = fs.getVolumeHeader(); - ExtentDescriptor firstExtent = sb.getCatalogFile().getExtents()[0]; + ExtentDescriptor firstExtent = sb.getCatalogFile().getExtent(0); catalogHeaderNodeOffset = firstExtent.getStartBlock() * sb.getBlockSize(); if (firstExtent.getStartBlock() != 0 && firstExtent.getBlockCount() != 0) { buffer = ByteBuffer.allocate(NodeDescriptor.BT_NODE_DESCRIPTOR_LENGTH @@ -121,9 +124,13 @@ // First record (folder) HFSUnicodeString name = new HFSUnicodeString(params.getVolumeName()); CatalogKey ck = new CatalogKey(CatalogNodeId.HFSPLUS_POR_CNID, name); - CatalogFolder folder = new CatalogFolder(); - folder.setFolderId(CatalogNodeId.HFSPLUS_ROOT_CNID); - folder.setValence(params.isJournaled() ? 2 : 0); + int valence = params.isJournaled() ? 2 : 0; + Calendar now = Calendar.getInstance(); + now.setTime(new Date()); + int macDate = (int) HFSUtils.getDate(now.getTimeInMillis() / 1000, true); + CatalogFolder folder = + new CatalogFolder(valence, CatalogNodeId.HFSPLUS_ROOT_CNID, macDate, macDate, + macDate); LeafRecord record = new LeafRecord(ck, folder.getBytes()); rootNode.addNodeRecord(0, record, offset); // Second record (thread) Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogFolder.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -27,89 +27,103 @@ public class CatalogFolder { public static final int CATALOG_FOLDER_SIZE = 88; - - private byte[] data; + private int recordType; + private int valence; + private CatalogNodeId folderId; + private int createDate; + private int contentModDate; + private int attrModDate; + + /** + * + * @param src + */ public CatalogFolder(final byte[] src) { - data = new byte[88]; + byte[] data = new byte[88]; System.arraycopy(src, 0, data, 0, CATALOG_FOLDER_SIZE); + recordType = BigEndian.getInt16(data, 0); + valence = BigEndian.getInt32(data, 4); + folderId = new CatalogNodeId(data, 8); + createDate = BigEndian.getInt32(data, 12); + contentModDate = BigEndian.getInt32(data, 16); + attrModDate = BigEndian.getInt32(data, 20); } /** - * Create a new catalog folder. * - * @param folderId - * + * @param valence + * @param folderID + * @param createDate + * @param contentModDate + * @param attrModDate */ - public CatalogFolder() { - data = new byte[88]; - BigEndian.setInt16(data, 0, HfsPlusConstants.RECORD_TYPE_FOLDER); + public CatalogFolder(int valence, CatalogNodeId folderID, int createDate, + int contentModDate, int attribModDate) { + this.recordType = HfsPlusConstants.RECORD_TYPE_FOLDER; + this.valence = valence; + this.folderId = folderID; + this.createDate = createDate; + this.contentModDate = contentModDate; + this.attrModDate = attribModDate; } - public final int getRecordType() { - return BigEndian.getInt16(data, 0); - } - - public final void setValence(int valence) { + /** + * Return bytes representation of the catalog folder. + * + * @return byte array representation. + */ + public byte[] getBytes() { + byte[] data = new byte[88]; + BigEndian.setInt16(data, 0, recordType); BigEndian.setInt32(data, 4, valence); + System.arraycopy(folderId.getBytes(), 0, data, 8, folderId.getBytes().length); + BigEndian.setInt32(data, 12, createDate); + BigEndian.setInt32(data, 16, contentModDate); + BigEndian.setInt32(data, 20, attrModDate); + return data; } - public final int getValence() { - return BigEndian.getInt32(data, 4); + /* + * (non-Javadoc) + * @see java.lang.Object#toString() + */ + public String toString() { + StringBuffer s = new StringBuffer(); + s.append("Record type: ").append(recordType).append("\n"); + s.append("Valence: ").append(valence).append("\n"); + s.append("Folder ID: ").append(folderId.getId()).append("\n"); + s.append("Creation Date :").append( + HFSUtils.printDate(createDate, "EEE MMM d HH:mm:ss yyyy")).append("\n"); + s.append("Content Mod Date :").append( + HFSUtils.printDate(contentModDate, "EEE MMM d HH:mm:ss yyyy")).append("\n"); + s.append("Attr Mod Date :").append( + HFSUtils.printDate(attrModDate, "EEE MMM d HH:mm:ss yyyy")).append("\n"); + return s.toString(); } - public final CatalogNodeId getFolderId() { - return new CatalogNodeId(data, 8); + public int getRecordType() { + return recordType; } - public final void setFolderId(CatalogNodeId folderId) { - System.arraycopy(folderId.getBytes(), 0, data, 8, - folderId.getBytes().length); + public int getValence() { + return valence; } - public final int getCreateDate() { - return BigEndian.getInt32(data, 12); + public CatalogNodeId getFolderId() { + return folderId; } - public void setCreateDate(int time) { - BigEndian.setInt32(data, 12, time); + public int getCreateDate() { + return createDate; } - public final int getContentModDate() { - return BigEndian.getInt32(data, 16); + public int getContentModDate() { + return contentModDate; } - public void setContentModDate(int time) { - BigEndian.setInt32(data, 16, time); + public int getAttrModDate() { + return attrModDate; } - - public final int getAttrModDate() { - return BigEndian.getInt32(data, 20); - } - - public void setAttrModDate(int time) { - BigEndian.setInt32(data, 20, time); - } - - public byte[] getBytes() { - return data; - } - - public final String toString() { - StringBuffer s = new StringBuffer(); - s.append("Record type: ").append(getRecordType()).append("\n"); - s.append("Valence: ").append(getValence()).append("\n"); - s.append("Folder ID: ").append(getFolderId().getId()).append("\n"); - s.append("Creation Date :").append( - HFSUtils.printDate(getCreateDate(), "EEE MMM d HH:mm:ss yyyy")) - .append("\n"); - s.append("Content Mod Date :").append( - HFSUtils.printDate(getContentModDate(), - "EEE MMM d HH:mm:ss yyyy")).append("\n"); - s.append("Attr Mod Date :") - .append( - HFSUtils.printDate(getAttrModDate(), - "EEE MMM d HH:mm:ss yyyy")).append("\n"); - return s.toString(); - } + } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogKey.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -27,12 +27,19 @@ public class CatalogKey extends AbstractKey { - public static final int MINIMUM_KEY_LENGTH = 6; - public static final int MAXIMUM_KEY_LENGTH = 516; + public static final int MINIMUM_KEY_LENGTH = 6; + public static final int MAXIMUM_KEY_LENGTH = 516; + /** + * Catalog node id of the folder that contains file or folder represented by + * the record. For thread records, contains the catalog node id of the file + * or folder itself. + */ + private CatalogNodeId parentId; + /** Name of the file or folder, empty for thread records. */ + private HFSUnicodeString nodeName; - private HFSUnicodeString nodeName; - /** + * Create catalog key from existing data. * * @param src * @param offset @@ -45,7 +52,7 @@ currentOffset += 2; ck = new byte[4]; System.arraycopy(src, currentOffset, ck, 0, 4); - parentID = new CatalogNodeId(ck, 0); + parentId = new CatalogNodeId(ck, 0); currentOffset += 4; if (keyLength > MINIMUM_KEY_LENGTH) { nodeName = new HFSUnicodeString(src, currentOffset); @@ -53,24 +60,20 @@ } /** - * Create catalog key based on parent CNID and the name of the file or folder. + * Create new catalog key based on parent CNID and the name of the file or folder. * * @param parentID Parent catalog node identifier. * @param name Name of the file or folder. * */ public CatalogKey(final CatalogNodeId parentID, final HFSUnicodeString name) { - this.parentID = parentID; + this.parentId = parentID; this.nodeName = name; this.keyLength = MINIMUM_KEY_LENGTH + name.getLength(); } - public final int getKeyLength() { - return keyLength; - } - public final CatalogNodeId getParentId() { - return parentID; + return parentId; } public final HFSUnicodeString getNodeName() { @@ -104,7 +107,7 @@ public byte[] getBytes() { byte[] data = new byte[this.getKeyLength()]; BigEndian.setInt16(data, 0, this.getKeyLength()); - System.arraycopy(parentID.getBytes(), 0, data, 2, 4); + System.arraycopy(parentId.getBytes(), 0, data, 2, 4); System.arraycopy(nodeName.getBytes(), 0, data, 6, nodeName.getLength()); return data; } 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-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/CatalogThread.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -28,42 +28,50 @@ 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; - private byte[] data; - + /** + * Create catalog thread from existing data. + * + * @param src byte array contains catalog thread data. + */ public CatalogThread(final byte[] src) { - data = new byte[512]; + byte[] data = new byte[512]; System.arraycopy(src, 0, data, 0, CATALOG_THREAD_SIZE); + recordType = BigEndian.getInt16(data, 0); + parentId = new CatalogNodeId(data, 4); + nodeName = new HFSUnicodeString(data, 8); } /** * Create a new catalog thread. * - * @param type - * @param parent - * @param name + * @param type catalog thread record type. + * @param parent {@link CatalogNodeId} of the file or folder reference by the tread record. + * @param name {@link HFSUnicodeString} represent the name of the file or folder reference by the tread record. */ public CatalogThread(int type, CatalogNodeId parent, HFSUnicodeString name) { - data = new byte[512]; - BigEndian.setInt16(data, 0, type); - BigEndian.setInt32(data, 4, parent.getId()); - System.arraycopy(parent.getBytes(), 0, data, 4, 4); - System.arraycopy(name.getBytes(), 0, data, 8, name.getBytes().length); + this.recordType = type; + this.parentId = parent; + this.nodeName = name; } - - public final int getRecordType() { - return BigEndian.getInt16(data, 0); - } - - public final CatalogNodeId getParentId() { - return new CatalogNodeId(data, 4); - } - - public final HFSUnicodeString getNodeName() { - return new HFSUnicodeString(data, 8); - } + /** + * + * @return + */ public byte[] getBytes() { + byte[] data = new byte[512]; + BigEndian.setInt16(data, 0, recordType); + BigEndian.setInt32(data, 4, parentId.getId()); + System.arraycopy(parentId.getBytes(), 0, data, 4, 4); + System.arraycopy(nodeName.getBytes(), 0, data, 8, nodeName.getBytes().length); return data; } + } 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-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentDescriptor.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -23,44 +23,61 @@ import org.jnode.util.BigEndian; public class ExtentDescriptor { - + /** The size pf 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; - private byte[] data; - /** - * Create empty extent descriptor. + * Create a new extent descriptor. + * + * @param startBlock first allocation block. + * @param blockCount number of blocks in the extent. */ - public ExtentDescriptor() { - data = new byte[EXTENT_DESCRIPTOR_LENGTH]; - } - - public ExtentDescriptor(final byte[] src, final int offset) { - data = new byte[EXTENT_DESCRIPTOR_LENGTH]; + public ExtentDescriptor(int startBlock, int blockCount) { + this.startBlock = startBlock; + this.blockCount = blockCount; + } + + /** + * Create extent descriptor from existing data. + * + * @param src byte array contains existing extent descriptor informations. + * @param offset position where data for extent descriptor begin. + */ + 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); } + /** + * + * @return + */ + public final byte[] getBytes() { + byte[] data = new byte[EXTENT_DESCRIPTOR_LENGTH]; + BigEndian.setInt32(data, 0, startBlock); + BigEndian.setInt32(data, 4, blockCount); + return data; + } - public final int getStartBlock() { - return BigEndian.getInt32(data, 0); + public final String toString() { + return "Start block : " + startBlock + "\tBlock count : " + blockCount + "\n"; } - public final void setStartBlock(int start) { - BigEndian.setInt32(data, 0, start); - } + public int getStartBlock() { + return startBlock; + } - public final int getBlockCount() { - return BigEndian.getInt32(data, 4); - } + public int getBlockCount() { + return blockCount; + } + + public boolean isEmpty(){ + return (startBlock == 0 || blockCount == 0); + } - public final void setBlockCount(int count) { - BigEndian.setInt32(data, 4, count); - } - - public final byte[] getBytes() { - return data; - } - - public final String toString() { - return "Start block : " + getStartBlock() + "\tBlock count : " + getBlockCount() + "\n"; - } } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentKey.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentKey.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/extent/ExtentKey.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -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.extent; import org.jnode.fs.hfsplus.catalog.CatalogNodeId; @@ -26,71 +26,94 @@ import org.jnode.util.BigEndian; public class ExtentKey extends AbstractKey { - - public static final byte DATA_FORK = (byte) 0x00; - public static final byte RESOURCE_FORK = (byte) 0xFF; - public static final int KEY_LENGTH = 12; - byte[] ek; + public static final byte DATA_FORK = (byte) 0x00; + public static final byte RESOURCE_FORK = (byte) 0xFF; + public static final int KEY_LENGTH = 12; - public ExtentKey(final byte[] src, final int offset) { - ek = new byte[KEY_LENGTH]; - System.arraycopy(src, offset, ek, 0, KEY_LENGTH); - } + private int forkType; + private int pad; + private CatalogNodeId fileId; + private int startBlock; - @Override - public final int getKeyLength() { - return BigEndian.getInt16(ek, 0); - } - - public final int getForkType() { - return BigEndian.getInt8(ek, 2); - } + /** + * + * @param src + * @param offset + */ + public ExtentKey(final byte[] src, final int offset) { + byte[] ek = new byte[KEY_LENGTH]; + System.arraycopy(src, offset, ek, 0, KEY_LENGTH); + keyLength = BigEndian.getInt16(ek, 0); + forkType = BigEndian.getInt8(ek, 2); + pad = BigEndian.getInt8(ek, 3); + fileId = new CatalogNodeId(ek, 4); + startBlock = BigEndian.getInt32(ek, 8); + } - public final int getPad() { - return BigEndian.getInt8(ek, 3); - } + /** + * + * @param forkType + * @param pad + * @param fileId + * @param startBlock + */ + public ExtentKey(int forkType, int pad, CatalogNodeId fileId, int startBlock) { + super(); + this.forkType = forkType; + this.pad = pad; + this.fileId = fileId; + this.startBlock = startBlock; + } - public final CatalogNodeId getCatalogNodeId() { - return new CatalogNodeId(ek, 4); - } + @Override + public final int compareTo(final Key key) { + int res = -1; + if (key instanceof ExtentKey) { + ExtentKey compareKey = (ExtentKey) key; + res = fileId.compareTo(compareKey.getFileId()); + if (res == 0) { + res = compareForkType(compareKey.getForkType()); + if (res == 0) { + return compareStartBlock(compareKey.getStartBlock()); + } + } + } + return res; + } - public final int getStartBlock() { - return BigEndian.getInt32(ek, 8); - } + @Override + public byte[] getBytes() { + byte[] data = new byte[this.getKeyLength()]; + return data; + } - @Override - public final int compareTo(final Key key) { - int res = -1; - if (key instanceof ExtentKey) { - ExtentKey compareKey = (ExtentKey) key; - res = getCatalogNodeId().compareTo(compareKey.getCatalogNodeId()); - if (res == 0) { - res = compareForkType(compareKey.getForkType()); - if (res == 0) { - return compareStartBlock(compareKey.getStartBlock()); - } - } - } - return res; - } + private int compareForkType(int fork) { + Integer currentForkType = Integer.valueOf(forkType); + Integer forkType = Integer.valueOf(fork); + return currentForkType.compareTo(forkType); + } - @Override - public byte[] getBytes() { - byte[] data = new byte[this.getKeyLength()]; - return data; - } - - private int compareForkType(int fork) { - Integer currentForkType = Integer.valueOf(this.getForkType()); - Integer forkType = Integer.valueOf(fork); - return currentForkType.compareTo(forkType); - } - - private int compareStartBlock(int block) { - Integer currentStartBlock = Integer.valueOf(this.getStartBlock()); - Integer startBlock = Integer.valueOf(block); - return currentStartBlock.compareTo(startBlock); - } + private int compareStartBlock(int block) { + Integer currentStartBlock = Integer.valueOf(startBlock); + Integer startBlock = Integer.valueOf(block); + return currentStartBlock.compareTo(startBlock); + } + public int getForkType() { + return forkType; + } + + public int getPad() { + return pad; + } + + public CatalogNodeId getFileId() { + return fileId; + } + + public int getStartBlock() { + return startBlock; + } + } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractKey.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractKey.java 2009-03-13 11:24:46 UTC (rev 5096) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/tree/AbstractKey.java 2009-03-13 19:35:50 UTC (rev 5097) @@ -20,14 +20,14 @@ package org.jnode.fs.hfsplus.tree; -import org.jnode.fs.hfsplus.catalog.CatalogNodeId; public abstract class AbstractKey implements Key { protected int keyLength; - protected CatalogNodeId parentID; - public abstract int getKeyLength(); + public final int getKeyLength() { + return keyLength; + } public abstract byte[] getBytes(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |