Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 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> |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 7 | #include <linux/hdreg.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 8 | #include <linux/slab.h> |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 9 | #include <linux/syscalls.h> |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 10 | #include <linux/types.h> |
| 11 | #include <linux/uaccess.h> |
| 12 | |
| 13 | static int compat_put_ushort(unsigned long arg, unsigned short val) |
| 14 | { |
| 15 | return put_user(val, (unsigned short __user *)compat_ptr(arg)); |
| 16 | } |
| 17 | |
| 18 | static int compat_put_int(unsigned long arg, int val) |
| 19 | { |
| 20 | return put_user(val, (compat_int_t __user *)compat_ptr(arg)); |
| 21 | } |
| 22 | |
Martin K. Petersen | ac481c2 | 2009-10-03 20:52:01 +0200 | [diff] [blame] | 23 | static int compat_put_uint(unsigned long arg, unsigned int val) |
| 24 | { |
| 25 | return put_user(val, (compat_uint_t __user *)compat_ptr(arg)); |
| 26 | } |
| 27 | |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 28 | static int compat_put_long(unsigned long arg, long val) |
| 29 | { |
| 30 | return put_user(val, (compat_long_t __user *)compat_ptr(arg)); |
| 31 | } |
| 32 | |
| 33 | static int compat_put_ulong(unsigned long arg, compat_ulong_t val) |
| 34 | { |
| 35 | return put_user(val, (compat_ulong_t __user *)compat_ptr(arg)); |
| 36 | } |
| 37 | |
| 38 | static int compat_put_u64(unsigned long arg, u64 val) |
| 39 | { |
| 40 | return put_user(val, (compat_u64 __user *)compat_ptr(arg)); |
| 41 | } |
| 42 | |
Arnd Bergmann | 9617db0 | 2007-10-09 13:23:55 +0200 | [diff] [blame] | 43 | struct compat_hd_geometry { |
| 44 | unsigned char heads; |
| 45 | unsigned char sectors; |
| 46 | unsigned short cylinders; |
| 47 | u32 start; |
| 48 | }; |
| 49 | |
| 50 | static int compat_hdio_getgeo(struct gendisk *disk, struct block_device *bdev, |
| 51 | struct compat_hd_geometry __user *ugeo) |
| 52 | { |
| 53 | struct hd_geometry geo; |
| 54 | int ret; |
| 55 | |
| 56 | if (!ugeo) |
| 57 | return -EINVAL; |
| 58 | if (!disk->fops->getgeo) |
| 59 | return -ENOTTY; |
| 60 | |
Cong Wang | 8b0d77f | 2013-07-03 15:01:12 -0700 | [diff] [blame] | 61 | memset(&geo, 0, sizeof(geo)); |
Arnd Bergmann | 9617db0 | 2007-10-09 13:23:55 +0200 | [diff] [blame] | 62 | /* |
| 63 | * We need to set the startsect first, the driver may |
| 64 | * want to override it. |
| 65 | */ |
| 66 | geo.start = get_start_sect(bdev); |
| 67 | ret = disk->fops->getgeo(bdev, &geo); |
| 68 | if (ret) |
| 69 | return ret; |
| 70 | |
| 71 | ret = copy_to_user(ugeo, &geo, 4); |
Mathieu Desnoyers | 3ddc5b4 | 2013-09-11 14:23:18 -0700 | [diff] [blame] | 72 | ret |= put_user(geo.start, &ugeo->start); |
Arnd Bergmann | 9617db0 | 2007-10-09 13:23:55 +0200 | [diff] [blame] | 73 | if (ret) |
| 74 | ret = -EFAULT; |
| 75 | |
| 76 | return ret; |
| 77 | } |
| 78 | |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 79 | static int compat_hdio_ioctl(struct block_device *bdev, fmode_t mode, |
| 80 | unsigned int cmd, unsigned long arg) |
Arnd Bergmann | 9617db0 | 2007-10-09 13:23:55 +0200 | [diff] [blame] | 81 | { |
| 82 | mm_segment_t old_fs = get_fs(); |
| 83 | unsigned long kval; |
| 84 | unsigned int __user *uvp; |
| 85 | int error; |
| 86 | |
| 87 | set_fs(KERNEL_DS); |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 88 | error = __blkdev_driver_ioctl(bdev, mode, |
Arnd Bergmann | 9617db0 | 2007-10-09 13:23:55 +0200 | [diff] [blame] | 89 | cmd, (unsigned long)(&kval)); |
| 90 | set_fs(old_fs); |
| 91 | |
| 92 | if (error == 0) { |
| 93 | uvp = compat_ptr(arg); |
| 94 | if (put_user(kval, uvp)) |
| 95 | error = -EFAULT; |
| 96 | } |
| 97 | return error; |
| 98 | } |
| 99 | |
Arnd Bergmann | b3087cc | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 100 | struct compat_cdrom_read_audio { |
| 101 | union cdrom_addr addr; |
| 102 | u8 addr_format; |
| 103 | compat_int_t nframes; |
| 104 | compat_caddr_t buf; |
| 105 | }; |
| 106 | |
| 107 | struct compat_cdrom_generic_command { |
| 108 | unsigned char cmd[CDROM_PACKET_SIZE]; |
| 109 | compat_caddr_t buffer; |
| 110 | compat_uint_t buflen; |
| 111 | compat_int_t stat; |
| 112 | compat_caddr_t sense; |
| 113 | unsigned char data_direction; |
| 114 | compat_int_t quiet; |
| 115 | compat_int_t timeout; |
| 116 | compat_caddr_t reserved[1]; |
| 117 | }; |
| 118 | |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 119 | static int compat_cdrom_read_audio(struct block_device *bdev, fmode_t mode, |
| 120 | unsigned int cmd, unsigned long arg) |
Arnd Bergmann | b3087cc | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 121 | { |
| 122 | struct cdrom_read_audio __user *cdread_audio; |
| 123 | struct compat_cdrom_read_audio __user *cdread_audio32; |
| 124 | __u32 data; |
| 125 | void __user *datap; |
| 126 | |
| 127 | cdread_audio = compat_alloc_user_space(sizeof(*cdread_audio)); |
| 128 | cdread_audio32 = compat_ptr(arg); |
| 129 | |
| 130 | if (copy_in_user(&cdread_audio->addr, |
| 131 | &cdread_audio32->addr, |
| 132 | (sizeof(*cdread_audio32) - |
| 133 | sizeof(compat_caddr_t)))) |
| 134 | return -EFAULT; |
| 135 | |
| 136 | if (get_user(data, &cdread_audio32->buf)) |
| 137 | return -EFAULT; |
| 138 | datap = compat_ptr(data); |
| 139 | if (put_user(datap, &cdread_audio->buf)) |
| 140 | return -EFAULT; |
| 141 | |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 142 | return __blkdev_driver_ioctl(bdev, mode, cmd, |
Arnd Bergmann | b3087cc | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 143 | (unsigned long)cdread_audio); |
| 144 | } |
| 145 | |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 146 | static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode, |
| 147 | unsigned int cmd, unsigned long arg) |
Arnd Bergmann | b3087cc | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 148 | { |
| 149 | struct cdrom_generic_command __user *cgc; |
| 150 | struct compat_cdrom_generic_command __user *cgc32; |
| 151 | u32 data; |
| 152 | unsigned char dir; |
| 153 | int itmp; |
| 154 | |
| 155 | cgc = compat_alloc_user_space(sizeof(*cgc)); |
| 156 | cgc32 = compat_ptr(arg); |
| 157 | |
| 158 | if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) || |
| 159 | get_user(data, &cgc32->buffer) || |
| 160 | put_user(compat_ptr(data), &cgc->buffer) || |
| 161 | copy_in_user(&cgc->buflen, &cgc32->buflen, |
| 162 | (sizeof(unsigned int) + sizeof(int))) || |
| 163 | get_user(data, &cgc32->sense) || |
| 164 | put_user(compat_ptr(data), &cgc->sense) || |
| 165 | get_user(dir, &cgc32->data_direction) || |
| 166 | put_user(dir, &cgc->data_direction) || |
| 167 | get_user(itmp, &cgc32->quiet) || |
| 168 | put_user(itmp, &cgc->quiet) || |
| 169 | get_user(itmp, &cgc32->timeout) || |
| 170 | put_user(itmp, &cgc->timeout) || |
| 171 | get_user(data, &cgc32->reserved[0]) || |
| 172 | put_user(compat_ptr(data), &cgc->reserved[0])) |
| 173 | return -EFAULT; |
| 174 | |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 175 | return __blkdev_driver_ioctl(bdev, mode, cmd, (unsigned long)cgc); |
Arnd Bergmann | b3087cc | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 176 | } |
| 177 | |
Arnd Bergmann | 18cf7f8 | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 178 | struct compat_blkpg_ioctl_arg { |
| 179 | compat_int_t op; |
| 180 | compat_int_t flags; |
| 181 | compat_int_t datalen; |
| 182 | compat_caddr_t data; |
| 183 | }; |
| 184 | |
Al Viro | 56b26ad | 2008-09-19 03:17:36 -0400 | [diff] [blame] | 185 | static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode, |
Arnd Bergmann | 18cf7f8 | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 186 | unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32) |
| 187 | { |
| 188 | struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a)); |
| 189 | compat_caddr_t udata; |
| 190 | compat_int_t n; |
| 191 | int err; |
| 192 | |
| 193 | err = get_user(n, &ua32->op); |
| 194 | err |= put_user(n, &a->op); |
| 195 | err |= get_user(n, &ua32->flags); |
| 196 | err |= put_user(n, &a->flags); |
| 197 | err |= get_user(n, &ua32->datalen); |
| 198 | err |= put_user(n, &a->datalen); |
| 199 | err |= get_user(udata, &ua32->data); |
| 200 | err |= put_user(compat_ptr(udata), &a->data); |
| 201 | if (err) |
| 202 | return err; |
| 203 | |
Al Viro | 56b26ad | 2008-09-19 03:17:36 -0400 | [diff] [blame] | 204 | return blkdev_ioctl(bdev, mode, cmd, (unsigned long)a); |
Arnd Bergmann | 18cf7f8 | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 205 | } |
| 206 | |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 207 | #define BLKBSZGET_32 _IOR(0x12, 112, int) |
| 208 | #define BLKBSZSET_32 _IOW(0x12, 113, int) |
| 209 | #define BLKGETSIZE64_32 _IOR(0x12, 114, int) |
| 210 | |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 211 | static int compat_blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, |
| 212 | unsigned cmd, unsigned long arg) |
Arnd Bergmann | 7199d4c | 2007-10-09 13:23:52 +0200 | [diff] [blame] | 213 | { |
Philip Langdale | 33013a8 | 2007-10-27 13:34:10 +0200 | [diff] [blame] | 214 | switch (cmd) { |
Arnd Bergmann | 9617db0 | 2007-10-09 13:23:55 +0200 | [diff] [blame] | 215 | case HDIO_GET_UNMASKINTR: |
| 216 | case HDIO_GET_MULTCOUNT: |
| 217 | case HDIO_GET_KEEPSETTINGS: |
| 218 | case HDIO_GET_32BIT: |
| 219 | case HDIO_GET_NOWERR: |
| 220 | case HDIO_GET_DMA: |
| 221 | case HDIO_GET_NICE: |
| 222 | case HDIO_GET_WCACHE: |
| 223 | case HDIO_GET_ACOUSTIC: |
| 224 | case HDIO_GET_ADDRESS: |
| 225 | case HDIO_GET_BUSSTATE: |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 226 | return compat_hdio_ioctl(bdev, mode, cmd, arg); |
Arnd Bergmann | b3087cc | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 227 | case CDROMREADAUDIO: |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 228 | return compat_cdrom_read_audio(bdev, mode, cmd, arg); |
Arnd Bergmann | b3087cc | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 229 | case CDROM_SEND_PACKET: |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 230 | return compat_cdrom_generic_command(bdev, mode, cmd, arg); |
Arnd Bergmann | b3087cc | 2007-10-09 13:23:56 +0200 | [diff] [blame] | 231 | |
Arnd Bergmann | 7199d4c | 2007-10-09 13:23:52 +0200 | [diff] [blame] | 232 | /* |
| 233 | * No handler required for the ones below, we just need to |
| 234 | * convert arg to a 64 bit pointer. |
| 235 | */ |
| 236 | case BLKSECTSET: |
| 237 | /* |
| 238 | * 0x03 -- HD/IDE ioctl's used by hdparm and friends. |
| 239 | * Some need translations, these do not. |
| 240 | */ |
| 241 | case HDIO_GET_IDENTITY: |
| 242 | case HDIO_DRIVE_TASK: |
| 243 | case HDIO_DRIVE_CMD: |
Arnd Bergmann | 7199d4c | 2007-10-09 13:23:52 +0200 | [diff] [blame] | 244 | /* 0x330 is reserved -- it used to be HDIO_GETGEO_BIG */ |
| 245 | case 0x330: |
Arnd Bergmann | 7199d4c | 2007-10-09 13:23:52 +0200 | [diff] [blame] | 246 | /* CDROM stuff */ |
| 247 | case CDROMPAUSE: |
| 248 | case CDROMRESUME: |
| 249 | case CDROMPLAYMSF: |
| 250 | case CDROMPLAYTRKIND: |
| 251 | case CDROMREADTOCHDR: |
| 252 | case CDROMREADTOCENTRY: |
| 253 | case CDROMSTOP: |
| 254 | case CDROMSTART: |
| 255 | case CDROMEJECT: |
| 256 | case CDROMVOLCTRL: |
| 257 | case CDROMSUBCHNL: |
| 258 | case CDROMMULTISESSION: |
| 259 | case CDROM_GET_MCN: |
| 260 | case CDROMRESET: |
| 261 | case CDROMVOLREAD: |
| 262 | case CDROMSEEK: |
| 263 | case CDROMPLAYBLK: |
| 264 | case CDROMCLOSETRAY: |
| 265 | case CDROM_DISC_STATUS: |
| 266 | case CDROM_CHANGER_NSLOTS: |
| 267 | case CDROM_GET_CAPABILITY: |
| 268 | /* Ignore cdrom.h about these next 5 ioctls, they absolutely do |
| 269 | * not take a struct cdrom_read, instead they take a struct cdrom_msf |
| 270 | * which is compatible. |
| 271 | */ |
| 272 | case CDROMREADMODE2: |
| 273 | case CDROMREADMODE1: |
| 274 | case CDROMREADRAW: |
| 275 | case CDROMREADCOOKED: |
| 276 | case CDROMREADALL: |
| 277 | /* DVD ioctls */ |
| 278 | case DVD_READ_STRUCT: |
| 279 | case DVD_WRITE_STRUCT: |
| 280 | case DVD_AUTH: |
| 281 | arg = (unsigned long)compat_ptr(arg); |
Andreas Schwab | 1c92560 | 2008-10-31 22:39:46 +0100 | [diff] [blame] | 282 | /* These intepret arg as an unsigned long, not as a pointer, |
| 283 | * so we must not do compat_ptr() conversion. */ |
| 284 | case HDIO_SET_MULTCOUNT: |
| 285 | case HDIO_SET_UNMASKINTR: |
| 286 | case HDIO_SET_KEEPSETTINGS: |
| 287 | case HDIO_SET_32BIT: |
| 288 | case HDIO_SET_NOWERR: |
| 289 | case HDIO_SET_DMA: |
| 290 | case HDIO_SET_PIO_MODE: |
| 291 | case HDIO_SET_NICE: |
| 292 | case HDIO_SET_WCACHE: |
| 293 | case HDIO_SET_ACOUSTIC: |
| 294 | case HDIO_SET_BUSSTATE: |
| 295 | case HDIO_SET_ADDRESS: |
| 296 | case CDROMEJECT_SW: |
| 297 | case CDROM_SET_OPTIONS: |
| 298 | case CDROM_CLEAR_OPTIONS: |
| 299 | case CDROM_SELECT_SPEED: |
| 300 | case CDROM_SELECT_DISC: |
| 301 | case CDROM_MEDIA_CHANGED: |
| 302 | case CDROM_DRIVE_STATUS: |
| 303 | case CDROM_LOCKDOOR: |
| 304 | case CDROM_DEBUG: |
Arnd Bergmann | 7199d4c | 2007-10-09 13:23:52 +0200 | [diff] [blame] | 305 | break; |
| 306 | default: |
| 307 | /* unknown ioctl number */ |
| 308 | return -ENOIOCTLCMD; |
| 309 | } |
| 310 | |
Al Viro | 33c2dca | 2008-02-22 22:02:50 -0500 | [diff] [blame] | 311 | return __blkdev_driver_ioctl(bdev, mode, cmd, arg); |
Arnd Bergmann | 7199d4c | 2007-10-09 13:23:52 +0200 | [diff] [blame] | 312 | } |
| 313 | |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 314 | /* Most of the generic ioctls are handled in the normal fallback path. |
| 315 | This assumes the blkdev's low level compat_ioctl always returns |
| 316 | ENOIOCTLCMD for unknown ioctls. */ |
| 317 | long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 318 | { |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 319 | int ret = -ENOIOCTLCMD; |
| 320 | struct inode *inode = file->f_mapping->host; |
| 321 | struct block_device *bdev = inode->i_bdev; |
| 322 | struct gendisk *disk = bdev->bd_disk; |
| 323 | fmode_t mode = file->f_mode; |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 324 | struct backing_dev_info *bdi; |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 325 | loff_t size; |
Akinobu Mita | 63f2649 | 2014-05-25 21:43:33 +0900 | [diff] [blame] | 326 | unsigned int max_sectors; |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 327 | |
Christoph Hellwig | fd4ce1a | 2008-11-05 14:58:42 +0100 | [diff] [blame] | 328 | /* |
| 329 | * O_NDELAY can be altered using fcntl(.., F_SETFL, ..), so we have |
| 330 | * to updated it before every ioctl. |
| 331 | */ |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 332 | if (file->f_flags & O_NDELAY) |
Christoph Hellwig | fd4ce1a | 2008-11-05 14:58:42 +0100 | [diff] [blame] | 333 | mode |= FMODE_NDELAY; |
| 334 | else |
| 335 | mode &= ~FMODE_NDELAY; |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 336 | |
| 337 | switch (cmd) { |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 338 | case HDIO_GETGEO: |
| 339 | return compat_hdio_getgeo(disk, bdev, compat_ptr(arg)); |
Martin K. Petersen | ac481c2 | 2009-10-03 20:52:01 +0200 | [diff] [blame] | 340 | case BLKPBSZGET: |
| 341 | return compat_put_uint(arg, bdev_physical_block_size(bdev)); |
| 342 | case BLKIOMIN: |
| 343 | return compat_put_uint(arg, bdev_io_min(bdev)); |
| 344 | case BLKIOOPT: |
| 345 | return compat_put_uint(arg, bdev_io_opt(bdev)); |
| 346 | case BLKALIGNOFF: |
| 347 | return compat_put_int(arg, bdev_alignment_offset(bdev)); |
Martin K. Petersen | 98262f2 | 2009-12-03 09:24:48 +0100 | [diff] [blame] | 348 | case BLKDISCARDZEROES: |
| 349 | return compat_put_uint(arg, bdev_discard_zeroes_data(bdev)); |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 350 | case BLKFLSBUF: |
| 351 | case BLKROSET: |
| 352 | case BLKDISCARD: |
Adrian Hunter | 8d57a98 | 2010-08-11 14:17:49 -0700 | [diff] [blame] | 353 | case BLKSECDISCARD: |
Mikulas Patocka | 3b3a181 | 2014-07-02 12:46:23 -0400 | [diff] [blame] | 354 | case BLKZEROOUT: |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 355 | /* |
| 356 | * the ones below are implemented in blkdev_locked_ioctl, |
| 357 | * but we call blkdev_ioctl, which gets the lock for us |
| 358 | */ |
| 359 | case BLKRRPART: |
Al Viro | 56b26ad | 2008-09-19 03:17:36 -0400 | [diff] [blame] | 360 | return blkdev_ioctl(bdev, mode, cmd, |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 361 | (unsigned long)compat_ptr(arg)); |
| 362 | case BLKBSZSET_32: |
Al Viro | 56b26ad | 2008-09-19 03:17:36 -0400 | [diff] [blame] | 363 | return blkdev_ioctl(bdev, mode, BLKBSZSET, |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 364 | (unsigned long)compat_ptr(arg)); |
| 365 | case BLKPG: |
Al Viro | 56b26ad | 2008-09-19 03:17:36 -0400 | [diff] [blame] | 366 | return compat_blkpg_ioctl(bdev, mode, cmd, compat_ptr(arg)); |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 367 | case BLKRAGET: |
| 368 | case BLKFRAGET: |
| 369 | if (!arg) |
| 370 | return -EINVAL; |
| 371 | bdi = blk_get_backing_dev_info(bdev); |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 372 | return compat_put_long(arg, |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 373 | (bdi->ra_pages * PAGE_SIZE) / 512); |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 374 | case BLKROGET: /* compatible */ |
| 375 | return compat_put_int(arg, bdev_read_only(bdev) != 0); |
| 376 | case BLKBSZGET_32: /* get the logical block size (cf. BLKSSZGET) */ |
| 377 | return compat_put_int(arg, block_size(bdev)); |
| 378 | case BLKSSZGET: /* get block device hardware sector size */ |
Martin K. Petersen | e1defc4 | 2009-05-22 17:17:49 -0400 | [diff] [blame] | 379 | return compat_put_int(arg, bdev_logical_block_size(bdev)); |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 380 | case BLKSECTGET: |
Akinobu Mita | 63f2649 | 2014-05-25 21:43:33 +0900 | [diff] [blame] | 381 | max_sectors = min_t(unsigned int, USHRT_MAX, |
| 382 | queue_max_sectors(bdev_get_queue(bdev))); |
| 383 | return compat_put_ushort(arg, max_sectors); |
Martin K. Petersen | ef00f59 | 2012-01-11 16:29:31 +0100 | [diff] [blame] | 384 | case BLKROTATIONAL: |
| 385 | return compat_put_ushort(arg, |
| 386 | !blk_queue_nonrot(bdev_get_queue(bdev))); |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 387 | case BLKRASET: /* compatible, but no compat_ptr (!) */ |
| 388 | case BLKFRASET: |
| 389 | if (!capable(CAP_SYS_ADMIN)) |
| 390 | return -EACCES; |
| 391 | bdi = blk_get_backing_dev_info(bdev); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 392 | bdi->ra_pages = (arg * 512) / PAGE_SIZE; |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 393 | return 0; |
| 394 | case BLKGETSIZE: |
Mike Snitzer | 77304d2 | 2010-11-08 14:39:12 +0100 | [diff] [blame] | 395 | size = i_size_read(bdev->bd_inode); |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 396 | if ((size >> 9) > ~0UL) |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 397 | return -EFBIG; |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 398 | return compat_put_ulong(arg, size >> 9); |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 399 | |
| 400 | case BLKGETSIZE64_32: |
Mike Snitzer | 77304d2 | 2010-11-08 14:39:12 +0100 | [diff] [blame] | 401 | return compat_put_u64(arg, i_size_read(bdev->bd_inode)); |
Arnd Bergmann | 171044d4 | 2007-10-09 13:23:53 +0200 | [diff] [blame] | 402 | |
| 403 | case BLKTRACESETUP32: |
Arnd Bergmann | 171044d4 | 2007-10-09 13:23:53 +0200 | [diff] [blame] | 404 | case BLKTRACESTART: /* compatible */ |
| 405 | case BLKTRACESTOP: /* compatible */ |
| 406 | case BLKTRACETEARDOWN: /* compatible */ |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 407 | ret = blk_trace_ioctl(bdev, cmd, compat_ptr(arg)); |
Arnd Bergmann | 7199d4c | 2007-10-09 13:23:52 +0200 | [diff] [blame] | 408 | return ret; |
Al Viro | 45048d0 | 2008-09-18 15:53:24 -0400 | [diff] [blame] | 409 | default: |
| 410 | if (disk->fops->compat_ioctl) |
| 411 | ret = disk->fops->compat_ioctl(bdev, mode, cmd, arg); |
| 412 | if (ret == -ENOIOCTLCMD) |
| 413 | ret = compat_blkdev_driver_ioctl(bdev, mode, cmd, arg); |
| 414 | return ret; |
| 415 | } |
Arnd Bergmann | f58c4c0 | 2007-10-09 13:23:51 +0200 | [diff] [blame] | 416 | } |