generic block based fiemap implementation
Subsystems (3)
PATCH 3/4 generic block based fiemap implementation
From: Josef Bacik <[email protected]>
Any block based fs (this patch includes ext3) just has to declare its own fiemap() function and then call this generic function with its own get_block_t. This works well for block based filesystems that will map multiple contiguous blocks at one time, but will work for filesystems that only map one block at a time, you will just end up with an "extent" for each block. One gotcha is this will not play nicely where there is hole+data after the EOF. This function will assume its hit the end of the data as soon as it hits a hole after the EOF, so if there is any data past that it will not pick that up. AFAIK no block based fs does this anyway, but its in the comments of the function anyway just in case.
--- fs/ext2/ext2.h | 2 + fs/ext2/file.c | 1 + fs/ext2/inode.c | 8 +++ fs/ext3/file.c | 1 + fs/ext3/inode.c | 8 +++ fs/ioctl.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/ext3_fs.h | 2 + include/linux/fs.h | 3 + 8 files changed, 144 insertions(+), 0 deletions(-)
fs/ext2/ext2.h +2 -0
@@ -133,6 +133,8 @@ extern void ext2_truncate (struct inode *);extern int ext2_setattr (struct dentry *,struct iattr *);extern void ext2_set_inode_flags (struct inode *inode);extern void ext2_get_inode_flags (struct ext2_inode_info *); +extern int ext2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 len);int __ext2_write_begin (struct file *file,struct address_space *mapping,loff_t pos,unsigned len,unsigned flags,struct page **pagep,void **fsdata);
fs/ext2/file.c +1 -0
@@ -86,4 +86,5 @@ const struct inode_operations ext2_file_inode_operations = {#endif .setattr = ext2_setattr, .permission = ext2_permission, + .fiemap = ext2_fiemap, };
fs/ext2/inode.c +8 -0
@@ -31,6 +31,7 @@#include <linux/writeback.h> #include <linux/buffer_head.h> #include <linux/mpage.h> +#include <linux/fiemap.h> #include "ext2.h" #include "acl.h" #include "xip.h"
@@ -704,6 +705,13 @@ int ext2_get_block(struct inode *inode, sector_t iblock, struct buffer_head *bh_ } +int ext2_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 len) +{ +return generic_block_fiemap (inode, fieinfo, start, len, + ext2_get_block); +} +static int ext2_writepage (struct page *page,struct writeback_control *wbc) {return block_write_full_page (page, ext2_get_block, wbc);
fs/ext3/file.c +1 -0
@@ -134,5 +134,6 @@ const struct inode_operations ext3_file_inode_operations = { .removexattr = generic_removexattr, #endif .permission = ext3_permission, + .fiemap = ext3_fiemap, };
fs/ext3/inode.c +8 -0
@@ -36,6 +36,7 @@#include <linux/mpage.h> #include <linux/uio.h> #include <linux/bio.h> +#include <linux/fiemap.h> #include "xattr.h" #include "acl.h"
@@ -981,6 +982,13 @@ out:return ret; } +int ext3_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 len) +{ +return generic_block_fiemap (inode, fieinfo, start, len, + ext3_get_block); +} +/* * `handle' can be NULL if create is zero */
fs/ioctl.c +119 -0
131 lines not on this page · raw message
include/linux/ext3_fs.h +2 -0
@@ -836,6 +836,8 @@ extern void ext3_truncate (struct inode *);extern void ext3_set_inode_flags (struct inode *);extern void ext3_get_inode_flags (struct ext3_inode_info *);extern void ext3_set_aops (struct inode *inode); +extern int ext3_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo, +u64 start,u64 len);/* ioctl.c */ extern int ext3_ioctl (struct inode *, struct file *, unsigned int,
include/linux/fs.h +3 -0
@@ -1978,6 +1978,9 @@ extern int vfs_fstat(unsigned int, struct kstat *);extern int do_vfs_ioctl (struct file *filp,unsigned int fd,unsigned int cmd,unsigned long arg); +extern int generic_block_fiemap (struct inode *inode, +struct fiemap_extent_info *fieinfo,u64 start, +u64 len,get_block_t *get_block);extern void get_filesystem (struct file_system_type *fs);extern void put_filesystem (struct file_system_type *fs);
Signature · 1 line
1.5.4.1