From: <ga...@us...> - 2009-01-06 10:25:35
|
Revision: 4831 http://jnode.svn.sourceforge.net/jnode/?rev=4831&view=rev Author: galatnm Date: 2009-01-06 10:25:31 +0000 (Tue, 06 Jan 2009) Log Message: ----------- Use of params for formatter. Modified Paths: -------------- 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/HfsPlusFileSystemFormatter.java trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java trunk/fs/src/fs/org/jnode/fs/hfsplus/command/FormatHfsPlusCommand.java Added Paths: ----------- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java Added: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java (rev 0) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java 2009-01-06 10:25:31 UTC (rev 4831) @@ -0,0 +1,33 @@ +package org.jnode.fs.hfsplus; + +public class HFSPlusParams { + private String volumeName; + private int blockSize; + private boolean journaled; + private int journalSize; + + public String getVolumeName() { + return volumeName; + } + public void setVolumeName(String volumeName) { + this.volumeName = volumeName; + } + public int getBlockSize() { + return blockSize; + } + public void setBlockSize(int blockSize) { + this.blockSize = blockSize; + } + public boolean isJournaled() { + return journaled; + } + public void setJournaled(boolean journaled) { + this.journaled = journaled; + } + public int getJournalSize() { + return journalSize; + } + public void setJournalSize(int journalSize) { + this.journalSize = journalSize; + } +} Property changes on: trunk/fs/src/fs/org/jnode/fs/hfsplus/HFSPlusParams.java ___________________________________________________________________ Added: svn:executable + * Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusConstants.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusConstants.java 2009-01-05 15:09:00 UTC (rev 4830) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusConstants.java 2009-01-06 10:25:31 UTC (rev 4831) @@ -38,4 +38,7 @@ public static final int DATA_CLUMP_FACTOR = 16; public static final int RESOURCE_CLUMP_FACTOR = 16; + + public static final int DEFAULT_JOURNAL_SIZE = 8 * 1024 * 1024; + } Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-01-05 15:09:00 UTC (rev 4830) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystem.java 2009-01-06 10:25:31 UTC (rev 4831) @@ -41,7 +41,7 @@ * @throws FileSystemException */ public final void read() throws FileSystemException { - sb = new Superblock(this); + sb = new Superblock(this, false); log.debug("Superblock informations:\n" + sb.toString()); if (!sb.isAttribute(HfsPlusConstants.HFSPLUS_VOL_UNMNT_BIT)) { @@ -111,10 +111,10 @@ * * @throws FileSystemException */ - public void create(int blockSize) throws FileSystemException { - sb = new Superblock(); + public void create(HFSPlusParams params) throws FileSystemException { + sb = new Superblock(this, true); try { - sb.create(this, blockSize, false); + sb.create(params); this.getApi().write(1024, ByteBuffer.wrap(sb.getBytes())); flush(); } catch (IOException e) { Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemFormatter.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemFormatter.java 2009-01-05 15:09:00 UTC (rev 4830) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/HfsPlusFileSystemFormatter.java 2009-01-06 10:25:31 UTC (rev 4831) @@ -9,9 +9,12 @@ import org.jnode.naming.InitialNaming; public class HfsPlusFileSystemFormatter extends Formatter<HfsPlusFileSystem> { - - protected HfsPlusFileSystemFormatter() { + + private HFSPlusParams params; + + public HfsPlusFileSystemFormatter(HFSPlusParams params) { super(new HfsPlusFileSystemType()); + this.params = params; } @Override @@ -20,7 +23,7 @@ FileSystemService fss = InitialNaming.lookup(FileSystemService.NAME); HfsPlusFileSystemType type = fss.getFileSystemType(HfsPlusFileSystemType.ID); HfsPlusFileSystem fs = type.create(device, false); - fs.create(HfsPlusConstants.OPTIMAL_BLOCK_SIZE); + fs.create(params); return fs; } catch (NameNotFoundException e) { throw new FileSystemException(e); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-01-05 15:09:00 UTC (rev 4830) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/Superblock.java 2009-01-06 10:25:31 UTC (rev 4831) @@ -35,15 +35,6 @@ private byte[] data; /** - * Default constructor for empty volume header. - */ - public Superblock() { - super(null); - data = new byte[SUPERBLOCK_LENGTH]; - log.setLevel(Level.INFO); - } - - /** * Create the volume header and load information for the file system passed * as parameter. * @@ -53,18 +44,21 @@ * @throws FileSystemException * If magic number (0X482B) is incorrect or not available. */ - public Superblock(final HfsPlusFileSystem fs) throws FileSystemException { + public Superblock(final HfsPlusFileSystem fs, boolean create) throws FileSystemException { super(fs); log.setLevel(Level.INFO); + data = new byte[SUPERBLOCK_LENGTH]; try { - ByteBuffer b = ByteBuffer.allocate(SUPERBLOCK_LENGTH); - // skip the first 1024 bytes (boot sector) and read the volume - // header. - 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)"); + if (!create) { + // 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); @@ -74,20 +68,19 @@ /** * Create a new volume header. * - * @param fs - * @param blockSize + * @param params + * * @throws ApiNotFoundException */ - public void create(HfsPlusFileSystem fs, int blockSize, boolean journaled) throws IOException, + public void create(HFSPlusParams params) throws IOException, ApiNotFoundException, FileSystemException { - - this.fs = fs; 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; @@ -106,7 +99,6 @@ // Set attributes. this.setAttribute(HFSPLUS_VOL_UNMNT_BIT); this.setLastMountedVersion(0x446534a); - // TODO Put correct dates. Calendar now = Calendar.getInstance(); now.setTime(new Date()); int macDate = (int) HFSUtils.getDate(now.getTimeInMillis() / 1000, true); @@ -128,13 +120,12 @@ int nextBlock = 0; // Journal creation ExtentDescriptor desc = this.getAllocationFile().getExtents()[0]; - if (journaled) { - int journalSize = 8 * 1024 * 1024; + if (params.isJournaled()) { this.setFileCount(2); this.setAttribute(HFSPLUS_VOL_JOURNALED_BIT); this.setNextCatalogId(this.getNextCatalogId() + 2); this.setJournalInfoBlock(desc.getStartBlock() + desc.getBlockCount()); - blockUsed = blockUsed + 1 + (journalSize / blockSize); + blockUsed = blockUsed + 1 + (params.getJournalSize() / blockSize); } else { this.setJournalInfoBlock(0); nextBlock = desc.getStartBlock() + desc.getBlockCount(); Modified: trunk/fs/src/fs/org/jnode/fs/hfsplus/command/FormatHfsPlusCommand.java =================================================================== --- trunk/fs/src/fs/org/jnode/fs/hfsplus/command/FormatHfsPlusCommand.java 2009-01-05 15:09:00 UTC (rev 4830) +++ trunk/fs/src/fs/org/jnode/fs/hfsplus/command/FormatHfsPlusCommand.java 2009-01-06 10:25:31 UTC (rev 4831) @@ -2,18 +2,34 @@ import org.jnode.fs.Formatter; import org.jnode.fs.command.AbstractFormatCommand; +import org.jnode.fs.hfsplus.HFSPlusParams; +import org.jnode.fs.hfsplus.HfsPlusConstants; import org.jnode.fs.hfsplus.HfsPlusFileSystem; +import org.jnode.fs.hfsplus.HfsPlusFileSystemFormatter; +import org.jnode.shell.syntax.Argument; +import org.jnode.shell.syntax.StringArgument; public class FormatHfsPlusCommand extends AbstractFormatCommand<HfsPlusFileSystem> { + + private final StringArgument ARG_VOLUME_NAME = + new StringArgument("volumename", Argument.OPTIONAL, "set volume name"); public FormatHfsPlusCommand() { super("Format a block device with HFS+ filesystem"); + registerArguments(ARG_VOLUME_NAME); } + public static void main(String[] args) throws Exception { + new FormatHfsPlusCommand().execute(args); + } + @Override protected Formatter<HfsPlusFileSystem> getFormatter() { - // TODO implement it. - return null; + HFSPlusParams params = new HFSPlusParams(); + params.setVolumeName(ARG_VOLUME_NAME.getValue()); + params.setBlockSize(HfsPlusConstants.OPTIMAL_BLOCK_SIZE); + params.setJournaled(false); + params.setJournalSize(HfsPlusConstants.DEFAULT_JOURNAL_SIZE); + return new HfsPlusFileSystemFormatter(params); } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |