support fsync()
authorDavid Crawshaw <david@zentus.com>
Sun, 7 Jan 2007 16:10:20 +0000 (08:10 -0800)
committerDavid Crawshaw <david@zentus.com>
Sun, 7 Jan 2007 16:10:20 +0000 (08:10 -0800)
darcs-hash:20070107161020-0c629-f8cb28cb78260e588b7a1a5515d6a3a6c940a7f0.gz

src/org/ibex/nestedvm/Runtime.java
src/org/ibex/nestedvm/UsermodeConstants.java
src/org/ibex/nestedvm/support.s
src/org/ibex/nestedvm/support_aux.c
src/org/ibex/nestedvm/syscalls.h
src/org/ibex/nestedvm/util/Seekable.java

index f8a1579..201fde9 100644 (file)
@@ -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.
         <i>syscall</i> should be the contents of V0 and <i>a</i>, <i>b</i>, <i>c</i>, and <i>d</i> 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;
 
index 07c03f4..0385965 100644 (file)
@@ -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;
index 3a50fac..9ff9216 100644 (file)
@@ -195,3 +195,4 @@ SYSCALL(alarm)
 SYSCALL_R(getgroups)
 SYSCALL_R(setsid)
 SYSCALL_R2(__resolve_ip_r,SYS_resolve_ip)
+SYSCALL_R(fsync)
index 0be4859..54181e9 100644 (file)
@@ -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;
 }
index c346a40..13e4295 100644 (file)
@@ -85,3 +85,4 @@
 #define SYS_setgroups 88
 #define SYS_resolve_ip 89
 #define SYS_setsid 90
+#define SYS_fsync 91
index 9da8d27..485d364 100644 (file)
@@ -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(); }