]>
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> | |
08f85851 | 12 | #include <linux/blkdev.h> |
6d79125b CO |
13 | #include "ext2.h" |
14 | #include "xip.h" | |
15 | ||
dd22f551 MW |
16 | static inline long __inode_direct_access(struct inode *inode, sector_t block, |
17 | void **kaddr, unsigned long *pfn, long size) | |
afa597ba | 18 | { |
30afcb4b | 19 | struct block_device *bdev = inode->i_sb->s_bdev; |
dd22f551 MW |
20 | sector_t sector = block * (PAGE_SIZE / 512); |
21 | return bdev_direct_access(bdev, sector, kaddr, pfn, size); | |
6d79125b CO |
22 | } |
23 | ||
afa597ba | 24 | static inline int |
70688e4d | 25 | __ext2_get_block(struct inode *inode, pgoff_t pgoff, int create, |
afa597ba CO |
26 | sector_t *result) |
27 | { | |
28 | struct buffer_head tmp; | |
29 | int rc; | |
30 | ||
31 | memset(&tmp, 0, sizeof(struct buffer_head)); | |
7ba3ec57 | 32 | tmp.b_size = 1 << inode->i_blkbits; |
70688e4d | 33 | rc = ext2_get_block(inode, pgoff, &tmp, create); |
afa597ba CO |
34 | *result = tmp.b_blocknr; |
35 | ||
36 | /* did we get a sparse block (hole in the file)? */ | |
0cfc11ed | 37 | if (!tmp.b_blocknr && !rc) { |
afa597ba CO |
38 | BUG_ON(create); |
39 | rc = -ENODATA; | |
40 | } | |
41 | ||
42 | return rc; | |
43 | } | |
44 | ||
6d79125b | 45 | int |
70688e4d | 46 | ext2_clear_xip_target(struct inode *inode, sector_t block) |
afa597ba | 47 | { |
30afcb4b JH |
48 | void *kaddr; |
49 | unsigned long pfn; | |
dd22f551 | 50 | long size; |
6d79125b | 51 | |
dd22f551 MW |
52 | size = __inode_direct_access(inode, block, &kaddr, &pfn, PAGE_SIZE); |
53 | if (size < 0) | |
54 | return size; | |
55 | clear_page(kaddr); | |
56 | return 0; | |
6d79125b CO |
57 | } |
58 | ||
59 | void ext2_xip_verify_sb(struct super_block *sb) | |
60 | { | |
61 | struct ext2_sb_info *sbi = EXT2_SB(sb); | |
62 | ||
afa597ba CO |
63 | if ((sbi->s_mount_opt & EXT2_MOUNT_XIP) && |
64 | !sb->s_bdev->bd_disk->fops->direct_access) { | |
65 | sbi->s_mount_opt &= (~EXT2_MOUNT_XIP); | |
2314b07c AF |
66 | ext2_msg(sb, KERN_WARNING, |
67 | "warning: ignoring xip option - " | |
68 | "not supported by bdev"); | |
6d79125b CO |
69 | } |
70 | } | |
71 | ||
70688e4d NP |
72 | int ext2_get_xip_mem(struct address_space *mapping, pgoff_t pgoff, int create, |
73 | void **kmem, unsigned long *pfn) | |
6d79125b | 74 | { |
dd22f551 | 75 | long rc; |
70688e4d | 76 | sector_t block; |
6d79125b | 77 | |
afa597ba | 78 | /* first, retrieve the sector number */ |
70688e4d | 79 | rc = __ext2_get_block(mapping->host, pgoff, create, &block); |
6d79125b | 80 | if (rc) |
70688e4d | 81 | return rc; |
6d79125b | 82 | |
afa597ba | 83 | /* retrieve address of the target data */ |
dd22f551 MW |
84 | rc = __inode_direct_access(mapping->host, block, kmem, pfn, PAGE_SIZE); |
85 | return (rc < 0) ? rc : 0; | |
6d79125b | 86 | } |