fix
authorMiklos Szeredi <miklos@szeredi.hu>
Mon, 28 Feb 2005 17:32:16 +0000 (17:32 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Mon, 28 Feb 2005 17:32:16 +0000 (17:32 +0000)
ChangeLog
include/fuse.h
lib/fuse.c
lib/fuse_i.h

index 4622dbe4220703ee3897d41ded8a515c86af35de..a05370fa5c7c3fa8bff32a1e6f4afd88927ea964 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,9 +1,11 @@
 2005-02-28  Miklos Szeredi <miklos@szeredi.hu>
 
-       * libfuse: added opendir() operation.  This can be used in case
+       * libfuse: added opendir() method.  This can be used in case
        permission checking in getdir() is too late.  Thanks to Usarin
        Heininga for pointing out this deficiency
 
+       * libfuse: added init() and destroy() methods to fuse_operations
+
        * kernel: llseek() method for files and directories made explicit
 
        * kernel: fixed inode leak in NFS export in case of nodeid
index 5b9df10c63f700d3dd631d714fa0d871e7852b76..df6149f5f38d1ddbb48dba99afe5d73786231058 100644 (file)
@@ -85,9 +85,9 @@ struct fuse_file_info {
  * negated error value (-errno) directly.
  *
  * All methods are optional, but some are essential for a useful
- * filesystem (e.g. getattr).  Flush, release and fsync are special
- * purpose methods, without which a full featured filesystem can still
- * be implemented.
+ * filesystem (e.g. getattr).  Flush, release, fsync, init and destroy
+ * are special purpose methods, without which a full featured
+ * filesystem can still be implemented.
  */
 struct fuse_operations {
     /** Get file attributes.
@@ -245,10 +245,26 @@ struct fuse_operations {
     /** Open direcory
      * 
      * This method should check if the open operation is permitted for
-     * this directory.  The fuse_file_info parameter is currently
-     * unused.  This method is optional.
+     * this  directory.   The  fuse_file_info parameter  is  currently
+     * unused.
      */
     int (*opendir) (const char *, struct fuse_file_info *);
+
+    /**
+     * Initialize filesystem
+     *
+     * The return value will passed in the private_data field of
+     * fuse_context to all file operations and as a parameter to the
+     * destroy() method.
+     */
+    void *(*init) (void);
+
+    /**
+     * Clean up filesystem
+     * 
+     * Called on filesystem exit.
+     */
+    void (*destroy) (void *);
 };
 
 /** Extra context that may be needed by some filesystems
@@ -269,7 +285,7 @@ struct fuse_context {
     /** Thread ID of the calling process */
     pid_t pid;
 
-    /** Currently unused */
+    /** Private filesystem data */
     void *private_data;
 };
 
index 64696b8c2ed4edf9d76af2e50942f5f1fe60c59f..b1aab25a6384905f6d064ba5510c3cb9ebe5ea3e 100644 (file)
@@ -1497,6 +1497,9 @@ static void do_init(struct fuse *f, struct fuse_in_header *in,
         fflush(stdout);
     }
     f->got_init = 1;
+    if (f->op.init)
+        f->user_data = f->op.init();
+
     memset(&outarg, 0, sizeof(outarg));
     outarg.major = FUSE_KERNEL_VERSION;
     outarg.minor = FUSE_KERNEL_MINOR_VERSION;
@@ -1628,6 +1631,7 @@ void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd)
     ctx->uid = in->uid;
     ctx->gid = in->gid;
     ctx->pid = in->pid;
+    ctx->private_data = f->user_data;
 
     argsize = cmd->buflen - sizeof(struct fuse_in_header);
 
@@ -2031,6 +2035,8 @@ void fuse_destroy(struct fuse *f)
     free(f->name_table);
     pthread_mutex_destroy(&f->lock);
     pthread_mutex_destroy(&f->worker_lock);
+    if (f->op.destroy)
+        f->op.destroy(f->user_data);
     free(f);
 }
 
index 17615b42ac0b07c40767732f8e766aa160d0304b..7ab485d074faf38e03f73bf2bfe1e5f87970e390 100644 (file)
@@ -29,6 +29,7 @@ struct fuse {
     int numavail;
     volatile int exited;
     int got_init;
+    void *user_data;
 };
 
 struct fuse *fuse_new_common(int fd, const char *opts,