Revision: 5637
          http://jnode.svn.sourceforge.net/jnode/?rev=5637&view=rev
Author:   galatnm
Date:     2009-08-10 21:31:59 +0000 (Mon, 10 Aug 2009)

Log Message:
-----------
CheckStyle.

Modified Paths:
--------------
    trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java
    trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java
    trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableEntry.java

Modified: trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java      
2009-08-10 21:17:38 UTC (rev 5636)
+++ trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java      
2009-08-10 21:31:59 UTC (rev 5637)
@@ -51,168 +51,167 @@
  * @author craw...@jnode.org
  */
 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.
-       private final FlagArgument FLAG_INIT_MBR = new FlagArgument(
-                       "initMBR", Argument.OPTIONAL, "if set, init the 
device's Master Boot Record");
+    // 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");
 
-       private final FlagArgument FLAG_DELETE = new FlagArgument(
-                       "delete", Argument.OPTIONAL, "if set, delete a 
partition");
+    private final FlagArgument FLAG_DELETE =
+            new FlagArgument("delete", Argument.OPTIONAL, "if set, delete a 
partition");
 
-       private final FlagArgument FLAG_BOOTABLE = new FlagArgument(
-                       "bootable", Argument.OPTIONAL, "if set, toggle the 
partition's bootable flag");
+    private final FlagArgument FLAG_BOOTABLE =
+            new FlagArgument("bootable", Argument.OPTIONAL,
+                    "if set, toggle the partition's bootable flag");
 
-       private final FlagArgument FLAG_MODIFY = new FlagArgument(
-                       "modify", Argument.OPTIONAL, "if set, modify or create 
a partition");
+    private final FlagArgument FLAG_MODIFY =
+            new FlagArgument("modify", Argument.OPTIONAL, "if set, modify or 
create a partition");
 
-       private final IntegerArgument ARG_PARTITION = new IntegerArgument(
-                       "partition", Argument.OPTIONAL, "Target partition 
number (0..3)");
+    private final IntegerArgument ARG_PARTITION =
+            new IntegerArgument("partition", Argument.OPTIONAL, "Target 
partition number (0..3)");
 
-       private final LongArgument ARG_START = new LongArgument(
-                       "start", Argument.OPTIONAL, "Partition start sector");
+    private final LongArgument ARG_START =
+            new LongArgument("start", Argument.OPTIONAL, "Partition start 
sector");
 
-       private final LongArgument ARG_SECTORS = new LongArgument(
-                       "sectors", Argument.OPTIONAL, "Partition size in 
sectors");
+    private final LongArgument ARG_SECTORS =
+            new LongArgument("sectors", Argument.OPTIONAL, "Partition size in 
sectors");
 
-       private final SizeArgument ARG_BYTES = new SizeArgument(
-                       "bytes", Argument.OPTIONAL, "Partition size in bytes 
(300K, 45M, etc)");
+    private final SizeArgument ARG_BYTES =
+            new SizeArgument("bytes", Argument.OPTIONAL, "Partition size in 
bytes (300K, 45M, etc)");
 
-       private final IBMPartitionTypeArgument ARG_TYPE = new 
IBMPartitionTypeArgument(
-                       "type", Argument.OPTIONAL, "IBM partition type code");
+    private final IBMPartitionTypeArgument ARG_TYPE =
+            new IBMPartitionTypeArgument("type", Argument.OPTIONAL, "IBM 
partition type code");
 
-       private final DeviceArgument ARG_DEVICE = new DeviceArgument(
-                       "deviceId", Argument.OPTIONAL, "Target device", 
BlockDeviceAPI.class);
+    private final DeviceArgument ARG_DEVICE =
+            new DeviceArgument("deviceId", Argument.OPTIONAL, "Target device", 
BlockDeviceAPI.class);
 
+    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 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();
 
-       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();
+        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);
+    }
 
-               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);
-       }
+    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()) {
+                final List<IBMPartitionTableEntry> exPartitions =
+                        partitionTable.getExtendedPartitions();
+                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++;
+        }
+    }
 
-                               out.println("ID " + i  + " " +
-                                               (entry.getBootIndicator() ? 
"Boot" : "No") + "    " +
-                                               entry.getStartLba() + "    " +
-                                               (entry.getStartLba() + sectors) 
+ "    " +
-                                               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
-                                       out.println("ID " + i + " " +
-                                                       
(exEntry.getBootIndicator() ? "Boot" : "No") + "    " +
-                                                       exEntry.getStartLba() + 
"    " +
-                                                       "-----" /* 
(exEntry.getStartLba() + entry.getNrSectors()) */ + "    " +
-                                                       "-----" /* 
exEntry.getNrSectors() */ + "    " + si);
-                                       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()) {
-                                       out.println("    IDE Disk : " + 
ideDevice.getId() +
-                                                       "(" + desc.getModel() + 
" " +
-                                                       
desc.getSectorsIn28bitAddressing() * IDEConstants.SECTOR_SIZE + ")");
-                               }
-                       }
-               }
-       }
+    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 +
+                            ")");
+                }
+            }
+        }
+    }
 }

Modified: trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java   
2009-08-10 21:17:38 UTC (rev 5636)
+++ trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java   
2009-08-10 21:31:59 UTC (rev 5637)
@@ -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;
@@ -53,16 +53,16 @@
 
     private final MasterBootRecord MBR;
     private BootSector bs;
-    
+
     private final PrintWriter out;
 
-    public PartitionHelper(String deviceId, PrintWriter out) throws 
DeviceNotFoundException, ApiNotFoundException,
-            IOException, NameNotFoundException {
+    public PartitionHelper(String deviceId, PrintWriter out) throws 
DeviceNotFoundException,
+            ApiNotFoundException, IOException, NameNotFoundException {
         this((IDEDevice) DeviceUtils.getDeviceManager().getDevice(deviceId), 
out);
     }
 
-    public PartitionHelper(IDEDevice device, PrintWriter out) throws 
DeviceNotFoundException, ApiNotFoundException,
-            IOException {
+    public PartitionHelper(IDEDevice device, PrintWriter out) throws 
DeviceNotFoundException,
+            ApiNotFoundException, IOException {
         this.current = device;
         this.api = current.getAPI(BlockDeviceAPI.class);
         this.MBR = new MasterBootRecord(api);
@@ -71,10 +71,10 @@
         reloadMBR();
     }
 
-    public IDEDevice getDevice(){
-       return current;
+    public IDEDevice getDevice() {
+        return current;
     }
-    
+
     public void initMbr() throws DeviceNotFoundException, 
ApiNotFoundException, IOException {
         out.println("Initialize MBR ...");
 
@@ -82,7 +82,8 @@
         bs = new GrubBootSector(PLAIN_MASTER_BOOT_SECTOR);
 
         if (MBR.containsPartitionTable()) {
-            out.println("This device already contains a partition table. Copy 
the already existing partitions.");
+            out
+                    .println("This device already contains a partition table. 
Copy the already existing partitions.");
 
             for (int i = 0; i < 4; i++) {
                 final IBMPartitionTableEntry oldEntry = oldMBR.getPartition(i);
@@ -125,19 +126,19 @@
         if (!MBR.containsPartitionTable())
             throw new IOException("This device doesn't contain a valid 
partition table.");
     }
-    
-    public IBMPartitionTable getPartitionTable(){
-       return new IBMPartitionTable(new IBMPartitionTableType(), MBR.array(), 
current);
+
+    public IBMPartitionTable getPartitionTable() {
+        return new IBMPartitionTable(new IBMPartitionTableType(), MBR.array(), 
current);
     }
 
     public int getNbPartitions() {
         return bs.getNbPartitions();
     }
-    
+
     public IBMPartitionTableEntry getPartition(int partNr) {
-       return bs.getPartition(partNr);
+        return bs.getPartition(partNr);
     }
-    
+
     public void modifyPartition(int id, boolean bootIndicator, long start, 
long size,
             boolean sizeUnit, IBMPartitionTypes fs) throws IOException {
         checkMBR();
@@ -157,8 +158,6 @@
         entry.setNrSectors(nbSectors);
     }
 
-    
-
     public void deletePartition(int partNumber) throws IOException {
         checkMBR();
         
bs.getPartition(partNumber).setSystemIndicator(IBMPartitionTypes.PARTTYPE_EMPTY);
@@ -179,8 +178,8 @@
         bs.getPartition(partNumber).setBootIndicator(!currentStatus);
     }
 
-    private static final byte PLAIN_MASTER_BOOT_SECTOR[] = {
-        (byte) 0xEB, (byte) 0x48, (byte) 0x90, (byte) 0x00, (byte) 0x00, 
(byte) 0x00,
+    private static final byte PLAIN_MASTER_BOOT_SECTOR[] =
+    {(byte) 0xEB, (byte) 0x48, (byte) 0x90, (byte) 0x00, (byte) 0x00, (byte) 
0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 
(byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 
(byte) 0x00,
         (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 
(byte) 0x00,

Modified: trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableEntry.java        
2009-08-10 21:17:38 UTC (rev 5636)
+++ trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTableEntry.java        
2009-08-10 21:31:59 UTC (rev 5637)
@@ -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.ibm;
 
 import org.jnode.driver.block.CHS;
@@ -69,8 +69,7 @@
         // pgwiasda
         // there are more than one type of extended Partitions
         return (id == IBMPartitionTypes.PARTTYPE_WIN95_FAT32_EXTENDED ||
-                id == IBMPartitionTypes.PARTTYPE_LINUX_EXTENDED || 
-                id == IBMPartitionTypes.PARTTYPE_DOS_EXTENDED);
+                id == IBMPartitionTypes.PARTTYPE_LINUX_EXTENDED || id == 
IBMPartitionTypes.PARTTYPE_DOS_EXTENDED);
     }
 
     public boolean getBootIndicator() {
@@ -138,23 +137,22 @@
     public void setNrSectors(long v) {
         LittleEndian.setInt32(bs, ofs + 12, (int) v);
     }
-    
-    public long getNbrBlocks(int sectorSize){
-       long sectors = getNrSectors();
-       long blocks = sectors;
-       if (sectorSize < 1024) {
-               blocks /= (1024 / sectorSize);
-               odd = getNrSectors() % (1024 / sectorSize);
-       } else {
-               blocks *= (sectorSize / 1024);
-       }
-       return blocks;
+
+    public long getNbrBlocks(int sectorSize) {
+        long sectors = getNrSectors();
+        long blocks = sectors;
+        if (sectorSize < 1024) {
+            blocks /= (1024 / sectorSize);
+            odd = getNrSectors() % (1024 / sectorSize);
+        } else {
+            blocks *= (sectorSize / 1024);
+        }
+        return blocks;
     }
-    
-    public boolean isOdd(){
-       return odd!=0;
+
+    public boolean isOdd() {
+        return odd != 0;
     }
-    
 
     public void clear() {
         for (int i = 0; i < 16; i++) {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Jnode-svn-commits mailing list
Jnode-svn-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits

Reply via email to