X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FUnixRuntime.java;h=8031f58e5fabffab82a27daa58980a605c1b1357;hp=0bc102809b0cb88ac0dda49f5854a35444cb5008;hb=8f20cbd09cb3b11fe8bd65e66d02f3453940c996;hpb=404ead23c2104bbed240370653a5308849b98905 diff --git a/src/org/ibex/nestedvm/UnixRuntime.java b/src/org/ibex/nestedvm/UnixRuntime.java index 0bc1028..8031f58 100644 --- a/src/org/ibex/nestedvm/UnixRuntime.java +++ b/src/org/ibex/nestedvm/UnixRuntime.java @@ -5,8 +5,6 @@ package org.ibex.nestedvm; import org.ibex.nestedvm.util.*; -// HACK: This is ugly, this stuff needs to be in org.ibex.util or something -import org.ibex.classgen.util.Sort; import java.io.*; import java.util.*; import java.net.*; @@ -46,7 +44,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 +78,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 +1168,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?"":"/"); - } - System.err.println("reverseMap: " + f + " => " + ret); - return ret; - } - private File hostFile(String path) { char sep = File.separatorChar; if(sep != '/') { @@ -1435,11 +1445,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);