diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/ext2/xip.c | 81 |
1 files changed, 47 insertions, 34 deletions
diff --git a/fs/ext2/xip.c b/fs/ext2/xip.c index d44431d1a33..0aa5ac159c0 100644 --- a/fs/ext2/xip.c +++ b/fs/ext2/xip.c @@ -15,66 +15,79 @@ #include "xip.h" static inline int -__inode_direct_access(struct inode *inode, sector_t sector, unsigned long *data) { +__inode_direct_access(struct inode *inode, sector_t sector, + unsigned long *data) +{ BUG_ON(!inode->i_sb->s_bdev->bd_disk->fops->direct_access); return inode->i_sb->s_bdev->bd_disk->fops ->direct_access(inode->i_sb->s_bdev,sector,data); } +static inline int +__ext2_get_sector(struct inode *inode, sector_t offset, int create, + sector_t *result) +{ + struct buffer_head tmp; + int rc; + + memset(&tmp, 0, sizeof(struct buffer_head)); + rc = ext2_get_block(inode, offset/ (PAGE_SIZE/512), &tmp, + create); + *result = tmp.b_blocknr; + + /* did we get a sparse block (hole in the file)? */ + if (!(*result)) { + BUG_ON(create); + rc = -ENODATA; + } + + return rc; +} + int -ext2_clear_xip_target(struct inode *inode, int block) { - sector_t sector = block*(PAGE_SIZE/512); +ext2_clear_xip_target(struct inode *inode, int block) +{ + sector_t sector = block * (PAGE_SIZE/512); unsigned long data; int rc; rc = __inode_direct_access(inode, sector, &data); - if (rc) - return rc; - clear_page((void*)data); - return 0; + if (!rc) + clear_page((void*)data); + return rc; } void ext2_xip_verify_sb(struct super_block *sb) { struct ext2_sb_info *sbi = EXT2_SB(sb); - if ((sbi->s_mount_opt & EXT2_MOUNT_XIP)) { - if ((sb->s_bdev == NULL) || - sb->s_bdev->bd_disk == NULL || - sb->s_bdev->bd_disk->fops == NULL || - sb->s_bdev->bd_disk->fops->direct_access == NULL) { - sbi->s_mount_opt &= (~EXT2_MOUNT_XIP); - ext2_warning(sb, __FUNCTION__, - "ignoring xip option - not supported by bdev"); - } + if ((sbi->s_mount_opt & EXT2_MOUNT_XIP) && + !sb->s_bdev->bd_disk->fops->direct_access) { + sbi->s_mount_opt &= (~EXT2_MOUNT_XIP); + ext2_warning(sb, __FUNCTION__, + "ignoring xip option - not supported by bdev"); } } -struct page* -ext2_get_xip_page(struct address_space *mapping, sector_t blockno, +struct page * +ext2_get_xip_page(struct address_space *mapping, sector_t offset, int create) { int rc; unsigned long data; - struct buffer_head tmp; + sector_t sector; - tmp.b_state = 0; - tmp.b_blocknr = 0; - rc = ext2_get_block(mapping->host, blockno/(PAGE_SIZE/512) , &tmp, - create); + /* first, retrieve the sector number */ + rc = __ext2_get_sector(mapping->host, offset, create, §or); if (rc) - return ERR_PTR(rc); - if (tmp.b_blocknr == 0) { - /* SPARSE block */ - BUG_ON(create); - return ERR_PTR(-ENODATA); - } + goto error; + /* retrieve address of the target data */ rc = __inode_direct_access - (mapping->host,tmp.b_blocknr*(PAGE_SIZE/512) ,&data); - if (rc) - return ERR_PTR(rc); + (mapping->host, sector * (PAGE_SIZE/512), &data); + if (!rc) + return virt_to_page(data); - SetPageUptodate(virt_to_page(data)); - return virt_to_page(data); + error: + return ERR_PTR(rc); } |