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