From a6a5a73b92822166c7656cec347edcf6e78c6a1a Mon Sep 17 00:00:00 2001 From: brian Date: Fri, 26 May 2006 20:37:30 -0700 Subject: [PATCH] allow access to every "root" on the host fs (ie other drives on windows) darcs-hash:20060527033730-24bed-bad4dac4073942cabd2f444a2712998b4a752044.gz --- src/org/ibex/nestedvm/UnixRuntime.java | 101 ++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 44 deletions(-) diff --git a/src/org/ibex/nestedvm/UnixRuntime.java b/src/org/ibex/nestedvm/UnixRuntime.java index 6fb22b0..2852f35 100644 --- a/src/org/ibex/nestedvm/UnixRuntime.java +++ b/src/org/ibex/nestedvm/UnixRuntime.java @@ -46,7 +46,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { if(!exec) { gs = defaultGS; String userdir = Platform.getProperty("user.dir"); - cwd = (userdir == null || Platform.getProperty("nestedvm.root") != null) ? null : HostFS.reverseMap(userdir); + cwd = userdir == null ? null : gs.mapHostPath(userdir); if(cwd == null) cwd = "/"; cwd = cwd.substring(1); } @@ -80,9 +80,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { String tmp; if(!envHas("USER",extra) && Platform.getProperty("user.name") != null) defaults[n++] = "USER=" + Platform.getProperty("user.name"); - if(!envHas("HOME",extra) && (tmp=Platform.getProperty("user.home")) != null && (tmp=HostFS.reverseMap(tmp)) != null) + if(!envHas("HOME",extra) && (tmp=Platform.getProperty("user.home")) != null && (tmp=gs.mapHostPath(tmp)) != null) defaults[n++] = "HOME=" + tmp; - if(!envHas("TMPDIR",extra) && (tmp=Platform.getProperty("java.io.tmpdir")) != null && (tmp=HostFS.reverseMap(tmp)) != null) + if(!envHas("TMPDIR",extra) && (tmp=Platform.getProperty("java.io.tmpdir")) != null && (tmp=gs.mapHostPath(tmp)) != null) defaults[n++] = "TMPDIR=" + tmp; if(!envHas("SHELL",extra)) defaults[n++] = "SHELL=/bin/sh"; if(!envHas("TERM",extra) && !win32Hacks) defaults[n++] = "TERM=vt100"; @@ -1170,12 +1170,63 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { public GlobalState(int maxProcs, boolean defaultMounts) { tasks = new UnixRuntime[maxProcs+1]; if(defaultMounts) { - addMount("/",new HostFS()); + File root = null; + if(Platform.getProperty("nestedvm.root") != null) { + root = new File(Platform.getProperty("nestedvm.root")); + if(!root.isDirectory()) throw new IllegalArgumentException("nestedvm.root is not a directory"); + } else { + String cwd = Platform.getProperty("user.dir"); + root = Platform.getRoot(new File(cwd != null ? cwd : ".")); + } + + addMount("/",new HostFS(root)); + + if(Platform.getProperty("nestedvm.root") == null) { + File[] roots = Platform.listRoots(); + for(int i=0;i=0;i--) { + FS fs = i == mps.length ? root : mps[i].fs; + String path = i == mps.length ? "" : mps[i].path; + if(!(fs instanceof HostFS)) continue; + File fsroot = ((HostFS)fs).getRoot(); + if(!fsroot.isAbsolute()) fsroot = new File(fsroot.getAbsolutePath()); + if(f.getPath().startsWith(fsroot.getPath())) { + char sep = File.separatorChar; + String child = f.getPath().substring(fsroot.getPath().length()); + if(sep != '/') { + char[] child_ = child.toCharArray(); + for(int j=0;j=0;i--) ret += (String) vec.elementAt(i) + (i==0?"":"/"); - } - return ret; - } - private File hostFile(String path) { char sep = File.separatorChar; if(sep != '/') { @@ -1432,11 +1447,9 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { return new File(root,path); } - public HostFS() { this(hostRootDir()); } public HostFS(String root) { this(new File(root)); } public HostFS(File root) { this.root = root; } - public FD open(UnixRuntime r, String path, int flags, int mode) throws ErrnoException { final File f = hostFile(path); return r.hostFSOpen(f,flags,mode,this); -- 1.7.10.4