|
From: <ga...@us...> - 2012-08-09 14:08:27
|
Revision: 5904
http://jnode.svn.sourceforge.net/jnode/?rev=5904&view=rev
Author: galatnm
Date: 2012-08-09 14:08:21 +0000 (Thu, 09 Aug 2012)
Log Message:
-----------
Initial Apple partition map support (patch from L. Quinane)
Added Paths:
-----------
trunk/fs/descriptors/org.jnode.partitions.apm.xml
trunk/fs/src/fs/org/jnode/partitions/apm/
trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTable.java
trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTableEntry.java
trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTableType.java
Added: trunk/fs/descriptors/org.jnode.partitions.apm.xml
===================================================================
--- trunk/fs/descriptors/org.jnode.partitions.apm.xml (rev 0)
+++ trunk/fs/descriptors/org.jnode.partitions.apm.xml 2012-08-09 14:08:21 UTC (rev 5904)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plugin SYSTEM "jnode.dtd">
+
+<plugin id="org.jnode.partitions.apm"
+ name="JNode APM partition table classes"
+ version="0.2.9-dev"
+ license-name="lgpl"
+ provider-name="JNode.org">
+
+ <requires>
+ <import plugin="org.jnode.partitions"/>
+ </requires>
+
+ <runtime>
+ <library name="jnode-fs.jar">
+ <export name="org.jnode.partitions.apm.*"/>
+ </library>
+ </runtime>
+
+ <extension point="org.jnode.partitions.types">
+ <type class="org.jnode.partitions.apm.ApmPartitionTableType"/>
+ </extension>
+
+</plugin>
Added: trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTable.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTable.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTable.java 2012-08-09 14:08:21 UTC (rev 5904)
@@ -0,0 +1,101 @@
+/*
+ * $Id: $
+ *
+ * Copyright (C) 2003-2012 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * 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.apm;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import org.apache.log4j.Logger;
+import org.jnode.driver.Device;
+import org.jnode.partitions.PartitionTable;
+import org.jnode.partitions.PartitionTableType;
+import org.jnode.util.LittleEndian;
+
+/**
+ * The main Apple Partition Map (APM) partition table class.
+ *
+ * @author Luke Quinane
+ */
+public class ApmPartitionTable implements PartitionTable<ApmPartitionTableEntry> {
+
+ /** The type of partition table */
+ private final ApmPartitionTableType tableType;
+
+ /** The partition entries */
+ private final List<ApmPartitionTableEntry> partitions = new ArrayList<ApmPartitionTableEntry>();
+
+ /** My logger */
+ private static final Logger log = Logger.getLogger(ApmPartitionTable.class);
+
+ /**
+ * Create a new instance
+ *
+ * @param tableType the partition table type.
+ * @param first16KiB the first 16,384 bytes of the disk.
+ * @param device the drive device.
+ */
+ public ApmPartitionTable(ApmPartitionTableType tableType, byte[] first16KiB, Device device) {
+ this.tableType = tableType;
+
+ long entries = LittleEndian.getUInt32(first16KiB, 0x204);
+
+ for (int partitionNumber = 0; partitionNumber < entries; partitionNumber++) {
+ log.debug("try part " + partitionNumber);
+
+ int offset = 0x200 + (partitionNumber * 0x200);
+
+ ApmPartitionTableEntry entry = new ApmPartitionTableEntry(this, first16KiB, offset);
+
+ if (entry.isValid())
+ {
+ partitions.add(entry);
+ }
+ }
+ }
+
+ /**
+ * Checks if the given boot sector contain a APM partition table.
+ *
+ * @param first16KiB the first 16,384 bytes of the disk.
+ * @return {@code true} if the boot sector contains a APM partition table.
+ */
+ public static boolean containsPartitionTable(byte[] first16KiB) {
+ if ((first16KiB[0x200] & 0xFF) != 0x50) {
+ return false;
+ }
+ if ((first16KiB[0x201] & 0xFF) != 0x4d) {
+ return false;
+ }
+ return true;
+ }
+
+ public Iterator<ApmPartitionTableEntry> iterator() {
+ return Collections.unmodifiableList(partitions).iterator();
+ }
+
+ /**
+ * @see org.jnode.partitions.PartitionTable#getType()
+ */
+ public PartitionTableType getType() {
+ return tableType;
+ }
+}
Added: trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTableEntry.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTableEntry.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTableEntry.java 2012-08-09 14:08:21 UTC (rev 5904)
@@ -0,0 +1,117 @@
+/*
+ * $Id: $
+ *
+ * Copyright (C) 2003-2012 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * 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.apm;
+
+import java.nio.charset.Charset;
+import org.jnode.partitions.PartitionTableEntry;
+import org.jnode.partitions.ibm.IBMPartitionTable;
+import org.jnode.util.BigEndian;
+import org.jnode.util.LittleEndian;
+import org.jnode.util.NumberUtils;
+
+/**
+ * A APM partition table entry.
+ *
+ * @author Luke Quinane
+ */
+public class ApmPartitionTableEntry implements PartitionTableEntry {
+
+ /** The first 16KiB of the drive. */
+ private final byte[] first16KiB;
+
+ /** The offset to this partition table entry. */
+ private final int offset;
+
+ /**
+ * Creates a new entry.
+ *
+ * @param parent the parent table.
+ * @param first16KiB the first 16,384 bytes of the disk.
+ * @param offset the offset of this entry in the table.
+ */
+ public ApmPartitionTableEntry(ApmPartitionTable parent, byte[] first16KiB, int offset) {
+ this.first16KiB = first16KiB;
+ this.offset = offset;
+ }
+
+ public boolean isValid() {
+ return first16KiB.length > offset + 128 && !isEmpty();
+ }
+
+ /**
+ * @see org.jnode.partitions.PartitionTableEntry#getChildPartitionTable()
+ */
+ public IBMPartitionTable getChildPartitionTable() {
+ throw new UnsupportedOperationException("No child partitions.");
+ }
+
+ /**
+ * @see org.jnode.partitions.PartitionTableEntry#hasChildPartitionTable()
+ */
+ public boolean hasChildPartitionTable() {
+ return false;
+ }
+
+ public boolean isEmpty() {
+ return "Apple_Scratch".equals(getType());
+ }
+
+ public long getStartOffset() {
+ return BigEndian.getInt32(first16KiB, offset + 0x8) * 0x200L;
+ }
+
+ public long getEndOffset() {
+ return getStartOffset() + (BigEndian.getInt32(first16KiB, offset + 0xc) + 1) * 0x200L;
+ }
+
+ public String getName() {
+ byte[] nameBytes = new byte[31];
+ System.arraycopy(first16KiB, offset + 0x10, nameBytes, 0, nameBytes.length);
+ return new String(nameBytes, Charset.forName("ASCII")).replace("\u0000", "");
+ }
+
+ public String getType() {
+ byte[] nameBytes = new byte[31];
+ System.arraycopy(first16KiB, offset + 0x30, nameBytes, 0, nameBytes.length);
+ return new String(nameBytes, Charset.forName("ASCII")).replace("\u0000", "");
+ }
+
+ public String dump() {
+ StringBuilder b = new StringBuilder();
+ for (int i = 0; i < 128; i++) {
+ b.append(NumberUtils.hex(LittleEndian.getUInt8(first16KiB, offset + i), 2));
+ b.append(' ');
+ }
+ return b.toString();
+ }
+
+ /**
+ * @see Object#toString()
+ */
+ public String toString() {
+ StringBuilder builder = new StringBuilder(32);
+ builder.append('[').append(getName()).append(' ');
+ builder.append("t:").append(getType()).append(' ');
+ builder.append("s:").append(getStartOffset()).append(' ');
+ builder.append("e:").append(getEndOffset()).append(']');
+ return builder.toString();
+ }
+}
Added: trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTableType.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTableType.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/partitions/apm/ApmPartitionTableType.java 2012-08-09 14:08:21 UTC (rev 5904)
@@ -0,0 +1,47 @@
+/*
+ * $Id: $
+ *
+ * Copyright (C) 2003-2012 JNode.org
+ *
+ * This library is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published
+ * by the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * 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.apm;
+
+import org.jnode.driver.Device;
+import org.jnode.driver.block.BlockDeviceAPI;
+import org.jnode.partitions.PartitionTable;
+import org.jnode.partitions.PartitionTableException;
+import org.jnode.partitions.PartitionTableType;
+
+/**
+ * Apple Partition Map (APM) partition table type.
+ *
+ * @author Luke Quinane
+ */
+public class ApmPartitionTableType implements PartitionTableType {
+
+ public PartitionTable<?> create(byte[] firstSector, Device device) throws PartitionTableException {
+ return new ApmPartitionTable(this, firstSector, device);
+ }
+
+ public String getName() {
+ return "APM";
+ }
+
+ public boolean supports(byte[] first16KiB, BlockDeviceAPI devApi) {
+ return ApmPartitionTable.containsPartitionTable(first16KiB);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|