diff -uNr filelib-old/cfile.c filelib/cfile.c
--- filelib-old/cfile.c	Fri Dec 13 18:16:52 2002
+++ filelib/cfile.c	Fri Dec 13 16:46:03 2002
@@ -28,6 +28,7 @@
 #include <fcntl.h>
 #include <errno.h>
 
+#include <dirent.h>
 
 /*
  *	void r_check_access (char *fname, int flen, int what, int *result)
@@ -304,6 +305,108 @@
 #endif
 }
 
+// My addiditions (clj)
+
+#if _STAT_VER != 3
+#  warning "The version of the stat struct is not compatible with this version of libhostio."
+#endif
+
+static __inline__ void r_stat(char *fname, int flen, int *stat_struct, int *res)
+{
+	char pbuffer[FILENAME_MAX];
+	int x;
+
+	if (flen >= (FILENAME_MAX - 1)) {
+		x = FILENAME_MAX - 1;
+	} else {
+		x = flen;
+	}
+	memcpy (pbuffer, fname, x);
+	pbuffer[x] = '\0';
+
+	*res = stat(pbuffer, (struct stat*)stat_struct);
+}
+
+void _fl_stat(int *w) { r_stat((char *)(w[0]), (int)(w[1]), (int *)(w[2]), (int *)(w[3])); }
+
+static __inline__ void r_fstat(int fd, int *stat_struct, int *res)
+{
+	*res = fstat(fd, (struct stat*)stat_struct);
+}
+
+void _fl_fstat(int *w) { r_fstat((int)(w[0]), (int *)(w[1]), (int *)(w[2])); }
+
+static __inline__ void r_opendir(char *fname, int flen, int *dd)
+{
+	char pbuffer[FILENAME_MAX];
+	int x;
+
+	if (flen >= (FILENAME_MAX - 1)) {
+		x = FILENAME_MAX - 1;
+	} else {
+		x = flen;
+	}
+	memcpy (pbuffer, fname, x);
+	pbuffer[x] = '\0';
+
+	(int *) *dd = opendir(pbuffer);
+}
+
+void _fl_opendir(int *w) { r_opendir((char *)(w[0]), (int)(w[1]), (int *)(w[2])); }
+
+// This function returns non-zero (ie not null) on success... The real things
+// returns the pointer of course, but we wont do that as it is not needed.
+static __inline__ void r_readdir(int dd, int *dirent_struct, int *result)
+{
+	struct dirent *dirent_ptr;
+
+	dirent_ptr = readdir((DIR *) dd);
+	if(dirent_ptr)
+	{
+		
+		memcpy(dirent_struct, dirent_ptr, sizeof(struct dirent));
+		*result = 1;
+	}
+	else
+		*result = 0;
+
+}
+
+void _fl_readdir(int *w) { r_readdir((int)(w[0]), (int *)(w[1]), (int *)(w[2])); }
+
+static __inline__ void r_closedir(int dd, int *result)
+{
+	*result = closedir((DIR *) dd);
+}
+
+void _fl_closedir(int *w) { r_closedir((int)(w[0]), (int *)(w[1])); }
+
+static __inline__ void r_chmod(char *fname, int flen, int mode, int *result)
+{
+	char pbuffer[FILENAME_MAX];
+	int x;
+
+	if (flen >= (FILENAME_MAX - 1)) {
+		x = FILENAME_MAX - 1;
+	} else {
+		x = flen;
+	}
+	memcpy (pbuffer, fname, x);
+	pbuffer[x] = '\0';
+
+	*result = chmod(pbuffer, mode);
+}
+
+void _fl_chmod(int *w) { r_chmod((char *)(w[0]), (int)(w[1]), (int)(w[2]), (int *)(w[3])); }
+
+static __inline__ void r_fsync(int fd, int *result)
+{
+	*result = fsync(fd);
+}
+
+void _fl_fsync(int *w) { r_fsync((int)(w[0]), (int *)(w[1])); }
+
+// End of my additions (clj)
 
 void _fl_check_access (int *w)				{ r_check_access ((char *)(w[0]), (int)(w[1]), (int)(w[2]), (int *)(w[3])); }
 void _fl_size (int *w)					{ r_size ((char *)(w[0]), (int)(w[1]), (int *)(w[2])); }
diff -uNr filelib-old/filelib.inc filelib/filelib.inc
--- filelib-old/filelib.inc	Fri Dec 13 18:16:52 2002
+++ filelib/filelib.inc	Thu Dec 12 19:07:36 2002
@@ -64,3 +64,60 @@
 #PRAGMA EXTERNAL "PROC BX.fl.fd.fd.copy (CHAN OF INT c, VAL INT src.fd, dst.fd, count, INT result) = 3"
 --}}}  
 
+DATA TYPE C.STAT IS [18]INT32:
+
+DATA TYPE STAT
+  RECORD
+    INT64 dev:
+    INT32 ino:
+    INT32 mode:
+    INT32 nlink:
+    INT32 uid:
+    INT32 gid:
+    INT64 rdev:
+    INT32 size:
+    INT32 blksize:
+    INT32 blocks:
+    INT32 atime:
+    INT32 mtime:
+    INT32 ctime:
+:
+
+DATA TYPE C.DIRENT IS [3 + 64]INT32:
+
+DATA TYPE DIRENT
+  RECORD
+    INT32 ino:
+    INT32 off:
+    INT16 reclen:
+    BYTE type:
+    [256]BYTE filename:
+:
+
+VAL INT32 S.IFMT   IS     #F000: -- 0170000 bitmask for the file type bitfields
+VAL INT32 S.IFSOCK IS     #C000: -- 0140000 socket
+VAL INT32 S.IFLNK  IS     #A000: -- 0120000 symbolic link
+VAL INT32 S.IFREG  IS     #8000: -- 0100000 regular file
+VAL INT32 S.IFBLK  IS     #6000: -- 0060000 block device
+VAL INT32 S.IFDIR  IS     #4000: -- 0040000 directory
+VAL INT32 S.IFCHR  IS     #2000: -- 0020000 character device
+VAL INT32 S.IFIFO  IS     #1000: -- 0010000 fifo
+VAL INT32 S.ISUID  IS     #800:  -- 0004000 set UID bit
+VAL INT32 S.ISGID  IS     #400:  -- 0002000 set GID bit (see below)
+VAL INT32 S.ISVTX  IS     #200:  -- 0001000 sticky bit (see below)
+VAL INT32 S.IRWXU  IS     #1C0:  -- 00700   mask for file owner permissions
+VAL INT32 S.IRUSR  IS     #100:  -- 00400   owner has read permission
+VAL INT32 S.IWUSR  IS     #80:   -- 00200   owner has write permission
+VAL INT32 S.IXUSR  IS     #40:   -- 00100   owner has execute permission
+VAL INT32 S.IRWXG  IS     #38:   -- 00070   mask for group permissions
+VAL INT32 S.IRGRP  IS     #20:   -- 00040   group has read permission
+VAL INT32 S.IWGRP  IS     #10:   -- 00020   group has write permission
+VAL INT32 S.IXGRP  IS     #8:    -- 00010   group has execute permission
+VAL INT32 S.IRWXO  IS     #7:    -- 00007   mask for permissions for others (not in group)
+VAL INT32 S.IROTH  IS     #4:    -- 00004   others have read permission
+VAL INT32 S.IWOTH  IS     #2:    -- 00002   others have write permisson
+VAL INT32 S.IXOTH  IS     #1:    -- 00001   others have execute permission
+
+
+
+
diff -uNr filelib-old/filelib.occ filelib/filelib.occ
--- filelib-old/filelib.occ	Fri Dec 13 18:16:52 2002
+++ filelib/filelib.occ	Fri Dec 13 16:45:48 2002
@@ -46,6 +46,13 @@
 #PRAGMA EXTERNAL "PROC B.fl.sendfile (VAL INT src.fd, dst.fd, count, INT offset, result) = 3"
 
 #PRAGMA EXTERNAL "PROC C.killcall (CHAN OF INT c, INT result) = 0"
+#PRAGMA EXTERNAL "PROC C.fl.stat(VAL []BYTE filename, RESULT C.STAT result, RESULT INT res) = 0"
+#PRAGMA EXTERNAL "PROC C.fl.fstat(VAL INT fd, RESULT C.STAT result, RESULT INT res) = 0"
+#PRAGMA EXTERNAL "PROC C.fl.opendir(VAL []BYTE filename, RESULT INT dd) = 0"
+#PRAGMA EXTERNAL "PROC C.fl.readdir(VAL INT dd, C.DIRENT info, RESULT INT res) = 0"
+#PRAGMA EXTERNAL "PROC C.fl.closedir(VAL INT dd, RESULT INT res) = 0"
+#PRAGMA EXTERNAL "PROC C.fl.chmod(VAL []BYTE filename, INT mode, RESULT INT res) = 0"
+#PRAGMA EXTERNAL "PROC C.fl.fsync(VAL INT fd, RESULT INT result) = 0"
 --}}}  
 
 --{{{  BOOL FUNCTION file.check.access (VAL []BYTE filename, VAL INT what)
@@ -299,4 +306,109 @@
     --}}}  
 :
 --}}}  
+
+-- My modifications (clj)
+
+PROC c.stat.2.stat(VAL C.STAT c.info, RESULT STAT info)--{{{
+  PAR
+    [2]INT32 info.dev RETYPES info[dev]:
+    PAR
+      info.dev[0] := c.info[0] --INT64 dev:
+      info.dev[1] := c.info[1] --INT62 dev:
+    -- A short ints worth of paddings skips cell 2
+    info[ino] := c.info[3] -- INT32 ino:
+    info[mode] := c.info[4] --INT16 mode:
+    info[nlink] := c.info[5] --INT32 nlink:
+    info[uid] := c.info[6] --INT32 uid:
+    info[gid] := c.info[7] --INT32 gid:
+    [2]INT32 info.rdev RETYPES info[rdev]:
+    PAR
+      info.rdev[0] := c.info[8]
+      info.rdev[1] := c.info[9] --INT64 rdev:
+    -- A short ints worth of paddings skips cell 10
+    info[size] := c.info[11] --INT32 size: 
+    info[blksize] := c.info[12] --INT32 blksize:
+    info[blocks] := c.info[13] --INT32 blocks:
+    info[atime] := c.info[14] --INT32 atime:
+    info[mtime] := c.info[15] --INT32 mtime:
+    info[ctime] := c.info[16] --INT32 ctime:
+:
+--}}}
+
+-- 0 on success
+-- -1 on error
+PROC file.stat(VAL []BYTE name, RESULT STAT info, RESULT INT res)--{{{
+  C.STAT c.info:
+  SEQ
+    C.fl.stat(name, c.info, res)
+    IF
+      res = 0
+        c.stat.2.stat(c.info, info)
+      TRUE
+        SKIP
+:
+--}}}
+
+PROC file.fstat(VAL INT fd, RESULT STAT info, RESULT INT res)--{{{
+  C.STAT c.info:
+  SEQ
+    C.fl.fstat(fd, c.info, res)
+    IF
+      res = 0
+        c.stat.2.stat(c.info, info)
+      TRUE
+        SKIP
+:
+--}}}
+
+PROC c.dirent.2.dirent(VAL C.DIRENT c.info, RESULT DIRENT info)--{{{
+  SEQ 
+    PAR
+      info[ino] := c.info[0]
+      info[off] := c.info[1]
+    SEQ
+      VAL [2]INT16 c.info.reclen.type RETYPES c.info[2]:
+      PAR
+        info[reclen] := c.info.reclen.type[0]
+        VAL [2]BYTE  c.info.type.char RETYPES c.info.reclen.type[1]:
+        PAR
+          info[type] := c.info.type.char[0]
+          info[filename][0] := c.info.type.char[1]
+      VAL [256]BYTE c.filename RETYPES [c.info FROM 3 FOR 64]:
+      INITIAL INT len IS ((INT info[reclen]) - (3 * 4)):
+      [info[filename] FROM 1 FOR len] := [c.filename FROM 0 FOR len]
+      info[filename][(INT info[reclen])] := 0 -- just making sure
+:--}}}
+
+PROC file.opendir(VAL []BYTE filename, RESULT INT dd)--{{{
+  SEQ
+    C.fl.opendir(filename, dd)
+:--}}}
+
+PROC file.readdir(VAL INT dd, RESULT DIRENT info, RESULT INT res)--{{{
+  C.DIRENT c.info:
+  SEQ
+    C.fl.readdir(dd, c.info, res)
+    IF
+      res > 0
+        c.dirent.2.dirent(c.info, info)
+      TRUE
+        SKIP
+:--}}}
+
+PROC file.closedir(VAL INT dd, RESULT INT res)--{{{
+  SEQ
+    C.fl.closedir(dd, res)
+:--}}}
+
+PROC file.chmod(VAL []BYTE filename, INT mode, RESULT INT res)--{{{
+  SEQ
+    C.fl.chmod(filename, mode, res)
+:--}}}
+
+PROC file.fsync(VAL INT fd, RESULT INT result)
+  SEQ
+    C.fl.fsync(fd, result)
+:
+
 

