diff options
Diffstat (limited to 'fs/block_dev.c')
-rw-r--r-- | fs/block_dev.c | 55 |
1 files changed, 1 insertions, 54 deletions
diff --git a/fs/block_dev.c b/fs/block_dev.c index 47a949d8a07e..a1e09b4fe1ba 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c | |||
@@ -70,19 +70,6 @@ static void bdev_inode_switch_bdi(struct inode *inode, | |||
70 | spin_unlock(&dst->wb.list_lock); | 70 | spin_unlock(&dst->wb.list_lock); |
71 | } | 71 | } |
72 | 72 | ||
73 | sector_t blkdev_max_block(struct block_device *bdev) | ||
74 | { | ||
75 | sector_t retval = ~((sector_t)0); | ||
76 | loff_t sz = i_size_read(bdev->bd_inode); | ||
77 | |||
78 | if (sz) { | ||
79 | unsigned int size = block_size(bdev); | ||
80 | unsigned int sizebits = blksize_bits(size); | ||
81 | retval = (sz >> sizebits); | ||
82 | } | ||
83 | return retval; | ||
84 | } | ||
85 | |||
86 | /* Kill _all_ buffers and pagecache , dirty or not.. */ | 73 | /* Kill _all_ buffers and pagecache , dirty or not.. */ |
87 | void kill_bdev(struct block_device *bdev) | 74 | void kill_bdev(struct block_device *bdev) |
88 | { | 75 | { |
@@ -163,52 +150,12 @@ static int | |||
163 | blkdev_get_block(struct inode *inode, sector_t iblock, | 150 | blkdev_get_block(struct inode *inode, sector_t iblock, |
164 | struct buffer_head *bh, int create) | 151 | struct buffer_head *bh, int create) |
165 | { | 152 | { |
166 | if (iblock >= blkdev_max_block(I_BDEV(inode))) { | ||
167 | if (create) | ||
168 | return -EIO; | ||
169 | |||
170 | /* | ||
171 | * for reads, we're just trying to fill a partial page. | ||
172 | * return a hole, they will have to call get_block again | ||
173 | * before they can fill it, and they will get -EIO at that | ||
174 | * time | ||
175 | */ | ||
176 | return 0; | ||
177 | } | ||
178 | bh->b_bdev = I_BDEV(inode); | 153 | bh->b_bdev = I_BDEV(inode); |
179 | bh->b_blocknr = iblock; | 154 | bh->b_blocknr = iblock; |
180 | set_buffer_mapped(bh); | 155 | set_buffer_mapped(bh); |
181 | return 0; | 156 | return 0; |
182 | } | 157 | } |
183 | 158 | ||
184 | static int | ||
185 | blkdev_get_blocks(struct inode *inode, sector_t iblock, | ||
186 | struct buffer_head *bh, int create) | ||
187 | { | ||
188 | sector_t end_block = blkdev_max_block(I_BDEV(inode)); | ||
189 | unsigned long max_blocks = bh->b_size >> inode->i_blkbits; | ||
190 | |||
191 | if ((iblock + max_blocks) > end_block) { | ||
192 | max_blocks = end_block - iblock; | ||
193 | if ((long)max_blocks <= 0) { | ||
194 | if (create) | ||
195 | return -EIO; /* write fully beyond EOF */ | ||
196 | /* | ||
197 | * It is a read which is fully beyond EOF. We return | ||
198 | * a !buffer_mapped buffer | ||
199 | */ | ||
200 | max_blocks = 0; | ||
201 | } | ||
202 | } | ||
203 | |||
204 | bh->b_bdev = I_BDEV(inode); | ||
205 | bh->b_blocknr = iblock; | ||
206 | bh->b_size = max_blocks << inode->i_blkbits; | ||
207 | if (max_blocks) | ||
208 | set_buffer_mapped(bh); | ||
209 | return 0; | ||
210 | } | ||
211 | |||
212 | static ssize_t | 159 | static ssize_t |
213 | blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | 160 | blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, |
214 | loff_t offset, unsigned long nr_segs) | 161 | loff_t offset, unsigned long nr_segs) |
@@ -217,7 +164,7 @@ blkdev_direct_IO(int rw, struct kiocb *iocb, const struct iovec *iov, | |||
217 | struct inode *inode = file->f_mapping->host; | 164 | struct inode *inode = file->f_mapping->host; |
218 | 165 | ||
219 | return __blockdev_direct_IO(rw, iocb, inode, I_BDEV(inode), iov, offset, | 166 | return __blockdev_direct_IO(rw, iocb, inode, I_BDEV(inode), iov, offset, |
220 | nr_segs, blkdev_get_blocks, NULL, NULL, 0); | 167 | nr_segs, blkdev_get_block, NULL, NULL, 0); |
221 | } | 168 | } |
222 | 169 | ||
223 | int __sync_blockdev(struct block_device *bdev, int wait) | 170 | int __sync_blockdev(struct block_device *bdev, int wait) |