Revision: 5965
          http://jnode.svn.sourceforge.net/jnode/?rev=5965&view=rev
Author:   galatnm
Date:     2013-02-20 11:55:05 +0000 (Wed, 20 Feb 2013)
Log Message:
-----------
Strengthen the checks for IBM partition tables. (Luke Quinane)

Modified Paths:
--------------
    trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java
    trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTable.java

Modified: trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java    2013-02-20 
08:18:08 UTC (rev 5964)
+++ trunk/fs/src/fs/org/jnode/fs/ntfs/CompressedDataRun.java    2013-02-20 
11:55:05 UTC (rev 5965)
@@ -224,7 +224,7 @@
 
        @Override
        public long mapVcnToLcn(long vcn) {
-               throw new UnsupportedOperationException("Not yet implemented");
+               return compressedRun.mapVcnToLcn(vcn);
        }
 
        /**

Modified: trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTable.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTable.java     
2013-02-20 08:18:08 UTC (rev 5964)
+++ trunk/fs/src/fs/org/jnode/partitions/ibm/IBMPartitionTable.java     
2013-02-20 11:55:05 UTC (rev 5965)
@@ -33,6 +33,7 @@
 import org.jnode.driver.bus.ide.IDEConstants;
 import org.jnode.partitions.PartitionTable;
 import org.jnode.partitions.PartitionTableType;
+import org.jnode.util.LittleEndian;
 
 /**
  * @author epr
@@ -125,18 +126,56 @@
     }
 
     /**
-     * Does the given bootsector contain an IBM partition table?
+     * Does the given boot sector contain an IBM partition table?
      * 
-     * @param bootSector
+     * @param bootSector the data to check.
+     * @return {@code true} if the data contains an IBM partition table, 
{@code false} otherwise.
      */
     public static boolean containsPartitionTable(byte[] bootSector) {
-        if ((bootSector[510] & 0xFF) != 0x55) {
+        if (LittleEndian.getUInt16(bootSector, 510) != 0xaa55) {
             return false;
         }
-        if ((bootSector[511] & 0xFF) != 0xAA) {
-            return false;
+
+        if (LittleEndian.getUInt16(bootSector, 428) == 0x5678) {
+            // Matches the AAP MBR extra signature, probably an valid 
partition table
+            return true;
         }
-        return true;
+
+        if (LittleEndian.getUInt16(bootSector, 380) == 0xa55a) {
+            // Matches the AST/NEC MBR extra signature, probably an valid 
partition table
+            return true;
+        }
+
+        if (LittleEndian.getUInt16(bootSector, 252) == 0x55aa) {
+            // Matches the Disk Manager MBR extra signature, probably an valid 
partition table
+            return true;
+        }
+
+        if (LittleEndian.getUInt32(bootSector, 2) == 0x4c57454e) {
+            // Matches the NEWLDR MBR extra signature, probably an valid 
partition table
+            return true;
+        }
+
+        // Nothing matched, fall back to validating any specified partition 
entries
+        IBMPartitionTableEntry lastValid = null;
+        boolean foundValidEntry = false;
+        for (int partitionNumber = 0; partitionNumber < TABLE_SIZE; 
partitionNumber++) {
+            IBMPartitionTableEntry partition = new 
IBMPartitionTableEntry(null, bootSector, partitionNumber);
+
+            if (partition.isValid()) {
+                if (lastValid != null) {
+                    if (lastValid.getStartLba() + lastValid.getNrSectors() > 
partition.getStartLba()) {
+                        // End of previous partition entry after the start of 
the next one
+                        return false;
+                    }
+                }
+
+                foundValidEntry = true;
+                lastValid = partition;
+            }
+        }
+
+        return foundValidEntry;
     }
 
     public Iterator<IBMPartitionTableEntry> iterator() {

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


------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_feb
_______________________________________________
Jnode-svn-commits mailing list
Jnode-svn-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jnode-svn-commits

Reply via email to