1 #include <linux/blkdev.h>
2 #include <linux/blkpg.h>
3 #include <linux/blktrace_api.h>
4 #include <linux/cdrom.h>
5 #include <linux/compat.h>
6 #include <linux/elevator.h>
8 #include <linux/hdreg.h>
9 #include <linux/syscalls.h>
10 #include <linux/smp_lock.h>
11 #include <linux/types.h>
12 #include <linux/uaccess.h>
14 static int compat_put_ushort(unsigned long arg, unsigned short val)
16 return put_user(val, (unsigned short __user *)compat_ptr(arg));
19 static int compat_put_int(unsigned long arg, int val)
21 return put_user(val, (compat_int_t __user *)compat_ptr(arg));
24 static int compat_put_long(unsigned long arg, long val)
26 return put_user(val, (compat_long_t __user *)compat_ptr(arg));
29 static int compat_put_ulong(unsigned long arg, compat_ulong_t val)
31 return put_user(val, (compat_ulong_t __user *)compat_ptr(arg));
34 static int compat_put_u64(unsigned long arg, u64 val)
36 return put_user(val, (compat_u64 __user *)compat_ptr(arg));
39 #define BLKBSZGET_32 _IOR(0x12, 112, int)
40 #define BLKBSZSET_32 _IOW(0x12, 113, int)
41 #define BLKGETSIZE64_32 _IOR(0x12, 114, int)
43 static int compat_blkdev_locked_ioctl(struct inode *inode, struct file *file,
44 struct block_device *bdev,
45 unsigned cmd, unsigned long arg)
47 struct backing_dev_info *bdi;
54 bdi = blk_get_backing_dev_info(bdev);
57 return compat_put_long(arg,
58 (bdi->ra_pages * PAGE_CACHE_SIZE) / 512);
59 case BLKROGET: /* compatible */
60 return compat_put_int(arg, bdev_read_only(bdev) != 0);
61 case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */
62 return compat_put_int(arg, block_size(bdev));
63 case BLKSSZGET: /* get block device hardware sector size */
64 return compat_put_int(arg, bdev_hardsect_size(bdev));
66 return compat_put_ushort(arg,
67 bdev_get_queue(bdev)->max_sectors);
68 case BLKRASET: /* compatible, but no compat_ptr (!) */
70 if (!capable(CAP_SYS_ADMIN))
72 bdi = blk_get_backing_dev_info(bdev);
75 bdi->ra_pages = (arg * 512) / PAGE_CACHE_SIZE;
78 if ((bdev->bd_inode->i_size >> 9) > ~0UL)
80 return compat_put_ulong(arg, bdev->bd_inode->i_size >> 9);
83 return compat_put_u64(arg, bdev->bd_inode->i_size);
88 /* Most of the generic ioctls are handled in the normal fallback path.
89 This assumes the blkdev's low level compat_ioctl always returns
90 ENOIOCTLCMD for unknown ioctls. */
91 long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
93 int ret = -ENOIOCTLCMD;
94 struct inode *inode = file->f_mapping->host;
95 struct block_device *bdev = inode->i_bdev;
96 struct gendisk *disk = bdev->bd_disk;
102 * the ones below are implemented in blkdev_locked_ioctl,
103 * but we call blkdev_ioctl, which gets the lock for us
106 return blkdev_ioctl(inode, file, cmd,
107 (unsigned long)compat_ptr(arg));
109 return blkdev_ioctl(inode, file, BLKBSZSET,
110 (unsigned long)compat_ptr(arg));
114 ret = compat_blkdev_locked_ioctl(inode, file, bdev, cmd, arg);
115 /* FIXME: why do we assume -> compat_ioctl needs the BKL? */
116 if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl)
117 ret = disk->fops->compat_ioctl(file, cmd, arg);