implement truncate and fstat better
authorbrian <brian@brianweb.net>
Thu, 27 May 2004 04:44:44 +0000 (21:44 -0700)
committerbrian <brian@brianweb.net>
Thu, 27 May 2004 04:44:44 +0000 (21:44 -0700)
darcs-hash:20040527044444-24bed-ce50a73d70d3db7f788906294ab86e15f4a16926.gz

src/org/ibex/nestedvm/Runtime.java
src/org/ibex/nestedvm/UnixRuntime.java
src/org/ibex/nestedvm/util/InodeCache.java
src/org/ibex/nestedvm/util/Platform.java
src/org/ibex/nestedvm/util/Seekable.java

index ff33ba9..5a1a895 100644 (file)
@@ -732,10 +732,9 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable {
             return hostFSDirFD(f,data);
         }
         
             return hostFSDirFD(f,data);
         }
         
-        // FIXME: Truncate
         final Seekable.File sf;
         try {
         final Seekable.File sf;
         try {
-            sf = new Seekable.File(f,write);
+            sf = new Seekable.File(f,write,(flags & O_TRUNC) != 0);
         } catch(FileNotFoundException e) {
             if(e.getMessage() != null && e.getMessage().indexOf("Permission denied") >= 0) throw new ErrnoException(EACCES);
             return null;
         } catch(FileNotFoundException e) {
             if(e.getMessage() != null && e.getMessage().indexOf("Permission denied") >= 0) throw new ErrnoException(EACCES);
             return null;
@@ -810,12 +809,11 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable {
     }
     
     /** The stat/fstat syscall helper */
     }
     
     /** The stat/fstat syscall helper */
-    // FIXME: Populate uid/gid/nlink
     int stat(FStat fs, int addr) throws FaultException {
         memWrite(addr+0,(fs.dev()<<16)|(fs.inode()&0xffff)); // st_dev (top 16), // st_ino (bottom 16)
         memWrite(addr+4,((fs.type()&0xf000))|(fs.mode()&0xfff)); // st_mode
     int stat(FStat fs, int addr) throws FaultException {
         memWrite(addr+0,(fs.dev()<<16)|(fs.inode()&0xffff)); // st_dev (top 16), // st_ino (bottom 16)
         memWrite(addr+4,((fs.type()&0xf000))|(fs.mode()&0xfff)); // st_mode
-        memWrite(addr+8,1<<16); // st_nlink (top 16) // st_uid (bottom 16)
-        memWrite(addr+12,0); // st_gid (top 16) // st_rdev (bottom 16)
+        memWrite(addr+8,fs.nlink()<<16|fs.uid()&0xffff); // st_nlink (top 16) // st_uid (bottom 16)
+        memWrite(addr+12,fs.gid()<<16|0); // st_gid (top 16) // st_rdev (bottom 16)
         memWrite(addr+16,fs.size()); // st_size
         memWrite(addr+20,fs.atime()); // st_atime
         // memWrite(addr+24,0) // st_spare1
         memWrite(addr+16,fs.size()); // st_size
         memWrite(addr+20,fs.atime()); // st_atime
         // memWrite(addr+24,0) // st_spare1
index b4f651d..24a5ece 100644 (file)
@@ -533,7 +533,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         return n;
     }
     
         return n;
     }
     
-    // FIXME: UDP is totally broken
+    // FEATURE: UDP is totally broken
     
     static class SocketFD extends FD {
         public static final int TYPE_STREAM = 0;
     
     static class SocketFD extends FD {
         public static final int TYPE_STREAM = 0;
@@ -1094,7 +1094,7 @@ public abstract class UnixRuntime extends Runtime implements Cloneable {
         }
 
         public synchronized Object exec(UnixRuntime r, String path) throws ErrnoException {
         }
 
         public synchronized Object exec(UnixRuntime r, String path) throws ErrnoException {
-            // FIXME: Hideous hack to make a standalone busybox possible
+            // HACK: Hideous hack to make a standalone busybox possible
             if(path.equals("bin/busybox") && Boolean.valueOf(getSystemProperty("nestedvm.busyboxhack")).booleanValue())
                 return r.getClass();
             FStat fstat = stat(r,path);
             if(path.equals("bin/busybox") && Boolean.valueOf(getSystemProperty("nestedvm.busyboxhack")).booleanValue())
                 return r.getClass();
             FStat fstat = stat(r,path);
index cb1d7f0..a169d5f 100644 (file)
@@ -1,7 +1,5 @@
 package org.ibex.nestedvm.util;
 
 package org.ibex.nestedvm.util;
 
-import java.util.Arrays;
-
 // Based on the various org.xwt.util.* classes by Adam Megacz
 
 public class InodeCache {
 // Based on the various org.xwt.util.* classes by Adam Megacz
 
 public class InodeCache {
index f9dca10..ed59627 100644 (file)
@@ -13,7 +13,7 @@ public abstract class Platform {
     static {
         float version;
         try {
     static {
         float version;
         try {
-            version = Float.parseFloat(System.getProperty("java.specification.version"));
+            version = Float.valueOf(System.getProperty("java.specification.version")).floatValue();
         } catch(Exception e) {
             System.err.println("WARNING: " + e + " while trying to find jvm version -  assuming 1.1");
             version = 1.1f;
         } catch(Exception e) {
             System.err.println("WARNING: " + e + " while trying to find jvm version -  assuming 1.1");
             version = 1.1f;
@@ -49,10 +49,17 @@ public abstract class Platform {
     public static String timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong, Locale l) { return p._timeZoneGetDisplayName(tz,dst,showlong,l); }
     public static String timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong) { return timeZoneGetDisplayName(tz,dst,showlong,Locale.getDefault()); }
     
     public static String timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong, Locale l) { return p._timeZoneGetDisplayName(tz,dst,showlong,l); }
     public static String timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong) { return timeZoneGetDisplayName(tz,dst,showlong,Locale.getDefault()); }
     
+    abstract RandomAccessFile _truncatedRandomAccessFile(File f, String mode) throws IOException;
+    public static RandomAccessFile truncatedRandomAccessFile(File f, String mode) throws IOException { return p._truncatedRandomAccessFile(f,mode); }
+    
+    // FEATURE: Make sure GCClass can get rid of uncalled superclass methdos
+    
     static class Jdk11 extends Platform {
         boolean _atomicCreateFile(File f) throws IOException {
     static class Jdk11 extends Platform {
         boolean _atomicCreateFile(File f) throws IOException {
-            // FIXME: Just do this non-atomicly
-            throw new RuntimeException("FIXME");
+            // This is not atomic, but its the best we can do on jdk 1.1
+            if(f.exists()) return false;
+            new FileOutputStream(f).close();
+            return true;
         }
         void _socketHalfClose(Socket s, boolean output) throws IOException {
             throw new IOException("half closing sockets not supported");
         }
         void _socketHalfClose(Socket s, boolean output) throws IOException {
             throw new IOException("half closing sockets not supported");
@@ -79,6 +86,11 @@ public abstract class Platform {
             if(off > 0) sb.append(":").append(off);
             return sb.toString();
         }
             if(off > 0) sb.append(":").append(off);
             return sb.toString();
         }
+        
+        RandomAccessFile _truncatedRandomAccessFile(File f, String mode) throws IOException {
+            new FileOutputStream(f).close();
+            return new RandomAccessFile(f,mode);
+        }
     }
     
     static class Jdk12 extends Jdk11 {
     }
     
     static class Jdk12 extends Jdk11 {
@@ -89,6 +101,12 @@ public abstract class Platform {
         String _timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong, Locale l) {
             return tz.getDisplayName(dst,showlong ? TimeZone.LONG : TimeZone.SHORT, l);
         }
         String _timeZoneGetDisplayName(TimeZone tz, boolean dst, boolean showlong, Locale l) {
             return tz.getDisplayName(dst,showlong ? TimeZone.LONG : TimeZone.SHORT, l);
         }
+        
+        RandomAccessFile _truncatedRandomAccessFile(File f, String mode) throws IOException {
+            RandomAccessFile raf = new RandomAccessFile(f,mode);
+            raf.setLength(0);
+            return raf;
+        }       
     }
     
     static class Jdk13 extends Jdk12 {
     }
     
     static class Jdk13 extends Jdk12 {
index cf8cca7..51c7a39 100644 (file)
@@ -66,15 +66,13 @@ public abstract class Seekable {
         private final RandomAccessFile raf;
         
         public File(String fileName) throws IOException { this(fileName,false); }
         private final RandomAccessFile raf;
         
         public File(String fileName) throws IOException { this(fileName,false); }
-        public File(String fileName, boolean writable) throws IOException { this(new java.io.File(fileName),writable); }    
+        public File(String fileName, boolean writable) throws IOException { this(new java.io.File(fileName),writable,false); }    
         
         
-        public File(java.io.File file, boolean writable) throws IOException {
-            raf = new RandomAccessFile(file,writable ? "rw" : "r");
+        public File(java.io.File file, boolean writable, boolean truncate) throws IOException {
+            String mode = writable ? "rw" : "r";
+            raf = truncate ? Platform.truncatedRandomAccessFile(file,mode) : new RandomAccessFile(file,mode);
         }
         
         }
         
-        // NOTE: RandomAccessFile.setLength() is a Java2 function
-        public void setLength(int n) throws IOException { raf.setLength(n); }
-        
         public int read(byte[] buf, int offset, int length) throws IOException { return raf.read(buf,offset,length); }
         public int write(byte[] buf, int offset, int length) throws IOException { raf.write(buf,offset,length); return length; }
         public void seek(int pos) throws IOException{ raf.seek(pos); }
         public int read(byte[] buf, int offset, int length) throws IOException { return raf.read(buf,offset,length); }
         public int write(byte[] buf, int offset, int length) throws IOException { raf.write(buf,offset,length); return length; }
         public void seek(int pos) throws IOException{ raf.seek(pos); }