|
From: <fd...@us...> - 2008-05-01 15:15:23
|
Revision: 4035
http://jnode.svn.sourceforge.net/jnode/?rev=4035&view=rev
Author: fduminy
Date: 2008-05-01 08:15:18 -0700 (Thu, 01 May 2008)
Log Message:
-----------
jpartition : work in progress
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java
trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java
trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/consoleview/ConsoleView.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -57,7 +57,12 @@
private void start() throws Exception
{
- selectDevice();
+ if(!selectDevice())
+ {
+ println("no device to partition");
+ return;
+ }
+
if(!UserFacade.getInstance().getSelectedDevice().hasPartititionTable())
{
println("device has no partition table");
@@ -85,15 +90,23 @@
}
}
- private void selectDevice() throws IOException
+ private boolean selectDevice() throws IOException
{
+ boolean deviceSelected = false;
+
List<Device> devices = UserFacade.getInstance().getDevices();
- Options devicesOpt = new Options(context);
- int choice = (int) devicesOpt.show("Select a device", devices, DeviceLabelizer.INSTANCE);
+ if((devices != null) && !devices.isEmpty())
+ {
+ Options devicesOpt = new Options(context);
+ int choice = (int) devicesOpt.show("Select a device", devices, DeviceLabelizer.INSTANCE);
- String device = devices.get(choice - 1).getName();
- UserFacade.getInstance().selectDevice(device);
- println("device="+device);
+ String device = devices.get(choice - 1).getName();
+ UserFacade.getInstance().selectDevice(device);
+ println("device="+device);
+ deviceSelected = true;
+ }
+
+ return deviceSelected;
}
private void selectPartition() throws Exception
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/OSFacade.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -2,11 +2,16 @@
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import javax.naming.NameNotFoundException;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
import org.jnode.driver.ApiNotFoundException;
+import org.jnode.driver.DeviceAPI;
import org.jnode.driver.DeviceListener;
import org.jnode.driver.DeviceManager;
import org.jnode.driver.DeviceUtils;
@@ -19,6 +24,24 @@
import org.jnode.partitions.ibm.IBMPartitionTableEntry;
public class OSFacade {
+ private static final Logger LOG = Logger.getLogger(OSFacade.class);
+
+ private static Comparator<Partition> PARTITION_COMPARATOR = new Comparator<Partition>()
+ {
+ public int compare(Partition p1, Partition p2) {
+ // we assume here that the partition doesn't intersect
+ return (int) (p1.getStart() - p2.getStart());
+ }
+ };
+
+ @SuppressWarnings("unchecked")
+ private static final Class<PartitionableBlockDeviceAPI> REQUIRED_API = PartitionableBlockDeviceAPI.class;
+
+ static
+ {
+ LOG.setLevel(Level.DEBUG);
+ }
+
private static final OSFacade INSTANCE;
static
{
@@ -86,7 +109,7 @@
DeviceManager devMan = org.jnode.driver.DeviceUtils
.getDeviceManager();
for (org.jnode.driver.Device dev : devMan
- .getDevicesByAPI(IDEDeviceAPI.class)) {
+ .getDevicesByAPI(REQUIRED_API)) {
Device device = createDevice(dev);
if (device != null) {
devices.add(device);
@@ -95,54 +118,46 @@
} catch (NameNotFoundException e) {
throw new OSFacadeException("error in getDevices", e);
}
+
return devices;
}
private Device createDevice(org.jnode.driver.Device dev) throws OSFacadeException
{
+ LOG.debug("createDevice: wrapping device "+dev.getId());
+
Device device = null;
List<IBMPartitionTableEntry> partitions = getPartitions(dev);
if(partitions != null) // null if not supported
{
+ LOG.debug("createDevice: nbPartitions="+partitions.size());
+
+ long devSize = 0;
+ try {
+ devSize = dev.getAPI(REQUIRED_API).getLength();
+ } catch (ApiNotFoundException e) {
+ throw new OSFacadeException("error in createDevice", e);
+ } catch (IOException e) {
+ throw new OSFacadeException("error in createDevice", e);
+ }
+
+ // one empty partition taking all place
List<Partition> devPartitions = new ArrayList<Partition>(partitions.size());
- Partition prevPartition = null;
+ devPartitions.add(new Partition(0L, devSize, false));
+ // add used partitions
+ device = new Device(dev.getId(), devSize, dev, devPartitions);
for(IBMPartitionTableEntry e : partitions)
{
IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
+
long start = pte.getStartLba();
long size = pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
-
- if(pte.isEmpty())
- {
- if((prevPartition != null) && !prevPartition.isUsed())
- {
- // current and previous partitions are empty
- prevPartition.mergeWithNextPartition(size);
- }
- else
- {
- // current partition is empty but not the previous one
- devPartitions.add(new Partition(start, size, false));
- }
- }
- else
- {
- // current partition is not empty
- devPartitions.add(new Partition(start, size, true));
- }
+ device.addPartition(start, size); // add a non-empty partition
}
-
- try {
- long devSize = dev.getAPI(IDEDeviceAPI.class).getLength();
- device = new Device(dev.getId(), devSize, dev, devPartitions);
- } catch (ApiNotFoundException e) {
- throw new OSFacadeException("error in createDevice", e);
- } catch (IOException e) {
- throw new OSFacadeException("error in createDevice", e);
- }
}
+ LOG.debug("createDevice: return device="+device);
return device;
}
@@ -152,24 +167,26 @@
List<IBMPartitionTableEntry> partitions = new ArrayList<IBMPartitionTableEntry>();
try {
- if (dev.implementsAPI(IDEDeviceAPI.class)) {
- if (dev.implementsAPI(PartitionableBlockDeviceAPI.class)) {
- PartitionableBlockDeviceAPI<?> api = dev
- .getAPI(PartitionableBlockDeviceAPI.class);
- boolean supportedPartitions = true;
+ if (dev.implementsAPI(REQUIRED_API)) {
+ PartitionableBlockDeviceAPI<?> api = dev
+ .getAPI(REQUIRED_API);
+ boolean supportedPartitions = true;
- for (PartitionTableEntry e : api.getPartitionTable()) {
- if (!(e instanceof IBMPartitionTableEntry)) {
- // non IBM partition tables are not handled for now
- supportedPartitions = false;
- break;
- }
+ for (PartitionTableEntry e : api.getPartitionTable()) {
+ if (!(e instanceof IBMPartitionTableEntry)) {
+ // non IBM partition tables are not handled for now
+ supportedPartitions = false;
+ break;
+ }
- partitions.add((IBMPartitionTableEntry) e);
+ IBMPartitionTableEntry entry = (IBMPartitionTableEntry) e;
+ if(entry.isValid() && !entry.isEmpty())
+ {
+ partitions.add(entry);
}
+ }
- supported = supportedPartitions;
- }
+ supported = supportedPartitions;
}
} catch (ApiNotFoundException e) {
throw new OSFacadeException("error in getPartitions", e);
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -19,7 +19,7 @@
if(size < MIN_SIZE)
{
- throw new IllegalArgumentException("size must be > "+MIN_SIZE);
+ throw new IllegalArgumentException("size must be >= "+MIN_SIZE);
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/UserFacade.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -8,6 +8,7 @@
import java.util.List;
import java.util.Map;
+import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.jnode.apps.jpartition.ErrorReporter;
import org.jnode.apps.jpartition.commands.CreatePartitionCommand;
@@ -26,8 +27,13 @@
import org.jnode.fs.jfat.ClusterSize;
public class UserFacade {
- private static final Logger log = Logger.getLogger(UserFacade.class);
+ private static final Logger LOG = Logger.getLogger(UserFacade.class);
+ static
+ {
+ LOG.setLevel(Level.DEBUG);
+ }
+
private static final UserFacade INSTANCE = new UserFacade();
final private Map<String, Device> devices = new HashMap<String, Device>();
@@ -107,7 +113,7 @@
public void errorHappened(OSFacadeException e) {
if(errorReporter != null)
{
- errorReporter.reportError(log, UserFacade.this, e);
+ errorReporter.reportError(LOG, UserFacade.this, e);
}
}
};
@@ -209,7 +215,7 @@
} catch (OSFacadeException e) {
if(errorReporter != null)
{
- errorReporter.reportError(log, this, e);
+ errorReporter.reportError(LOG, this, e);
}
}
}
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/model/AbstractTestDevice.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -158,7 +158,7 @@
assertEquals(getStartFreeSpace(), shift, false, part1);
Partition part2 = partitions.get(getIndexFreeSpacePartition()+1);
- Assert.assertTrue("must return the same instance as addPartition", newPart == part1);
+ Assert.assertTrue("must return the same instance as addPartition", newPart == part2);
}
@Test
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/model/TestOSFacade.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -2,6 +2,7 @@
import org.jnode.apps.jpartition.ErrorReporter;
import org.jnode.apps.jpartition.utils.device.DeviceUtils;
+import org.jnode.test.AnnotationTest.Test;
import org.junit.Before;
public class TestOSFacade extends AbstractTest {
@@ -12,4 +13,9 @@
UserFacade.getInstance().getDeviceNames();
//selectedDevice = new Device("dev1", 10000);
}
+
+ @Test
+ public void removeMe()
+ {
+ }
}
Modified: trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
===================================================================
--- trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2008-04-30 20:42:29 UTC (rev 4034)
+++ trunk/distr/src/test/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2008-05-01 15:15:18 UTC (rev 4035)
@@ -18,8 +18,19 @@
import org.jnode.driver.DeviceNotFoundException;
import org.jnode.driver.DriverException;
import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.fs.service.FileSystemService;
+import org.jnode.fs.service.def.FileSystemPlugin;
import org.jnode.naming.InitialNaming;
import org.jnode.naming.NameSpace;
+import org.jnode.plugin.Extension;
+import org.jnode.plugin.ExtensionPoint;
+import org.jnode.plugin.Plugin;
+import org.jnode.plugin.PluginDescriptor;
+import org.jnode.plugin.PluginDescriptorListener;
+import org.jnode.plugin.PluginException;
+import org.jnode.plugin.PluginPrerequisite;
+import org.jnode.plugin.Runtime;
+import org.jnode.plugin.model.PluginDescriptorModel;
import org.jnode.test.fs.driver.stubs.StubDeviceManager;
import org.jnode.util.OsUtils;
@@ -38,6 +49,129 @@
InitialNaming.setNameSpace(namespace);
InitialNaming.bind(DeviceManager.NAME, StubDeviceManager.INSTANCE);
+
+ PluginDescriptor desc = new PluginDescriptor()
+ {
+
+ public void addListener(PluginDescriptorListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public boolean depends(String id) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public String getCustomPluginClassName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ExtensionPoint getExtensionPoint(
+ String extensionPointId) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ExtensionPoint[] getExtensionPoints() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Extension[] getExtensions() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getId() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getLicenseName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getLicenseUrl() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Plugin getPlugin() throws PluginException {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public ClassLoader getPluginClassLoader() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public PluginPrerequisite[] getPrerequisites() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public int getPriority() {
+ // TODO Auto-generated method stub
+ return 0;
+ }
+
+ public String getProviderName() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getProviderUrl() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Runtime getRuntime() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getVersion() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean hasCustomPluginClass() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isAutoStart() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isFragment() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public boolean isSystemPlugin() {
+ // TODO Auto-generated method stub
+ return true;
+ }
+
+ public void removeListener(PluginDescriptorListener listener) {
+ // TODO Auto-generated method stub
+
+ }
+
+ };
+ FileSystemService fss = new FileSystemPlugin(desc);
+ namespace.bind(FileSystemService.class, fss);
} catch (NameAlreadyBoundException e) {
throw new RuntimeException(e);
} catch (NamingException e) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|