return hostFSDirFD(f,data);
}
- // FIXME: Truncate
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;
}
/** 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
- 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
return n;
}
- // FIXME: UDP is totally broken
+ // FEATURE: UDP is totally broken
static class SocketFD extends FD {
public static final int TYPE_STREAM = 0;
}
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);
package org.ibex.nestedvm.util;
-import java.util.Arrays;
-
// Based on the various org.xwt.util.* classes by Adam Megacz
public class InodeCache {
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;
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 {
- // 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");
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 {
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 {
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); }