Commit e5e5558e authored by Miklos Szeredi's avatar Miklos Szeredi Committed by Linus Torvalds

[PATCH] FUSE - read-only operations

This patch adds the read-only filesystem operations of FUSE.

This contains the following files:

 o dir.c
    - directory, symlink and file-inode operations

The following operations are added:

 o lookup
 o getattr
 o readlink
 o follow_link
 o directory open
 o readdir
 o directory release
 o permission
 o dentry revalidate
 o statfs
Signed-off-by: default avatarMiklos Szeredi <miklos@szeredi.hu>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 334f485d
......@@ -4,4 +4,4 @@
obj-$(CONFIG_FUSE_FS) += fuse.o
fuse-objs := dev.o inode.o
fuse-objs := dev.o dir.o inode.o
......@@ -691,6 +691,13 @@ static struct fuse_req *request_find(struct fuse_conn *fc, u64 unique)
return NULL;
}
/* fget() needs to be done in this context */
static void process_getdir(struct fuse_req *req)
{
struct fuse_getdir_out_i *arg = req->out.args[0].value;
arg->file = fget(arg->fd);
}
static int copy_out_args(struct fuse_copy_state *cs, struct fuse_out *out,
unsigned nbytes)
{
......@@ -770,6 +777,8 @@ static ssize_t fuse_dev_writev(struct file *file, const struct iovec *iov,
if (!err) {
if (req->interrupted)
err = -ENOENT;
else if (req->in.h.opcode == FUSE_GETDIR && !oh.error)
process_getdir(req);
} else if (!req->interrupted)
req->out.h.error = -EIO;
request_end(fc, req);
......
This diff is collapsed.
......@@ -30,6 +30,9 @@ struct fuse_inode {
* and kernel */
u64 nodeid;
/** The request used for sending the FORGET message */
struct fuse_req *forget_req;
/** Time in jiffies until the file attributes are valid */
unsigned long i_time;
};
......@@ -129,6 +132,7 @@ struct fuse_req {
/** Data for asynchronous requests */
union {
struct fuse_forget_in forget_in;
struct fuse_init_in_out init_in_out;
} misc;
......@@ -197,6 +201,11 @@ struct fuse_conn {
struct backing_dev_info bdi;
};
struct fuse_getdir_out_i {
int fd;
void *file; /* Used by kernel only */
};
static inline struct fuse_conn **get_fuse_conn_super_p(struct super_block *sb)
{
return (struct fuse_conn **) &sb->s_fs_info;
......@@ -239,6 +248,38 @@ extern struct file_operations fuse_dev_operations;
*/
extern spinlock_t fuse_lock;
/**
* Get a filled in inode
*/
struct inode *fuse_iget(struct super_block *sb, unsigned long nodeid,
int generation, struct fuse_attr *attr, int version);
/**
* Send FORGET command
*/
void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
unsigned long nodeid, int version);
/**
* Initialise inode operations on regular files and special files
*/
void fuse_init_common(struct inode *inode);
/**
* Initialise inode and file operations on a directory
*/
void fuse_init_dir(struct inode *inode);
/**
* Initialise inode operations on a symlink
*/
void fuse_init_symlink(struct inode *inode);
/**
* Change attributes of an inode
*/
void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr);
/**
* Check if the connection can be released, and if yes, then free the
* connection structure
......@@ -306,6 +347,16 @@ void request_send_noreply(struct fuse_conn *fc, struct fuse_req *req);
*/
void request_send_background(struct fuse_conn *fc, struct fuse_req *req);
/**
* Get the attributes of a file
*/
int fuse_do_getattr(struct inode *inode);
/**
* Invalidate inode attributes
*/
void fuse_invalidate_attr(struct inode *inode);
/**
* Send the INIT message
*/
......
......@@ -51,12 +51,20 @@ static struct inode *fuse_alloc_inode(struct super_block *sb)
fi = get_fuse_inode(inode);
fi->i_time = jiffies - 1;
fi->nodeid = 0;
fi->forget_req = fuse_request_alloc();
if (!fi->forget_req) {
kmem_cache_free(fuse_inode_cachep, inode);
return NULL;
}
return inode;
}
static void fuse_destroy_inode(struct inode *inode)
{
struct fuse_inode *fi = get_fuse_inode(inode);
if (fi->forget_req)
fuse_request_free(fi->forget_req);
kmem_cache_free(fuse_inode_cachep, inode);
}
......@@ -65,8 +73,27 @@ static void fuse_read_inode(struct inode *inode)
/* No op */
}
void fuse_send_forget(struct fuse_conn *fc, struct fuse_req *req,
unsigned long nodeid, int version)
{
struct fuse_forget_in *inarg = &req->misc.forget_in;
inarg->version = version;
req->in.h.opcode = FUSE_FORGET;
req->in.h.nodeid = nodeid;
req->in.numargs = 1;
req->in.args[0].size = sizeof(struct fuse_forget_in);
req->in.args[0].value = inarg;
request_send_noreply(fc, req);
}
static void fuse_clear_inode(struct inode *inode)
{
struct fuse_conn *fc = get_fuse_conn(inode);
if (fc) {
struct fuse_inode *fi = get_fuse_inode(inode);
fuse_send_forget(fc, fi->forget_req, fi->nodeid, inode->i_version);
fi->forget_req = NULL;
}
}
void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr)
......@@ -94,6 +121,22 @@ static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
{
inode->i_mode = attr->mode & S_IFMT;
i_size_write(inode, attr->size);
if (S_ISREG(inode->i_mode)) {
fuse_init_common(inode);
} else if (S_ISDIR(inode->i_mode))
fuse_init_dir(inode);
else if (S_ISLNK(inode->i_mode))
fuse_init_symlink(inode);
else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
fuse_init_common(inode);
init_special_inode(inode, inode->i_mode,
new_decode_dev(attr->rdev));
} else {
/* Don't let user create weird files */
inode->i_mode = S_IFREG;
fuse_init_common(inode);
}
}
static int fuse_inode_eq(struct inode *inode, void *_nodeidp)
......@@ -158,6 +201,43 @@ static void fuse_put_super(struct super_block *sb)
spin_unlock(&fuse_lock);
}
static void convert_fuse_statfs(struct kstatfs *stbuf, struct fuse_kstatfs *attr)
{
stbuf->f_type = FUSE_SUPER_MAGIC;
stbuf->f_bsize = attr->bsize;
stbuf->f_blocks = attr->blocks;
stbuf->f_bfree = attr->bfree;
stbuf->f_bavail = attr->bavail;
stbuf->f_files = attr->files;
stbuf->f_ffree = attr->ffree;
stbuf->f_namelen = attr->namelen;
/* fsid is left zero */
}
static int fuse_statfs(struct super_block *sb, struct kstatfs *buf)
{
struct fuse_conn *fc = get_fuse_conn_super(sb);
struct fuse_req *req;
struct fuse_statfs_out outarg;
int err;
req = fuse_get_request(fc);
if (!req)
return -ERESTARTSYS;
req->in.numargs = 0;
req->in.h.opcode = FUSE_STATFS;
req->out.numargs = 1;
req->out.args[0].size = sizeof(outarg);
req->out.args[0].value = &outarg;
request_send(fc, req);
err = req->out.h.error;
if (!err)
convert_fuse_statfs(buf, &outarg.st);
fuse_put_request(fc, req);
return err;
}
enum {
OPT_FD,
OPT_ROOTMODE,
......@@ -318,6 +398,7 @@ static struct super_operations fuse_super_operations = {
.read_inode = fuse_read_inode,
.clear_inode = fuse_clear_inode,
.put_super = fuse_put_super,
.statfs = fuse_statfs,
.show_options = fuse_show_options,
};
......
......@@ -42,13 +42,61 @@ struct fuse_attr {
__u32 rdev;
};
struct fuse_kstatfs {
__u64 blocks;
__u64 bfree;
__u64 bavail;
__u64 files;
__u64 ffree;
__u32 bsize;
__u32 namelen;
};
enum fuse_opcode {
FUSE_LOOKUP = 1,
FUSE_FORGET = 2, /* no reply */
FUSE_GETATTR = 3,
FUSE_READLINK = 5,
FUSE_GETDIR = 7,
FUSE_STATFS = 17,
FUSE_INIT = 26
};
/* Conservative buffer size for the client */
#define FUSE_MAX_IN 8192
#define FUSE_NAME_MAX 1024
struct fuse_entry_out {
__u64 nodeid; /* Inode ID */
__u64 generation; /* Inode generation: nodeid:gen must
be unique for the fs's lifetime */
__u64 entry_valid; /* Cache timeout for the name */
__u64 attr_valid; /* Cache timeout for the attributes */
__u32 entry_valid_nsec;
__u32 attr_valid_nsec;
struct fuse_attr attr;
};
struct fuse_forget_in {
__u64 version;
};
struct fuse_attr_out {
__u64 attr_valid; /* Cache timeout for the attributes */
__u32 attr_valid_nsec;
__u32 dummy;
struct fuse_attr attr;
};
struct fuse_getdir_out {
__u32 fd;
};
struct fuse_statfs_out {
struct fuse_kstatfs st;
};
struct fuse_init_in_out {
__u32 major;
__u32 minor;
......@@ -70,3 +118,15 @@ struct fuse_out_header {
__u64 unique;
};
struct fuse_dirent {
__u64 ino;
__u64 off;
__u32 namelen;
__u32 type;
char name[0];
};
#define FUSE_NAME_OFFSET ((unsigned) ((struct fuse_dirent *) 0)->name)
#define FUSE_DIRENT_ALIGN(x) (((x) + sizeof(__u64) - 1) & ~(sizeof(__u64) - 1))
#define FUSE_DIRENT_SIZE(d) \
FUSE_DIRENT_ALIGN(FUSE_NAME_OFFSET + (d)->namelen)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment