|
From: <ga...@us...> - 2011-08-11 11:42:19
|
Revision: 5845
http://jnode.svn.sourceforge.net/jnode/?rev=5845&view=rev
Author: galatnm
Date: 2011-08-11 11:42:10 +0000 (Thu, 11 Aug 2011)
Log Message:
-----------
FS : clean up HFS+ code.
Modified Paths:
--------------
trunk/JNode.ipr
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2File.java
trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java
trunk/fs/src/fs/org/jnode/fs/ext2/Superblock.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/HfsPlusFileSystem.java
trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java
trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java
trunk/fs/src/fs/org/jnode/fs/spi/AbstractFSFile.java
trunk/fs/src/test/org/jnode/fs/hfsplus/HfsPlusFileSystemTest.java
Added Paths:
-----------
trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java
Removed Paths:
-------------
trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java
Modified: trunk/JNode.ipr
===================================================================
--- trunk/JNode.ipr 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/JNode.ipr 2011-08-11 11:42:10 UTC (rev 5845)
@@ -17,11 +17,11 @@
<component name="CheckStyle-IDEA">
<option name="configuration">
<map>
- <entry key="active-configuration" value="FILE:$PROJECT_DIR$/all/jnode_checks.xml:JNode" />
+ <entry key="active-configuration" value="FILE:/home/flesire/developement/sources/jnode/jnode.orig/all/jnode_checks.xml:JNode" />
<entry key="check-test-classes" value="true" />
<entry key="config-file" value="$PROJECT_DIR$/all/jnode_checks.xml" />
<entry key="location-0" value="CLASSPATH:/sun_checks.xml:The default CheckStyle rules." />
- <entry key="location-1" value="FILE:$PROJECT_DIR$/all/jnode_checks.xml:JNode" />
+ <entry key="location-1" value="FILE:/home/flesire/developement/sources/jnode/jnode.orig/all/jnode_checks.xml:JNode" />
<entry key="thirdparty-classpath" value="" />
</map>
</option>
@@ -214,12 +214,13 @@
</component>
<component name="IdProvider" IDEtalkID="435AAC2234C36B0F2257FA7F02C447FB" />
<component name="InspectionProjectProfileManager">
- <list size="5">
+ <list size="6">
<item index="0" class="java.lang.String" itemvalue="SERVER PROBLEM" />
- <item index="1" class="java.lang.String" itemvalue="INFO" />
- <item index="2" class="java.lang.String" itemvalue="TYPO" />
- <item index="3" class="java.lang.String" itemvalue="WARNING" />
- <item index="4" class="java.lang.String" itemvalue="ERROR" />
+ <item index="1" class="java.lang.String" itemvalue="WEAK WARNING" />
+ <item index="2" class="java.lang.String" itemvalue="INFO" />
+ <item index="3" class="java.lang.String" itemvalue="TYPO" />
+ <item index="4" class="java.lang.String" itemvalue="WARNING" />
+ <item index="5" class="java.lang.String" itemvalue="ERROR" />
</list>
</component>
<component name="JavacSettings">
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2File.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2File.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2File.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -45,32 +45,13 @@
log.setLevel(Level.DEBUG);
}
- /**
- * @see org.jnode.fs.FSFile#getLength()
- */
+ @Override
public long getLength() {
//log.debug("getLength(): "+iNode.getSize());
return iNode.getSize();
}
- private long getLengthInBlocks() {
- return iNode.getSizeInBlocks();
- }
-
- private void rereadInode() throws IOException {
- int iNodeNr = iNode.getINodeNr();
- try {
- iNode = ((Ext2FileSystem) getFileSystem()).getINode(iNodeNr);
- } catch (FileSystemException ex) {
- final IOException ioe = new IOException();
- ioe.initCause(ex);
- throw ioe;
- }
- }
-
- /**
- * @see org.jnode.fs.FSFile#setLength(long)
- */
+ @Override
public void setLength(long length) throws IOException {
if (!canWrite())
throw new ReadOnlyFileSystemException("FileSystem or File is readonly");
@@ -163,9 +144,9 @@
} // synchronized(inode)
}
- /**
- * @see org.jnode.fs.FSFile#read(long, ByteBuffer)
- */
+
+
+ @Override
public void read(long fileOffset, ByteBuffer destBuf) throws IOException {
final int len = destBuf.remaining();
final int off = 0;
@@ -174,8 +155,7 @@
final byte[] dest = destBA.toArray();
//synchronize to the inode cache to make sure that the inode does not
- // get
- //flushed between reading it and locking it
+ // get flushed between reading it and locking it
synchronized (((Ext2FileSystem) getFileSystem()).getInodeCache()) {
//reread the inode before synchronizing to it to make sure
//all threads use the same instance
@@ -228,13 +208,7 @@
destBA.refreshByteBuffer();
}
- /**
- * Write into the file. fileOffset is between 0 and getLength() (see the
- * methods write(byte[], int, int), setPosition(long), setLength(long) in
- * org.jnode.fs.service.def.FileHandleImpl)
- *
- * @see org.jnode.fs.FSFile#write(long, ByteBuffer)
- */
+ @Override
public void write(long fileOffset, ByteBuffer srcBuf) throws IOException {
final int len = srcBuf.remaining();
final int off = 0;
@@ -331,11 +305,7 @@
}
}
- /**
- * Flush any cached data to the disk.
- *
- * @throws IOException
- */
+ @Override
public void flush() throws IOException {
log.debug("Ext2File.flush()");
iNode.update();
@@ -343,4 +313,19 @@
//been allocated or deallocated
iNode.getExt2FileSystem().updateFS();
}
+
+ private long getLengthInBlocks() {
+ return iNode.getSizeInBlocks();
+ }
+
+ private void rereadInode() throws IOException {
+ int iNodeNr = iNode.getINodeNr();
+ try {
+ iNode = ((Ext2FileSystem) getFileSystem()).getINode(iNodeNr);
+ } catch (FileSystemException ex) {
+ final IOException ioe = new IOException();
+ ioe.initCause(ex);
+ throw ioe;
+ }
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Ext2FileSystem.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -91,7 +91,7 @@
// skip the first 1024 bytes (bootsector) and read the superblock
// TODO: the superblock should read itself
getApi().read(1024, data);
- // superblock = new Superblock(data, this);
+ // superblock = new SuperBlock(data, this);
superblock = new Superblock();
superblock.read(data.array(), this);
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/Superblock.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/Superblock.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/Superblock.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -157,7 +157,7 @@
setPreallocBlocks(8);
setPreallocDirBlocks(0);
- log.debug("Superblock.create(): getBlockSize(): " + getBlockSize());
+ log.debug("SuperBlock.create(): getBlockSize(): " + getBlockSize());
}
/**
@@ -693,7 +693,7 @@
}
/**
- * @return the Superblock's dirty flag
+ * @return the SuperBlock's dirty flag
*/
public boolean isDirty() {
return dirty;
Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusDirectory.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -29,6 +29,7 @@
import org.apache.log4j.Logger;
import org.jnode.fs.FSDirectory;
import org.jnode.fs.FSEntry;
+import org.jnode.fs.FileSystem;
import org.jnode.fs.ReadOnlyFileSystemException;
import org.jnode.fs.hfsplus.catalog.Catalog;
import org.jnode.fs.hfsplus.catalog.CatalogFile;
@@ -38,26 +39,29 @@
import org.jnode.fs.hfsplus.tree.LeafRecord;
import org.jnode.fs.spi.FSEntryTable;
-public class HfsPlusDirectory extends HfsPlusEntry implements FSDirectory {
+public class HfsPlusDirectory implements FSDirectory {
private static final Logger log = Logger.getLogger(HfsPlusDirectory.class);
+ /** The directory entry */
+ private HfsPlusEntry entry;
+
/** Table of entries of our parent */
private FSEntryTable entries;
+ /** The catalog directory record */
private CatalogFolder folder;
- public HfsPlusDirectory(HfsPlusFileSystem fs, HfsPlusDirectory parent, String name,
- LeafRecord record) {
- super(fs, parent, name, record);
- this.folder = new CatalogFolder(record.getData());
+ public HfsPlusDirectory(HfsPlusEntry entry) {
+ this.entry = entry;
+ this.folder = new CatalogFolder(entry.getData());
this.entries = FSEntryTable.EMPTY_TABLE;
}
@Override
public FSEntry addDirectory(String name) throws IOException {
log.debug("<<< BEGIN addDirectory " + name + " >>>");
- if (fs.isReadOnly()) {
+ if (getFileSystem().isReadOnly()) {
throw new ReadOnlyFileSystemException();
}
@@ -73,7 +77,7 @@
@Override
public FSEntry addFile(String name) throws IOException {
log.debug("<<< BEGIN addFile " + name + " >>>");
- if (fs.isReadOnly()) {
+ if (getFileSystem().isReadOnly()) {
throw new ReadOnlyFileSystemException();
}
if (getEntry(name) != null) {
@@ -86,10 +90,11 @@
return newEntry;
}
- private final FSEntry createFileEntry(final String name) throws IOException {
+ private FSEntry createFileEntry(final String name) throws IOException {
+ //TODO implements this method.
/*
* if (fs.isReadOnly()) { throw new ReadOnlyFileSystemException(); }
- * Catalog catalog = fs.getCatalog(); Superblock volumeHeader =
+ * Catalog catalog = fs.getCatalog(); SuperBlock volumeHeader =
* ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader(); LeafRecord
* fileRecord = catalog.createNode(name, this.folder .getFolderId(), new
* CatalogNodeId(volumeHeader.getNextCatalogId()),
@@ -107,14 +112,14 @@
@Override
public void flush() throws IOException {
log.debug("<<< BEGIN flush >>>");
- if (fs.isReadOnly()) {
+ if (getFileSystem().isReadOnly()) {
throw new ReadOnlyFileSystemException();
}
boolean flushEntries = isEntriesLoaded() && entries.isDirty();
- if (isDirty() || flushEntries) {
+ if (entry.isDirty() || flushEntries) {
writeEntries(entries);
// entries.resetDirty();
- resetDirty();
+ entry.resetDirty();
}
log.debug("<<< END flush >>>");
}
@@ -137,13 +142,12 @@
@Override
public void remove(String name) throws IOException {
- if (fs.isReadOnly()) {
+ if (getFileSystem().isReadOnly()) {
throw new ReadOnlyFileSystemException();
}
if (entries.remove(name) >= 0) {
- setDirty();
+ entry.setDirty();
flush();
- return;
} else {
throw new FileNotFoundException(name);
}
@@ -160,7 +164,7 @@
if (!isEntriesLoaded()) {
log.debug("checkEntriesLoaded : loading");
try {
- if (rights.canRead()) {
+ if (entry.getAccessRights().canRead()) {
entries = readEntries();
log.debug("Load " + entries.size() + " entrie(s).");
} else {
@@ -169,7 +173,7 @@
entries = FSEntryTable.EMPTY_TABLE;
log.debug("checkEntriesLoaded : can't read, using EMPTY_TABLE");
}
- resetDirty();
+ entry.resetDirty();
} catch (IOException e) {
log.fatal("unable to read directory entries", e);
// the next time, we will call checkEntriesLoaded()
@@ -185,16 +189,16 @@
*
* @return if the entries are already loaded from the device
*/
- private final boolean isEntriesLoaded() {
+ private boolean isEntriesLoaded() {
return (entries != FSEntryTable.EMPTY_TABLE);
}
/**
*
- * @return
+ * @return read all entries link to the current directory in the file system.
* @throws IOException
*/
- private final FSEntryTable readEntries() throws IOException {
+ private FSEntryTable readEntries() throws IOException {
List<FSEntry> pathList = new LinkedList<FSEntry>();
HfsPlusFileSystem fs = (HfsPlusFileSystem) getFileSystem();
if (fs.getVolumeHeader().getFolderCount() > 0) {
@@ -203,7 +207,7 @@
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);
+ HfsPlusEntry e = new HfsPlusEntry(fs, this, name, rec);
pathList.add(e);
}
}
@@ -217,23 +221,23 @@
/**
*
- * @param name
- * @return
- * @throws IOException
+ * @param name The name of the entry.
+ * @return Return the newly created entry.
+ * @throws IOException if problem occurs during catalog node creation or if system is read-only.
*/
- private final FSEntry createDirectoryEntry(final String name) throws IOException {
- if (fs.isReadOnly()) {
+ private FSEntry createDirectoryEntry(final String name) throws IOException {
+ if (getFileSystem().isReadOnly()) {
throw new ReadOnlyFileSystemException();
}
- Catalog catalog = fs.getCatalog();
- Superblock volumeHeader = ((HfsPlusFileSystem) getFileSystem()).getVolumeHeader();
+ Catalog catalog = ((HfsPlusFileSystem)getFileSystem()).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);
+ HfsPlusEntry newEntry = new HfsPlusEntry((HfsPlusFileSystem)getFileSystem(), this, name, folderRecord);
newEntry.setDirty();
volumeHeader.setFolderCount(volumeHeader.getFolderCount() + 1);
log.debug("New volume header :\n" + volumeHeader.toString());
@@ -247,14 +251,22 @@
* @param newEntry
* @throws IOException
*/
- private final void setFreeEntry(FSEntry newEntry) throws IOException {
+ private void setFreeEntry(FSEntry newEntry) throws IOException {
checkEntriesLoaded();
if (entries.setFreeEntry(newEntry) >= 0) {
log.debug("setFreeEntry: free entry found !");
- setDirty();
+ entry.setDirty();
flush();
- return;
}
}
+ @Override
+ public boolean isValid() {
+ return entry.isValid();
+ }
+
+ @Override
+ public FileSystem<?> getFileSystem() {
+ return entry.getFileSystem();
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusEntry.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusEntry.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -26,6 +26,7 @@
import org.jnode.fs.FSDirectory;
import org.jnode.fs.FSEntry;
import org.jnode.fs.FSFile;
+import org.jnode.fs.FSObject;
import org.jnode.fs.FileSystem;
import org.jnode.fs.hfsplus.catalog.CatalogFile;
import org.jnode.fs.hfsplus.catalog.CatalogFolder;
@@ -87,7 +88,7 @@
if (!isDirectory()) {
throw new IOException("It is not a Directory");
}
- return (HfsPlusDirectory) this;
+ return new HfsPlusDirectory(this);
}
@Override
@@ -95,7 +96,7 @@
if (!isFile()) {
throw new IOException("It is not a file");
}
- return (HfsPlusFile) this;
+ return new HfsPlusFile(this);
}
@Override
@@ -164,4 +165,8 @@
return valid;
}
+ public byte[] getData(){
+ return this.record.getData();
+ }
+
}
Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFile.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFile.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFile.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -24,17 +24,19 @@
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;
import org.jnode.fs.hfsplus.tree.LeafRecord;
-public class HfsPlusFile extends HfsPlusEntry implements FSFile {
+public class HfsPlusFile implements FSFile {
+ private HfsPlusEntry entry;
+
private CatalogFile file;
- public HfsPlusFile(HfsPlusFileSystem fs, HfsPlusDirectory parent, String name, LeafRecord record) {
- super(fs, parent, name, record);
- this.file = new CatalogFile(record.getData());
+ public HfsPlusFile(HfsPlusEntry entry) {
+ this.file = new CatalogFile(entry.getData());
}
@Override
@@ -48,11 +50,16 @@
}
@Override
+ public void setLength(final long length) throws IOException {
+ // TODO Auto-generated method stub
+ }
+
+ @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());
+ long firstOffset = (long) d.getStartOffset(fs.getVolumeHeader().getBlockSize());
fs.getApi().read(firstOffset, dest);
}
}
@@ -64,9 +71,14 @@
}
- public void setLength(final long length) throws IOException {
- // TODO Auto-generated method stub
+ @Override
+ public boolean isValid() {
+ return entry.isValid();
}
+ @Override
+ public FileSystem<?> getFileSystem() {
+ return entry.getFileSystem();
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -37,7 +37,7 @@
private final Logger log = Logger.getLogger(getClass());
/** HFS volume header */
- private Superblock volumeHeader;
+ private SuperBlock volumeHeader;
/** Catalog special file for this instance */
private Catalog catalog;
@@ -55,22 +55,22 @@
}
/**
- *
+ *
* @throws FileSystemException
*/
public final void read() throws FileSystemException {
- volumeHeader = new Superblock(this, false);
+ volumeHeader = new SuperBlock(this, false);
log.debug(volumeHeader.toString());
- if (!volumeHeader.isAttribute(Superblock.HFSPLUS_VOL_UNMNT_BIT)) {
+ if (!volumeHeader.isAttribute(SuperBlock.HFSPLUS_VOL_UNMNT_BIT)) {
log.info(getDevice().getId() +
" Filesystem has not been cleanly unmounted, mounting it readonly");
setReadOnly(true);
}
- if (volumeHeader.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 (volumeHeader.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");
@@ -98,35 +98,20 @@
log.info("Create root entry.");
LeafRecord record = catalog.getRecord(CatalogNodeId.HFSPLUS_POR_CNID);
if (record != null) {
- return new HfsPlusDirectory(this, null, "/", record);
+ return new HfsPlusEntry(this, null, "/", record);
}
log.error("Root entry : No record found.");
return null;
}
- /*
- * (non-Javadoc)
- *
- * @see org.jnode.fs.FileSystem#getFreeSpace()
- */
public final long getFreeSpace() {
return volumeHeader.getFreeBlocks() * volumeHeader.getBlockSize();
}
- /*
- * (non-Javadoc)
- *
- * @see org.jnode.fs.FileSystem#getTotalSpace()
- */
public final long getTotalSpace() {
return volumeHeader.getTotalBlocks() * volumeHeader.getBlockSize();
}
- /*
- * (non-Javadoc)
- *
- * @see org.jnode.fs.FileSystem#getUsableSpace()
- */
public final long getUsableSpace() {
return -1;
}
@@ -135,7 +120,7 @@
return catalog;
}
- public final Superblock getVolumeHeader() {
+ public final SuperBlock getVolumeHeader() {
return volumeHeader;
}
@@ -147,7 +132,7 @@
* @throws FileSystemException
*/
public void create(HFSPlusParams params) throws FileSystemException {
- volumeHeader = new Superblock(this, true);
+ volumeHeader = new SuperBlock(this, true);
try {
params.initializeDefaultsValues(this);
volumeHeader.create(params);
Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemType.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -63,7 +63,7 @@
return false;
}
int magicNumber = BigEndian.getInt16(magic.array(), 0);
- return (magicNumber == Superblock.HFSPLUS_SUPER_MAGIC);
+ return (magicNumber == SuperBlock.HFSPLUS_SUPER_MAGIC);
}
}
Copied: trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java (from rev 5844, trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java)
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -0,0 +1,475 @@
+/*
+ * $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;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.Calendar;
+import java.util.Date;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jnode.fs.FileSystemException;
+import org.jnode.fs.hfsplus.catalog.CatalogNodeId;
+import org.jnode.fs.hfsplus.extent.ExtentDescriptor;
+import org.jnode.util.BigEndian;
+import org.jnode.util.NumberUtils;
+
+/**
+ * HFS+ volume header definition.
+ *
+ * @author Fabien Lesire
+ *
+ */
+public class SuperBlock extends HfsPlusObject {
+
+ public static final int HFSPLUS_SUPER_MAGIC = 0x482b;
+
+ public static final int HFSPLUS_MIN_VERSION = 0x0004; /* HFS+ */
+ public static final int HFSPLUS_CURRENT_VERSION = 5; /* HFSX */
+
+ /* HFS+ volume attributes */
+ public static final int HFSPLUS_VOL_UNMNT_BIT = 8;
+ public static final int HFSPLUS_VOL_SPARE_BLK_BIT = 9;
+ public static final int HFSPLUS_VOL_NOCACHE_BIT = 10;
+ public static final int HFSPLUS_VOL_INCNSTNT_BIT = 11;
+ public static final int HFSPLUS_VOL_NODEID_REUSED_BIT = 12;
+ public static final int HFSPLUS_VOL_JOURNALED_BIT = 13;
+ public static final int HFSPLUS_VOL_SOFTLOCK_BIT = 15;
+
+ private final Logger log = Logger.getLogger(getClass());
+
+ /** Volume header data length */
+ public static final int SUPERBLOCK_LENGTH = 1024;
+
+ /** Data bytes array that contains volume header information */
+ private byte[] data;
+
+ /**
+ * Create the volume header and load information for the file system passed
+ * as parameter.
+ *
+ * @param fs The file system contains HFS+ partition.
+ *
+ * @throws FileSystemException If magic number (0X482B) is incorrect or not
+ * available.
+ */
+ public SuperBlock(final HfsPlusFileSystem fs, boolean create) throws FileSystemException {
+ super(fs);
+ log.setLevel(Level.INFO);
+ data = new byte[SUPERBLOCK_LENGTH];
+ try {
+ if (!create) {
+ log.info("load HFS+ volume header.");
+ // skip the first 1024 bytes (boot sector) and read the volume
+ // header.
+ ByteBuffer b = ByteBuffer.allocate(SUPERBLOCK_LENGTH);
+ fs.getApi().read(1024, b);
+ data = new byte[SUPERBLOCK_LENGTH];
+ System.arraycopy(b.array(), 0, data, 0, SUPERBLOCK_LENGTH);
+ if (getMagic() != HFSPLUS_SUPER_MAGIC) {
+ throw new FileSystemException("Not hfs+ volume header (" + getMagic() +
+ ": bad magic)");
+ }
+
+ }
+ } catch (IOException e) {
+ throw new FileSystemException(e);
+ }
+ }
+
+ /**
+ * Create a new volume header.
+ *
+ * @param params File system format parameters.
+ * @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;
+ int burnedBlocksAfterAltVH = 0;
+ /*
+ * Volume header is located at sector 2. Block before this position must
+ * be invalidated.
+ */
+ int blockSize = params.getBlockSize();
+ if (blockSize == 512) {
+ burnedBlocksBeforeVH = 2;
+ burnedBlocksAfterAltVH = 1;
+ } else if (blockSize == 1024) {
+ burnedBlocksBeforeVH = 1;
+ }
+ // Populate volume header.
+ this.setMagic(HFSPLUS_SUPER_MAGIC);
+ this.setVersion(HFSPLUS_MIN_VERSION);
+ // Set attributes.
+ this.setAttribute(HFSPLUS_VOL_UNMNT_BIT);
+ this.setLastMountedVersion(0x446534a);
+ Calendar now = Calendar.getInstance();
+ now.setTime(new Date());
+ int macDate = HfsUtils.getNow();
+ this.setCreateDate(macDate);
+ this.setModifyDate(macDate);
+ this.setCheckedDate(macDate);
+ // ---
+ this.setBlockSize(blockSize);
+ this.setTotalBlocks((int) params.getBlockCount());
+ this.setFreeBlocks((int) params.getBlockCount());
+ this.setRsrcClumpSize(params.getResourceClumpSize());
+ this.setDataClumpSize(params.getDataClumpSize());
+ this.setNextCatalogId(CatalogNodeId.HFSPLUS_FIRSTUSER_CNID.getId());
+ // Allocation file creation
+ log.info("Init allocation file.");
+ long allocationClumpSize = getClumpSize(params.getBlockCount());
+ long bitmapBlocks = allocationClumpSize / blockSize;
+ long blockUsed = 2 + burnedBlocksBeforeVH + burnedBlocksAfterAltVH + bitmapBlocks;
+ 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);
+ forkdata.write(data, 112);
+ // Journal creation
+ int nextBlock = 0;
+ if (params.isJournaled()) {
+ this.setFileCount(2);
+ this.setAttribute(HFSPLUS_VOL_JOURNALED_BIT);
+ this.setNextCatalogId(this.getNextCatalogId() + 2);
+ this.setJournalInfoBlock(desc.getNext());
+ blockUsed = blockUsed + 1 + (params.getJournalSize() / blockSize);
+ } else {
+ this.setJournalInfoBlock(0);
+ nextBlock = desc.getNext();
+ }
+ // Extent B-Tree initialization
+ log.info("Init extent file.");
+ forkdata =
+ new HfsPlusForkData(params.getExtentClumpSize(), params.getExtentClumpSize(),
+ (params.getExtentClumpSize() / blockSize));
+ desc = new ExtentDescriptor(nextBlock, forkdata.getTotalBlocks());
+ forkdata.addDescriptor(0, desc);
+ forkdata.write(data, 192);
+ blockUsed += forkdata.getTotalBlocks();
+ nextBlock = desc.getNext();
+ // Catalog B-Tree initialization
+ log.info("Init catalog file.");
+ int totalBlocks = params.getCatalogClumpSize() / blockSize;
+ forkdata =
+ new HfsPlusForkData(params.getCatalogClumpSize(), params.getCatalogClumpSize(),
+ totalBlocks);
+ desc = new ExtentDescriptor(nextBlock, totalBlocks);
+ forkdata.addDescriptor(0, desc);
+ forkdata.write(data, 272);
+ blockUsed += totalBlocks;
+
+ this.setFreeBlocks(this.getFreeBlocks() - (int) blockUsed);
+ this.setNextAllocation((int) blockUsed - 1 - burnedBlocksAfterAltVH + 10 *
+ (this.getCatalogFile().getClumpSize() / this.getBlockSize()));
+ }
+
+ /**
+ * Calculate the number of blocks needed for bitmap.
+ *
+ * @param totalBlocks Total of blocks found in the device.
+ * @return the number of blocks.
+ * @throws IOException
+ */
+ private long getClumpSize(long totalBlocks) throws IOException {
+ long clumpSize;
+ long minClumpSize = totalBlocks >> 3;
+ if ((totalBlocks & 7) == 0) {
+ ++minClumpSize;
+ }
+ clumpSize = minClumpSize;
+ return clumpSize;
+ }
+
+ // Getters/setters
+
+ public final int getMagic() {
+ return BigEndian.getInt16(data, 0);
+ }
+
+ public final void setMagic(final int value) {
+ BigEndian.setInt16(data, 0, value);
+ }
+
+ //
+ public final int getVersion() {
+ return BigEndian.getInt16(data, 2);
+ }
+
+ public final void setVersion(final int value) {
+ BigEndian.setInt16(data, 2, value);
+ }
+
+ //
+ public final int getAttributes() {
+
+ return BigEndian.getInt32(data, 4);
+ }
+
+ public final void setAttribute(final int attributeMaskBit) {
+ BigEndian.setInt32(data, 4, getAttributes() | (1 << attributeMaskBit));
+ }
+
+ //
+ public final int getLastMountedVersion() {
+ return BigEndian.getInt32(data, 8);
+ }
+
+ public final void setLastMountedVersion(final int value) {
+ BigEndian.setInt32(data, 8, value);
+ }
+
+ //
+ public final int getJournalInfoBlock() {
+ return BigEndian.getInt32(data, 12);
+ }
+
+ public final void setJournalInfoBlock(final int value) {
+ BigEndian.setInt32(data, 12, value);
+ }
+
+ //
+ public final long getCreateDate() {
+ return BigEndian.getUInt32(data, 16);
+ }
+
+ public final void setCreateDate(final int value) {
+ BigEndian.setInt32(data, 16, value);
+ }
+
+ public final long getModifyDate() {
+ return BigEndian.getUInt32(data, 20);
+ }
+
+ public final void setModifyDate(final int value) {
+ BigEndian.setInt32(data, 20, value);
+ }
+
+ public final long getBackupDate() {
+ return BigEndian.getUInt32(data, 24);
+ }
+
+ public final void setBackupDate(final int value) {
+ BigEndian.setInt32(data, 24, value);
+ }
+
+ public final long getCheckedDate() {
+ return BigEndian.getUInt32(data, 28);
+ }
+
+ public final void setCheckedDate(final int value) {
+ BigEndian.setInt32(data, 28, value);
+ }
+
+ //
+ public final int getFileCount() {
+ return BigEndian.getInt32(data, 32);
+ }
+
+ public final void setFileCount(final int value) {
+ BigEndian.setInt32(data, 32, value);
+ }
+
+ //
+ public final int getFolderCount() {
+ return BigEndian.getInt32(data, 36);
+ }
+
+ public final void setFolderCount(final int value) {
+ BigEndian.setInt32(data, 36, value);
+ }
+
+ //
+ public final int getBlockSize() {
+ return BigEndian.getInt32(data, 40);
+ }
+
+ public final void setBlockSize(final int value) {
+ BigEndian.setInt32(data, 40, value);
+ }
+
+ //
+ public final int getTotalBlocks() {
+ return BigEndian.getInt32(data, 44);
+ }
+
+ public final void setTotalBlocks(final int value) {
+ BigEndian.setInt32(data, 44, value);
+ }
+
+ //
+ public final int getFreeBlocks() {
+ return BigEndian.getInt32(data, 48);
+ }
+
+ public final void setFreeBlocks(final int value) {
+ BigEndian.setInt32(data, 48, value);
+ }
+
+ //
+ public final int getNextAllocation() {
+ return BigEndian.getInt32(data, 52);
+ }
+
+ public final void setNextAllocation(final int value) {
+ BigEndian.setInt32(data, 52, value);
+ }
+
+ public final long getRsrcClumpSize() {
+ return BigEndian.getInt32(data, 56);
+ }
+
+ public final void setRsrcClumpSize(final int value) {
+ BigEndian.setInt32(data, 56, value);
+ }
+
+ public final int getDataClumpSize() {
+ return BigEndian.getInt32(data, 60);
+ }
+
+ public final void setDataClumpSize(final int value) {
+ BigEndian.setInt32(data, 60, value);
+ }
+
+ public final int getNextCatalogId() {
+ return BigEndian.getInt32(data, 64);
+ }
+
+ public final void setNextCatalogId(final int value) {
+ BigEndian.setInt32(data, 64, value);
+ }
+
+ public final int getWriteCount() {
+ return BigEndian.getInt32(data, 68);
+ }
+
+ public final void setWriteCount(final int value) {
+ BigEndian.setInt32(data, 68, value);
+ }
+
+ public final long getEncodingsBmp() {
+ return BigEndian.getInt64(data, 72);
+ }
+
+ public final void setEncodingsBmp(final long value) {
+ BigEndian.setInt64(data, 72, value);
+ }
+
+ public final byte[] getFinderInfo() {
+ byte[] result = new byte[32];
+ System.arraycopy(data, 80, result, 0, 32);
+ return result;
+ }
+
+ public final HfsPlusForkData getAllocationFile() {
+ return new HfsPlusForkData(data, 112);
+ }
+
+ public final HfsPlusForkData getExtentsFile() {
+ return new HfsPlusForkData(data, 192);
+ }
+
+ public final HfsPlusForkData getCatalogFile() {
+ return new HfsPlusForkData(data, 272);
+ }
+
+ public final HfsPlusForkData getAttributesFile() {
+ return new HfsPlusForkData(data, 352);
+ }
+
+ public final HfsPlusForkData getStartupFile() {
+ return new HfsPlusForkData(data, 432);
+ }
+
+ /**
+ * Get string representation of attribute.
+ *
+ * @return the string representation
+ */
+ public final String getAttributesAsString() {
+ return ((isAttribute(HFSPLUS_VOL_UNMNT_BIT)) ? " kHFSVolumeUnmountedBit" : "") +
+ ((isAttribute(HFSPLUS_VOL_INCNSTNT_BIT)) ? " kHFSBootVolumeInconsistentBit" : "") +
+ ((isAttribute(HFSPLUS_VOL_JOURNALED_BIT)) ? " kHFSVolumeJournaledBit" : "");
+ }
+
+ /**
+ * Check if the corresponding attribute corresponding is set.
+ *
+ * @param maskBit Bit position of the attribute. See constants.
+ *
+ * @return {@code true} if attribute is set.
+ */
+ public final boolean isAttribute(final int maskBit) {
+ return (((getAttributes() >> maskBit) & 0x1) != 0);
+ }
+
+ public byte[] getBytes() {
+ return data;
+ }
+
+ public void update() throws IOException {
+ fs.getApi().write(1024, ByteBuffer.wrap(data));
+ }
+
+ public final String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("Magic: 0x").append(NumberUtils.hex(getMagic(), 4)).append("\n");
+ buffer.append("Version: ").append(getVersion()).append("\n").append("\n");
+ buffer.append("Attributes: ").append(getAttributesAsString()).append(" (").append(
+ getAttributes()).append(")").append("\n").append("\n");
+ buffer.append("Create date: ").append(
+ HfsUtils.printDate(getCreateDate(), "EEE MMM d HH:mm:ss yyyy")).append("\n");
+ buffer.append("Modify date: ").append(
+ HfsUtils.printDate(getModifyDate(), "EEE MMM d HH:mm:ss yyyy")).append("\n");
+ buffer.append("Backup date: ").append(
+ HfsUtils.printDate(getBackupDate(), "EEE MMM d HH:mm:ss yyyy")).append("\n");
+ buffer.append("Checked date: ").append(
+ HfsUtils.printDate(getCheckedDate(), "EEE MMM d HH:mm:ss yyyy")).append("\n")
+ .append("\n");
+ buffer.append("File count: ").append(getFileCount()).append("\n");
+ buffer.append("Folder count: ").append(getFolderCount()).append("\n").append("\n");
+ buffer.append("Block size: ").append(getBlockSize()).append("\n");
+ buffer.append("Total blocks: ").append(getTotalBlocks()).append("\n");
+ buffer.append("Free blocks: ").append(getFreeBlocks()).append("\n").append("\n");
+ buffer.append("Next catalog ID: ").append(getNextCatalogId()).append("\n");
+ buffer.append("Write count: ").append(getWriteCount()).append("\n");
+ buffer.append("Encoding bmp: ").append(getEncodingsBmp()).append("\n");
+ buffer.append("Finder Infos: ").append(getFinderInfo()).append("\n").append("\n");
+ buffer.append("Journal block: ").append(getJournalInfoBlock()).append("\n").append("\n");
+ buffer.append("Allocation file").append("\n");
+ buffer.append(getAllocationFile().toString()).append("\n");
+ buffer.append("Extents file").append("\n");
+ buffer.append(getExtentsFile().toString()).append("\n");
+ buffer.append("Catalog file").append("\n");
+ buffer.append(getCatalogFile().toString()).append("\n");
+ buffer.append("Attributes file").append("\n");
+ buffer.append(getAttributesFile().toString()).append("\n");
+ buffer.append("Startup file").append("\n");
+ buffer.append(getStartupFile().toString()).append("\n");
+ return buffer.toString();
+ }
+}
Property changes on: trunk/fs/src/fs/org/jnode/fs/hfsplus/SuperBlock.java
___________________________________________________________________
Added: svn:executable
+ *
Deleted: trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -1,478 +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;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.Calendar;
-import java.util.Date;
-
-import org.apache.log4j.Level;
-import org.apache.log4j.Logger;
-import org.jnode.fs.FileSystemException;
-import org.jnode.fs.hfsplus.catalog.CatalogNodeId;
-import org.jnode.fs.hfsplus.extent.ExtentDescriptor;
-import org.jnode.util.BigEndian;
-import org.jnode.util.NumberUtils;
-
-/**
- * HFS+ volume header definition.
- *
- * @author Fabien Lesire
- *
- */
-public class Superblock extends HfsPlusObject {
-
- public static final int HFSPLUS_SUPER_MAGIC = 0x482b;
-
- public static final int HFSPLUS_MIN_VERSION = 0x0004; /* HFS+ */
- public static final int HFSPLUS_CURRENT_VERSION = 5; /* HFSX */
-
- /* HFS+ volume attributes */
- public static final int HFSPLUS_VOL_UNMNT_BIT = 8;
- public static final int HFSPLUS_VOL_SPARE_BLK_BIT = 9;
- public static final int HFSPLUS_VOL_NOCACHE_BIT = 10;
- public static final int HFSPLUS_VOL_INCNSTNT_BIT = 11;
- public static final int HFSPLUS_VOL_NODEID_REUSED_BIT = 12;
- public static final int HFSPLUS_VOL_JOURNALED_BIT = 13;
- public static final int HFSPLUS_VOL_SOFTLOCK_BIT = 15;
-
- private final Logger log = Logger.getLogger(getClass());
-
- /** Volume header data length */
- public static final int SUPERBLOCK_LENGTH = 1024;
-
- /** Data bytes array that contains volume header information */
- private byte[] data;
-
- /**
- * Create the volume header and load information for the file system passed
- * as parameter.
- *
- * @param fs The file system contains HFS+ partition.
- *
- * @throws FileSystemException If magic number (0X482B) is incorrect or not
- * available.
- */
- public Superblock(final HfsPlusFileSystem fs, boolean create) throws FileSystemException {
- super(fs);
- log.setLevel(Level.INFO);
- data = new byte[SUPERBLOCK_LENGTH];
- try {
- if (!create) {
- log.info("load HFS+ volume header.");
- // skip the first 1024 bytes (boot sector) and read the volume
- // header.
- ByteBuffer b = ByteBuffer.allocate(SUPERBLOCK_LENGTH);
- fs.getApi().read(1024, b);
- data = new byte[SUPERBLOCK_LENGTH];
- System.arraycopy(b.array(), 0, data, 0, SUPERBLOCK_LENGTH);
- if (getMagic() != HFSPLUS_SUPER_MAGIC) {
- throw new FileSystemException("Not hfs+ volume header (" + getMagic() +
- ": bad magic)");
- }
-
- }
- } catch (IOException e) {
- throw new FileSystemException(e);
- }
- }
-
- /**
- * Create a new volume header.
- *
- * @param params
- *
- * @throws IOException
- * @throws ApiNotFoundException
- * @throws FileSystemException
- */
- 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;
- int burnedBlocksAfterAltVH = 0;
- /*
- * Volume header is located at sector 2. Block before this position must
- * be invalidated.
- */
- int blockSize = params.getBlockSize();
- if (blockSize == 512) {
- burnedBlocksBeforeVH = 2;
- burnedBlocksAfterAltVH = 1;
- } else if (blockSize == 1024) {
- burnedBlocksBeforeVH = 1;
- }
- // Populate volume header.
- this.setMagic(HFSPLUS_SUPER_MAGIC);
- this.setVersion(HFSPLUS_MIN_VERSION);
- // Set attributes.
- this.setAttribute(HFSPLUS_VOL_UNMNT_BIT);
- this.setLastMountedVersion(0x446534a);
- Calendar now = Calendar.getInstance();
- now.setTime(new Date());
- int macDate = HfsUtils.getNow();
- this.setCreateDate(macDate);
- this.setModifyDate(macDate);
- this.setCheckedDate(macDate);
- // ---
- this.setBlockSize(blockSize);
- this.setTotalBlocks((int) params.getBlockCount());
- this.setFreeBlocks((int) params.getBlockCount());
- this.setRsrcClumpSize(params.getResourceClumpSize());
- this.setDataClumpSize(params.getDataClumpSize());
- this.setNextCatalogId(CatalogNodeId.HFSPLUS_FIRSTUSER_CNID.getId());
- // Allocation file creation
- log.info("Init allocation file.");
- long allocationClumpSize = getClumpSize(params.getBlockCount());
- long bitmapBlocks = allocationClumpSize / blockSize;
- long blockUsed = 2 + burnedBlocksBeforeVH + burnedBlocksAfterAltVH + bitmapBlocks;
- 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);
- forkdata.write(data, 112);
- // Journal creation
- int nextBlock = 0;
- if (params.isJournaled()) {
- this.setFileCount(2);
- this.setAttribute(HFSPLUS_VOL_JOURNALED_BIT);
- this.setNextCatalogId(this.getNextCatalogId() + 2);
- this.setJournalInfoBlock(desc.getNext());
- blockUsed = blockUsed + 1 + (params.getJournalSize() / blockSize);
- } else {
- this.setJournalInfoBlock(0);
- nextBlock = desc.getNext();
- }
- // Extent B-Tree initialization
- log.info("Init extent file.");
- forkdata =
- new HfsPlusForkData(params.getExtentClumpSize(), params.getExtentClumpSize(),
- (params.getExtentClumpSize() / blockSize));
- desc = new ExtentDescriptor(nextBlock, forkdata.getTotalBlocks());
- forkdata.addDescriptor(0, desc);
- forkdata.write(data, 192);
- blockUsed += forkdata.getTotalBlocks();
- nextBlock = desc.getNext();
- // Catalog B-Tree initialization
- log.info("Init catalog file.");
- int totalBlocks = params.getCatalogClumpSize() / blockSize;
- forkdata =
- new HfsPlusForkData(params.getCatalogClumpSize(), params.getCatalogClumpSize(),
- totalBlocks);
- desc = new ExtentDescriptor(nextBlock, totalBlocks);
- forkdata.addDescriptor(0, desc);
- forkdata.write(data, 272);
- blockUsed += totalBlocks;
-
- this.setFreeBlocks(this.getFreeBlocks() - (int) blockUsed);
- this.setNextAllocation((int) blockUsed - 1 - burnedBlocksAfterAltVH + 10 *
- (this.getCatalogFile().getClumpSize() / this.getBlockSize()));
- }
-
- /**
- * Calculate the number of blocks needed for bitmap.
- *
- * @param totalBlocks Total of blocks found in the device.
- * @return the number of blocks.
- * @throws IOException
- */
- private long getClumpSize(long totalBlocks) throws IOException {
- long clumpSize;
- long minClumpSize = totalBlocks >> 3;
- if ((totalBlocks & 7) == 0) {
- ++minClumpSize;
- }
- clumpSize = minClumpSize;
- return clumpSize;
- }
-
- // Getters/setters
-
- public final int getMagic() {
- return BigEndian.getInt16(data, 0);
- }
-
- public final void setMagic(final int value) {
- BigEndian.setInt16(data, 0, value);
- }
-
- //
- public final int getVersion() {
- return BigEndian.getInt16(data, 2);
- }
-
- public final void setVersion(final int value) {
- BigEndian.setInt16(data, 2, value);
- }
-
- //
- public final int getAttributes() {
-
- return BigEndian.getInt32(data, 4);
- }
-
- public final void setAttribute(final int attributeMaskBit) {
- BigEndian.setInt32(data, 4, getAttributes() | (1 << attributeMaskBit));
- }
-
- //
- public final int getLastMountedVersion() {
- return BigEndian.getInt32(data, 8);
- }
-
- public final void setLastMountedVersion(final int value) {
- BigEndian.setInt32(data, 8, value);
- }
-
- //
- public final int getJournalInfoBlock() {
- return BigEndian.getInt32(data, 12);
- }
-
- public final void setJournalInfoBlock(final int value) {
- BigEndian.setInt32(data, 12, value);
- }
-
- //
- public final long getCreateDate() {
- return BigEndian.getUInt32(data, 16);
- }
-
- public final void setCreateDate(final int value) {
- BigEndian.setInt32(data, 16, value);
- }
-
- public final long getModifyDate() {
- return BigEndian.getUInt32(data, 20);
- }
-
- public final void setModifyDate(final int value) {
- BigEndian.setInt32(data, 20, value);
- }
-
- public final long getBackupDate() {
- return BigEndian.getUInt32(data, 24);
- }
-
- public final void setBackupDate(final int value) {
- BigEndian.setInt32(data, 24, value);
- }
-
- public final long getCheckedDate() {
- return BigEndian.getUInt32(data, 28);
- }
-
- public final void setCheckedDate(final int value) {
- BigEndian.setInt32(data, 28, value);
- }
-
- //
- public final int getFileCount() {
- return BigEndian.getInt32(data, 32);
- }
-
- public final void setFileCount(final int value) {
- BigEndian.setInt32(data, 32, value);
- }
-
- //
- public final int getFolderCount() {
- return BigEndian.getInt32(data, 36);
- }
-
- public final void setFolderCount(final int value) {
- BigEndian.setInt32(data, 36, value);
- }
-
- //
- public final int getBlockSize() {
- return BigEndian.getInt32(data, 40);
- }
-
- public final void setBlockSize(final int value) {
- BigEndian.setInt32(data, 40, value);
- }
-
- //
- public final int getTotalBlocks() {
- return BigEndian.getInt32(data, 44);
- }
-
- public final void setTotalBlocks(final int value) {
- BigEndian.setInt32(data, 44, value);
- }
-
- //
- public final int getFreeBlocks() {
- return BigEndian.getInt32(data, 48);
- }
-
- public final void setFreeBlocks(final int value) {
- BigEndian.setInt32(data, 48, value);
- }
-
- //
- public final int getNextAllocation() {
- return BigEndian.getInt32(data, 52);
- }
-
- public final void setNextAllocation(final int value) {
- BigEndian.setInt32(data, 52, value);
- }
-
- public final long getRsrcClumpSize() {
- return BigEndian.getInt32(data, 56);
- }
-
- public final void setRsrcClumpSize(final int value) {
- BigEndian.setInt32(data, 56, value);
- }
-
- public final int getDataClumpSize() {
- return BigEndian.getInt32(data, 60);
- }
-
- public final void setDataClumpSize(final int value) {
- BigEndian.setInt32(data, 60, value);
- }
-
- public final int getNextCatalogId() {
- return BigEndian.getInt32(data, 64);
- }
-
- public final void setNextCatalogId(final int value) {
- BigEndian.setInt32(data, 64, value);
- }
-
- public final int getWriteCount() {
- return BigEndian.getInt32(data, 68);
- }
-
- public final void setWriteCount(final int value) {
- BigEndian.setInt32(data, 68, value);
- }
-
- public final long getEncodingsBmp() {
- return BigEndian.getInt64(data, 72);
- }
-
- public final void setEncodingsBmp(final long value) {
- BigEndian.setInt64(data, 72, value);
- }
-
- public final byte[] getFinderInfo() {
- byte[] result = new byte[32];
- System.arraycopy(data, 80, result, 0, 32);
- return result;
- }
-
- public final HfsPlusForkData getAllocationFile() {
- return new HfsPlusForkData(data, 112);
- }
-
- public final HfsPlusForkData getExtentsFile() {
- return new HfsPlusForkData(data, 192);
- }
-
- public final HfsPlusForkData getCatalogFile() {
- return new HfsPlusForkData(data, 272);
- }
-
- public final HfsPlusForkData getAttributesFile() {
- return new HfsPlusForkData(data, 352);
- }
-
- public final HfsPlusForkData getStartupFile() {
- return new HfsPlusForkData(data, 432);
- }
-
- /**
- * Get string representation of attribute.
- *
- * @return the string representation
- */
- public final String getAttributesAsString() {
- return ((isAttribute(HFSPLUS_VOL_UNMNT_BIT)) ? " kHFSVolumeUnmountedBit" : "") +
- ((isAttribute(HFSPLUS_VOL_INCNSTNT_BIT)) ? " kHFSBootVolumeInconsistentBit" : "") +
- ((isAttribute(HFSPLUS_VOL_JOURNALED_BIT)) ? " kHFSVolumeJournaledBit" : "");
- }
-
- /**
- * Check if the corresponding attribute corresponding is set.
- *
- * @param maskBit Bit position of the attribute. See constants.
- *
- * @return {@code true} if attribute is set.
- */
- public final boolean isAttribute(final int maskBit) {
- return (((getAttributes() >> maskBit) & 0x1) != 0);
- }
-
- public byte[] getBytes() {
- return data;
- }
-
- public void update() throws IOException {
- fs.getApi().write(1024, ByteBuffer.wrap(data));
- }
-
- public final String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("Magic: 0x").append(NumberUtils.hex(getMagic(), 4)).append("\n");
- buffer.append("Version: ").append(getVersion()).append("\n").append("\n");
- buffer.append("Attributes: ").append(getAttributesAsString()).append(" (").append(
- getAttributes()).append(")").append("\n").append("\n");
- buffer.append("Create date: ").append(
- HfsUtils.printDate(getCreateDate(), "EEE MMM d HH:mm:ss yyyy")).append("\n");
- buffer.append("Modify date: ").append(
- HfsUtils.printDate(getModifyDate(), "EEE MMM d HH:mm:ss yyyy")).append("\n");
- buffer.append("Backup date: ").append(
- HfsUtils.printDate(getBackupDate(), "EEE MMM d HH:mm:ss yyyy")).append("\n");
- buffer.append("Checked date: ").append(
- HfsUtils.printDate(getCheckedDate(), "EEE MMM d HH:mm:ss yyyy")).append("\n")
- .append("\n");
- buffer.append("File count: ").append(getFileCount()).append("\n");
- buffer.append("Folder count: ").append(getFolderCount()).append("\n").append("\n");
- buffer.append("Block size: ").append(getBlockSize()).append("\n");
- buffer.append("Total blocks: ").append(getTotalBlocks()).append("\n");
- buffer.append("Free blocks: ").append(getFreeBlocks()).append("\n").append("\n");
- buffer.append("Next catalog ID: ").append(getNextCatalogId()).append("\n");
- buffer.append("Write count: ").append(getWriteCount()).append("\n");
- buffer.append("Encoding bmp: ").append(getEncodingsBmp()).append("\n");
- buffer.append("Finder Infos: ").append(getFinderInfo()).append("\n").append("\n");
- buffer.append("Journal block: ").append(getJournalInfoBlock()).append("\n").append("\n");
- buffer.append("Allocation file").append("\n");
- buffer.append(getAllocationFile().toString()).append("\n");
- buffer.append("Extents file").append("\n");
- buffer.append(getExtentsFile().toString()).append("\n");
- buffer.append("Catalog file").append("\n");
- buffer.append(getCatalogFile().toString()).append("\n");
- buffer.append("Attributes file").append("\n");
- buffer.append(getAttributesFile().toString()).append("\n");
- buffer.append("Startup file").append("\n");
- buffer.append(getStartupFile().toString()).append("\n");
- return buffer.toString();
- }
-}
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-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/hfsplus/catalog/Catalog.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -29,7 +29,7 @@
import org.jnode.fs.hfsplus.HFSPlusParams;
import org.jnode.fs.hfsplus.HfsPlusFileSystem;
import org.jnode.fs.hfsplus.HfsUnicodeString;
-import org.jnode.fs.hfsplus.Superblock;
+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;
@@ -65,7 +65,7 @@
public Catalog(final HfsPlusFileSystem fs) throws IOException {
log.info("Load B-Tree catalog file.");
this.fs = fs;
- Superblock sb = fs.getVolumeHeader();
+ SuperBlock sb = fs.getVolumeHeader();
ExtentDescriptor firstExtent = sb.getCatalogFile().getExtent(0);
catalogHeaderNodeOffset = firstExtent.getStartOffset(sb.getBlockSize());
if (!firstExtent.isEmpty()) {
@@ -149,7 +149,7 @@
* @throws IOException
*/
public void update() throws IOException {
- Superblock vh = fs.getVolumeHeader();
+ SuperBlock vh = fs.getVolumeHeader();
int offset = vh.getCatalogFile().getExtent(0).getStartOffset(vh.getBlockSize());
fs.getApi().write(offset, this.getBytes());
}
Modified: trunk/fs/src/fs/org/jnode/fs/spi/AbstractFSFile.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/spi/AbstractFSFile.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/fs/org/jnode/fs/spi/AbstractFSFile.java 2011-08-11 11:42:10 UTC (rev 5845)
@@ -47,6 +47,8 @@
*/
public abstract long getLength();
+ public abstract void setLength(long length) throws IOException;
+
/**
* Read some data from the file
*
Modified: trunk/fs/src/test/org/jnode/fs/hfsplus/HfsPlusFileSystemTest.java
===================================================================
--- trunk/fs/src/test/org/jnode/fs/hfsplus/HfsPlusFileSystemTest.java 2011-08-07 08:53:41 UTC (rev 5844)
+++ trunk/fs/src/test/org...
[truncated message content] |