Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[deliverable/linux.git] / fs / ext2 / xip.c
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/blkdev.h>
13 #include "ext2.h"
14 #include "xip.h"
15
16 static inline long __inode_direct_access(struct inode *inode, sector_t block,
17 void **kaddr, unsigned long *pfn, long size)
18 {
19 struct block_device *bdev = inode->i_sb->s_bdev;
20 sector_t sector = block * (PAGE_SIZE / 512);
21 return bdev_direct_access(bdev, sector, kaddr, pfn, size);
22 }
23
24 static inline int
25 __ext2_get_block(struct inode *inode, pgoff_t pgoff, int create,
26 sector_t *result)
27 {
28 struct buffer_head tmp;
29 int rc;
30
31 memset(&tmp, 0, sizeof(struct buffer_head));
32 tmp.b_size = 1 << inode->i_blkbits;
33 rc = ext2_get_block(inode, pgoff, &tmp, create);
34 *result = tmp.b_blocknr;
35
36 /* did we get a sparse block (hole in the file)? */
37 if (!tmp.b_blocknr && !rc) {
38 BUG_ON(create);
39 rc = -ENODATA;
40 }
41
42 return rc;
43 }
44
45 int
46 ext2_clear_xip_target(struct inode *inode, sector_t block)
47 {
48 void *kaddr;
49 unsigned long pfn;
50 long size;
51
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;
57 }
58
59 void ext2_xip_verify_sb(struct super_block *sb)
60 {
61 struct ext2_sb_info *sbi = EXT2_SB(sb);
62
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);
66 ext2_msg(sb, KERN_WARNING,
67 "warning: ignoring xip option - "
68 "not supported by bdev");
69 }
70 }
71
72 int ext2_get_xip_mem(struct address_space *mapping, pgoff_t pgoff, int create,
73 void **kmem, unsigned long *pfn)
74 {
75 long rc;
76 sector_t block;
77
78 /* first, retrieve the sector number */
79 rc = __ext2_get_block(mapping->host, pgoff, create, &block);
80 if (rc)
81 return rc;
82
83 /* retrieve address of the target data */
84 rc = __inode_direct_access(mapping->host, block, kmem, pfn, PAGE_SIZE);
85 return (rc < 0) ? rc : 0;
86 }
This page took 0.037855 seconds and 5 git commands to generate.