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