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
* 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.
/** 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
/** Thread ID of the calling process */
pid_t pid;
- /** Currently unused */
+ /** Private filesystem data */
void *private_data;
};
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;
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);
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);
}