@@ -326,4 +326,5 @@ const struct file_operations hpfs_dir_ops =
.fsync = hpfs_file_fsync,
.unlocked_ioctl = hpfs_ioctl,
.compat_ioctl = compat_ptr_ioctl,
+ .fitrim = hpfs_fitrim,
};
@@ -216,6 +216,7 @@ const struct file_operations hpfs_file_ops =
.splice_read = generic_file_splice_read,
.unlocked_ioctl = hpfs_ioctl,
.compat_ioctl = compat_ptr_ioctl,
+ .fitrim = hpfs_fitrim,
};
const struct inode_operations hpfs_file_iops =
@@ -329,6 +329,7 @@ void hpfs_error(struct super_block *, const char *, ...);
int hpfs_stop_cycles(struct super_block *, int, int *, int *, char *);
unsigned hpfs_get_free_dnodes(struct super_block *);
long hpfs_ioctl(struct file *file, unsigned cmd, unsigned long arg);
+long hpfs_fitrim(struct file *file, struct fstrim_range *range);
/*
* local time (HPFS) to GMT (Unix)
@@ -200,30 +200,24 @@ static int hpfs_statfs(struct dentry *dentry, struct kstatfs *buf)
return 0;
}
+long hpfs_fitrim(struct file *file, struct fstrim_range *range)
+{
+ secno n_trimmed;
+
+ int r = hpfs_trim_fs(file_inode(file)->i_sb, range->start >> 9,
+ (range->start + range->len) >> 9,
+ (range->minlen + 511) >> 9, &n_trimmed);
+
+ if (r)
+ return r;
+
+ range->len = (u64)n_trimmed << 9;
+ return 0;
+}
long hpfs_ioctl(struct file *file, unsigned cmd, unsigned long arg)
{
- switch (cmd) {
- case FITRIM: {
- struct fstrim_range range;
- secno n_trimmed;
- int r;
- if (!capable(CAP_SYS_ADMIN))
- return -EPERM;
- if (copy_from_user(&range, (struct fstrim_range __user *)arg, sizeof(range)))
- return -EFAULT;
- r = hpfs_trim_fs(file_inode(file)->i_sb, range.start >> 9, (range.start + range.len) >> 9, (range.minlen + 511) >> 9, &n_trimmed);
- if (r)
- return r;
- range.len = (u64)n_trimmed << 9;
- if (copy_to_user((struct fstrim_range __user *)arg, &range, sizeof(range)))
- return -EFAULT;
- return 0;
- }
- default: {
- return -ENOIOCTLCMD;
- }
- }
+ return -ENOIOCTLCMD;
}