From bd37ef12130e7b21c7b5fa4c200f332f9490c4d2 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Thu, 13 Mar 2008 01:01:18 -0700 Subject: [PATCH] add /cygdrive support darcs-hash:20080313080118-0c629-c7fccbd04a4100055217aaaa7ac2920fc9c35878.gz --- src/org/ibex/nestedvm/UnixRuntime.java | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/org/ibex/nestedvm/UnixRuntime.java b/src/org/ibex/nestedvm/UnixRuntime.java index fed82d0..73275ae 100644 --- a/src/org/ibex/nestedvm/UnixRuntime.java +++ b/src/org/ibex/nestedvm/UnixRuntime.java @@ -1362,6 +1362,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { addMount("/dev",new DevFS()); addMount("/resource",new ResourceFS()); + addMount("/cygdrive",new CygdriveFS()); } } @@ -1601,7 +1602,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { protected File root; public File getRoot() { return root; } - private File hostFile(String path) { + protected File hostFile(String path) { char sep = File.separatorChar; if(sep != '/') { char buf[] = path.toCharArray(); @@ -1687,6 +1688,23 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { public int myDev() { return devno; } } } + + /* Implements the Cygwin notation for accessing MS Windows drive letters + * in a unix path. The path /cygdrive/c/myfile is converted to C:\file. + * As there is no POSIX standard for this, little checking is done. */ + public static class CygdriveFS extends HostFS { + protected File hostFile(String path) { + final char drive = path.charAt(0); + + if (drive < 'a' || drive > 'z' || path.charAt(1) != '/') + return null; + + path = drive + ":" + path.substring(1).replace('/', '\\'); + return new File(path); + } + + public CygdriveFS() { super("/"); } + } private static void putInt(byte[] buf, int off, int n) { buf[off+0] = (byte)((n>>>24)&0xff); -- 1.7.10.4