fat: Add FITRIM ioctl for FAT file system
Subsystems (2)
OGAWA Hirofumi
maintainerPATCH 1/1 fat: Add FITRIM ioctl for FAT file system
From: Wentao Wang <[email protected]>
Add FITRIM ioctl for FAT file system
[[email protected]: bug fixes, coding style fixes, add signal check]
Signed-off-by Wentao Wang <[email protected]>
Signed-off-by OGAWA Hirofumi <[email protected]>
---
fs/fat/fat.h | 1 fs/fat/fatent.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fs/fat/file.c | 33 +++++++++++++++++ 3 files changed, 136 insertions(+)
fs/fat/fat.h renamed from fs/fat/fat.h~fat-fitrim +1 -0
@@ -357,6 +357,7 @@ extern int fat_alloc_clusters(struct ino int nr_cluster);extern int fat_free_clusters (struct inode *inode,int cluster);extern int fat_count_free_clusters (struct super_block *sb); +extern int fat_trim_fs (struct inode *inode,struct fstrim_range *range);/* fat/file.c */ extern long fat_generic_ioctl(struct file *filp, unsigned int cmd,
fs/fat/fatent.c renamed from fs/fat/fatent.c~fat-fitrim +102 -0
111 lines not on this page · raw message
fs/fat/file.c renamed from fs/fat/file.c~fat-fitrim +33 -0
@@ -121,6 +121,37 @@ static int fat_ioctl_get_volume_id(strucreturn put_user (sbi->vol_id, user_attr); } +static int fat_ioctl_fitrim (struct inode *inode,unsigned long arg) +{ +struct super_block *sb = inode->i_sb; +struct fstrim_range __user *user_range; +struct fstrim_range range; +struct request_queue *q =bdev_get_queue (sb->s_bdev); +int err; + +if (!capable (CAP_SYS_ADMIN )) +return -EPERM ; + +if (!blk_queue_discard (q)) +return -EOPNOTSUPP ; + + user_range = (struct fstrim_range __user *)arg; +if (copy_from_user (&range, user_range,sizeof (range))) +return -EFAULT ; + + range.minlen = max_t(unsigned int, range.minlen, + q->limits.discard_granularity); + + err =fat_trim_fs (inode, &range); +if (err <0 ) +return err; + +if (copy_to_user (user_range, &range,sizeof (range))) +return -EFAULT ; + +return 0 ; +} +long fat_generic_ioctl (struct file *filp,unsigned int cmd,unsigned long arg) {struct inode *inode =file_inode (filp);
@@ -133,6 +164,8 @@ long fat_generic_ioctl(struct file *filpreturn fat_ioctl_set_attributes (filp, user_attr);case FAT_IOCTL_GET_VOLUME_ID :return fat_ioctl_get_volume_id (inode, user_attr); +case FITRIM : +return fat_ioctl_fitrim (inode, arg);default :return -ENOTTY ;/* Inappropriate ioctl for device */ }
_
Signature · 1 line
OGAWA Hirofumi <[email protected]>