From: David Crawshaw Date: Sun, 7 Jan 2007 16:10:20 +0000 (-0800) Subject: support fsync() X-Git-Url: http://git.megacz.com/?p=nestedvm.git;a=commitdiff_plain;h=67c7e733423baf297e3a6684eed50af00e2c8255 support fsync() darcs-hash:20070107161020-0c629-f8cb28cb78260e588b7a1a5515d6a3a6c940a7f0.gz --- diff --git a/src/org/ibex/nestedvm/Runtime.java b/src/org/ibex/nestedvm/Runtime.java index f8a1579..201fde9 100644 --- a/src/org/ibex/nestedvm/Runtime.java +++ b/src/org/ibex/nestedvm/Runtime.java @@ -1048,6 +1048,22 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { } } + final int fsync(int fdn) { + if(fdn < 0 || fdn >= OPEN_MAX) return -EBADFD; + if(fds[fdn] == null) return -EBADFD; + FD fd = fds[fdn]; + + Seekable s = fd.seekable(); + if (s == null) return -EINVAL; + + try { + s.sync(); + return 0; + } catch (IOException e) { + return -EIO; + } + } + /** The syscall dispatcher. The should be called by subclasses when the syscall instruction is invoked. syscall should be the contents of V0 and a, b, c, and d should be @@ -1097,6 +1113,7 @@ public abstract class Runtime implements UsermodeConstants,Registers,Cloneable { case SYS_getgid: return sys_getgid(); case SYS_getegid: return sys_getegid(); + case SYS_fsync: return fsync(a); case SYS_memcpy: memcpy(a,b,c); return a; case SYS_memset: memset(a,b,c); return a; diff --git a/src/org/ibex/nestedvm/UsermodeConstants.java b/src/org/ibex/nestedvm/UsermodeConstants.java index 07c03f4..0385965 100644 --- a/src/org/ibex/nestedvm/UsermodeConstants.java +++ b/src/org/ibex/nestedvm/UsermodeConstants.java @@ -90,6 +90,7 @@ public interface UsermodeConstants { public static final int SYS_setgroups = 88; public static final int SYS_resolve_ip = 89; public static final int SYS_setsid = 90; + public static final int SYS_fsync = 91; public static final int AF_UNIX = 1; public static final int AF_INET = 2; public static final int SOCK_STREAM = 1; diff --git a/src/org/ibex/nestedvm/support.s b/src/org/ibex/nestedvm/support.s index 3a50fac..9ff9216 100644 --- a/src/org/ibex/nestedvm/support.s +++ b/src/org/ibex/nestedvm/support.s @@ -195,3 +195,4 @@ SYSCALL(alarm) SYSCALL_R(getgroups) SYSCALL_R(setsid) SYSCALL_R2(__resolve_ip_r,SYS_resolve_ip) +SYSCALL_R(fsync) diff --git a/src/org/ibex/nestedvm/support_aux.c b/src/org/ibex/nestedvm/support_aux.c index 0be4859..54181e9 100644 --- a/src/org/ibex/nestedvm/support_aux.c +++ b/src/org/ibex/nestedvm/support_aux.c @@ -117,6 +117,7 @@ REENT_WRAPPER1(setgid,gid_t) REENT_WRAPPER1(setegid,gid_t) REENT_WRAPPER2(setgroups,int,const gid_t *) REENT_WRAPPER0R(setsid,pid_t) +REENT_WRAPPER1(fsync,int) extern int __execve_r(struct _reent *ptr, const char *path, char *const argv[], char *const envp[]); int _execve(const char *path, char *const argv[], char *const envp[]) { @@ -170,11 +171,6 @@ void sync() { /* do nothing*/ } -int fsync(int fd) { - /* do nothing */ - return 0; -} - char *ttyname(int fd) { return isatty(fd) ? "/dev/console" : NULL; } diff --git a/src/org/ibex/nestedvm/syscalls.h b/src/org/ibex/nestedvm/syscalls.h index c346a40..13e4295 100644 --- a/src/org/ibex/nestedvm/syscalls.h +++ b/src/org/ibex/nestedvm/syscalls.h @@ -85,3 +85,4 @@ #define SYS_setgroups 88 #define SYS_resolve_ip 89 #define SYS_setsid 90 +#define SYS_fsync 91 diff --git a/src/org/ibex/nestedvm/util/Seekable.java b/src/org/ibex/nestedvm/util/Seekable.java index 9da8d27..485d364 100644 --- a/src/org/ibex/nestedvm/util/Seekable.java +++ b/src/org/ibex/nestedvm/util/Seekable.java @@ -14,6 +14,9 @@ public abstract class Seekable { public abstract void close() throws IOException; public abstract int pos() throws IOException; + public void sync() throws IOException { + throw new IOException("sync not implemented for " + getClass()); + } public void resize(long length) throws IOException { throw new IOException("resize not implemented for " + getClass()); } @@ -90,6 +93,7 @@ public abstract class Seekable { 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 sync() throws IOException { raf.getFD().sync(); } public void seek(int pos) throws IOException{ raf.seek(pos); } public int pos() throws IOException { return (int) raf.getFilePointer(); } public int length() throws IOException { return (int)raf.length(); }