]>
Commit | Line | Data |
---|---|---|
6d79125b CO |
1 | /* |
2 | * linux/fs/ext2/xip.c | |
3 | * | |
4 | * Copyright (C) 2005 IBM Corporation | |
5 | * Author: Carsten Otte (cotte@de.ibm.com) | |
6 | */ | |
7 | ||
8 | #include <linux/mm.h> | |
9 | #include <linux/fs.h> | |
10 | #include <linux/genhd.h> | |
11 | #include <linux/buffer_head.h> | |
12 | #include <linux/ext2_fs_sb.h> | |
13 | #include <linux/ext2_fs.h> | |
08f85851 | 14 | #include <linux/blkdev.h> |
6d79125b CO |
15 | #include "ext2.h" |
16 | #include "xip.h" | |
17 | ||
18 | static inline int | |
70688e4d | 19 | __inode_direct_access(struct inode *inode, sector_t block, |
30afcb4b | 20 | void **kaddr, unsigned long *pfn) |
afa597ba | 21 | { |
30afcb4b JH |
22 | struct block_device *bdev = inode->i_sb->s_bdev; |
23 | struct block_device_operations *ops = bdev->bd_disk->fops; | |
70688e4d NP |
24 | sector_t sector; |
25 | ||
26 | sector = block * (PAGE_SIZE / 512); /* ext2 block to bdev sector */ | |
30afcb4b JH |
27 | |
28 | BUG_ON(!ops->direct_access); | |
29 | return ops->direct_access(bdev, sector, kaddr, pfn); | |
6d79125b CO |
30 | } |
31 | ||
afa597ba | 32 | static inline int |
70688e4d | 33 | __ext2_get_block(struct inode *inode, pgoff_t pgoff, int create, |
afa597ba CO |
34 | sector_t *result) |
35 | { | |
36 | struct buffer_head tmp; | |
37 | int rc; | |
38 | ||
39 | memset(&tmp, 0, sizeof(struct buffer_head)); | |
70688e4d | 40 | rc = ext2_get_block(inode, pgoff, &tmp, create); |
afa597ba CO |
41 | *result = tmp.b_blocknr; |
42 | ||
43 | /* did we get a sparse block (hole in the file)? */ | |
0cfc11ed | 44 | if (!tmp.b_blocknr && !rc) { |
afa597ba CO |
45 | BUG_ON(create); |
46 | rc = -ENODATA; | |
47 | } | |
48 | ||
49 | return rc; | |
50 | } | |
51 | ||
6d79125b | 52 | int |
70688e4d | 53 | ext2_clear_xip_target(struct inode *inode, sector_t block) |
afa597ba | 54 | { |
30afcb4b JH |
55 | void *kaddr; |
56 | unsigned long pfn; | |
6d79125b CO |
57 | int rc; |
58 | ||
70688e4d | 59 | rc = __inode_direct_access(inode, block, &kaddr, &pfn); |
afa597ba | 60 | if (!rc) |
30afcb4b | 61 | clear_page(kaddr); |
afa597ba | 62 | return rc; |
6d79125b CO |
63 | } |
64 | ||
65 | void ext2_xip_verify_sb(struct super_block *sb) | |
66 | { | |
67 | struct ext2_sb_info *sbi = EXT2_SB(sb); | |
68 | ||
afa597ba CO |
69 | if ((sbi->s_mount_opt & EXT2_MOUNT_XIP) && |
70 | !sb->s_bdev->bd_disk->fops->direct_access) { | |
71 | sbi->s_mount_opt &= (~EXT2_MOUNT_XIP); | |
605afd60 | 72 | ext2_warning(sb, __func__, |
afa597ba | 73 | "ignoring xip option - not supported by bdev"); |
6d79125b CO |
74 | } |
75 | } | |
76 | ||
70688e4d NP |
77 | int ext2_get_xip_mem(struct address_space *mapping, pgoff_t pgoff, int create, |
78 | void **kmem, unsigned long *pfn) | |
6d79125b CO |
79 | { |
80 | int rc; | |
70688e4d | 81 | sector_t block; |
6d79125b | 82 | |
afa597ba | 83 | /* first, retrieve the sector number */ |
70688e4d | 84 | rc = __ext2_get_block(mapping->host, pgoff, create, &block); |
6d79125b | 85 | if (rc) |
70688e4d | 86 | return rc; |
6d79125b | 87 | |
afa597ba | 88 | /* retrieve address of the target data */ |
70688e4d NP |
89 | rc = __inode_direct_access(mapping->host, block, kmem, pfn); |
90 | return rc; | |
6d79125b | 91 | } |