You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(97) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(127) |
Feb
(34) |
Mar
(16) |
Apr
(26) |
May
(55) |
Jun
(107) |
Jul
(36) |
Aug
(72) |
Sep
(90) |
Oct
(41) |
Nov
(27) |
Dec
(13) |
| 2008 |
Jan
(37) |
Feb
(39) |
Mar
(98) |
Apr
(115) |
May
(134) |
Jun
(120) |
Jul
(86) |
Aug
(149) |
Sep
(68) |
Oct
(66) |
Nov
(104) |
Dec
(49) |
| 2009 |
Jan
(131) |
Feb
(132) |
Mar
(125) |
Apr
(172) |
May
(161) |
Jun
(43) |
Jul
(47) |
Aug
(38) |
Sep
(18) |
Oct
(6) |
Nov
(1) |
Dec
(15) |
| 2010 |
Jan
(21) |
Feb
(8) |
Mar
(10) |
Apr
(4) |
May
(9) |
Jun
|
Jul
(1) |
Aug
|
Sep
|
Oct
(2) |
Nov
|
Dec
(4) |
| 2011 |
Jan
(23) |
Feb
(10) |
Mar
(13) |
Apr
(3) |
May
|
Jun
(19) |
Jul
(11) |
Aug
(22) |
Sep
|
Oct
(4) |
Nov
(2) |
Dec
(12) |
| 2012 |
Jan
(3) |
Feb
(4) |
Mar
(7) |
Apr
(3) |
May
|
Jun
(1) |
Jul
(1) |
Aug
(30) |
Sep
(3) |
Oct
(2) |
Nov
|
Dec
(8) |
| 2013 |
Jan
(3) |
Feb
(40) |
Mar
|
Apr
|
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(12) |
Dec
|
| 2021 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
|
Dec
|
|
From: <fd...@us...> - 2007-04-15 21:46:07
|
Revision: 3169
http://jnode.svn.sourceforge.net/jnode/?rev=3169&view=rev
Author: fduminy
Date: 2007-04-15 14:46:06 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Modified Paths:
--------------
trunk/fs/src/driver/org/jnode/driver/block/PartitionableBlockDeviceAPI.java
trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java
trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java
Modified: trunk/fs/src/driver/org/jnode/driver/block/PartitionableBlockDeviceAPI.java
===================================================================
--- trunk/fs/src/driver/org/jnode/driver/block/PartitionableBlockDeviceAPI.java 2007-04-15 21:43:33 UTC (rev 3168)
+++ trunk/fs/src/driver/org/jnode/driver/block/PartitionableBlockDeviceAPI.java 2007-04-15 21:46:06 UTC (rev 3169)
@@ -49,4 +49,6 @@
* @throws IOException
*/
public PartitionTable<PTE> getPartitionTable() throws IOException;
+
+ public String toString();
}
Modified: trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java 2007-04-15 21:43:33 UTC (rev 3168)
+++ trunk/fs/src/fs/org/jnode/partitions/command/FdiskCommand.java 2007-04-15 21:46:06 UTC (rev 3169)
@@ -146,7 +146,7 @@
}
final String deviceId = ARG_DEVICE.getValue(cmdLine);
- final PartitionHelper helper = new PartitionHelper(deviceId, dm);
+ final PartitionHelper helper = new PartitionHelper(deviceId);
// initMBR
if (isInitMBR) {
Modified: trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java
===================================================================
--- trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java 2007-04-15 21:43:33 UTC (rev 3168)
+++ trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java 2007-04-15 21:46:06 UTC (rev 3169)
@@ -3,9 +3,13 @@
import java.io.IOException;
import java.nio.ByteBuffer;
+import javax.naming.NameNotFoundException;
+
import org.jnode.driver.ApiNotFoundException;
+import org.jnode.driver.Device;
import org.jnode.driver.DeviceManager;
import org.jnode.driver.DeviceNotFoundException;
+import org.jnode.driver.DeviceUtils;
import org.jnode.driver.DriverException;
import org.jnode.driver.block.BlockDeviceAPI;
import org.jnode.driver.bus.ide.IDEConstants;
@@ -27,21 +31,26 @@
public static final boolean SECTORS = false;
private final IDEDevice current;
- private final DeviceManager dm;
private final BlockDeviceAPI api;
private ByteBuffer MBR;
private BootSector bs;
-
- public PartitionHelper(String deviceId, DeviceManager dm)
+
+ public PartitionHelper(String deviceId)
+ throws DeviceNotFoundException, ApiNotFoundException, IOException, NameNotFoundException
+ {
+ this((IDEDevice)DeviceUtils.getDeviceManager().getDevice(deviceId));
+ }
+
+ public PartitionHelper(IDEDevice device)
throws DeviceNotFoundException, ApiNotFoundException, IOException
{
- this.current = (IDEDevice)dm.getDevice(deviceId);
- this.dm = dm;
+ this.current = device;
this.api = current.getAPI(BlockDeviceAPI.class);
reloadMBR();
}
+
public void initMbr() throws DeviceNotFoundException, ApiNotFoundException,
IOException
@@ -78,15 +87,23 @@
// restart the device
try {
- dm.stop(current);
- dm.start(current);
+ DeviceManager devMan = DeviceUtils.getDeviceManager();
+ devMan.stop(current);
+ devMan.start(current);
} catch (DeviceNotFoundException e) {
e.printStackTrace();
} catch (DriverException e) {
e.printStackTrace();
+ } catch (NameNotFoundException e) {
+ e.printStackTrace();
}
}
+ public boolean hasValidMBR()
+ {
+ return IBMPartitionTable.containsPartitionTable(MBR.array());
+ }
+
private void reloadMBR() throws IOException
{
this.MBR = ByteBuffer.allocate(IDEConstants.SECTOR_SIZE);
@@ -96,7 +113,7 @@
private void checkMBR() throws IOException
{
- if (!IBMPartitionTable.containsPartitionTable(MBR.array()))
+ if (!hasValidMBR())
throw new IOException("This device doesn't contain a valid MBR, use --initmbr.");
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 21:43:41
|
Revision: 3168
http://jnode.svn.sourceforge.net/jnode/?rev=3168&view=rev
Author: fduminy
Date: 2007-04-15 14:43:33 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
fixed missing libs bug for ant build
Modified Paths:
--------------
trunk/distr/build.xml
Modified: trunk/distr/build.xml
===================================================================
--- trunk/distr/build.xml 2007-04-15 21:24:32 UTC (rev 3167)
+++ trunk/distr/build.xml 2007-04-15 21:43:33 UTC (rev 3168)
@@ -8,6 +8,8 @@
<property name="my.jar" value="${jnode-distr.jar}"/>
<property name="junit4.jar" value="${basedir}/lib/junit-4.1.jar"/>
+ <property name="commons-logging.jar" value="${basedir}/lib/commons-logging.jar"/>
+ <property name="stamps-mvc.jar" value="${basedir}/lib/stamps_framework.jar"/>
<!-- Subproject specific classpath -->
<path id="my-cp">
@@ -18,6 +20,8 @@
<pathelement location="${jnode-fs.jar}"/>
<pathelement location="${junit4.jar}"/>
+ <pathelement location="${commons-logging.jar}"/>
+ <pathelement location="${stamps-mvc.jar}"/>
<path refid="cp"/>
</path>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 21:24:33
|
Revision: 3167
http://jnode.svn.sourceforge.net/jnode/?rev=3167&view=rev
Author: fduminy
Date: 2007-04-15 14:24:32 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Removed Paths:
-------------
trunk/distr/src/apps/org/jnode/apps/jpartition/view/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 21:22:29
|
Revision: 3166
http://jnode.svn.sourceforge.net/jnode/?rev=3166&view=rev
Author: fduminy
Date: 2007-04-15 14:22:28 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java
Removed Paths:
-------------
trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java 2007-04-15 21:20:05 UTC (rev 3165)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java 2007-04-15 21:22:28 UTC (rev 3166)
@@ -1,58 +0,0 @@
-package org.jnode.apps.jpartition.controller;
-
-import javax.naming.NameNotFoundException;
-
-import org.apache.log4j.Logger;
-import org.jnode.apps.jpartition.model.DevicePartitions;
-import org.jnode.apps.jpartition.model.DevicePartitionsList;
-import org.jnode.apps.jpartition.view.DevicePartitionsFrame;
-import org.jnode.apps.jpartition.view.DevicePartitionsUI;
-import org.jnode.driver.Device;
-import org.jnode.driver.DeviceListener;
-import org.jnode.driver.DeviceUtils;
-
-public class DevicePartitionsController implements DeviceListener
-{
- private static final Logger log = Logger.getLogger(DevicePartitionsController.class);
-
- private DevicePartitionsList model;
- private DevicePartitionsFrame view;
-
- public DevicePartitionsController(DevicePartitionsList model,
- DevicePartitionsFrame view)
- {
- this.model = model;
- this.view = view;
-
- try {
- DeviceUtils.getDeviceManager().addListener(this);
- } catch (NameNotFoundException e) {
- log.error(e);
- }
- }
-
- public void deviceStarted(Device device) {
- System.err.println("deviceStarted...");
- DevicePartitions devPart = new DevicePartitions(device);
- model.add(devPart);
- view.getDevPartsUI().deviceAdded(devPart);
- }
-
- public void deviceStop(Device device) {
- System.err.println("deviceStop...");
- DevicePartitions devPartsToRemove = null;
- for(DevicePartitions devParts : model)
- {
- if(device.equals(devParts.getDevice()))
- {
- devPartsToRemove = devParts;
- break;
- }
- }
- if(devPartsToRemove != null)
- {
- model.remove(devPartsToRemove);
- view.getDevPartsUI().deviceRemoved(devPartsToRemove);
- }
- }
-}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/controller/MainController.java 2007-04-15 21:22:28 UTC (rev 3166)
@@ -0,0 +1,92 @@
+package org.jnode.apps.jpartition.controller;
+
+import it.battlehorse.stamps.Dispatcher;
+import it.battlehorse.stamps.factories.DispatcherRegistry;
+import it.battlehorse.stamps.factories.TransformerRegistry;
+
+import org.jnode.apps.jpartition.ViewFactory;
+import org.jnode.apps.jpartition.model.CommandProcessorModel;
+import org.jnode.apps.jpartition.model.DeviceModel;
+import org.jnode.apps.jpartition.model.FileDeviceModel;
+import org.jnode.apps.jpartition.swingview.MainView;
+
+public class MainController
+{
+ final private DeviceModel deviceModel;
+ final private FileDeviceModel fileDeviceModel;
+ final private CommandProcessorModel cmdProcessorModel;
+
+ public MainController(ViewFactory viewFactory) throws Exception
+ {
+ TransformerRegistry.getInstance().loadTransformers();
+ Dispatcher dispatcher = DispatcherRegistry.getInstance().getBasicDispatcher();
+
+ // FileDevice
+ this.fileDeviceModel = new FileDeviceModel();
+ Object fileDeviceView = viewFactory.createFileDeviceView(this);
+
+ dispatcher.registerModel("FileDeviceModel",fileDeviceModel);
+ dispatcher.registerView("FileDeviceModel",fileDeviceView,true);
+
+ // CommandProcessor
+ this.cmdProcessorModel = new CommandProcessorModel();
+ Object cmdProcessorView = viewFactory.createCommandProcessorView(this);
+
+ dispatcher.registerModel("CommandProcessorModel",cmdProcessorModel);
+ dispatcher.registerView("CommandProcessorModel",cmdProcessorView,true);
+
+ // Device
+ this.deviceModel = new DeviceModel();
+ Object deviceView = viewFactory.createDeviceView(this, fileDeviceView, cmdProcessorView);
+
+ dispatcher.registerModel("DeviceModel",deviceModel);
+ dispatcher.registerView("DeviceModel",deviceView,true);
+ }
+
+/*
+ final private DeviceModel model;
+
+ public DeviceController(DeviceModel model)
+ {
+ this.model = model;
+ }
+
+
+ public static DeviceModel getDevicePartitions()
+ {
+ DeviceModel devParts = new DeviceModel();
+ try {
+ org.jnode.driver.DeviceManager devMan = org.jnode.driver.DeviceUtils.getDeviceManager();
+ Collection<Device> devices = devMan.getDevicesByAPI(PartitionableBlockDeviceAPI.class);
+ for(Device device : devices)
+ {
+ devParts.add(new DeviceModel((IDEDevice) device));
+ }
+ } catch (NameNotFoundException e) {
+ log.error(e);
+ }
+ return devParts;
+ }
+*/
+
+
+ public void userAddFakeDisk() {
+ fileDeviceModel.addFakeDisk();
+ }
+
+ public void userAddVMWareDisk() {
+ fileDeviceModel.addVMWareDisk();
+ }
+
+ public void userRemoveFileDevice(Object device) {
+ fileDeviceModel.removeFileDevice(device);
+ }
+
+ public void userProcessCommands() {
+ cmdProcessorModel.processCommands();
+ }
+
+ public void userSelectDevice(Object device) {
+ deviceModel.setDevice(device);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 21:20:18
|
Revision: 3165
http://jnode.svn.sourceforge.net/jnode/?rev=3165&view=rev
Author: fduminy
Date: 2007-04-15 14:20:05 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDeviceDriver.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/BasicNameSpace.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,35 @@
+/**
+ *
+ */
+package org.jnode.apps.jpartition.utils;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jnode.naming.NameSpace;
+
+public final class BasicNameSpace implements NameSpace {
+ protected final Map<Class<?>, Object> namespace = new HashMap<Class<?>, Object>();
+
+ public <T> void bind(Class<T> name, T service)
+ throws NamingException, NameAlreadyBoundException {
+ namespace.put(name, service);
+ }
+
+ public <T> T lookup(Class<T> name) throws NameNotFoundException {
+ return (T) namespace.get(name);
+ }
+
+ public Set<Class<?>> nameSet() {
+ return namespace.keySet();
+ }
+
+ public void unbind(Class<?> name) {
+ namespace.remove(name);
+ }
+}
\ No newline at end of file
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/AbstractIDEDevice.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,49 @@
+package org.jnode.apps.jpartition.utils.device;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import javax.naming.NameNotFoundException;
+
+import org.jnode.driver.DriverException;
+import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.driver.bus.ide.IDEConstants;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.PartitionTable;
+import org.jnode.partitions.ibm.IBMPartitionTable;
+import org.jnode.partitions.ibm.IBMPartitionTableType;
+
+abstract public class AbstractIDEDevice extends IDEDevice
+ implements PartitionableBlockDeviceAPI
+{
+ protected PartitionTable pt;
+
+ public AbstractIDEDevice(String name,
+ boolean primary, boolean master)
+ {
+ super(null, primary, master, name, null, null);
+ }
+
+ public PartitionTable getPartitionTable() throws IOException {
+ return pt;
+ }
+
+ public int getSectorSize() throws IOException {
+ return IDEConstants.SECTOR_SIZE;
+ }
+
+ protected PartitionTable buildPartitionTable() throws DriverException,
+ IOException, NameNotFoundException
+ {
+ // Read the bootsector
+ final byte[] bs = new byte[IDEConstants.SECTOR_SIZE];
+ read(0, ByteBuffer.wrap(bs));
+
+ return new IBMPartitionTable(new IBMPartitionTableType(), bs, this);
+ }
+
+ public String toString()
+ {
+ return getId();
+ }
+}
\ No newline at end of file
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/DeviceUtils.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,154 @@
+package org.jnode.apps.jpartition.utils.device;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.naming.NameNotFoundException;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.swingview.ErrorReporter;
+import org.jnode.apps.jpartition.swingview.FileDeviceView;
+import org.jnode.apps.vmware.disk.VMWareDisk;
+import org.jnode.apps.vmware.disk.tools.DiskFactory;
+import org.jnode.driver.ApiNotFoundException;
+import org.jnode.driver.Device;
+import org.jnode.driver.DeviceAlreadyRegisteredException;
+import org.jnode.driver.DeviceManager;
+import org.jnode.driver.DeviceNotFoundException;
+import org.jnode.driver.DriverException;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.command.PartitionHelper;
+import org.jnode.partitions.ibm.IBMPartitionTypes;
+
+public class DeviceUtils {
+ private static final long DEFAULT_FILE_SIZE = 1000;
+ private static final Logger log = Logger.getLogger(FileDeviceView.class);
+
+ public static IDEDevice createFakeDevice()
+ {
+ IDEDevice device = null;
+ try
+ {
+ String name = findUnusedName("fake");
+ FakeIDEDevice fd = new FakeIDEDevice(name, true, true, 1024000);
+ if(addDevice(fd))
+ {
+ device = fd;
+ }
+ else
+ {
+ ErrorReporter.reportError(log, DeviceUtils.class.getName(), "failed to add device");
+ }
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+ return device;
+ }
+
+ public static IDEDevice createVMWareDevice() {
+ IDEDevice device = null;
+
+ try
+ {
+ AbstractIDEDevice fd = createDevice();
+ if(addDevice(fd))
+ {
+ device = fd;
+ }
+ else
+ {
+ ErrorReporter.reportError(log, DeviceUtils.class.getName(), "failed to add device");
+ }
+ } catch (Exception e) {
+ log.error(e);
+ }
+
+ return device;
+ }
+
+ public static AbstractIDEDevice createDevice() throws Exception
+ {
+ File tmpFile = File.createTempFile("disk", "");
+ File directory = tmpFile.getParentFile();
+ String name = tmpFile.getName();
+
+ File mainFile = DiskFactory.createSparseDisk(directory, name, DEFAULT_FILE_SIZE);
+ VMWareDisk vmwareDisk = new VMWareDisk(mainFile);
+
+ AbstractIDEDevice dev = new FileIDEDevice(name,
+ true, true, vmwareDisk);
+ return dev;
+ }
+
+ public static void restart(Device device)
+ {
+ DeviceManager devMan;
+ try {
+ devMan = org.jnode.driver.DeviceUtils.getDeviceManager();
+
+ devMan.stop(device);
+ devMan.start(device);
+ } catch (NameNotFoundException e) {
+ log.error(e);
+ } catch (DeviceNotFoundException e) {
+ log.error(e);
+ } catch (DriverException e) {
+ log.error(e);
+ }
+ }
+
+ public static boolean addDevice(AbstractIDEDevice device)
+ {
+ boolean success = false;
+ try
+ {
+ DeviceManager devMan = org.jnode.driver.DeviceUtils.getDeviceManager();
+ devMan.register(device);
+ success = true;
+
+ PartitionHelper helper = new PartitionHelper(device);
+ helper.initMbr();
+ helper.write();
+ if(helper.hasValidMBR())
+ {
+ helper.modifyPartition(0, true, 0, DEFAULT_FILE_SIZE,
+ false, IBMPartitionTypes.PARTTYPE_WIN95_FAT32);
+ }
+ } catch (NameNotFoundException e) {
+ log.error(e);
+ } catch (DeviceAlreadyRegisteredException e) {
+ log.error(e);
+ } catch (DriverException e) {
+ log.error(e);
+ } catch (DeviceNotFoundException e) {
+ log.error(e);
+ } catch (ApiNotFoundException e) {
+ log.error(e);
+ } catch (IOException e) {
+ log.error(e);
+ }
+
+ return success;
+ }
+
+ public static String findUnusedName(String baseName) throws NameNotFoundException
+ {
+ DeviceManager devMan = org.jnode.driver.DeviceUtils.getDeviceManager();
+ String name = null;
+ int i = 0;
+ do
+ {
+ String newName = baseName + "-" + i;
+ try {
+ devMan.getDevice(newName);
+ i++;
+ } catch (DeviceNotFoundException e) {
+ name = newName;
+ }
+ }
+ while(name == null);
+
+ return name;
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FakeIDEDevice.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,57 @@
+package org.jnode.apps.jpartition.utils.device;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jnode.apps.vmware.disk.VMWareDisk;
+import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
+import org.jnode.apps.vmware.disk.tools.DiskFactory;
+import org.jnode.driver.DeviceManager;
+import org.jnode.driver.DriverException;
+import org.jnode.driver.block.BlockDeviceAPIHelper;
+import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.driver.bus.ide.IDEDeviceFactory;
+import org.jnode.driver.bus.ide.IDEDriverUtils;
+import org.jnode.naming.InitialNaming;
+
+public class FakeIDEDevice extends AbstractIDEDevice implements PartitionableBlockDeviceAPI
+{
+ private final long length;
+ public FakeIDEDevice(String name,
+ boolean primary, boolean master,
+ long length)
+ throws IOException, DriverException, NameNotFoundException, UnsupportedFormatException
+ {
+ super(name, primary, master);
+ this.length = length;
+
+ registerAPI(PartitionableBlockDeviceAPI.class, this);
+
+ setDriver(new FileIDEDeviceDriver());
+
+ pt = buildPartitionTable();
+ }
+
+ public void flush() throws IOException {
+ }
+
+ public long getLength() throws IOException {
+ return length;
+ }
+
+ public void read(long devOffset, ByteBuffer destBuf) throws IOException {
+ while(destBuf.remaining() > 0)
+ {
+ destBuf.put((byte) 0);
+ }
+ }
+
+ public void write(long devOffset, ByteBuffer srcBuf) throws IOException {
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDevice.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,61 @@
+package org.jnode.apps.jpartition.utils.device;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+
+import org.jnode.apps.vmware.disk.VMWareDisk;
+import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
+import org.jnode.apps.vmware.disk.tools.DiskFactory;
+import org.jnode.driver.DeviceManager;
+import org.jnode.driver.DriverException;
+import org.jnode.driver.block.BlockDeviceAPIHelper;
+import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.driver.bus.ide.IDEDeviceFactory;
+import org.jnode.driver.bus.ide.IDEDriverUtils;
+import org.jnode.naming.InitialNaming;
+
+public class FileIDEDevice extends AbstractIDEDevice implements PartitionableBlockDeviceAPI
+{
+ private VMWareDisk vmwareDisk;
+
+ public FileIDEDevice(String name,
+ boolean primary, boolean master,
+ VMWareDisk vmwareDisk)
+ throws IOException, DriverException, NameNotFoundException, UnsupportedFormatException
+ {
+ super(name, primary, master);
+ registerAPI(PartitionableBlockDeviceAPI.class, this);
+
+ this.vmwareDisk = vmwareDisk;
+
+ setDriver(new FileIDEDeviceDriver());
+
+ pt = buildPartitionTable();
+ }
+
+ public void flush() throws IOException {
+ vmwareDisk.flush();
+ }
+
+ public long getLength() throws IOException {
+ return vmwareDisk.getLength();
+ }
+
+ public void read(long devOffset, ByteBuffer destBuf) throws IOException {
+ BlockDeviceAPIHelper.checkBounds(this, devOffset, destBuf.remaining());
+
+ vmwareDisk.read(devOffset, destBuf);
+ }
+
+ public void write(long devOffset, ByteBuffer srcBuf) throws IOException {
+ BlockDeviceAPIHelper.checkBounds(this, devOffset, srcBuf.remaining());
+
+ vmwareDisk.write(devOffset, srcBuf);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDeviceDriver.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDeviceDriver.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/utils/device/FileIDEDeviceDriver.java 2007-04-15 21:20:05 UTC (rev 3165)
@@ -0,0 +1,32 @@
+package org.jnode.apps.jpartition.utils.device;
+
+import org.jnode.driver.Driver;
+import org.jnode.driver.DriverException;
+import org.jnode.driver.DeviceAlreadyRegisteredException;
+import org.jnode.driver.bus.ide.IDEDevice;
+
+/**
+ *
+ * @author Fabien DUMINY (fduminy at jnode.org)
+ *
+ */
+public class FileIDEDeviceDriver extends Driver {
+ /**
+ * Start the device.
+ *
+ * @throws org.jnode.driver.DriverException
+ *
+ */
+ protected void startDevice() throws DriverException {
+ }
+
+ /**
+ * Stop the device.
+ *
+ * @throws org.jnode.driver.DriverException
+ *
+ */
+ protected void stopDevice() throws DriverException {
+
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 21:17:18
|
Revision: 3164
http://jnode.svn.sourceforge.net/jnode/?rev=3164&view=rev
Author: fduminy
Date: 2007-04-15 14:17:16 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java
trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/CommandProcessorView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,82 @@
+package org.jnode.apps.jpartition.swingview;
+
+import it.battlehorse.stamps.annotations.ModelDependent;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.controller.MainController;
+
+public class CommandProcessorView extends JPanel
+{
+ private static final Logger log = Logger.getLogger(CommandProcessorView.class);
+
+ private MainController controller;
+
+ private DefaultListModel commands = new DefaultListModel();
+ private JList commandsUI = new JList(commands);
+ private JButton btnApply = new JButton("Apply");
+
+ public CommandProcessorView(MainController controller)
+ {
+ this.controller = controller;
+
+ setBorder(BorderFactory.createTitledBorder("pending commands"));
+
+ JPanel btnPanel = new JPanel(new BorderLayout());
+ btnPanel.add(btnApply, BorderLayout.NORTH);
+
+ JPanel panel = new JPanel(new BorderLayout());
+ panel.add(btnPanel, BorderLayout.EAST);
+ panel.add(new JScrollPane(commandsUI), BorderLayout.CENTER);
+ add(panel);
+
+ btnApply.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent ae_) {
+ CommandProcessorView.this.setEnabled(false);
+ CommandProcessorView.this.controller.userProcessCommands();
+ }
+ });
+ }
+
+ @ModelDependent(modelKey ="CommandProcessorModel" , propertyKey = "commandsProcessed")
+ public void commandsProcessed(Object command) {
+ setEnabled(true);
+ }
+
+ @ModelDependent(modelKey ="CommandProcessorModel" , propertyKey = "commandAdded")
+ public void commandAdded(Object command) {
+ commands.addElement(command);
+ }
+
+ @ModelDependent(modelKey ="CommandProcessorModel" , propertyKey = "commandStarted")
+ public void commandStarted(Object command) {
+ refreshCommand(command);
+ }
+
+ @ModelDependent(modelKey ="CommandProcessorModel" , propertyKey = "commandFinished")
+ public void commandFinished(Object command) {
+ refreshCommand(command);
+ }
+
+ @ModelDependent(modelKey ="CommandProcessorModel" , propertyKey = "commandRemoved")
+ public void commandRemoved(Object command) {
+ commands.removeElement(command);
+ }
+
+ protected void refreshCommand(Object command)
+ {
+ int index = commands.indexOf(command);
+ commands.set(index, command);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DeviceView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,96 @@
+package org.jnode.apps.jpartition.swingview;
+
+import it.battlehorse.stamps.annotations.ModelDependent;
+
+import javax.swing.JPanel;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.controller.MainController;
+import org.jnode.apps.jpartition.model.DeviceModel;
+
+public class DeviceView extends JPanel
+{
+ private static final Logger log = Logger.getLogger(DeviceView.class);
+
+ final private MainController controller;
+
+ //final private Object device;
+
+ public DeviceView(MainController controller)
+ {
+ this.controller = controller;
+ }
+
+/*
+ private static final Logger log = Logger.getLogger(DevicePartitionsUI.class);
+
+ final private DevicePartitionsList devicePartitions;
+
+ final private DefaultComboBoxModel cboDevicesModel = new DefaultComboBoxModel();
+ final private JComboBox cboDevices = new JComboBox(cboDevicesModel);
+ final private JPanel partitionsPanel = new JPanel(new FlowLayout());
+ final private PartitionController controller;
+
+ public DevicePartitionsUI(DevicePartitionsList devicePartitions, PartitionController controller)
+ {
+ super(new BorderLayout());
+
+ setBorder(BorderFactory.createTitledBorder(""));
+
+ this.devicePartitions = devicePartitions;
+ this.controller = controller;
+
+ JPanel devPanel = new JPanel(new BorderLayout());
+ devPanel.add(new JLabel("device : "), BorderLayout.WEST);
+ devPanel.add(cboDevices, BorderLayout.CENTER);
+ add(devPanel, BorderLayout.NORTH);
+
+ add(partitionsPanel, BorderLayout.CENTER);
+
+ for(DeviceModel devParts : devicePartitions)
+ {
+ cboDevicesModel.addElement(devParts);
+ }
+
+ if(cboDevicesModel.getSize() > 0)
+ {
+ cboDevices.setSelectedIndex(0);
+ }
+
+ cboDevices.addItemListener(new ItemListener()
+ {
+ public void itemStateChanged(ItemEvent event) {
+ if(event.getStateChange() == ItemEvent.SELECTED)
+ {
+ log.debug("itemStateChanged");
+ DeviceModel devParts = (DeviceModel) event.getItem();
+ partitionsPanel.removeAll();
+
+ if(devParts.getPartitions().isEmpty())
+ {
+ DiskAreaUI disk = new DiskAreaUI(DevicePartitionsUI.this.controller.getCommandProcessor(), devParts.getDevice());
+ disk.setLabel("disk not partitioned");
+ partitionsPanel.add(disk);
+ }
+ else
+ {
+ for(PartitionModel partition : devParts.getPartitions())
+ {
+ partitionsPanel.add(new PartitionUI(DevicePartitionsUI.this.controller.getCommandProcessor(), devParts.getDevice(), partition));
+ }
+ }
+ }
+ }
+ });
+ }
+
+ public void deviceAdded(DeviceModel devParts) {
+ log.debug("deviceAdded");
+ cboDevicesModel.addElement(devParts);
+ }
+
+ public void deviceRemoved(DeviceModel devParts) {
+ cboDevicesModel.removeElement(devParts);
+ }
+*/
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/DiskAreaView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,85 @@
+package org.jnode.apps.jpartition.swingview;
+
+import java.awt.Color;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.BorderFactory;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import org.jnode.apps.jpartition.controller.MainController;
+
+public class DiskAreaView extends JPanel
+{
+ final protected MainController controller;
+
+ final protected JLabel lblInfos = new JLabel();
+
+ public DiskAreaView(MainController controller)
+ {
+ this.controller = controller;
+
+ setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
+ lblInfos.setBackground(Color.CYAN);
+ add(lblInfos);
+
+ addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mousePressed(MouseEvent event) {
+ showMenu(event);
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent event) {
+ showMenu(event);
+ }
+ });
+ }
+/*
+ final private CommandProcessor commandProcessor;
+ final private Device device;
+
+ public DiskAreaView(CommandProcessor commandProcessor, Device device)
+ {
+ this.commandProcessor = commandProcessor;
+ this.device = device;
+
+ setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
+ lblInfos.setBackground(Color.CYAN);
+ add(lblInfos);
+
+ addMouseListener(new MouseAdapter()
+ {
+ @Override
+ public void mousePressed(MouseEvent event) {
+ showMenu(event);
+ }
+
+ @Override
+ public void mouseReleased(MouseEvent event) {
+ showMenu(event);
+ }
+ });
+ }
+
+ public void setLabel(String label)
+ {
+ lblInfos.setText(label);
+ }
+*/
+
+ protected void showMenu(MouseEvent event)
+ {
+ //TODO add popup menu
+/*
+ if(event.isPopupTrigger())
+ {
+ JPopupMenu menu = new JPopupMenu("context menu");
+ menu.add(new JMenuItem(new InitMbrAction((IDEDevice) device, commandProcessor)));
+ menu.show(event.getComponent(), event.getX(), event.getY());
+ }
+*/
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/ErrorReporter.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,39 @@
+package org.jnode.apps.jpartition.swingview;
+
+import org.apache.log4j.Logger;
+
+import charva.awt.Component;
+import charvax.swing.JOptionPane;
+
+public class ErrorReporter {
+ public static void reportError(Logger log, Object source, Throwable t)
+ {
+ reportError(log, source, (Object) t);
+ }
+
+ public static void reportError(Logger log, Object source, String message)
+ {
+ reportError(log, source, (Object) message);
+ }
+
+ private static void reportError(Logger log, Object source, Object message)
+ {
+ Component parent = (source instanceof Component) ? (Component) source : null;
+ Throwable t = (message instanceof Throwable) ? (Throwable) message : null;
+
+ String msg = (t == null) ? String.valueOf(message) : t.getMessage();
+ JOptionPane.showMessageDialog(parent,
+ "an error happened : "+msg+"\nSee logs for details",
+ "error",
+ JOptionPane.ERROR_MESSAGE);
+
+ if(t != null)
+ {
+ log.error(msg, t);
+ }
+ else
+ {
+ log.error(msg);
+ }
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/FileDeviceView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,81 @@
+package org.jnode.apps.jpartition.swingview;
+
+import it.battlehorse.stamps.annotations.ModelDependent;
+
+import java.awt.BorderLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.AbstractListModel;
+import javax.swing.DefaultListModel;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.controller.MainController;
+
+public class FileDeviceView extends JFrame
+{
+ private static final Logger log = Logger.getLogger(FileDeviceView.class);
+
+ private JList devicesList = new JList(new DefaultListModel());
+ private JPanel buttons = new JPanel();
+ private JButton addVMWareDiskButton = new JButton("add VMWare disk");
+ private JButton addFakeDiskButton = new JButton("add fake disk");
+ private JButton removeButton = new JButton("remove device");
+ final private MainController controller;
+
+ public FileDeviceView(MainController controller) throws Exception
+ {
+ this.controller = controller;
+
+ setTitle("File devices");
+ setLayout(new BorderLayout());
+ add(new JScrollPane(devicesList), BorderLayout.CENTER);
+ add(buttons, BorderLayout.SOUTH);
+
+ buttons.add(addVMWareDiskButton);
+ buttons.add(addFakeDiskButton);
+ buttons.add(removeButton);
+
+ addFakeDiskButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event) {
+ FileDeviceView.this.controller.userAddFakeDisk();
+ }
+ });
+ addVMWareDiskButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event) {
+ FileDeviceView.this.controller.userAddVMWareDisk();
+ }
+ });
+ removeButton.addActionListener(new ActionListener()
+ {
+ public void actionPerformed(ActionEvent event) {
+ if(devicesList.getSelectedIndex() >= 0)
+ {
+ Object value = devicesList.getSelectedValue();
+ FileDeviceView.this.controller.userRemoveFileDevice(value);
+ }
+ }
+ });
+
+ setSize(600, 300);
+ setVisible(true);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ }
+
+ @ModelDependent(modelKey ="FileDeviceModel" , propertyKey = "deviceAdded")
+ public void addDevice(Object device) {
+ ((DefaultListModel) devicesList.getModel()).addElement(device);
+ }
+
+ @ModelDependent(modelKey ="FileDeviceModel" , propertyKey = "deviceRemoved")
+ public void removeDevice(Object device) {
+ ((DefaultListModel) devicesList.getModel()).removeElement(device);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/MainView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,76 @@
+package org.jnode.apps.jpartition.swingview;
+
+import it.battlehorse.stamps.annotations.ModelDependent;
+
+import java.awt.BorderLayout;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+
+import javax.swing.DefaultComboBoxModel;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.controller.MainController;
+
+public class MainView extends JFrame {
+ private static final Logger log = Logger.getLogger(DeviceView.class);
+
+ final private MainController controller;
+ final private DefaultComboBoxModel devices;
+ final private DeviceView deviceView;
+
+ public MainView(MainController controller,
+ JFrame fileDeviceView,
+ JComponent cmdProcessorView) throws Exception
+ {
+ this.controller = controller;
+
+ setTitle("JPartition");
+ setLayout(new BorderLayout());
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+
+ add(cmdProcessorView, BorderLayout.SOUTH);
+
+ deviceView = new DeviceView(controller);
+ add(deviceView, BorderLayout.CENTER);
+
+ devices = new DefaultComboBoxModel();
+ JComboBox cboDevices = new JComboBox(devices);
+ cboDevices.addItemListener(new ItemListener()
+ {
+ public void itemStateChanged(ItemEvent event) {
+ boolean selected = (event.getStateChange() == ItemEvent.SELECTED);
+ if(selected)
+ {
+ MainView.this.controller.userSelectDevice(event.getItem());
+ }
+ }
+ });
+ add(cboDevices, BorderLayout.NORTH);
+
+ setSize(600, 300);
+ setVisible(true);
+ setLocation(fileDeviceView.getX(), fileDeviceView.getY() + fileDeviceView.getHeight());
+ }
+
+ @ModelDependent(modelKey ="DeviceModel" , propertyKey = "deviceStarted")
+ public void deviceStarted(Object device) {
+ log.debug("deviceStarted");
+ devices.addElement(device);
+ }
+
+ @ModelDependent(modelKey ="DeviceModel" , propertyKey = "deviceStop")
+ public void deviceStop(Object device) {
+ log.debug("deviceStop");
+ devices.removeElement(device);
+ }
+
+ @ModelDependent(modelKey ="DeviceModel" , propertyKey = "deviceSelected")
+ public void deviceSelected(Object device) {
+ log.debug("deviceSelected");
+ //TODO
+ //deviceView.init(device);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/PartitionView.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,83 @@
+package org.jnode.apps.jpartition.swingview;
+
+import it.battlehorse.stamps.annotations.ModelDependent;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.controller.MainController;
+import org.jnode.partitions.ibm.IBMPartitionTypes;
+
+public class PartitionView extends DiskAreaView
+{
+ private static final Logger log = Logger.getLogger(PartitionView.class);
+
+ private DeviceView deviceView;
+
+ public PartitionView(MainController controller, DeviceView deviceView)
+ {
+ super(controller);
+
+ this.deviceView = deviceView;
+ }
+
+ @ModelDependent(modelKey = "partition", propertyKey = "empty")
+ public void setEmpty(boolean empty) {
+ lblInfos.setText(empty ? "empty" : "");
+ }
+
+ @ModelDependent(modelKey = "partition", propertyKey = "bootable")
+ public void setBootable(boolean bootable) {
+ lblInfos.setText(bootable ? "B" : "");
+ }
+
+ @ModelDependent(modelKey = "partition", propertyKey = "type")
+ public void setType(IBMPartitionTypes type) {
+ lblInfos.setText(type.getName());
+ }
+
+ @ModelDependent(modelKey = "partition", propertyKey = "start")
+ public void setStart(long start) {
+
+ }
+
+ @ModelDependent(modelKey = "partition", propertyKey = "size")
+ public void setSize(long size) {
+ }
+
+/*
+ public PartitionModel getPartition() {
+ return partition;
+ }
+
+ public void setPartition(PartitionModel partition) {
+ if(this.partition != partition)
+ {
+ this.partition = partition;
+ refreshFromModel();
+ }
+ }
+
+ public void refreshFromModel()
+ {
+ StringBuilder sb = new StringBuilder();
+
+ String name = partition.getType().getName();
+ log.debug("refreshFromModel: name="+name);
+ if(name.length() > 10)
+ {
+ name = name.substring(0, 10);
+ }
+ String boot = partition.isBootable() ? "(B)" : "(-)";
+ log.debug("refreshFromModel: boot="+boot);
+
+ sb.append(boot).append(name);
+ if(!partition.isEmpty())
+ {
+ sb.append("-").append(partition.getStart());
+ sb.append("-").append(partition.getSize());
+ }
+ lblInfos.setText(sb.toString());
+
+ log.debug("refreshFromModel: description="+sb.toString());
+ }
+*/
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/SwingViewFactory.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,24 @@
+package org.jnode.apps.jpartition.swingview;
+
+import javax.swing.JComponent;
+import javax.swing.JFrame;
+
+import org.jnode.apps.jpartition.ViewFactory;
+import org.jnode.apps.jpartition.controller.MainController;
+
+public class SwingViewFactory implements ViewFactory {
+ public Object createDeviceView(MainController controller,
+ Object fileDeviceView, Object cmdProcessorView) throws Exception
+ {
+ return new MainView(controller, (JFrame)fileDeviceView, (JComponent)cmdProcessorView);
+ }
+
+ public Object createFileDeviceView(MainController controller) throws Exception
+ {
+ return new FileDeviceView(controller);
+ }
+
+ public Object createCommandProcessorView(MainController mainController) {
+ return new CommandProcessorView(mainController);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/BaseDeviceAction.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,54 @@
+package org.jnode.apps.jpartition.swingview.actions;
+
+import java.awt.event.ActionEvent;
+
+import javax.swing.AbstractAction;
+import javax.swing.Icon;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.commands.BaseDeviceCommand;
+import org.jnode.apps.jpartition.commands.framework.Command;
+import org.jnode.apps.jpartition.commands.framework.CommandProcessor;
+import org.jnode.apps.jpartition.swingview.ErrorReporter;
+import org.jnode.driver.bus.ide.IDEDevice;
+
+abstract public class BaseDeviceAction extends AbstractAction
+{
+ private static final Logger log = Logger.getLogger(BaseDeviceAction.class);
+
+ final protected CommandProcessor processor;
+ final protected IDEDevice device;
+
+ public BaseDeviceAction(IDEDevice device, CommandProcessor processor) {
+ super();
+ this.processor = processor;
+ this.device = device;
+ }
+
+ public BaseDeviceAction(IDEDevice device, CommandProcessor processor, String name, Icon icon) {
+ super(name, icon);
+ this.processor = processor;
+ this.device = device;
+ }
+
+ public BaseDeviceAction(IDEDevice device, CommandProcessor processor, String name) {
+ super(name);
+ this.processor = processor;
+ this.device = device;
+ }
+
+ public void actionPerformed(ActionEvent event)
+ {
+ try
+ {
+ Command command = getCommand(device);
+ processor.addCommand(command);
+ }
+ catch(Throwable t)
+ {
+ ErrorReporter.reportError(log, this, t);
+ }
+ }
+
+ abstract protected BaseDeviceCommand getCommand(IDEDevice device);
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/swingview/actions/InitMbrAction.java 2007-04-15 21:17:16 UTC (rev 3164)
@@ -0,0 +1,18 @@
+package org.jnode.apps.jpartition.swingview.actions;
+
+import org.jnode.apps.jpartition.commands.BaseDeviceCommand;
+import org.jnode.apps.jpartition.commands.InitMbrCommand;
+import org.jnode.apps.jpartition.commands.framework.CommandProcessor;
+import org.jnode.driver.bus.ide.IDEDevice;
+
+public class InitMbrAction extends BaseDeviceAction
+{
+ public InitMbrAction(IDEDevice device, CommandProcessor processor) {
+ super(device, processor, "init MBR");
+ }
+
+ @Override
+ protected BaseDeviceCommand getCommand(IDEDevice device) {
+ return new InitMbrCommand(device);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 21:05:18
|
Revision: 3163
http://jnode.svn.sourceforge.net/jnode/?rev=3163&view=rev
Author: fduminy
Date: 2007-04-15 14:05:11 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Removed Paths:
-------------
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java 2007-04-15 19:46:31 UTC (rev 3162)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java 2007-04-15 21:05:11 UTC (rev 3163)
@@ -1,73 +0,0 @@
-package org.jnode.apps.jpartition.model;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-import org.jnode.driver.ApiNotFoundException;
-import org.jnode.driver.Device;
-import org.jnode.driver.block.PartitionableBlockDeviceAPI;
-import org.jnode.partitions.PartitionTableEntry;
-import org.jnode.partitions.ibm.IBMPartitionTableEntry;
-
-public class DevicePartitions
-{
- private static final Logger log = Logger.getLogger(DevicePartitions.class);
-
- private final Device device;
- private final List<Partition> partitions = new ArrayList<Partition>();
-
- public DevicePartitions(Device device)
- {
- this.device = device;
- try {
- addPartitions(device);
- } catch (Exception e) {
- log.error(e);
- }
- }
-
- public List<Partition> getPartitions()
- {
- return partitions;
- }
-
- protected void addPartitions(Device device) throws Exception
- {
- System.err.println("addPartitions");
- if(device.implementsAPI(PartitionableBlockDeviceAPI.class))
- {
- System.err.println("implementsAPI");
- partitions.clear();
- PartitionableBlockDeviceAPI<?> api = device.getAPI(PartitionableBlockDeviceAPI.class);
- for(PartitionTableEntry e : api.getPartitionTable())
- {
- System.err.println("PartitionTableEntry");
- addPartition(e);
- }
- }
- }
-
- public void addPartition(PartitionTableEntry e)
- {
- if(e instanceof IBMPartitionTableEntry)
- {
- IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
- partitions.add(new Partition(pte));
- }
- else
- {
- log.warn("found non-IBMPartitionTableEntry");
- }
- }
-
- public String toString()
- {
- return device.getId();
- }
-
- public Device getDevice() {
- return device;
- }
-}
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java 2007-04-15 19:46:31 UTC (rev 3162)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java 2007-04-15 21:05:11 UTC (rev 3163)
@@ -1,7 +0,0 @@
-package org.jnode.apps.jpartition.model;
-
-import java.util.ArrayList;
-
-public class DevicePartitionsList extends ArrayList<DevicePartitions>
-{
-}
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2007-04-15 19:46:31 UTC (rev 3162)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2007-04-15 21:05:11 UTC (rev 3163)
@@ -1,40 +0,0 @@
-package org.jnode.apps.jpartition.model;
-
-import org.jnode.driver.bus.ide.IDEConstants;
-import org.jnode.partitions.ibm.IBMPartitionTableEntry;
-import org.jnode.partitions.ibm.IBMPartitionTypes;
-
-public class Partition
-{
- private final IBMPartitionTableEntry pte;
-
- public Partition(IBMPartitionTableEntry pte)
- {
- this.pte = pte;
- }
-
- public boolean isEmpty()
- {
- return pte.isEmpty();
- }
-
- public boolean isBootable()
- {
- return pte.getBootIndicator();
- }
-
- public IBMPartitionTypes getType()
- {
- return pte.getSystemIndicator();
- }
-
- public long getStart()
- {
- return pte.getStartLba();
- }
-
- public long getSize()
- {
- return pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
- }
-}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 19:46:32
|
Revision: 3162
http://jnode.svn.sourceforge.net/jnode/?rev=3162&view=rev
Author: fduminy
Date: 2007-04-15 12:46:31 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/CommandProcessorModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java
trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/AbstractModel.java 2007-04-15 19:46:31 UTC (rev 3162)
@@ -0,0 +1,32 @@
+package org.jnode.apps.jpartition.model;
+
+import it.battlehorse.stamps.Model;
+
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyChangeSupport;
+
+abstract public class AbstractModel implements Model
+{
+ final protected PropertyChangeSupport propSupport;
+
+ /**
+ * Creates a new instance of the class
+ */
+ public AbstractModel() {
+ propSupport = new PropertyChangeSupport(this);
+ }
+
+ //
+ // This method will be invoked by the dispatcher on model registration
+ //
+ public void addPropertyChangeListener(PropertyChangeListener listener) {
+ propSupport.addPropertyChangeListener(listener);
+ }
+
+ //
+ // This method will be invoked by the dispatcher on model deregistration
+ //
+ public void removePropertyChangeListener(PropertyChangeListener listener) {
+ propSupport.removePropertyChangeListener(listener);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/CommandProcessorModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/CommandProcessorModel.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/CommandProcessorModel.java 2007-04-15 19:46:31 UTC (rev 3162)
@@ -0,0 +1,53 @@
+package org.jnode.apps.jpartition.model;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.jpartition.commands.framework.Command;
+import org.jnode.apps.jpartition.commands.framework.CommandProcessor;
+import org.jnode.apps.jpartition.commands.framework.CommandProcessorListener;
+import org.jnode.apps.jpartition.swingview.ErrorReporter;
+
+public class CommandProcessorModel extends AbstractModel
+ implements CommandProcessorListener
+{
+ private static final Logger log = Logger.getLogger(CommandProcessorModel.class);
+
+ private final CommandProcessor commandProcessor;
+
+ public CommandProcessorModel()
+ {
+ commandProcessor = new CommandProcessor();
+ commandProcessor.addListener(this);
+ }
+
+ public void processCommands()
+ {
+ try
+ {
+ commandProcessor.process();
+ }
+ catch(Throwable t)
+ {
+ ErrorReporter.reportError(log, this, t);
+ }
+ finally
+ {
+ propSupport.firePropertyChange("commandsProcessed", null, this);
+ }
+ }
+
+ public void commandAdded(CommandProcessor processor, Command command) {
+ propSupport.firePropertyChange("commandAdded", null, command);
+ }
+
+ public void commandStarted(CommandProcessor processor, Command command) {
+ propSupport.firePropertyChange("commandStarted", command, command);
+ }
+
+ public void commandFinished(CommandProcessor processor, Command command) {
+ propSupport.firePropertyChange("commandFinished", command, command);
+ }
+
+ public void commandRemoved(CommandProcessor processor, Command command) {
+ propSupport.firePropertyChange("commandRemoved", command, command);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DeviceModel.java 2007-04-15 19:46:31 UTC (rev 3162)
@@ -0,0 +1,106 @@
+package org.jnode.apps.jpartition.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.naming.NameNotFoundException;
+
+import org.apache.log4j.Logger;
+import org.jnode.driver.Device;
+import org.jnode.driver.DeviceListener;
+import org.jnode.driver.DeviceUtils;
+import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.PartitionTableEntry;
+import org.jnode.partitions.command.PartitionHelper;
+import org.jnode.partitions.ibm.IBMPartitionTableEntry;
+
+public class DeviceModel extends AbstractModel
+ implements DeviceListener
+{
+ private static final Logger log = Logger.getLogger(DeviceModel.class);
+
+ private final List<PartitionModel> partitions = new ArrayList<PartitionModel>();
+
+ public DeviceModel()
+ {
+ try {
+ DeviceUtils.getDeviceManager().addListener(this);
+ } catch (NameNotFoundException e) {
+ log.error(e);
+ }
+ }
+
+ public void setDevice(Object device) {
+ propSupport.firePropertyChange("deviceSelected", null, device);
+ try {
+ addPartitions((IDEDevice) device);
+ } catch (Exception e) {
+ log.error(e);
+ }
+ }
+
+ protected void addPartitions(IDEDevice device) throws Exception
+ {
+ PartitionHelper helper = new PartitionHelper(device);
+
+ log.debug("addPartitions");
+ if(device.implementsAPI(PartitionableBlockDeviceAPI.class))
+ {
+ log.debug("implementsAPI");
+ partitions.clear();
+ PartitionableBlockDeviceAPI<?> api = device.getAPI(PartitionableBlockDeviceAPI.class);
+ for(PartitionTableEntry e : api.getPartitionTable())
+ {
+ log.debug("PartitionTableEntry");
+ addPartition(e);
+ }
+ }
+ }
+
+ public void addPartition(PartitionTableEntry e)
+ {
+ if(e instanceof IBMPartitionTableEntry)
+ {
+ IBMPartitionTableEntry pte = (IBMPartitionTableEntry) e;
+ addPartition(new PartitionModel(pte));
+ }
+ else
+ {
+ log.warn("found non-IBMPartitionTableEntry");
+ }
+ }
+
+ public void addPartition(PartitionModel partition)
+ {
+ propSupport.fireIndexedPropertyChange("partitionAdded", partitions.size(), null, partition);
+ partitions.add(partition);
+ }
+
+ public void removePartition(PartitionModel partition)
+ {
+ int index = partitions.indexOf(partition);
+ propSupport.fireIndexedPropertyChange("partitionRemoved", index, null, partition);
+ partitions.remove(partition);
+ }
+
+ //
+ // DeviceListener interface
+ //
+ public void deviceStarted(Device device) {
+ if(device instanceof IDEDevice)
+ {
+ log.debug("deviceStarted...");
+ propSupport.firePropertyChange("deviceStarted", null, device);
+ }
+ }
+
+ public void deviceStop(Device device) {
+ log.debug("deviceStop...");
+ propSupport.firePropertyChange("deviceStop", null, device);
+ }
+
+ //
+ //
+ //
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/FileDeviceModel.java 2007-04-15 19:46:31 UTC (rev 3162)
@@ -0,0 +1,36 @@
+package org.jnode.apps.jpartition.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jnode.apps.jpartition.utils.device.DeviceUtils;
+import org.jnode.driver.bus.ide.IDEDevice;
+
+public class FileDeviceModel extends AbstractModel {
+ private List<IDEDevice> fileDevices = new ArrayList<IDEDevice>();
+
+ public void addFakeDisk() {
+ addDevice(DeviceUtils.createFakeDevice());
+ }
+
+ public void addVMWareDisk() {
+ addDevice(DeviceUtils.createVMWareDevice());
+ }
+
+ public void addDevice(IDEDevice device)
+ {
+ if(device != null)
+ {
+ fileDevices.add(device);
+ propSupport.firePropertyChange("deviceAdded", null, device);
+ }
+ }
+
+ public void removeFileDevice(Object device) {
+ if(device != null)
+ {
+ fileDevices.remove(device);
+ propSupport.firePropertyChange("deviceRemoved", null, device);
+ }
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/PartitionModel.java 2007-04-15 19:46:31 UTC (rev 3162)
@@ -0,0 +1,110 @@
+package org.jnode.apps.jpartition.model;
+
+import it.battlehorse.stamps.annotations.Refreshable;
+
+import org.jnode.partitions.ibm.IBMPartitionTableEntry;
+import org.jnode.partitions.ibm.IBMPartitionTypes;
+
+
+public class PartitionModel extends AbstractModel
+{
+ private boolean empty;
+ private boolean bootable;
+ private IBMPartitionTypes type;
+ private long start;
+ private long size;
+
+ private IBMPartitionTableEntry pte;
+
+ public PartitionModel(IBMPartitionTableEntry pte)
+ {
+ this.pte = pte;
+
+ //TODO remove these fake values
+ this.empty = false;
+ this.bootable = true;
+ this.type = IBMPartitionTypes.PARTTYPE_WIN95_FAT32;
+ this.start = 0;
+ this.size = 1024;
+ }
+
+ @Refreshable
+ public boolean isEmpty() {
+ return empty;
+ }
+ public void setEmpty(boolean empty) {
+ propSupport.firePropertyChange("empty", this.empty, empty);
+ this.empty = empty;
+ }
+
+ @Refreshable
+ public boolean isBootable() {
+ return bootable;
+ }
+ public void setBootable(boolean bootable) {
+ propSupport.firePropertyChange("bootable", this.bootable, bootable);
+ this.bootable = bootable;
+ }
+
+ @Refreshable
+ public IBMPartitionTypes getType() {
+ return type;
+ }
+ public void setType(IBMPartitionTypes type) {
+ propSupport.firePropertyChange("type", this.type, type);
+ this.type = type;
+ }
+
+ @Refreshable
+ public long getStart() {
+ return start;
+ }
+ public void setStart(long start) {
+ propSupport.firePropertyChange("start", this.start, start);
+ this.start = start;
+ }
+
+ @Refreshable
+ public long getSize() {
+ return size;
+ }
+ public void setSize(long size) {
+ propSupport.firePropertyChange("size", this.size, size);
+ this.size = size;
+ }
+
+
+/*
+ private final IBMPartitionTableEntry pte;
+
+ public PartitionModel(IBMPartitionTableEntry pte)
+ {
+ this.pte = pte;
+ }
+
+ public boolean isEmpty()
+ {
+ return pte.isEmpty();
+ }
+
+ public boolean isBootable()
+ {
+ return pte.getBootIndicator();
+ }
+
+ public IBMPartitionTypes getType()
+ {
+ return pte.getSystemIndicator();
+ }
+
+ public long getStart()
+ {
+ return pte.getStartLba();
+ }
+
+ public long getSize()
+ {
+ return pte.getNrSectors() * IDEConstants.SECTOR_SIZE;
+ }
+*/
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 19:44:42
|
Revision: 3161
http://jnode.svn.sourceforge.net/jnode/?rev=3161&view=rev
Author: fduminy
Date: 2007-04-15 12:44:40 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/BaseCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/Command.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandException.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandStatus.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/BaseCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/BaseCommand.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/BaseCommand.java 2007-04-15 19:44:40 UTC (rev 3161)
@@ -0,0 +1,52 @@
+package org.jnode.apps.jpartition.commands.framework;
+
+import org.apache.log4j.Logger;
+
+abstract public class BaseCommand implements Command
+{
+ private static final Logger log = Logger.getLogger(BaseCommand.class);
+
+ private CommandStatus status = CommandStatus.NOT_RUNNING;
+ protected String name;
+
+ protected BaseCommand(String name)
+ {
+ this.name = name;
+ }
+
+ final public void execute(CommandProcessor processor) throws CommandException
+ {
+ try
+ {
+ status = CommandStatus.RUNNING;
+ processor.commandStarted(this);
+
+ doExecute();
+ status = CommandStatus.SUCCESS;
+ }
+ catch(CommandException e)
+ {
+ log.error("command failed", e);
+ status = CommandStatus.FAILED;
+ throw e;
+ }
+ catch(Throwable t)
+ {
+ log.error("command failed", t);
+ status = CommandStatus.FAILED;
+ throw new CommandException("command failed", t);
+ }
+ }
+
+ public CommandStatus getStatus()
+ {
+ return status;
+ }
+
+ abstract protected void doExecute() throws CommandException;
+
+ @Override
+ public String toString() {
+ return status + " - " + name;
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/Command.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/Command.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/Command.java 2007-04-15 19:44:40 UTC (rev 3161)
@@ -0,0 +1,6 @@
+package org.jnode.apps.jpartition.commands.framework;
+
+public interface Command {
+ public void execute(CommandProcessor processor) throws CommandException;
+ public CommandStatus getStatus();
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandException.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandException.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandException.java 2007-04-15 19:44:40 UTC (rev 3161)
@@ -0,0 +1,16 @@
+package org.jnode.apps.jpartition.commands.framework;
+
+public class CommandException extends Exception {
+ public CommandException(String s, Throwable cause) {
+ super(s, cause);
+ }
+
+ public CommandException(String s) {
+ super(s);
+ }
+
+ public CommandException(Throwable cause) {
+ super(cause);
+ }
+
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessor.java 2007-04-15 19:44:40 UTC (rev 3161)
@@ -0,0 +1,118 @@
+package org.jnode.apps.jpartition.commands.framework;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+import org.apache.log4j.Logger;
+
+public class CommandProcessor {
+ private static final Logger log = Logger.getLogger(CommandProcessor.class);
+
+ private Stack<Command> commands = new Stack<Command>();
+ private List<CommandProcessorListener> listeners = new ArrayList<CommandProcessorListener>();
+
+ private boolean running = false;
+
+ public synchronized void process()
+ {
+ if(!running)
+ {
+ running = true;
+
+ while(!commands.isEmpty())
+ {
+ Command command = null;
+ try
+ {
+ command = peekCommand();
+
+ command.execute(this);
+ }
+ catch(CommandException e)
+ {
+ log.error("error in command processing", e);
+ break;
+ }
+ catch(Throwable t)
+ {
+ log.error("unexpected error in command processing", t);
+ break;
+ }
+ finally
+ {
+ if(command != null)
+ {
+ for(CommandProcessorListener l : listeners)
+ {
+ l.commandFinished(this, command);
+ }
+
+ try {
+ removeCommand();
+ }
+ catch(Throwable t)
+ {
+ log.error("error in removeCommand", t);
+ }
+ }
+ }
+ }
+
+ running = false;
+ }
+ }
+
+ public void addCommand(Command command)
+ {
+ if(command.getStatus() != CommandStatus.NOT_RUNNING)
+ {
+ throw new IllegalArgumentException("command must be in status NOT_RUNNING");
+ }
+
+ commands.push(command);
+
+ for(CommandProcessorListener l : listeners)
+ {
+ l.commandAdded(this, command);
+ }
+ }
+
+ protected Command peekCommand() throws Exception
+ {
+ Command command = commands.peek();
+ if(command.getStatus() != CommandStatus.NOT_RUNNING)
+ {
+ throw new Exception("command already started : "+command);
+ }
+ return command;
+ }
+
+ protected void removeCommand()
+ {
+ Command command = commands.pop();
+
+ for(CommandProcessorListener l : listeners)
+ {
+ l.commandRemoved(this, command);
+ }
+ }
+
+ public void commandStarted(Command command)
+ {
+ for(CommandProcessorListener l : listeners)
+ {
+ l.commandStarted(this, command);
+ }
+ }
+
+ public void addListener(CommandProcessorListener listener)
+ {
+ listeners.add(listener);
+ }
+
+ public void removeListener(CommandProcessorListener listener)
+ {
+ listeners.remove(listener);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandStatus.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandStatus.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandStatus.java 2007-04-15 19:44:40 UTC (rev 3161)
@@ -0,0 +1,19 @@
+package org.jnode.apps.jpartition.commands.framework;
+
+public enum CommandStatus {
+ NOT_RUNNING("not running"),
+ RUNNING("running"),
+ SUCCESS("success"),
+ FAILED("failed");
+
+
+ private final String name;
+ private CommandStatus(String name)
+ {
+ this.name = name;
+ }
+
+ final public String toString(){
+ return name;
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 18:18:00
|
Revision: 3160
http://jnode.svn.sourceforge.net/jnode/?rev=3160&view=rev
Author: fduminy
Date: 2007-04-15 11:17:56 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/
trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessorListener.java
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/ViewFactory.java 2007-04-15 18:17:56 UTC (rev 3160)
@@ -0,0 +1,12 @@
+package org.jnode.apps.jpartition;
+
+import org.jnode.apps.jpartition.controller.MainController;
+
+public interface ViewFactory {
+ Object createDeviceView(MainController controller, Object fileDeviceView,
+ Object cmdProcessorView) throws Exception;
+
+ Object createFileDeviceView(MainController controller) throws Exception;
+
+ Object createCommandProcessorView(MainController mainController);
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/BaseDeviceCommand.java 2007-04-15 18:17:56 UTC (rev 3160)
@@ -0,0 +1,23 @@
+package org.jnode.apps.jpartition.commands;
+
+import org.jnode.apps.jpartition.commands.framework.BaseCommand;
+import org.jnode.apps.jpartition.commands.framework.CommandException;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.command.FdiskCommand;
+
+abstract public class BaseDeviceCommand extends BaseCommand {
+ protected final IDEDevice device;
+
+ public BaseDeviceCommand(String name, IDEDevice device)
+ {
+ super(name);
+ this.device = device;
+ }
+
+ abstract protected void doExecute() throws CommandException;
+
+ @Override
+ public String toString() {
+ return super.toString() + " - " + device.getId();
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/InitMbrCommand.java 2007-04-15 18:17:56 UTC (rev 3160)
@@ -0,0 +1,23 @@
+package org.jnode.apps.jpartition.commands;
+
+import org.jnode.apps.jpartition.commands.framework.CommandException;
+import org.jnode.driver.bus.ide.IDEDevice;
+import org.jnode.partitions.command.PartitionHelper;
+
+public class InitMbrCommand extends BaseDeviceCommand {
+
+ public InitMbrCommand(IDEDevice device) {
+ super("init MBR", device);
+ }
+
+ @Override
+ protected void doExecute() throws CommandException {
+ PartitionHelper helper;
+ try {
+ helper = new PartitionHelper(device);
+ helper.initMbr();
+ } catch (Throwable t) {
+ throw new CommandException(t);
+ }
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessorListener.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessorListener.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/commands/framework/CommandProcessorListener.java 2007-04-15 18:17:56 UTC (rev 3160)
@@ -0,0 +1,8 @@
+package org.jnode.apps.jpartition.commands.framework;
+
+public interface CommandProcessorListener {
+ void commandAdded(CommandProcessor processor, Command command);
+ void commandRemoved(CommandProcessor processor, Command command);
+ void commandStarted(CommandProcessor processor, Command command);
+ void commandFinished(CommandProcessor processor, Command command);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 18:15:19
|
Revision: 3159
http://jnode.svn.sourceforge.net/jnode/?rev=3159&view=rev
Author: fduminy
Date: 2007-04-15 11:15:09 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of JPartition : refactor around stamps-mvc for better separation
of model, view and controller
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
Removed Paths:
-------------
trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java
trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java
trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java 2007-04-15 18:10:57 UTC (rev 3158)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java 2007-04-15 18:15:09 UTC (rev 3159)
@@ -1,35 +0,0 @@
-/**
- *
- */
-package org.jnode.apps.jpartition;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Set;
-
-import javax.naming.NameAlreadyBoundException;
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.jnode.naming.NameSpace;
-
-public final class BasicNameSpace implements NameSpace {
- protected final Map<Class<?>, Object> namespace = new HashMap<Class<?>, Object>();
-
- public <T> void bind(Class<T> name, T service)
- throws NamingException, NameAlreadyBoundException {
- namespace.put(name, service);
- }
-
- public <T> T lookup(Class<T> name) throws NameNotFoundException {
- return (T) namespace.get(name);
- }
-
- public Set<Class<?>> nameSet() {
- return namespace.keySet();
- }
-
- public void unbind(Class<?> name) {
- namespace.remove(name);
- }
-}
\ No newline at end of file
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java 2007-04-15 18:10:57 UTC (rev 3158)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java 2007-04-15 18:15:09 UTC (rev 3159)
@@ -1,86 +0,0 @@
-package org.jnode.apps.jpartition;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
-
-import javax.naming.NameNotFoundException;
-import javax.naming.NamingException;
-
-import org.jnode.apps.vmware.disk.VMWareDisk;
-import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
-import org.jnode.driver.DeviceManager;
-import org.jnode.driver.DriverException;
-import org.jnode.driver.block.BlockDeviceAPIHelper;
-import org.jnode.driver.block.PartitionableBlockDeviceAPI;
-import org.jnode.driver.bus.ide.IDEConstants;
-import org.jnode.driver.bus.ide.IDEDevice;
-import org.jnode.driver.bus.ide.IDEDeviceFactory;
-import org.jnode.driver.bus.ide.IDEDriverUtils;
-import org.jnode.naming.InitialNaming;
-import org.jnode.partitions.PartitionTable;
-import org.jnode.partitions.ibm.IBMPartitionTable;
-import org.jnode.partitions.ibm.IBMPartitionTableType;
-
-public class FileIDEDevice extends IDEDevice implements PartitionableBlockDeviceAPI
-{
- private VMWareDisk vmwareDisk;
- private PartitionTable pt;
-
- public FileIDEDevice(File file, long fileSize,
- boolean primary, boolean master)
- throws IOException, DriverException, NameNotFoundException, UnsupportedFormatException
- {
- super(null, primary, master, file.getName(), null, null);
- registerAPI(PartitionableBlockDeviceAPI.class, this);
-
- vmwareDisk = new VMWareDisk(file);
-
- setDriver(new FileIDEDeviceDriver());
-
- pt = buildPartitionTable();
- }
-
- public void flush() throws IOException {
- vmwareDisk.flush();
- }
-
- public long getLength() throws IOException {
- return vmwareDisk.getLength();
- }
-
- public void read(long devOffset, ByteBuffer destBuf) throws IOException {
- BlockDeviceAPIHelper.checkBounds(this, devOffset, destBuf.remaining());
-
- vmwareDisk.read(devOffset, destBuf);
- }
-
- public void write(long devOffset, ByteBuffer srcBuf) throws IOException {
- BlockDeviceAPIHelper.checkBounds(this, devOffset, srcBuf.remaining());
-
- vmwareDisk.write(devOffset, srcBuf);
- }
-
- public String toString()
- {
- return getId();
- }
-
- public PartitionTable getPartitionTable() throws IOException {
- return pt;
- }
-
- public int getSectorSize() throws IOException {
- return IDEConstants.SECTOR_SIZE;
- }
-
- protected PartitionTable buildPartitionTable() throws DriverException, IOException, NameNotFoundException
- {
- // Read the bootsector
- final byte[] bs = new byte[IDEConstants.SECTOR_SIZE];
- read(0, ByteBuffer.wrap(bs));
-
- return new IBMPartitionTable(new IBMPartitionTableType(), bs, this);
- }
-}
Deleted: trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java 2007-04-15 18:10:57 UTC (rev 3158)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java 2007-04-15 18:15:09 UTC (rev 3159)
@@ -1,32 +0,0 @@
-package org.jnode.apps.jpartition;
-
-import org.jnode.driver.Driver;
-import org.jnode.driver.DriverException;
-import org.jnode.driver.DeviceAlreadyRegisteredException;
-import org.jnode.driver.bus.ide.IDEDevice;
-
-/**
- *
- * @author Fabien DUMINY (fduminy at jnode.org)
- *
- */
-public class FileIDEDeviceDriver extends Driver {
- /**
- * Start the device.
- *
- * @throws org.jnode.driver.DriverException
- *
- */
- protected void startDevice() throws DriverException {
- }
-
- /**
- * Stop the device.
- *
- * @throws org.jnode.driver.DriverException
- *
- */
- protected void stopDevice() throws DriverException {
-
- }
-}
Modified: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2007-04-15 18:10:57 UTC (rev 3158)
+++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2007-04-15 18:15:09 UTC (rev 3159)
@@ -1,60 +1,58 @@
package org.jnode.apps.jpartition;
-import java.util.Collection;
-
-import javax.naming.NameNotFoundException;
-import javax.swing.JFrame;
-import javax.swing.SwingUtilities;
-
import org.apache.log4j.Logger;
-import org.jnode.apps.jpartition.model.DevicePartitions;
-import org.jnode.apps.jpartition.model.DevicePartitionsList;
-import org.jnode.apps.jpartition.view.DevicePartitionsFrame;
-import org.jnode.apps.jpartition.view.FileDeviceFrame;
-import org.jnode.driver.Device;
-import org.jnode.driver.DeviceManager;
-import org.jnode.driver.block.PartitionableBlockDeviceAPI;
+import org.jnode.apps.jpartition.controller.MainController;
+import org.jnode.apps.jpartition.swingview.SwingViewFactory;
+import org.jnode.apps.jpartition.utils.BasicNameSpace;
import org.jnode.naming.InitialNaming;
import org.jnode.naming.NameSpace;
import org.jnode.test.fs.driver.stubs.StubDeviceManager;
+import org.jnode.test.gui.Emu;
+import org.jnode.util.OsUtils;
-public class JPartition {
+public class JPartition extends Emu
+{
private static final Logger log = Logger.getLogger(JPartition.class);
- public static void main(String[] args) throws Exception {
- initJNodeCore();
+ public static void main(String[] args) throws Throwable
+ {
+// testCharva();
- FileDeviceFrame frm = new FileDeviceFrame();
- frm.setSize(300, 300);
- frm.setVisible(true);
- frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ if(!OsUtils.isJNode())
+ {
+ initJNodeCore();
+ }
- DevicePartitionsFrame mainUI = new DevicePartitionsFrame(getDevicePartitions());
- mainUI.setSize(300, 300);
- mainUI.setVisible(true);
- mainUI.setLocation(frm.getX(), frm.getY() + frm.getHeight());
- mainUI.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ ViewFactory viewFactory = new SwingViewFactory();
+ MainController controller = new MainController(viewFactory);
}
- public static DevicePartitionsList getDevicePartitions()
- {
- DevicePartitionsList devParts = new DevicePartitionsList();
- try {
- DeviceManager devMan = InitialNaming.lookup(DeviceManager.NAME);
- Collection<Device> devices = devMan.getDevicesByAPI(PartitionableBlockDeviceAPI.class);
- for(Device device : devices)
- {
- devParts.add(new DevicePartitions(device));
- }
- } catch (NameNotFoundException e) {
- log.error(e);
- }
- return devParts;
- }
-
private static void initJNodeCore() throws Exception {
NameSpace namespace = new BasicNameSpace();
InitialNaming.setNameSpace(namespace);
namespace.bind(DeviceManager.NAME, StubDeviceManager.INSTANCE);
- }
+ }
+
+/*
+ private static void testCharva() throws Throwable
+ {
+ initEnv();
+ SwingTextScreenConsoleManager cm = new SwingTextScreenConsoleManager();
+ TextConsole tc = (TextConsole) cm.createConsole("Console 1",
+ ConsoleManager.CreateOptions.TEXT | ConsoleManager.CreateOptions.SCROLLABLE);
+ cm.focus(tc);
+ CommandShell cs = new CommandShell(tc);
+ final ShellManager sm = InitialNaming.lookup(ShellManager.NAME);
+ sm.registerShell(cs);
+ new Thread(cs).start();
+
+ charvax.swing.JFrame frm = new charvax.swing.JFrame("test");
+ JLabel label = new JLabel("test");
+ frm.add(label);
+ frm.setFocus(label);
+ frm.setSize(300, 300);
+ frm.setVisible(true);
+ frm.setDefaultCloseOperation(charvax.swing.JFrame.EXIT_ON_CLOSE);
+ }
+*/
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 18:11:12
|
Revision: 3158
http://jnode.svn.sourceforge.net/jnode/?rev=3158&view=rev
Author: fduminy
Date: 2007-04-15 11:10:57 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
update of VMWareDisk
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DescriptorRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDiskFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeaderRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskCopier.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskFactory.java
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java 2007-04-15 18:09:27 UTC (rev 3157)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java 2007-04-15 18:10:57 UTC (rev 3158)
@@ -12,12 +12,15 @@
import java.util.Map;
import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.extent.Access;
+import org.jnode.apps.vmware.disk.extent.ExtentType;
import org.jnode.apps.vmware.disk.handler.ExtentFactory;
import org.jnode.apps.vmware.disk.handler.FileDescriptor;
import org.jnode.apps.vmware.disk.handler.IOHandler;
import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
import org.jnode.apps.vmware.disk.handler.simple.SimpleExtentFactory;
import org.jnode.apps.vmware.disk.handler.sparse.SparseExtentFactory;
+import org.jnode.apps.vmware.disk.handler.sparse.SparseExtentHeader;
/**
* Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
@@ -191,6 +194,13 @@
return fileDescriptor;
}
+ public static ExtentDeclaration createExtentDeclaration(File mainFile, String fileName, Access access, long sizeInSectors, ExtentType extentType, long offset)
+ {
+ final File extentFile = IOUtils.getExtentFile(mainFile, fileName);
+ final boolean isMainExtent = extentFile.getName().equals(mainFile.getName());
+ return new ExtentDeclaration(access, sizeInSectors, extentType, fileName, extentFile, offset, isMainExtent);
+ }
+
public static File getExtentFile(File mainFile, String extentFileName) {
String path = mainFile.getParentFile().getAbsolutePath();
return new File(path, extentFileName);
@@ -304,4 +314,8 @@
return false;
}
+
+ public static void computeGrainTableCoverage(SparseExtentHeader header) {
+ header.setGrainTableCoverage(header.getNumGTEsPerGT() * header.getGrainSize());
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DescriptorRW.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DescriptorRW.java 2007-04-15 18:09:27 UTC (rev 3157)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DescriptorRW.java 2007-04-15 18:10:57 UTC (rev 3158)
@@ -159,9 +159,7 @@
offset = Long.valueOf(st.nextToken());
}
- final File extentFile = IOUtils.getExtentFile(mainFile, fileName);
- final boolean isMainExtent = extentFile.getName().equals(mainFile.getName());
- return new ExtentDeclaration(access, sizeInSectors, extentType, fileName, extentFile, offset, isMainExtent);
+ return IOUtils.createExtentDeclaration(mainFile, fileName, access, sizeInSectors, extentType, offset);
}
protected Header readHeader(BufferedReader reader) throws IOException, UnsupportedFormatException
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java 2007-04-15 18:09:27 UTC (rev 3157)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java 2007-04-15 18:10:57 UTC (rev 3158)
@@ -18,7 +18,6 @@
private final GrainTable[] grainTables;
public AllocationTable(GrainDirectory grainDirectory, GrainTable[] grainTables)
- throws IOException
{
this.grainDirectory = grainDirectory;
this.grainTables = grainTables;
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDiskFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDiskFactory.java 2007-04-15 18:09:27 UTC (rev 3157)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDiskFactory.java 2007-04-15 18:10:57 UTC (rev 3158)
@@ -1,8 +1,26 @@
package org.jnode.apps.vmware.disk.handler.sparse;
import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.ExtentDeclaration;
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.jnode.apps.vmware.disk.descriptor.AdapterType;
+import org.jnode.apps.vmware.disk.descriptor.CreateType;
+import org.jnode.apps.vmware.disk.descriptor.Descriptor;
+import org.jnode.apps.vmware.disk.descriptor.DiskDatabase;
+import org.jnode.apps.vmware.disk.descriptor.Header;
+import org.jnode.apps.vmware.disk.extent.Access;
+import org.jnode.apps.vmware.disk.extent.Extent;
+import org.jnode.apps.vmware.disk.extent.ExtentType;
import org.jnode.apps.vmware.disk.tools.DiskFactory;
+import org.jnode.driver.bus.ide.IDEConstants;
/**
* Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
@@ -12,9 +30,120 @@
*/
public class SparseDiskFactory extends DiskFactory
{
+ private static final Logger LOG = Logger.getLogger(SparseDiskFactory.class);
+
@Override
- protected boolean createDiskImpl(File mainFile, long size)
+ protected File createDiskImpl(File directory, String name, long size) throws IOException
{
- return true;
+ File mainFile = createMainFile(directory, name, size);
+ return mainFile;
}
+
+ protected File createMainFile(File directory, String name, long size) throws IOException
+ {
+ File mainFile = new File(directory, createDiskFileName(name, 0));
+ RandomAccessFile raf = new RandomAccessFile(mainFile, "rw");
+ FileChannel channel = raf.getChannel();
+
+ Descriptor descriptor = buildDescriptor(mainFile, size);
+ SparseExtentHeader header = new SparseExtentHeader();
+
+
+ return mainFile;
+ }
+
+ protected Descriptor buildDescriptor(File mainFile, long size)
+ {
+ LOG.info("buildDescriptor: wanted size="+size);
+ long sizeInSectors = size / IDEConstants.SECTOR_SIZE;
+ if((size % IDEConstants.SECTOR_SIZE) != 0)
+ {
+ LOG.debug("buildDescriptor: adding 1 more sector to fit size");
+ sizeInSectors ++;
+ }
+
+ // build DiskDatabase
+ DiskDatabase ddb = new DiskDatabase();
+ ddb.setAdapterType(AdapterType.ide);
+ ddb.setSectors(64);
+ ddb.setHeads(32);
+
+ int cylinderCapacity = ddb.getSectors() * ddb.getHeads();
+ int cylinders = (int) (sizeInSectors / cylinderCapacity);
+ if((sizeInSectors % cylinderCapacity) != 0)
+ {
+ LOG.debug("buildDescriptor: adding 1 more cylinder to fit size");
+ cylinders++;
+ }
+ ddb.setCylinders(cylinders);
+
+ int nbSectors = ddb.getCylinders() * ddb.getHeads() * ddb.getSectors();
+ LOG.info("buildDescriptor: allocated size="+(nbSectors * IDEConstants.SECTOR_SIZE));
+
+ // build Header
+ Header header = new Header();
+ header.setVersion("1");
+ header.setContentID(0);
+ header.setParentContentID(Header.CID_NOPARENT);
+ header.setCreateType(CreateType.monolithicSparse);
+ header.setParentFileNameHint("");
+
+ // build extents
+ List<Extent> extents = new ArrayList<Extent>();
+ SparseExtent mainExtent = createMainExtent(mainFile, nbSectors);
+ extents.add(mainExtent);
+
+ Descriptor descriptor = new Descriptor(mainFile, header, extents, ddb);
+ mainExtent.setDescriptor(descriptor);
+ return descriptor;
+ }
+
+ private SparseExtent createMainExtent(File mainFile, int nbSectors)
+ {
+ long offset = 0L; //TODO should be changed ?
+ ExtentDeclaration extentDecl = IOUtils.createExtentDeclaration(mainFile, mainFile.getName(), Access.RW, nbSectors, ExtentType.SPARSE, offset);
+
+ // create extent header
+ SparseExtentHeader sparseHeader = new SparseExtentHeader();
+ sparseHeader.setValidNewLineDetectionTest(true);
+ sparseHeader.setRedundantGrainTableWillBeUsed(false);
+
+ sparseHeader.setGrainSize(16);
+ sparseHeader.setDescriptorOffset(0); //TODO set value
+ sparseHeader.setDescriptorSize(0); //TODO set value
+ sparseHeader.setRgdOffset(0); //TODO set value
+
+ sparseHeader.setNumGTEsPerGT(512);
+ sparseHeader.setGdOffset(0); //TODO set value
+ sparseHeader.setOverHead(0); //TODO set value
+ sparseHeader.setUncleanShutdown(false);
+
+
+ int nbGrains = (int) (nbSectors / sparseHeader.getGrainSize());
+ int modulo = (int) (nbSectors % sparseHeader.getGrainSize());
+ if(modulo != 0)
+ {
+ nbGrains++;
+ nbSectors += (sparseHeader.getGrainSize() - modulo);
+ }
+ sparseHeader.setCapacity(nbSectors);
+
+ IOUtils.computeGrainTableCoverage(sparseHeader);
+
+ // create allocation table
+ int nbEntries = (int) (nbSectors / sparseHeader.getGrainTableCoverage());
+ int[] entries = new int[nbEntries];
+ Arrays.fill(entries, 0);
+ GrainDirectory gd = new GrainDirectory(entries);
+ GrainTable[] gTables = null;
+ AllocationTable allocationTable = new AllocationTable(gd, gTables);
+
+ SparseExtent mainExtent = new SparseExtent(null, extentDecl, sparseHeader, allocationTable, allocationTable);
+ return mainExtent;
+ }
+
+ protected String createDiskFileName(String name, int index)
+ {
+ return name + "-" + index + ".vmdk";
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeaderRW.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeaderRW.java 2007-04-15 18:09:27 UTC (rev 3157)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeaderRW.java 2007-04-15 18:10:57 UTC (rev 3158)
@@ -106,7 +106,7 @@
}
// additional/computed attributes
- header.setGrainTableCoverage(header.getNumGTEsPerGT() * header.getGrainSize());
+ IOUtils.computeGrainTableCoverage(header);
if(header.getGrainSize() <= 8)
{
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskCopier.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskCopier.java 2007-04-15 18:09:27 UTC (rev 3157)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskCopier.java 2007-04-15 18:10:57 UTC (rev 3158)
@@ -67,7 +67,7 @@
}
catch(IOException ioe)
{
- ioe.printStackTrace();
+ LOG.error(ioe);
throw ioe;
}
finally
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskFactory.java 2007-04-15 18:09:27 UTC (rev 3157)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskFactory.java 2007-04-15 18:10:57 UTC (rev 3158)
@@ -1,6 +1,7 @@
package org.jnode.apps.vmware.disk.tools;
import java.io.File;
+import java.io.IOException;
import org.jnode.apps.vmware.disk.handler.sparse.SparseDiskFactory;
@@ -14,12 +15,12 @@
{
private static final SparseDiskFactory SPARSE_FACTORY = new SparseDiskFactory();
- public static File createSparseDisk(File directory, String name, long size)
+ public static File createSparseDisk(File directory, String name, long size) throws IOException
{
return SPARSE_FACTORY.createDisk(directory, name, size);
}
- public File createDisk(File directory, String name, long size)
+ public File createDisk(File directory, String name, long size) throws IOException
{
if(!directory.isDirectory())
{
@@ -30,13 +31,8 @@
throw new IllegalArgumentException(directory.getAbsolutePath()+" must be writable");
}
- File mainFile = new File(directory, name);
- if(!createDiskImpl(mainFile, size))
- {
- mainFile = null;
- }
- return mainFile;
+ return createDiskImpl(directory, name, size);
}
- abstract protected boolean createDiskImpl(File mainFile, long size);
+ abstract protected File createDiskImpl(File directory, String name, long size) throws IOException;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 18:09:27
|
Revision: 3157
http://jnode.svn.sourceforge.net/jnode/?rev=3157&view=rev
Author: fduminy
Date: 2007-04-15 11:09:27 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
added stamps-mvc library (licence: LGPL) for JPartition
+ needed lib: commons-logging
Added Paths:
-----------
trunk/distr/lib/commons-logging.jar
trunk/distr/lib/stamps_framework.jar
Added: trunk/distr/lib/commons-logging.jar
===================================================================
(Binary files differ)
Property changes on: trunk/distr/lib/commons-logging.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/distr/lib/stamps_framework.jar
===================================================================
(Binary files differ)
Property changes on: trunk/distr/lib/stamps_framework.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-04-15 18:07:07
|
Revision: 3156
http://jnode.svn.sourceforge.net/jnode/?rev=3156&view=rev
Author: fduminy
Date: 2007-04-15 11:07:05 -0700 (Sun, 15 Apr 2007)
Log Message:
-----------
added stamps-mvc library (licence: LGPL) for JPartition
+ needed lib: commons-logging
Modified Paths:
--------------
trunk/distr/.classpath
Modified: trunk/distr/.classpath
===================================================================
--- trunk/distr/.classpath 2007-04-03 21:50:21 UTC (rev 3155)
+++ trunk/distr/.classpath 2007-04-15 18:07:05 UTC (rev 3156)
@@ -5,6 +5,8 @@
<classpathentry kind="src" path="src/apps"/>
<classpathentry kind="src" path="/JNode-GUI"/>
<classpathentry kind="lib" path="/JNode-Shell/lib/bsh-2.0b4.jar"/>
+ <classpathentry kind="lib" path="lib/stamps_framework.jar"/>
+ <classpathentry kind="lib" path="lib/commons-logging.jar"/>
<classpathentry kind="src" path="/JNode-Shell"/>
<classpathentry kind="src" path="/JNode-TextUI"/>
<classpathentry combineaccessrules="false" kind="src" path="/JNode-FS"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-04-03 21:50:22
|
Revision: 3155
http://jnode.svn.sourceforge.net/jnode/?rev=3155&view=rev
Author: lsantha
Date: 2007-04-03 14:50:21 -0700 (Tue, 03 Apr 2007)
Log Message:
-----------
Renamed.
Removed Paths:
-------------
trunk/fs/descriptors/org.jnode.jfat.xml
Deleted: trunk/fs/descriptors/org.jnode.jfat.xml
===================================================================
--- trunk/fs/descriptors/org.jnode.jfat.xml 2007-04-03 20:22:03 UTC (rev 3154)
+++ trunk/fs/descriptors/org.jnode.jfat.xml 2007-04-03 21:50:21 UTC (rev 3155)
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!DOCTYPE plugin SYSTEM "jnode.dtd">
-
-<plugin id="org.jnode.fs.jfat"
- name="JNode JFAT FileSystem"
- version="@VERSION@"
- license-name="lgpl"
- provider-name="JNode.org">
-
- <requires>
- <import plugin="org.jnode.fs"/>
- <import plugin="org.jnode.partitions.ibm"/>
- </requires>
-
- <runtime>
- <library name="jnode-fs.jar">
- <export name="org.jnode.fs.jfat.*"/>
- </library>
- </runtime>
-
- <extension point="org.jnode.fs.types">
- <type class="org.jnode.fs.jfat.FatFileSystemType"/>
- </extension>
-
-</plugin>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-04-03 20:22:07
|
Revision: 3154
http://jnode.svn.sourceforge.net/jnode/?rev=3154&view=rev
Author: lsantha
Date: 2007-04-03 13:22:03 -0700 (Tue, 03 Apr 2007)
Log Message:
-----------
Renamed.
Added Paths:
-----------
trunk/fs/descriptors/org.jnode.fs.jfat.xml
Copied: trunk/fs/descriptors/org.jnode.fs.jfat.xml (from rev 3144, trunk/fs/descriptors/org.jnode.jfat.xml)
===================================================================
--- trunk/fs/descriptors/org.jnode.fs.jfat.xml (rev 0)
+++ trunk/fs/descriptors/org.jnode.fs.jfat.xml 2007-04-03 20:22:03 UTC (rev 3154)
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plugin SYSTEM "jnode.dtd">
+
+<plugin id="org.jnode.fs.jfat"
+ name="JNode JFAT FileSystem"
+ version="@VERSION@"
+ license-name="lgpl"
+ provider-name="JNode.org">
+
+ <requires>
+ <import plugin="org.jnode.fs"/>
+ <import plugin="org.jnode.partitions.ibm"/>
+ </requires>
+
+ <runtime>
+ <library name="jnode-fs.jar">
+ <export name="org.jnode.fs.jfat.*"/>
+ </library>
+ </runtime>
+
+ <extension point="org.jnode.fs.types">
+ <type class="org.jnode.fs.jfat.FatFileSystemType"/>
+ </extension>
+
+</plugin>
Property changes on: trunk/fs/descriptors/org.jnode.fs.jfat.xml
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-04-03 20:21:43
|
Revision: 3153
http://jnode.svn.sourceforge.net/jnode/?rev=3153&view=rev
Author: lsantha
Date: 2007-04-03 13:21:40 -0700 (Tue, 03 Apr 2007)
Log Message:
-----------
GRUB installer inplementation in progress, by Tango. I've applied some refactorings on it.
Added Paths:
-----------
trunk/fs/src/fs/org/jnode/fs/jfat/command/
trunk/fs/src/fs/org/jnode/fs/jfat/command/GrubJFatBootSector.java
trunk/fs/src/fs/org/jnode/fs/jfat/command/GrubJFatFormatter.java
trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrubInstallCommand.java
Added: trunk/fs/src/fs/org/jnode/fs/jfat/command/GrubJFatBootSector.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/command/GrubJFatBootSector.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/command/GrubJFatBootSector.java 2007-04-03 20:21:40 UTC (rev 3153)
@@ -0,0 +1,47 @@
+package org.jnode.fs.jfat.command;
+
+import org.jnode.fs.jfat.BootSector;
+
+/**
+ *
+ * @author Tango Devian
+ *
+ */
+/**
+ * This file will contain the differetn value se
+ *
+ */
+
+
+class GrubJFatBootSector extends BootSector{
+
+ public GrubJFatBootSector(byte[] sector) {
+ super(sector);
+ }
+ /**
+ * Constructor for GrubBootSector.
+ * @param size
+ */
+ public GrubJFatBootSector(int size) {
+ super(size);
+ }
+ /**
+ * Gets the first sector of stage1_5
+ * @return long
+ */
+ public long getStage1_5Sector() {
+ return get32(0x44);
+ }
+
+ /**
+ * Sets the first sector of stage1_5
+ */
+ public void setStage1_5Sector(long v) {
+ set32(0x44, v);
+ }
+
+
+
+
+
+}
Added: trunk/fs/src/fs/org/jnode/fs/jfat/command/GrubJFatFormatter.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/command/GrubJFatFormatter.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/command/GrubJFatFormatter.java 2007-04-03 20:21:40 UTC (rev 3153)
@@ -0,0 +1,267 @@
+package org.jnode.fs.jfat.command;
+
+
+import java.io.*;
+import java.nio.ByteBuffer;
+import java.util.zip.CRC32;
+import org.apache.log4j.Logger;
+import org.jnode.driver.ApiNotFoundException;
+import org.jnode.driver.Device;
+import org.jnode.driver.block.BlockDeviceAPI;
+import org.jnode.fs.FileSystemException;
+import org.jnode.fs.jfat.BootSector;
+import org.jnode.util.FileUtils;
+import org.jnode.util.LittleEndian;
+
+/**
+ * File :GrubFatFormatter.java
+ * <p/>
+ * The very important file for the Grub Installation. Here the methods for write
+ * to the MBR and the setting the Stage2 are kept.
+ *
+ * @author Tango Devian
+ */
+class GrubJFatFormatter {
+ private static final Logger log = Logger.getLogger(GrubJFatFormatter.class);
+
+ // The variables parameters declaration
+ byte[] stage1;
+
+ byte[] stage1_5;
+ /**
+ * The Source path for the Grub in CD://devices/sg0/boot/grub/STAGE1.
+ * Because the grub can installed from the Live Boot CD.
+ */
+ final String stageResourceName1 = "//devices/sg0/BOOT/GRUB/STAGE1.";
+
+ final String stageResourceName1_5 = "//devices/sg0/BOOT/GRUB/FAT1_5.";
+
+ private static int installPartition = 0xFFFFFFFF;
+
+ private String configFile;
+
+ private int bootSectorOffset;
+ private static boolean clock = true;
+ private static boolean verify = true;
+
+ /**
+ * Create the actual bootsector.
+ */
+ private BootSector createBootSector(String stage1Name, String stage1_5Name,
+ BlockDeviceAPI devApi) throws Exception {
+ System.out.println("The createbootsector entered.");
+ if (stage1Name == null) {
+ System.out.println("hi i am in createbotsector....");
+ stage1Name = "//devices/sg0/BOOT/GRUB/STAGE1.";
+ }
+ if (stage1_5Name == null) {
+ stage1_5Name = "//devices/sg0/BOOT/GRUB/FAT1_5.";
+ }
+ try {
+ stage1 = getStage1(stage1Name);
+ stage1_5 = getStage1_5(stage1_5Name);
+ return new GrubJFatBootSector(getStage1(stageResourceName1));
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+
+ }
+
+ /**
+ * Reading the Grub stages from the device
+ *
+ * @param stage1ResourceName
+ * @return
+ * @throws IOException
+ */
+ public byte[] getStage1(String stage1ResourceName) throws IOException {
+ if (stage1 == null) {
+ File file = new File(stage1ResourceName);
+ InputStream is = new FileInputStream(file);
+ byte[] buf = new byte[512];
+ FileUtils.copy(is, buf);
+ is.close();
+ stage1 = buf;
+ }
+ return stage1;
+ }
+
+ public byte[] getStage1_5(String stage1_5ResourceName) throws IOException {
+ if (stage1_5 == null) {
+ File file = new File(stage1_5ResourceName);
+ InputStream in = new FileInputStream(file);
+ byte[] buf = new byte[(int) file.length()];
+ FileUtils.copy(in, buf);
+ in.close();
+ stage1_5 = buf;
+ }
+ return stage1_5;
+
+ }
+
+ /**
+ * The method that will write the stage1.5 for the fat specific to the
+ * Boot-sector to the block device.
+ */
+ public final static void writeStage1_5(long stage1_5_start, byte[] stage1_5,
+ BlockDeviceAPI devApi) {
+ try {
+ devApi.write(stage1_5_start, ByteBuffer.wrap(stage1_5));
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ /**
+ * @throws FileSystemException
+ * @throws FileSystemException
+ * @throws FileSystemException
+ * @throws IOException
+ * @throws IOException
+ * @see org.jnode.fs.fat.FatFormatter#format(BlockDeviceAPI)
+ */
+ public final void format(Device device, String path) throws FileSystemException, IOException {
+
+ System.out.println("The format(device) entered.");
+ BlockDeviceAPI devApi;
+ try {
+
+ devApi = device.getAPI(BlockDeviceAPI.class);
+ System.out.println("The devAPI initialization successfully....");
+ } catch (ApiNotFoundException e) {
+ throw new FileSystemException("Device is not a partition!", e);
+ }
+ System.out.println("The GrubJFatBootSector starting now......");
+ try {
+ GrubJFatBootSector bs = (GrubJFatBootSector) createBootSector(
+ stageResourceName1, stageResourceName1_5, devApi);
+
+ try {
+ bs.write(devApi);
+ // write the GRUB's stage1 to the MBR
+ // Writing Stage1
+ devApi.flush();
+
+ System.out.println("The stage1 is written successfully...");
+
+ stage1_5 = getStage1_5(stageResourceName1_5);
+
+ System.out.println("The stage1_5 buffer is created successfully....");
+ // writting the stage1.5;Here it is FatStage1_5
+ LittleEndian.setInt32(stage1_5, 512 - 8, bootSectorOffset + 2);
+ /* Fixup the install partition */
+ LittleEndian.setInt32(stage1_5, 512 + 0x08, installPartition);
+
+ setConfigFile("/boot/grub/menu.lst");
+ /* Fixup the config file */
+ if (configFile != null) {
+ int ofs = 512 + 0x12;
+ while (stage1_5[ofs] != 0) {
+ ofs++;
+ }
+ ofs++; /* Skip '\0' */
+ for (int i = 0; i < configFile.length(); i++) {
+ stage1_5[ofs++] = (byte) configFile.charAt(i);
+ }
+ stage1_5[ofs] = 0;
+ }
+ System.out.println("grub version [");
+ int i;
+ for (i = 512 + 0x12; stage1_5[i] != 0; i++) {
+ System.out.print((char) stage1_5[i]);
+ }
+ System.out.println("[ config ]");
+ i++;
+ for (; stage1_5[i] != 0; i++) {
+ System.out.println((char) stage1_5[i]);
+ }
+ // writting the stage1.5
+ System.out.println("the stage1_5 is writing now...pls wait...");
+
+ writeStage1_5(bs.getBytesPerSector(), stage1_5, devApi);
+ } catch (IOException e) {
+ System.out.println("The Bootsector Failed....");
+ }
+ } catch (Exception e) {
+ System.out.println("The exception at format()");
+ }
+
+ System.out.println("Thanks...The stage1_5 is written successfully.....");
+
+ // writting of the stage2 and menu.LST
+ System.out.println("The Stage2 is now writing....");
+ copyFAT("//devices/sg0/BOOT/GRUB/STAGE2_E.", path + "/boot/grub/");
+ System.out.println("The Menu.LSt is now writting....");
+ copyFAT("//devices/sg0/BOOT/GRUB/MENU.LST", path + "/boot/grub/");
+ System.out.println("The Stage2 is successfully created....");
+ }
+
+ public String getConfigFile() {
+ return configFile;
+ }
+
+ private void setConfigFile(String configFile) {
+ this.configFile = configFile;
+ }
+
+ public int getInstallPartition() {
+ return installPartition;
+ }
+
+ public static void setInstallPartition(int installPartition1) {
+ installPartition = installPartition1;
+ }
+
+ public static Long copyFile(File srcFile, File destFile) throws IOException {
+
+ InputStream in = new FileInputStream(srcFile);
+ OutputStream out = new FileOutputStream(destFile);
+ long millis = System.currentTimeMillis();
+ CRC32 checksum = null;
+ if (verify) {
+ checksum = new CRC32();
+ checksum.reset();
+ }
+ byte[] buffer = new byte[1024];
+ int bytesRead;
+ while ((bytesRead = in.read(buffer)) >= 0) {
+ if (verify) {
+ checksum.update(buffer, 0, bytesRead);
+ }
+ out.write(buffer, 0, bytesRead);
+ }
+ out.close();
+ in.close();
+ if (clock) {
+ millis = System.currentTimeMillis() - millis;
+ System.out.println("Second(s): " + (millis / 1000L));
+ }
+ if (verify) {
+ return new Long(checksum.getValue());
+ } else {
+ return null;
+ }
+ }
+
+ public static void copyFAT(String srcFileCopy, String destFileCopy) throws IOException {
+
+ // make sure the source file is indeed a readable file
+ File srcFile = new File(srcFileCopy);
+ if (!srcFile.isFile() || !srcFile.canRead()) {
+ System.err.println("Not a readable file: " + srcFile.getName());
+ System.exit(1);
+ }
+ // make sure the second argument is a directory
+ File destDir = new File(destFileCopy);
+ if (!destDir.exists()) {
+ destDir.mkdirs();
+ System.out.println("The BOOT/GRUB/ Directory is created...");
+ }
+ // create File object for destination file
+ File destFile = new File(destDir, srcFile.getName());
+
+ // copy file, optionally creating a checksum
+ Long checksumSrc = copyFile(srcFile, destFile);
+ }
+}
Added: trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrubInstallCommand.java
===================================================================
--- trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrubInstallCommand.java (rev 0)
+++ trunk/fs/src/fs/org/jnode/fs/jfat/command/JGrubInstallCommand.java 2007-04-03 20:21:40 UTC (rev 3153)
@@ -0,0 +1,105 @@
+package org.jnode.fs.jfat.command;
+
+import java.io.File;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.io.IOException;
+import java.io.FileNotFoundException;
+
+import javax.naming.NameNotFoundException;
+
+import org.jnode.driver.Device;
+import org.jnode.driver.DeviceManager;
+import org.jnode.driver.DeviceNotFoundException;
+import org.jnode.driver.DriverException;
+import org.jnode.naming.InitialNaming;
+import org.jnode.shell.Command;
+import org.jnode.shell.CommandLine;
+import org.jnode.shell.help.Help;
+import org.jnode.shell.help.Parameter;
+import org.jnode.shell.help.ParsedArguments;
+import org.jnode.shell.help.argument.DeviceArgument;
+import org.jnode.shell.help.argument.FileArgument;
+
+/**
+ * The Grub Installer command for the JNODE.
+ * jnode/>jgrub HDA_TARGET
+ * HDA_TARGET /dev/hda0 or /dev/fd0
+ *
+ * @author Tango Devian
+ */
+public class JGrubInstallCommand implements Command {
+
+ static final DeviceArgument ARG_DEVICE = new DeviceArgument("device", "device to where the Grub will install");
+
+ static final FileArgument ARG_DIR = new FileArgument("directory", "the directory where you set the Stage2 and Menu.Lst");
+
+ static final Help.Info HELP_INFO = new Help.Info("grub", "Install the grub to the specified location.", new Parameter[]{
+ new Parameter(ARG_DEVICE, Parameter.MANDATORY),
+ new Parameter(ARG_DIR, Parameter.MANDATORY)});
+
+ //static final Parameter PARAM_DEVICE = new Parameter(ARG_DEVICE,
+ //Parameter.MANDATORY);
+ /**
+ * @param args
+ * @throws Exception
+ */
+ public static void main(String[] args) throws Exception {
+ new JGrubInstallCommand().execute(new CommandLine(args), System.in, System.out, System.err);
+ }
+
+ /**
+ *
+ */
+ public void execute(CommandLine commandLine, InputStream in, PrintStream out, PrintStream err) throws Exception {
+ try {
+ ParsedArguments cmdLine = HELP_INFO.parse(commandLine.toStringArray());
+ String device = ARG_DEVICE.getValue(cmdLine);
+ //i am not sure yet
+ File destDir = ARG_DIR.getFile(cmdLine);
+
+ out.println("grub The dm is now initialized.");
+ DeviceManager dm = InitialNaming.lookup(DeviceManager.NAME);
+
+ out.println("The getdevice() method invoking now.");
+ Device dev = dm.getDevice(device);
+
+ out.println("The device is successfully initialized.");
+ out.println("The Grub Installer is started......wait");
+ try {
+ try {
+ new GrubJFatFormatter().format(dev, destDir.getAbsolutePath());
+ } catch (FileNotFoundException e) {
+ err.println("The ERROR at GRUB FAT FORMAT method.");
+ }
+ } catch (IOException e) {
+ err.println("The ERROR at the FAT FORMAT method...");
+ }
+ //restart the device
+ dm.stop(dev);
+ out.println("The device is stopped....");
+ dm.start(dev);
+ out.println("The Grub successflly installed.");
+ } catch (NameNotFoundException e) {
+ out.println("The NameNotFoundException occured...");
+ } catch (DeviceNotFoundException e) {
+ err.println("The Device Not Found...");
+ } catch (DriverException e) {
+ out.println("The DriverException Occuered......");
+ }
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-04-03 20:21:25
|
Revision: 3152
http://jnode.svn.sourceforge.net/jnode/?rev=3152&view=rev
Author: lsantha
Date: 2007-04-03 13:21:24 -0700 (Tue, 03 Apr 2007)
Log Message:
-----------
GRUB installer inplementation in progress, by Tango. I've applied some refactorings on it.
Added Paths:
-----------
trunk/fs/descriptors/org.jnode.fs.jfat.command.xml
Added: trunk/fs/descriptors/org.jnode.fs.jfat.command.xml
===================================================================
--- trunk/fs/descriptors/org.jnode.fs.jfat.command.xml (rev 0)
+++ trunk/fs/descriptors/org.jnode.fs.jfat.command.xml 2007-04-03 20:21:24 UTC (rev 3152)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plugin SYSTEM "jnode.dtd">
+
+<plugin id="org.jnode.fs.jfat.command"
+ name="JFAT speciffic commands"
+ version="@VERSION@"
+ provider-name="JNode.org"
+ license-name="lgpl">
+
+ <requires>
+ <import plugin="org.jnode.fs.jfat"/>
+ <import plugin="org.jnode.shell.help"/>
+ </requires>
+
+ <runtime>
+ <library name="jnode-fs.jar">
+ <export name="org.jnode.fs.jfat.command.*"/>
+ </library>
+ </runtime>
+
+ <extension point="org.jnode.shell.aliases">
+ <alias name="grub" class="org.jnode.fs.jfat.command.JGrubInstallCommand"/>
+ </extension>
+
+ <extension point="org.jnode.security.permissions">
+ <permission class="java.io.FilePermission" name="<<ALL FILES>>" actions="read,write,delete"/>
+ </extension>
+</plugin>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-04-03 20:20:50
|
Revision: 3151
http://jnode.svn.sourceforge.net/jnode/?rev=3151&view=rev
Author: lsantha
Date: 2007-04-03 13:20:47 -0700 (Tue, 03 Apr 2007)
Log Message:
-----------
GRUB installer inplementation in progress, by Tango. I've applied some refactorings on it.
Modified Paths:
--------------
trunk/all/conf/default-plugin-list.xml
Modified: trunk/all/conf/default-plugin-list.xml
===================================================================
--- trunk/all/conf/default-plugin-list.xml 2007-03-31 22:18:46 UTC (rev 3150)
+++ trunk/all/conf/default-plugin-list.xml 2007-04-03 20:20:47 UTC (rev 3151)
@@ -105,6 +105,7 @@
<plugin id="org.jnode.fs.ext2"/>
<plugin id="org.jnode.fs.fat"/>
<plugin id="org.jnode.fs.jfat"/>
+ <plugin id="org.jnode.fs.jfat.command"/>
<plugin id="org.jnode.fs.ramfs"/>
<plugin id="org.jnode.fs.ramfs.def"/>
<plugin id="org.jnode.fs.iso9660"/>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-03-31 22:18:49
|
Revision: 3150
http://jnode.svn.sourceforge.net/jnode/?rev=3150&view=rev
Author: fduminy
Date: 2007-03-31 15:18:46 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
new version with some refactoring, more tests ...
- working disk type detection
- working read/write of headers only
- read/write of sectors still buggy
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/TestVMWareDisk.java
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/TestVMWareDisk.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/TestVMWareDisk.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/TestVMWareDisk.java 2007-03-31 22:18:46 UTC (rev 3150)
@@ -0,0 +1,109 @@
+package org.jnode.apps.vmware.disk.test.readwrite;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.jnode.apps.vmware.disk.VMWareDisk;
+import org.jnode.apps.vmware.disk.handler.IOHandler;
+import org.jnode.apps.vmware.disk.test.Utils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+public class TestVMWareDisk extends BaseReadWriteTest
+{
+ private static final Logger LOG = Logger.getLogger(TestVMWareDisk.class);
+
+ public TestVMWareDisk(File diskFile) throws IOException
+ {
+ super(diskFile);
+ }
+
+ @Test
+ public void read() throws Exception
+ {
+ VMWareDisk disk = new VMWareDisk(diskFile);
+
+ ByteBuffer data = IOUtils.allocate(IOHandler.SECTOR_SIZE * 100);
+ disk.read(0, data);
+
+ Assert.assertEquals(toString()+": buffer should be filled", 0, data.remaining());
+ }
+
+ @Test
+ @Ignore
+ public void write() throws Exception
+ {
+ VMWareDisk disk = new VMWareDisk(diskFile);
+
+ ByteBuffer data = IOUtils.allocate(IOHandler.SECTOR_SIZE * 100);
+ disk.write(0, data);
+
+ Assert.assertEquals(toString()+": buffer should be fully copied", 0, data.remaining());
+ }
+
+ @Test
+ @Ignore
+ public void writeAndRead() throws Exception
+ {
+ Utils.DO_CLEAR = false;
+
+ LOG.info("BEGIN writeAndRead");
+ VMWareDisk disk = new VMWareDisk(diskFile);
+
+ // write
+ LOG.info("writeAndRead: writing...");
+ int size = IOHandler.SECTOR_SIZE * 100;
+ ByteBuffer expectedData = IOUtils.allocate(size);
+ for(int i = 0 ; i < (size / 4) ; i++)
+ {
+ expectedData.putInt(i);
+ }
+ expectedData.rewind();
+ disk.write(0, expectedData);
+ disk.flush();
+
+ // read
+ LOG.info("writeAndRead: reading...");
+ VMWareDisk disk2 = new VMWareDisk(diskFile);
+ Assert.assertEquals("disk has different size", disk.getLength(), disk2.getLength());
+ Assert.assertEquals("disk has different descriptor", disk.getDescriptor(), disk2.getDescriptor());
+
+ expectedData.rewind();
+ ByteBuffer actualData = IOUtils.allocate(size);
+ disk2.read(0, actualData);
+ long nbErrors = 0;
+ long nbInts = (size / 4);
+ for(int i = 0 ; i < nbInts ; i++)
+ {
+ int actual = actualData.getInt(i);
+ int expected = expectedData.getInt();
+ //Assert.assertEquals("bad data at index "+(i*4), expected, actual);
+ if(actual != expected)
+ {
+ nbErrors++;
+ }
+ }
+ double ratio = ((double) ((10000 * nbErrors) / nbInts)) / 100.0;
+ Assert.assertTrue("bad data. nbErrors="+nbErrors+" (ratio="+ratio+"%)", (nbErrors == 0));
+
+ LOG.info("END writeAndRead");
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-03-31 16:56:34
|
Revision: 3149
http://jnode.svn.sourceforge.net/jnode/?rev=3149&view=rev
Author: fduminy
Date: 2007-03-31 09:56:33 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
new version with some refactoring, more tests ...
- working disk type detection
- working read/write of headers only
- read/write of sectors still buggy
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleDescriptorRW.java
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleDescriptorRW.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleDescriptorRW.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleDescriptorRW.java 2007-03-31 16:56:33 UTC (rev 3149)
@@ -0,0 +1,38 @@
+/**
+ *
+ */
+package org.jnode.apps.vmware.disk.handler.simple;
+
+import java.io.IOException;
+
+import org.jnode.apps.vmware.disk.ExtentDeclaration;
+import org.jnode.apps.vmware.disk.descriptor.Descriptor;
+import org.jnode.apps.vmware.disk.descriptor.DescriptorRW;
+import org.jnode.apps.vmware.disk.extent.Extent;
+import org.jnode.apps.vmware.disk.handler.FileDescriptor;
+import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+final class SimpleDescriptorRW extends DescriptorRW
+{
+ @Override
+ public Extent createMainExtent(Descriptor desc, ExtentDeclaration extentDecl)
+ {
+ return new Extent(desc, extentDecl);
+ }
+
+ @Override
+ public Extent createExtent(FileDescriptor fileDescriptor, ExtentDeclaration extentDecl)
+ throws IOException, UnsupportedFormatException
+ {
+ Descriptor desc = (fileDescriptor == null) ? null :
+ fileDescriptor.getDescriptor();
+ return createMainExtent(desc, extentDecl);
+ }
+
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-03-31 16:55:19
|
Revision: 3148
http://jnode.svn.sourceforge.net/jnode/?rev=3148&view=rev
Author: fduminy
Date: 2007-03-31 09:55:17 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
new version with some refactoring, more tests ...
- working disk type detection
- working read/write of headers only
- read/write of sectors still buggy
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/BaseReadWriteTest.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/TestHeader.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/
trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskCopier.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskFactory.java
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/BaseReadWriteTest.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/BaseReadWriteTest.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/BaseReadWriteTest.java 2007-03-31 16:55:17 UTC (rev 3148)
@@ -0,0 +1,163 @@
+package org.jnode.apps.vmware.disk.test.readwrite;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.jnode.apps.vmware.disk.VMWareDisk;
+import org.jnode.apps.vmware.disk.handler.IOHandler;
+import org.jnode.apps.vmware.disk.test.BaseTest;
+import org.jnode.apps.vmware.disk.test.Utils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+@RunWith(value = Parameterized.class)
+abstract public class BaseReadWriteTest extends BaseTest {
+ private static final Logger LOG = Logger.getLogger(BaseReadWriteTest.class);
+
+ private static final String DISKS_PACKAGE = "/org/jnode/apps/vmware/disk/test/disks/";
+ private static final String DISK_BASE_NAME = "Menuet32-";
+
+ private static final String RESTRICT_TO_FILE_NAME = "Menuet32-0";
+ //private static final String RESTRICT_TO_FILE_NAME = null;
+
+ private static final String DISKS_PATH;
+ static
+ {
+ String classpath = System.getProperty("java.class.path");
+ StringTokenizer tokenizer = new StringTokenizer(classpath, File.pathSeparator, false);
+ File foundPath = null;
+ while(tokenizer.hasMoreTokens())
+ {
+ File path = new File(tokenizer.nextToken());
+ if(path.isDirectory())
+ {
+ path = new File(path, DISKS_PACKAGE);
+ if(path.exists())
+ {
+ foundPath = path;
+ break;
+ }
+ }
+ }
+ if(foundPath == null)
+ {
+ throw new RuntimeException("directory not found for package "+DISKS_PACKAGE);
+ }
+
+ DISKS_PATH = foundPath.getAbsolutePath();
+
+ System.out.println("\ndirectory for package "+DISKS_PACKAGE+" : "+DISKS_PATH);
+ }
+
+ @Parameters
+ public static List<File[]> data()
+ {
+ File directory = new File(DISKS_PATH);
+ File[] files = directory.listFiles(new FilenameFilter()
+ {
+ public boolean accept(File dir, String name) {
+ boolean ok = name.matches(DISK_BASE_NAME + "[0-9]*.vmdk");
+
+ if(RESTRICT_TO_FILE_NAME != null)
+ {
+ ok &= name.startsWith(RESTRICT_TO_FILE_NAME);
+ }
+
+ return ok;
+ }
+ });
+ List<File[]> list = new ArrayList<File[]>(files.length);
+ for(File f : files)
+ {
+ list.add(new File[]{f});
+ }
+
+ return list;
+ }
+
+ public BaseReadWriteTest(File diskFile) throws IOException
+ {
+ super(diskFile, true);
+ }
+
+ @Test
+ @Ignore
+ public void read() throws Exception
+ {
+ VMWareDisk disk = new VMWareDisk(diskFile);
+
+ ByteBuffer data = IOUtils.allocate(IOHandler.SECTOR_SIZE * 100);
+ disk.read(0, data);
+
+ Assert.assertEquals(toString()+": buffer should be filled", 0, data.remaining());
+ }
+
+ @Test
+ @Ignore
+ public void write() throws Exception
+ {
+ VMWareDisk disk = new VMWareDisk(diskFile);
+
+ ByteBuffer data = IOUtils.allocate(IOHandler.SECTOR_SIZE * 100);
+ disk.write(0, data);
+
+ Assert.assertEquals(toString()+": buffer should be fully copied", 0, data.remaining());
+ }
+
+ @Test
+ public void writeAndRead() throws Exception
+ {
+ Utils.DO_CLEAR = false;
+
+ LOG.info("BEGIN writeAndRead");
+ VMWareDisk disk = new VMWareDisk(diskFile);
+
+ // write
+ LOG.info("writeAndRead: writing...");
+ int size = IOHandler.SECTOR_SIZE * 100;
+ ByteBuffer expectedData = IOUtils.allocate(size);
+ for(int i = 0 ; i < (size / 4) ; i++)
+ {
+ expectedData.putInt(i);
+ }
+ expectedData.rewind();
+ disk.write(0, expectedData);
+ disk.flush();
+
+ // read
+ LOG.info("writeAndRead: reading...");
+ VMWareDisk disk2 = new VMWareDisk(diskFile);
+ Assert.assertEquals("disk has different size", disk.getLength(), disk2.getLength());
+ Assert.assertEquals("disk has different descriptor", disk.getDescriptor(), disk2.getDescriptor());
+
+ expectedData.rewind();
+ ByteBuffer actualData = IOUtils.allocate(size);
+ disk2.read(0, actualData);
+ for(int i = 0 ; i < (size / 4) ; i++)
+ {
+ int actual = actualData.getInt(i);
+ int expected = expectedData.getInt();
+ Assert.assertEquals("bad data at index "+(i*4), expected, actual);
+ }
+ LOG.info("END writeAndRead");
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/TestHeader.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/TestHeader.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/readwrite/TestHeader.java 2007-03-31 16:55:17 UTC (rev 3148)
@@ -0,0 +1,73 @@
+package org.jnode.apps.vmware.disk.test.readwrite;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.jnode.apps.vmware.disk.VMWareDisk;
+import org.jnode.apps.vmware.disk.handler.IOHandler;
+import org.jnode.apps.vmware.disk.test.Utils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+public class TestHeader extends BaseReadWriteTest
+{
+ private static final Logger LOG = Logger.getLogger(TestHeader.class);
+
+ public TestHeader(File diskFile) throws IOException
+ {
+ super(diskFile);
+ }
+
+ @Test
+ public void read() throws Exception
+ {
+ VMWareDisk disk = new VMWareDisk(diskFile);
+ disk.flush();
+ }
+
+ @Test
+ public void write() throws Exception
+ {
+ VMWareDisk disk = new VMWareDisk(diskFile);
+ disk.flush();
+ }
+
+ @Test
+ public void writeAndRead() throws Exception
+ {
+ Utils.DO_CLEAR = false;
+
+ LOG.info("BEGIN writeAndRead");
+ VMWareDisk disk = new VMWareDisk(diskFile);
+
+ // write
+ LOG.info("writeAndRead: writing...");
+ disk.flush();
+
+ // read
+ LOG.info("writeAndRead: reading...");
+ VMWareDisk disk2 = new VMWareDisk(diskFile);
+ Assert.assertEquals("disk has different size", disk.getLength(), disk2.getLength());
+ Assert.assertEquals("disk has different descriptor", disk.getDescriptor(), disk2.getDescriptor());
+ disk2.flush();
+ LOG.info("END writeAndRead");
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskCopier.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskCopier.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskCopier.java 2007-03-31 16:55:17 UTC (rev 3148)
@@ -0,0 +1,90 @@
+package org.jnode.apps.vmware.disk.tools;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.test.Utils;
+
+public class DiskCopier {
+ private static final Logger LOG = Logger.getLogger(Utils.class);
+
+ public static File copyDisk(final File mainFile, final File toDirectory)
+ throws IOException
+ {
+ final String name = mainFile.getName();
+ final int idx = name.lastIndexOf('.');
+ final String beginName = name.substring(0, idx);
+ final String endName = name.substring(idx);
+
+ final File parentDir = mainFile.getParentFile();
+ File[] files = parentDir.listFiles(new FilenameFilter()
+ {
+ public boolean accept(File dir, String name) {
+ boolean ok = name.startsWith(beginName) &&
+ name.endsWith(endName);
+ return ok;
+ }
+ });
+
+ File mainFileCopy = null;
+ for(File file : files)
+ {
+ File f = copyFile(file, toDirectory);
+ if(file.getName().equals(mainFile.getName()))
+ {
+ mainFileCopy = f;
+ }
+ }
+
+ return mainFileCopy;
+ }
+
+
+ public static File copyFile(File file, File dir) throws IOException
+ {
+ LOG.debug("copying file "+file.getName()+" to "+dir.getName());
+ FileInputStream fis = null;
+ FileOutputStream fos = null;
+ File outFile = null;
+
+ try
+ {
+ fis = new FileInputStream(file);
+ FileChannel inCh = fis.getChannel();
+
+ outFile = new File(dir, file.getName());
+ fos = new FileOutputStream(outFile);
+ FileChannel outCh = fos.getChannel();
+
+ outCh.transferFrom(inCh, 0, inCh.size());
+
+ return outFile;
+ }
+ catch(IOException ioe)
+ {
+ ioe.printStackTrace();
+ throw ioe;
+ }
+ finally
+ {
+ try {
+ if(fos != null)
+ {
+ fos.close();
+ }
+ }
+ finally
+ {
+ if(fis != null)
+ {
+ fis.close();
+ }
+ }
+ }
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskFactory.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/tools/DiskFactory.java 2007-03-31 16:55:17 UTC (rev 3148)
@@ -0,0 +1,42 @@
+package org.jnode.apps.vmware.disk.tools;
+
+import java.io.File;
+
+import org.jnode.apps.vmware.disk.handler.sparse.SparseDiskFactory;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+abstract public class DiskFactory
+{
+ private static final SparseDiskFactory SPARSE_FACTORY = new SparseDiskFactory();
+
+ public static File createSparseDisk(File directory, String name, long size)
+ {
+ return SPARSE_FACTORY.createDisk(directory, name, size);
+ }
+
+ public File createDisk(File directory, String name, long size)
+ {
+ if(!directory.isDirectory())
+ {
+ throw new IllegalArgumentException(directory.getAbsolutePath()+" is not a directory");
+ }
+ if(!directory.canWrite())
+ {
+ throw new IllegalArgumentException(directory.getAbsolutePath()+" must be writable");
+ }
+
+ File mainFile = new File(directory, name);
+ if(!createDiskImpl(mainFile, size))
+ {
+ mainFile = null;
+ }
+ return mainFile;
+ }
+
+ abstract protected boolean createDiskImpl(File mainFile, long size);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-03-31 16:51:38
|
Revision: 3147
http://jnode.svn.sourceforge.net/jnode/?rev=3147&view=rev
Author: fduminy
Date: 2007-03-31 09:51:34 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
new version with some refactoring, more tests ...
- working disk type detection
- working read/write of headers only
- read/write of sectors still buggy
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTableRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDescriptorRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDiskFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeaderRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentIO.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentRW.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/BaseTest.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestCreation.java
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTableRW.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTableRW.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTableRW.java 2007-03-31 16:51:34 UTC (rev 3147)
@@ -0,0 +1,95 @@
+package org.jnode.apps.vmware.disk.handler.sparse;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.nio.channels.FileChannel;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.jnode.apps.vmware.disk.handler.IOHandler;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+public class AllocationTableRW {
+ private static final Logger LOG = Logger.getLogger(SparseExtentRW.class);
+
+ public AllocationTable read(RandomAccessFile raf, SparseExtentHeader header)
+ throws IOException
+ {
+ long nbGrains = header.getCapacity() / header.getGrainSize();
+ int nbGrainTables = (int) (nbGrains / header.getNumGTEsPerGT());
+ LOG.debug("read: capacity="+header.getCapacity()+" grainSize="+header.getGrainSize()+
+ " NumGTEsPerGT="+header.getNumGTEsPerGT()+" => nbGrainTables="+nbGrainTables);
+
+ GrainDirectory grainDirectory = new GrainDirectory(readEntries(raf, nbGrainTables));
+ GrainTable[] grainTables = new GrainTable[nbGrainTables];
+ for(int i = 0 ; i < grainTables.length ; i++)
+ {
+ if(LOG.isDebugEnabled())
+ {
+ long pos = raf.getChannel().position();
+ if((pos % IOHandler.SECTOR_SIZE) != 0)
+ {
+ LOG.fatal("read: FATAL: pos not begin of a sector");
+ }
+
+ final long gtOffset = (pos / IOHandler.SECTOR_SIZE);
+ final long gde = grainDirectory.getEntry(i);
+ if(gde != gtOffset)
+ {
+ LOG.fatal("read: FATAL: grainTables["+i+"] (value:"+gtOffset+") doesn't match to GrainDirectoryEntry #"+i+ "(value:"+gde+")");
+ }
+
+ raf.getChannel().position(gde);
+ }
+
+ grainTables[i] = new GrainTable(readEntries(raf, header.getNumGTEsPerGT()));
+ }
+
+ return new AllocationTable(grainDirectory, grainTables);
+ }
+
+ public void write(FileChannel channel, AllocationTable table) throws IOException
+ {
+ write(channel, table.getGrainDirectory());
+ for(int gtNum = 0 ; gtNum < table.getNbGrainTables() ; gtNum++)
+ {
+ write(channel, table.getGrainTable(gtNum));
+ }
+ }
+
+ protected void write(FileChannel channel, EntryArray ea) throws IOException
+ {
+ ByteBuffer b = IOUtils.allocate(ea.getSize() * IOUtils.INT_SIZE);
+ IntBuffer ib = b.asIntBuffer();
+ for(int i = 0 ; i < ea.getSize() ; i++)
+ {
+ ib.put(ea.getEntry(i));
+ }
+ ib.rewind();
+ channel.write(b);
+ }
+
+ protected int[] readEntries(RandomAccessFile raf, int nbEntries) throws IOException
+ {
+ IntBuffer bb = IOUtils.getByteBuffer(raf, nbEntries * IOUtils.INT_SIZE).asIntBuffer();
+
+ int[] entries = new int[nbEntries];
+ for(int entryNumber = 0 ; entryNumber < nbEntries ; entryNumber++)
+ {
+ int entry = bb.get();
+ if(entry > 0)
+ {
+ LOG.debug("readEntries: entry["+entryNumber+"]="+entry);
+ }
+ entries[entryNumber] = entry;
+ }
+ return entries;
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDescriptorRW.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDescriptorRW.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDescriptorRW.java 2007-03-31 16:51:34 UTC (rev 3147)
@@ -0,0 +1,50 @@
+/**
+ *
+ */
+package org.jnode.apps.vmware.disk.handler.sparse;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.ExtentDeclaration;
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.jnode.apps.vmware.disk.descriptor.Descriptor;
+import org.jnode.apps.vmware.disk.descriptor.DescriptorRW;
+import org.jnode.apps.vmware.disk.extent.Extent;
+import org.jnode.apps.vmware.disk.handler.FileDescriptor;
+import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+final class SparseDescriptorRW extends DescriptorRW {
+ static final Logger LOG = Logger.getLogger(SparseDescriptorRW.class);
+
+ @Override
+ public SparseExtent createMainExtent(Descriptor desc, ExtentDeclaration extentDecl) throws IOException, UnsupportedFormatException
+ {
+ SparseExtentFactory factory = new SparseExtentFactory();
+
+ RandomAccessFile raf = new RandomAccessFile(extentDecl.getExtentFile(), "rw");
+ ByteBuffer bb = IOUtils.getByteBuffer(raf, 1024);
+
+ SparseExtentHeaderRW reader = new SparseExtentHeaderRW();
+ SparseExtentHeader header = reader.read(bb);
+ SparseFileDescriptor sfd = new SparseFileDescriptor(desc, raf, factory, header);
+ return createExtent(sfd, extentDecl);
+ }
+
+ @Override
+ public SparseExtent createExtent(FileDescriptor fileDescriptor,
+ ExtentDeclaration extentDecl)
+ throws IOException, UnsupportedFormatException
+ {
+ SparseFileDescriptor sfd = (SparseFileDescriptor) fileDescriptor;
+ return new SparseExtentRW().read(sfd.getRandomAccessFile().getChannel(), sfd, extentDecl);
+ }
+}
\ No newline at end of file
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDiskFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDiskFactory.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseDiskFactory.java 2007-03-31 16:51:34 UTC (rev 3147)
@@ -0,0 +1,20 @@
+package org.jnode.apps.vmware.disk.handler.sparse;
+
+import java.io.File;
+
+import org.jnode.apps.vmware.disk.tools.DiskFactory;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+public class SparseDiskFactory extends DiskFactory
+{
+ @Override
+ protected boolean createDiskImpl(File mainFile, long size)
+ {
+ return true;
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeaderRW.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeaderRW.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeaderRW.java 2007-03-31 16:51:34 UTC (rev 3147)
@@ -0,0 +1,178 @@
+package org.jnode.apps.vmware.disk.handler.sparse;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.Channel;
+import java.nio.channels.FileChannel;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+public class SparseExtentHeaderRW
+{
+ static final Logger LOG = Logger.getLogger(SparseExtentHeaderRW.class);
+
+ private static final byte singleEndLineChar = '\n';
+ private static final byte nonEndLineChar = ' ';
+ private static final byte doubleEndLineChar1 = '\r';
+ private static final byte doubleEndLineChar2 = '\n';
+
+ private static final int PAD_SIZE = 435;
+ private static final int MAGIC_NUMBER = 0x564d444b;
+ private static final int VERSION = 1;
+
+ private static final byte TRUE = (byte)1;
+ private static final byte FALSE = (byte)0;
+
+ private static final int numGTEsPerGT = 512;
+
+ public SparseExtentHeader read(ByteBuffer bb)
+ throws IOException, UnsupportedFormatException
+ {
+ //TODO optimise the size
+ //ByteBuffer bb = IOUtils.getByteBuffer(raf, 1024);
+
+ SparseExtentHeader header = new SparseExtentHeader();
+
+ int magicNum = bb.getInt();
+ LOG.debug("magicNum="+Long.toHexString(magicNum));
+ if(magicNum != MAGIC_NUMBER)
+ {
+ throw new UnsupportedFormatException("not the magic number");
+ }
+
+ int version = bb.getInt();
+ if(version != VERSION)
+ {
+ throw new IOException("bad version number (found:" + version + ")");
+ }
+
+ int flags = bb.getInt();
+ header.setValidNewLineDetectionTest((flags & 0x01) == 0x01); // bit 0
+ header.setRedundantGrainTableWillBeUsed((flags & 0x02) == 0x02); // bit 1
+
+ header.setCapacity(bb.getLong());
+ header.setGrainSize(bb.getLong());
+ header.setDescriptorOffset(bb.getLong());
+ header.setDescriptorSize(bb.getLong());
+
+ LOG.debug("read: offset(NumGTEsPerGT)="+bb.position());
+ int nb = bb.getInt();
+ if(nb != numGTEsPerGT)
+ {
+ throw new IOException("bad number of entries per grain table (found:" + nb + ")");
+ }
+ header.setNumGTEsPerGT(nb);
+
+ header.setRgdOffset(bb.getLong());
+
+ LOG.debug("read: offset(GdOffset)="+bb.position());
+ header.setGdOffset(bb.getLong());
+ header.setOverHead(bb.getLong());
+ header.setUncleanShutdown(bb.get() == TRUE);
+
+ LOG.debug("read: offset(singleEndLineChar)="+bb.position());
+ byte b = bb.get();
+ if(b != singleEndLineChar)
+ {
+ throw new IOException("file corrupted after a FTP (singleEndLineChar="+b+")");
+ }
+ b = bb.get();
+ if(b != nonEndLineChar)
+ {
+ throw new IOException("file corrupted after a FTP (nonEndLineChar="+b+")");
+ }
+ b = bb.get();
+ if(b != doubleEndLineChar1)
+ {
+ throw new IOException("file corrupted after a FTP (doubleEndLineChar1="+b+")");
+ }
+ b = bb.get();
+ if(b != doubleEndLineChar2)
+ {
+ throw new IOException("file corrupted after a FTP (doubleEndLineChar2="+b+")");
+ }
+
+ if(bb.remaining() < PAD_SIZE)
+ {
+ throw new UnsupportedFormatException("bad pad size (size="+bb.remaining()+")");
+ }
+
+ // additional/computed attributes
+ header.setGrainTableCoverage(header.getNumGTEsPerGT() * header.getGrainSize());
+
+ if(header.getGrainSize() <= 8)
+ {
+ throw new IOException("grainSize must be greater than 8 (actual:"+header.getGrainSize()+")");
+ }
+ if(!IOUtils.isPowerOf2(header.getGrainSize()))
+ {
+ throw new IOException("grainSize must be a power of 2 (actual:"+header.getGrainSize()+")");
+ }
+
+//TODO: according to the spec the following test shouldn't fail but **it is actually failing**
+// if((header.getCapacity() % header.getGrainSize()) != 0)
+// {
+// throw new IOException("capacity must be a multiple of grainSize (actual grainSize:"+header.getGrainSize()+", actual capacity="+header.getCapacity()+")");
+// }
+
+ LOG.debug("header="+header);
+
+ return header;
+ }
+
+ public void write(FileChannel channel, SparseExtentHeader header) throws IOException {
+ ByteBuffer bb = IOUtils.allocate(1024);
+ bb.putInt(MAGIC_NUMBER);
+ bb.putInt(VERSION);
+
+ int flags = 0;
+ if(header.isValidNewLineDetectionTest())
+ {
+ flags &= 0x01; // bit 0
+ }
+ if(header.isRedundantGrainTableWillBeUsed())
+ {
+ flags &= 0x02; // bit 1
+ }
+ bb.putInt(flags);
+
+ bb.putLong(header.getCapacity());
+ bb.putLong(header.getGrainSize());
+ bb.putLong(header.getDescriptorOffset());
+ bb.putLong(header.getDescriptorSize());
+
+ LOG.debug("write: offset(NumGTEsPerGT)="+bb.position());
+ bb.putInt(header.getNumGTEsPerGT());
+ bb.putLong(header.getRgdOffset());
+
+ LOG.debug("write: offset(GdOffset)="+bb.position());
+ bb.putLong(header.getGdOffset());
+ bb.putLong(header.getOverHead());
+ bb.put(header.isUncleanShutdown() ? TRUE : FALSE);
+
+ LOG.debug("write: offset(singleEndLineChar)="+bb.position());
+ bb.put(singleEndLineChar);
+ bb.put(nonEndLineChar);
+ bb.put(doubleEndLineChar1);
+ bb.put(doubleEndLineChar2);
+
+ for(int i = 0 ; i < PAD_SIZE ; i++)
+ {
+ bb.put((byte) 0);
+ }
+
+ bb.limit(bb.position());
+ bb.rewind();
+ LOG.debug("write: buffer="+bb);
+
+ channel.write(bb);
+ }
+}
\ No newline at end of file
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentIO.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentIO.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentIO.java 2007-03-31 16:51:34 UTC (rev 3147)
@@ -0,0 +1,75 @@
+package org.jnode.apps.vmware.disk.handler.sparse;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.extent.Extent;
+import org.jnode.apps.vmware.disk.handler.ExtentIO;
+import org.jnode.apps.vmware.disk.handler.IOHandler;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+public class SparseExtentIO extends ExtentIO {
+ private static final Logger LOG = Logger.getLogger(SparseExtentIO.class);
+
+ public SparseExtentIO(RandomAccessFile raf, Extent extent) {
+ super(raf, extent);
+ }
+
+ @Override
+ public void read(long sector, ByteBuffer dst) throws IOException {
+ SparseExtent spe = (SparseExtent) extent;
+
+ int oldLimit = dst.limit();
+ dst.limit((int) (dst.position() + IOHandler.SECTOR_SIZE));
+
+ int offset = spe.getOffset(sector, false, raf); // false: don't allocate
+ if(offset < 0)
+ {
+ // grain not yet allocated
+ // this is the vmware disk behavior : we don't allocate new grains on read
+ // we put zeros in the buffer
+ for(int i = 0 ; i < IOHandler.SECTOR_SIZE; i++)
+ {
+ dst.put((byte) 0);
+ }
+ }
+ else
+ {
+ LOG.debug("read: sector="+sector+" offset="+offset+" size="+dst.remaining());
+ channel.position(offset);
+ int read = channel.read(dst);
+ LOG.debug("read: nbRead="+read);
+ }
+
+ dst.limit(oldLimit);
+ }
+
+ @Override
+ public void write(long sector, ByteBuffer src) throws IOException
+ {
+ SparseExtent spe = (SparseExtent) extent;
+
+ // true: allocate if necessary
+ int offset = spe.getOffset(sector, true, raf);
+
+ LOG.debug("write: sector="+sector+" offset="+offset+" size="+src.remaining());
+ channel.position(offset);
+ channel.write(src);
+ }
+
+ @Override
+ public void flush() throws IOException {
+ SparseExtent spe = (SparseExtent) extent;
+
+ new SparseExtentRW().write(channel, spe);
+
+ super.flush();
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentRW.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentRW.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentRW.java 2007-03-31 16:51:34 UTC (rev 3147)
@@ -0,0 +1,61 @@
+package org.jnode.apps.vmware.disk.handler.sparse;
+
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.ExtentDeclaration;
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.jnode.apps.vmware.disk.descriptor.Descriptor;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+public class SparseExtentRW {
+ private static final Logger LOG = Logger.getLogger(SparseExtentRW.class);
+
+ private static final AllocationTableRW ALLOC_TABLE_RW = new AllocationTableRW();
+ private static final SparseExtentHeaderRW SPARSE_EXT_HEADER_RW = new SparseExtentHeaderRW();
+
+ public void write(FileChannel channel, SparseExtent extent) throws IOException {
+ channel.position(0L);
+ SPARSE_EXT_HEADER_RW.write(channel, extent.getHeader());
+
+ IOUtils.positionSector(channel, extent.getHeader().getRgdOffset());
+ LOG.debug("write: position(redundantAllocTable)="+channel.position());
+ ALLOC_TABLE_RW.write(channel, extent.getRedundantAllocationTable());
+
+ IOUtils.positionSector(channel, extent.getHeader().getGdOffset());
+ LOG.debug("write: position(allocTable)="+channel.position());
+ ALLOC_TABLE_RW.write(channel, extent.getAllocationTable());
+
+ LOG.debug("write: position="+channel.position());
+ }
+
+ public SparseExtent read(FileChannel channel,
+ SparseFileDescriptor fileDescriptor, ExtentDeclaration extentDecl)
+ throws IOException
+ {
+ LOG.debug("fileDescriptor="+fileDescriptor);
+ Descriptor descriptor = fileDescriptor.getDescriptor();
+
+ RandomAccessFile raf = fileDescriptor.getRandomAccessFile();
+ SparseExtentHeader header = fileDescriptor.getHeader();
+
+ IOUtils.positionSector(raf.getChannel(), header.getRgdOffset());
+ LOG.debug("read: position(redundantAllocTable)="+channel.position());
+ AllocationTable redundantAllocationTable = ALLOC_TABLE_RW.read(raf, header);
+
+ IOUtils.positionSector(raf.getChannel(), header.getGdOffset());
+ LOG.debug("read: position(allocTable)="+channel.position());
+ AllocationTable allocationTable = ALLOC_TABLE_RW.read(raf, header);
+
+ return new SparseExtent(descriptor, extentDecl,
+ header, redundantAllocationTable,
+ allocationTable);
+ }
+}
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/BaseTest.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/BaseTest.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/BaseTest.java 2007-03-31 16:51:34 UTC (rev 3147)
@@ -0,0 +1,44 @@
+package org.jnode.apps.vmware.disk.test;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.jnode.apps.vmware.disk.tools.DiskCopier;
+import org.junit.After;
+import org.junit.Before;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+abstract public class BaseTest {
+
+ protected final File originalDiskFile;
+ protected final boolean copyDisk;
+ protected File diskFile;
+
+ public BaseTest(File diskFile, boolean copyDisk) {
+ this.originalDiskFile = diskFile;
+ this.copyDisk = copyDisk;
+ }
+
+ @Before
+ public void setUp() throws IOException {
+ this.diskFile = copyDisk ? DiskCopier.copyDisk(originalDiskFile, Utils.createTempDir()) : originalDiskFile;
+ }
+
+ @After
+ public void tearDown() throws IOException {
+ Utils.clearTempDir(true);
+ Utils.DO_CLEAR = true;
+ }
+
+ @Override
+ public String toString() {
+ return diskFile.getName();
+ }
+
+}
\ No newline at end of file
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestCreation.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestCreation.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestCreation.java 2007-03-31 16:51:34 UTC (rev 3147)
@@ -0,0 +1,31 @@
+package org.jnode.apps.vmware.disk.test;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.junit.Test;
+
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+public class TestCreation extends BaseTest
+{
+ private static final Logger LOG = Logger.getLogger(TestCreation.class);
+
+ public TestCreation() throws IOException
+ {
+ super(Utils.createTempFile("create"), false);
+ }
+
+ @Test
+ public void createSparseDisk() throws Exception
+ {
+
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <fd...@us...> - 2007-03-31 16:18:52
|
Revision: 3146
http://jnode.svn.sourceforge.net/jnode/?rev=3146&view=rev
Author: fduminy
Date: 2007-03-31 09:18:50 -0700 (Sat, 31 Mar 2007)
Log Message:
-----------
new version with some refactoring, more tests ...
- working disk type detection
- working read/write of headers only
- read/write of sectors still buggy
Modified Paths:
--------------
trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/VMWareDisk.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentIO.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/IOHandler.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/UnsupportedFormatException.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleExtentFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/EntryArray.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainDirectory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainTable.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtent.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentFactory.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeader.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseIOHandler.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/Utils.java
Added Paths:
-----------
trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DescriptorRW.java
Removed Paths:
-------------
trunk/distr/src/apps/org/jnode/apps/vmware/disk/DescriptorReader.java
trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestVMWareDisk.java
Deleted: trunk/distr/src/apps/org/jnode/apps/vmware/disk/DescriptorReader.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/DescriptorReader.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/DescriptorReader.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -1,190 +0,0 @@
-package org.jnode.apps.vmware.disk;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import org.jnode.apps.vmware.disk.IOUtils.KeyValue;
-import org.jnode.apps.vmware.disk.descriptor.AdapterType;
-import org.jnode.apps.vmware.disk.descriptor.CreateType;
-import org.jnode.apps.vmware.disk.descriptor.Descriptor;
-import org.jnode.apps.vmware.disk.descriptor.DiskDatabase;
-import org.jnode.apps.vmware.disk.descriptor.Header;
-import org.jnode.apps.vmware.disk.extent.Access;
-import org.jnode.apps.vmware.disk.extent.Extent;
-import org.jnode.apps.vmware.disk.extent.ExtentType;
-import org.jnode.apps.vmware.disk.handler.ExtentFactory;
-import org.jnode.apps.vmware.disk.handler.FileDescriptor;
-import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
-import org.jnode.util.ByteBufferInputStream;
-
-/**
- * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
- *
- * @author Fabien DUMINY (fduminy at jnode dot org)
- *
- */
-public class DescriptorReader {
- private static final String VERSION = "version";
- private static final String CID = "CID";
- private static final String PARENT_CID = "parentCID";
- private static final String CREATE_TYPE = "createType";
-
- private static final String DDB = "ddb";
- private static final String ADAPTER_TYPE = "ddb.adapterType";
- private static final String SECTORS = "ddb.geometry.sectors";
- private static final String HEADS = "ddb.geometry.heads";
- private static final String CYLINDERS = "ddb.geometry.cylinders";
-
- //protected
-
- public Descriptor read(File file, ByteBuffer bb,
- ExtentFactory factory)
- throws IOException, UnsupportedFormatException
- {
- BufferedReader br = null;
-
- try {
-
- Reader r = new InputStreamReader(new ByteBufferInputStream(bb));
- br = new BufferedReader(r);
-
- Header header = readHeader(br);
-
- List<String> extentDecls = new ArrayList<String>();
- String lastLine = readExtents(br, factory, extentDecls);
- DiskDatabase diskDatabase = readDiskDatabase(br, lastLine);
-
- List<Extent> extents = new ArrayList<Extent>();
- boolean isMain = true;
- ExtentDeclaration mainExtentDecl = null;
- for(String decl : extentDecls)
- {
- ExtentDeclaration extentDecl = readExtentDeclaration(decl, file);
- if(isMain)
- {
- isMain = false;
- mainExtentDecl = extentDecl;
- }
- else
- {
- Extent extent = createExtent(factory, extentDecl);
- extents.add(extent);
- }
- }
-
- Descriptor desc = new Descriptor(file, header, extents, diskDatabase);
-
- Extent mainExtent = factory.createMainExtent(desc, mainExtentDecl);
- extents.add(0, mainExtent);
-
- return desc;
- }
- finally
- {
- if(br != null)
- {
- br.close();
- }
- }
- }
-
- protected DiskDatabase readDiskDatabase(BufferedReader br, String lastLine) throws IOException
- {
- DiskDatabase ddb = new DiskDatabase();
-
- Map<String, String> values = IOUtils.readValuesMap(lastLine, br, true,
- ADAPTER_TYPE, SECTORS, HEADS, CYLINDERS);
-
- String value = values.get(ADAPTER_TYPE);
- ddb.setAdapterType(AdapterType.valueOf(value));
-
- value = values.get(SECTORS);
- ddb.setSectors(Integer.valueOf(value));
-
- value = values.get(HEADS);
- ddb.setHeads(Integer.valueOf(value));
-
- value = values.get(CYLINDERS);
- ddb.setCylinders(Integer.valueOf(value));
-
- return ddb;
- }
-
- protected String readExtents(BufferedReader br,
- ExtentFactory factory,
- List<String> extentDecls)
- throws IOException, UnsupportedFormatException
- {
- String line;
-
- while(!(line = IOUtils.readLine(br)).startsWith(DDB))
- {
- extentDecls.add(line);
- }
-
- return line;
- }
-
- protected Extent createExtent(ExtentFactory factory, ExtentDeclaration extentDecl)
- throws IOException, UnsupportedFormatException
- {
- FileDescriptor fileDescriptor = IOUtils.readFileDescriptor(
- extentDecl.getExtentFile(), false);
-
- Extent extent = factory.createExtent(fileDescriptor, extentDecl);
-
- return extent;
- }
-
- protected ExtentDeclaration readExtentDeclaration(String line, File mainFile)
- {
- StringTokenizer st = new StringTokenizer(line, " ", false);
-
- final Access access = Access.valueOf(st.nextToken());
- final long sizeInSectors = Long.valueOf(st.nextToken());
- final ExtentType extentType = ExtentType.valueOf(st.nextToken());
-
- final String fileName = IOUtils.removeQuotes(st.nextToken());
-
- long offset = 0L;
- if(st.hasMoreTokens())
- {
- offset = Long.valueOf(st.nextToken());
- }
-
- final File extentFile = IOUtils.getExtentFile(mainFile, fileName);
- final boolean isMainExtent = extentFile.getName().equals(mainFile.getName());
- return new ExtentDeclaration(access, sizeInSectors, extentType, fileName, extentFile, offset, isMainExtent);
- }
-
- protected Header readHeader(BufferedReader reader) throws IOException, UnsupportedFormatException
- {
- Header header = new Header();
-
- KeyValue keyValue = IOUtils.readValue(reader, null, VERSION, false);
- if(!"1".equals(keyValue.getValue()))
- {
- throw new UnsupportedFormatException("expected version 1 (found:"+keyValue.getValue()+")");
- }
- header.setVersion(keyValue.getValue());
-
- keyValue = IOUtils.readValue(reader, keyValue, CID, false);
- header.setContentID(Long.valueOf(keyValue.getValue(), 16));
-
- keyValue = IOUtils.readValue(reader, keyValue, PARENT_CID, false);
- header.setParentContentID(Long.parseLong(keyValue.getValue(), 16));
-
- keyValue = IOUtils.readValue(reader, keyValue, CREATE_TYPE, true);
- header.setCreateType(CreateType.valueOf(keyValue.getValue()));
-
- return header;
- }
-}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -3,13 +3,18 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileChannel.MapMode;
import java.util.HashMap;
import java.util.Map;
import org.apache.log4j.Logger;
-import org.jnode.apps.vmware.disk.descriptor.AdapterType;
import org.jnode.apps.vmware.disk.handler.ExtentFactory;
import org.jnode.apps.vmware.disk.handler.FileDescriptor;
+import org.jnode.apps.vmware.disk.handler.IOHandler;
import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
import org.jnode.apps.vmware.disk.handler.simple.SimpleExtentFactory;
import org.jnode.apps.vmware.disk.handler.sparse.SparseExtentFactory;
@@ -21,7 +26,7 @@
*
*/
public class IOUtils {
- private static final Logger LOG = Logger.getLogger(SparseExtentFactory.class);
+ private static final Logger LOG = Logger.getLogger(IOUtils.class);
private static final String COMMENT = "#";
private static final String EQUAL = "=";
@@ -31,11 +36,15 @@
new SparseExtentFactory(),
new SimpleExtentFactory(),
};
+
+ public static final int INT_SIZE = 4;
+ public static final ByteOrder BYTE_ORDER = ByteOrder.LITTLE_ENDIAN;
public static class KeyValue
{
private String key;
private String value;
+
public String getKey() {
return key;
}
@@ -48,6 +57,20 @@
public void setValue(String value) {
this.value = value;
}
+
+ @Override
+ public String toString() {
+ return "KeyValue[key:"+key+", value:"+value+"]";
+ }
+ public void setNull() {
+ setKey(null);
+ setValue(null);
+ }
+
+ public boolean isNull()
+ {
+ return (key == null) && (value == null);
+ }
}
public static String readLine(BufferedReader reader) throws IOException
@@ -65,7 +88,7 @@
}
}
- //throw new IOException("no more lines");
+ LOG.debug("no more lines");
return null;
}
@@ -80,12 +103,20 @@
throws IOException
{
keyValue = readValue(readLine(reader), keyValue, wantedKey);
+ if(keyValue.isNull())
+ {
+ return keyValue;
+ }
if(wantedKey != null)
{
while(keyValue.getValue() == null)
{
keyValue = readValue(readLine(reader), keyValue, wantedKey);
+ if(keyValue.isNull())
+ {
+ return keyValue;
+ }
}
}
@@ -100,8 +131,7 @@
{
keyValue = (keyValue == null) ? new KeyValue() : keyValue;
- keyValue.setKey(null);
- keyValue.setValue(null);
+ keyValue.setNull();
if(line == null)
{
@@ -115,18 +145,22 @@
return keyValue;
}
+
keyValue.setKey(line.substring(0, idx).trim());
keyValue.setValue(line.substring(idx + 1).trim());
+ LOG.debug("readValue: line="+line+" idx="+idx+" -> KeyValue="+keyValue);
if((wantedKey != null) && !keyValue.getKey().equals(wantedKey))
{
+ LOG.debug("readValue: KeyValue="+keyValue);
+ LOG.fatal("************");
throw new IOException("excepted key("+wantedKey+") not found (actual:"+keyValue.getKey()+")");
}
return keyValue;
}
- public static FileDescriptor readFileDescriptor(File file, boolean isMain)
+ public static FileDescriptor readFileDescriptor(File file)
throws IOException, UnsupportedFormatException
{
FileDescriptor fileDescriptor = null;
@@ -135,7 +169,7 @@
{
try {
LOG.debug("trying with factory "+f.getClass().getName());
- FileDescriptor fd = f.createFileDescriptor(file, isMain);
+ FileDescriptor fd = f.createFileDescriptor(file);
// we have found the factory for that format
fileDescriptor = fd;
@@ -143,7 +177,7 @@
break;
} catch (UnsupportedFormatException e) {
// ignore, we will try with the next factory
- LOG.debug(f.getClass().getName()+":"+file+" not supported "+e.getMessage());
+ LOG.debug(f.getClass().getName()+":"+file+" not supported. reason: "+e.getMessage());
}
}
@@ -152,6 +186,8 @@
throw new UnsupportedFormatException("format not supported for file "+file);
}
+ LOG.info("descriptor for "+file.getName()+" is "+fileDescriptor.getClass().getName());
+
return fileDescriptor;
}
@@ -202,4 +238,70 @@
{
return (o1 == null) ? (o2 == null) : o1.equals(o2);
}
+
+ public static ByteBuffer allocate(int capacity)
+ {
+ ByteBuffer bb = ByteBuffer.allocate(capacity);
+ bb.order(BYTE_ORDER);
+ return bb;
+ }
+
+ public static ByteBuffer getSectorsByteBuffer(RandomAccessFile raf, int firstSector, int nbSectors) throws IOException
+ {
+ IOUtils.positionSector(raf.getChannel(), firstSector);
+ return IOUtils.getByteBuffer(raf, nbSectors * IOHandler.SECTOR_SIZE);
+ }
+
+ public static ByteBuffer getByteBuffer(RandomAccessFile raf, int size) throws IOException
+ {
+ FileChannel ch = raf.getChannel();
+
+// int capacity = Math.min(size, (int) (raf.length() - ch.position()));
+// if(capacity == 0)
+// {
+// throw new IOException("empty file");
+// }
+//
+ if((ch.position() + size) > ch.size())
+ {
+ //TODO fix the bug
+ LOG.fatal("getByteBuffer: FATAL: size too big. size="+size+" position="+ch.position()+" channel.size="+ch.size());
+ size = (int) (ch.size() - ch.position());
+ }
+
+ LOG.debug("getByteBuffer: pos="+ch.position()+" size="+size+" channel.size="+ch.size());
+ ByteBuffer bb = ch.map(MapMode.READ_ONLY, ch.position(), size);
+ bb.order(BYTE_ORDER);
+
+ if(LOG.isDebugEnabled())
+ {
+ LOG.debug("bb="+bb.toString()+" content="+bb.duplicate().asCharBuffer());
+ }
+
+ return bb;
+ }
+
+ public static void positionSector(FileChannel channel, long sector) throws IOException {
+ channel.position(sector * IOHandler.SECTOR_SIZE);
+ LOG.debug("positionSector(sector="+sector+") -> "+channel.position());
+ }
+
+ public static boolean isPowerOf2(long value) {
+ long val = 1;
+ if(val == value)
+ {
+ return true;
+ }
+
+ for(int i = 0 ; i < 64 ; i++)
+ {
+ val <<= 1;
+ if(val == value)
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/VMWareDisk.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/VMWareDisk.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/VMWareDisk.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -26,15 +26,18 @@
private final Descriptor descriptor;
private final IOHandler handler;
+ private final long length;
+
public VMWareDisk(File file) throws IOException, UnsupportedFormatException
{
- FileDescriptor fd = IOUtils.readFileDescriptor(file, true);
+ FileDescriptor fd = IOUtils.readFileDescriptor(file);
ExtentFactory factory = fd.getExtentFactory();
this.handler = factory.createIOHandler(fd);
this.descriptor = fd.getDescriptor();
+ this.length = handler.getNbSectors() * IOHandler.SECTOR_SIZE;
LOG.debug("handler for file "+file.getName()+" : "+handler.getClass().getName());
}
@@ -54,9 +57,7 @@
}
public long getLength() {
- DiskDatabase ddb = descriptor.getDiskDatabase();
- return ddb.getCylinders() * ddb.getHeads() * ddb.getSectors() *
- IOHandler.SECTOR_SIZE;
+ return length;
}
public Descriptor getDescriptor() {
Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DescriptorRW.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DescriptorRW.java (rev 0)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DescriptorRW.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -0,0 +1,197 @@
+package org.jnode.apps.vmware.disk.descriptor;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.RandomAccessFile;
+import java.io.Reader;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.channels.FileChannel.MapMode;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.ExtentDeclaration;
+import org.jnode.apps.vmware.disk.IOUtils;
+import org.jnode.apps.vmware.disk.IOUtils.KeyValue;
+import org.jnode.apps.vmware.disk.extent.Access;
+import org.jnode.apps.vmware.disk.extent.Extent;
+import org.jnode.apps.vmware.disk.extent.ExtentType;
+import org.jnode.apps.vmware.disk.handler.ExtentFactory;
+import org.jnode.apps.vmware.disk.handler.FileDescriptor;
+import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
+import org.jnode.apps.vmware.disk.handler.sparse.SparseExtentHeader;
+import org.jnode.util.ByteBufferInputStream;
+
+/**
+ * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
+ *
+ * @author Fabien DUMINY (fduminy at jnode dot org)
+ *
+ */
+abstract public class DescriptorRW {
+ private static final Logger LOG = Logger.getLogger(DescriptorRW.class);
+
+ private static final String VERSION = "version";
+ private static final String CID = "CID";
+ private static final String PARENT_CID = "parentCID";
+ private static final String CREATE_TYPE = "createType";
+
+ private static final String DDB = "ddb";
+ private static final String ADAPTER_TYPE = "ddb.adapterType";
+ private static final String SECTORS = "ddb.geometry.sectors";
+ private static final String HEADS = "ddb.geometry.heads";
+ private static final String CYLINDERS = "ddb.geometry.cylinders";
+
+ public Descriptor read(File file, int firstSector, int nbSectors)
+ throws IOException, UnsupportedFormatException
+ {
+ RandomAccessFile raf = null;
+ BufferedReader br = null;
+
+ try {
+ raf = new RandomAccessFile(file, "r");
+ ByteBuffer bb = IOUtils.getSectorsByteBuffer(raf, firstSector, nbSectors);
+
+ Reader r = new InputStreamReader(new ByteBufferInputStream(bb));
+ br = new BufferedReader(r);
+
+ Header header = readHeader(br);
+
+ List<String> extentDecls = new ArrayList<String>();
+ String lastLine = readExtents(br, extentDecls);
+ DiskDatabase diskDatabase = readDiskDatabase(br, lastLine);
+
+ List<Extent> extents = new ArrayList<Extent>(extentDecls.size());
+ ExtentDeclaration mainExtentDecl = null;
+ for(String decl : extentDecls)
+ {
+ ExtentDeclaration extentDecl = readExtentDeclaration(decl, file);
+ if(extentDecl.isMainExtent())
+ {
+ mainExtentDecl = extentDecl;
+ }
+ else
+ {
+ FileDescriptor fileDescriptor = IOUtils.readFileDescriptor(
+ extentDecl.getExtentFile());
+
+ Extent extent = createExtent(fileDescriptor, extentDecl);
+ extents.add(extent);
+ }
+ }
+
+ Descriptor desc = new Descriptor(file, header, extents, diskDatabase);
+
+ Extent mainExtent = createMainExtent(desc, mainExtentDecl);
+ extents.add(0, mainExtent);
+
+ return desc;
+ }
+ finally
+ {
+ if(br != null)
+ {
+ br.close();
+ }
+
+ if(raf != null)
+ {
+ raf.close();
+ }
+ }
+ }
+
+ protected DiskDatabase readDiskDatabase(BufferedReader br, String lastLine) throws IOException
+ {
+ DiskDatabase ddb = new DiskDatabase();
+
+ Map<String, String> values = IOUtils.readValuesMap(lastLine, br, true,
+ ADAPTER_TYPE, SECTORS, HEADS, CYLINDERS);
+
+ String value = values.get(ADAPTER_TYPE);
+ ddb.setAdapterType(AdapterType.valueOf(value));
+
+ value = values.get(SECTORS);
+ ddb.setSectors(Integer.valueOf(value));
+
+ value = values.get(HEADS);
+ ddb.setHeads(Integer.valueOf(value));
+
+ value = values.get(CYLINDERS);
+ ddb.setCylinders(Integer.valueOf(value));
+
+ return ddb;
+ }
+
+ protected String readExtents(BufferedReader br,
+ List<String> extentDecls)
+ throws IOException, UnsupportedFormatException
+ {
+ String line;
+
+ while( ((line = IOUtils.readLine(br)) != null) &&
+ !line.startsWith(DDB))
+ {
+ extentDecls.add(line);
+ }
+
+ return line;
+ }
+
+ protected ExtentDeclaration readExtentDeclaration(String line, File mainFile)
+ {
+ StringTokenizer st = new StringTokenizer(line, " ", false);
+
+ final Access access = Access.valueOf(st.nextToken());
+ final long sizeInSectors = Long.valueOf(st.nextToken());
+ final ExtentType extentType = ExtentType.valueOf(st.nextToken());
+
+ final String fileName = IOUtils.removeQuotes(st.nextToken());
+
+ long offset = 0L;
+ if(st.hasMoreTokens())
+ {
+ offset = Long.valueOf(st.nextToken());
+ }
+
+ final File extentFile = IOUtils.getExtentFile(mainFile, fileName);
+ final boolean isMainExtent = extentFile.getName().equals(mainFile.getName());
+ return new ExtentDeclaration(access, sizeInSectors, extentType, fileName, extentFile, offset, isMainExtent);
+ }
+
+ protected Header readHeader(BufferedReader reader) throws IOException, UnsupportedFormatException
+ {
+ Header header = new Header();
+
+ LOG.debug("trying to read VERSION");
+ KeyValue keyValue = IOUtils.readValue(reader, null, VERSION, false);
+ if(!"1".equals(keyValue.getValue()))
+ {
+ throw new UnsupportedFormatException("expected version 1 (found:"+keyValue.getValue()+")");
+ }
+ header.setVersion(keyValue.getValue());
+
+ keyValue = IOUtils.readValue(reader, keyValue, CID, false);
+ header.setContentID(Long.valueOf(keyValue.getValue(), 16));
+
+ keyValue = IOUtils.readValue(reader, keyValue, PARENT_CID, false);
+ header.setParentContentID(Long.parseLong(keyValue.getValue(), 16));
+
+ keyValue = IOUtils.readValue(reader, keyValue, CREATE_TYPE, true);
+ header.setCreateType(CreateType.valueOf(keyValue.getValue()));
+
+ return header;
+ }
+
+ abstract protected Extent createMainExtent(Descriptor desc,
+ ExtentDeclaration mainExtentDecl) throws IOException, UnsupportedFormatException;
+
+ abstract protected Extent createExtent(FileDescriptor fileDescriptor, ExtentDeclaration extentDecl)
+ throws IOException, UnsupportedFormatException;
+
+}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentFactory.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentFactory.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -5,11 +5,13 @@
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
+import java.nio.channels.FileChannel.MapMode;
import org.apache.log4j.Logger;
-import org.jnode.apps.vmware.disk.DescriptorReader;
import org.jnode.apps.vmware.disk.ExtentDeclaration;
+import org.jnode.apps.vmware.disk.IOUtils;
import org.jnode.apps.vmware.disk.descriptor.Descriptor;
+import org.jnode.apps.vmware.disk.descriptor.DescriptorRW;
import org.jnode.apps.vmware.disk.extent.Extent;
import org.jnode.apps.vmware.disk.handler.sparse.SparseExtentFactory;
@@ -22,21 +24,17 @@
abstract public class ExtentFactory
{
private static final Logger LOG = Logger.getLogger(SparseExtentFactory.class);
-
- protected static final DescriptorReader READER = new DescriptorReader();
-
- public FileDescriptor createFileDescriptor(File file, boolean isMain)
+
+ public FileDescriptor createFileDescriptor(File file)
throws IOException, UnsupportedFormatException
{
RandomAccessFile raf = null;
FileDescriptor fileDescriptor = null;
- ByteBuffer bb = null;
-
+
try {
raf = new RandomAccessFile(file, "rw");
- bb = readHeaderForDiskType(raf);
- fileDescriptor = createFileDescriptor(file, raf, bb, isMain);
+ fileDescriptor = createFileDescriptor(file, raf);
}
finally
{
@@ -46,45 +44,18 @@
// been created, then close it
raf.close();
}
- else if((bb != null) && (raf != null))
- {
- // synchronize the RandomAccessFile with what
- // has been actually read in the ByteBuffer
- raf.seek(bb.position());
- }
}
return fileDescriptor;
}
- protected ByteBuffer readHeaderForDiskType(RandomAccessFile raf) throws IOException
- {
- //TODO optimise the size
- int capacity = Math.min(1024, (int) raf.length());
- if(capacity == 0)
- {
- throw new IOException("empty file");
- }
-
- ByteBuffer bb = ByteBuffer.allocate(capacity);
- bb.order(ByteOrder.LITTLE_ENDIAN);
- raf.getChannel().read(bb);
- bb.rewind();
- LOG.debug("bb="+bb.toString());
- return bb;
- }
+ abstract protected DescriptorRW getDescriptorRW();
abstract protected FileDescriptor createFileDescriptor(File file,
- RandomAccessFile raf, ByteBuffer bb,
- boolean isMain)
+ RandomAccessFile raf)
throws IOException, UnsupportedFormatException;
- abstract public Extent createExtent(FileDescriptor fileDescriptor, ExtentDeclaration extentDecl)
- throws IOException, UnsupportedFormatException;
-
- abstract public Extent createMainExtent(Descriptor desc, ExtentDeclaration extentDecl) throws IOException, UnsupportedFormatException;
-
abstract public IOHandler createIOHandler(FileDescriptor fileDescriptor)
throws IOException, UnsupportedFormatException;
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentIO.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentIO.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentIO.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -6,6 +6,7 @@
import java.nio.channels.FileChannel;
import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.extent.Extent;
import org.jnode.apps.vmware.disk.handler.sparse.SparseExtentFactory;
/**
@@ -18,13 +19,15 @@
{
private static final Logger LOG = Logger.getLogger(ExtentIO.class);
- private final RandomAccessFile raf;
- private final FileChannel channel;
+ protected final RandomAccessFile raf;
+ protected final FileChannel channel;
+ protected final Extent extent;
- public ExtentIO(RandomAccessFile raf)
+ public ExtentIO(RandomAccessFile raf, Extent extent)
{
this.raf = raf;
- this.channel = raf.getChannel();
+ this.channel = raf.getChannel();
+ this.extent = extent;
}
public void read(long sector, ByteBuffer dst) throws IOException
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/IOHandler.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/IOHandler.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/IOHandler.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -8,6 +8,7 @@
import org.apache.log4j.Logger;
import org.jnode.apps.vmware.disk.descriptor.Descriptor;
+import org.jnode.apps.vmware.disk.descriptor.DescriptorRW;
import org.jnode.apps.vmware.disk.descriptor.DiskDatabase;
import org.jnode.apps.vmware.disk.extent.Extent;
@@ -22,6 +23,9 @@
public static final int SECTOR_SIZE = 512;
+ protected static final boolean READ = true;
+ protected static final boolean WRITE = false;
+
final protected Descriptor descriptor;
final private long nbSectors;
@@ -83,9 +87,9 @@
}
}
- protected ExtentIO getExtentIO(long sector) throws IOException
+ protected ExtentIO getExtentIO(long sector, boolean mode) throws IOException
{
- Extent extent = getExtent(sector);
+ Extent extent = getExtent(sector, mode);
return getExtentIO(extent);
}
@@ -97,19 +101,24 @@
{
RandomAccessFile raf = new RandomAccessFile(extent.getFile(), "rw");
LOG.debug("length for file "+extent.getFileName()+" : "+raf.length());
- io = new ExtentIO(raf);
+ io = createExtentIO(raf, extent);
extentIOCache.put(extent, io);
}
return io;
}
- protected Extent getExtent(long sector) throws IOException
+ protected ExtentIO createExtentIO(RandomAccessFile raf, Extent extent)
{
+ return new ExtentIO(raf, extent);
+ }
+
+ protected Extent getExtent(long sector, boolean mode) throws IOException
+ {
Extent handler = null;
for(Extent extent : descriptor.getExtents())
{
- LOG.debug(extent.getFileName()+": SizeInSectors="+extent.getSizeInSectors());
+ //LOG.debug(extent.getFileName()+": SizeInSectors="+extent.getSizeInSectors());
if(sector < extent.getSizeInSectors())
{
@@ -123,18 +132,34 @@
}
public void readImpl(long sector, int nbSectors, ByteBuffer dst)
- throws IOException {
- for(int i = 0 ; i < nbSectors ; i++, sector++)
- {
- getExtentIO(sector).read(sector, dst);
- }
- }
+ throws IOException
+ {
+ LOG.debug("readImpl: sector="+sector+" nbSectors="+nbSectors+
+ " buffer.remaining="+dst.remaining());
+ for(int i = 0 ; i < nbSectors ; i++, sector++)
+ {
+ final ExtentIO io = getExtentIO(sector, READ);
+ dst.limit(dst.position() + SECTOR_SIZE);
+ io.read(sector, dst);
+ }
+ }
public void writeImpl(long sector, int nbSectors, ByteBuffer src)
- throws IOException {
- for(int i = 0 ; i < nbSectors ; i++, sector++)
- {
- getExtentIO(sector).write(sector, src);
- }
- }
+ throws IOException
+ {
+ LOG.debug("writeImpl: sector="+sector+" nbSectors="+nbSectors+
+ " buffer.remaining="+src.remaining());
+ for(int i = 0 ; i < nbSectors ; i++, sector++)
+ {
+ final ExtentIO io = getExtentIO(sector, WRITE);
+ src.limit(src.position() + SECTOR_SIZE);
+ io.write(sector, src);
+ }
+ }
+
+ public long getNbSectors() {
+ return nbSectors;
+ }
+
+
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/UnsupportedFormatException.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/UnsupportedFormatException.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/UnsupportedFormatException.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -1,19 +1,22 @@
package org.jnode.apps.vmware.disk.handler;
+import java.io.IOException;
+
/**
* Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
*
* @author Fabien DUMINY (fduminy at jnode dot org)
*
*/
-public class UnsupportedFormatException extends Exception {
+public class UnsupportedFormatException extends IOException {
public UnsupportedFormatException() {
super();
}
public UnsupportedFormatException(String s, Throwable cause) {
- super(s, cause);
+ super(s);
+ initCause(cause);
}
public UnsupportedFormatException(String s) {
@@ -21,7 +24,8 @@
}
public UnsupportedFormatException(Throwable cause) {
- super(cause);
+ super();
+ initCause(cause);
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleExtentFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleExtentFactory.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleExtentFactory.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -6,7 +6,9 @@
import java.nio.ByteBuffer;
import org.jnode.apps.vmware.disk.ExtentDeclaration;
+import org.jnode.apps.vmware.disk.IOUtils;
import org.jnode.apps.vmware.disk.descriptor.Descriptor;
+import org.jnode.apps.vmware.disk.descriptor.DescriptorRW;
import org.jnode.apps.vmware.disk.extent.Extent;
import org.jnode.apps.vmware.disk.handler.ExtentFactory;
import org.jnode.apps.vmware.disk.handler.FileDescriptor;
@@ -22,28 +24,21 @@
public class SimpleExtentFactory extends ExtentFactory
{
protected FileDescriptor createFileDescriptor(File file,
- RandomAccessFile raf, ByteBuffer bb,
- boolean isMain)
+ RandomAccessFile raf)
throws IOException, UnsupportedFormatException
{
- Descriptor descriptor = READER.read(file, bb, this);
+ // read 2 sectors, starting from sector number 0
+ Descriptor descriptor = getDescriptorRW().read(file, 0, 2);
+
return new FileDescriptor(descriptor, raf, this);
}
- public Extent createMainExtent(Descriptor desc, ExtentDeclaration extentDecl)
- {
- return new Extent(desc, extentDecl);
+ public SimpleIOHandler createIOHandler(FileDescriptor fileDescriptor) throws IOException, UnsupportedFormatException {
+ return new SimpleIOHandler(fileDescriptor);
}
-
- public Extent createExtent(FileDescriptor fileDescriptor, ExtentDeclaration extentDecl)
- throws IOException, UnsupportedFormatException
- {
- Descriptor desc = (fileDescriptor == null) ? null :
- fileDescriptor.getDescriptor();
- return createMainExtent(desc, extentDecl);
- }
- public IOHandler createIOHandler(FileDescriptor fileDescriptor) throws IOException, UnsupportedFormatException {
- return new SimpleIOHandler(fileDescriptor);
+ @Override
+ protected SimpleDescriptorRW getDescriptorRW() {
+ return new SimpleDescriptorRW();
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -1,8 +1,10 @@
package org.jnode.apps.vmware.disk.handler.sparse;
import java.io.IOException;
-import java.io.RandomAccessFile;
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.test.readwrite.TestVMWareDisk;
+
/**
* Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
*
@@ -10,32 +12,18 @@
*
*/
public class AllocationTable {
+ private static final Logger LOG = Logger.getLogger(TestVMWareDisk.class);
+
private final GrainDirectory grainDirectory;
private final GrainTable[] grainTables;
- public AllocationTable(RandomAccessFile raf, SparseExtentHeader header)
+ public AllocationTable(GrainDirectory grainDirectory, GrainTable[] grainTables)
throws IOException
{
- long nbGrains = header.getCapacity() / header.getGrainSize();
- int nbGrainTables = (int) (nbGrains / header.getNumGTEsPerGT());
-
- grainDirectory = new GrainDirectory(raf, nbGrainTables);
- grainTables = new GrainTable[nbGrainTables];
- for(int i = 0 ; i < grainTables.length ; i++)
- {
- grainTables[i] = new GrainTable(raf, header.getNumGTEsPerGT());
- }
- }
-
- public void write(RandomAccessFile raf) throws IOException
- {
- grainDirectory.write(raf);
- for(GrainTable gt : grainTables)
- {
- gt.write(raf);
- }
+ this.grainDirectory = grainDirectory;
+ this.grainTables = grainTables;
}
-
+
public GrainDirectory getGrainDirectory() {
return grainDirectory;
}
@@ -47,6 +35,12 @@
public GrainTable getGrainTable(int tableNum)
{
+ if((tableNum < 0) || (tableNum >= grainTables.length))
+ {
+ //TODO fix the bug
+ LOG.fatal("getGrainTable: FATAL: index out of bounds, actual="+tableNum+", max="+(grainTables.length-1)+", using max");
+ tableNum = (grainTables.length - 1);
+ }
return grainTables[tableNum];
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/EntryArray.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/EntryArray.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/EntryArray.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -2,7 +2,13 @@
import java.io.IOException;
import java.io.RandomAccessFile;
+import java.nio.ByteBuffer;
+import java.nio.IntBuffer;
+import java.nio.channels.FileChannel;
+import org.apache.log4j.Logger;
+import org.jnode.apps.vmware.disk.IOUtils;
+
/**
* Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
*
@@ -11,26 +17,15 @@
*/
public class EntryArray
{
+ private static final Logger LOG = Logger.getLogger(EntryArray.class);
+
final private int[] entries;
- public EntryArray(RandomAccessFile raf, int nbEntries)
- throws IOException
+ public EntryArray(int[] entries)
{
- entries = new int[nbEntries];
- for(int entryNumber = 0 ; entryNumber < nbEntries ; entryNumber++)
- {
- setEntry(entryNumber, raf.readInt());
- }
+ this.entries = entries;
}
- public void write(RandomAccessFile raf) throws IOException
- {
- for(int entry : entries)
- {
- raf.writeInt(entry);
- }
- }
-
public int getSize()
{
return entries.length;
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainDirectory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainDirectory.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainDirectory.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -11,8 +11,8 @@
*/
public class GrainDirectory extends EntryArray
{
- public GrainDirectory(RandomAccessFile raf, int nbEntries) throws IOException
+ public GrainDirectory(int[] entries)
{
- super(raf, nbEntries);
+ super(entries);
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainTable.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainTable.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainTable.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -11,8 +11,8 @@
*/
public class GrainTable extends EntryArray
{
- public GrainTable(RandomAccessFile raf, int nbEntries) throws IOException
+ public GrainTable(int[] entries)
{
- super(raf, nbEntries);
+ super(entries);
}
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtent.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtent.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtent.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -1,8 +1,14 @@
package org.jnode.apps.vmware.disk.handler.sparse;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+
+import org.apache.log4j.Logger;
import org.jnode.apps.vmware.disk.ExtentDeclaration;
import org.jnode.apps.vmware.disk.descriptor.Descriptor;
import org.jnode.apps.vmware.disk.extent.Extent;
+import org.jnode.apps.vmware.disk.handler.IOHandler;
/**
* Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
@@ -12,6 +18,8 @@
*/
public class SparseExtent extends Extent
{
+ private static final Logger LOG = Logger.getLogger(SparseExtent.class);
+
private final SparseExtentHeader header;
private final AllocationTable redundantAllocationTable;
private final AllocationTable allocationTable;
@@ -27,15 +35,53 @@
this.redundantAllocationTable = redundantAllocationTable;
this.allocationTable = allocationTable;
}
+
+ protected int getOffset(long sector, boolean allocate, RandomAccessFile raf) throws IOException
+ {
+ final long grainTableCoverage = header.getGrainTableCoverage();
+ final int grainDirNum = (int) Math.floor(sector / grainTableCoverage);
+ final int grainDirEntry = allocationTable.getGrainDirectory().getEntry(grainDirNum);
+
+ LOG.debug("getGrainTableEntry: grainTableCoverage="+grainTableCoverage+" grainDirNum="+grainDirNum+" grainDirEntry="+grainDirEntry+" nbGrainTables="+allocationTable.getNbGrainTables());
+
+ GrainTable grainTable = allocationTable.getGrainTable(grainDirEntry);
+ final int grainTableNum = (int) Math.floor((sector % grainTableCoverage) / header.getGrainSize());
+ int grainTableEntry = grainTable.getEntry(grainTableNum);
+
+ LOG.debug("getGrainTableEntry: grainTableNum="+grainTableNum+" grainTableEntry="+grainTableEntry);
+
+ if(allocate && (grainTableEntry == 0))
+ {
+ long offset = raf.length();
+ raf.setLength(offset + header.getGrainSize() * IOHandler.SECTOR_SIZE);
+ LOG.debug("getGrainTableEntry: resized file "+getFileName()+" to "+raf.length());
+
+ grainTableEntry = (int) (offset / IOHandler.SECTOR_SIZE);
+ grainTable.setEntry(grainTableNum, grainTableEntry);
+
+ // also modify the redundant table
+ grainTable = redundantAllocationTable.getGrainTable(grainDirEntry);
+ grainTable.setEntry(grainTableNum, grainTableEntry);
+ }
-/* TODO implement it later
- public void write() throws IOException {
- raf.seek(0L);
- header.write(raf);
- redundantAllocationTable.write(raf);
- allocationTable.write(raf);
+ int grainOffset = grainTableEntry * IOHandler.SECTOR_SIZE;
+ return grainOffset;
}
-*/
+
+
+
+ public SparseExtentHeader getHeader() {
+ return header;
+ }
+
+ public AllocationTable getRedundantAllocationTable() {
+ return redundantAllocationTable;
+ }
+
+ public AllocationTable getAllocationTable() {
+ return allocationTable;
+ }
+
@Override
public String toString() {
return "SparseExtent["+getFileName()+"]";
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentFactory.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentFactory.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentFactory.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -1,19 +1,16 @@
package org.jnode.apps.vmware.disk.handler.sparse;
import java.io.File;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
-import java.util.List;
import org.apache.log4j.Logger;
-import org.jnode.apps.vmware.disk.ExtentDeclaration;
+import org.jnode.apps.vmware.disk.IOUtils;
import org.jnode.apps.vmware.disk.descriptor.Descriptor;
-import org.jnode.apps.vmware.disk.extent.Extent;
+import org.jnode.apps.vmware.disk.descriptor.DiskDatabase;
import org.jnode.apps.vmware.disk.handler.ExtentFactory;
import org.jnode.apps.vmware.disk.handler.FileDescriptor;
-import org.jnode.apps.vmware.disk.handler.IOHandler;
import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
/**
@@ -22,21 +19,25 @@
* @author Fabien DUMINY (fduminy at jnode dot org)
*
*/
-public class SparseExtentFactory extends ExtentFactory
+public class SparseExtentFactory extends ExtentFactory
{
private static final Logger LOG = Logger.getLogger(SparseExtentFactory.class);
- protected FileDescriptor createFileDescriptor(File file,
- RandomAccessFile raf, ByteBuffer bb,
- boolean isMain)
+ protected SparseFileDescriptor createFileDescriptor(File file,
+ RandomAccessFile raf)
throws IOException, UnsupportedFormatException
{
- SparseExtentHeader header = SparseExtentHeader.read(bb);
+ ByteBuffer bb = IOUtils.getByteBuffer(raf, 1024);
+
+ SparseExtentHeaderRW reader = new SparseExtentHeaderRW();
+ SparseExtentHeader header = reader.read(bb);
Descriptor embeddedDescriptor;
if (header.getDescriptorOffset() != 0) {
- LOG.debug("isMain="+isMain);
- //embeddedDescriptor = isMain ? null : READER.read(file, bb, this);
- embeddedDescriptor = READER.read(file, bb, this);
+ embeddedDescriptor = getDescriptorRW().read(file, (int) header.getDescriptorOffset(), (int) header.getDescriptorSize());
+
+ DiskDatabase ddb = embeddedDescriptor.getDiskDatabase();
+ long nbSectors = ddb.getCylinders() * ddb.getHeads() * ddb.getSectors();
+ LOG.debug("createFileDescriptor: capacity="+header.getCapacity()+" nbSectors="+nbSectors);
} else {
LOG.debug("embeddedDescriptor = null");
embeddedDescriptor = null;
@@ -44,45 +45,20 @@
return new SparseFileDescriptor(embeddedDescriptor, raf, this, header);
}
- public Extent createMainExtent(Descriptor desc, ExtentDeclaration extentDecl) throws IOException, UnsupportedFormatException
+ public SparseIOHandler createIOHandler(FileDescriptor fileDescriptor) throws IOException
{
- RandomAccessFile raf = new RandomAccessFile(extentDecl.getExtentFile(), "rw");
- ByteBuffer bb = readHeaderForDiskType(raf);
-
- SparseExtentHeader header = SparseExtentHeader.read(bb);
- SparseFileDescriptor sfd = new SparseFileDescriptor(desc, raf, this, header);
- return createExtent(sfd, extentDecl);
- }
-
- public SparseExtent createExtent(FileDescriptor fileDescriptor,
- ExtentDeclaration extentDecl)
- throws IOException, UnsupportedFormatException
- {
SparseFileDescriptor sfd = (SparseFileDescriptor) fileDescriptor;
- LOG.debug("fileDescriptor="+fileDescriptor);
- Descriptor descriptor = (fileDescriptor == null) ? null :
- fileDescriptor.getDescriptor();
-
- RandomAccessFile raf = fileDescriptor.getRandomAccessFile();
- SparseExtentHeader header = sfd.getHeader();
-
- AllocationTable redundantAllocationTable = new AllocationTable(raf, header);
- AllocationTable allocationTable = new AllocationTable(raf, header);
-
- return new SparseExtent(descriptor, extentDecl,
- header, redundantAllocationTable,
- allocationTable);
- }
+ SparseIOHandler handler = null;
- public IOHandler createIOHandler(FileDescriptor fileDescriptor) throws IOException
- {
- SparseFileDescriptor sfd = (SparseFileDescriptor) fileDescriptor;
- IOHandler handler = null;
-
Descriptor desc = sfd.getDescriptor();
handler = new SparseIOHandler(desc);
return handler;
}
+
+ @Override
+ protected SparseDescriptorRW getDescriptorRW() {
+ return new SparseDescriptorRW();
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeader.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeader.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeader.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -1,9 +1,5 @@
package org.jnode.apps.vmware.disk.handler.sparse;
-import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
import org.apache.log4j.Logger;
import org.jnode.apps.vmware.disk.handler.UnsupportedFormatException;
@@ -16,11 +12,8 @@
*/
public class SparseExtentHeader
{
- private static final Logger LOG = Logger.getLogger(SparseExtentFactory.class);
+ static final Logger LOG = Logger.getLogger(SparseExtentHeader.class);
- private static final int MAGIC_NUMBER = 0x564d444b; // 'V','M', 'D', 'K'
- private static final int VERSION = 1;
-
// flags
private boolean validNewLineDetectionTest;
private boolean redundantGrainTableWillBeUsed;
@@ -31,124 +24,15 @@
private long descriptorSize;
private long rgdOffset;
- private static final int numGTEsPerGT = 512;
+ // additional/computed fields
+ private long grainTableCoverage;
+ private int numGTEsPerGT = 512;
+
private long gdOffset;
private long overHead;
private boolean uncleanShutdown;
- private static final byte singleEndLineChar = '\n';
- private static final byte nonEndLineChar = ' ';
- private static final byte doubleEndLineChar1 = '\r';
- private static final byte doubleEndLineChar2 = '\n';
-
- private static final int PAD_SIZE = 435;
-
- public static boolean readMagicNumber(ByteBuffer bb) throws IOException
- {
- int magicNum = bb.getInt();
- LOG.debug("magicNum="+Long.toHexString(magicNum));
- return (magicNum == MAGIC_NUMBER);
- }
-
- public static SparseExtentHeader read(ByteBuffer bb)
- throws IOException, UnsupportedFormatException
- {
- SparseExtentHeader header = new SparseExtentHeader();
-
- if(!readMagicNumber(bb))
- {
- throw new UnsupportedFormatException("not the magic number");
- }
-
- int version = bb.getInt();
- if(version != VERSION)
- {
- throw new IOException("bad version number (found:" + version + ")");
- }
-
- int flags = bb.getInt();
- header.validNewLineDetectionTest = ((flags & 0x01) == 0x01); // bit 0
- header.redundantGrainTableWillBeUsed = ((flags & 0x02) == 0x02); // bit 1
-
- header.capacity = bb.getLong();
- header.grainSize = bb.getLong();
- header.descriptorOffset = bb.getLong();
- header.descriptorSize = bb.getLong();
-
- int nb = bb.getInt();
- if(nb != numGTEsPerGT)
- {
- throw new IOException("bad number of entries per grain table (found:" + nb + ")");
- }
-
- header.rgdOffset = bb.getLong();
- header.gdOffset = bb.getLong();
- header.overHead = bb.getLong();
- header.uncleanShutdown = (bb.get() != 0);
-
- if(bb.get() != singleEndLineChar)
- {
- throw new IOException("file corrupted after a FTP");
- }
- if(bb.get() != nonEndLineChar)
- {
- throw new IOException("file corrupted after a FTP");
- }
- if(bb.get() != doubleEndLineChar1)
- {
- throw new IOException("file corrupted after a FTP");
- }
- if(bb.get() != doubleEndLineChar2)
- {
- throw new IOException("file corrupted after a FTP");
- }
-
- if(bb.remaining() < PAD_SIZE)
- {
- throw new UnsupportedFormatException("bad pad size");
- }
-
- return header;
- }
-
- public void write(RandomAccessFile raf) throws IOException
- {
- raf.seek(0L);
- raf.writeInt(MAGIC_NUMBER);
- raf.writeInt(VERSION);
-
- int flags = 0;
- if(validNewLineDetectionTest)
- {
- flags &= 0x01; // bit 0
- }
- if(redundantGrainTableWillBeUsed)
- {
- flags &= 0x02; // bit 1
- }
- raf.writeInt(flags);
-
- raf.writeLong(capacity);
- raf.writeLong(grainSize);
- raf.writeLong(descriptorOffset);
- raf.writeLong(descriptorSize);
- raf.writeInt(numGTEsPerGT);
- raf.writeLong(rgdOffset);
- raf.writeLong(gdOffset);
- raf.writeLong(overHead);
- raf.writeBoolean(uncleanShutdown);
- raf.writeByte(singleEndLineChar);
- raf.writeByte(nonEndLineChar);
- raf.writeByte(doubleEndLineChar1);
- raf.writeByte(doubleEndLineChar2);
-
- for(int i = 0 ; i < PAD_SIZE ; i++)
- {
- raf.writeByte(0);
- }
- }
-
public int getNumGTEsPerGT() {
return numGTEsPerGT;
}
@@ -156,6 +40,15 @@
public long getCapacity() {
return capacity;
}
+
+ /**
+ *
+ * @return gtCoverage (grain table coverage) in sectors
+ */
+ public long getGrainTableCoverage()
+ {
+ return grainTableCoverage;
+ }
public long getGrainSize() {
return grainSize;
@@ -165,4 +58,101 @@
{
return descriptorOffset;
}
+
+ public boolean isValidNewLineDetectionTest() {
+ return validNewLineDetectionTest;
+ }
+
+ public void setValidNewLineDetectionTest(boolean validNewLineDetectionTest) {
+ this.validNewLineDetectionTest = validNewLineDetectionTest;
+ }
+
+ public boolean isRedundantGrainTableWillBeUsed() {
+ return redundantGrainTableWillBeUsed;
+ }
+
+ public void setRedundantGrainTableWillBeUsed(
+ boolean redundantGrainTableWillBeUsed) {
+ this.redundantGrainTableWillBeUsed = redundantGrainTableWillBeUsed;
+ }
+
+ public long getDescriptorSize() {
+ return descriptorSize;
+ }
+
+ public void setDescriptorSize(long descriptorSize) {
+ this.descriptorSize = descriptorSize;
+ }
+
+ public long getRgdOffset() {
+ return rgdOffset;
+ }
+
+ public void setRgdOffset(long rgdOffset) {
+ this.rgdOffset = rgdOffset;
+ }
+
+ public long getGdOffset() {
+ return gdOffset;
+ }
+
+ public void setGdOffset(long gdOffset) {
+ this.gdOffset = gdOffset;
+ }
+
+ public long getOverHead() {
+ return overHead;
+ }
+
+ public void setOverHead(long overHead) {
+ this.overHead = overHead;
+ }
+
+ public boolean isUncleanShutdown() {
+ return uncleanShutdown;
+ }
+
+ public void setUncleanShutdown(boolean uncleanShutdown) {
+ this.uncleanShutdown = uncleanShutdown;
+ }
+
+ public void setCapacity(long capacity) {
+ this.capacity = capacity;
+ }
+
+ public void setGrainSize(long grainSize) {
+ this.grainSize = grainSize;
+ }
+
+ public void setDescriptorOffset(long descriptorOffset) {
+ this.descriptorOffset = descriptorOffset;
+ }
+
+ public void setGrainTableCoverage(long grainTableCoverage) {
+ this.grainTableCoverage = grainTableCoverage;
+ }
+
+ public void setNumGTEsPerGT(int numGTEsPerGT) {
+ this.numGTEsPerGT = numGTEsPerGT;
+ }
+
+
+
+ @Override
+ public String toString()
+ {
+ // flags
+ return "SparseExtentHeader[validNewLineDetectionTest="+validNewLineDetectionTest+
+ ", redundantGrainTableWillBeUsed="+redundantGrainTableWillBeUsed+
+ ", capacity="+capacity+
+ ", grainSize="+grainSize+
+ ", descriptorOffset="+descriptorOffset+
+ ", descriptorSize="+descriptorSize+
+ ", rgdOffset="+rgdOffset+
+ ", grainTableCoverage="+grainTableCoverage+
+ ", numGTEsPerGT="+numGTEsPerGT+
+ ", gdOffset="+gdOffset+
+ ", overHead="+overHead+
+ ", uncleanShutdown="+uncleanShutdown+"]";
+ }
}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseIOHandler.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseIOHandler.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseIOHandler.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -4,8 +4,7 @@
package org.jnode.apps.vmware.disk.handler.sparse;
import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
+import java.io.RandomAccessFile;
import org.apache.log4j.Logger;
import org.jnode.apps.vmware.disk.descriptor.Descriptor;
@@ -28,4 +27,9 @@
{
super(descriptor);
}
+
+ @Override
+ protected SparseExtentIO createExtentIO(RandomAccessFile raf, Extent extent) {
+ return new SparseExtentIO(raf, extent);
+ }
}
\ No newline at end of file
Deleted: trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestVMWareDisk.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestVMWareDisk.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestVMWareDisk.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -1,141 +0,0 @@
-package org.jnode.apps.vmware.disk.test;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.jnode.apps.vmware.disk.VMWareDisk;
-import org.jnode.apps.vmware.disk.handler.IOHandler;
-import org.junit.After;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
-/**
- * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare)
- *
- * @author Fabien DUMINY (fduminy at jnode dot org)
- *
- */
-@RunWith(value = Parameterized.class)
-public class TestVMWareDisk {
- private static final String DISKS_PATH = "/home/fabien/data/Projets/JNode/jnode/distr/src/apps/org/jnode/apps/vmware/disk/test/disks/";
- private static final String DISK_BASE_NAME = "Menuet32-";
-
- private static final String RESTRICT_TO_FILE_NAME = "Menuet32-0";
- //private static final String RESTRICT_TO_FILE_NAME = null;
-
- @Parameters
- public static List<File[]> data()
- {
- File directory = new File(DISKS_PATH);
- File[] files = directory.listFiles(new FilenameFilter()
- {
- public boolean accept(File dir, String name) {
- boolean ok = name.matches(DISK_BASE_NAME + "[0-9]*.vmdk");
-
- if(RESTRICT_TO_FILE_NAME != null)
- {
- ok &= name.startsWith(RESTRICT_TO_FILE_NAME);
- }
-
- return ok;
- }
- });
- List<File[]> list = new ArrayList<File[]>(files.length);
- for(File f : files)
- {
- list.add(new File[]{f});
- }
-
- return list;
- }
-
- final private File originalDiskFile;
- private File diskFile;
-
- public TestVMWareDisk(File diskFile) throws IOException
- {
- super();
- this.originalDiskFile = diskFile;
- }
-
- @Before
- public void setUp() throws IOException
- {
- this.diskFile = Utils.copyDisk(originalDiskFile);
- }
-
- @After
- public void tearDown() throws IOException
- {
- Utils.clearTempDir(true);
- }
-
- @Test
- public void read() throws Exception
- {
- VMWareDisk disk = new VMWareDisk(diskFile);
-
- ByteBuffer data = ByteBuffer.allocate(IOHandler.SECTOR_SIZE * 100);
- disk.read(0, data);
-
- Assert.assertEquals(toString()+": buffer should be filled", 0, data.remaining());
- }
-
- @Test
- public void write() throws Exception
- {
- VMWareDisk disk = new VMWareDisk(diskFile);
-
- ByteBuffer data = ByteBuffer.allocate(IOHandler.SECTOR_SIZE * 100);
- disk.write(0, data);
-
- Assert.assertEquals(toString()+": buffer should be fully copied", 0, data.remaining());
- }
-
- @Test
- public void writeAndRead() throws Exception
- {
- VMWareDisk disk = new VMWareDisk(diskFile);
-
- // write
- int size = IOHandler.SECTOR_SIZE * 100;
- ByteBuffer expectedData = ByteBuffer.allocate(size);
- for(int i = 0 ; i < (size / 4) ; i++)
- {
- expectedData.putInt(i);
- }
- expectedData.rewind();
- disk.write(0, expectedData);
- disk.flush();
-
- // read
- VMWareDisk disk2 = new VMWareDisk(diskFile);
- Assert.assertEquals("disk has different size", disk.getLength(), disk2.getLength());
- Assert.assertEquals("disk has different descriptor", disk.getDescriptor(), disk2.getDescriptor());
-
- expectedData.rewind();
- ByteBuffer actualData = ByteBuffer.allocate(size);
- disk2.read(0, actualData);
- for(int i = 0 ; i < (size / 4) ; i++)
- {
- int actual = actualData.getInt(i);
- int expected = expectedData.getInt();
- Assert.assertEquals("bad data at index "+(i*4), expected, actual);
- }
- }
-
- @Override
- public String toString()
- {
- return diskFile.getName();
- }
-}
Modified: trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/Utils.java
===================================================================
--- trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/Utils.java 2007-03-26 20:42:13 UTC (rev 3145)
+++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/Utils.java 2007-03-31 16:18:50 UTC (rev 3146)
@@ -19,16 +19,24 @@
private static final Logger LOG = Logger.getLogger(Utils.class);
private static final String TEMP_DIR = "VMWareDisk";
+ private static final File TEMP_DIR_FILE;
+ static
+ {
+ String tmpDir = System.getProperty("java.io.tmpdir");
+ TEMP_DIR_FILE = new File(tmpDir, TEMP_DIR);
+ }
+ private static long SEQ_NUMBER = 0L;
+
+ public static boolean DO_CLEAR = true;
+
public static File createTempDir() throws IOException
{
- String tmpDir = System.getProperty("java.io.tmpdir");
- File dir = new File(tmpDir, TEMP_DIR);
- if(!dir.exists())
+ if(!TEMP_DIR_FILE.exists())
{
- if(!dir.mkdir())
+ if(!TEMP_DIR_FILE.mkdir())
{
- throw new IOException("can't create directory "+dir);
+ throw new IOException("can't create directory "+TEMP_DIR_FILE.getAbsolutePath());
}
}
else
@@ -36,16 +44,22 @@
clearTempDir(false);
}
- return dir;
+ return TEMP_DIR_FILE;
}
+
+ public static File createTempFile(String prefix) throws IOException
+ {
+ File tmpDir = createTempDir();
+ return new File(tmpDir, String.valueOf(prefix) + SEQ_NUMBER++);
+ }
public static void clearTempDir(boolean deleteDir) throws IOException
{
- String tmpDir = System.getProperty("java.io.tmpdir");
- File dir = new File(tmpDir, TEMP_DIR);
- if(dir.exists())
+ if(!DO_CLEAR) return;
+
+ if(TEMP_DIR_FILE.exis...
[truncated message content] |
|
From: <kon...@us...> - 2007-03-26 20:42:16
|
Revision: 3145
http://jnode.svn.sourceforge.net/jnode/?rev=3145&view=rev
Author: konkubinaten
Date: 2007-03-26 13:42:13 -0700 (Mon, 26 Mar 2007)
Log Message:
-----------
Fixed main method to create GrepCommand instead of GcCommand (issue 990)
Modified Paths:
--------------
trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java
Modified: trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java
===================================================================
--- trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java 2007-03-18 20:53:31 UTC (rev 3144)
+++ trunk/shell/src/shell/org/jnode/shell/command/GrepCommand.java 2007-03-26 20:42:13 UTC (rev 3145)
@@ -40,7 +40,7 @@
*/
public static void main(String[] args)
throws Exception {
- new GcCommand().execute(new CommandLine(args), System.in, System.out, System.err);
+ new GrepCommand().execute(new CommandLine(args), System.in, System.out, System.err);
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|