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-03-19 00:44:39
|
Revision: 3144 http://jnode.svn.sourceforge.net/jnode/?rev=3144&view=rev Author: fduminy Date: 2007-03-18 13:53:31 -0700 (Sun, 18 Mar 2007) Log Message: ----------- JPartition (JNode disk partitionner) : alpha version Modified Paths: -------------- trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java Modified: trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java =================================================================== --- trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java 2007-03-18 19:35:21 UTC (rev 3143) +++ trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java 2007-03-18 20:53:31 UTC (rev 3144) @@ -40,7 +40,7 @@ this.dm = dm; this.api = current.getAPI(BlockDeviceAPI.class); - read(); + reloadMBR(); } public void initMbr() throws DeviceNotFoundException, ApiNotFoundException, @@ -66,12 +66,16 @@ bs.getPartition(2).setSystemIndicator(IBMPartitionTypes.PARTTYPE_EMPTY); bs.getPartition(3).setSystemIndicator(IBMPartitionTypes.PARTTYPE_EMPTY); } + + //reloadMBR(); } public void write() throws IOException { bs.write(api); + reloadMBR(); + // restart the device try { dm.stop(current); @@ -83,12 +87,10 @@ } } - private void read() throws IOException, ApiNotFoundException + private void reloadMBR() throws IOException { - //read the MBR this.MBR = ByteBuffer.allocate(IDEConstants.SECTOR_SIZE); - api.read(0, MBR); - + api.read(0, MBR); bs = new BootSector(MBR.array()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-03-19 00:35:35
|
Revision: 3141 http://jnode.svn.sourceforge.net/jnode/?rev=3141&view=rev Author: fduminy Date: 2007-03-18 12:26:26 -0700 (Sun, 18 Mar 2007) Log Message: ----------- vmware disk read/write access : alpha version Added Paths: ----------- trunk/distr/src/apps/org/jnode/apps/vmware/ trunk/distr/src/apps/org/jnode/apps/vmware/disk/ trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/ trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/ trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Extent.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleExtentFactory.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainTable.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestVMWareDisk.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/Utils.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/disks/ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/disks/others/ Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Extent.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Extent.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Extent.java 2007-03-18 19:26:26 UTC (rev 3141) @@ -0,0 +1,104 @@ +package org.jnode.apps.vmware.disk.extent; + +import java.io.File; + +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.handler.sparse.SparseExtentFactory; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class Extent { + private static final Logger LOG = Logger.getLogger(Extent.class); + + private Descriptor descriptor; + + final private Access access; + final private long sizeInSectors; // a sector is 512 bytes + final private ExtentType extentType; + final private String fileName; // relative to the location of the descriptor + final private File file; + final private long offset; + + public Extent(Descriptor descriptor, ExtentDeclaration extentDecl) + { + this.descriptor = descriptor; + this.access = extentDecl.getAccess(); + this.sizeInSectors = extentDecl.getSizeInSectors(); + this.extentType = extentDecl.getExtentType(); + this.fileName = extentDecl.getFileName(); + this.file = extentDecl.getExtentFile(); + this.offset = extentDecl.getOffset(); + + LOG.debug("created extent for file "+file.getAbsolutePath()+ + " offset="+offset+" fileSize="+file.length()); + } + + public Access getAccess() { + return access; + } + + public long getSizeInSectors() { + return sizeInSectors; + } + + public ExtentType getExtentType() { + return extentType; + } + + public String getFileName() { + return fileName; + } + + public long getOffset() { + return offset; + } + + final public Descriptor getDescriptor() { + return descriptor; + } + + public void setDescriptor(Descriptor descriptor) { + if(this.descriptor != null) + { + throw new IllegalStateException("descriptor already assigned"); + } + + this.descriptor = descriptor; + } + + + + public File getFile() { + return file; + } + + @Override + public String toString() { + return "Extent["+fileName+"]"; + } + + @Override + public boolean equals(Object obj) + { + if(!(obj instanceof Extent)) + { + return false; + } + + Extent e = (Extent) obj; + + return this.access.equals(e.access) && + (this.sizeInSectors == e.sizeInSectors) && + this.extentType.equals(e.extentType) && + this.fileName.equals(e.fileName) && + this.file.equals(e.file) && + (this.offset == e.offset); + } +} Added: 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 (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleExtentFactory.java 2007-03-18 19:26:26 UTC (rev 3141) @@ -0,0 +1,49 @@ +package org.jnode.apps.vmware.disk.handler.simple; + +import java.io.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; + +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.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; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class SimpleExtentFactory extends ExtentFactory +{ + protected FileDescriptor createFileDescriptor(File file, + RandomAccessFile raf, ByteBuffer bb, + boolean isMain) + throws IOException, UnsupportedFormatException + { + Descriptor descriptor = READER.read(file, bb, this); + return new FileDescriptor(descriptor, raf, this); + } + + public Extent createMainExtent(Descriptor desc, ExtentDeclaration extentDecl) + { + return new Extent(desc, extentDecl); + } + + 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); + } +} Added: 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 (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/AllocationTable.java 2007-03-18 19:26:26 UTC (rev 3141) @@ -0,0 +1,52 @@ +package org.jnode.apps.vmware.disk.handler.sparse; + +import java.io.IOException; +import java.io.RandomAccessFile; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class AllocationTable { + private final GrainDirectory grainDirectory; + private final GrainTable[] grainTables; + + public AllocationTable(RandomAccessFile raf, SparseExtentHeader header) + 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); + } + } + + public GrainDirectory getGrainDirectory() { + return grainDirectory; + } + + public int getNbGrainTables() + { + return grainTables.length; + } + + public GrainTable getGrainTable(int tableNum) + { + return grainTables[tableNum]; + } +} Added: 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 (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainTable.java 2007-03-18 19:26:26 UTC (rev 3141) @@ -0,0 +1,18 @@ +package org.jnode.apps.vmware.disk.handler.sparse; + +import java.io.IOException; +import java.io.RandomAccessFile; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class GrainTable extends EntryArray +{ + public GrainTable(RandomAccessFile raf, int nbEntries) throws IOException + { + super(raf, nbEntries); + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestVMWareDisk.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestVMWareDisk.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/TestVMWareDisk.java 2007-03-18 19:26:26 UTC (rev 3141) @@ -0,0 +1,141 @@ +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(); + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/Utils.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/Utils.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/test/Utils.java 2007-03-18 19:26:26 UTC (rev 3141) @@ -0,0 +1,135 @@ +package org.jnode.apps.vmware.disk.test; + +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; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class Utils { + private static final Logger LOG = Logger.getLogger(Utils.class); + + private static final String TEMP_DIR = "VMWareDisk"; + + public static File createTempDir() throws IOException + { + String tmpDir = System.getProperty("java.io.tmpdir"); + File dir = new File(tmpDir, TEMP_DIR); + if(!dir.exists()) + { + if(!dir.mkdir()) + { + throw new IOException("can't create directory "+dir); + } + } + else + { + clearTempDir(false); + } + + return dir; + } + + 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()) + { + for(File tmpFile : dir.listFiles()) + { + LOG.debug("deleting file "+tmpFile); + tmpFile.delete(); + } + } + + if(deleteDir) + { + dir.delete(); + } + } + + public static File copyDisk(final File mainFile) 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 tmpDir = createTempDir(); + + File mainFileCopy = null; + for(File file : files) + { + File f = copyFile(file, tmpDir); + 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(); + } + } + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-03-18 23:57:38
|
Revision: 3143 http://jnode.svn.sourceforge.net/jnode/?rev=3143&view=rev Author: fduminy Date: 2007-03-18 12:35:21 -0700 (Sun, 18 Mar 2007) Log Message: ----------- JPartition (JNode disk partitionner) : alpha version Added Paths: ----------- trunk/distr/src/apps/org/jnode/apps/jpartition/ 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 trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java trunk/distr/src/apps/org/jnode/apps/jpartition/controller/ trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java trunk/distr/src/apps/org/jnode/apps/jpartition/model/ 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 trunk/distr/src/apps/org/jnode/apps/jpartition/view/ trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsFrame.java trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsUI.java trunk/distr/src/apps/org/jnode/apps/jpartition/view/FileDeviceFrame.java trunk/distr/src/apps/org/jnode/apps/jpartition/view/PartitionUI.java Added: trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/BasicNameSpace.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,35 @@ +/** + * + */ +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 Added: trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDevice.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,86 @@ +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); + } +} Added: trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/FileIDEDeviceDriver.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,32 @@ +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 { + + } +} Added: trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/JPartition.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,60 @@ +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.naming.InitialNaming; +import org.jnode.naming.NameSpace; +import org.jnode.test.fs.driver.stubs.StubDeviceManager; + +public class JPartition { + private static final Logger log = Logger.getLogger(JPartition.class); + + public static void main(String[] args) throws Exception { + initJNodeCore(); + + FileDeviceFrame frm = new FileDeviceFrame(); + frm.setSize(300, 300); + frm.setVisible(true); + frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + + 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); + } + + 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); + } +} Added: trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/controller/DevicePartitionsController.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,58 @@ +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/model/DevicePartitions.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitions.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,73 @@ +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; + } +} Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/DevicePartitionsList.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,7 @@ +package org.jnode.apps.jpartition.model; + +import java.util.ArrayList; + +public class DevicePartitionsList extends ArrayList<DevicePartitions> +{ +} Added: trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/model/Partition.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,40 @@ +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; + } +} Added: trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsFrame.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsFrame.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsFrame.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,28 @@ +package org.jnode.apps.jpartition.view; + +import javax.swing.JFrame; + +import org.jnode.apps.jpartition.controller.DevicePartitionsController; +import org.jnode.apps.jpartition.model.DevicePartitionsList; + +public class DevicePartitionsFrame extends JFrame { + private DevicePartitionsUI devPartsUI; + + private DevicePartitionsController controller; + + public DevicePartitionsFrame(DevicePartitionsList devicePartitionsList) + { + setTitle("JPartition"); + + devPartsUI = new DevicePartitionsUI(devicePartitionsList); + add(devPartsUI); + + controller = new DevicePartitionsController(devicePartitionsList, this); + } + + public DevicePartitionsUI getDevPartsUI() { + return devPartsUI; + } + + +} Added: trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsUI.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsUI.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/view/DevicePartitionsUI.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,67 @@ +package org.jnode.apps.jpartition.view; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; + +import javax.swing.DefaultComboBoxModel; +import javax.swing.JComboBox; +import javax.swing.JPanel; + +import org.jnode.apps.jpartition.model.DevicePartitions; +import org.jnode.apps.jpartition.model.DevicePartitionsList; +import org.jnode.apps.jpartition.model.Partition; + +public class DevicePartitionsUI extends JPanel { + private DevicePartitionsList devicePartitions; + + private DefaultComboBoxModel cboDevicesModel = new DefaultComboBoxModel(); + private JComboBox cboDevices = new JComboBox(cboDevicesModel); + private JPanel partitionsPanel = new JPanel(new FlowLayout()); + + public DevicePartitionsUI(DevicePartitionsList devicePartitions) + { + super(new BorderLayout()); + this.devicePartitions = devicePartitions; + + add(cboDevices, BorderLayout.NORTH); + add(partitionsPanel, BorderLayout.CENTER); + + for(DevicePartitions 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) + { + System.err.println("itemStateChanged"); + DevicePartitions devParts = (DevicePartitions) event.getItem(); + partitionsPanel.removeAll(); + + for(Partition partition : devParts.getPartitions()) + { + partitionsPanel.add(new PartitionUI(partition)); + } + } + } + }); + } + + public void deviceAdded(DevicePartitions devParts) { + System.err.println("deviceAdded"); + cboDevicesModel.addElement(devParts); + } + + public void deviceRemoved(DevicePartitions devParts) { + cboDevicesModel.removeElement(devParts); + } +} Added: trunk/distr/src/apps/org/jnode/apps/jpartition/view/FileDeviceFrame.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/view/FileDeviceFrame.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/view/FileDeviceFrame.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,133 @@ +package org.jnode.apps.jpartition.view; + +import java.awt.BorderLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; + +import javax.naming.NameNotFoundException; +import javax.swing.DefaultListModel; +import javax.swing.JButton; +import javax.swing.JFileChooser; +import javax.swing.JFrame; +import javax.swing.JList; +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.JScrollPane; + +import org.apache.log4j.Logger; +import org.jnode.apps.jpartition.FileIDEDevice; +import org.jnode.driver.ApiNotFoundException; +import org.jnode.driver.DeviceAlreadyRegisteredException; +import org.jnode.driver.DeviceManager; +import org.jnode.driver.DeviceNotFoundException; +import org.jnode.driver.DeviceUtils; +import org.jnode.driver.DriverException; +import org.jnode.partitions.command.PartitionHelper; +import org.jnode.partitions.ibm.IBMPartitionTypes; + +public class FileDeviceFrame extends JFrame +{ + private static final Logger log = Logger.getLogger(FileDeviceFrame.class); + + private static final long DEFAULT_FILE_SIZE = 1000; + + private DefaultListModel fileDevices = new DefaultListModel(); + + private JList devicesList = new JList(fileDevices); + private JPanel buttons = new JPanel(); + private JButton addButton = new JButton("add device"); + private JButton removeButton = new JButton("remove device"); + + public FileDeviceFrame() throws Exception + { + setTitle("File devices"); + setLayout(new BorderLayout()); + add(new JScrollPane(devicesList), BorderLayout.CENTER); + add(buttons, BorderLayout.SOUTH); + + buttons.add(addButton); + buttons.add(removeButton); + + addButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent event) { + JFileChooser jfc = new JFileChooser(); + jfc.setDialogType(JFileChooser.SAVE_DIALOG); + int result = jfc.showSaveDialog(FileDeviceFrame.this); + if(result == JFileChooser.APPROVE_OPTION) + { + try + { + FileIDEDevice fd = createDevice(jfc.getSelectedFile()); + if(addDevice(fd)) + { + fileDevices.addElement(fd); + } + else + { + JOptionPane.showMessageDialog(FileDeviceFrame.this, + "failed to add device", "add device", + JOptionPane.ERROR_MESSAGE); + } + } catch (Exception e) { + log.error(e); + } + } + } + }); + removeButton.addActionListener(new ActionListener() + { + public void actionPerformed(ActionEvent event) { + if(devicesList.getSelectedIndex() >= 0) + { + //TODO + } + } + }); + } + + protected FileIDEDevice createDevice(File file) throws Exception + { + //return new FileDevice(file, "rw"); + FileIDEDevice dev = new FileIDEDevice(file, DEFAULT_FILE_SIZE, + true, true); + return dev; + } + + private boolean addDevice(FileIDEDevice device) + { + boolean success = false; + try + { + DeviceManager devMan = DeviceUtils.getDeviceManager(); + devMan.register(device); + success = true; + + PartitionHelper helper = new PartitionHelper(device.getId(), devMan); + helper.initMbr(); + helper.write(); + 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) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (ApiNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + return success; + } +} Added: trunk/distr/src/apps/org/jnode/apps/jpartition/view/PartitionUI.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/jpartition/view/PartitionUI.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/jpartition/view/PartitionUI.java 2007-03-18 19:35:21 UTC (rev 3143) @@ -0,0 +1,57 @@ +package org.jnode.apps.jpartition.view; + +import java.awt.Color; + +import javax.swing.BorderFactory; +import javax.swing.JLabel; +import javax.swing.JPanel; + +import org.jnode.apps.jpartition.model.Partition; + +public class PartitionUI extends JPanel +{ + private Partition partition = null; + + private JLabel lblInfos = new JLabel(); + + public PartitionUI(Partition partition) + { + setPartition(partition); + + + setBorder(BorderFactory.createLineBorder(Color.BLUE, 5)); + lblInfos.setBackground(Color.CYAN); + add(lblInfos); + } + + public Partition getPartition() { + return partition; + } + + public void setPartition(Partition partition) { + if(this.partition != partition) + { + this.partition = partition; + refreshFromModel(); + } + } + + public void refreshFromModel() + { + StringBuilder sb = new StringBuilder(); + + String name = partition.getType().getName(); + if(name.length() > 10) + { + name = name.substring(0, 10); + } + String boot = partition.isBootable() ? "(B)" : "(-)"; + sb.append(boot).append(name); + if(!partition.isEmpty()) + { + sb.append("-").append(partition.getStart()); + sb.append("-").append(partition.getSize()); + } + lblInfos.setText(sb.toString()); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-03-18 23:34:36
|
Revision: 3142 http://jnode.svn.sourceforge.net/jnode/?rev=3142&view=rev Author: fduminy Date: 2007-03-18 12:33:19 -0700 (Sun, 18 Mar 2007) Log Message: ----------- vmware disk read/write access : alpha version Added Paths: ----------- trunk/distr/lib/ trunk/distr/lib/junit-4.1.jar trunk/distr/src/apps/log4j.properties trunk/distr/src/apps/org/jnode/apps/vmware/disk/DescriptorReader.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/ExtentDeclaration.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/RandomAccessFileReader.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/VMWareDisk.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/AdapterType.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/CreateType.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Descriptor.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DiskDatabase.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Header.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Access.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/ExtentType.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/FileDescriptor.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/SimpleIOHandler.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/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/SparseFileDescriptor.java trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseIOHandler.java Added: trunk/distr/lib/junit-4.1.jar =================================================================== (Binary files differ) Property changes on: trunk/distr/lib/junit-4.1.jar ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/distr/src/apps/log4j.properties =================================================================== --- trunk/distr/src/apps/log4j.properties (rev 0) +++ trunk/distr/src/apps/log4j.properties 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,17 @@ +# log4j configuration file that directs its logging output +# to a SocketAppender. The SocketAppender is configuted to send its +# output to a server running on the localhost port number 12345. + +# Don't remove that log4j config file !!! +# It is used by following applications : +# - vmware.disk (under package /org/jnode/apps/vmware/disk) +# - JPartition (under package /org/jnode/apps/jpartition) + +log4j.rootLogger=DEBUG, A1 + +# A1 is set to be a SocketAppender sending its output to the server +running on the local host, port 4445 + +log4j.appender.A1=org.apache.log4j.net.SocketAppender +log4j.appender.A1.Port=4445 +log4j.appender.A1.RemoteHost=localhost Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/DescriptorReader.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/DescriptorReader.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/DescriptorReader.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,190 @@ +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; + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/ExtentDeclaration.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/ExtentDeclaration.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/ExtentDeclaration.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,65 @@ +package org.jnode.apps.vmware.disk; + +import java.io.File; + +import org.jnode.apps.vmware.disk.extent.Access; +import org.jnode.apps.vmware.disk.extent.ExtentType; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class ExtentDeclaration { + private final Access access; + private final long sizeInSectors; + private final ExtentType extentType; + private final String fileName; + private final File extentFile; + private final long offset; + private final boolean isMainExtent; + + public ExtentDeclaration(Access access, long sizeInSectors, + ExtentType extentType, String fileName, File extentFile, + long offset, boolean isMainExtent) + { + this.access = access; + this.sizeInSectors = sizeInSectors; + this.extentType = extentType; + this.fileName = fileName; + this.extentFile = extentFile; + this.offset = offset; + this.isMainExtent = isMainExtent; + } + + public Access getAccess() { + return access; + } + + public long getSizeInSectors() { + return sizeInSectors; + } + + public ExtentType getExtentType() { + return extentType; + } + + public String getFileName() { + return fileName; + } + + public File getExtentFile() { + return extentFile; + } + + public boolean isMainExtent() { + return isMainExtent; + } + + public long getOffset() { + return offset; + } + + +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/IOUtils.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,205 @@ +package org.jnode.apps.vmware.disk; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +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.UnsupportedFormatException; +import org.jnode.apps.vmware.disk.handler.simple.SimpleExtentFactory; +import org.jnode.apps.vmware.disk.handler.sparse.SparseExtentFactory; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class IOUtils { + private static final Logger LOG = Logger.getLogger(SparseExtentFactory.class); + + private static final String COMMENT = "#"; + private static final String EQUAL = "="; + + private final static ExtentFactory[] FACTORIES = + { + new SparseExtentFactory(), + new SimpleExtentFactory(), + }; + + public static class KeyValue + { + private String key; + private String value; + public String getKey() { + return key; + } + public void setKey(String key) { + this.key = key; + } + public String getValue() { + return value; + } + public void setValue(String value) { + this.value = value; + } + } + + public static String readLine(BufferedReader reader) throws IOException + { + String line = null; + while((line = reader.readLine()) != null) + { + LOG.debug("line="+line); + + line = line.trim(); + if(!line.isEmpty() && + !line.startsWith(COMMENT)) + { + return line; + } + } + + //throw new IOException("no more lines"); + return null; + } + + public static String removeQuotes(String value) + { + // remove enclosing '"' + return (value == null) ? null : value.substring(1, value.length() - 1); + } + + public static KeyValue readValue(BufferedReader reader, KeyValue keyValue, + String wantedKey, boolean removeQuotes) + throws IOException + { + keyValue = readValue(readLine(reader), keyValue, wantedKey); + + if(wantedKey != null) + { + while(keyValue.getValue() == null) + { + keyValue = readValue(readLine(reader), keyValue, wantedKey); + } + } + + keyValue.setValue(removeQuotes ? removeQuotes(keyValue.getValue()) : keyValue.getValue()); + + return keyValue; + } + + private static KeyValue readValue(String line, KeyValue keyValue, + String wantedKey) + throws IOException + { + keyValue = (keyValue == null) ? new KeyValue() : keyValue; + + keyValue.setKey(null); + keyValue.setValue(null); + + if(line == null) + { + return keyValue; + } + + int idx = line.indexOf(EQUAL); + if(idx < 0) + { + LOG.debug("err2: tried to read key "+wantedKey+", line="+line); + return keyValue; + } + + keyValue.setKey(line.substring(0, idx).trim()); + keyValue.setValue(line.substring(idx + 1).trim()); + + if((wantedKey != null) && !keyValue.getKey().equals(wantedKey)) + { + throw new IOException("excepted key("+wantedKey+") not found (actual:"+keyValue.getKey()+")"); + } + + return keyValue; + } + + public static FileDescriptor readFileDescriptor(File file, boolean isMain) + throws IOException, UnsupportedFormatException + { + FileDescriptor fileDescriptor = null; + + for(ExtentFactory f : FACTORIES) + { + try { + LOG.debug("trying with factory "+f.getClass().getName()); + FileDescriptor fd = f.createFileDescriptor(file, isMain); + + // we have found the factory for that format + fileDescriptor = fd; + + break; + } catch (UnsupportedFormatException e) { + // ignore, we will try with the next factory + LOG.debug(f.getClass().getName()+":"+file+" not supported "+e.getMessage()); + } + } + + if(fileDescriptor == null) + { + throw new UnsupportedFormatException("format not supported for file "+file); + } + + return fileDescriptor; + } + + public static File getExtentFile(File mainFile, String extentFileName) { + String path = mainFile.getParentFile().getAbsolutePath(); + return new File(path, extentFileName); + } + + public static Map<String, String> readValuesMap(String lastLine, + BufferedReader br, + boolean removeQuotes, + String... requiredKeys) throws IOException + { + Map<String, String> values = new HashMap<String, String>(); + + KeyValue keyValue = IOUtils.readValue(lastLine, null, null); + if(keyValue.getValue() == null) + { + keyValue = IOUtils.readValue(br, keyValue, null, removeQuotes); + } + values.put(keyValue.getKey(), keyValue.getValue()); + + while((keyValue = IOUtils.readValue(br, keyValue, null, removeQuotes)).getValue() != null) + { + values.put(keyValue.getKey(), keyValue.getValue()); + } + + // check required keys + boolean error = false; + StringBuilder sb = new StringBuilder("required keys not found : "); + for(String reqKey : requiredKeys) + { + if(!values.keySet().contains(reqKey)) + { + error = true; + sb.append(reqKey).append(','); + } + } + if(error) + { + throw new IOException(sb.toString()); + } + + return values; + } + + public static boolean equals(Object o1, Object o2) + { + return (o1 == null) ? (o2 == null) : o1.equals(o2); + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/RandomAccessFileReader.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/RandomAccessFileReader.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/RandomAccessFileReader.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,41 @@ +package org.jnode.apps.vmware.disk; + +import java.io.IOException; +import java.io.RandomAccessFile; +import java.io.Reader; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class RandomAccessFileReader extends Reader +{ + private final RandomAccessFile raf; + private final boolean mustClose; + + public RandomAccessFileReader(RandomAccessFile raf, boolean mustClose) + { + this.raf = raf; + this.mustClose = mustClose; + } + + @Override + public void close() throws IOException { + if(mustClose) + { + raf.close(); + } + } + + @Override + public int read(char[] buf, int offset, int count) throws IOException { + int nbRead = 0; + for(int i = offset ; i < (offset + count) ; i++) + { + buf[i] = raf.readChar(); + } + return nbRead; + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/VMWareDisk.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/VMWareDisk.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/VMWareDisk.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,67 @@ +package org.jnode.apps.vmware.disk; + +import java.io.File; +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.apache.log4j.Logger; +import org.jnode.apps.vmware.disk.descriptor.Descriptor; +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; +import org.jnode.apps.vmware.disk.handler.sparse.SparseIOHandler; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class VMWareDisk +{ + private static final Logger LOG = Logger.getLogger(VMWareDisk.class); + + private final Descriptor descriptor; + private final IOHandler handler; + + public VMWareDisk(File file) throws IOException, UnsupportedFormatException + { + FileDescriptor fd = IOUtils.readFileDescriptor(file, true); + + ExtentFactory factory = fd.getExtentFactory(); + + this.handler = factory.createIOHandler(fd); + this.descriptor = fd.getDescriptor(); + + LOG.debug("handler for file "+file.getName()+" : "+handler.getClass().getName()); + } + + public void write(long sector, ByteBuffer data) throws IOException + { + handler.write(sector, data); + } + + public void read(long sector, ByteBuffer data) throws IOException + { + handler.read(sector, data); + } + + public void flush() throws IOException + { + handler.flush(); + } + + public long getLength() { + DiskDatabase ddb = descriptor.getDiskDatabase(); + return ddb.getCylinders() * ddb.getHeads() * ddb.getSectors() * + IOHandler.SECTOR_SIZE; + } + + public Descriptor getDescriptor() { + return descriptor; + } + + +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/AdapterType.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/AdapterType.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/AdapterType.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,15 @@ +package org.jnode.apps.vmware.disk.descriptor; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public enum AdapterType { + ide, + busLogic, + lsiLogic, + legacyLogic, + legacyESX +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/CreateType.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/CreateType.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/CreateType.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,21 @@ +package org.jnode.apps.vmware.disk.descriptor; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public enum CreateType { + monolithicSparse, + vmfsSparse, + monolithicFlat, + vmfs, + twoGbMaxExtentSparse, + twoGbMaxExtentFlat, + fullDevice, + vmfsRaw, + partitionedDevice, + vmfsRawDeviceMap, + vmfsPassthroughRawDeviceMap +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Descriptor.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Descriptor.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Descriptor.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,88 @@ +package org.jnode.apps.vmware.disk.descriptor; + +import java.io.File; +import java.util.List; + +import org.apache.log4j.Logger; +import org.jnode.apps.vmware.disk.VMWareDisk; +import org.jnode.apps.vmware.disk.extent.Extent; +import org.jnode.apps.vmware.disk.handler.ExtentFactory; +import org.jnode.apps.vmware.disk.handler.FileDescriptor; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class Descriptor { + private static final Logger LOG = Logger.getLogger(Descriptor.class); + + final private File mainFile; + final private Header header; + final private List<Extent> extents; + final private DiskDatabase diskDatabase; + + public Descriptor(File mainFile, Header header, List<Extent> extents, + DiskDatabase diskDatabase) + { + this.mainFile = mainFile; + this.header = header; + this.extents = extents; + this.diskDatabase = diskDatabase; + } + + public Header getHeader() { + return header; + } + + public List<Extent> getExtents() { + return extents; + } + + public DiskDatabase getDiskDatabase() { + return diskDatabase; + } + + public File getMainFile() { + return mainFile; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof Descriptor)) + { + return false; + } + + Descriptor desc = (Descriptor) obj; + + String file1 = ""; + String file2 = ""; + try { + file1 = this.mainFile.getCanonicalPath(); + file2 = desc.mainFile.getCanonicalPath(); + } catch (Exception e) { + LOG.error("can't compare filenames", e); + } + + return file1.equals(file2) && + this.header.equals(desc.header) && + this.extents.equals(desc.extents) && + this.diskDatabase.equals(desc.diskDatabase); + } + + @Override + public String toString() { + String file1 = ""; + try { + file1 = this.mainFile.getCanonicalPath(); + } catch (Exception e) { + LOG.error("can't compare filenames", e); + } + + return "Descriptor: file=" + file1 + + ","+header+",extents="+extents+ + ","+diskDatabase; + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DiskDatabase.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DiskDatabase.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/DiskDatabase.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,61 @@ +package org.jnode.apps.vmware.disk.descriptor; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class DiskDatabase { + private AdapterType adapterType; + private int sectors; + private int heads; + private int cylinders; + public AdapterType getAdapterType() { + return adapterType; + } + public void setAdapterType(AdapterType adapterType) { + this.adapterType = adapterType; + } + public int getSectors() { + return sectors; + } + public void setSectors(int sectors) { + this.sectors = sectors; + } + public int getHeads() { + return heads; + } + public void setHeads(int heads) { + this.heads = heads; + } + public int getCylinders() { + return cylinders; + } + public void setCylinders(int cylinders) { + this.cylinders = cylinders; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof DiskDatabase)) + { + return false; + } + + DiskDatabase d = (DiskDatabase) obj; + + return (this.adapterType == d.adapterType) && + (this.sectors == d.sectors) && + (this.heads == d.heads) && + (this.cylinders == d.cylinders); + } + + @Override + public String toString() { + return "DiskDatabase[adapterType:"+adapterType+ + ",sectors:"+sectors+ + ",heads:"+heads+ + ",cylinders:"+cylinders+"]"; + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Header.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Header.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/descriptor/Header.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,89 @@ +package org.jnode.apps.vmware.disk.descriptor; + +import org.jnode.apps.vmware.disk.IOUtils; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class Header { + /** + * cid/content id when no parent + */ + public static final long CID_NOPARENT = 0x0; + + private String version; + private long contentID; // cid + private long parentContentID; // parent cid (maybe be CID_NOPARENT) + + private CreateType createType; + + private String parentFileNameHint; + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public long getContentID() { + return contentID; + } + + public void setContentID(long contentID) { + this.contentID = contentID; + } + + public long getParentContentID() { + return parentContentID; + } + + public void setParentContentID(long parentContentID) { + this.parentContentID = parentContentID; + } + + public CreateType getCreateType() { + return createType; + } + + public void setCreateType(CreateType createType) { + this.createType = createType; + } + + public String getParentFileNameHint() { + return parentFileNameHint; + } + + public void setParentFileNameHint(String parentFileNameHint) { + this.parentFileNameHint = parentFileNameHint; + } + + @Override + public boolean equals(Object obj) { + if(!(obj instanceof Header)) + { + return false; + } + + Header h = (Header) obj; + + return this.version.equals(h.version) && + (this.contentID == h.contentID) && + (this.parentContentID == h.parentContentID) && + this.createType.equals(h.createType) && + IOUtils.equals(this.parentFileNameHint, h.parentFileNameHint); + } + + @Override + public String toString() { + return "Header[version:"+version + + ",contentID:"+contentID+ + ",parentContentID:"+parentContentID+ + ",createType:"+createType+ + ",parentFileNameHint:"+parentFileNameHint+"]"; + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Access.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Access.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/Access.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,13 @@ +package org.jnode.apps.vmware.disk.extent; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public enum Access { + RW, + RDONLY, + NOACCESS +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/ExtentType.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/ExtentType.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/extent/ExtentType.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,17 @@ +package org.jnode.apps.vmware.disk.extent; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public enum ExtentType { + FLAT, + SPARSE, + ZERO, + VMFS, + VMFSSPARSE, + VMFSRDM, + VMFSRAW +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentFactory.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentFactory.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentFactory.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,90 @@ +package org.jnode.apps.vmware.disk.handler; + +import java.io.File; +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.DescriptorReader; +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.sparse.SparseExtentFactory; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +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) + 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); + } + finally + { + if((fileDescriptor == null) && (raf != null)) + { + // if there was an error but RandomAccessFile has + // 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 FileDescriptor createFileDescriptor(File file, + RandomAccessFile raf, ByteBuffer bb, + boolean isMain) + 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; +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentIO.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentIO.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/ExtentIO.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,55 @@ +package org.jnode.apps.vmware.disk.handler; + +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; + +import org.apache.log4j.Logger; +import org.jnode.apps.vmware.disk.handler.sparse.SparseExtentFactory; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class ExtentIO +{ + private static final Logger LOG = Logger.getLogger(ExtentIO.class); + + private final RandomAccessFile raf; + private final FileChannel channel; + + public ExtentIO(RandomAccessFile raf) + { + this.raf = raf; + this.channel = raf.getChannel(); + } + + public void read(long sector, ByteBuffer dst) throws IOException + { + int oldLimit = dst.limit(); + dst.limit((int) (dst.position() + IOHandler.SECTOR_SIZE)); + + channel.position(IOHandler.SECTOR_SIZE * sector); + LOG.debug("channel pos before : "+channel.position()); + int read = channel.read(dst); + LOG.debug("channel pos after : "+channel.position()); + LOG.debug("nb bytes read: "+read); + + dst.limit(oldLimit); + } + + public void write(long sector, ByteBuffer src) throws IOException + { + channel.position(IOHandler.SECTOR_SIZE * sector); + channel.write(src); + } + + public void flush() throws IOException + { + raf.close(); + channel.close(); + } +} \ No newline at end of file Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/FileDescriptor.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/FileDescriptor.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/FileDescriptor.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,39 @@ +package org.jnode.apps.vmware.disk.handler; + +import java.io.RandomAccessFile; + +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 FileDescriptor +{ + final private Descriptor descriptor; + final private RandomAccessFile raf; + final private ExtentFactory factory; + + public FileDescriptor(Descriptor descriptor, RandomAccessFile raf, + ExtentFactory factory) + { + this.descriptor = descriptor; + this.raf = raf; + this.factory = factory; + } + + public Descriptor getDescriptor() { + return descriptor; + } + + public RandomAccessFile getRandomAccessFile() + { + return raf; + } + + public ExtentFactory getExtentFactory() { + return factory; + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/IOHandler.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/IOHandler.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/IOHandler.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,140 @@ +package org.jnode.apps.vmware.disk.handler; + +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.jnode.apps.vmware.disk.descriptor.Descriptor; +import org.jnode.apps.vmware.disk.descriptor.DiskDatabase; +import org.jnode.apps.vmware.disk.extent.Extent; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +abstract public class IOHandler { + private static final Logger LOG = Logger.getLogger(IOHandler.class); + + public static final int SECTOR_SIZE = 512; + + final protected Descriptor descriptor; + final private long nbSectors; + + final private Map<Extent, ExtentIO> extentIOCache = new HashMap<Extent, ExtentIO>(); + + protected IOHandler(Descriptor descriptor) throws IOException { + this.descriptor = descriptor; + + DiskDatabase ddb = descriptor.getDiskDatabase(); + nbSectors = ddb.getCylinders() * ddb.getHeads() * ddb.getSectors(); + } + + public void write(long sector, ByteBuffer data) + throws IOException + { + int nbSectors = checkBounds(sector, data); + writeImpl(sector, nbSectors, data); + } + + public void read(long sector, ByteBuffer data) + throws IOException + { + int nbSectors = checkBounds(sector, data); + readImpl(sector, nbSectors, data); + } + + public void flush() throws IOException + { + for(ExtentIO io : extentIOCache.values()) + { + io.flush(); + } + extentIOCache.clear(); + } + + protected int checkBounds(long sector, ByteBuffer buffer) throws IOException { + int nbSectors = buffer.remaining() / SECTOR_SIZE; + if((buffer.remaining() % SECTOR_SIZE) != 0) + { + nbSectors++; + } + + checkBounds(sector); + checkBounds(sector + nbSectors - 1); + + return nbSectors; + } + + protected void checkBounds(long sector) throws IOException + { + if(sector < 0) + { + throw new IOException("negative sector (actual:"+sector+")"); + } + + if(sector >= this.nbSectors) + { + throw new IOException("sector above limit("+this.nbSectors+") (actual:"+sector+")"); + } + } + + protected ExtentIO getExtentIO(long sector) throws IOException + { + Extent extent = getExtent(sector); + return getExtentIO(extent); + } + + final protected ExtentIO getExtentIO(Extent extent) throws IOException + { + ExtentIO io = extentIOCache.get(extent); + + if(io == null) + { + RandomAccessFile raf = new RandomAccessFile(extent.getFile(), "rw"); + LOG.debug("length for file "+extent.getFileName()+" : "+raf.length()); + io = new ExtentIO(raf); + extentIOCache.put(extent, io); + } + + return io; + } + + protected Extent getExtent(long sector) throws IOException + { + Extent handler = null; + for(Extent extent : descriptor.getExtents()) + { + LOG.debug(extent.getFileName()+": SizeInSectors="+extent.getSizeInSectors()); + + if(sector < extent.getSizeInSectors()) + { + handler = extent; + break; + } + + sector -= extent.getSizeInSectors(); + } + return handler; + } + + public void readImpl(long sector, int nbSectors, ByteBuffer dst) + throws IOException { + for(int i = 0 ; i < nbSectors ; i++, sector++) + { + getExtentIO(sector).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); + } + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/UnsupportedFormatException.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/UnsupportedFormatException.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/UnsupportedFormatException.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,27 @@ +package org.jnode.apps.vmware.disk.handler; + +/** + * 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 UnsupportedFormatException() { + super(); + } + + public UnsupportedFormatException(String s, Throwable cause) { + super(s, cause); + } + + public UnsupportedFormatException(String s) { + super(s); + } + + public UnsupportedFormatException(Throwable cause) { + super(cause); + } + +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleIOHandler.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleIOHandler.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/simple/SimpleIOHandler.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,22 @@ +/** + * + */ +package org.jnode.apps.vmware.disk.handler.simple; + +import java.io.IOException; + +import org.jnode.apps.vmware.disk.handler.FileDescriptor; +import org.jnode.apps.vmware.disk.handler.IOHandler; +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 SimpleIOHandler extends IOHandler { + public SimpleIOHandler(FileDescriptor fileDescriptor) throws IOException, UnsupportedFormatException { + super(fileDescriptor.getDescriptor()); + } +} \ No newline at end of file Added: 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 (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/EntryArray.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,48 @@ +package org.jnode.apps.vmware.disk.handler.sparse; + +import java.io.IOException; +import java.io.RandomAccessFile; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class EntryArray +{ + final private int[] entries; + + public EntryArray(RandomAccessFile raf, int nbEntries) + throws IOException + { + entries = new int[nbEntries]; + for(int entryNumber = 0 ; entryNumber < nbEntries ; entryNumber++) + { + setEntry(entryNumber, raf.readInt()); + } + } + + public void write(RandomAccessFile raf) throws IOException + { + for(int entry : entries) + { + raf.writeInt(entry); + } + } + + public int getSize() + { + return entries.length; + } + + public int getEntry(int entryNumber) + { + return entries[entryNumber]; + } + + public void setEntry(int entryNumber, int value) + { + entries[entryNumber] = value; + } +} Added: 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 (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/GrainDirectory.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,18 @@ +package org.jnode.apps.vmware.disk.handler.sparse; + +import java.io.IOException; +import java.io.RandomAccessFile; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class GrainDirectory extends EntryArray +{ + public GrainDirectory(RandomAccessFile raf, int nbEntries) throws IOException + { + super(raf, nbEntries); + } +} Added: 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 (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtent.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,43 @@ +package org.jnode.apps.vmware.disk.handler.sparse; + +import org.jnode.apps.vmware.disk.ExtentDeclaration; +import org.jnode.apps.vmware.disk.descriptor.Descriptor; +import org.jnode.apps.vmware.disk.extent.Extent; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class SparseExtent extends Extent +{ + private final SparseExtentHeader header; + private final AllocationTable redundantAllocationTable; + private final AllocationTable allocationTable; + + public SparseExtent(Descriptor descriptor, ExtentDeclaration extentDecl, + SparseExtentHeader header, + AllocationTable redundantAllocationTable, + AllocationTable allocationTable) + { + super(descriptor, extentDecl); + + this.header = header; + this.redundantAllocationTable = redundantAllocationTable; + this.allocationTable = allocationTable; + } + +/* TODO implement it later + public void write() throws IOException { + raf.seek(0L); + header.write(raf); + redundantAllocationTable.write(raf); + allocationTable.write(raf); + } +*/ + @Override + public String toString() { + return "SparseExtent["+getFileName()+"]"; + } +} Added: 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 (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentFactory.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,88 @@ +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.descriptor.Descriptor; +import org.jnode.apps.vmware.disk.extent.Extent; +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; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +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) + throws IOException, UnsupportedFormatException + { + SparseExtentHeader header = SparseExtentHeader.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); + } else { + LOG.debug("embeddedDescriptor = null"); + embeddedDescriptor = null; + } + return new SparseFileDescriptor(embeddedDescriptor, raf, this, header); + } + + public Extent createMainExtent(Descriptor desc, ExtentDeclaration extentDecl) throws IOException, UnsupportedFormatException + { + 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); + } + + public IOHandler createIOHandler(FileDescriptor fileDescriptor) throws IOException + { + SparseFileDescriptor sfd = (SparseFileDescriptor) fileDescriptor; + IOHandler handler = null; + + Descriptor desc = sfd.getDescriptor(); + handler = new SparseIOHandler(desc); + + return handler; + } + +} Added: 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 (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseExtentHeader.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,168 @@ +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; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class SparseExtentHeader +{ + private static final Logger LOG = Logger.getLogger(SparseExtentFactory.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; + + private long capacity; + private long grainSize; + private long descriptorOffset; + private long descriptorSize; + private long rgdOffset; + + private static final 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; + } + + public long getCapacity() { + return capacity; + } + + public long getGrainSize() { + return grainSize; + } + + public long getDescriptorOffset() + { + return descriptorOffset; + } +} Added: trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseFileDescriptor.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseFileDescriptor.java (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseFileDescriptor.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,33 @@ +package org.jnode.apps.vmware.disk.handler.sparse; + +import java.io.RandomAccessFile; + +import org.jnode.apps.vmware.disk.descriptor.Descriptor; +import org.jnode.apps.vmware.disk.handler.ExtentFactory; +import org.jnode.apps.vmware.disk.handler.FileDescriptor; + +/** + * Wrote from the 'Virtual Disk Format 1.0' specifications (from VMWare) + * + * @author Fabien DUMINY (fduminy at jnode dot org) + * + */ +public class SparseFileDescriptor extends FileDescriptor +{ + private final SparseExtentHeader header; + + public SparseFileDescriptor(Descriptor descriptor, RandomAccessFile raf, + ExtentFactory factory, SparseExtentHeader header) + { + super(descriptor, raf, factory); + + this.header = header; + } + + public SparseExtentHeader getHeader() { + return header; + } + + + +} Added: 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 (rev 0) +++ trunk/distr/src/apps/org/jnode/apps/vmware/disk/handler/sparse/SparseIOHandler.java 2007-03-18 19:33:19 UTC (rev 3142) @@ -0,0 +1,31 @@ +/** + * + */ +package org.jnode.apps.vmware.disk.handler.sparse; + +import java.io.IOException; +import java.util.HashMap; +import java.util.Map; + +import org.apache.log4j.Logger; +import org.jnode.apps.vmware.disk.descriptor.Descriptor; +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 SparseIOHandler extends IOHandler +{ + public static final Logger LOG = Logger.getLogger(SparseIOHandler.class); + + protected SparseIOHandler(Descriptor descriptor) + throws IOException + { + super(descriptor); + } +} \ 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-18 22:03:55
|
Revision: 3140 http://jnode.svn.sourceforge.net/jnode/?rev=3140&view=rev Author: fduminy Date: 2007-03-18 12:23:58 -0700 (Sun, 18 Mar 2007) Log Message: ----------- vmware disk read/write access : alpha version Modified Paths: -------------- trunk/distr/.classpath trunk/distr/build.xml Modified: trunk/distr/.classpath =================================================================== --- trunk/distr/.classpath 2007-03-17 18:21:32 UTC (rev 3139) +++ trunk/distr/.classpath 2007-03-18 19:23:58 UTC (rev 3140) @@ -7,5 +7,7 @@ <classpathentry kind="lib" path="/JNode-Shell/lib/bsh-2.0b4.jar"/> <classpathentry kind="src" path="/JNode-Shell"/> <classpathentry kind="src" path="/JNode-TextUI"/> + <classpathentry combineaccessrules="false" kind="src" path="/JNode-FS"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="output" path="build/classes"/> </classpath> Modified: trunk/distr/build.xml =================================================================== --- trunk/distr/build.xml 2007-03-17 18:21:32 UTC (rev 3139) +++ trunk/distr/build.xml 2007-03-18 19:23:58 UTC (rev 3140) @@ -7,12 +7,18 @@ <property name="my-src.dir" value="${basedir}/src"/> <property name="my.jar" value="${jnode-distr.jar}"/> + <property name="junit4.jar" value="${basedir}/lib/junit-4.1.jar"/> + <!-- Subproject specific classpath --> <path id="my-cp"> <pathelement location="${jnode-core.jar}"/> <pathelement location="${jnode-gui.jar}"/> <pathelement location="${jnode-textui.jar}"/> <pathelement location="${jnode-shell.jar}"/> + <pathelement location="${jnode-fs.jar}"/> + + <pathelement location="${junit4.jar}"/> + <path refid="cp"/> </path> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-03-18 12:34:50
|
Revision: 3139 http://jnode.svn.sourceforge.net/jnode/?rev=3139&view=rev Author: lsantha Date: 2007-03-17 11:21:32 -0700 (Sat, 17 Mar 2007) Log Message: ----------- Fixed reflective access to fields of type: static final String . Modified Paths: -------------- trunk/core/src/core/org/jnode/vm/VmReflection.java trunk/core/src/core/org/jnode/vm/classmgr/VmStatics.java Modified: trunk/core/src/core/org/jnode/vm/VmReflection.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmReflection.java 2007-03-08 21:11:03 UTC (rev 3138) +++ trunk/core/src/core/org/jnode/vm/VmReflection.java 2007-03-17 18:21:32 UTC (rev 3139) @@ -25,11 +25,7 @@ import org.jnode.vm.annotation.MagicPermission; import org.jnode.vm.annotation.PrivilegedActionPragma; -import org.jnode.vm.classmgr.VmField; -import org.jnode.vm.classmgr.VmInstanceField; -import org.jnode.vm.classmgr.VmMethod; -import org.jnode.vm.classmgr.VmStaticField; -import org.jnode.vm.classmgr.VmType; +import org.jnode.vm.classmgr.*; import org.jnode.vm.memmgr.VmHeapManager; import org.jnode.vm.memmgr.VmWriteBarrier; import org.jnode.vm.scheduler.VmProcessor; @@ -48,8 +44,16 @@ if (field.isStatic()) { final VmStaticField sf = (VmStaticField) field; initialize(sf); - return getStaticFieldAddress(sf).loadObjectReference().toObject(); - } else { + Object obj = getStaticFieldAddress(sf).loadObjectReference().toObject(); + //handles the reflective access to static final String fields, which didn't work. + if(obj != null && sf.isFinal() && field.getSignature().equals("Ljava/lang/String;")){ + if(obj instanceof VmConstString){ + VmConstString cs = (VmConstString) obj; + obj = Vm.getVm().getSharedStatics().getStringEntry(cs.getSharedStaticsIndex()); + } + } + return obj; + } else { final VmInstanceField inf = (VmInstanceField) field; return getInstanceFieldAddress(o, inf).loadObjectReference().toObject(); } Modified: trunk/core/src/core/org/jnode/vm/classmgr/VmStatics.java =================================================================== --- trunk/core/src/core/org/jnode/vm/classmgr/VmStatics.java 2007-03-08 21:11:03 UTC (rev 3138) +++ trunk/core/src/core/org/jnode/vm/classmgr/VmStatics.java 2007-03-17 18:21:32 UTC (rev 3139) @@ -156,7 +156,18 @@ return (VmType)getRawObject(idx); } - public final void setInt(int idx, int value) { + /** + * Get a String entry at the given index. + * + * @param idx + * @return the string + */ + public final String getStringEntry(int idx) { + allocator.testType(idx, TYPE_STRING); + return (String)getRawObject(idx); + } + + public final void setInt(int idx, int value) { allocator.testType(idx, TYPE_INT); if (statics[idx] != value) { if (locked) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-03-08 21:11:09
|
Revision: 3138 http://jnode.svn.sourceforge.net/jnode/?rev=3138&view=rev Author: lsantha Date: 2007-03-08 13:11:03 -0800 (Thu, 08 Mar 2007) Log Message: ----------- Added support for console stacking. Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java Modified: trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2007-03-08 21:09:02 UTC (rev 3137) +++ trunk/shell/src/shell/org/jnode/shell/command/driver/console/ConsoleCommand.java 2007-03-08 21:11:03 UTC (rev 3138) @@ -92,6 +92,8 @@ System.out.println(); if (listConsoles) { + conMgr.printConsoles(System.out); + /* final Set<String> consoleNames = conMgr.getConsoleNames(); System.out.println("Nr. of registered consoles: " + consoleNames.size()); @@ -103,6 +105,7 @@ + KeyEvent.getKeyText(console .getAcceleratorKeyCode())); } + */ } else if (newConsole) { if (isolateNewConsole) { try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-03-08 21:09:06
|
Revision: 3137 http://jnode.svn.sourceforge.net/jnode/?rev=3137&view=rev Author: lsantha Date: 2007-03-08 13:09:02 -0800 (Thu, 08 Mar 2007) Log Message: ----------- Added support for console stacking. Modified Paths: -------------- trunk/textui/src/textui/charva/awt/Toolkit.java Modified: trunk/textui/src/textui/charva/awt/Toolkit.java =================================================================== --- trunk/textui/src/textui/charva/awt/Toolkit.java 2007-03-08 21:08:29 UTC (rev 3136) +++ trunk/textui/src/textui/charva/awt/Toolkit.java 2007-03-08 21:09:02 UTC (rev 3137) @@ -155,7 +155,8 @@ final ShellManager sm = InitialNaming.lookup(ShellManager.NAME); final ConsoleManager conMgr = sm.getCurrentShell().getConsole().getManager(); final TextConsole console = (TextConsole) conMgr - .createConsole("charva", ConsoleManager.CreateOptions.TEXT); + .createConsole("charva", ConsoleManager.CreateOptions.TEXT | + ConsoleManager.CreateOptions.STACKED); console.addKeyboardListener(new KeyboardAdapter() { public void keyPressed(KeyboardEvent event) { if (event.isControlDown() && event.getKeyChar() == 'z') { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-03-08 21:08:32
|
Revision: 3136 http://jnode.svn.sourceforge.net/jnode/?rev=3136&view=rev Author: lsantha Date: 2007-03-08 13:08:29 -0800 (Thu, 08 Mar 2007) Log Message: ----------- Added support for console stacking. Modified Paths: -------------- trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java Modified: trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java 2007-03-08 21:07:31 UTC (rev 3135) +++ trunk/distr/src/apps/org/jnode/apps/editor/TextEditor.java 2007-03-08 21:08:29 UTC (rev 3136) @@ -37,7 +37,9 @@ ShellManager sm = InitialNaming.lookup(ShellManager.NAME); TextScreenConsoleManager manager = (TextScreenConsoleManager) sm.getCurrentShell().getConsole().getManager(); TextConsole console = manager.createConsole("editor", - ConsoleManager.CreateOptions.TEXT |ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR_IN); + ConsoleManager.CreateOptions.TEXT | + ConsoleManager.CreateOptions.STACKED | + ConsoleManager.CreateOptions.NO_SYSTEM_OUT_ERR_IN); manager.focus(console); TextEditor te = new TextEditor(console); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ls...@us...> - 2007-03-08 21:07:32
|
Revision: 3135 http://jnode.svn.sourceforge.net/jnode/?rev=3135&view=rev Author: lsantha Date: 2007-03-08 13:07:31 -0800 (Thu, 08 Mar 2007) Log Message: ----------- Added suupport for console stacking. Modified Paths: -------------- trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsole.java trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java Modified: trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java 2007-02-27 15:39:33 UTC (rev 3134) +++ trunk/core/src/driver/org/jnode/driver/console/ConsoleManager.java 2007-03-08 21:07:31 UTC (rev 3135) @@ -22,6 +22,7 @@ package org.jnode.driver.console; import java.util.Set; +import java.io.PrintStream; import org.jnode.driver.input.KeyboardListener; import org.jnode.driver.input.PointerListener; @@ -101,18 +102,21 @@ public void setParent(ConsoleManager parent); /** - * Option constants for use in {@link #createConsole(String, int)} + * Option constants for use in {@link org.jnode.driver.console.ConsoleManager#createConsole(String, int)} * @author Ewout Prangsma (ep...@us...) */ public static final class CreateOptions { - /** Create a text console */ + /** Create a text console. */ public static final int TEXT = 0x01; - /** Create a scrollable console */ + /** Create a scrollable console. */ public static final int SCROLLABLE = 0x02; - /** Do not claim System.out, err, in when focused */ + /** Do not claim System.out, err, in when focused. */ public static final int NO_SYSTEM_OUT_ERR_IN = 0x04; + + /** Stack console on the current screen */ + public static final int STACKED = 0x08; } /** @@ -122,4 +126,6 @@ * @return */ public Console createConsole(String name, int options); + + public void printConsoles(PrintStream ps); } Modified: trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsole.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsole.java 2007-02-27 15:39:33 UTC (rev 3134) +++ trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsole.java 2007-03-08 21:07:31 UTC (rev 3135) @@ -256,6 +256,8 @@ public void setAcceleratorKeyCode(int keyCode) { this.acceleratorKeyCode = keyCode; + if(mgr instanceof AbstractConsoleManager) + ((AbstractConsoleManager)mgr).restack(this); } public int getAcceleratorKeyCode() { Modified: trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java 2007-02-27 15:39:33 UTC (rev 3134) +++ trunk/core/src/driver/org/jnode/driver/console/spi/AbstractConsoleManager.java 2007-03-08 21:07:31 UTC (rev 3135) @@ -22,14 +22,9 @@ package org.jnode.driver.console.spi; import java.awt.event.InputEvent; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.Map; -import java.util.Set; +import java.awt.event.KeyEvent; +import java.util.*; +import java.io.PrintStream; import javax.naming.NameNotFoundException; @@ -77,13 +72,16 @@ private AbstractConsoleManager parent; + private final Map<Integer, Stack<Console>> stackMap = new HashMap<Integer, Stack<Console>>(); + private Stack<Console> currentStack; + /** * Initialize a new instance */ public AbstractConsoleManager() throws ConsoleException { try { - devMan = (DeviceManager) InitialNaming.lookup(DeviceManager.NAME); + devMan = InitialNaming.lookup(DeviceManager.NAME); openInput(devMan); } catch (NameNotFoundException ex) { throw new ConsoleException("DeviceManager not found", ex); @@ -93,7 +91,7 @@ protected final void initializeKeyboard(Device kbDev) { try { - this.kbApi = (KeyboardAPI) kbDev.getAPI(KeyboardAPI.class); + this.kbApi = kbDev.getAPI(KeyboardAPI.class); this.kbApi.addKeyboardListener(this); } catch (ApiNotFoundException ex) { BootLog.error("KeyboardAPI not found", ex); @@ -195,15 +193,54 @@ } } - public Console getConsoleByAccelerator(int keyCode) { - for (Console console : consoles.values()) { - if (console.getAcceleratorKeyCode() == keyCode) { - return console; + public void printConsoles(PrintStream ps) { + ArrayList<Integer> list = new ArrayList<Integer>(); + list.addAll(stackMap.keySet()); + Collections.sort(list); + for(Integer key : list){ + ps.println("Screen of " + KeyEvent.getKeyText(key) + ":"); + Stack<Console> stack = stackMap.get(key); + int t_ind = stack.size(); + for(int i = t_ind; i-- > 0;){ + Console console = stack.get(i); + String prefix = console == current ? " > " : + i == t_ind - 1? " * " : " "; + ps.println(prefix + console.getConsoleName()); } } + } + + public Console getConsoleByAccelerator(int keyCode) { + Stack<Console> stack = stackMap.get(keyCode); + if(stack != null && !stack.empty()){ + currentStack = stack; + return stack.peek(); + } + return null; } + protected void setAccelerator(Console console) { + for (int i = 0; i < 12; i++) { + final int keyCode = KeyEvent.VK_F1 + i; + Stack<Console> stack = stackMap.get(keyCode); + if (stack == null) { + stack = new Stack<Console>(); + } + + if (stack.empty()){ + stackMap.put(keyCode, stack); + stack.push(console); + currentStack = stack; + return; + } + } + } + + protected void stackConsole(Console console){ + if(currentStack != null) currentStack.push(console); + } + /** * Just keeping track of the One previous console will lead to lots of * problems. We need a stack, at least. Currently it is the client's @@ -219,13 +256,56 @@ if (current == console) { console.focusLost(new FocusEvent(FocusEvent.FOCUS_LOST)); } + consoles.remove(console.getConsoleName()); + if(currentStack != null && currentStack.peek() == console) { + currentStack.pop(); + if(!currentStack.empty()) { + current = currentStack.peek(); + focus(current); + } else { + Integer last_key = null; + for(Iterator<Map.Entry<Integer, Stack<Console>>> it = stackMap.entrySet().iterator(); it.hasNext(); ){ + Map.Entry<Integer, Stack<Console>> entry = it.next(); + if(entry.getValue().equals(currentStack)){ + last_key = entry.getKey(); + it.remove(); + break; + } + } + if(!stackMap.isEmpty()){ + Integer new_key = null; + List<Integer> keys = new ArrayList<Integer>(stackMap.keySet()); + Collections.sort(keys); + if(last_key == null){ + new_key = keys.get(0); + } else { + Collections.reverse(keys); + for(Integer k : keys){ + if(k < last_key){ + new_key = k; + break; + } + } + if(new_key == null){ + new_key = keys.get(keys.size() - 1); + } + } + + currentStack = stackMap.get(new_key); + current = currentStack.peek(); + focus(current); + } + } + } + if (current == console) { current = null; if (!consoles.isEmpty()) { - focus((Console)consoles.values().iterator().next()); + focus(consoles.values().iterator().next()); } } + if(parent != null && consoles.isEmpty()){ handleFocus(); } @@ -320,6 +400,36 @@ this.parent = (AbstractConsoleManager) parent; } + void restack(final AbstractConsole console){ + int accel = console.getAcceleratorKeyCode(); + if(accel == 0) return; + + //remove console + for(Iterator<Integer> iter = stackMap.keySet().iterator(); iter.hasNext(); ){ + Integer key = iter.next(); + if(key == accel) + return; //no restack needed + + Stack<Console> stack = stackMap.get(key); + if(stack.contains(console)){ + stack.remove(console); + + if(stack.empty()) + iter.remove(); + + break; + } + } + + //add the console to the specified screen + Stack<Console> stack = stackMap.get(accel); + if(stack == null){ + stack = new Stack<Console>(); + stackMap.put(accel, stack); + } + stack.push(console); + } + /** * This listener looks for registration of a keyboard device. * @@ -349,5 +459,4 @@ } } } - } Modified: trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java =================================================================== --- trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java 2007-02-27 15:39:33 UTC (rev 3134) +++ trunk/core/src/driver/org/jnode/driver/console/textscreen/TextScreenConsoleManager.java 2007-03-08 21:07:31 UTC (rev 3135) @@ -68,8 +68,13 @@ final TextScreen screen; screen = tsm.getSystemScreen().createCompatibleBufferScreen(); console = new TextScreenConsole(this, name, screen, options); - } - setAccelerator(console); + } + if ((options & CreateOptions.STACKED) != 0){ + stackConsole(console); + } else { + setAccelerator(console); + } + registerConsole(console); return console; } else { @@ -102,14 +107,16 @@ } } } - - private void setAccelerator(Console console) { + + /* + protected void setAccelerator(Console console) { for (int i = 0; i < 12; i++) { final int keyCode = KeyEvent.VK_F1 + i; if (getConsoleByAccelerator(keyCode) == null) { console.setAcceleratorKeyCode(keyCode); break; } - } + } } + */ } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2007-02-27 15:39:38
|
Revision: 3134 http://jnode.svn.sourceforge.net/jnode/?rev=3134&view=rev Author: galatnm Date: 2007-02-27 07:39:33 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Refactor code to be more generic. Modified Paths: -------------- trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbBluetoothDriver.java Added Paths: ----------- trunk/net/src/driver/org/jnode/driver/net/usb/UsbNetConstant.java trunk/net/src/driver/org/jnode/driver/net/usb/UsbNetDeviceToDriverMapper.java Removed Paths: ------------- trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbBluetoothDeviceToDriverMapper.java trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbNetConstant.java Copied: trunk/net/src/driver/org/jnode/driver/net/usb/UsbNetConstant.java (from rev 3133, trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbNetConstant.java) =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/usb/UsbNetConstant.java (rev 0) +++ trunk/net/src/driver/org/jnode/driver/net/usb/UsbNetConstant.java 2007-02-27 15:39:33 UTC (rev 3134) @@ -0,0 +1,10 @@ +package org.jnode.driver.net.usb; + +import org.jnode.driver.bus.usb.USBConstants; + +public interface UsbNetConstant extends USBConstants { + /* Subclass */ + public final static int US_SC_RF =0x01; + /* Protocols */ + public final static int US_PR_BLUETOOTH =0x01; /* Control/Bulk/Interrupt */ +} Added: trunk/net/src/driver/org/jnode/driver/net/usb/UsbNetDeviceToDriverMapper.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/usb/UsbNetDeviceToDriverMapper.java (rev 0) +++ trunk/net/src/driver/org/jnode/driver/net/usb/UsbNetDeviceToDriverMapper.java 2007-02-27 15:39:33 UTC (rev 3134) @@ -0,0 +1,45 @@ +package org.jnode.driver.net.usb; + +import org.apache.log4j.Logger; +import org.jnode.driver.Device; +import org.jnode.driver.DeviceToDriverMapper; +import org.jnode.driver.Driver; +import org.jnode.driver.bus.usb.InterfaceDescriptor; +import org.jnode.driver.bus.usb.USBConfiguration; +import org.jnode.driver.bus.usb.USBDevice; +import org.jnode.driver.bus.usb.USBInterface; +import org.jnode.driver.net.usb.bluetooth.UsbBluetoothDriver; +/** + * This class define driver finder for USB Wireless device. + * + * @author fabien L. + */ +public class UsbNetDeviceToDriverMapper implements DeviceToDriverMapper, UsbNetConstant { + + private static final Logger log = Logger.getLogger(UsbNetDeviceToDriverMapper.class); + + public Driver findDriver(Device device) { + + if (!(device instanceof USBDevice)) { + return null; + } + final USBDevice dev = (USBDevice) device; + final USBConfiguration conf = dev.getConfiguration(0); + final USBInterface intf = conf.getInterface(0); + final InterfaceDescriptor descr = intf.getDescriptor(); + if (descr.getInterfaceClass() != USB_CLASS_WIRELESS) { + return null; + } + log.debug("Found USB wireless device."); + if(descr.getInterfaceSubClass() == US_SC_RF){ + log.debug("Subclass " + descr.getInterfaceSubClass()); + return new UsbBluetoothDriver(); + } + return null; + } + + public int getMatchLevel() { + return MATCH_DEVCLASS; + } + +} Deleted: trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbBluetoothDeviceToDriverMapper.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbBluetoothDeviceToDriverMapper.java 2007-02-26 19:23:16 UTC (rev 3133) +++ trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbBluetoothDeviceToDriverMapper.java 2007-02-27 15:39:33 UTC (rev 3134) @@ -1,39 +0,0 @@ -package org.jnode.driver.net.usb.bluetooth; - -import org.jnode.driver.Device; -import org.jnode.driver.DeviceToDriverMapper; -import org.jnode.driver.Driver; -import org.jnode.driver.bus.usb.InterfaceDescriptor; -import org.jnode.driver.bus.usb.USBConfiguration; -import org.jnode.driver.bus.usb.USBDevice; -import org.jnode.driver.bus.usb.USBInterface; - -public class UsbBluetoothDeviceToDriverMapper implements DeviceToDriverMapper, UsbNetConstant { - - //private static final Logger log = Logger.getLogger(UsbBluetoothDeviceToDriverMapper.class); - - public Driver findDriver(Device device) { - - if (!(device instanceof USBDevice)) { - return null; - } - final USBDevice dev = (USBDevice) device; - final USBConfiguration conf = dev.getConfiguration(0); - final USBInterface intf = conf.getInterface(0); - final InterfaceDescriptor descr = intf.getDescriptor(); - if (descr.getInterfaceClass() != USB_CLASS_WIRELESS) { - return null; - } - //log.debug("Found usb wireless : " + descr); - if(descr.getInterfaceSubClass() == US_SC_RF){ - //log.debug("Found driver for subclass " + descr.getInterfaceSubClass()); - return new UsbBluetoothDriver(); - } - return null; - } - - public int getMatchLevel() { - return MATCH_DEVCLASS; - } - -} Modified: trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbBluetoothDriver.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbBluetoothDriver.java 2007-02-26 19:23:16 UTC (rev 3133) +++ trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbBluetoothDriver.java 2007-02-27 15:39:33 UTC (rev 3134) @@ -13,6 +13,7 @@ import org.jnode.driver.bus.usb.USBPacket; import org.jnode.driver.bus.usb.USBPipeListener; import org.jnode.driver.bus.usb.USBRequest; +import org.jnode.driver.net.usb.UsbNetConstant; import org.jnode.util.NumberUtils; public class UsbBluetoothDriver extends Driver implements USBPipeListener, UsbNetConstant { Deleted: trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbNetConstant.java =================================================================== --- trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbNetConstant.java 2007-02-26 19:23:16 UTC (rev 3133) +++ trunk/net/src/driver/org/jnode/driver/net/usb/bluetooth/UsbNetConstant.java 2007-02-27 15:39:33 UTC (rev 3134) @@ -1,10 +0,0 @@ -package org.jnode.driver.net.usb.bluetooth; - -import org.jnode.driver.bus.usb.USBConstants; - -public interface UsbNetConstant extends USBConstants { - /* Subclass */ - public final static int US_SC_RF =0x01; - /* Protocols */ - public final static int US_PR_BLUETOOTH =0x01; /* Control/Bulk/Interrupt */ -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2007-02-26 19:23:21
|
Revision: 3133 http://jnode.svn.sourceforge.net/jnode/?rev=3133&view=rev Author: konkubinaten Date: 2007-02-26 11:23:16 -0800 (Mon, 26 Feb 2007) Log Message: ----------- Create a new file if file is not present Modified Paths: -------------- trunk/distr/src/apps/org/jnode/apps/edit/Editor.java Modified: trunk/distr/src/apps/org/jnode/apps/edit/Editor.java =================================================================== --- trunk/distr/src/apps/org/jnode/apps/edit/Editor.java 2007-02-26 17:14:44 UTC (rev 3132) +++ trunk/distr/src/apps/org/jnode/apps/edit/Editor.java 2007-02-26 19:23:16 UTC (rev 3133) @@ -86,7 +86,14 @@ if(exists) readFile(file); - + else { + try { + file.createNewFile(); + } catch (IOException e) { + + } + } + updateTitle(file.getName()); textArea.requestFocus(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2007-02-26 17:14:46
|
Revision: 3132 http://jnode.svn.sourceforge.net/jnode/?rev=3132&view=rev Author: galatnm Date: 2007-02-26 09:14:44 -0800 (Mon, 26 Feb 2007) Log Message: ----------- Set keyboard interpreter during start device. Modified Paths: -------------- trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java Modified: trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java =================================================================== --- trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java 2007-02-20 19:20:58 UTC (rev 3131) +++ trunk/gui/src/driver/org/jnode/driver/input/usb/USBKeyboardDriver.java 2007-02-26 17:14:44 UTC (rev 3132) @@ -37,6 +37,7 @@ import org.jnode.driver.input.KeyboardAPI; import org.jnode.driver.input.KeyboardAPIAdapter; import org.jnode.driver.input.KeyboardInterpreter; +import org.jnode.driver.input.KeyboardInterpreterFactory; import org.jnode.util.ByteQueue; import org.jnode.util.ByteQueueProcessor; import org.jnode.util.ByteQueueProcessorThread; @@ -347,6 +348,7 @@ intPipe.asyncSubmit(req); // Register the PointerAPI + apiAdapter.setKbInterpreter(KeyboardInterpreterFactory.getDefaultKeyboardInterpreter()); dev.registerAPI(KeyboardAPI.class, apiAdapter); // Start the key event thread This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2007-02-20 19:21:01
|
Revision: 3131 http://jnode.svn.sourceforge.net/jnode/?rev=3131&view=rev Author: galatnm Date: 2007-02-20 11:20:58 -0800 (Tue, 20 Feb 2007) Log Message: ----------- Add descriptor for USB storage SCSI driver. 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-02-20 19:18:02 UTC (rev 3130) +++ trunk/all/conf/default-plugin-list.xml 2007-02-20 19:20:58 UTC (rev 3131) @@ -54,6 +54,7 @@ <plugin id="org.jnode.driver.block.ramdisk.command"/> <plugin id="org.jnode.driver.block.scsi.cdrom"/> <plugin id="org.jnode.driver.block.usb.storage"/> + <plugin id="org.jnode.driver.block.usb.storage.scsi"/> <plugin id="org.jnode.driver.bus.firewire"/> <plugin id="org.jnode.driver.bus.ide"/> <plugin id="org.jnode.driver.bus.ide.atapi"/> @@ -133,7 +134,7 @@ <plugin id="org.jnode.net.ipv4"/> <plugin id="org.jnode.net.ipv4.config"/> <plugin id="org.jnode.net.ipv4.core"/> - + <plugin id="com.jcraft.jsch"/> <plugin id="crypto-security"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2007-02-20 19:18:06
|
Revision: 3130 http://jnode.svn.sourceforge.net/jnode/?rev=3130&view=rev Author: galatnm Date: 2007-02-20 11:18:02 -0800 (Tue, 20 Feb 2007) Log Message: ----------- Add descriptor for USB storage SCSI driver. Added Paths: ----------- trunk/fs/descriptors/org.jnode.driver.block.usb.storage.scsi.xml Added: trunk/fs/descriptors/org.jnode.driver.block.usb.storage.scsi.xml =================================================================== --- trunk/fs/descriptors/org.jnode.driver.block.usb.storage.scsi.xml (rev 0) +++ trunk/fs/descriptors/org.jnode.driver.block.usb.storage.scsi.xml 2007-02-20 19:18:02 UTC (rev 3130) @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE plugin SYSTEM "jnode.dtd"> + +<plugin id="org.jnode.driver.block.usb.storage.scsi" + name="JNode USB Mass Storage SCSI drivers" + version="@VERSION@" + license-name="lgpl" + provider-name="JNode.org"> + + <requires> + <import plugin="org.jnode.driver.bus.usb"/> + <import plugin="org.jnode.driver.block"/> + <import plugin="org.jnode.driver.bus.scsi"/> + <import plugin="org.jnode.driver.block.usb.storage"/> + </requires> + + <runtime> + <library name="jnode-fs.jar"> + <export name="org.jnode.driver.block.usb.storage.scsi.*"/> + </library> + </runtime> + + <extension point="org.jnode.driver.mappers"> + <mapper class="org.jnode.driver.block.usb.storage.scsi.USBStorageSCSIDeviceToDriverMapper"/> + </extension> +</plugin> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ga...@us...> - 2007-02-20 19:16:43
|
Revision: 3129 http://jnode.svn.sourceforge.net/jnode/?rev=3129&view=rev Author: galatnm Date: 2007-02-20 11:16:35 -0800 (Tue, 20 Feb 2007) Log Message: ----------- Correct scsi driver detection. Modified Paths: -------------- trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageSCSIHostDriver.java trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDeviceToDriverMapper.java trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDriver.java Modified: trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageSCSIHostDriver.java =================================================================== --- trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageSCSIHostDriver.java 2007-02-17 17:30:42 UTC (rev 3128) +++ trunk/fs/src/driver/org/jnode/driver/block/usb/storage/USBStorageSCSIHostDriver.java 2007-02-20 19:16:35 UTC (rev 3129) @@ -9,16 +9,16 @@ * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but + * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., + * along with this library; If not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - + package org.jnode.driver.block.usb.storage; import org.apache.log4j.Logger; @@ -56,7 +56,7 @@ /** Storage specific device data */ private USBStorageDeviceData USBMassStorage; - + /** The SCSI device that i'm host of */ private USBStorageSCSIDevice scsiDevice; @@ -88,9 +88,9 @@ default: throw new DriverException("Transport protocol not implemented."); } - + USBEndPoint ep; - + for (int i = 0; i < conf.getInterface(0).getDescriptor().getNumEndPoints(); i++) { ep = conf.getInterface(0).getEndPoint(i); // Is it a bulk endpoint ? @@ -162,7 +162,7 @@ public void requestFailed(USBRequest request) { log.debug("USBStorageSCSIHostDriver failed with status:" + request.getStatus()); } - + private final class USBStorageSCSIHostBus extends Bus { /** @@ -170,10 +170,13 @@ */ public USBStorageSCSIHostBus(Device parent) { super(parent); - } + } } - - private final class USBStorageSCSIDevice extends SCSIDevice { + /** + * + * @author Fabien Lesire + */ + public final class USBStorageSCSIDevice extends SCSIDevice { private InquiryData inquiryResult; @@ -195,10 +198,10 @@ int res = this.executeCommand(new CDBTestUnitReady(),null,0,50000); log.debug("*** result : 0x" + NumberUtils.hex(res) + " ***" ); } - + /** - * Execute an INQUUIRY command. - * + * Execute an INQUIRY command. + * * @throws SCSIException * @throws TimeoutException * @throws InterruptedException @@ -211,12 +214,12 @@ inquiryResult = new InquiryData(inqData); log.debug("INQUIRY Data : " + inquiryResult.toString()); } - + protected final void capacity() throws SCSIException, TimeoutException, InterruptedException { log.info("*** Read capacity ***"); CapacityData cd = MMCUtils.readCapacity(this); log.debug("Capacity Data : " + cd.toString()); - + } /** Modified: trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDeviceToDriverMapper.java =================================================================== --- trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDeviceToDriverMapper.java 2007-02-17 17:30:42 UTC (rev 3128) +++ trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDeviceToDriverMapper.java 2007-02-20 19:16:35 UTC (rev 3129) @@ -9,22 +9,23 @@ * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but + * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., + * along with this library; If not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - + package org.jnode.driver.block.usb.storage.scsi; import org.apache.log4j.Logger; import org.jnode.driver.Device; import org.jnode.driver.DeviceToDriverMapper; import org.jnode.driver.Driver; +import org.jnode.driver.block.usb.storage.USBStorageSCSIHostDriver.USBStorageSCSIDevice; import org.jnode.driver.bus.scsi.SCSIDevice; import org.jnode.driver.bus.usb.USBDevice; @@ -39,8 +40,7 @@ */ public Driver findDriver(Device device) { log.debug("*** USBStorageSCSIDeviceToDriverMapper::findDriver ***"); - if ((device instanceof USBDevice) && (device instanceof SCSIDevice)) { - log.debug("*** find USBStorageSCSIDriver ***"); + if (device instanceof USBStorageSCSIDevice) { return new USBStorageSCSIDriver(); } return null; @@ -48,7 +48,7 @@ /** * Gets the matching level of this mapper. The mappers are queried in order * of match level. This will ensure the best available driver for a device. - * + * * @return One of the MATCH_xxx constants. * @see #MATCH_DEVICE_REVISION * @see #MATCH_DEVICE Modified: trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDriver.java =================================================================== --- trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDriver.java 2007-02-17 17:30:42 UTC (rev 3128) +++ trunk/fs/src/driver/org/jnode/driver/block/usb/storage/scsi/USBStorageSCSIDriver.java 2007-02-20 19:16:35 UTC (rev 3129) @@ -9,16 +9,16 @@ * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * - * This library is distributed in the hope that it will be useful, but + * This library is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public * License for more details. * * You should have received a copy of the GNU Lesser General Public License - * along with this library; If not, write to the Free Software Foundation, Inc., + * along with this library; If not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - + package org.jnode.driver.block.usb.storage.scsi; import java.io.IOException; @@ -82,16 +82,16 @@ } catch (DeviceAlreadyRegisteredException ex) { throw new DriverException(ex); } - + this.locked = false; this.changed = true; this.capacity = null; this.blockAlignment.setAlignment(2048); - + dev.registerAPI(RemovableDeviceAPI.class, this); dev.registerAPI(FSBlockDeviceAPI.class, blockAlignment); } - + @Override protected void stopDevice() throws DriverException { try { @@ -123,7 +123,8 @@ } public void read(long devOffset, ByteBuffer dest) throws IOException { - // TODO Auto-generated method stub + processChanged(); + if (capacity == null) { throw new IOException("No medium"); } } @@ -149,7 +150,7 @@ /** * Unlock the device. - * + * * @throws IOException */ public synchronized void unlock() throws IOException { @@ -196,13 +197,13 @@ } public boolean canLock() { - // TODO Auto-generated method stub - return false; + return true; } - + /** + * It's a removable device. + */ public boolean canEject() { - // TODO Auto-generated method stub - return false; + return true; } public void lock() throws IOException { @@ -211,8 +212,7 @@ } public boolean isLocked() { - // TODO Auto-generated method stub - return false; + return locked; } public void eject() throws IOException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-02-17 17:30:51
|
Revision: 3128 http://jnode.svn.sourceforge.net/jnode/?rev=3128&view=rev Author: fduminy Date: 2007-02-17 09:30:42 -0800 (Sat, 17 Feb 2007) Log Message: ----------- fixed bad path to lib for eclipse config file Modified Paths: -------------- trunk/distr/.classpath Modified: trunk/distr/.classpath =================================================================== --- trunk/distr/.classpath 2007-02-17 17:28:40 UTC (rev 3127) +++ trunk/distr/.classpath 2007-02-17 17:30:42 UTC (rev 3128) @@ -4,7 +4,7 @@ <classpathentry kind="src" path="/JNode-Core"/> <classpathentry kind="src" path="src/apps"/> <classpathentry kind="src" path="/JNode-GUI"/> - <classpathentry kind="lib" path="/JNode-Shell/lib/bsh-2.0b1.jar"/> + <classpathentry kind="lib" path="/JNode-Shell/lib/bsh-2.0b4.jar"/> <classpathentry kind="src" path="/JNode-Shell"/> <classpathentry kind="src" path="/JNode-TextUI"/> <classpathentry kind="output" path="build/classes"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-02-17 17:28:46
|
Revision: 3127 http://jnode.svn.sourceforge.net/jnode/?rev=3127&view=rev Author: fduminy Date: 2007-02-17 09:28:40 -0800 (Sat, 17 Feb 2007) Log Message: ----------- fixed bad path to lib for eclipse config file Modified Paths: -------------- trunk/shell/.classpath Modified: trunk/shell/.classpath =================================================================== --- trunk/shell/.classpath 2007-02-14 23:00:16 UTC (rev 3126) +++ trunk/shell/.classpath 2007-02-17 17:28:40 UTC (rev 3127) @@ -5,8 +5,7 @@ <classpathentry kind="lib" path="/JNode-Core/lib/log4j-1.2.8.jar"/> <classpathentry kind="lib" path="/JNode-Core/lib/junit.jar"/> <classpathentry kind="lib" path="/JNode-Core/lib/ant.jar"/> - <classpathentry kind="lib" path="lib/bsh-2.0b1.jar"/> + <classpathentry kind="lib" path="lib/bsh-2.0b4.jar"/> <classpathentry kind="lib" path="/JNode-Core/lib/ant-launcher.jar"/> - <classpathentry kind="lib" path="lib/groovy-all-1.0-RC-01.jar"/> <classpathentry kind="output" path="build/classes"/> </classpath> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <kon...@us...> - 2007-02-14 23:00:33
|
Revision: 3126 http://jnode.svn.sourceforge.net/jnode/?rev=3126&view=rev Author: konkubinaten Date: 2007-02-14 15:00:16 -0800 (Wed, 14 Feb 2007) Log Message: ----------- added getNanoTime to java.lang.System based on cpu cycles Modified Paths: -------------- trunk/core/src/classpath/vm/java/lang/VMSystem.java trunk/core/src/core/org/jnode/vm/Unsafe.java trunk/core/src/core/org/jnode/vm/VmSystem.java trunk/core/src/native/x86/unsafe.asm Added Paths: ----------- trunk/core/src/test/org/jnode/test/NanoTimeTest.java Modified: trunk/core/src/classpath/vm/java/lang/VMSystem.java =================================================================== --- trunk/core/src/classpath/vm/java/lang/VMSystem.java 2007-02-14 19:59:46 UTC (rev 3125) +++ trunk/core/src/classpath/vm/java/lang/VMSystem.java 2007-02-14 23:00:16 UTC (rev 3126) @@ -195,8 +195,7 @@ * @since 1.5 */ public static long nanoTime(){ - //TODO implement it - throw new UnsupportedOperationException(); + return VmSystem.nanoTime(); }; /** Modified: trunk/core/src/core/org/jnode/vm/Unsafe.java =================================================================== --- trunk/core/src/core/org/jnode/vm/Unsafe.java 2007-02-14 19:59:46 UTC (rev 3125) +++ trunk/core/src/core/org/jnode/vm/Unsafe.java 2007-02-14 23:00:16 UTC (rev 3126) @@ -742,4 +742,12 @@ VmProcessor.current().getArchitecture().getStackReader() .debugStackTrace(max); } + + /** + * return a nanosecond accurate timer based on the clock cycles + * of the CPU + * @return nanosecond accurate time + */ + public static native long getCpuCycles(); + } Modified: trunk/core/src/core/org/jnode/vm/VmSystem.java =================================================================== --- trunk/core/src/core/org/jnode/vm/VmSystem.java 2007-02-14 19:59:46 UTC (rev 3125) +++ trunk/core/src/core/org/jnode/vm/VmSystem.java 2007-02-14 23:00:16 UTC (rev 3126) @@ -90,6 +90,8 @@ private static volatile long currentTimeMillis; + private static long mhz = -1; + private static long rtcIncrement; private static RTCService rtcService; @@ -700,6 +702,47 @@ } /** + * <p> + * Returns the current value of a nanosecond-precise system timer. + * The value of the timer is an offset relative to some arbitrary fixed + * time, which may be in the future (making the value negative). This + * method is useful for timing events where nanosecond precision is + * required. This is achieved by calling this method before and after the + * event, and taking the difference betweent the two times: + * </p> + * <p> + * <code>long startTime = System.nanoTime();</code><br /> + * <code>... <emph>event code</emph> ...</code><br /> + * <code>long endTime = System.nanoTime();</code><br /> + * <code>long duration = endTime - startTime;</code><br /> + * </p> + * <p> + * Note that the value is only nanosecond-precise, and not accurate; there + * is no guarantee that the difference between two values is really a + * nanosecond. Also, the value is prone to overflow if the offset + * exceeds 2^63. + * </p> + * + * @return the time of a system timer in nanoseconds. + * @since 1.5 + */ + public static long nanoTime(){ + if (mhz == -1) { + long start = Unsafe.getCpuCycles(); + try { + Thread.sleep(1000); + } catch (Exception e) { + // set some "random" value + mhz = 1000; + } + long end = Unsafe.getCpuCycles(); + mhz = end - start; + mhz = mhz / 1000000; + } + return Unsafe.getCpuCycles() / mhz; + } + + /** * Returns the number of milliseconds since booting the kernel of JNode. * * This method does not call any other method and CAN be used in the Modified: trunk/core/src/native/x86/unsafe.asm =================================================================== --- trunk/core/src/native/x86/unsafe.asm 2007-02-14 19:59:46 UTC (rev 3125) +++ trunk/core/src/native/x86/unsafe.asm 2007-02-14 23:00:16 UTC (rev 3126) @@ -355,4 +355,9 @@ ; static native int readKdbInput(); GLABEL Q43org5jnode2vm6Unsafe23readKdbInput2e2829I jmp kdb_recv_char - \ No newline at end of file + +; public static native long getCpuCycles(); +GLABEL Q43org5jnode2vm6Unsafe23getCpuCycles2e2829J + rdtsc + ret + Added: trunk/core/src/test/org/jnode/test/NanoTimeTest.java =================================================================== --- trunk/core/src/test/org/jnode/test/NanoTimeTest.java (rev 0) +++ trunk/core/src/test/org/jnode/test/NanoTimeTest.java 2007-02-14 23:00:16 UTC (rev 3126) @@ -0,0 +1,53 @@ +/* + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.test; + + +/** + * @author Peter + */ +public class NanoTimeTest { + + public static void main(String[] args) { + NanoTimeTest ntt = new NanoTimeTest(); + ntt.run(500); + ntt.run(1000); + ntt.run(1500); + ntt.run(2000); + ntt.run(2500); + ntt.run(3000); + } + + public void run(int ms) { + long start = System.nanoTime(); + try { + Thread.sleep(ms); + } catch (Exception e) { + e.printStackTrace(); + } + long end = System.nanoTime(); + long nano = end - start; + + System.out.println("The test ran " + ms + "ms and according to " + + "System.nanoTime that was " + nano + "ns"); + long p = Math.abs(ms * 1000L - nano) / ms; + System.out.println("Aberration : " + p + " promill"); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-02-14 19:59:49
|
Revision: 3125 http://jnode.svn.sourceforge.net/jnode/?rev=3125&view=rev Author: fduminy Date: 2007-02-14 11:59:46 -0800 (Wed, 14 Feb 2007) Log Message: ----------- fixed bug found when typing "locale <tab>" (infinite loop?) Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/help/argument/ListArgument.java Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/ListArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/ListArgument.java 2007-02-11 22:32:31 UTC (rev 3124) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/ListArgument.java 2007-02-14 19:59:46 UTC (rev 3125) @@ -64,9 +64,12 @@ StringBuilder result = new StringBuilder(toStringArgument(items.iterator().next())); for (T item : items) { - while (!isPartOfArgument(item, result.toString())) { + while ((result.length() != 0) && + !isPartOfArgument(item, result.toString())) + { // shorten the result until it matches - result = result.deleteCharAt(result.length()); + // remove the last character : + result.setLength(result.length() - 1); } } log.debug("\nresult="+result); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-02-11 22:32:32
|
Revision: 3124 http://jnode.svn.sourceforge.net/jnode/?rev=3124&view=rev Author: fduminy Date: 2007-02-11 14:32:31 -0800 (Sun, 11 Feb 2007) Log Message: ----------- - IBMPartitionTypes is now an enum instead of an interface - added some functions for disk partitionning - extracted partionning functions from FDiskCommand to put them in the class PartitionHelper Added Paths: ----------- trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java trunk/fs/src/fs/org/jnode/partitions/help/ trunk/fs/src/fs/org/jnode/partitions/help/argument/ trunk/fs/src/fs/org/jnode/partitions/help/argument/IBMPartitionTypeArgument.java Added: trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java =================================================================== --- trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java (rev 0) +++ trunk/fs/src/fs/org/jnode/partitions/command/PartitionHelper.java 2007-02-11 22:32:31 UTC (rev 3124) @@ -0,0 +1,668 @@ +package org.jnode.partitions.command; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.jnode.driver.ApiNotFoundException; +import org.jnode.driver.DeviceManager; +import org.jnode.driver.DeviceNotFoundException; +import org.jnode.driver.DriverException; +import org.jnode.driver.block.BlockDeviceAPI; +import org.jnode.driver.bus.ide.IDEConstants; +import org.jnode.driver.bus.ide.IDEDevice; +import org.jnode.fs.fat.BootSector; +import org.jnode.fs.fat.GrubBootSector; +import org.jnode.partitions.ibm.IBMPartitionTable; +import org.jnode.partitions.ibm.IBMPartitionTableEntry; +import org.jnode.partitions.ibm.IBMPartitionTypes; + +/** + * + * @author Fabien DUMINY (fduminy at jnode.org) + * + */ +public class PartitionHelper +{ + public static final boolean BYTES = true; + 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) + throws DeviceNotFoundException, ApiNotFoundException, IOException + { + this.current = (IDEDevice)dm.getDevice(deviceId); + this.dm = dm; + this.api = current.getAPI(BlockDeviceAPI.class); + + read(); + } + + public void initMbr() throws DeviceNotFoundException, ApiNotFoundException, + IOException + { + System.out.println("Initialize MBR ..."); + + BootSector oldMBR = bs; + bs = new GrubBootSector(PLAIN_MASTER_BOOT_SECTOR); + + if (IBMPartitionTable.containsPartitionTable(MBR.array())) { + System.out.println("This device already contains a partition table. Copy the already existing partitions."); + + for (int i = 0; i < 4; i++) { + final IBMPartitionTableEntry oldEntry = oldMBR.getPartition(i); + modifyPartition(i, oldEntry.getBootIndicator(), oldEntry.getStartLba(), + oldEntry.getNrSectors(), SECTORS, + oldEntry.getSystemIndicator()); + } + } else { + bs.getPartition(0).setSystemIndicator(IBMPartitionTypes.PARTTYPE_EMPTY); + bs.getPartition(1).setSystemIndicator(IBMPartitionTypes.PARTTYPE_EMPTY); + bs.getPartition(2).setSystemIndicator(IBMPartitionTypes.PARTTYPE_EMPTY); + bs.getPartition(3).setSystemIndicator(IBMPartitionTypes.PARTTYPE_EMPTY); + } + } + + public void write() throws IOException + { + bs.write(api); + + // restart the device + try { + dm.stop(current); + dm.start(current); + } catch (DeviceNotFoundException e) { + e.printStackTrace(); + } catch (DriverException e) { + e.printStackTrace(); + } + } + + private void read() throws IOException, ApiNotFoundException + { + //read the MBR + this.MBR = ByteBuffer.allocate(IDEConstants.SECTOR_SIZE); + api.read(0, MBR); + + bs = new BootSector(MBR.array()); + } + + private void checkMBR() throws IOException + { + if (!IBMPartitionTable.containsPartitionTable(MBR.array())) + throw new IOException("This device doesn't contain a valid MBR, use --initmbr."); + } + + public void modifyPartition(int id, boolean bootIndicator, + long start, long size, + boolean sizeUnit, + IBMPartitionTypes fs) + throws IOException + { + checkMBR(); + + long nbSectors = size; + if(sizeUnit == BYTES) + { + nbSectors = size / IDEConstants.SECTOR_SIZE; + if((size % IDEConstants.SECTOR_SIZE) > 0) + { + nbSectors++; + } + } + + IBMPartitionTableEntry entry = bs.getPartition(id); + entry.setBootIndicator(bootIndicator); + entry.setSystemIndicator(fs); + entry.setStartLba(start); + entry.setNrSectors(nbSectors); + } + + public int getNbPartitions() + { + return bs.getNbPartitions(); + } + + public void deletePartition(int partNumber) throws IOException + { + checkMBR(); + bs.getPartition(partNumber).setSystemIndicator(IBMPartitionTypes.PARTTYPE_EMPTY); + } + + public void toggleBootable(int partNumber) throws IOException + { + checkMBR(); + + // save the current state for the targeted partition + boolean currentStatus = bs.getPartition(partNumber).getBootIndicator(); + + // erase all the states + for (int i = 0; i < 4; i++) { + bs.getPartition(i).setBootIndicator(false); + } + + // put back the reversed state for the targeted partition + bs.getPartition(partNumber).setBootIndicator(!currentStatus); + } + + + private static final byte PLAIN_MASTER_BOOT_SECTOR[] = + { + (byte)0xEB, + (byte)0x48, + (byte)0x90, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x03, + (byte)0x02, + (byte)0xFF, + (byte)0x00, + (byte)0x00, + (byte)0x80, + (byte)0x01, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x08, + (byte)0xFA, + (byte)0xEA, + (byte)0x50, + (byte)0x7C, + (byte)0x00, + (byte)0x00, + (byte)0x31, + (byte)0xC0, + (byte)0x8E, + (byte)0xD8, + (byte)0x8E, + (byte)0xD0, + (byte)0xBC, + (byte)0x00, + (byte)0x20, + (byte)0xFB, + (byte)0xA0, + (byte)0x40, + (byte)0x7C, + (byte)0x3C, + (byte)0xFF, + (byte)0x74, + (byte)0x02, + (byte)0x88, + (byte)0xC2, + (byte)0x52, + (byte)0xBE, + (byte)0x76, + (byte)0x7D, + (byte)0xE8, + (byte)0x34, + (byte)0x01, + (byte)0xF6, + (byte)0xC2, + (byte)0x80, + (byte)0x74, + (byte)0x54, + (byte)0xB4, + (byte)0x41, + (byte)0xBB, + (byte)0xAA, + (byte)0x55, + (byte)0xCD, + (byte)0x13, + (byte)0x5A, + (byte)0x52, + (byte)0x72, + (byte)0x49, + (byte)0x81, + (byte)0xFB, + (byte)0x55, + (byte)0xAA, + (byte)0x75, + (byte)0x43, + (byte)0xA0, + (byte)0x41, + (byte)0x7C, + (byte)0x84, + (byte)0xC0, + (byte)0x75, + (byte)0x05, + (byte)0x83, + (byte)0xE1, + (byte)0x01, + (byte)0x74, + (byte)0x37, + (byte)0x66, + (byte)0x8B, + (byte)0x4C, + (byte)0x10, + (byte)0xBE, + (byte)0x05, + (byte)0x7C, + (byte)0xC6, + (byte)0x44, + (byte)0xFF, + (byte)0x01, + (byte)0x66, + (byte)0x8B, + (byte)0x1E, + (byte)0x44, + (byte)0x7C, + (byte)0xC7, + (byte)0x04, + (byte)0x10, + (byte)0x00, + (byte)0xC7, + (byte)0x44, + (byte)0x02, + (byte)0x01, + (byte)0x00, + (byte)0x66, + (byte)0x89, + (byte)0x5C, + (byte)0x08, + (byte)0xC7, + (byte)0x44, + (byte)0x06, + (byte)0x00, + (byte)0x70, + (byte)0x66, + (byte)0x31, + (byte)0xC0, + (byte)0x89, + (byte)0x44, + (byte)0x04, + (byte)0x66, + (byte)0x89, + (byte)0x44, + (byte)0x0C, + (byte)0xB4, + (byte)0x42, + (byte)0xCD, + (byte)0x13, + (byte)0x72, + (byte)0x05, + (byte)0xBB, + (byte)0x00, + (byte)0x70, + (byte)0xEB, + (byte)0x7D, + (byte)0xB4, + (byte)0x08, + (byte)0xCD, + (byte)0x13, + (byte)0x73, + (byte)0x0A, + (byte)0xF6, + (byte)0xC2, + (byte)0x80, + (byte)0x0F, + (byte)0x84, + (byte)0xF3, + (byte)0x00, + (byte)0xE9, + (byte)0x8D, + (byte)0x00, + (byte)0xBE, + (byte)0x05, + (byte)0x7C, + (byte)0xC6, + (byte)0x44, + (byte)0xFF, + (byte)0x00, + (byte)0x66, + (byte)0x31, + (byte)0xC0, + (byte)0x88, + (byte)0xF0, + (byte)0x40, + (byte)0x66, + (byte)0x89, + (byte)0x44, + (byte)0x04, + (byte)0x31, + (byte)0xD2, + (byte)0x88, + (byte)0xCA, + (byte)0xC1, + (byte)0xE2, + (byte)0x02, + (byte)0x88, + (byte)0xE8, + (byte)0x88, + (byte)0xF4, + (byte)0x40, + (byte)0x89, + (byte)0x44, + (byte)0x08, + (byte)0x31, + (byte)0xC0, + (byte)0x88, + (byte)0xD0, + (byte)0xC0, + (byte)0xE8, + (byte)0x02, + (byte)0x66, + (byte)0x89, + (byte)0x04, + (byte)0x66, + (byte)0xA1, + (byte)0x44, + (byte)0x7C, + (byte)0x66, + (byte)0x31, + (byte)0xD2, + (byte)0x66, + (byte)0xF7, + (byte)0x34, + (byte)0x88, + (byte)0x54, + (byte)0x0A, + (byte)0x66, + (byte)0x31, + (byte)0xD2, + (byte)0x66, + (byte)0xF7, + (byte)0x74, + (byte)0x04, + (byte)0x88, + (byte)0x54, + (byte)0x0B, + (byte)0x89, + (byte)0x44, + (byte)0x0C, + (byte)0x3B, + (byte)0x44, + (byte)0x08, + (byte)0x7D, + (byte)0x3C, + (byte)0x8A, + (byte)0x54, + (byte)0x0D, + (byte)0xC0, + (byte)0xE2, + (byte)0x06, + (byte)0x8A, + (byte)0x4C, + (byte)0x0A, + (byte)0xFE, + (byte)0xC1, + (byte)0x08, + (byte)0xD1, + (byte)0x8A, + (byte)0x6C, + (byte)0x0C, + (byte)0x5A, + (byte)0x8A, + (byte)0x74, + (byte)0x0B, + (byte)0xBB, + (byte)0x00, + (byte)0x70, + (byte)0x8E, + (byte)0xC3, + (byte)0x31, + (byte)0xDB, + (byte)0xB8, + (byte)0x01, + (byte)0x02, + (byte)0xCD, + (byte)0x13, + (byte)0x72, + (byte)0x2A, + (byte)0x8C, + (byte)0xC3, + (byte)0x8E, + (byte)0x06, + (byte)0x48, + (byte)0x7C, + (byte)0x60, + (byte)0x1E, + (byte)0xB9, + (byte)0x00, + (byte)0x01, + (byte)0x8E, + (byte)0xDB, + (byte)0x31, + (byte)0xF6, + (byte)0x31, + (byte)0xFF, + (byte)0xFC, + (byte)0xF3, + (byte)0xA5, + (byte)0x1F, + (byte)0x61, + (byte)0xFF, + (byte)0x26, + (byte)0x42, + (byte)0x7C, + (byte)0xBE, + (byte)0x7C, + (byte)0x7D, + (byte)0xE8, + (byte)0x40, + (byte)0x00, + (byte)0xEB, + (byte)0x0E, + (byte)0xBE, + (byte)0x81, + (byte)0x7D, + (byte)0xE8, + (byte)0x38, + (byte)0x00, + (byte)0xEB, + (byte)0x06, + (byte)0xBE, + (byte)0x8B, + (byte)0x7D, + (byte)0xE8, + (byte)0x30, + (byte)0x00, + (byte)0xBE, + (byte)0x90, + (byte)0x7D, + (byte)0xE8, + (byte)0x2A, + (byte)0x00, + (byte)0xEB, + (byte)0xFE, + (byte)0x47, + (byte)0x52, + (byte)0x55, + (byte)0x42, + (byte)0x20, + (byte)0x00, + (byte)0x47, + (byte)0x65, + (byte)0x6F, + (byte)0x6D, + (byte)0x00, + (byte)0x48, + (byte)0x61, + (byte)0x72, + (byte)0x64, + (byte)0x20, + (byte)0x44, + (byte)0x69, + (byte)0x73, + (byte)0x6B, + (byte)0x00, + (byte)0x52, + (byte)0x65, + (byte)0x61, + (byte)0x64, + (byte)0x00, + (byte)0x20, + (byte)0x45, + (byte)0x72, + (byte)0x72, + (byte)0x6F, + (byte)0x72, + (byte)0x00, + (byte)0xBB, + (byte)0x01, + (byte)0x00, + (byte)0xB4, + (byte)0x0E, + (byte)0xCD, + (byte)0x10, + (byte)0xAC, + (byte)0x3C, + (byte)0x00, + (byte)0x75, + (byte)0xF4, + (byte)0xC3, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x24, + (byte)0x12, + (byte)0x0F, + (byte)0x09, + (byte)0x00, + (byte)0xBE, + (byte)0xBD, + (byte)0x7D, + (byte)0x31, + (byte)0xC0, + (byte)0xCD, + (byte)0x13, + (byte)0x46, + (byte)0x8A, + (byte)0x0C, + (byte)0x80, + (byte)0xF9, + (byte)0x00, + (byte)0x75, + (byte)0x0F, + (byte)0xBE, + (byte)0xDA, + (byte)0x7D, + (byte)0xE8, + (byte)0xC6, + (byte)0xFF, + (byte)0xEB, + (byte)0x94, + (byte)0x46, + (byte)0x6C, + (byte)0x6F, + (byte)0x70, + (byte)0x70, + (byte)0x79, + (byte)0x00, + (byte)0xBB, + (byte)0x00, + (byte)0x70, + (byte)0xB8, + (byte)0x01, + (byte)0x02, + (byte)0xB5, + (byte)0x00, + (byte)0xB6, + (byte)0x00, + (byte)0xCD, + (byte)0x13, + (byte)0x72, + (byte)0xD7, + (byte)0xB6, + (byte)0x01, + (byte)0xB5, + (byte)0x4F, + (byte)0xE9, + (byte)0xDD, + (byte)0xFE, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x00, + (byte)0x55, + (byte)0xAA }; +} Added: trunk/fs/src/fs/org/jnode/partitions/help/argument/IBMPartitionTypeArgument.java =================================================================== --- trunk/fs/src/fs/org/jnode/partitions/help/argument/IBMPartitionTypeArgument.java (rev 0) +++ trunk/fs/src/fs/org/jnode/partitions/help/argument/IBMPartitionTypeArgument.java 2007-02-11 22:32:31 UTC (rev 3124) @@ -0,0 +1,43 @@ +package org.jnode.partitions.help.argument; + +import java.util.Arrays; +import java.util.Collection; + +import org.jnode.partitions.ibm.IBMPartitionTypes; +import org.jnode.shell.help.ParsedArguments; +import org.jnode.shell.help.argument.ListArgument; + + +public class IBMPartitionTypeArgument extends ListArgument<IBMPartitionTypes> +{ + public IBMPartitionTypeArgument(String name, String description) + { + super(name, description, false); + } + + public IBMPartitionTypes getArgValue(String value) + { + int fs = Integer.parseInt(value, 16); + return IBMPartitionTypes.valueOf(fs); + } + + @Override + protected String toStringArgument(IBMPartitionTypes arg) { + return Integer.toHexString(arg.getCode()); + } + + @Override + protected Collection<IBMPartitionTypes> getValues() { + return Arrays.asList(IBMPartitionTypes.values()); + } + + @Override + public int compare(IBMPartitionTypes choice1, IBMPartitionTypes choice2) { + return choice1.getCode() - choice2.getCode(); + } + + @Override + protected boolean isPartOfArgument(IBMPartitionTypes argument, String part) { + return toStringArgument(argument).startsWith(part); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-02-11 22:30:53
|
Revision: 3123 http://jnode.svn.sourceforge.net/jnode/?rev=3123&view=rev Author: fduminy Date: 2007-02-11 14:30:51 -0800 (Sun, 11 Feb 2007) Log Message: ----------- added argument for values of type size, which allow use of multipliers (like K, M, G, ...) Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/help/argument/SizeArgument.java Added: trunk/shell/src/shell/org/jnode/shell/help/argument/SizeArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/SizeArgument.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/SizeArgument.java 2007-02-11 22:30:51 UTC (rev 3123) @@ -0,0 +1,76 @@ +/* + * $Id: LongArgument.java 2945 2006-12-20 08:51:17Z qades $ + * + * JNode.org + * Copyright (C) 2003-2006 JNode.org + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation; either version 2.1 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; If not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +package org.jnode.shell.help.argument; + +import org.jnode.shell.help.ParsedArguments; +import org.jnode.util.NumberUtils; + +/** + * @author Ewout Prangsma (ep...@us...) + */ +/** + * @author Ewout Prangsma (ep...@us...) + * @author Fabien DUMINY (fduminy at jnode.org) + * + * TODO should be factorized with IntegerArgument + */ +public class SizeArgument extends LongArgument { + public SizeArgument(String name, String description, boolean multi, + String min, String max) + { + this(name, description, multi, NumberUtils.getSize(min), + NumberUtils.getSize(max)); + } + + public SizeArgument(String name, String description, boolean multi, + long min, long max) + { + super(name, description, multi, min, max); + checkSize("min", min); + checkSize("max", max); + } + + public SizeArgument(String name, String description, boolean multi) { + this(name, description, multi, 0L, Long.MAX_VALUE); + } + + public SizeArgument(String name, String description) { + this(name, description, SINGLE); + } + + public boolean hasSizeUnit(ParsedArguments args) { + return (NumberUtils.getSizeUnit(this.getValue(args)) != null); + } + + @Override + protected long getLongValue(String value) { + return NumberUtils.getSize(value); + } + + protected void checkSize(String name, long size) + { + if(size < 0) + { + throw new IllegalArgumentException(name+" can't be negative"); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-02-11 22:29:52
|
Revision: 3122 http://jnode.svn.sourceforge.net/jnode/?rev=3122&view=rev Author: fduminy Date: 2007-02-11 14:29:51 -0800 (Sun, 11 Feb 2007) Log Message: ----------- added min/max properties for validation of int/long arguments Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/help/argument/IntegerArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/LongArgument.java Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/IntegerArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/IntegerArgument.java 2007-02-11 22:28:59 UTC (rev 3121) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/IntegerArgument.java 2007-02-11 22:29:51 UTC (rev 3122) @@ -27,22 +27,65 @@ /** * @author Ewout Prangsma (ep...@us...) + * @author Fabien DUMINY (fduminy at jnode.org) + * + * TODO should be factorized with LongArgument */ public class IntegerArgument extends Argument { + private int min; + private int max; + public IntegerArgument(String name, String description) { + this(name, description, SINGLE); + } + public IntegerArgument(String name, String description, boolean multi) { - super(name, description, multi); + this(name, description, multi, Integer.MIN_VALUE, Integer.MAX_VALUE); } - public IntegerArgument(String name, String description) { - super(name, description); + public IntegerArgument(String name, String description, boolean multi, int min, int max) { + super(name, description, multi); + if(min > max) + { + throw new IllegalArgumentException("min(value:"+min+") > max(value:"+max+")"); + } + + this.min = min; + this.max = max; } - + public String complete(String partial) { return partial; + } + + @Override + protected boolean isValidValue(String value) { + int val = -1; + try { + val = getIntValue(value); + } catch (NumberFormatException e) { + return false; + } + + if(val < min) + { + return false; + } + + if(val > max) + { + return false; + } + + return true; } public int getInteger(ParsedArguments args) { - return Integer.parseInt(this.getValue(args)); + return getIntValue(this.getValue(args)); } + + protected int getIntValue(String value) + { + return Integer.parseInt(value); + } } Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/LongArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/LongArgument.java 2007-02-11 22:28:59 UTC (rev 3121) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/LongArgument.java 2007-02-11 22:29:51 UTC (rev 3122) @@ -27,21 +27,68 @@ /** * @author Ewout Prangsma (ep...@us...) */ +/** + * @author Ewout Prangsma (ep...@us...) + * @author Fabien DUMINY (fduminy at jnode.org) + * + * TODO should be factorized with IntegerArgument + */ public class LongArgument extends Argument { - - public LongArgument(String name, String description, boolean multi) { - super(name, description, multi); - } + private long min; + private long max; + + public LongArgument(String name, String description) { + this(name, description, SINGLE); + } - public LongArgument(String name, String description) { - super(name, description); - } + public LongArgument(String name, String description, boolean multi) { + this(name, description, multi, Long.MIN_VALUE, Long.MAX_VALUE); + } - public String complete(String partial) { - return partial; - } - - public long getLong(ParsedArguments args) { - return Long.parseLong(this.getValue(args)); - } + public LongArgument(String name, String description, boolean multi, + long min, long max) { + super(name, description, multi); + if(min > max) + { + throw new IllegalArgumentException("min(value:"+min+") > max(value:"+max+")"); + } + + this.min = min; + this.max = max; + } + + public String complete(String partial) { + return partial; + } + + @Override + protected boolean isValidValue(String value) { + long val = -1; + try { + val = getLongValue(value); + } catch (NumberFormatException e) { + return false; + } + + if(val < min) + { + return false; + } + + if(val > max) + { + return false; + } + + return true; + } + + public long getLong(ParsedArguments args) { + return getLongValue(this.getValue(args)); + } + + protected long getLongValue(String value) + { + return Long.parseLong(value); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-02-11 22:29:01
|
Revision: 3121 http://jnode.svn.sourceforge.net/jnode/?rev=3121&view=rev Author: fduminy Date: 2007-02-11 14:28:59 -0800 (Sun, 11 Feb 2007) Log Message: ----------- reworked Argument whith small set of possible values around the class ListArgument Added Paths: ----------- trunk/shell/src/shell/org/jnode/shell/help/argument/ListArgument.java Added: trunk/shell/src/shell/org/jnode/shell/help/argument/ListArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/ListArgument.java (rev 0) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/ListArgument.java 2007-02-11 22:28:59 UTC (rev 3121) @@ -0,0 +1,116 @@ +package org.jnode.shell.help.argument; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.apache.log4j.Level; +import org.apache.log4j.Logger; +import org.jnode.shell.help.Argument; +import org.jnode.shell.help.ParsedArguments; + +public abstract class ListArgument<T> extends Argument + implements Comparator<T> +{ + private static final Logger log = Logger.getLogger(ListArgument.class); + + static + { + log.setLevel(Level.DEBUG); + } + + public ListArgument(String name, String description, boolean multi) + { + super(name, description, multi); + } + + public ListArgument(String name, String description) + { + this(name, description, false); + } + + @Override + final public String complete(String partial) { + final List<T> result = new ArrayList<T>(); + for (T choice : getValues()) { + if (isPartOfArgument(choice, partial)) { + result.add(choice); + } + } + + Collections.sort(result, this); + return completeFromList(partial, result); + } + + final protected String completeFromList(String partial, Collection<T> list) { + log.debug("list.size()="+list.size()); + if (list.size() == 0) // none found + return partial; + + if (list.size() == 1) return toStringArgument(list.iterator().next()) + " "; + + // list matching + list(list); + + // return the common part, i.e. complete as much as possible + return common(list); + } + + final protected String common(Collection<T> items) { + if (items.isEmpty()) + return ""; + + StringBuilder result = new StringBuilder(toStringArgument(items.iterator().next())); + for (T item : items) { + while (!isPartOfArgument(item, result.toString())) { + // shorten the result until it matches + result = result.deleteCharAt(result.length()); + } + } + log.debug("\nresult="+result); + return result.toString(); + } + + final public void list(Collection<T> items) { + String[] result = new String[items.size()]; + int i = 0; + for(T item : items) + { + result[i] = item.toString(); + i++; + } + list(result); + } + + final public T getArgValue(ParsedArguments cmdLine) + { + String value = getValue(cmdLine); + if(value == null) + { + return null; + } + + return getArgValue(value); + } + + abstract protected Collection<T> getValues(); + abstract public T getArgValue(String value); + abstract protected boolean isPartOfArgument(T argument, String part); + abstract protected String toStringArgument(T arg); + abstract public int compare(T choice1, T choice2); + + @Override + final protected boolean isValidValue(String value) { + if ((value == null) || "".equals(value)) + return true; + + try { + return (getArgValue(value) != null); + } catch (IllegalArgumentException e) { + return false; + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fd...@us...> - 2007-02-11 22:28:12
|
Revision: 3120 http://jnode.svn.sourceforge.net/jnode/?rev=3120&view=rev Author: fduminy Date: 2007-02-11 14:28:11 -0800 (Sun, 11 Feb 2007) Log Message: ----------- reworked Argument whith small set of possible values around the class ListArgument Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/help/argument/CountryArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/LanguageArgument.java trunk/shell/src/shell/org/jnode/shell/help/argument/StringListArgument.java Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/CountryArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/CountryArgument.java 2007-02-11 22:25:20 UTC (rev 3119) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/CountryArgument.java 2007-02-11 22:28:11 UTC (rev 3120) @@ -22,6 +22,7 @@ package org.jnode.shell.help.argument; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Locale; @@ -34,11 +35,15 @@ .getISOCountries()); public CountryArgument(String name, String description, boolean multi) { - super(name, description, multi, validCountries); + super(name, description, multi); } public CountryArgument(String name, String description) { - super(name, description, validCountries); + super(name, description); } + @Override + protected Collection<String> getValues() { + return validCountries; + } } Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/LanguageArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/LanguageArgument.java 2007-02-11 22:25:20 UTC (rev 3119) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/LanguageArgument.java 2007-02-11 22:28:11 UTC (rev 3120) @@ -22,6 +22,7 @@ package org.jnode.shell.help.argument; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.Locale; @@ -33,11 +34,15 @@ private static final List<String> languages = Arrays.asList(Locale.getISOLanguages()); public LanguageArgument(String name, String description, boolean multi) { - super(name, description, multi, languages); + super(name, description, multi); } public LanguageArgument(String name, String description) { - super(name, description, languages); + super(name, description); } + @Override + protected Collection<String> getValues() { + return languages; + } } Modified: trunk/shell/src/shell/org/jnode/shell/help/argument/StringListArgument.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/help/argument/StringListArgument.java 2007-02-11 22:25:20 UTC (rev 3119) +++ trunk/shell/src/shell/org/jnode/shell/help/argument/StringListArgument.java 2007-02-11 22:28:11 UTC (rev 3120) @@ -1,50 +1,41 @@ package org.jnode.shell.help.argument; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; +import java.util.Collection; -import org.jnode.shell.help.Argument; +import org.jnode.shell.help.ParsedArguments; -public class StringListArgument extends Argument { - - private final List<String> choices; - - public StringListArgument(String name, String description, boolean multi, List<String> choices) { +abstract public class StringListArgument extends ListArgument<String> +{ + public StringListArgument(String name, String description, boolean multi) { super(name, description, multi); - this.choices = choices; } - public StringListArgument(String name, String description, List<String> choices) { - this(name, description, false, choices); + public StringListArgument(String name, String description) { + super(name, description, false); } - public StringListArgument(String name, String description, boolean multi, String[] choices) { - this(name, description, multi, Arrays.asList(choices)); + @Override + public String getArgValue(String value) { + return value; } - - public StringListArgument(String name, String description, String[] choices) { - this(name, description, false, choices); + + @Override + protected String toStringArgument(String arg) + { + return arg; } - - public String complete(String partial) { - final List<String> result = new ArrayList<String>(); - for (String choice : choices) { - if (choice.startsWith(partial)) { - result.add(choice); - } - } - - Collections.sort(result); - return complete(partial, result); + + @Override + protected boolean isPartOfArgument(String argument, String part) + { + return argument.startsWith(part); } - - protected boolean isValidValue(String choice) { - if ((choice == null) || "".equals(choice)) - return true; - - return choices.contains(choice); + + @Override + public int compare(String choice1, String choice2) + { + return choice1.compareTo(choice2); } + abstract protected Collection<String> getValues(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |