blkdev_get_blocks(struct inode *inode, sector_t iblock,
unsigned long max_blocks, struct buffer_head *bh, int create)
{
- if ((iblock + max_blocks) > max_block(I_BDEV(inode)))
- return -EIO;
+ sector_t end_block = max_block(I_BDEV(inode));
+
+ if ((iblock + max_blocks) > end_block) {
+ max_blocks = end_block - iblock;
+ if ((long)max_blocks <= 0) {
+ if (create)
+ return -EIO; /* write fully beyond EOF */
+ /*
+ * It is a read which is fully beyond EOF. We return
+ * a !buffer_mapped buffer
+ */
+ max_blocks = 0;
+ }
+ }
bh->b_bdev = I_BDEV(inode);
bh->b_blocknr = iblock;
bh->b_size = max_blocks << inode->i_blkbits;
- set_buffer_mapped(bh);
+ if (max_blocks)
+ set_buffer_mapped(bh);
return 0;
}
* pseudo-fs
*/
-static spinlock_t bdev_lock __cacheline_aligned_in_smp = SPIN_LOCK_UNLOCKED;
+static __cacheline_aligned_in_smp DEFINE_SPINLOCK(bdev_lock);
static kmem_cache_t * bdev_cachep;
static struct inode *bdev_alloc_inode(struct super_block *sb)
if (!bdops->media_changed(bdev->bd_disk))
return 0;
- if (__invalidate_device(bdev, 0))
+ if (__invalidate_device(bdev))
printk("VFS: busy inodes on changed media.\n");
if (bdops->revalidate_disk)
EXPORT_SYMBOL(blkdev_get);
-int blkdev_open(struct inode * inode, struct file * filp)
+static int blkdev_open(struct inode * inode, struct file * filp)
{
struct block_device *bdev;
int res;
return res;
}
-EXPORT_SYMBOL(blkdev_open);
-
int blkdev_put(struct block_device *bdev)
{
int ret = 0;
.mmap = generic_file_mmap,
.fsync = block_fsync,
.ioctl = block_ioctl,
+#ifdef CONFIG_COMPAT
+ .compat_ioctl = compat_blkdev_ioctl,
+#endif
.readv = generic_file_readv,
.writev = generic_file_write_nolock,
.sendfile = generic_file_sendfile,
};
-EXPORT_SYMBOL(def_blk_fops);
-
int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg)
{
int res;