|
From: <fd...@us...> - 2010-04-03 17:52:29
|
Revision: 5744
http://jnode.svn.sourceforge.net/jnode/?rev=5744&view=rev
Author: fduminy
Date: 2010-04-03 17:52:23 +0000 (Sat, 03 Apr 2010)
Log Message:
-----------
formatted comment
Modified Paths:
--------------
trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java
Modified: trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java 2010-04-03 17:50:32 UTC (rev 5743)
+++ trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java 2010-04-03 17:52:23 UTC (rev 5744)
@@ -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.partitions.command;
import java.io.IOException;
@@ -51,11 +51,9 @@
* @author cr...@jn...
*/
public class FdiskCommand extends AbstractCommand {
- // FIXME ... this is a dangerous command and it needs some extra checking to
- // help
- // avoid catastrophic errors. At the very least, it needs a mode that shows
- // the
- // user what would happen but does nothing.
+ // FIXME ... this is a dangerous command and it needs some extra checking to help
+ // avoid catastrophic errors. At the very least, it needs a mode that shows the
+ // user what would happen but does nothing.
private final FlagArgument FLAG_INIT_MBR =
new FlagArgument("initMBR", Argument.OPTIONAL,
"if set, init the device's Master Boot Record");
@@ -88,130 +86,130 @@
private final DeviceArgument ARG_DEVICE =
new DeviceArgument("deviceId", Argument.OPTIONAL, "Target device", BlockDeviceAPI.class);
- public FdiskCommand() {
- super("perform disk partition management tasks");
+ public FdiskCommand() {
+ super("perform disk partition management tasks");
registerArguments(FLAG_BOOTABLE, FLAG_DELETE, FLAG_INIT_MBR, FLAG_MODIFY, ARG_DEVICE,
ARG_PARTITION, ARG_START, ARG_SECTORS, ARG_BYTES, ARG_TYPE);
- }
+ }
- public static void main(String[] args) throws Exception {
- new FdiskCommand().execute(args);
- }
+ public static void main(String[] args) throws Exception {
+ new FdiskCommand().execute(args);
+ }
- public void execute() throws Exception {
- final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
- PrintWriter out = getOutput().getPrintWriter();
- PrintWriter err = getError().getPrintWriter();
- if (!ARG_DEVICE.isSet()) {
- // Show all devices.
- listAvailableDevices(dm, out);
- return;
- }
+ public void execute() throws Exception {
+ final DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
+ PrintWriter out = getOutput().getPrintWriter();
+ PrintWriter err = getError().getPrintWriter();
+ if (!ARG_DEVICE.isSet()) {
+ // Show all devices.
+ listAvailableDevices(dm, out);
+ return;
+ }
- Device dev = ARG_DEVICE.getValue();
- // FIXME PartitionHelper assumes that the device is an IDE device !?!
- if (!(dev instanceof IDEDevice)) {
- err.println(dev.getId() + " is not an IDE device");
- exit(1);
- }
- final PartitionHelper helper = new PartitionHelper(dev.getId(), out);
- try {
- helper.checkMBR();
- } catch (IOException ioex) {
- out.println(ioex.getMessage());
- out.println("Create a new MBR with a valid partition table.");
- helper.initMbr();
- helper.write();
- }
+ Device dev = ARG_DEVICE.getValue();
+ // FIXME PartitionHelper assumes that the device is an IDE device !?!
+ if (!(dev instanceof IDEDevice)) {
+ err.println(dev.getId() + " is not an IDE device");
+ exit(1);
+ }
+ final PartitionHelper helper = new PartitionHelper(dev.getId(), out);
+ try{
+ helper.checkMBR();
+ } catch (IOException ioex){
+ out.println(ioex.getMessage());
+ out.println("Create a new MBR with a valid partition table.");
+ helper.initMbr();
+ helper.write();
+ }
- if (FLAG_BOOTABLE.isSet()) {
- helper.toggleBootable(getPartitionNumber(helper));
- helper.write();
- } else if (FLAG_DELETE.isSet()) {
- helper.deletePartition(getPartitionNumber(helper));
- helper.write();
- } else if (FLAG_MODIFY.isSet()) {
- modifyPartition(helper, getPartitionNumber(helper), out);
- helper.write();
- } else if (FLAG_INIT_MBR.isSet()) {
- helper.initMbr();
- helper.write();
- } else {
- printPartitionTable(helper, out);
- }
- }
+ if (FLAG_BOOTABLE.isSet()) {
+ helper.toggleBootable(getPartitionNumber(helper));
+ helper.write();
+ } else if (FLAG_DELETE.isSet()) {
+ helper.deletePartition(getPartitionNumber(helper));
+ helper.write();
+ } else if (FLAG_MODIFY.isSet()) {
+ modifyPartition(helper, getPartitionNumber(helper), out);
+ helper.write();
+ } else if (FLAG_INIT_MBR.isSet()) {
+ helper.initMbr();
+ helper.write();
+ } else {
+ printPartitionTable(helper, out);
+ }
+ }
- private int getPartitionNumber(PartitionHelper helper) {
- int partNumber = ARG_PARTITION.getValue();
- if (partNumber >= helper.getNbPartitions() || partNumber < 0) {
- throw new IllegalArgumentException("Partition number is invalid");
- }
- return partNumber;
- }
+ private int getPartitionNumber(PartitionHelper helper) {
+ int partNumber = ARG_PARTITION.getValue();
+ if (partNumber >= helper.getNbPartitions() || partNumber < 0) {
+ throw new IllegalArgumentException("Partition number is invalid");
+ }
+ return partNumber;
+ }
private void modifyPartition(PartitionHelper helper, int id, PrintWriter out)
throws IOException {
- long start = ARG_START.getValue();
- long size = ARG_SECTORS.isSet() ? ARG_SECTORS.getValue() : ARG_BYTES.getValue();
- IBMPartitionTypes type = ARG_TYPE.getValue();
+ long start = ARG_START.getValue();
+ long size = ARG_SECTORS.isSet() ? ARG_SECTORS.getValue() : ARG_BYTES.getValue();
+ IBMPartitionTypes type = ARG_TYPE.getValue();
out.println("Init " + id + " with start = " + start + ", size = " + size + ", fs = " +
Integer.toHexString(type.getCode()));
boolean sizeUnit = ARG_BYTES.isSet() ? PartitionHelper.BYTES : PartitionHelper.SECTORS;
- helper.modifyPartition(id, false, start, size, sizeUnit, type);
- }
+ helper.modifyPartition(id, false, start, size, sizeUnit, type);
+ }
- private void printPartitionTable(PartitionHelper helper, PrintWriter out)
- throws DeviceNotFoundException, ApiNotFoundException, IOException {
- IDEDevice ideDev = helper.getDevice();
- IDEDriveDescriptor descriptor = ideDev.getDescriptor();
- int sectorSize = IDEConstants.SECTOR_SIZE;
- if (ideDev != null) {
- out.println("IDE Disk : " + ideDev.getId() + ": " +
- descriptor.getSectorsIn28bitAddressing() * 512 + " bytes");
- }
- out.println("Device Boot Start End Blocks System");
- IBMPartitionTable partitionTable = helper.getPartitionTable();
- int i = 0;
- for (IBMPartitionTableEntry entry : partitionTable) {
- IBMPartitionTypes si = entry.getSystemIndicator();
- if (!entry.isEmpty()) {
- long sectors = entry.getNrSectors();
+ private void printPartitionTable(PartitionHelper helper, PrintWriter out)
+ throws DeviceNotFoundException, ApiNotFoundException, IOException {
+ IDEDevice ideDev = helper.getDevice();
+ IDEDriveDescriptor descriptor = ideDev.getDescriptor();
+ int sectorSize = IDEConstants.SECTOR_SIZE;
+ if (ideDev != null) {
+ out.println("IDE Disk : " + ideDev.getId() + ": " +
+ descriptor.getSectorsIn28bitAddressing() * 512 + " bytes");
+ }
+ out.println("Device Boot Start End Blocks System");
+ IBMPartitionTable partitionTable = helper.getPartitionTable();
+ int i = 0;
+ for(IBMPartitionTableEntry entry : partitionTable){
+ IBMPartitionTypes si = entry.getSystemIndicator();
+ if (!entry.isEmpty()) {
+ long sectors = entry.getNrSectors();
out.println("ID " + i + " " + (entry.getBootIndicator() ? "Boot" : "No") + " " +
entry.getStartLba() + " " + (entry.getStartLba() + sectors) + " " +
- entry.getNbrBlocks(sectorSize) + (entry.isOdd() ? "" : "+") + " " + si);
- }
- if (entry.isExtended()) {
+ entry.getNbrBlocks(sectorSize) + (entry.isOdd()?"":"+") + " " + si);
+ }
+ if (entry.isExtended()) {
final List<IBMPartitionTableEntry> exPartitions =
partitionTable.getExtendedPartitions();
- int j = 0;
- for (IBMPartitionTableEntry exEntry : exPartitions) {
- si = exEntry.getSystemIndicator();
- // FIXME ... this needs work
+ int j = 0;
+ for (IBMPartitionTableEntry exEntry : exPartitions) {
+ si = exEntry.getSystemIndicator();
+ // FIXME ... this needs work
out.println("ID " + i + " " + (exEntry.getBootIndicator() ? "Boot" : "No") +
" " + exEntry.getStartLba() + " " + "-----" + " " + "-----" +
" " + si);
- j++;
- }
- }
- i++;
- }
- }
+ j++;
+ }
+ }
+ i++;
+ }
+ }
- private void listAvailableDevices(DeviceManager dm, PrintWriter out) {
- final Collection<Device> allDevices = dm.getDevicesByAPI(BlockDeviceAPI.class);
- for (Device dev : allDevices) {
- out.println("Found device : " + dev.getId() + "[" + dev.getClass() + "]");
- if (dev instanceof IDEDevice) {
- IDEDevice ideDevice = (IDEDevice) dev;
- IDEDriveDescriptor desc = ideDevice.getDescriptor();
- if (desc.isDisk()) {
+ private void listAvailableDevices(DeviceManager dm, PrintWriter out) {
+ final Collection<Device> allDevices = dm.getDevicesByAPI(BlockDeviceAPI.class);
+ for (Device dev : allDevices) {
+ out.println("Found device : " + dev.getId() + "[" + dev.getClass() + "]");
+ if (dev instanceof IDEDevice) {
+ IDEDevice ideDevice = (IDEDevice) dev;
+ IDEDriveDescriptor desc = ideDevice.getDescriptor();
+ if (desc.isDisk()) {
out.println(" IDE Disk : " + ideDevice.getId() + "(" + desc.getModel() +
" " + desc.getSectorsIn28bitAddressing() * IDEConstants.SECTOR_SIZE +
")");
- }
- }
- }
- }
+ }
+ }
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|