X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fnestedvm%2FUnixRuntime.java;h=73275ae79f854ef33c35cf1292945c39af7daef6;hp=0291ab8154cbdc6e3094f1e1ce5a97c520fe15d1;hb=bd37ef12130e7b21c7b5fa4c200f332f9490c4d2;hpb=b9a61c0d0d94182340ac416abea42d07bc64baff;ds=sidebyside diff --git a/src/org/ibex/nestedvm/UnixRuntime.java b/src/org/ibex/nestedvm/UnixRuntime.java index 0291ab8..73275ae 100644 --- a/src/org/ibex/nestedvm/UnixRuntime.java +++ b/src/org/ibex/nestedvm/UnixRuntime.java @@ -164,7 +164,10 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { } FD _open(String path, int flags, int mode) throws ErrnoException { - return gs.open(this,normalizePath(path),flags,mode); + path = normalizePath(path); + FD fd = gs.open(this,path,flags,mode); + if (fd != null && path != null) fd.setNormalizedPath(path); + return fd; } private int sys_getppid() { @@ -703,7 +706,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { return n; } - void _closedFD(FD fd) { + void _preCloseFD(FD fd) { // release all fcntl locks on this file Seekable s = fd.seekable(); if (s == null) return; @@ -720,6 +723,13 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { } catch (IOException e) { throw new RuntimeException(e); } } + void _postCloseFD(FD fd) { + if (fd.isMarkedForDeleteOnClose()) { + try { gs.unlink(this, fd.getNormalizedPath()); } + catch (Throwable t) {} + } + } + /** Implements the F_GETLK and F_SETLK cases of fcntl syscall. * If l_start = 0 and l_len = 0 the lock refers to the entire file. * Uses GlobalState to ensure locking across processes in the same JVM. @@ -1352,6 +1362,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { addMount("/dev",new DevFS()); addMount("/resource",new ResourceFS()); + addMount("/cygdrive",new CygdriveFS()); } } @@ -1591,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(); @@ -1617,7 +1628,21 @@ public abstract class UnixRuntime extends Runtime implements Cloneable { File f = hostFile(path); if(r.sm != null && !r.sm.allowUnlink(f)) throw new ErrnoException(EPERM); if(!f.exists()) throw new ErrnoException(ENOENT); - if(!f.delete()) throw new ErrnoException(EPERM); + if(!f.delete()) { + // Can't delete file immediately, so mark for + // delete on close all matching FDs + boolean marked = false; + for(int i=0;i '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);