diff options
Diffstat (limited to 'fs/ioctl.c')
-rw-r--r-- | fs/ioctl.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/fs/ioctl.c b/fs/ioctl.c index f855ea4fc888..4f46752ce4f9 100644 --- a/fs/ioctl.c +++ b/fs/ioctl.c | |||
@@ -6,7 +6,6 @@ | |||
6 | 6 | ||
7 | #include <linux/syscalls.h> | 7 | #include <linux/syscalls.h> |
8 | #include <linux/mm.h> | 8 | #include <linux/mm.h> |
9 | #include <linux/smp_lock.h> | ||
10 | #include <linux/capability.h> | 9 | #include <linux/capability.h> |
11 | #include <linux/file.h> | 10 | #include <linux/file.h> |
12 | #include <linux/fs.h> | 11 | #include <linux/fs.h> |
@@ -530,6 +529,41 @@ static int ioctl_fsthaw(struct file *filp) | |||
530 | return thaw_super(sb); | 529 | return thaw_super(sb); |
531 | } | 530 | } |
532 | 531 | ||
532 | static int ioctl_fstrim(struct file *filp, void __user *argp) | ||
533 | { | ||
534 | struct super_block *sb = filp->f_path.dentry->d_inode->i_sb; | ||
535 | struct fstrim_range range; | ||
536 | int ret = 0; | ||
537 | |||
538 | if (!capable(CAP_SYS_ADMIN)) | ||
539 | return -EPERM; | ||
540 | |||
541 | /* If filesystem doesn't support trim feature, return. */ | ||
542 | if (sb->s_op->trim_fs == NULL) | ||
543 | return -EOPNOTSUPP; | ||
544 | |||
545 | /* If a blockdevice-backed filesystem isn't specified, return EINVAL. */ | ||
546 | if (sb->s_bdev == NULL) | ||
547 | return -EINVAL; | ||
548 | |||
549 | if (argp == NULL) { | ||
550 | range.start = 0; | ||
551 | range.len = ULLONG_MAX; | ||
552 | range.minlen = 0; | ||
553 | } else if (copy_from_user(&range, argp, sizeof(range))) | ||
554 | return -EFAULT; | ||
555 | |||
556 | ret = sb->s_op->trim_fs(sb, &range); | ||
557 | if (ret < 0) | ||
558 | return ret; | ||
559 | |||
560 | if ((argp != NULL) && | ||
561 | (copy_to_user(argp, &range, sizeof(range)))) | ||
562 | return -EFAULT; | ||
563 | |||
564 | return 0; | ||
565 | } | ||
566 | |||
533 | /* | 567 | /* |
534 | * When you add any new common ioctls to the switches above and below | 568 | * When you add any new common ioctls to the switches above and below |
535 | * please update compat_sys_ioctl() too. | 569 | * please update compat_sys_ioctl() too. |
@@ -580,6 +614,10 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, | |||
580 | error = ioctl_fsthaw(filp); | 614 | error = ioctl_fsthaw(filp); |
581 | break; | 615 | break; |
582 | 616 | ||
617 | case FITRIM: | ||
618 | error = ioctl_fstrim(filp, argp); | ||
619 | break; | ||
620 | |||
583 | case FS_IOC_FIEMAP: | 621 | case FS_IOC_FIEMAP: |
584 | return ioctl_fiemap(filp, arg); | 622 | return ioctl_fiemap(filp, arg); |
585 | 623 | ||