Fix two bugs in UnixRuntime and change Pipe class to be public
[nestedvm.git] / src / org / ibex / nestedvm / UnixRuntime.java
index fed82d0..adddc51 100644 (file)
@@ -1,5 +1,5 @@
 // Copyright 2000-2005 the Contributors, as shown in the revision logs.
-// Licensed under the Apache Public Source License 2.0 ("the License").
+// Licensed under the Apache License 2.0 ("the License").
 // You may not use this file except in compliance with the License.
 
 package org.ibex.nestedvm;
@@ -195,7 +195,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
     
     private int sys_access(int cstring, int mode) throws ErrnoException, ReadFaultException {
         // FEATURE: sys_access
-        return gs.stat(this,cstring(cstring)) == null ? -ENOENT : 0;
+        return gs.stat(this,normalizePath(cstring(cstring))) == null ? -ENOENT : 0;
     }
     
     private int sys_realpath(int inAddr, int outAddr) throws FaultException {
@@ -563,7 +563,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         return 0;   
     }
     
-    static class Pipe {
+    public static class Pipe {
         private final byte[] pipebuf = new byte[PIPE_BUF*4];
         private int readPos;
         private int writePos;
@@ -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);
@@ -1793,7 +1811,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
             if(path.startsWith("fd/")) {
                 int n;
                 try {
-                    n = Integer.parseInt(path.substring(4));
+                    n = Integer.parseInt(path.substring(3));
                 } catch(NumberFormatException e) {
                     return null;
                 }