Commit d360ab81 authored by Hirofumi Ogawa's avatar Hirofumi Ogawa Committed by Linus Torvalds

[PATCH] adds st_blocks for [lf]stat() to ramfs

This makes ramfs support proper st_blocks accounting.
parent 0e3a6c7d
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
static struct super_operations ramfs_ops; static struct super_operations ramfs_ops;
static struct address_space_operations ramfs_aops; static struct address_space_operations ramfs_aops;
static struct file_operations ramfs_file_operations; static struct file_operations ramfs_file_operations;
static struct inode_operations ramfs_file_inode_operations;
static struct inode_operations ramfs_dir_inode_operations; static struct inode_operations ramfs_dir_inode_operations;
static struct backing_dev_info ramfs_backing_dev_info = { static struct backing_dev_info ramfs_backing_dev_info = {
...@@ -66,6 +67,7 @@ static struct inode *ramfs_get_inode(struct super_block *sb, int mode, dev_t dev ...@@ -66,6 +67,7 @@ static struct inode *ramfs_get_inode(struct super_block *sb, int mode, dev_t dev
init_special_inode(inode, mode, dev); init_special_inode(inode, mode, dev);
break; break;
case S_IFREG: case S_IFREG:
inode->i_op = &ramfs_file_inode_operations;
inode->i_fop = &ramfs_file_operations; inode->i_fop = &ramfs_file_operations;
break; break;
case S_IFDIR: case S_IFDIR:
...@@ -114,6 +116,27 @@ static int ramfs_create(struct inode *dir, struct dentry *dentry, int mode) ...@@ -114,6 +116,27 @@ static int ramfs_create(struct inode *dir, struct dentry *dentry, int mode)
return ramfs_mknod(dir, dentry, mode | S_IFREG, 0); return ramfs_mknod(dir, dentry, mode | S_IFREG, 0);
} }
static int ramfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
struct kstat *stat)
{
struct inode *inode = dentry->d_inode;
stat->dev = inode->i_sb->s_dev;
stat->ino = inode->i_ino;
stat->mode = inode->i_mode;
stat->nlink = inode->i_nlink;
stat->uid = inode->i_uid;
stat->gid = inode->i_gid;
stat->rdev = kdev_t_to_nr(inode->i_rdev);
stat->atime = inode->i_atime;
stat->mtime = inode->i_mtime;
stat->ctime = inode->i_ctime;
stat->size = inode->i_size;
stat->blocks = inode->i_mapping->nrpages << (PAGE_CACHE_SHIFT - 9);
stat->blksize = inode->i_blksize;
return 0;
}
static int ramfs_symlink(struct inode * dir, struct dentry *dentry, const char * symname) static int ramfs_symlink(struct inode * dir, struct dentry *dentry, const char * symname)
{ {
...@@ -147,6 +170,10 @@ static struct file_operations ramfs_file_operations = { ...@@ -147,6 +170,10 @@ static struct file_operations ramfs_file_operations = {
.sendfile = generic_file_sendfile, .sendfile = generic_file_sendfile,
}; };
static struct inode_operations ramfs_file_inode_operations = {
.getattr = ramfs_getattr,
};
static struct inode_operations ramfs_dir_inode_operations = { static struct inode_operations ramfs_dir_inode_operations = {
.create = ramfs_create, .create = ramfs_create,
.lookup = simple_lookup, .lookup = simple_lookup,
......
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