* - read(), write() are not passed a filehandle, but rather a
* pathname. The offset of the read and write is passed as the last
* argument, like the pread() and pwrite() system calls.
+ *
+ * - release() is called when an open file has:
+ * 1) all file descriptors closed
+ * 2) all memory mappings unmapped
+ * This call need only be implemented if this information is required,
+ * otherwise set this function to NULL.
+ *
*/
struct fuse_operations {
int (*getattr) (const char *, struct stat *);
int (*read) (const char *, char *, size_t, off_t);
int (*write) (const char *, const char *, size_t, off_t);
int (*statfs) (struct fuse_statfs *);
+ int (*release) (const char *);
};
/** Extra context that may be needed by some filesystems */
return out.h.error;
}
+static int fuse_release(struct inode *inode, struct file *file)
+{
+ struct fuse_conn *fc = INO_FC(inode);
+ struct fuse_in in = FUSE_IN_INIT;
+ struct fuse_out out = FUSE_OUT_INIT;
+
+ if(!fc->has_release)
+ return 0;
+
+ in.h.opcode = FUSE_RELEASE;
+ in.h.ino = inode->i_ino;
+ request_send(fc, &in, &out);
+
+ if(out.h.error == -ENOSYS) {
+ fc->has_release = 0;
+ return 0;
+ }
+
+ return out.h.error;
+}
+
static int fuse_readpage(struct file *file, struct page *page)
{
static struct file_operations fuse_file_operations = {
open: fuse_open,
+ release: fuse_release,
read: generic_file_read,
write: generic_file_write,
mmap: generic_file_mmap,
#define FUSE_MAX_PATH 4096
#define PARAM(inarg) (((char *)(inarg)) + sizeof(*inarg))
+static const char *opname(enum fuse_opcode opcode)
+{
+ switch(opcode) {
+ case FUSE_LOOKUP: return "LOOKUP";
+ case FUSE_FORGET: return "FORGET";
+ case FUSE_GETATTR: return "GETATTR";
+ case FUSE_SETATTR: return "SETATTR";
+ case FUSE_READLINK: return "READLINK";
+ case FUSE_SYMLINK: return "SYMLINK";
+ case FUSE_GETDIR: return "GETDIR";
+ case FUSE_MKNOD: return "MKNOD";
+ case FUSE_MKDIR: return "MKDIR";
+ case FUSE_UNLINK: return "UNLINK";
+ case FUSE_RMDIR: return "RMDIR";
+ case FUSE_RENAME: return "RENAME";
+ case FUSE_LINK: return "LINK";
+ case FUSE_OPEN: return "OPEN";
+ case FUSE_READ: return "READ";
+ case FUSE_WRITE: return "WRITE";
+ case FUSE_STATFS: return "STATFS";
+ case FUSE_RELEASE: return "RELEASE";
+ default: return "???";
+ }
+}
+
static inline void inc_avail(struct fuse *f)
{
pthread_mutex_lock(&f->lock);
send_reply(f, in, res, NULL, 0);
}
+static void do_release(struct fuse *f, struct fuse_in_header *in)
+{
+ int res;
+ char *path;
+
+ res = -ENOENT;
+ path = get_path(f, in->ino);
+ if(path != NULL) {
+ res = -ENOSYS;
+ if(f->op.release)
+ res = f->op.release(path);
+ free(path);
+ }
+ send_reply(f, in, res, NULL, 0);
+}
+
static void do_read(struct fuse *f, struct fuse_in_header *in,
struct fuse_read_in *arg)
{
dec_avail(f);
if((f->flags & FUSE_DEBUG)) {
- printf("unique: %i, opcode: %i, ino: %li, insize: %i\n", in->unique,
- in->opcode, in->ino, cmd->buflen);
+ printf("unique: %i, opcode: %s (%i), ino: %li, insize: %i\n",
+ in->unique, opname(in->opcode), in->opcode, in->ino,
+ cmd->buflen);
fflush(stdout);
}
do_statfs(f, in);
break;
+ case FUSE_RELEASE:
+ do_release(f, in);
+ break;
+
default:
fprintf(stderr, "Operation %i not implemented\n", in->opcode);
send_reply(f, in, -ENOSYS, NULL, 0);