1 #include <linux/capability.h>
3 #include <linux/export.h>
9 #include <linux/blktrace_api.h>
10 #include <asm/uaccess.h>
16 struct hd_struct *
part, *lpart;
19 struct disk_part_iter piter;
38 length =
p.length >> 9;
40 if (
sizeof(
sector_t) ==
sizeof(
long) &&
41 sizeof(
long long) >
sizeof(
long)) {
43 if (pstart != start || plength != length
44 || pstart < 0 || plength < 0 || partno > 65535)
52 DISK_PITER_INCL_EMPTY);
54 if (!(start + length <= part->start_sect ||
55 start >= part->start_sect + part->nr_sects)) {
65 ADDPART_FLAG_NONE,
NULL);
67 return IS_ERR(part) ? PTR_ERR(part) : 0;
73 bdevp =
bdget(part_devt(part));
98 length =
p.length >> 9;
100 if (
sizeof(
sector_t) ==
sizeof(
long) &&
101 sizeof(
long long) >
sizeof(
long)) {
103 if (pstart != start || plength != length
104 || pstart < 0 || plength < 0)
110 bdevp =
bdget(part_devt(part));
117 if (start != part->start_sect) {
126 DISK_PITER_INCL_EMPTY);
128 if (lpart->partno != partno &&
129 !(start + length <= lpart->start_sect ||
130 start >= lpart->start_sect + lpart->nr_sects)
141 part_nr_sects_write(part, (
sector_t)length);
153 static int blkdev_reread_part(
struct block_device *bdev)
155 struct gendisk *disk = bdev->
bd_disk;
158 if (!disk_part_scan_enabled(disk) || bdev != bdev->
bd_contains)
172 unsigned long flags = 0;
181 if (start + len > (i_size_read(bdev->
bd_inode) >> 9))
184 flags |= BLKDEV_DISCARD_SECURE;
198 if (start + len > (i_size_read(bdev->
bd_inode) >> 9))
204 static int put_ushort(
unsigned long arg,
unsigned short val)
206 return put_user(val, (
unsigned short __user *)arg);
209 static int put_int(
unsigned long arg,
int val)
211 return put_user(val, (
int __user *)arg);
214 static int put_uint(
unsigned long arg,
unsigned int val)
216 return put_user(val, (
unsigned int __user *)arg);
219 static int put_long(
unsigned long arg,
long val)
221 return put_user(val, (
long __user *)arg);
224 static int put_ulong(
unsigned long arg,
unsigned long val)
226 return put_user(val, (
unsigned long __user *)arg);
229 static int put_u64(
unsigned long arg,
u64 val)
235 unsigned cmd,
unsigned long arg)
237 struct gendisk *disk = bdev->
bd_disk;
239 if (disk->fops->ioctl)
240 return disk->fops->ioctl(bdev, mode, cmd, arg);
264 static inline int is_unrecognized_ioctl(
int ret)
277 struct gendisk *disk = bdev->
bd_disk;
288 if (!is_unrecognized_ioctl(ret))
297 if (!is_unrecognized_ioctl(ret))
316 return blk_ioctl_discard(bdev, range[0], range[1],
328 return blk_ioctl_zeroout(bdev, range[0], range[1]);
336 if (!disk->fops->getgeo)
343 memset(&geo, 0,
sizeof(geo));
344 geo.
start = get_start_sect(bdev);
345 ret = disk->fops->getgeo(bdev, &geo);
366 return put_int(arg, bdev_logical_block_size(bdev));
368 return put_uint(arg, bdev_physical_block_size(bdev));
370 return put_uint(arg, bdev_io_min(bdev));
372 return put_uint(arg, bdev_io_opt(bdev));
374 return put_int(arg, bdev_alignment_offset(bdev));
376 return put_uint(arg, bdev_discard_zeroes_data(bdev));
378 return put_ushort(arg, queue_max_sectors(bdev_get_queue(bdev)));
380 return put_ushort(arg, !blk_queue_nonrot(bdev_get_queue(bdev)));
400 if (
blkdev_get(bdev, mode | FMODE_EXCL, &bdev) < 0)
404 if (!(mode & FMODE_EXCL))
411 ret = blkdev_reread_part(bdev);
415 if ((size >> 9) > ~0
UL)
417 return put_ulong(arg, size >> 9);
419 return put_u64(arg, i_size_read(bdev->
bd_inode));