From: David Crawshaw Date: Sat, 18 Nov 2006 01:56:08 +0000 (-0800) Subject: add ftruncate() syscall X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=commitdiff_plain;h=6d6d9f59a2e6fe3b9e5b3563efcf0124bea4a672 add ftruncate() syscall darcs-hash:20061118015608-0c629-c674bc92b29c3a46e6ff2cea2d9bbaf92ff9fd9e.gz --- diff --git a/src/org/ibex/nestedvm/Runtime.java b/src/org/ibex/nestedvm/Runtime.java index bc55744..f286620 100644 --- a/src/org/ibex/nestedvm/Runtime.java +++ b/src/org/ibex/nestedvm/Runtime.java @@ -809,6 +809,17 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { copyout(buf,addr,n); return n; } + + /** The ftruncate syscall */ + private int sys_ftruncate(int fdn, long length) { + if (fdn < 0 || fdn >= OPEN_MAX) return -EBADFD; + if (fds[fdn] == null) return -EBADFD; + + Seekable seekable = fds[fdn].seekable(); + if (length < 0 || seekable == null) return -EINVAL; + try { seekable.resize(length); } catch (IOException e) { return -EIO; } + return 0; + } /** The close syscall */ private int sys_close(int fdn) { @@ -1058,6 +1069,7 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { case SYS_close: return sys_close(a); case SYS_read: return sys_read(a,b,c); case SYS_lseek: return sys_lseek(a,b,c); + case SYS_ftruncate: return sys_ftruncate(a,b); case SYS_getpid: return sys_getpid(); case SYS_calljava: return sys_calljava(a,b,c,d); case SYS_gettimeofday: return sys_gettimeofday(a,b); diff --git a/src/org/ibex/nestedvm/util/Seekable.java b/src/org/ibex/nestedvm/util/Seekable.java index bc21a55..cacca0a 100644 --- a/src/org/ibex/nestedvm/util/Seekable.java +++ b/src/org/ibex/nestedvm/util/Seekable.java @@ -13,6 +13,10 @@ public abstract class Seekable { public abstract void seek(int pos) throws IOException; public abstract void close() throws IOException; public abstract int pos() throws IOException; + + public void resize(long length) throws IOException { + throw new IOException("resize not implemented for " + getClass()); + } public int read() throws IOException { byte[] buf = new byte[1]; @@ -83,6 +87,7 @@ public abstract class Seekable { public int pos() throws IOException { return (int) raf.getFilePointer(); } public int length() throws IOException { return (int)raf.length(); } public void close() throws IOException { raf.close(); } + public void resize(long length) throws IOException { raf.setLength(length); } } public static class InputStream extends Seekable {