API change
diff --git a/ChangeLog b/ChangeLog
index e8d2cac..947b410 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2004-11-26  Miklos Szeredi <miklos@szeredi.hu>
+
+	* libfuse API change: open, read, write, flush, fsync and release
+	are passed a 'struct fuse_file_info' pointer containing the open
+	flags (open and release), and the file handle.  Verion changed to
+	3.0.
+
 2004-11-23  Miklos Szeredi <miklos@szeredi.hu>
 
 	* More cleanups in the kernel
diff --git a/configure.in b/configure.in
index 94deca7..256bd7b 100644
--- a/configure.in
+++ b/configure.in
@@ -1,4 +1,4 @@
-AC_INIT(fuse, 2.1-pre1)
+AC_INIT(fuse, 3.0-pre0)
 AM_INIT_AUTOMAKE
 AM_CONFIG_HEADER(include/config.h)
 
diff --git a/example/fusexmp.c b/example/fusexmp.c
index 02d0363..40af830 100644
--- a/example/fusexmp.c
+++ b/example/fusexmp.c
@@ -191,11 +191,11 @@
 }
 
 
-static int xmp_open(const char *path, int flags)
+static int xmp_open(const char *path, struct fuse_file_info *fi)
 {
     int res;
 
-    res = open(path, flags);
+    res = open(path, fi->flags);
     if(res == -1) 
         return -errno;
 
@@ -203,11 +203,13 @@
     return 0;
 }
 
-static int xmp_read(const char *path, char *buf, size_t size, off_t offset)
+static int xmp_read(const char *path, char *buf, size_t size, off_t offset,
+                    struct fuse_file_info *fi)
 {
     int fd;
     int res;
 
+    (void) fi;
     fd = open(path, O_RDONLY);
     if(fd == -1)
         return -errno;
@@ -221,11 +223,12 @@
 }
 
 static int xmp_write(const char *path, const char *buf, size_t size,
-                     off_t offset)
+                     off_t offset, struct fuse_file_info *fi)
 {
     int fd;
     int res;
 
+    (void) fi;
     fd = open(path, O_WRONLY);
     if(fd == -1)
         return -errno;
@@ -249,23 +252,25 @@
     return 0;
 }
 
-static int xmp_release(const char *path, int flags)
+static int xmp_release(const char *path, struct fuse_file_info *fi)
 {
     /* Just a stub.  This method is optional and can safely be left
        unimplemented */
-
+    
     (void) path;
-    (void) flags;
+    (void) fi;
     return 0;
 }
 
-static int xmp_fsync(const char *path, int isdatasync)
+static int xmp_fsync(const char *path, int isdatasync,
+                     struct fuse_file_info *fi)
 {
     /* Just a stub.  This method is optional and can safely be left
        unimplemented */
 
     (void) path;
     (void) isdatasync;
+    (void) fi;
     return 0;
 }
 
diff --git a/example/hello.c b/example/hello.c
index 5065fb7..75196ff 100644
--- a/example/hello.c
+++ b/example/hello.c
@@ -47,20 +47,22 @@
     return 0;
 }
 
-static int hello_open(const char *path, int flags)
+static int hello_open(const char *path, struct fuse_file_info *fi)
 {
     if(strcmp(path, hello_path) != 0)
         return -ENOENT;
 
-    if((flags & 3) != O_RDONLY)
+    if((fi->flags & 3) != O_RDONLY)
         return -EACCES;
 
     return 0;
 }
 
-static int hello_read(const char *path, char *buf, size_t size, off_t offset)
+static int hello_read(const char *path, char *buf, size_t size, off_t offset,
+                      struct fuse_file_info *fi)
 {
     size_t len;
+    (void) fi;
     if(strcmp(path, hello_path) != 0)
         return -ENOENT;
     
diff --git a/example/null.c b/example/null.c
index b854289..fd88a05 100644
--- a/example/null.c
+++ b/example/null.c
@@ -38,7 +38,7 @@
     return 0;
 }
 
-static int null_open(const char *path, int UNUSED(flags))
+static int null_open(const char *path, struct fuse_file_info *UNUSED(fi))
 {
     if(strcmp(path, "/") != 0)
         return -ENOENT;
@@ -47,7 +47,7 @@
 }
 
 static int null_read(const char *path, char *UNUSED(buf), size_t size,
-                     off_t UNUSED(offset))
+                     off_t UNUSED(offset), struct fuse_file_info *UNUSED(fi))
 {
     if(strcmp(path, "/") != 0)
         return -ENOENT;
@@ -56,7 +56,7 @@
 }
 
 static int null_write(const char *path, const char *UNUSED(buf), size_t size,
-                     off_t UNUSED(offset))
+                     off_t UNUSED(offset), struct fuse_file_info *UNUSED(fi))
 {
     if(strcmp(path, "/") != 0)
         return -ENOENT;
diff --git a/include/fuse.h b/include/fuse.h
index a5115ee..072ac22 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -12,10 +12,10 @@
 /* This file defines the library interface of FUSE */
 
 /** Major version of FUSE library interface */
-#define FUSE_MAJOR_VERSION 2
+#define FUSE_MAJOR_VERSION 3
 
 /** Minor version of FUSE library interface */
-#define FUSE_MINOR_VERSION 1
+#define FUSE_MINOR_VERSION 0
 
 /* This interface uses 64 bit off_t */
 #if _FILE_OFFSET_BITS != 64
@@ -53,6 +53,16 @@
 typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type,
                               ino_t ino);
 
+/** Information about open files */
+struct fuse_file_info {
+    /** Open flags.  Available in open() and release() */
+    int flags;
+
+    /** File handle.  May be filled in by filesystem in open().
+        Available in all other file operations */
+    unsigned long fh;
+};
+
 /**
  * The file system operations:
  *
@@ -125,13 +135,15 @@
     int (*chown)       (const char *, uid_t, gid_t);
     int (*truncate)    (const char *, off_t);
     int (*utime)       (const char *, struct utimbuf *);
-    int (*open)        (const char *, int);
-    int (*read)        (const char *, char *, size_t, off_t);
-    int (*write)       (const char *, const char *, size_t, off_t);
+    int (*open)        (const char *, struct fuse_file_info *);
+    int (*read)        (const char *, char *, size_t, off_t,
+                        struct fuse_file_info *);
+    int (*write)       (const char *, const char *, size_t, off_t,
+                        struct fuse_file_info *);
     int (*statfs)      (const char *, struct statfs *);
-    int (*flush)       (const char *);
-    int (*release)     (const char *, int);
-    int (*fsync)       (const char *, int);
+    int (*flush)       (const char *, struct fuse_file_info *);
+    int (*release)     (const char *, struct fuse_file_info *);
+    int (*fsync)       (const char *, int, struct fuse_file_info *);
     int (*setxattr)    (const char *, const char *, const char *, size_t, int);
     int (*getxattr)    (const char *, const char *, char *, size_t);
     int (*listxattr)   (const char *, char *, size_t);
@@ -291,16 +303,6 @@
 int __fuse_exited(struct fuse* f);
 void __fuse_set_getcontext_func(struct fuse_context *(*func)(void));
 
-
-/* ----------------------------------------------------------- *
- * Compatibility cruft                                         *
- * ----------------------------------------------------------- */
-
-#ifdef FUSE_DIRFIL_COMPAT
-typedef int (*fuse_dirfil_old_t) (fuse_dirh_t h, const char *name, int type);
-#define fuse_dirfil_t fuse_dirfil_old_t
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/kernel/configure.ac b/kernel/configure.ac
index 7be6890..3b06f46 100644
--- a/kernel/configure.ac
+++ b/kernel/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT(fuse-kernel, 2.1-pre1)
+AC_INIT(fuse-kernel, 3.0-pre0)
 AC_CONFIG_HEADERS([config.h])
 
 AC_PROG_INSTALL
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 8dcd5a8..e370ef4 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -9,4 +9,4 @@
 	mount.c		\
 	fuse_i.h
 
-libfuse_la_LDFLAGS = -lpthread -version-number 2:1:0
+libfuse_la_LDFLAGS = -lpthread -version-number 3:0:0
diff --git a/lib/fuse.c b/lib/fuse.c
index 59f8b45..66474fb 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -1058,13 +1058,16 @@
     int res;
     char *path;
     struct fuse_open_out outarg;
+    struct fuse_file_info fi;
 
+    memset(&fi, 0, sizeof(fi));
+    fi.flags = arg->flags;
     res = -ENOENT;
     path = get_path(f, in->nodeid);
     if (path != NULL) {
         res = -ENOSYS;
         if (f->op.open)
-            res = f->op.open(path, arg->flags);
+            res = f->op.open(path, &fi);
     }
     if (res == 0) {
         int res2;
@@ -1074,8 +1077,7 @@
            races with rename/unlink, against which the kernel can't
            protect */
         pthread_mutex_lock(&f->lock);
-        f->fh_ctr ++;
-        outarg.fh = f->fh_ctr;
+        outarg.fh = fi.fh;
         if (f->flags & FUSE_DEBUG) {
             printf("OPEN[%lu] flags: 0x%x\n", outarg.fh, arg->flags);
             fflush(stdout);
@@ -1085,7 +1087,7 @@
         if(res2 == -ENOENT) {
             /* The open syscall was interrupted, so it must be cancelled */
             if(f->op.release)
-                f->op.release(path, arg->flags);
+                f->op.release(path, &fi);
         } else
             get_node(f, in->nodeid)->open_count ++;
         pthread_mutex_unlock(&f->lock);
@@ -1102,7 +1104,10 @@
 {
     char *path;
     int res;
+    struct fuse_file_info fi;
 
+    memset(&fi, 0, sizeof(fi));
+    fi.fh = arg->fh;
     res = -ENOENT;
     path = get_path(f, in->nodeid);
     if (path != NULL) {
@@ -1112,7 +1117,7 @@
         }
         res = -ENOSYS;
         if (f->op.flush)
-            res = f->op.flush(path);
+            res = f->op.flush(path, &fi);
         free(path);
     }
     send_reply(f, in, res, NULL, 0);
@@ -1123,6 +1128,11 @@
 {
     struct node *node;
     char *path;
+    struct fuse_file_info fi;
+
+    memset(&fi, 0, sizeof(fi));
+    fi.flags = arg->flags;
+    fi.fh = arg->fh;
 
     pthread_mutex_lock(&f->lock);
     node = get_node(f, in->nodeid);
@@ -1136,7 +1146,7 @@
             fflush(stdout);
         }
         if (f->op.release)
-            f->op.release(path, arg->flags);
+            f->op.release(path, &fi);
 
         if(node->is_hidden && node->open_count == 0)
             /* can now clean up this hidden file */
@@ -1160,7 +1170,11 @@
         char *buf = outbuf + sizeof(struct fuse_out_header);
         size_t size;
         size_t outsize;
+        struct fuse_file_info fi;
         
+        memset(&fi, 0, sizeof(fi));
+        fi.fh = arg->fh;
+
         res = -ENOENT;
         path = get_path(f, in->nodeid);
         if (path != NULL) {
@@ -1172,7 +1186,7 @@
             
             res = -ENOSYS;
             if (f->op.read)
-                res = f->op.read(path, buf, arg->size, arg->offset);
+                res = f->op.read(path, buf, arg->size, arg->offset, &fi);
             free(path);
         }
         
@@ -1201,6 +1215,10 @@
     int res;
     char *path;
     struct fuse_write_out outarg;
+    struct fuse_file_info fi;
+
+    memset(&fi, 0, sizeof(fi));
+    fi.fh = arg->fh;
 
     res = -ENOENT;
     path = get_path(f, in->nodeid);
@@ -1214,7 +1232,7 @@
 
         res = -ENOSYS;
         if (f->op.write)
-            res = f->op.write(path, PARAM(arg), arg->size, arg->offset);
+            res = f->op.write(path, PARAM(arg), arg->size, arg->offset, &fi);
         free(path);
     }
     
@@ -1267,6 +1285,10 @@
 {
     int res;
     char *path;
+    struct fuse_file_info fi;
+
+    memset(&fi, 0, sizeof(fi));
+    fi.fh = inarg->fh;
 
     res = -ENOENT;
     path = get_path(f, in->nodeid);
@@ -1277,7 +1299,7 @@
         }
         res = -ENOSYS;
         if (f->op.fsync)
-            res = f->op.fsync(path, inarg->datasync);
+            res = f->op.fsync(path, inarg->datasync, &fi);
         free(path);
     }
     send_reply(f, in, res, NULL, 0);
diff --git a/lib/fuse_i.h b/lib/fuse_i.h
index ca230a9..b9ea903 100644
--- a/lib/fuse_i.h
+++ b/lib/fuse_i.h
@@ -51,7 +51,6 @@
     nodeid_t ctr;
     unsigned int generation;
     unsigned int hidectr;
-    unsigned long fh_ctr;
     pthread_mutex_t lock;
     int numworker;
     int numavail;