|
From: <cr...@us...> - 2008-05-23 15:48:33
|
Revision: 4118
http://jnode.svn.sourceforge.net/jnode/?rev=4118&view=rev
Author: crawley
Date: 2008-05-23 08:48:30 -0700 (Fri, 23 May 2008)
Log Message:
-----------
Converted the format commands
Modified Paths:
--------------
trunk/fs/descriptors/org.jnode.fs.ext2.command.xml
trunk/fs/descriptors/org.jnode.fs.fat.command.xml
trunk/fs/descriptors/org.jnode.fs.jfat.command.xml
trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java
trunk/fs/src/fs/org/jnode/fs/ext2/command/FormatExt2Command.java
trunk/fs/src/fs/org/jnode/fs/fat/command/FormatFatCommand.java
trunk/fs/src/fs/org/jnode/fs/jfat/command/FatFormatCommand.java
Modified: trunk/fs/descriptors/org.jnode.fs.ext2.command.xml
===================================================================
--- trunk/fs/descriptors/org.jnode.fs.ext2.command.xml 2008-05-22 13:39:44 UTC (rev 4117)
+++ trunk/fs/descriptors/org.jnode.fs.ext2.command.xml 2008-05-23 15:48:30 UTC (rev 4118)
@@ -22,4 +22,13 @@
<extension point="org.jnode.shell.aliases">
<alias name="formatExt2" class="org.jnode.fs.ext2.command.FormatExt2Command"/>
</extension>
+
+ <extension point="org.jnode.shell.syntaxes">
+ <syntax alias="formatExt2">
+ <sequence description="format an EXT2 file system">
+ <optional><option argLabel="blockSize" shortName="b" longName="blocksize"/></optional>
+ <argument argLabel="device"/>
+ </sequence>
+ </syntax>
+ </extension>
</plugin>
\ No newline at end of file
Modified: trunk/fs/descriptors/org.jnode.fs.fat.command.xml
===================================================================
--- trunk/fs/descriptors/org.jnode.fs.fat.command.xml 2008-05-22 13:39:44 UTC (rev 4117)
+++ trunk/fs/descriptors/org.jnode.fs.fat.command.xml 2008-05-23 15:48:30 UTC (rev 4118)
@@ -22,4 +22,13 @@
<extension point="org.jnode.shell.aliases">
<alias name="formatFat" class="org.jnode.fs.fat.command.FormatFatCommand"/>
</extension>
+
+ <extension point="org.jnode.shell.syntaxes">
+ <syntax alias="formatFat">
+ <sequence description="format a FAT32 file system">
+ <optional><option argLabel="fsType" shortName="t" longName="fstype"/></optional>
+ <argument argLabel="device"/>
+ </sequence>
+ </syntax>
+ </extension>
</plugin>
\ No newline at end of file
Modified: trunk/fs/descriptors/org.jnode.fs.jfat.command.xml
===================================================================
--- trunk/fs/descriptors/org.jnode.fs.jfat.command.xml 2008-05-22 13:39:44 UTC (rev 4117)
+++ trunk/fs/descriptors/org.jnode.fs.jfat.command.xml 2008-05-23 15:48:30 UTC (rev 4118)
@@ -24,6 +24,15 @@
<alias name="grub" class="org.jnode.fs.jfat.command.JGrubInstallCommand"/>
<alias name="formatJFat" class="org.jnode.fs.jfat.command.FatFormatCommand"/>
</extension>
+
+ <extension point="org.jnode.shell.syntaxes">
+ <syntax alias="formatJFat">
+ <sequence description="format a JFat file system">
+ <optional><option argLabel="clusterSize" shortName="c" longName="clustersize"/></optional>
+ <argument argLabel="device"/>
+ </sequence>
+ </syntax>
+ </extension>
<extension point="org.jnode.security.permissions">
<permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write,delete"/>
Modified: trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java 2008-05-22 13:39:44 UTC (rev 4117)
+++ trunk/fs/src/fs/org/jnode/fs/command/AbstractFormatCommand.java 2008-05-23 15:48:30 UTC (rev 4118)
@@ -37,56 +37,35 @@
import org.jnode.naming.InitialNaming;
import org.jnode.shell.AbstractCommand;
import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.SyntaxErrorException;
-import org.jnode.shell.help.argument.DeviceArgument;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.DeviceArgument;
/**
* @author Fabien DUMINY (fduminy at jnode.org)
- *
+ * @author cr...@jn...
*/
-abstract public class AbstractFormatCommand<T extends FileSystem<?>> extends AbstractCommand {
- private static final DeviceArgument ARG_DEVICE = new DeviceArgument("device-id",
- "the device to format");
+public abstract class AbstractFormatCommand<T extends FileSystem<?>> extends AbstractCommand {
+
+ protected final DeviceArgument ARG_DEVICE =
+ new DeviceArgument("device", Argument.MANDATORY, "the device to format", FSBlockDeviceAPI.class);
+
+ public AbstractFormatCommand(String description) {
+ super(description);
+ registerArguments(ARG_DEVICE);
+ }
- protected static final Parameter PARAM_DEVICE = new Parameter(ARG_DEVICE,
- Parameter.MANDATORY);
+ abstract protected Formatter<T> getFormatter();
- abstract protected ParsedArguments parse(CommandLine commandLine) throws SyntaxErrorException;
- abstract protected Formatter<T> getFormatter(ParsedArguments cmdLine);
+ final public void execute(CommandLine commandLine, InputStream in,
+ PrintStream out, PrintStream err)
+ throws FileSystemException, NameNotFoundException, DeviceNotFoundException, DriverException {
+ Device dev = ARG_DEVICE.getValue();
+ Formatter<T> formatter = getFormatter();
+ formatter.format(dev);
- final public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
- try {
- ParsedArguments cmdLine = parse(commandLine);
-
- String device = ARG_DEVICE.getValue(cmdLine);
- Formatter<T> formatter = getFormatter(cmdLine);
-
- DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
-
- Device dev = dm.getDevice(device);
- if(!(dev.getDriver() instanceof FSBlockDeviceAPI)){
- throw new FileSystemException(
- "device unsupported by format command");
- }
- formatter.format(dev);
-
- // restart the device
- dm.stop(dev);
- dm.start(dev);
- } catch (NameNotFoundException e) {
- e.printStackTrace();
- exit(1);
- } catch (DeviceNotFoundException e) {
- e.printStackTrace();
- exit(2);
- } catch (DriverException e) {
- e.printStackTrace();
- exit(3);
- } catch (FileSystemException e) {
- e.printStackTrace();
- exit(4);
- }
- }
+ // restart the device
+ final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
+ dm.stop(dev);
+ dm.start(dev);
+ }
}
Modified: trunk/fs/src/fs/org/jnode/fs/ext2/command/FormatExt2Command.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ext2/command/FormatExt2Command.java 2008-05-22 13:39:44 UTC (rev 4117)
+++ trunk/fs/src/fs/org/jnode/fs/ext2/command/FormatExt2Command.java 2008-05-23 15:48:30 UTC (rev 4118)
@@ -21,52 +21,55 @@
package org.jnode.fs.ext2.command;
+import java.util.HashMap;
+import java.util.Map;
+
import org.jnode.fs.command.AbstractFormatCommand;
import org.jnode.fs.ext2.BlockSize;
import org.jnode.fs.ext2.Ext2FileSystem;
import org.jnode.fs.ext2.Ext2FileSystemFormatter;
-import org.jnode.fs.fat.FatType;
-import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.SyntaxErrorException;
-import org.jnode.shell.help.argument.EnumOptionArgument;
-import org.jnode.shell.help.argument.OptionArgument;
+import org.jnode.fs.jfat.ClusterSize;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.EnumArgument;
+import org.jnode.shell.syntax.MappedArgument;
/**
* @author gbin
+ * @author cr...@jn...
*/
-@SuppressWarnings("unchecked")
public class FormatExt2Command extends AbstractFormatCommand<Ext2FileSystem> {
- static final EnumOptionArgument<BlockSize> BS_VAL = new EnumOptionArgument<BlockSize>("blocksize",
- "block size for ext2 filesystem",
- new EnumOptionArgument.EnumOption<BlockSize>("1", "1Kb", BlockSize._1Kb),
- new EnumOptionArgument.EnumOption<BlockSize>("2", "2Kb", BlockSize._2Kb),
- new EnumOptionArgument.EnumOption<BlockSize>("4", "4Kb", BlockSize._4Kb));
+
+ private static class BlockSizeArgument extends MappedArgument<BlockSize> {
+ private static final Map<String, BlockSize> MAP = new HashMap<String, BlockSize> ();
+ static {
+ MAP.put("1k", BlockSize._1Kb);
+ MAP.put("2k", BlockSize._2Kb);
+ MAP.put("4k", BlockSize._4Kb);
+ }
+ public BlockSizeArgument() {
+ super("blockSize", Argument.OPTIONAL, new BlockSize[0],
+ MAP, true, "block size for EXT2 filesystem (default 4k)");
+ }
- static final Parameter PARAM_BS_VAL = new Parameter(BS_VAL,
- Parameter.OPTIONAL);
+ @Override
+ protected String argumentKind() {
+ return "block size";
+ }
+ }
+
+ private final BlockSizeArgument ARG_BLOCK_SIZE = new BlockSizeArgument();
- public static Help.Info HELP_INFO = new Help.Info("format",
- new Syntax[] { new Syntax(
- "Format a block device with ext2 filesystem",
- new Parameter[] { PARAM_DEVICE, PARAM_BS_VAL }) });
+ public FormatExt2Command() {
+ super("Format a block device with ext2 filesystem");
+ registerArguments(ARG_BLOCK_SIZE);
+ }
public static void main(String[] args) throws Exception {
new FormatExt2Command().execute(args);
}
@Override
- protected Ext2FileSystemFormatter getFormatter(ParsedArguments cmdLine) {
- BlockSize bsize = BS_VAL.getEnum(cmdLine, BlockSize.class);
- return new Ext2FileSystemFormatter(bsize);
+ protected Ext2FileSystemFormatter getFormatter() {
+ return new Ext2FileSystemFormatter(ARG_BLOCK_SIZE.getValue());
}
-
- @Override
- protected ParsedArguments parse(CommandLine commandLine)
- throws SyntaxErrorException {
- return HELP_INFO.parse(commandLine);
- }
}
Modified: trunk/fs/src/fs/org/jnode/fs/fat/command/FormatFatCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/fat/command/FormatFatCommand.java 2008-05-22 13:39:44 UTC (rev 4117)
+++ trunk/fs/src/fs/org/jnode/fs/fat/command/FormatFatCommand.java 2008-05-23 15:48:30 UTC (rev 4118)
@@ -21,59 +21,54 @@
package org.jnode.fs.fat.command;
+import java.util.HashMap;
+import java.util.Map;
+
import org.jnode.fs.command.AbstractFormatCommand;
-import org.jnode.fs.fat.Fat;
import org.jnode.fs.fat.FatFileSystem;
import org.jnode.fs.fat.FatFileSystemFormatter;
import org.jnode.fs.fat.FatType;
-import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.SyntaxErrorException;
-import org.jnode.shell.help.argument.OptionArgument;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.MappedArgument;
/**
+ * This command formats a FAT12 or FAT16 filesystem.
+ *
* @author gbin
+ * @author cr...@jn...
*/
public class FormatFatCommand extends AbstractFormatCommand<FatFileSystem> {
+
+ private static class FatTypeArgument extends MappedArgument<FatType> {
+ private static final Map<String, FatType> MAP = new HashMap<String, FatType>();
+ static {
+ MAP.put("fat12", FatType.FAT12);
+ MAP.put("fat16", FatType.FAT16);
+ }
+
+ public FatTypeArgument() {
+ super("fsType", Argument.MANDATORY, new FatType[0], MAP,
+ true, "the kind of FAT filesystem to create");
+ }
+ @Override
+ protected String argumentKind() {
+ return "fat type";
+ }
+ }
+
+ private final FatTypeArgument ARG_FS_TYPE = new FatTypeArgument();
- static final OptionArgument FS = new OptionArgument("fstype",
- "FAT type", new OptionArgument.Option[] {
- new OptionArgument.Option("fat16", "FAT 16 filesystem"),
- new OptionArgument.Option("fat12", "FAT 12 filesystem")});
+ public FormatFatCommand() {
+ super("Format a block device with a FAT12 or FAT16 filesystem");
+ registerArguments(ARG_FS_TYPE);
+ }
- static final Parameter PARAM_FS = new Parameter(FS, Parameter.MANDATORY);
-
- public static Help.Info HELP_INFO = new Help.Info("format",
- new Syntax[] { new Syntax(
- "Format a block device with fat filesystem",
- new Parameter[] { PARAM_DEVICE, PARAM_FS}) });
-
public static void main(String[] args) throws Exception {
new FormatFatCommand().execute(args);
}
@Override
- protected FatFileSystemFormatter getFormatter(ParsedArguments cmdLine) {
- String FSType = FS.getValue(cmdLine).intern();
-
- FatFileSystemFormatter formatter = null;
- if (FSType == "fat16") {
- formatter = new FatFileSystemFormatter(FatType.FAT16);
- } else if (FSType == "fat12") {
- formatter = new FatFileSystemFormatter(FatType.FAT32);
- } else
- throw new IllegalArgumentException(
- "invalid fat type");
-
- return formatter;
+ protected FatFileSystemFormatter getFormatter() {
+ return new FatFileSystemFormatter(ARG_FS_TYPE.getValue());
}
-
- @Override
- protected ParsedArguments parse(CommandLine commandLine)
- throws SyntaxErrorException {
- return HELP_INFO.parse(commandLine);
- }
}
Modified: trunk/fs/src/fs/org/jnode/fs/jfat/command/FatFormatCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/command/FatFormatCommand.java 2008-05-22 13:39:44 UTC (rev 4117)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/command/FatFormatCommand.java 2008-05-23 15:48:30 UTC (rev 4118)
@@ -20,78 +20,65 @@
*/
package org.jnode.fs.jfat.command;
+import java.util.HashMap;
+import java.util.Map;
+
import org.apache.log4j.Logger;
import org.jnode.fs.command.AbstractFormatCommand;
-import org.jnode.fs.ext2.BlockSize;
import org.jnode.fs.jfat.ClusterSize;
import org.jnode.fs.jfat.FatFileSystem;
import org.jnode.fs.jfat.FatFileSystemFormatter;
-import org.jnode.shell.CommandLine;
-import org.jnode.shell.help.Help;
-import org.jnode.shell.help.Parameter;
-import org.jnode.shell.help.ParsedArguments;
-import org.jnode.shell.help.Syntax;
-import org.jnode.shell.help.SyntaxErrorException;
-import org.jnode.shell.help.argument.EnumOptionArgument;
-import org.jnode.shell.help.argument.OptionArgument;
+import org.jnode.shell.syntax.Argument;
+import org.jnode.shell.syntax.MappedArgument;
/**
- * @author Tango
- * <p>
- * The FAT32 formating command.
+ * This command formats a FAT32 file system.
*
+ * @author Tango
+ * @author cr...@jn...
*/
public class FatFormatCommand extends AbstractFormatCommand<FatFileSystem> {
private static final Logger log = Logger.getLogger(FatFormatCommand.class);
+
+ private static class ClusterSizeArgument extends MappedArgument<ClusterSize> {
+ private static final Map<String, ClusterSize> MAP = new HashMap<String, ClusterSize> ();
+ static {
+ MAP.put("1k", ClusterSize._1Kb);
+ MAP.put("2k", ClusterSize._2Kb);
+ MAP.put("4k", ClusterSize._4Kb);
+ MAP.put("8k", ClusterSize._8Kb);
+ MAP.put("16k", ClusterSize._16Kb);
+ MAP.put("32k", ClusterSize._32Kb);
+ // FIXME - should we enable this?
+ // MAP.put("64k", ClusterSize._64Kb);
+ }
+ public ClusterSizeArgument() {
+ super("clusterSize", Argument.OPTIONAL, new ClusterSize[0],
+ MAP, true, "cluster size for FAT32 filesystem (default 4k)");
+ }
- static final OptionArgument TYPE =
- new OptionArgument("action", "Type parameter",
- new OptionArgument.Option[] { new OptionArgument.Option(
- "-c", "Specify Sector Per Cluster Value") });
- static final Parameter PARAM_TYPE = new Parameter(TYPE, Parameter.OPTIONAL);
+ @Override
+ protected String argumentKind() {
+ return "cluster size";
+ }
+ }
- static final EnumOptionArgument<ClusterSize> BS_VAL =
- new EnumOptionArgument<ClusterSize>("clusterSize",
- "cluster size for fat filesystem",
- new EnumOptionArgument.EnumOption<ClusterSize>("1", "1Kb",
- ClusterSize._1Kb),
- new EnumOptionArgument.EnumOption<ClusterSize>("2", "2Kb",
- ClusterSize._2Kb),
- new EnumOptionArgument.EnumOption<ClusterSize>("4", "4Kb",
- ClusterSize._4Kb),
- new EnumOptionArgument.EnumOption<ClusterSize>("8", "8Kb",
- ClusterSize._8Kb),
- new EnumOptionArgument.EnumOption<ClusterSize>("16",
- "16Kb", ClusterSize._16Kb),
- new EnumOptionArgument.EnumOption<ClusterSize>("32",
- "32Kb", ClusterSize._32Kb),
- new EnumOptionArgument.EnumOption<ClusterSize>("32",
- "64Kb", ClusterSize._64Kb));
+ private final ClusterSizeArgument ARG_CLUSTER_SIZE = new ClusterSizeArgument();
+
+ public FatFormatCommand() {
+ super("Format a FAT32 file system");
+ registerArguments(ARG_CLUSTER_SIZE);
+ }
- static final Parameter PARAM_BS_VAL =
- new Parameter(BS_VAL, Parameter.OPTIONAL);
-
- public static Help.Info HELP_INFO =
- new Help.Info(
- "mkjfat",
- new Syntax[] { new Syntax(
- "Format a block device with a specified type.Enter the Cluster Size as 1 for 1KB. ",
- new Parameter[] { PARAM_TYPE, PARAM_BS_VAL,
- PARAM_DEVICE }) });
-
public static void main(String[] args) throws Exception {
new FatFormatCommand().execute(args);
}
-
- protected ParsedArguments parse(CommandLine commandLine)
- throws SyntaxErrorException {
- return HELP_INFO.parse(commandLine);
+
+ protected FatFileSystemFormatter getFormatter() {
+ ClusterSize clusterSize = ARG_CLUSTER_SIZE.isSet() ?
+ ARG_CLUSTER_SIZE.getValue() : ClusterSize._4Kb;
+ return new FatFileSystemFormatter(clusterSize);
}
-
- protected FatFileSystemFormatter getFormatter(ParsedArguments cmdLine) {
- ClusterSize bsize = BS_VAL.getEnum(cmdLine, ClusterSize.class);
- return new FatFileSystemFormatter(bsize);
- }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|